OSDN Git Service

Alter behavior of the tag line editor. If focus is lost while an item in the complete...
authorRandy Baumgarte <randy@fbn.cx>
Thu, 5 Aug 2010 17:35:23 +0000 (13:35 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Fri, 6 Aug 2010 16:07:17 +0000 (12:07 -0400)
src/cx/fbn/nevernote/gui/BrowserWindow.java
src/cx/fbn/nevernote/gui/TagLineEdit.java

index c4fb69e..0d640cd 100644 (file)
@@ -48,6 +48,7 @@ import com.trolltech.qt.core.QFile;
 import com.trolltech.qt.core.QFileSystemWatcher;\r
 import com.trolltech.qt.core.QIODevice;\r
 import com.trolltech.qt.core.QMimeData;\r
+import com.trolltech.qt.core.QModelIndex;\r
 import com.trolltech.qt.core.QUrl;\r
 import com.trolltech.qt.gui.QApplication;\r
 import com.trolltech.qt.gui.QCalendarWidget;\r
@@ -1293,7 +1294,12 @@ public class BrowserWindow extends QWidget {
        // Tag line has been modified by typing text\r
        @SuppressWarnings("unused")\r
        private void modifyTagsTyping() {\r
-\r
+               QModelIndex model = tagEdit.tagCompleter.currentIndex();\r
+               if (model != null) {\r
+                       tagEdit.completeText(tagEdit.currentCompleterSelection);\r
+               }\r
+               \r
+               \r
                String newTags = tagEdit.text();\r
                List<String> test = tagEdit.tagCompleter.getTagList();\r
                if (newTags.equalsIgnoreCase(saveTagList))\r
index f35cc92..50d5edf 100644 (file)
@@ -24,6 +24,7 @@ import java.util.List;
 \r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.core.QEvent;\r
+import com.trolltech.qt.core.QModelIndex;\r
 import com.trolltech.qt.gui.QLineEdit;\r
 \r
 import cx.fbn.nevernote.Global;\r
@@ -34,13 +35,16 @@ public class TagLineEdit extends QLineEdit {
        public Signal2<List<String>, String> text_changed = new Signal2<List<String>, String>();\r
        public TagLineCompleter tagCompleter;\r
        public Signal0 focusLost = new Signal0();\r
+       public String currentCompleterSelection;\r
        \r
        public TagLineEdit(List<Tag> allTags) {\r
                textChanged.connect(this, "textChanged(String)");\r
                tagCompleter = new TagLineCompleter(this);\r
                text_changed.connect(tagCompleter, "update(List, String)");\r
                tagCompleter.activated.connect(this, "completeText(String)");\r
+               tagCompleter.highlightedIndex.connect(this, "completerSelected(QModelIndex)");\r
                changed = false;\r
+               currentCompleterSelection = null;\r
        }\r
        \r
        public boolean hasChanged() {\r
@@ -67,11 +71,23 @@ public class TagLineEdit extends QLineEdit {
                }\r
        \r
                text_changed.emit(currentTags, prefix.trim());\r
+\r
                \r
        }\r
        \r
+       // This method is used to store the current selection from the completer.  It is\r
+       // saved until later in case focus is lost while one is selected, but Enter is never pressed.\r
        @SuppressWarnings("unused")\r
-       private void  completeText(String text){\r
+       private void completerSelected(QModelIndex model) {\r
+               currentCompleterSelection = null;\r
+               if (model == null)\r
+                       return;\r
+               tagCompleter.setCurrentRow(model.row());\r
+               currentCompleterSelection = tagCompleter.currentCompletion();\r
+               tagCompleter.setCurrentRow(model.row());\r
+       }\r
+       \r
+       public void  completeText(String text){\r
                int cursor_pos = cursorPosition();\r
                String before_text = text().substring(0,cursor_pos);\r
                String after_text = text().substring(cursor_pos);\r