Skip to content

Commit

Permalink
bookmarkstaglist: Avoid leaking a menu each time it is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Nov 10, 2024
1 parent 684b145 commit 34897c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,44 +180,46 @@ QStringList BookmarksTagList::getSelectedTags()

void BookmarksTagList::ShowContextMenu(const QPoint& pos)
{
QMenu* menu=new QMenu(this);

// MenuItem "Rename"
if(!popupMenu)
{
QAction* actionRename = new QAction("Rename", this);
menu->addAction(actionRename);
connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag()));
}
popupMenu=new QMenu(this);

// MenuItem "Create new Tag"
{
QAction* actionNewTag = new QAction("Create new Tag", this);
menu->addAction(actionNewTag);
connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag()));
}
// MenuItem "Rename"
{
QAction* actionRename = new QAction("Rename", this);
popupMenu->addAction(actionRename);
connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag()));
}

// Menu "Delete Tag"
{
QAction* actionDeleteTag = new QAction("Delete Tag", this);
menu->addAction(actionDeleteTag);
connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag()));
}
// MenuItem "Create new Tag"
{
QAction* actionNewTag = new QAction("Create new Tag", this);
popupMenu->addAction(actionNewTag);
connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag()));
}

// Menu "Select All"
{
QAction* action = new QAction("Select All", this);
menu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(SelectAll()));
}
// Menu "Delete Tag"
{
QAction* actionDeleteTag = new QAction("Delete Tag", this);
popupMenu->addAction(actionDeleteTag);
connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag()));
}

// Menu "Deselect All"
{
QAction* action = new QAction("Deselect All", this);
menu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(DeselectAll()));
}
// Menu "Select All"
{
QAction* action = new QAction("Select All", this);
popupMenu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(SelectAll()));
}

menu->popup(viewport()->mapToGlobal(pos));
// Menu "Deselect All"
{
QAction* action = new QAction("Deselect All", this);
popupMenu->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(DeselectAll()));
}
}
popupMenu->popup(viewport()->mapToGlobal(pos));
}

bool BookmarksTagList::RenameSelectedTag()
Expand Down
1 change: 1 addition & 0 deletions src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BookmarksTagList : public QTableWidget

private:
bool m_bShowUntagged;
QMenu* popupMenu{nullptr};

signals:

Expand Down

0 comments on commit 34897c8

Please sign in to comment.