From 43e3921fa33a932e821d2cbe48b29185f2894b4b Mon Sep 17 00:00:00 2001 From: James Yuzawa Date: Sat, 9 Nov 2024 09:22:14 -0500 Subject: [PATCH] Support tag renaming --- src/qtgui/bookmarks.cpp | 2 ++ src/qtgui/bookmarkstaglist.cpp | 39 +++++++++++++++++----------------- src/qtgui/bookmarkstaglist.h | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/qtgui/bookmarks.cpp b/src/qtgui/bookmarks.cpp index d4593e5ac..f884e512d 100644 --- a/src/qtgui/bookmarks.cpp +++ b/src/qtgui/bookmarks.cpp @@ -140,6 +140,7 @@ bool Bookmarks::load() std::stable_sort(m_BookmarkList.begin(),m_BookmarkList.end()); emit BookmarksChanged(); + emit TagListChanged(); return true; } return false; @@ -201,6 +202,7 @@ bool Bookmarks::save() } emit BookmarksChanged(); + emit TagListChanged(); file.close(); return true; } diff --git a/src/qtgui/bookmarkstaglist.cpp b/src/qtgui/bookmarkstaglist.cpp index 791f48d93..93caa4a9e 100644 --- a/src/qtgui/bookmarkstaglist.cpp +++ b/src/qtgui/bookmarkstaglist.cpp @@ -23,6 +23,7 @@ #include "bookmarkstaglist.h" #include "bookmarks.h" #include +#include #include #include #include @@ -182,19 +183,6 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos) { QMenu* menu=new QMenu(this); - // Rename currently does not work. - // The problem is that after the tag name is changed in GUI - // you can not find the right TagInfo because you dont know - // the old tag name. - #if 0 - // MenuItem "Rename" - { - QAction* actionRename = new QAction("Rename", this); - menu->addAction(actionRename); - connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag())); - } - #endif - // MenuItem "Create new Tag" { QAction* actionNewTag = new QAction("Create new Tag", this); @@ -202,6 +190,13 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos) connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag())); } + // MenuItem "Rename Tag" + { + QAction* actionRename = new QAction("Rename Tag", this); + menu->addAction(actionRename); + connect(actionRename, SIGNAL(triggered()), this, SLOT(RenameSelectedTag())); + } + // Menu "Delete Tag" { QAction* actionDeleteTag = new QAction("Delete Tag", this); @@ -226,7 +221,6 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos) menu->popup(viewport()->mapToGlobal(pos)); } -#if 0 bool BookmarksTagList::RenameSelectedTag() { QModelIndexList selected = selectionModel()->selectedRows(); @@ -236,14 +230,21 @@ bool BookmarksTagList::RenameSelectedTag() return true; } - int iRow = selected.first().row(); - QTableWidgetItem* pItem = item(iRow,1);bUpdating - editItem(pItem); - //Bookmarks::Get().save(); + int row = selected.first().row(); + QString oldName = item(row, 1)->text(); + TagInfo::sptr info = Bookmarks::Get().findOrAddTag(oldName); + bool ok; + QString newName = QInputDialog::getText(this, "Rename Tag", "Tag Name:", + QLineEdit::Normal, oldName, &ok); + if (ok && newName != oldName) + { + info->name = newName; + updateTags(); + Bookmarks::Get().save(); + } return true; } -#endif void BookmarksTagList::AddNewTag() { diff --git a/src/qtgui/bookmarkstaglist.h b/src/qtgui/bookmarkstaglist.h index 66caa9a48..b85ac3fff 100644 --- a/src/qtgui/bookmarkstaglist.h +++ b/src/qtgui/bookmarkstaglist.h @@ -48,7 +48,7 @@ public slots: void changeColor(int row, int column); void toggleCheckedState(int row, int column); void ShowContextMenu(const QPoint& pos); - //bool RenameSelectedTag(); + bool RenameSelectedTag(); void AddNewTag(); void AddTag(QString name, Qt::CheckState checkstate = Qt::Checked, QColor color = TagInfo::DefaultColor); void DeleteSelectedTag();