OSDN Git Service

Alter behavior of the tag line editor. If focus is lost while an item in the complete...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / TagLineEdit.java
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