import cx.fbn.nevernote.dialog.ShareNotebook;
import cx.fbn.nevernote.dialog.StackNotebook;
import cx.fbn.nevernote.dialog.TagEdit;
+import cx.fbn.nevernote.dialog.TagMerge;
import cx.fbn.nevernote.dialog.ThumbnailViewer;
import cx.fbn.nevernote.dialog.UpgradeAvailableDialog;
import cx.fbn.nevernote.dialog.WatchFolder;
emitLog = new ArrayList<String>();
tagTree.setDeleteAction(menuBar.tagDeleteAction);
+ tagTree.setMergeAction(menuBar.tagMergeAction);
tagTree.setEditAction(menuBar.tagEditAction);
tagTree.setAddAction(menuBar.tagAddAction);
tagTree.setIconAction(menuBar.tagIconAction);
menuBar.tagDeleteAction.setEnabled(false);
menuBar.tagIconAction.setEnabled(true);
}
+ if (selections.size() > 1)
+ menuBar.tagMergeAction.setEnabled(true);
+ else
+ menuBar.tagMergeAction.setEnabled(false);
listManager.setSelectedTags(selectedTagGUIDs);
listManager.loadNotesIndex();
noteIndexUpdated(false);
tagTree.clearSelection();
menuBar.noteRestoreAction.setVisible(false);
menuBar.tagEditAction.setEnabled(false);
+ menuBar.tagMergeAction.setEnabled(false);
menuBar.tagDeleteAction.setEnabled(false);
menuBar.tagIconAction.setEnabled(false);
selectedTagGUIDs.clear();
}
}
+ // Merge tags
+ private void mergeTags() {
+ List<Tag> tags = new ArrayList<Tag>();
+ List<QTreeWidgetItem> selections = tagTree.selectedItems();
+ for (int i=0; i<selections.size(); i++) {
+ Tag record = new Tag();
+ record.setGuid(selections.get(i).text(2));
+ record.setName(selections.get(i).text(0));
+ tags.add(record);
+ }
+ TagMerge mergeDialog = new TagMerge(tags);
+ mergeDialog.exec();
+ if (!mergeDialog.okClicked())
+ return;
+ String newGuid = mergeDialog.getNewTagGuid();
+
+ for (int i=0; i<tags.size(); i++) {
+ if (!tags.get(i).getGuid().equals(newGuid)) {
+ List<String> noteGuids = conn.getNoteTable().noteTagsTable.getTagNotes(tags.get(i).getGuid());
+ for (int j=0; j<noteGuids.size(); j++) {
+ String noteGuid = noteGuids.get(j);
+ conn.getNoteTable().noteTagsTable.deleteNoteTag(noteGuid);
+ if (!conn.getNoteTable().noteTagsTable.checkNoteNoteTags(noteGuid, newGuid))
+ conn.getNoteTable().noteTagsTable.saveNoteTag(noteGuid, newGuid);
+ }
+ }
+ }
+ listManager.reloadIndexes();
+ }
//***************************************************************
//***************************************************************
}
public void refreshLists() {
logger.log(logger.EXTREME, "Entering NeverNote.refreshLists");
- System.out.println("<><><><><><><><><><><><><><><><><><><><>");
updateQuotaBar();
listManager.refreshLists(currentNote, noteDirty, browserWindow.getContent());
tagIndexUpdated(true);
--- /dev/null
+/*\r
+ * This file is part of NeverNote \r
+ * Copyright 2009 Randy Baumgarte\r
+ * \r
+ * This file may be licensed under the terms of of the\r
+ * GNU General Public License Version 2 (the ``GPL'').\r
+ *\r
+ * Software distributed under the License is distributed\r
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
+ * express or implied. See the GPL for the specific language\r
+ * governing rights and limitations.\r
+ *\r
+ * You should have received a copy of the GPL along with this\r
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
+ * or write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ *\r
+*/\r
+\r
+package cx.fbn.nevernote.dialog;\r
+\r
+import java.util.List;\r
+\r
+import com.evernote.edam.type.Tag;\r
+import com.trolltech.qt.gui.QComboBox;\r
+import com.trolltech.qt.gui.QDialog;\r
+import com.trolltech.qt.gui.QHBoxLayout;\r
+import com.trolltech.qt.gui.QIcon;\r
+import com.trolltech.qt.gui.QLabel;\r
+import com.trolltech.qt.gui.QPushButton;\r
+import com.trolltech.qt.gui.QSpacerItem;\r
+import com.trolltech.qt.gui.QVBoxLayout;\r
+\r
+public class TagMerge extends QDialog {\r
+ private final QComboBox newTag;\r
+ private final QPushButton okButton;\r
+ private final QPushButton cancelButton;\r
+ private boolean okClicked;\r
+ private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+ \r
+ public TagMerge(List<Tag> tags) {\r
+ setWindowIcon(new QIcon(iconPath+"tag.png"));\r
+ okClicked = false;\r
+ \r
+ okButton = new QPushButton();\r
+ okButton.setText(tr("OK"));\r
+ okButton.pressed.connect(this, "onClicked()");\r
+ \r
+ cancelButton = new QPushButton();\r
+ cancelButton.setText(tr("Cancel"));\r
+ cancelButton.pressed.connect(this, "onCancel()");\r
+ \r
+ \r
+ QVBoxLayout middleLayout = new QVBoxLayout();\r
+ middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
+ middleLayout.addSpacerItem(new QSpacerItem(1,1));\r
+\r
+ QVBoxLayout closeLayout = new QVBoxLayout();\r
+ closeLayout.addWidget(new QLabel(tr("Merge Into")));\r
+ newTag = new QComboBox();\r
+ closeLayout.addWidget(newTag);\r
+ \r
+ QHBoxLayout buttonLayout = new QHBoxLayout();\r
+ buttonLayout.addStretch(1);\r
+ buttonLayout.addWidget(okButton);\r
+ buttonLayout.addWidget(cancelButton);\r
+ setWindowTitle(tr("Open/Close Notebooks"));\r
+ \r
+ QHBoxLayout upperLayout = new QHBoxLayout();\r
+ upperLayout.addLayout(middleLayout);\r
+ upperLayout.addLayout(closeLayout);\r
+ \r
+ QVBoxLayout mainLayout = new QVBoxLayout();\r
+ mainLayout.addLayout(upperLayout);\r
+ //mainLayout.addStretch(1);\r
+ mainLayout.addSpacing(1);\r
+ mainLayout.addLayout(buttonLayout);\r
+ setLayout(mainLayout);\r
+ \r
+ for (int i=0; i<tags.size(); i++) {\r
+ newTag.addItem(tags.get(i).getName(), tags.get(i).getGuid());\r
+ }\r
+ setWindowTitle(tr("Merge Tags"));\r
+ }\r
+ \r
+ @SuppressWarnings("unused")\r
+ private void onClicked() {\r
+ okClicked = true;\r
+ close();\r
+ }\r
+ \r
+ @SuppressWarnings("unused")\r
+ private void onCancel() {\r
+ okClicked = false;\r
+ close();\r
+ }\r
+ \r
+ public boolean okClicked() {\r
+ return okClicked;\r
+ }\r
+ \r
+ public String getNewTagGuid() {\r
+ int position = newTag.currentIndex();\r
+ return newTag.itemData(position).toString();\r
+ }\r
+}\r
\r
insertLatexAction = new QAction(tr("Insert LaTeX Formula"), this);\r
insertLatexAction.triggered.connect(parent, "insertLatex()");\r
- setupShortcut(insertLatexAction, "Insert_Latex");\r
+ setupShortcut(insertLatexAction, "Edit_Insert_Latex");\r
contextMenu.addAction(insertLatexAction);\r
insertLatexShortcut = new QShortcut(this);\r
- setupShortcut(insertLatexShortcut, "Latex_Insert");\r
+ setupShortcut(insertLatexShortcut, "Edit_Insert_Latex");\r
insertLatexShortcut.activated.connect(parent, "insertLatex()");\r
\r
contextMenu.addMenu(tableMenu);\r
public QAction tagAddAction; // Add a tag\r
public QAction tagDeleteAction; // Delete a tag\r
public QAction tagIconAction; // Change the icon\r
+ public QAction tagMergeAction; // Merge tags\r
\r
//**************************************************************************\r
//* Menu Bar Titles\r
tagIconAction.triggered.connect(parent, "setTagIcon()");\r
tagIconAction.setEnabled(false); \r
setupShortcut(tagIconAction, "File_Tag_Icon");\r
+ \r
+ tagMergeAction = new QAction(tr("Merge Tags"), this);\r
+ tagMergeAction.triggered.connect(parent, "mergeTags()");\r
+ tagMergeAction.setEnabled(false); \r
+ setupShortcut(tagMergeAction, "File_Tag_Merge");\r
\r
savedSearchAddAction = new QAction(tr("Add"),this);\r
savedSearchAddAction.triggered.connect(parent, "addSavedSearch()");\r
tagMenu.addAction(tagAddAction);\r
tagMenu.addAction(tagEditAction);\r
tagMenu.addAction(tagDeleteAction);\r
+ tagMenu.addAction(tagMergeAction);\r
tagMenu.addSeparator();\r
tagMenu.addAction(tagIconAction);\r
\r
private QAction deleteAction;\r
private QAction addAction;\r
private QAction iconAction;\r
+ private QAction mergeAction;\r
public TagSignal tagSignal;\r
public NoteSignal noteSignal;\r
private boolean showAllTags;\r
public void setIconAction(QAction i) {\r
iconAction = i;\r
}\r
+ public void setMergeAction(QAction i) { \r
+ mergeAction = i; }\r
\r
// Insert a new tag into the tree. This is used when we dynamically add a \r
// new tag after the full tag tree has been built. It only adds to the\r
menu.addAction(addAction);\r
menu.addAction(editAction);\r
menu.addAction(deleteAction);\r
+ menu.addAction(mergeAction);\r
menu.addSeparator();\r
menu.addAction(iconAction);\r
menu.exec(event.globalPos());\r
} \r
return tags;\r
}\r
+ // Get a list of notes by the tag guid\r
+ public List<String> getTagNotes(String tagGuid) {\r
+ if (tagGuid == null)\r
+ return null;\r
+ List<String> notes = new ArrayList<String>();\r
+ \r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ query.prepare("Select NoteGuid from NoteTags where tagGuid = :guid");\r
+ \r
+ query.bindValue(":guid", tagGuid);\r
+ if (!query.exec()) {\r
+ logger.log(logger.EXTREME, "getTagNotes SQL select has failed.");\r
+ logger.log(logger.MEDIUM, query.lastError());\r
+ return notes;\r
+ }\r
+ while (query.next()) {\r
+ notes.add(query.valueString(0));\r
+ } \r
+ return notes;\r
+ }\r
void prepareGetNoteTagsQuery() {\r
getNoteTagsQuery = new NSqlQuery(db.getConnection());\r
getNoteTagsQuery.prepare("Select TagGuid from NoteTags where noteGuid = :guid");\r