Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/kateexternaltoolsplugin.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> | ||||
3 | Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> | ||||
4 | Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Library General Public | ||||
8 | License version 2 as published by the Free Software Foundation. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "kateexternaltoolsplugin.h" | ||||
22 | #include "kateexternaltoolsplugin.moc" | ||||
23 | | ||||
24 | #include <kicon.h> | ||||
25 | #include <kiconloader.h> | ||||
26 | #include <ktexteditor/document.h> | ||||
27 | #include <ktexteditor/view.h> | ||||
28 | #include <ktexteditor/editor.h> | ||||
29 | #include <kate/application.h> | ||||
30 | | ||||
31 | #include <kparts/part.h> | ||||
32 | #include <kaction.h> | ||||
33 | #include <kactioncollection.h> | ||||
34 | | ||||
35 | #include <kurl.h> | ||||
36 | #include <klocale.h> | ||||
37 | #include <kdebug.h> | ||||
38 | #include <kmessagebox.h> | ||||
39 | | ||||
40 | #include <kpluginloader.h> | ||||
41 | #include <kpluginfactory.h> | ||||
42 | #include <kaboutdata.h> | ||||
43 | #include <kauthorized.h> | ||||
44 | | ||||
45 | K_PLUGIN_FACTORY(KateExternalToolsFactory, registerPlugin<KateExternalToolsPlugin>();) | ||||
46 | K_EXPORT_PLUGIN(KateExternalToolsFactory(KAboutData("kateexternaltools","kateexternaltoolsplugin",ki18n("External Tools"), "0.1", ki18n("Run external tools"), KAboutData::License_LGPL)) ) | ||||
47 | | ||||
48 | | ||||
49 | KateExternalToolsPlugin::KateExternalToolsPlugin( QObject* parent, const QList<QVariant>& ): | ||||
50 | Kate::Plugin ( (Kate::Application*)parent ),m_command(0) | ||||
51 | { | ||||
52 | if (KAuthorized::authorizeKAction("shell_access")) | ||||
53 | { | ||||
54 | KTextEditor::CommandInterface* cmdIface = | ||||
55 | qobject_cast<KTextEditor::CommandInterface*>( Kate::application()->editor() ); | ||||
56 | if( cmdIface ) { | ||||
57 | m_command=new KateExternalToolsCommand(this); | ||||
58 | cmdIface->registerCommand( m_command ); | ||||
59 | } | ||||
60 | } | ||||
61 | } | ||||
62 | | ||||
63 | KateExternalToolsPlugin::~KateExternalToolsPlugin() | ||||
64 | { | ||||
65 | if (KAuthorized::authorizeKAction("shell_access")) | ||||
66 | { | ||||
67 | if (m_command) { | ||||
68 | KTextEditor::CommandInterface* cmdIface = | ||||
69 | qobject_cast<KTextEditor::CommandInterface*>( Kate::application()->editor() ); | ||||
70 | if( cmdIface ) | ||||
71 | cmdIface->unregisterCommand( m_command ); | ||||
72 | delete m_command; | ||||
73 | } | ||||
74 | } | ||||
75 | } | ||||
76 | | ||||
77 | Kate::PluginView *KateExternalToolsPlugin::createView (Kate::MainWindow *mainWindow) | ||||
78 | { | ||||
79 | KateExternalToolsPluginView *view= new KateExternalToolsPluginView (mainWindow); | ||||
80 | connect(view,SIGNAL(destroyed(QObject*)),this,SLOT(viewDestroyed(QObject*))); | ||||
81 | m_views.append(view); | ||||
82 | return view; | ||||
83 | } | ||||
84 | | ||||
85 | KateExternalToolsPluginView *KateExternalToolsPlugin::extView(QWidget *widget) | ||||
86 | { | ||||
87 | foreach (KateExternalToolsPluginView* view, m_views) | ||||
88 | { | ||||
89 | if (view->mainWindow()->window()==widget) return view; | ||||
90 | } | ||||
91 | return 0; | ||||
92 | } | ||||
93 | | ||||
94 | void KateExternalToolsPlugin::viewDestroyed(QObject *view) | ||||
95 | { | ||||
96 | m_views.removeAll(dynamic_cast<KateExternalToolsPluginView*>(view)); | ||||
97 | } | ||||
98 | | ||||
99 | void KateExternalToolsPlugin::reload() { | ||||
100 | if (KAuthorized::authorizeKAction("shell_access")) | ||||
101 | { | ||||
102 | KTextEditor::CommandInterface* cmdIface = | ||||
103 | qobject_cast<KTextEditor::CommandInterface*>( Kate::application()->editor() ); | ||||
104 | if (cmdIface) | ||||
105 | if(m_command) m_command->reload(); | ||||
106 | } | ||||
107 | foreach(KateExternalToolsPluginView* view,m_views) { | ||||
108 | view->rebuildMenu(); | ||||
109 | } | ||||
110 | } | ||||
111 | | ||||
112 | uint KateExternalToolsPlugin::configPages() const | ||||
113 | { | ||||
114 | return 1; | ||||
115 | } | ||||
116 | | ||||
117 | Kate::PluginConfigPage *KateExternalToolsPlugin::configPage (uint number, QWidget *parent, const char *name ) | ||||
118 | { | ||||
119 | if (number == 0) { | ||||
120 | return new KateExternalToolsConfigWidget(parent, this, name); | ||||
121 | } | ||||
122 | return 0; | ||||
123 | } | ||||
124 | | ||||
125 | QString KateExternalToolsPlugin::configPageName (uint number) const | ||||
126 | { | ||||
127 | if (number == 0) { | ||||
128 | return i18n("External Tools"); | ||||
129 | } | ||||
130 | return QString(); | ||||
131 | } | ||||
132 | | ||||
133 | QString KateExternalToolsPlugin::configPageFullName (uint number) const | ||||
134 | { | ||||
135 | if (number == 0) { | ||||
136 | return i18n("External Tools"); | ||||
137 | } | ||||
138 | return QString(); | ||||
139 | } | ||||
140 | | ||||
141 | KIcon KateExternalToolsPlugin::configPageIcon (uint number) const | ||||
142 | { | ||||
143 | if (number == 0) { | ||||
144 | return KIcon(); | ||||
145 | } | ||||
146 | return KIcon(); | ||||
147 | } | ||||
148 | | ||||
149 | | ||||
150 | KateExternalToolsPluginView::KateExternalToolsPluginView (Kate::MainWindow *mainWindow) | ||||
151 | : Kate::PluginView (mainWindow), Kate::XMLGUIClient(KateExternalToolsFactory::componentData()) | ||||
152 | { | ||||
153 | externalTools = 0; | ||||
154 | | ||||
155 | if (KAuthorized::authorizeKAction("shell_access")) | ||||
156 | { | ||||
157 | externalTools = new KateExternalToolsMenuAction( i18n("External Tools"), actionCollection(), mainWindow, mainWindow ); | ||||
158 | actionCollection()->addAction("tools_external", externalTools); | ||||
159 | externalTools->setWhatsThis( i18n("Launch external helper applications") ); | ||||
160 | | ||||
161 | } | ||||
162 | | ||||
163 | mainWindow->guiFactory()->addClient (this); | ||||
164 | } | ||||
165 | | ||||
166 | void KateExternalToolsPluginView::rebuildMenu() { | ||||
167 | kDebug(13001); | ||||
168 | if (externalTools) { | ||||
169 | KXMLGUIFactory *f=factory(); | ||||
170 | f->removeClient(this); | ||||
171 | reloadXML(); | ||||
172 | externalTools->reload(); | ||||
173 | kDebug(13001)<<"has just returned from externalTools->reload()"; | ||||
174 | f->addClient(this); | ||||
175 | } | ||||
176 | } | ||||
177 | | ||||
178 | KateExternalToolsPluginView::~KateExternalToolsPluginView () | ||||
179 | { | ||||
180 | mainWindow()->guiFactory()->removeClient (this); | ||||
181 | | ||||
182 | delete externalTools; | ||||
183 | externalTools = 0; | ||||
184 | } | ||||
185 | | ||||
186 | // kate: space-indent on; indent-width 2; replace-tabs on; |