OSDN Git Service

Cleanup selection behavior on tag & notebook trees.
authorRandy Baumgarte <randy@fbn.cx>
Fri, 17 Dec 2010 19:27:37 +0000 (14:27 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 19 Dec 2010 04:08:32 +0000 (23:08 -0500)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/gui/NotebookTreeWidget.java
src/cx/fbn/nevernote/gui/TagTreeWidget.java

index d41a740..1ba5dfe 100644 (file)
@@ -212,9 +212,7 @@ public class NeverNote extends QMainWindow{
     ApplicationLogger          logger;
     List<String>                       selectedNotebookGUIDs;          // List of notebook GUIDs
     List<String>                       selectedTagGUIDs;                       // List of selected tag GUIDs
-    String                                     previousSelectedTag;            // Tag that was selected last time
     List<String>                       selectedNoteGUIDs;                      // List of selected notes
-    String                                     previousSelectedNotebook;       // Notebook selected last time
     String                                     selectedSavedSearchGUID;        // Currently selected saved searches
     private final HashMap<String, ExternalBrowse>      externalWindows;        // Notes being edited by an external window;
     
@@ -1191,7 +1189,8 @@ public class NeverNote extends QMainWindow{
     // Setup the tree containing the user's notebooks.
     private void initializeNotebookTree() {       
        logger.log(logger.HIGH, "Entering NeverNote.initializeNotebookTree");
-       notebookTree.itemClicked.connect(this, "notebookTreeSelection()");
+//     notebookTree.itemClicked.connect(this, "notebookTreeSelection()");
+       notebookTree.selectionSignal.connect(this, "notebookTreeSelection()");
        listManager.notebookSignal.refreshNotebookTreeCounts.connect(notebookTree, "updateCounts(List, List)");
        logger.log(logger.HIGH, "Leaving NeverNote.initializeNotebookTree");
     }   
@@ -1214,65 +1213,24 @@ public class NeverNote extends QMainWindow{
        menuBar.notebookIconAction.setEnabled(true);
        menuBar.notebookStackAction.setEnabled(true);
        List<QTreeWidgetItem> selections = notebookTree.selectedItems();
-       QTreeWidgetItem currentSelection;
        selectedNotebookGUIDs.clear();
-       if (!Global.mimicEvernoteInterface) {
-               for (int i=0; i<selections.size(); i++) {
-                       currentSelection = selections.get(i);
-                       if (!currentSelection.text(2).equals("STACK"))
-                               selectedNotebookGUIDs.add(currentSelection.text(2));
-                       else {
-                               String stackName = currentSelection.text(0);
-                               for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
-                                       Notebook book = listManager.getNotebookIndex().get(j);
-                                       if (book.getStack()!=null && book.getStack().equalsIgnoreCase(stackName))
-                                               selectedNotebookGUIDs.add(book.getGuid());
-                               }
-                       }
-               }
-       
-               
-               // There is the potential for no notebooks to be selected if this 
-               // happens then we make it look like all notebooks were selecetd.
-               // If that happens, just select the "all notebooks"
-               selections = notebookTree.selectedItems();
-               if (selections.size()==0) {
-                       selectedNotebookGUIDs.clear();
-                       menuBar.notebookEditAction.setEnabled(false);
-                       menuBar.notebookDeleteAction.setEnabled(false);
-                       menuBar.notebookIconAction.setEnabled(false);
-               menuBar.notebookStackAction.setEnabled(false);
-               }
-               if (selectedNotebookGUIDs.size() == 1 && selectedNotebookGUIDs.get(0).equals(previousSelectedNotebook)) {
-                       previousSelectedNotebook = selectedNotebookGUIDs.get(0);
-                       previousSelectedNotebook = "";
-                       notebookTree.clearSelection();
-                       notebookTreeSelection();
-                       return;
-               }
-               if (selectedNotebookGUIDs.size() == 1)
-                       previousSelectedNotebook = selectedNotebookGUIDs.get(0);
-               if (selectedNotebookGUIDs.size() > 1) 
-                       previousSelectedNotebook = "";
-       } else {
-               String guid = "";
-               String stackName = "";
-               if (selections.size() > 0) {
-                       guid = (selections.get(0).text(2));
-                       stackName = selections.get(0).text(0);
-               }
-               if (!guid.equals("") && !guid.equals("STACK")) {
-                       selectedNotebookGUIDs.add(guid);
-                       menuBar.notebookIconAction.setEnabled(true);
-               }
-               else {
-                       menuBar.notebookIconAction.setEnabled(true);
-                               for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
-                                       Notebook book = listManager.getNotebookIndex().get(j);
-                                       if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
-                                               selectedNotebookGUIDs.add(book.getGuid());
-                               }
-               }
+               String guid = "";
+               String stackName = "";
+               if (selections.size() > 0) {
+               guid = (selections.get(0).text(2));
+               stackName = selections.get(0).text(0);
+       }
+       if (!guid.equals("") && !guid.equals("STACK")) {
+               selectedNotebookGUIDs.add(guid);
+               menuBar.notebookIconAction.setEnabled(true);
+       }
+       else {
+               menuBar.notebookIconAction.setEnabled(true);
+                       for (int j=0; j<listManager.getNotebookIndex().size(); j++) {
+                               Notebook book = listManager.getNotebookIndex().get(j);
+                               if (book.getStack() != null && book.getStack().equalsIgnoreCase(stackName))
+                                       selectedNotebookGUIDs.add(book.getGuid());
+                       }
        }
        listManager.setSelectedNotebooks(selectedNotebookGUIDs);
        listManager.loadNotesIndex();
@@ -1925,7 +1883,8 @@ public class NeverNote extends QMainWindow{
     private void initializeTagTree() {
        logger.log(logger.HIGH, "Entering NeverNote.initializeTagTree");
 //     tagTree.itemSelectionChanged.connect(this, "tagTreeSelection()");
-       tagTree.itemClicked.connect(this, "tagTreeSelection()");
+//     tagTree.itemClicked.connect(this, "tagTreeSelection()");
+       tagTree.selectionSignal.connect(this, "tagTreeSelection()");
        listManager.tagSignal.refreshTagTreeCounts.connect(tagTree, "updateCounts(List)");
        logger.log(logger.HIGH, "Leaving NeverNote.initializeTagTree");
     }
@@ -1956,17 +1915,6 @@ public class NeverNote extends QMainWindow{
                menuBar.tagDeleteAction.setEnabled(false);
                menuBar.tagIconAction.setEnabled(true);
        }
-       if (selectedTagGUIDs.size() == 1 && selectedTagGUIDs.get(0).equals(previousSelectedTag)) {
-               previousSelectedTag = selectedTagGUIDs.get(0);
-               previousSelectedTag = "";
-               tagTree.clearSelection();
-               tagTreeSelection();
-               return;
-       }
-       if (selectedTagGUIDs.size() == 1)
-               previousSelectedTag = selectedTagGUIDs.get(0);
-       if (selectedTagGUIDs.size() > 1) 
-               previousSelectedTag = "";
        listManager.setSelectedTags(selectedTagGUIDs);
        listManager.loadNotesIndex();
        noteIndexUpdated(false);
index 197b258..23f1bcf 100644 (file)
@@ -39,6 +39,7 @@ import com.trolltech.qt.gui.QDragMoveEvent;
 import com.trolltech.qt.gui.QHeaderView;\r
 import com.trolltech.qt.gui.QIcon;\r
 import com.trolltech.qt.gui.QMenu;\r
+import com.trolltech.qt.gui.QMouseEvent;\r
 import com.trolltech.qt.gui.QTreeWidget;\r
 import com.trolltech.qt.gui.QTreeWidgetItem;\r
 import com.trolltech.qt.gui.QTreeWidgetItem.ChildIndicatorPolicy;\r
@@ -57,11 +58,12 @@ public class NotebookTreeWidget extends QTreeWidget {
        private QAction                                 publishAction;\r
        private QAction                                 shareAction;\r
        public NoteSignal                               noteSignal;\r
+       public Signal0                                  selectionSignal;\r
+       private String                                  selectedNotebook;\r
        private HashMap<String, QIcon>  icons;\r
        private final DatabaseConnection                db;\r
        private final HashMap<String, QTreeWidgetItem>  stacks;\r
-//     private final QTreeWidgetItem                   previousMouseOver;\r
-//     private boolean                                 previousMouseOverWasSelected;\r
+       private boolean rightButtonClicked;\r
        \r
        public void setAddAction(QAction a) {\r
                addAction = a;\r
@@ -117,6 +119,10 @@ public class NotebookTreeWidget extends QTreeWidget {
 //             if (width>0)\r
 //                     setColumnWidth(0, width);\r
 //             previousMouseOver = new QTreeWidgetItem();\r
+               selectionSignal = new Signal0();\r
+               selectedNotebook = "";\r
+               rightButtonClicked = false;\r
+               itemClicked.connect(this, "itemClicked()");\r
        }\r
        \r
        public void selectNotebook(QTreeWidgetItem item) {\r
@@ -505,4 +511,30 @@ public class NotebookTreeWidget extends QTreeWidget {
                return target;\r
        }\r
 \r
+       \r
+       @SuppressWarnings("unused")\r
+       private void itemClicked() {\r
+               List<QTreeWidgetItem> selectedItem = selectedItems();\r
+               if (selectedItem.size() == 1) {\r
+                       if (selectedItem.get(0).text(0).equalsIgnoreCase(selectedNotebook) && \r
+                                       !Global.mimicEvernoteInterface && !rightButtonClicked) {\r
+                               selectedNotebook = "";\r
+                               clearSelection();\r
+                       } else {\r
+                               selectedNotebook = selectedItem.get(0).text(0);\r
+                       }\r
+                       \r
+               }\r
+               selectionSignal.emit();\r
+       }\r
+\r
+       \r
+       @Override\r
+       public void mousePressEvent(QMouseEvent e) {\r
+               if (e.button() == Qt.MouseButton.RightButton)\r
+                       rightButtonClicked = true;\r
+               else\r
+                       rightButtonClicked = false;\r
+               super.mousePressEvent(e);\r
+       }\r
 }\r
index 1b215bb..f3402f2 100644 (file)
@@ -42,6 +42,7 @@ import com.trolltech.qt.gui.QDragMoveEvent;
 import com.trolltech.qt.gui.QHeaderView;\r
 import com.trolltech.qt.gui.QIcon;\r
 import com.trolltech.qt.gui.QMenu;\r
+import com.trolltech.qt.gui.QMouseEvent;\r
 import com.trolltech.qt.gui.QTreeWidget;\r
 import com.trolltech.qt.gui.QTreeWidgetItem;\r
 \r
@@ -61,6 +62,9 @@ public class TagTreeWidget extends QTreeWidget {
        private boolean showAllTags;\r
        private final DatabaseConnection db;\r
        private HashMap<String, QIcon>  icons;\r
+       public Signal0 selectionSignal;\r
+       public String selectedTag;\r
+       private boolean rightButtonClicked;\r
        \r
        \r
        public TagTreeWidget(DatabaseConnection d) {\r
@@ -75,6 +79,7 @@ public class TagTreeWidget extends QTreeWidget {
                header().setResizeMode(1, QHeaderView.ResizeMode.Stretch);\r
                header().setMovable(false);\r
                db = d;\r
+               selectionSignal = new Signal0();\r
                tagSignal = new TagSignal();\r
                noteSignal = new NoteSignal();\r
                setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);\r
@@ -82,6 +87,8 @@ public class TagTreeWidget extends QTreeWidget {
 //     setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);\r
        setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection);\r
        \r
+       selectedTag = "";\r
+       itemClicked.connect(this, "itemClicked()");\r
                int width = Global.getColumnWidth("tagTreeName");\r
                if (width>0)\r
                        setColumnWidth(0, width);\r
@@ -395,4 +402,30 @@ public class TagTreeWidget extends QTreeWidget {
                        }\r
                }\r
        }\r
+\r
+       @SuppressWarnings("unused")\r
+       private void itemClicked() {\r
+               \r
+               List<QTreeWidgetItem> selectedItem = selectedItems();\r
+               if (selectedItem.size() == 1) {\r
+                       if (selectedItem.get(0).text(0).equalsIgnoreCase(selectedTag) && !rightButtonClicked) {\r
+                               selectedTag = "";\r
+                               clearSelection();\r
+                       } else {\r
+                               selectedTag = selectedItem.get(0).text(0);\r
+                       }\r
+                       \r
+               }\r
+               selectionSignal.emit();\r
+       }\r
+\r
+       \r
+       @Override\r
+       public void mousePressEvent(QMouseEvent e) {\r
+               if (e.button() == Qt.MouseButton.RightButton)\r
+                       rightButtonClicked = true;\r
+               else\r
+                       rightButtonClicked = false;\r
+               super.mousePressEvent(e);\r
+       }\r
 }\r