OSDN Git Service

Added the ability to merge tags and corrected some shortcuts.
authorRandy Baumgarte <randy@fbn.cx>
Wed, 23 Mar 2011 20:31:07 +0000 (16:31 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 3 Apr 2011 18:03:10 +0000 (14:03 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/TagMerge.java [new file with mode: 0644]
src/cx/fbn/nevernote/gui/ContentView.java
src/cx/fbn/nevernote/gui/MainMenuBar.java
src/cx/fbn/nevernote/gui/TagTreeWidget.java
src/cx/fbn/nevernote/sql/NoteTagsTable.java

index 1eba567..d712f56 100644 (file)
@@ -154,6 +154,7 @@ import cx.fbn.nevernote.dialog.SetIcon;
 import cx.fbn.nevernote.dialog.ShareNotebook;
 import cx.fbn.nevernote.dialog.StackNotebook;
 import cx.fbn.nevernote.dialog.TagEdit;
 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;
 import cx.fbn.nevernote.dialog.ThumbnailViewer;
 import cx.fbn.nevernote.dialog.UpgradeAvailableDialog;
 import cx.fbn.nevernote.dialog.WatchFolder;
@@ -566,6 +567,7 @@ public class NeverNote extends QMainWindow{
                emitLog = new ArrayList<String>();
                
                tagTree.setDeleteAction(menuBar.tagDeleteAction);
                emitLog = new ArrayList<String>();
                
                tagTree.setDeleteAction(menuBar.tagDeleteAction);
+               tagTree.setMergeAction(menuBar.tagMergeAction);
                tagTree.setEditAction(menuBar.tagEditAction);
                tagTree.setAddAction(menuBar.tagAddAction);
                tagTree.setIconAction(menuBar.tagIconAction);
                tagTree.setEditAction(menuBar.tagEditAction);
                tagTree.setAddAction(menuBar.tagAddAction);
                tagTree.setIconAction(menuBar.tagIconAction);
@@ -2107,6 +2109,10 @@ public class NeverNote extends QMainWindow{
                menuBar.tagDeleteAction.setEnabled(false);
                menuBar.tagIconAction.setEnabled(true);
        }
                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);
        listManager.setSelectedTags(selectedTagGUIDs);
        listManager.loadNotesIndex();
        noteIndexUpdated(false);
@@ -2253,6 +2259,7 @@ public class NeverNote extends QMainWindow{
                tagTree.clearSelection();
                menuBar.noteRestoreAction.setVisible(false);
                menuBar.tagEditAction.setEnabled(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();
                menuBar.tagDeleteAction.setEnabled(false);
                menuBar.tagIconAction.setEnabled(false);
                selectedTagGUIDs.clear();
@@ -2291,7 +2298,36 @@ public class NeverNote extends QMainWindow{
                }
        
        }
                }
        
        }
+       // 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();
+       }
        
     //***************************************************************
     //***************************************************************
        
     //***************************************************************
     //***************************************************************
@@ -5340,7 +5376,6 @@ public class NeverNote extends QMainWindow{
        }
        public void refreshLists() {
                logger.log(logger.EXTREME, "Entering NeverNote.refreshLists");
        }
        public void refreshLists() {
                logger.log(logger.EXTREME, "Entering NeverNote.refreshLists");
-               System.out.println("<><><><><><><><><><><><><><><><><><><><>");
                updateQuotaBar();
                listManager.refreshLists(currentNote, noteDirty, browserWindow.getContent());
                tagIndexUpdated(true);
                updateQuotaBar();
                listManager.refreshLists(currentNote, noteDirty, browserWindow.getContent());
                tagIndexUpdated(true);
diff --git a/src/cx/fbn/nevernote/dialog/TagMerge.java b/src/cx/fbn/nevernote/dialog/TagMerge.java
new file mode 100644 (file)
index 0000000..6506ded
--- /dev/null
@@ -0,0 +1,106 @@
+/*\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
index 648570b..4c09bf0 100644 (file)
@@ -175,10 +175,10 @@ public class ContentView extends QWebView {
 \r
                insertLatexAction = new QAction(tr("Insert LaTeX Formula"), this);\r
                insertLatexAction.triggered.connect(parent, "insertLatex()");\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
                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
                insertLatexShortcut.activated.connect(parent, "insertLatex()");\r
                \r
                contextMenu.addMenu(tableMenu);\r
index 943759a..93ded16 100644 (file)
@@ -121,6 +121,7 @@ public class MainMenuBar extends QMenuBar {
        public QAction                  tagAddAction;                           // Add a tag\r
        public QAction                  tagDeleteAction;                        // Delete a tag\r
        public QAction                  tagIconAction;                          // Change the icon\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
        \r
        //**************************************************************************\r
        //* Menu Bar Titles\r
@@ -525,6 +526,11 @@ public class MainMenuBar extends QMenuBar {
                tagIconAction.triggered.connect(parent, "setTagIcon()");\r
                tagIconAction.setEnabled(false);                \r
                setupShortcut(tagIconAction, "File_Tag_Icon");\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
                                \r
                savedSearchAddAction = new QAction(tr("Add"),this);\r
                savedSearchAddAction.triggered.connect(parent, "addSavedSearch()");\r
@@ -738,6 +744,7 @@ public class MainMenuBar extends QMenuBar {
                tagMenu.addAction(tagAddAction);\r
                tagMenu.addAction(tagEditAction);\r
                tagMenu.addAction(tagDeleteAction);\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
                tagMenu.addSeparator();\r
                tagMenu.addAction(tagIconAction);\r
                \r
index 46f55f6..4ffa009 100644 (file)
@@ -57,6 +57,7 @@ public class TagTreeWidget extends QTreeWidget {
        private QAction deleteAction;\r
        private QAction addAction;\r
        private QAction iconAction;\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 TagSignal tagSignal;\r
        public NoteSignal noteSignal;\r
        private boolean showAllTags;\r
@@ -110,6 +111,8 @@ public class TagTreeWidget extends QTreeWidget {
        public void setIconAction(QAction i) {\r
                iconAction = i;\r
        }\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
        \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
@@ -406,6 +409,7 @@ public class TagTreeWidget extends QTreeWidget {
                menu.addAction(addAction);\r
                menu.addAction(editAction);\r
                menu.addAction(deleteAction);\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
                menu.addSeparator();\r
                menu.addAction(iconAction);\r
                menu.exec(event.globalPos());\r
index 75585ce..232bd7d 100644 (file)
@@ -72,6 +72,26 @@ public class NoteTagsTable {
                }       \r
                return tags;\r
        }\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
        void prepareGetNoteTagsQuery() {\r
                getNoteTagsQuery = new NSqlQuery(db.getConnection());\r
                getNoteTagsQuery.prepare("Select TagGuid from NoteTags where noteGuid = :guid");\r