Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/shell/textdocument.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 69 | static void selectAndReveal( KTextEditor::View* view, const KTextEditor::Range& range ) { | |||
---|---|---|---|---|---|
71 | if (range.isValid()) { | 71 | if (range.isValid()) { | ||
72 | view->setCursorPosition(range.start()); | 72 | view->setCursorPosition(range.start()); | ||
73 | if (!range.isEmpty()) { | 73 | if (!range.isEmpty()) { | ||
74 | view->setSelection(range); | 74 | view->setSelection(range); | ||
75 | } | 75 | } | ||
76 | } | 76 | } | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | class TextDocumentContextMenuData : public QObject | ||||
80 | { | ||||
81 | Q_OBJECT | ||||
82 | public: | ||||
83 | TextDocumentContextMenuData() | ||||
84 | { | ||||
85 | } | ||||
86 | | ||||
87 | ~TextDocumentContextMenuData() | ||||
88 | { | ||||
89 | delete addedContextMenu; | ||||
90 | addedContextMenu = nullptr; | ||||
91 | | ||||
92 | lastShowMenu = nullptr; | ||||
93 | } | ||||
94 | | ||||
95 | void populateContextMenu( KTextEditor::View* v, QMenu* menu ) | ||||
96 | { | ||||
97 | if (lastShowMenu) { | ||||
98 | foreach ( QAction* action, addedContextMenu->actions() ) { | ||||
99 | lastShowMenu->removeAction(action); | ||||
100 | } | ||||
101 | } | ||||
102 | | ||||
103 | delete addedContextMenu; | ||||
104 | addedContextMenu = new QMenu(); | ||||
105 | | ||||
106 | EditorContext c(v, v->cursorPosition()); | ||||
107 | auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c, addedContextMenu); | ||||
108 | | ||||
109 | ContextMenuExtension::populateMenu(addedContextMenu, extensions); | ||||
110 | | ||||
111 | foreach ( QAction* action, addedContextMenu->actions() ) { | ||||
112 | menu->addAction(action); | ||||
113 | } | ||||
114 | lastShowMenu = menu; | ||||
115 | } | ||||
116 | | ||||
117 | // we want to remove the previously added stuff before | ||||
118 | // the menu shows again. | ||||
119 | // This has to be a static instance because multiple views | ||||
120 | // can share the same context menu instance. | ||||
121 | QMenu* addedContextMenu = nullptr; | ||||
122 | QMenu* lastShowMenu = nullptr; | ||||
123 | }; | ||||
124 | | ||||
79 | class TextDocumentPrivate | 125 | class TextDocumentPrivate | ||
80 | { | 126 | { | ||
81 | public: | 127 | public: | ||
82 | explicit TextDocumentPrivate(TextDocument *textDocument) | 128 | explicit TextDocumentPrivate(TextDocument *textDocument) | ||
83 | : q(textDocument) | 129 | : q(textDocument) | ||
84 | { | 130 | { | ||
131 | if (!contextMenuData) { | ||||
132 | contextMenuData = new TextDocumentContextMenuData; | ||||
133 | } | ||||
85 | } | 134 | } | ||
86 | 135 | | |||
87 | ~TextDocumentPrivate() | 136 | ~TextDocumentPrivate() | ||
88 | { | 137 | { | ||
89 | delete addedContextMenu; | 138 | delete contextMenuData; | ||
90 | addedContextMenu = nullptr; | 139 | contextMenuData = nullptr; | ||
91 | | ||||
92 | saveSessionConfig(); | 140 | saveSessionConfig(); | ||
93 | delete document; | 141 | delete document; | ||
94 | } | 142 | } | ||
95 | 143 | | |||
96 | void setStatus(KTextEditor::Document* document, bool dirty) | 144 | void setStatus(KTextEditor::Document* document, bool dirty) | ||
97 | { | 145 | { | ||
98 | QIcon statusIcon; | 146 | QIcon statusIcon; | ||
99 | 147 | | |||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | |||||
226 | } | 274 | } | ||
227 | 275 | | |||
228 | TextDocument * const q; | 276 | TextDocument * const q; | ||
229 | 277 | | |||
230 | QPointer<KTextEditor::Document> document; | 278 | QPointer<KTextEditor::Document> document; | ||
231 | IDocument::DocumentState state = IDocument::Clean; | 279 | IDocument::DocumentState state = IDocument::Clean; | ||
232 | QString encoding; | 280 | QString encoding; | ||
233 | bool loaded = false; | 281 | bool loaded = false; | ||
234 | // we want to remove the added stuff when the menu hides | 282 | // there is only a single contextmenu at a time so use a single (static) | ||
235 | QMenu* addedContextMenu = nullptr; | 283 | // instance of the class keeping track of added menu actions. | ||
284 | static TextDocumentContextMenuData* contextMenuData; | ||||
236 | }; | 285 | }; | ||
237 | 286 | | |||
287 | TextDocumentContextMenuData* TextDocumentPrivate::contextMenuData = nullptr; | ||||
288 | | ||||
238 | class TextViewPrivate | 289 | class TextViewPrivate | ||
239 | { | 290 | { | ||
240 | public: | 291 | public: | ||
241 | explicit TextViewPrivate(TextView* q) : q(q) {} | 292 | explicit TextViewPrivate(TextView* q) : q(q) {} | ||
242 | 293 | | |||
243 | TextView* const q; | 294 | TextView* const q; | ||
244 | QPointer<KTextEditor::View> view; | 295 | QPointer<KTextEditor::View> view; | ||
245 | KTextEditor::Range initialRange; | 296 | KTextEditor::Range initialRange; | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 326 | { | |||
340 | view = d->document->createView(parent, Core::self()->uiControllerInternal()->defaultMainWindow()->kateWrapper()->interface()); | 391 | view = d->document->createView(parent, Core::self()->uiControllerInternal()->defaultMainWindow()->kateWrapper()->interface()); | ||
341 | 392 | | |||
342 | // get rid of some actions regarding the config dialog, we merge that one into the kdevelop menu already | 393 | // get rid of some actions regarding the config dialog, we merge that one into the kdevelop menu already | ||
343 | delete view->actionCollection()->action(QStringLiteral("set_confdlg")); | 394 | delete view->actionCollection()->action(QStringLiteral("set_confdlg")); | ||
344 | delete view->actionCollection()->action(QStringLiteral("editor_options")); | 395 | delete view->actionCollection()->action(QStringLiteral("editor_options")); | ||
345 | 396 | | |||
346 | view->setStatusBarEnabled(Core::self()->partControllerInternal()->showTextEditorStatusBar()); | 397 | view->setStatusBarEnabled(Core::self()->partControllerInternal()->showTextEditorStatusBar()); | ||
347 | 398 | | |||
348 | connect(view, &KTextEditor::View::contextMenuAboutToShow, this, &TextDocument::populateContextMenu); | 399 | connect(view, &KTextEditor::View::contextMenuAboutToShow, d->contextMenuData, &TextDocumentContextMenuData::populateContextMenu); | ||
349 | 400 | | |||
350 | if (KTextEditor::CodeCompletionInterface* cc = dynamic_cast<KTextEditor::CodeCompletionInterface*>(view)) | 401 | if (KTextEditor::CodeCompletionInterface* cc = dynamic_cast<KTextEditor::CodeCompletionInterface*>(view)) | ||
351 | cc->setAutomaticInvocationEnabled(core()->languageController()->completionSettings()->automaticCompletionEnabled()); | 402 | cc->setAutomaticInvocationEnabled(core()->languageController()->completionSettings()->automaticCompletionEnabled()); | ||
352 | 403 | | |||
353 | return view; | 404 | return view; | ||
354 | } | 405 | } | ||
355 | 406 | | |||
356 | KParts::Part *TextDocument::partForView(QWidget *view) const | 407 | KParts::Part *TextDocument::partForView(QWidget *view) const | ||
▲ Show 20 Lines • Show All 308 Lines • ▼ Show 20 Line(s) | |||||
665 | } | 716 | } | ||
666 | 717 | | |||
667 | void KDevelop::TextDocument::textChanged(KTextEditor::Document *document) | 718 | void KDevelop::TextDocument::textChanged(KTextEditor::Document *document) | ||
668 | { | 719 | { | ||
669 | Q_UNUSED(document); | 720 | Q_UNUSED(document); | ||
670 | notifyContentChanged(); | 721 | notifyContentChanged(); | ||
671 | } | 722 | } | ||
672 | 723 | | |||
673 | void KDevelop::TextDocument::populateContextMenu( KTextEditor::View* v, QMenu* menu ) | | |||
674 | { | | |||
675 | if (d->addedContextMenu) { | | |||
676 | foreach ( QAction* action, d->addedContextMenu->actions() ) { | | |||
677 | menu->removeAction(action); | | |||
678 | } | | |||
679 | delete d->addedContextMenu; | | |||
680 | } | | |||
681 | | ||||
682 | d->addedContextMenu = new QMenu(); | | |||
683 | | ||||
684 | EditorContext c(v, v->cursorPosition()); | | |||
685 | auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c, d->addedContextMenu); | | |||
686 | | ||||
687 | ContextMenuExtension::populateMenu(d->addedContextMenu, extensions); | | |||
688 | | ||||
689 | foreach ( QAction* action, d->addedContextMenu->actions() ) { | | |||
690 | menu->addAction(action); | | |||
691 | } | | |||
mwolff: can't you just add a slot here that removes the actions we added once the menu is closed? that… | |||||
mwolff: and with slot I mean an local lambda that takes a copy of the actions list | |||||
692 | } | | |||
693 | | ||||
694 | void KDevelop::TextDocument::repositoryCheckFinished(bool canRecreate) { | 724 | void KDevelop::TextDocument::repositoryCheckFinished(bool canRecreate) { | ||
695 | if ( d->state != IDocument::Dirty && d->state != IDocument::DirtyAndModified ) { | 725 | if ( d->state != IDocument::Dirty && d->state != IDocument::DirtyAndModified ) { | ||
696 | // document is not dirty for whatever reason, nothing to do. | 726 | // document is not dirty for whatever reason, nothing to do. | ||
697 | return; | 727 | return; | ||
698 | } | 728 | } | ||
699 | if ( ! canRecreate ) { | 729 | if ( ! canRecreate ) { | ||
700 | return; | 730 | return; | ||
701 | } | 731 | } | ||
Show All 30 Lines | |||||
732 | void KDevelop::TextDocument::documentUrlChanged(KTextEditor::Document* document) | 762 | void KDevelop::TextDocument::documentUrlChanged(KTextEditor::Document* document) | ||
733 | { | 763 | { | ||
734 | Q_UNUSED(document); | 764 | Q_UNUSED(document); | ||
735 | if (url() != d->document->url()) | 765 | if (url() != d->document->url()) | ||
736 | setUrl(d->document->url()); | 766 | setUrl(d->document->url()); | ||
737 | } | 767 | } | ||
738 | 768 | | |||
739 | #include "moc_textdocument.cpp" | 769 | #include "moc_textdocument.cpp" | ||
770 | #include "textdocument.moc" |
can't you just add a slot here that removes the actions we added once the menu is closed? that would fix this issue with way less code