OSDN Git Service

Fixed a problem with the tag entry text field on a note. The problem was that a...
authorRandy Baumgarte <randy@fbn.cx>
Wed, 28 Jul 2010 10:44:49 +0000 (06:44 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Wed, 28 Jul 2010 10:44:49 +0000 (06:44 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/gui/TagTreeWidget.java

index 5897cf1..a931981 100644 (file)
@@ -1459,6 +1459,13 @@ public class NeverNote extends QMainWindow{
        // A note's tags have been updated
        @SuppressWarnings("unused")
        private void updateNoteTags(String guid, List<String> tags) {
+               // Save any new tags.  We'll need them later.
+               List<String> newTags = new ArrayList<String>();
+               for (int i=0; i<tags.size(); i++) {
+                       if (conn.getTagTable().findTagByName(tags.get(i))==null) 
+                               newTags.add(tags.get(i));
+               }
+               
                listManager.saveNoteTags(guid, tags);
                listManager.countTagResults(listManager.getNoteIndex());
                StringBuffer names = new StringBuffer("");
@@ -1470,7 +1477,10 @@ public class NeverNote extends QMainWindow{
                }
                browserWindow.setTag(names.toString());
                noteDirty = true;
-//             tagTree.updateCounts(listManager.getTagCounter());
+               
+               // Now, we need to add any new tags to the tag tree
+               for (int i=0; i<newTags.size(); i++) 
+                       tagTree.insertTag(newTags.get(i), conn.getTagTable().findTagByName(newTags.get(i)));
        }
        // Get a string containing all tag names for a note
        private String getTagNamesForNote(Note n) {
index 8ae338d..3c3a9b6 100644 (file)
@@ -95,6 +95,29 @@ public class TagTreeWidget extends QTreeWidget {
                addAction = a;\r
        }\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
+       // top level.\r
+       public void insertTag(String name, String guid) {\r
+       String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+               QIcon icon = new QIcon(iconPath+"tag.png");\r
+               QTreeWidgetItem child;\r
+               Qt.Alignment ra = new Qt.Alignment(Qt.AlignmentFlag.AlignRight);\r
+               \r
+               // Build new tag & add it\r
+               child = new QTreeWidgetItem();\r
+               child.setText(0, name);\r
+               child.setIcon(0,icon);\r
+               child.setText(2, guid);\r
+               child.setTextAlignment(1, ra.value());\r
+               addTopLevelItem(child);\r
+               \r
+               // Resort the list\r
+               resizeColumnToContents(0);\r
+       resizeColumnToContents(1);\r
+       sortItems(0, SortOrder.AscendingOrder);\r
+       }\r
+       \r
        public void load(List<Tag> tags) {\r
        Tag tag;\r
        List<QTreeWidgetItem> index = new ArrayList<QTreeWidgetItem>();\r