diff --git a/src/qtgui/bookmarks.cpp b/src/qtgui/bookmarks.cpp index d4593e5ac..f540dda36 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; } @@ -249,6 +251,36 @@ TagInfo::sptr Bookmarks::findOrAddTag(QString tagName) return m_TagList.last(); } +bool Bookmarks::renameTag(QString oldTagName, QString tagName) +{ + tagName = tagName.trimmed(); + + // Do not edit "Untagged" tag. + if (oldTagName.compare(TagInfo::strUntagged) == 0) + { + return false; + } + + // Ensure new tag does not already exist + int idx = getTagIndex(tagName); + if (idx != -1) + { + return false; + } + + for (int i = 0; i < m_TagList.size(); i++) + { + TagInfo::sptr info = m_TagList[i]; + if (oldTagName.compare(info->name) == 0) + { + info->name = tagName; + save(); + return true; + } + } + return false; +} + bool Bookmarks::removeTag(QString tagName) { tagName = tagName.trimmed(); diff --git a/src/qtgui/bookmarks.h b/src/qtgui/bookmarks.h index 8e3fee6ea..b7d8e7411 100644 --- a/src/qtgui/bookmarks.h +++ b/src/qtgui/bookmarks.h @@ -115,6 +115,7 @@ class Bookmarks : public QObject QList getTagList() { return QList(m_TagList); } TagInfo::sptr findOrAddTag(QString tagName); + bool renameTag(QString oldTagName, QString tagName); int getTagIndex(QString tagName); bool removeTag(QString tagName); bool setTagChecked(QString tagName, bool bChecked); diff --git a/src/qtgui/bookmarkstaglist.cpp b/src/qtgui/bookmarkstaglist.cpp index 791f48d93..f4f6c37f3 100644 --- a/src/qtgui/bookmarkstaglist.cpp +++ b/src/qtgui/bookmarkstaglist.cpp @@ -23,6 +23,8 @@ #include "bookmarkstaglist.h" #include "bookmarks.h" #include +#include +#include #include #include #include @@ -182,19 +184,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,11 +191,25 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos) connect(actionNewTag, SIGNAL(triggered()), this, SLOT(AddNewTag())); } - // Menu "Delete Tag" - { - QAction* actionDeleteTag = new QAction("Delete Tag", this); - menu->addAction(actionDeleteTag); - connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag())); + QTableWidgetItem* theItem = itemAt(pos); + if (theItem) { + QString tagName = item(theItem->row(), 1)->text(); + if (tagName.compare(TagInfo::strUntagged) != 0) + { + // 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); + menu->addAction(actionDeleteTag); + connect(actionDeleteTag, SIGNAL(triggered()), this, SLOT(DeleteSelectedTag())); + } + } } // Menu "Select All" @@ -226,7 +229,6 @@ void BookmarksTagList::ShowContextMenu(const QPoint& pos) menu->popup(viewport()->mapToGlobal(pos)); } -#if 0 bool BookmarksTagList::RenameSelectedTag() { QModelIndexList selected = selectionModel()->selectedRows(); @@ -236,14 +238,26 @@ 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(); + bool ok; + QString newName = QInputDialog::getText(this, "Rename Tag", "Tag Name:", + QLineEdit::Normal, oldName, &ok); + if (ok) + { + if (Bookmarks::Get().renameTag(oldName, newName)) + { + updateTags(); + } + else + { + QMessageBox::warning(this, "Rename Tag", QString("Tag %1 already exists").arg(newName), + QMessageBox::Ok, QMessageBox::Ok); + } + } 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();