summaryrefslogtreecommitdiffstats
path: root/src/kile/kilekonsolewidget.cpp
blob: b1cdcbbdfc97cb59d6161f0dc29a0fbc68a0d02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***************************************************************************
    begin                : Mon Dec 22 2003
    copyright            : (C) 2001 - 2003 by Brachet Pascal, 2003 by Jeroen Wijnhout
    email                : Jeroen.Wijnhout@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kilekonsolewidget.h"
#include "kileinfo.h"

#include <tqfileinfo.h>
#include <tqframe.h>

#include <tdelocale.h>
#include <klibloader.h>
#include <kurl.h>
#include <tdeparts/part.h>
#include <kate/document.h>
#include <kate/view.h>

#include "kileuntitled.h"

namespace KileWidget
{
	Konsole::Konsole(KileInfo * info, TQWidget *parent, const char *name) : 
		TQVBox(parent, name),
		m_bPresent(false),
		m_ki(info)
	{
		spawn();
	}

	Konsole::~Konsole()
	{
	}

	void Konsole::spawn()
	{
		KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");

		if (!factory) return;
		m_part = (KParts::ReadOnlyPart *) factory->create(this);

		if (!m_part) return;

		if (m_part->widget()->inherits("TQFrame"))
			((TQFrame*)m_part->widget())->setFrameStyle(TQFrame::Panel|TQFrame::Sunken);

		m_bPresent=true;
		connect ( m_part, TQ_SIGNAL(destroyed()), this, TQ_SLOT(slotDestroyed()) );
	
		m_part->widget()->show();
		show();
	}


	void Konsole::sync()
	{
		Kate::Document *doc = m_ki->activeTextDocument();
		Kate::View *view = 0;

		if (doc)
			view = static_cast<Kate::View*>(doc->views().first());

		if (view)
		{
			TQString finame;
			KURL url = view->getDoc()->url();

			if ( url.path().isEmpty() || KileUntitled::isUntitled(url.path()) ) return;

			TQFileInfo fic(url.directory());
			if ( fic.isReadable() )
			{
				setDirectory(url.directory());
				activate();
			}

			view->setFocus();
		}
	}

	void Konsole::setDirectory(const TQString &dirname)
	{
		if (m_bPresent)
		{
			KURL url(dirname);
			if (m_part->url() != url)
				m_part->openURL(url);
		}
	}

	void Konsole::showEvent(TQShowEvent *ev)
	{
		TQWidget::showEvent(ev);
		activate();
	}

	void Konsole::activate()
	{
		if (m_bPresent)
		{
			m_part->widget()->show();
			this->setFocusProxy(m_part->widget());
			m_part->widget()->setFocus();
		}
	}

	void Konsole::slotDestroyed ()
	{
		m_bPresent=false;
		spawn();
	}
}

#include "kilekonsolewidget.moc"