OSDN Git Service

Modify tag completion to be a little less ugly and remove the potential for duplicati...
authorRandy Baumgarte <randy@fbn.cx>
Thu, 19 Aug 2010 14:55:00 +0000 (10:55 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 22 Aug 2010 22:48:37 +0000 (18:48 -0400)
src/cx/fbn/nevernote/gui/BrowserWindow.java

index 8a429d5..077c906 100644 (file)
@@ -28,6 +28,7 @@ import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Calendar;\r
+import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.GregorianCalendar;\r
 import java.util.HashMap;\r
@@ -1295,19 +1296,34 @@ public class BrowserWindow extends QWidget {
        // Tag line has been modified by typing text\r
        @SuppressWarnings("unused")\r
        private void modifyTagsTyping() {\r
+               String completionText = "";\r
                if (tagEdit.currentCompleterSelection != null && !tagEdit.currentCompleterSelection.equals("")) {\r
-                       tagEdit.completeText(tagEdit.currentCompleterSelection);\r
+                       completionText = tagEdit.currentCompleterSelection;\r
+                       tagEdit.currentCompleterSelection = "";\r
                }\r
                \r
-               \r
-               String newTags = tagEdit.text();\r
-               List<String> test = tagEdit.tagCompleter.getTagList();\r
-               if (newTags.equalsIgnoreCase(saveTagList))\r
+               if (tagEdit.text().equalsIgnoreCase(saveTagList))\r
                        return;\r
 \r
                // We know something has changed...\r
                String oldTagArray[] = saveTagList.split(Global.tagDelimeter);\r
-               String newTagArray[] = newTags.split(Global.tagDelimeter);\r
+               String newTagArray[] = tagEdit.text().split(Global.tagDelimeter);\r
+               \r
+               if (!completionText.equals("") && newTagArray.length > 0) {\r
+                       newTagArray[newTagArray.length-1] = completionText;\r
+               }\r
+               // Remove any potential duplicates from the new list\r
+               for (int i=0; i<newTagArray.length; i++) {\r
+                       boolean foundOnce = false;\r
+                       for (int j=0; j<newTagArray.length; j++) {\r
+                               if (newTagArray[j].equalsIgnoreCase(newTagArray[i])) {\r
+                                       if (!foundOnce) {\r
+                                               foundOnce = true;\r
+                                       } else\r
+                                               newTagArray[j] = "";\r
+                               }\r
+                       }\r
+               }\r
 \r
                List<String> newTagList = new ArrayList<String>();\r
                List<String> oldTagList = new ArrayList<String>();\r
@@ -1319,6 +1335,18 @@ public class BrowserWindow extends QWidget {
                        if (!newTagArray[i].trim().equals(""))\r
                                newTagList.add(newTagArray[i]);\r
 \r
+               // Let's cleanup the appearance of the tag list\r
+               Collections.sort(newTagList);\r
+               String newDisplay = "";\r
+               for (int i=0; i<newTagList.size(); i++) {\r
+                       newDisplay = newDisplay+newTagList.get(i);\r
+                       if (i<newTagList.size()-1)\r
+                               newDisplay = newDisplay+", ";\r
+               }\r
+               tagEdit.blockSignals(true);\r
+               tagEdit.setText(newDisplay);\r
+               tagEdit.blockSignals(false);\r
+               \r
                // We now have lists of the new & old. Remove duplicates. If all\r
                // are removed from both then nothing has really changed\r
                for (int i = newTagList.size() - 1; i >= 0; i--) {\r
@@ -1335,13 +1363,14 @@ public class BrowserWindow extends QWidget {
 \r
                if (oldTagList.size() != 0 || newTagList.size() != 0) {\r
                        currentTags.clear();\r
+                       newTagArray = tagEdit.text().split(Global.tagDelimeter);\r
                        for (int i = 0; i < newTagArray.length; i++)\r
                                if (!newTagArray[i].trim().equals(""))\r
                                        currentTags.add(newTagArray[i].trim());\r
 \r
                        noteSignal.tagsChanged.emit(currentNote.getGuid(), currentTags);\r
                }\r
-\r
+               \r
        }\r
 \r
        // Tab button was pressed\r
@@ -1634,7 +1663,6 @@ public class BrowserWindow extends QWidget {
                                icon = findIcon(type[0]);\r
                        if (icon.equals("attachment.png"))\r
                                icon = findIcon(url.substring(url.lastIndexOf(".")+1));\r
-                       StringBuffer imageBuffer = new StringBuffer();\r
                        String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));\r
 \r
                        logger.log(logger.EXTREME, "Creating resource ");\r
@@ -1853,6 +1881,7 @@ public class BrowserWindow extends QWidget {
                noteSignal.authorChanged.emit(currentNote.getGuid(), authorText.text());\r
        }\r
        \r
+       @SuppressWarnings("unused")\r
        private void geoBoxChanged() {\r
                int index = geoBox.currentIndex();\r
                geoBox.setCurrentIndex(0);\r