• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Generic Shell
 

KDevelop Generic Shell

  • src
editorproxy.cpp
1#include <tqwidget.h>
2#include <tqpopupmenu.h>
3#include <tqtimer.h>
4
5#include <kdebug.h>
6#include <tdeconfig.h>
7#include <tdeapplication.h>
8
9#include <tdeparts/part.h>
10
11#include <tdetexteditor/document.h>
12#include <tdetexteditor/view.h>
13#include <tdetexteditor/viewcursorinterface.h>
14#include <tdetexteditor/popupmenuinterface.h>
15#include <tdetexteditor/editinterface.h>
16#include <tdetexteditor/selectioninterface.h>
17#include <tdetexteditor/view.h>
18#include <kxmlguiclient.h>
19#include <kxmlguifactory.h>
20#include <tdemainwindow.h>
21#include <tdeactioncollection.h>
22#include <tdelocale.h>
23#include <tdestdaccel.h>
24
25#include "toplevel.h"
26#include "partcontroller.h"
27#include "core.h"
28#include "multibuffer.h"
29#include "kdeveditorutil.h"
30
31#include "editorproxy.h"
32
33using namespace KTextEditor;
34
35EditorProxy *EditorProxy::s_instance = 0;
36
37
38EditorProxy::EditorProxy()
39 : TQObject()
40{
41 m_delayedLineTimer = new TQTimer( this );
42 connect( m_delayedLineTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT(setLineNumberDelayed()) );
43 TDEConfig *config = kapp->config();
44
45 m_delayedViewCreationCompatibleUI = true;
46
47 TDEAction *ac = new TDEAction( i18n("Show Context Menu"), 0, this,
48 TQ_SLOT(showPopup()), TopLevel::getInstance()->main()->actionCollection(), "show_popup" );
49 TDEShortcut cut ;/*= TDEStdAccel::shortcut(TDEStdAccel::PopupMenuContext);*/
50 cut.append(KKey(CTRL+Key_Return));
51 ac->setShortcut(cut);
52}
53
54
55EditorProxy *EditorProxy::getInstance()
56{
57 if (!s_instance)
58 s_instance = new EditorProxy;
59
60 return s_instance;
61}
62
63void EditorProxy::setLineNumberDelayed()
64{
65 if( !this ) return;
66 setLineNumber(m_delayedPart, m_delayedLine, m_delayedCol);
67}
68
69
70void EditorProxy::setLineNumber(KParts::Part *part, int lineNum, int col)
71{
72 if (!part || !part->inherits("KTextEditor::Document"))
73 return;
74
75 if ( lineNum < 0 )
76 return;
77
78 KURL url = dynamic_cast<KParts::ReadOnlyPart*>( part )->url();
79 ViewCursorInterface *iface = dynamic_cast<ViewCursorInterface*>(part->widget());
80 if (iface)
81 {
82 iface->setCursorPositionReal(lineNum, col == -1 ? 0 : col);
83 }
84 else {
85 // Save the position for a rainy day (or when the view gets activated and wants its position)
86 for (TQValueList<MultiBuffer*>::ConstIterator it = m_editorParts.begin(); it != m_editorParts.end(); ++it)
87 if ((*it)->hasURL( url )) {
88 (*it)->registerDelayedActivation( part, lineNum, col );
89 return;
90 }
91
92 // Shouldn't hit this?
93 Q_ASSERT(false);
94 }
95}
96
97void EditorProxy::installPopup( KParts::Part * part )
98{
99
100 if ( part->inherits("KTextEditor::Document") && part->widget())
101 {
102 PopupMenuInterface *iface = dynamic_cast<PopupMenuInterface*>(part->widget());
103 if (iface)
104 {
105 KTextEditor::View * view = static_cast<KTextEditor::View*>( part->widget() );
106
107 TQPopupMenu * popup = static_cast<TQPopupMenu*>( part->factory()->container("tdetexteditor_popup", view ) );
108
109 if (!popup)
110 {
111 kdWarning() << k_funcinfo << "Popup not found!" << endl;
112 return;
113 }
114
115 TDEAction * action = NULL;
116 //If there is a tab for this file, we don't need to plug the closing menu entries here
117 TDEConfig *config = TDEGlobal::config();
118 config->setGroup("UI");
119 bool m_tabBarShown = ! config->readNumEntry("TabWidgetVisibility", 0);
120 if (!m_tabBarShown)
121 {
122 action = TopLevel::getInstance()->main()->actionCollection()->action( "file_close" );
123 if ( action && !action->isPlugged( popup ) )
124 {
125 popup->insertSeparator( 0 );
126 action->plug( popup, 0 );
127 }
128 action = TopLevel::getInstance()->main()->actionCollection()->action( "file_closeother" );
129 if ( action && !action->isPlugged( popup ) )
130 action->plug( popup, 1 );
131 }
132
133 iface->installPopup( popup );
134
135 connect(popup, TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(popupAboutToShow()));
136
137 // ugly hack: mark the "original" items
138 m_popupIds.resize(popup->count());
139 for (uint index=0; index < popup->count(); ++index)
140 m_popupIds[index] = popup->idAt(index);
141 }
142 }
143}
144
145void EditorProxy::popupAboutToShow()
146{
147 TQPopupMenu *popup = (TQPopupMenu*)sender();
148 if (!popup)
149 return;
150
151 // ugly hack: remove all but the "original" items
152 for (int index=popup->count()-1; index >= 0; --index)
153 {
154 int id = popup->idAt(index);
155 if (m_popupIds.contains(id) == 0)
156 {
157 TQMenuItem *item = popup->findItem(id);
158 if ( item && item->popup() )
159 delete item->popup();
160 else
161 popup->removeItemAt(index);
162 }
163 }
164
165 KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( PartController::getInstance()->activePart() );
166 if (!doc ) return;
167
168 unsigned int line;
169 unsigned int col;
170 if ( !KDevEditorUtil::currentPositionReal( &line, &col, doc ) ) return;
171
172 TQString wordstr;
173 TQString selection = KDevEditorUtil::currentSelection( doc );
174 if ( !selection.isEmpty() && selection.contains('\n') != 0 )
175 {
176 wordstr = selection;
177 }
178 else
179 {
180 wordstr = KDevEditorUtil::currentWord( doc );
181 }
182
183 TQString linestr = KDevEditorUtil::currentLine( doc );
184
185 EditorContext context( doc->url(), line, col, linestr, wordstr );
186 Core::getInstance()->fillContextMenu( popup, &context );
187
188 // Remove redundant separators (any that are first, last, or doubled)
189 bool lastWasSeparator = true;
190 for( uint i = 0; i < popup->count(); )
191 {
192 int id = popup->idAt( i );
193 if( lastWasSeparator && popup->findItem( id )->isSeparator() )
194 {
195 popup->removeItem( id );
196 // Since we removed an item, don't increment i
197 } else
198 {
199 lastWasSeparator = false;
200 i++;
201 }
202 }
203 if( lastWasSeparator && popup->count() > 0 )
204 popup->removeItem( popup->idAt( popup->count() - 1 ) );
205}
206
207void EditorProxy::showPopup( )
208{
209 kdDebug(9000) << k_funcinfo << endl;
210
211 if ( KParts::Part * part = PartController::getInstance()->activePart() )
212 {
213 ViewCursorInterface *iface = dynamic_cast<ViewCursorInterface*>( part->widget() );
214 if ( iface )
215 {
216 KTextEditor::View * view = static_cast<KTextEditor::View*>( part->widget() );
217 TQPopupMenu * popup = static_cast<TQPopupMenu*>( view->factory()->container("tdetexteditor_popup", view ) );
218
219 if ( popup )
220 {
221 popup->exec( view->mapToGlobal( iface->cursorCoordinates() ) );
222 }
223 }
224 }
225}
226
227void EditorProxy::registerEditor(MultiBuffer* wrapper)
228{
229 m_editorParts.append(wrapper);
230}
231
232void EditorProxy::deregisterEditor(MultiBuffer* wrapper)
233{
234 m_editorParts.remove(wrapper);
235}
236
237TQWidget * EditorProxy::widgetForPart( KParts::Part * part )
238{
239 if ( !part ) return 0;
240
241 if (part->widget())
242 return part->widget();
243
244 KURL url = dynamic_cast<KParts::ReadOnlyPart*>( part )->url();
245
246 for (TQValueList<MultiBuffer*>::ConstIterator it = m_editorParts.begin(); it != m_editorParts.end(); ++it)
247 if ((*it)->hasURL( url ))
248 return *it;
249
250 return 0L;
251}
252
253TQWidget * EditorProxy::topWidgetForPart( KParts::Part * part )
254{
255 if ( !part ) return 0;
256
257 KURL url = dynamic_cast<KParts::ReadOnlyPart*>( part )->url();
258
259 for (TQValueList<MultiBuffer*>::ConstIterator it = m_editorParts.begin(); it != m_editorParts.end(); ++it)
260 if ((*it)->hasURL( url ))
261 return *it;
262
263 if (part->widget())
264 return part->widget();
265
266 return 0L;
267}
268
269bool EditorProxy::isDelayedViewCapable( )
270{
271 return m_delayedViewCreationCompatibleUI;
272}
273
274TQWidget *EditorProxy::findPartWidget(KParts::Part *part)
275{
276 for (TQValueList<MultiBuffer*>::ConstIterator it = m_editorParts.begin(); it != m_editorParts.end(); ++it)
277 if ((*it)->hasPart(part))
278 return *it;
279
280 if (part->widget())
281 return part->widget();
282
283 return 0L;
284}
285
286#include "editorproxy.moc"
TopLevel::getInstance
static KDevMainWindow * getInstance()
Get a pointer to the single KDevTopLevel object.
Definition toplevel.cpp:18

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Generic Shell by doxygen 1.15.0
This website is maintained by Timothy Pearson.