Commit 4d63d74c authored by Milian Wolff's avatar Milian Wolff
Browse files

change the way we clear the menus, don't trust Qt's aboutToHide signal as there seemed to be many

cases where it didn't fire as I thought it would be. See also: http://labs.trolltech.com/blogs/2010/02/23/unpredictable-exec/

BUG: 228087
parent abd20401
......@@ -69,6 +69,14 @@ struct TextDocumentPrivate {
state = IDocument::Clean;
}
~TextDocumentPrivate()
{
if (m_addedContextMenu) {
delete m_addedContextMenu;
m_addedContextMenu = 0;
}
}
QPointer<KTextEditor::Document> document;
IDocument::DocumentState state;
QString encoding;
......@@ -89,12 +97,17 @@ struct TextDocumentPrivate {
void populateContextMenu( KTextEditor::View* v, QMenu* menu )
{
if (m_addedContextMenu) {
foreach ( QAction* action, m_addedContextMenu->actions() ) {
menu->removeAction(action);
}
delete m_addedContextMenu;
}
Context* c = new EditorContext( v, v->cursorPosition() );
QList<ContextMenuExtension> extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions( c );
menu->addSeparator();
// first we fill our container and than add those menus and actoins to the actual context menu
Q_ASSERT(m_addedContextMenu == 0);
m_addedContextMenu = new QMenu();
ContextMenuExtension::populateMenu(m_addedContextMenu, extensions);
foreach ( QAction* action, m_addedContextMenu->actions() ) {
......@@ -102,22 +115,6 @@ struct TextDocumentPrivate {
}
}
/**
* Kate uses a static menu, comes from a limitation of the KXMLGUI stuff.
* Hence we have to remove every action we added by hand (in KDevelop we have much
* more dynamic actions than static ones).
*/
void clearContextMenu()
{
QMenu* menu = qobject_cast<QMenu*>(m_textDocument->sender());
Q_ASSERT(menu);
foreach ( QAction* action, m_addedContextMenu->actions() ) {
menu->removeAction(action);
}
delete m_addedContextMenu;
m_addedContextMenu = 0;
}
void modifiedOnDisk(KTextEditor::Document *document, bool /*isModified*/,
KTextEditor::ModificationInterface::ModifiedOnDiskReason reason)
{
......@@ -296,8 +293,6 @@ QWidget *TextDocument::createViewWidget(QWidget *parent)
view->setContextMenu( view->defaultContextMenu() );
#endif
connect(view, SIGNAL(contextMenuAboutToShow(KTextEditor::View*,QMenu*)), this, SLOT(populateContextMenu(KTextEditor::View*,QMenu*)));
connect(view->contextMenu(), SIGNAL(aboutToHide()),
this, SLOT(clearContextMenu()));
}
if (KTextEditor::CodeCompletionInterface* cc = dynamic_cast<KTextEditor::CodeCompletionInterface*>(view))
......
......@@ -76,7 +76,6 @@ protected:
private:
Q_PRIVATE_SLOT(d, void newDocumentStatus(KTextEditor::Document*))
Q_PRIVATE_SLOT(d, void populateContextMenu(KTextEditor::View*, QMenu*))
Q_PRIVATE_SLOT(d, void clearContextMenu())
Q_PRIVATE_SLOT(d, void textChanged(KTextEditor::Document*))
Q_PRIVATE_SLOT(d, void modifiedOnDisk(KTextEditor::Document *, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason))
Q_PRIVATE_SLOT(d, void documentUrlChanged(KTextEditor::Document*))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment