OSDN Git Service

Add ability to include children of tags when selecting a parent tag.
authorRandy Baumgarte <randy@fbn.cx>
Sat, 27 Aug 2011 17:24:58 +0000 (13:24 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sat, 27 Aug 2011 17:24:58 +0000 (13:24 -0400)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/ConfigAppearancePage.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/utilities/ListManager.java

index 900ef9b..4f6d009 100644 (file)
@@ -1886,7 +1886,8 @@ public class Global {
     }\r
 \r
     //*****************************************************************************\r
-    // Control how tag selection behaves (should they be "and" or "or" selections\r
+    // Control if a user receives a warning when trying to create a note-to-note link\r
+    // when the DB is not synchronized.\r
     //*****************************************************************************\r
     public static boolean bypassSynchronizationWarning() {\r
                settings.beginGroup("User");\r
@@ -1961,6 +1962,28 @@ public class Global {
                return null;\r
     }\r
 \r
+    // If we should automatically select the children of any tag\r
+    public static boolean includeTagChildren() {\r
+               settings.beginGroup("General");\r
+               try {\r
+                       String value = (String)settings.value("includeTagChildren", "false");\r
+                       settings.endGroup();\r
+                       if (value.equals("true"))\r
+                               return true;\r
+                       else\r
+                               return false;\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Boolean value = (Boolean) settings.value("includeTagChildren", false);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+\r
+    }\r
+    public static void setIncludeTagChildren(boolean value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("includeTagChildren", value);\r
+               settings.endGroup();    \r
+    }\r
 \r
 }\r
 \r
index 1280408..7566f00 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of NixNote 
 * This file is part of NixNote 
  * Copyright 2009 Randy Baumgarte
  * 
  * This file may be licensed under the terms of of the
index ba99e54..da6e660 100644 (file)
@@ -22,6 +22,7 @@ package cx.fbn.nevernote.dialog;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
+import com.trolltech.qt.core.Qt;\r
 import com.trolltech.qt.gui.QApplication;\r
 import com.trolltech.qt.gui.QCheckBox;\r
 import com.trolltech.qt.gui.QComboBox;\r
@@ -29,6 +30,7 @@ import com.trolltech.qt.gui.QFormLayout;
 import com.trolltech.qt.gui.QGroupBox;\r
 import com.trolltech.qt.gui.QHBoxLayout;\r
 import com.trolltech.qt.gui.QLabel;\r
+import com.trolltech.qt.gui.QScrollArea;\r
 import com.trolltech.qt.gui.QSpinBox;\r
 import com.trolltech.qt.gui.QStyleFactory;\r
 import com.trolltech.qt.gui.QVBoxLayout;\r
@@ -52,6 +54,7 @@ public class ConfigAppearancePage extends QWidget {
        private final QCheckBox mimicEvernote;\r
        private final QCheckBox startMinimized;\r
        private final QCheckBox minimizeOnClose;\r
+       private final QCheckBox includeTagChildren;\r
        private final QSpinBox autoSaveInterval;\r
        \r
        private final List<String> tformats;\r
@@ -143,6 +146,7 @@ public class ConfigAppearancePage extends QWidget {
                checkForUpdates = new QCheckBox(tr("Check For Updates At Startup"));\r
                newNoteWithTags = new QCheckBox(tr("Create New Notes With Selected Tags"));\r
                anyTagSelection = new QCheckBox(tr("Display Notes Matching Any Selected Tags"));\r
+               includeTagChildren = new QCheckBox(tr("Include Children In Tag Selection"));\r
                \r
                QHBoxLayout autoSaveLayout = new QHBoxLayout();\r
                autoSaveLayout.addWidget(new QLabel(tr("Automatic Save Interval (in Minutes)")));\r
@@ -151,22 +155,38 @@ public class ConfigAppearancePage extends QWidget {
                autoSaveInterval.setMaximum(1440);\r
                autoSaveInterval.setMinimum(0);\r
                \r
-               QVBoxLayout mainLayout = new QVBoxLayout();\r
+               QVBoxLayout mainLayout = new QVBoxLayout(this);\r
                mainLayout.addWidget(styleGroup);\r
                mainLayout.addWidget(datetimeGroup);\r
                mainLayout.addLayout(autoSaveLayout);\r
                mainLayout.addWidget(tagBehaviorGroup);\r
-               mainLayout.addWidget(mimicEvernote); \r
-               mainLayout.addWidget(showTrayIcon);\r
-               mainLayout.addWidget(minimizeOnClose);\r
-               mainLayout.addWidget(startMinimized);\r
-               mainLayout.addWidget(showSplashScreen);\r
-               mainLayout.addWidget(verifyDelete);\r
-               mainLayout.addWidget(pdfPreview);\r
-               mainLayout.addWidget(newNoteWithTags);\r
-               mainLayout.addWidget(anyTagSelection);\r
-               mainLayout.addWidget(checkForUpdates);\r
-               mainLayout.addStretch(1);\r
+               \r
+               \r
+               QVBoxLayout checkboxLayout = new QVBoxLayout();\r
+               checkboxLayout.addWidget(mimicEvernote); \r
+               checkboxLayout.addWidget(showTrayIcon);\r
+               checkboxLayout.addWidget(minimizeOnClose);\r
+               checkboxLayout.addWidget(startMinimized);\r
+               checkboxLayout.addWidget(showSplashScreen);\r
+               checkboxLayout.addWidget(verifyDelete);\r
+               checkboxLayout.addWidget(pdfPreview);\r
+               checkboxLayout.addWidget(newNoteWithTags);\r
+               checkboxLayout.addWidget(anyTagSelection);\r
+               checkboxLayout.addWidget(includeTagChildren);\r
+               checkboxLayout.addWidget(checkForUpdates);\r
+               checkboxLayout.addStretch(1);\r
+\r
+               \r
+               QWidget checkBoxGroup = new QWidget();\r
+               checkBoxGroup.setLayout(checkboxLayout);\r
+\r
+               QScrollArea scrollArea = new QScrollArea();\r
+               scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded);\r
+               scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded);\r
+               scrollArea.setWidgetResizable(true);\r
+               scrollArea.setWidget(checkBoxGroup);\r
+\r
+               mainLayout.addWidget(scrollArea);\r
                setLayout(mainLayout);\r
                \r
                showTrayIcon.clicked.connect(this, "showTrayIconClicked(Boolean)");\r
@@ -314,12 +334,10 @@ public class ConfigAppearancePage extends QWidget {
        //********************************************\r
        //* Listeners for palette & style changes\r
        //********************************************\r
-       \r
        public void styleSelected(String style) {\r
                QApplication.setStyle(style);\r
                QApplication.setPalette(QApplication.style().standardPalette());\r
-       }\r
-       \r
+       }       \r
        public void standardPaletteChanged() {\r
                if (standardPalette.isChecked())\r
                        QApplication.setPalette(QApplication.style().standardPalette());\r
@@ -399,4 +417,16 @@ public class ConfigAppearancePage extends QWidget {
                anyTagSelection.setChecked(val);\r
        }\r
 \r
+\r
+       //*****************************************\r
+       //* Include a tag's child when selecting a parent\r
+       //*****************************************\r
+       public boolean getIncludeTagChildren() {\r
+               return includeTagChildren.isChecked();\r
+       }\r
+       public void setIncludeTagChildren(boolean val) {\r
+               includeTagChildren.setChecked(val);\r
+       }\r
+\r
+\r
 }\r
index 3ce5ac6..91093b5 100644 (file)
@@ -177,6 +177,7 @@ public class ConfigDialog extends QDialog {
                Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
                Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
                Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
+               Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
                \r
        FileOutputStream out = null;\r
                try {\r
@@ -341,6 +342,7 @@ public class ConfigDialog extends QDialog {
                appearancePage.setShowSplashScreen(Global.isWindowVisible("SplashScreen"));\r
                appearancePage.setTagBehavior(Global.tagBehavior());\r
                appearancePage.setMinimizeOnClose(Global.minimizeOnClose());\r
+               appearancePage.setIncludeTagChildren(Global.includeTagChildren());\r
                \r
                indexPage.setRegex(Global.getWordRegex());\r
                indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
index b64e0cb..323a861 100644 (file)
@@ -813,6 +813,36 @@ public class ListManager  {
                logger.log(logger.HIGH, "Leaving ListManager.updateTagGuid");\r
 \r
        }\r
+       // Find all children for a tag\r
+       public List<Tag> findAllChildren(String guid) {\r
+               List<Tag> tags = new ArrayList<Tag>();\r
+               return findAllChildrenRecursive(guid, tags);\r
+       }\r
+       public List<Tag> findAllChildrenRecursive(String guid, List<Tag> tags) {\r
+               \r
+               // Start looping through the tags.  If we find a tag which has a parent that\r
+               // matches guid, then we add it to the list of tags & search for its children.\r
+               for (int i=0; i<getTagIndex().size(); i++) {\r
+                       if (getTagIndex().get(i).getParentGuid() != null && getTagIndex().get(i).getParentGuid().equals(guid)) {\r
+                               tags.add(getTagIndex().get(i));\r
+                               tags = findAllChildrenRecursive(getTagIndex().get(i).getGuid(), tags);\r
+                       }\r
+               }\r
+               return tags;\r
+       }\r
+       // Give a list of tags, does any of them match a child tag?\r
+       public boolean checkNoteForChildTags(String guid, List<String> noteTags) {\r
+               boolean returnValue = false;\r
+               List<Tag> children = findAllChildren(guid);\r
+               for (int i=0; i<noteTags.size(); i++) {\r
+                       String noteTag = noteTags.get(i);\r
+                       for (int j=0; j<children.size(); j++) {\r
+                               if (noteTag.equals(children.get(j).getGuid()))\r
+                                       return true;\r
+                       }\r
+               }\r
+               return returnValue;\r
+       }\r
 \r
 \r
        //************************************************************************************\r
@@ -1054,24 +1084,44 @@ public class ListManager  {
                return good;\r
        }\r
        private boolean filterByTag(List<String> noteTags) {\r
+               // If either the note has no tags or there are\r
+               // no selected tags, then any note is good.\r
                if (noteTags == null || selectedTags == null)\r
                        return true;\r
                \r
+               // If there are no tags selected, then any note  is good\r
                if (selectedTags.size() == 0) \r
                        return true;\r
                \r
+               // If ALL tags must be matched, then check ALL note tags, \r
+               // otherwise we match on any criteria.\r
                if (!Global.anyTagSelectionMatch()) {\r
                        for (int i=0; i<selectedTags.size(); i++) {\r
                                String selectedGuid = selectedTags.get(i);\r
-                               if (!noteTags.contains(selectedGuid))\r
-                                       return false;\r
+                               boolean childMatch = false;\r
+                               // If we should include children in the results\r
+                               if (Global.includeTagChildren()) {\r
+                                       childMatch = checkNoteForChildTags(selectedGuid, noteTags);\r
+                                       // Do we have a match with this tag or any children\r
+                                       if (!noteTags.contains(selectedGuid)&& !childMatch)\r
+                                               return false;\r
+                               } else {\r
+                                       // Does this note have a matching tag\r
+                                       if (!noteTags.contains(selectedGuid))\r
+                                               return false;\r
+                               }\r
                        }\r
                        return true;\r
                } else {\r
+                       // Any match is displayed.\r
                        for (int i=0; i<selectedTags.size(); i++) {\r
                                String selectedGuid = selectedTags.get(i);\r
+                               // If we have a simple match, then we're good\r
                                if (noteTags.contains(selectedGuid))\r
                                                return true;\r
+                               // If we have a match with one of the children tags && we should include child tags\r
+                               if (Global.includeTagChildren() && checkNoteForChildTags(selectedGuid, noteTags))\r
+                                       return true;\r
                        }\r
                        return false;\r
                }\r