OSDN Git Service

Correct tag sort order on note list.
authorRandy Baumgarte <randy@fbn.cx>
Tue, 27 Mar 2012 10:22:01 +0000 (06:22 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Tue, 27 Mar 2012 10:22:01 +0000 (06:22 -0400)
src/cx/fbn/nevernote/gui/NoteTableModel.java
src/cx/fbn/nevernote/sql/NoteTable.java

index 3b8187e..c92e927 100644 (file)
@@ -1,5 +1,6 @@
 package cx.fbn.nevernote.gui;\r
 \r
+import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -154,9 +155,24 @@ public class NoteTableModel extends QAbstractTableModel {
                }\r
                if (col == Global.noteTableTagPosition) {\r
                        String tags = new String();\r
+                       List<String> tagNames = new ArrayList<String>();\r
                        for (int i=0; i<note.getTagNamesSize(); i++) {\r
-                               tags = tags + note.getTagNames().get(i);\r
-                               if (i!=note.getTagNamesSize()-1)\r
+                               tagNames.add(note.getTagNames().get(i));\r
+                       }\r
+                       \r
+                       while (tagNames.size() > 0) {\r
+                               int position = 0;\r
+                               for (int i=0; i<tagNames.size()-1; i++) {\r
+                                       String name1 = tagNames.get(i);\r
+                                       String name2 = tagNames.get(i+1);\r
+                                       if (name1.compareTo(name2) > 0) {\r
+                                               position = i+1;\r
+                                       }\r
+                               }\r
+                               \r
+                               tags = tags + tagNames.get(position);\r
+                               tagNames.remove(position);\r
+                               if (tagNames.size() > 0)\r
                                        tags = tags + ", ";\r
                        }\r
                        return tags;\r
index 4476c6f..54da38b 100644 (file)
@@ -309,18 +309,20 @@ public class NoteTable {
                na.setContentClass(query.valueString(16));\r
                \r
                if (loadTags) {\r
-                       n.setTagGuids(noteTagsTable.getNoteTags(n.getGuid()));\r
+                       List<String> tagGuids = noteTagsTable.getNoteTags(n.getGuid());\r
                        List<String> tagNames = new ArrayList<String>();\r
                        TagTable tagTable = db.getTagTable();\r
-                       for (int i=0; i<n.getTagGuids().size(); i++) {\r
-                               String currentGuid = n.getTagGuids().get(i);\r
+                       for (int i=0; i<tagGuids.size(); i++) {\r
+                               String currentGuid = tagGuids.get(i);\r
                                Tag tag = tagTable.getTag(currentGuid);\r
                                if (tag.getName() != null)\r
                                        tagNames.add(tag.getName());\r
                                else\r
                                        tagNames.add("");\r
                        }\r
+\r
                        n.setTagNames(tagNames);\r
+                       n.setTagGuids(tagGuids);                \r
                }\r
                \r
                if (loadContent) {\r