Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tag renaming #1396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/qtgui/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ bool Bookmarks::load()
std::stable_sort(m_BookmarkList.begin(),m_BookmarkList.end());

emit BookmarksChanged();
emit TagListChanged();
return true;
}
return false;
Expand Down Expand Up @@ -201,6 +202,7 @@ bool Bookmarks::save()
}

emit BookmarksChanged();
emit TagListChanged();
file.close();
return true;
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/qtgui/bookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Bookmarks : public QObject

QList<TagInfo::sptr> getTagList() { return QList<TagInfo::sptr>(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);
Expand Down
62 changes: 38 additions & 24 deletions src/qtgui/bookmarkstaglist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "bookmarkstaglist.h"
#include "bookmarks.h"
#include <QColorDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <stdio.h>
#include <QMenu>
#include <QHeaderView>
Expand Down Expand Up @@ -182,31 +184,32 @@ 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);
menu->addAction(actionNewTag);
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"
Expand 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();
Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/qtgui/bookmarkstaglist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading