Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/shell/textdocument.cpp
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Line(s) | 81 | public: | |||
---|---|---|---|---|---|
226 | } | 226 | } | ||
227 | 227 | | |||
228 | TextDocument * const q; | 228 | TextDocument * const q; | ||
229 | 229 | | |||
230 | QPointer<KTextEditor::Document> document; | 230 | QPointer<KTextEditor::Document> document; | ||
231 | IDocument::DocumentState state = IDocument::Clean; | 231 | IDocument::DocumentState state = IDocument::Clean; | ||
232 | QString encoding; | 232 | QString encoding; | ||
233 | bool loaded = false; | 233 | bool loaded = false; | ||
234 | // we want to remove the added stuff when the menu hides | 234 | // we want to remove the added stuff when the menu hides. | ||
235 | QMenu* addedContextMenu = nullptr; | 235 | // This has to be a static instance because multiple views | ||
236 | // can share the same context menu instance. | ||||
237 | static QMenu* addedContextMenu; | ||||
236 | }; | 238 | }; | ||
237 | 239 | | |||
240 | QMenu* TextDocumentPrivate::addedContextMenu = nullptr; | ||||
241 | | ||||
238 | class TextViewPrivate | 242 | class TextViewPrivate | ||
239 | { | 243 | { | ||
240 | public: | 244 | public: | ||
241 | explicit TextViewPrivate(TextView* q) : q(q) {} | 245 | explicit TextViewPrivate(TextView* q) : q(q) {} | ||
242 | 246 | | |||
243 | TextView* const q; | 247 | TextView* const q; | ||
244 | QPointer<KTextEditor::View> view; | 248 | QPointer<KTextEditor::View> view; | ||
245 | KTextEditor::Range initialRange; | 249 | KTextEditor::Range initialRange; | ||
▲ Show 20 Lines • Show All 437 Lines • ▼ Show 20 Line(s) | 678 | { | |||
683 | 687 | | |||
684 | EditorContext c(v, v->cursorPosition()); | 688 | EditorContext c(v, v->cursorPosition()); | ||
685 | auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c, d->addedContextMenu); | 689 | auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c, d->addedContextMenu); | ||
686 | 690 | | |||
687 | ContextMenuExtension::populateMenu(d->addedContextMenu, extensions); | 691 | ContextMenuExtension::populateMenu(d->addedContextMenu, extensions); | ||
688 | 692 | | |||
689 | foreach ( QAction* action, d->addedContextMenu->actions() ) { | 693 | foreach ( QAction* action, d->addedContextMenu->actions() ) { | ||
690 | menu->addAction(action); | 694 | menu->addAction(action); | ||
691 | } | 695 | } | ||
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 | } | 696 | } | ||
693 | 697 | | |||
694 | void KDevelop::TextDocument::repositoryCheckFinished(bool canRecreate) { | 698 | void KDevelop::TextDocument::repositoryCheckFinished(bool canRecreate) { | ||
695 | if ( d->state != IDocument::Dirty && d->state != IDocument::DirtyAndModified ) { | 699 | if ( d->state != IDocument::Dirty && d->state != IDocument::DirtyAndModified ) { | ||
696 | // document is not dirty for whatever reason, nothing to do. | 700 | // document is not dirty for whatever reason, nothing to do. | ||
697 | return; | 701 | return; | ||
698 | } | 702 | } | ||
699 | if ( ! canRecreate ) { | 703 | if ( ! canRecreate ) { | ||
Show All 40 Lines |
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