OSDN Git Service

Add automatic wildcard option.
authorRandy Baumgarte <randy@fbn.cx>
Tue, 13 Sep 2011 12:13:36 +0000 (08:13 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Tue, 13 Sep 2011 12:13:36 +0000 (08:13 -0400)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/dialog/ConfigIndexPage.java
src/cx/fbn/nevernote/sql/REnSearch.java

index 2e8da2d..a6646c0 100644 (file)
@@ -62,7 +62,7 @@ import cx.fbn.nevernote.utilities.Pair;
 \r
 public class Global {\r
        // Set current version and the known versions.\r
-       public static String version = "1.0.2";\r
+       public static String version = "1.0.4";\r
        public static String[] validVersions = {"1.0", "0.99", "0.98", "0.97", "0.96"};\r
     public static String username = ""; \r
     public static String password = "";     \r
@@ -1984,6 +1984,29 @@ public class Global {
                settings.setValue("includeTagChildren", value);\r
                settings.endGroup();    \r
     }\r
+    \r
+    // If we should automatically wildcard searches\r
+    public static boolean automaticWildcardSearches() {\r
+               settings.beginGroup("General");\r
+               try {\r
+                       String value = (String)settings.value("automaticWildcard", "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("automaticWildcard", false);\r
+                       settings.endGroup();\r
+                       return value;\r
+               }\r
+\r
+    }\r
+    public static void setAutomaticWildcardSearches(boolean value) {\r
+               settings.beginGroup("General");\r
+               settings.setValue("automaticWildcard", value);\r
+               settings.endGroup();    \r
+    }\r
 \r
 }\r
 \r
index 91093b5..9be08dc 100644 (file)
@@ -176,6 +176,7 @@ public class ConfigDialog extends QDialog {
                Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
                Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
                Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
+               Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
                Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
                Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
                \r
index 4669a23..7b3db98 100644 (file)
@@ -44,6 +44,7 @@ public class ConfigIndexPage extends QWidget {
        private final QCheckBox indexAttachmentsLocally;\r
        private final QCheckBox indexImageRecognition;\r
        private final QCheckBox indexTitle;\r
+       private final QCheckBox automaticWildcard;\r
        private final QLineEdit specialStrip;\r
        private final QCheckBox indexBody;\r
        private final QLineEdit regexEdit;\r
@@ -75,6 +76,9 @@ public class ConfigIndexPage extends QWidget {
                indexImageRecognition = new QCheckBox(tr("Index Image Recognition"));\r
                indexImageRecognition.setChecked(Global.indexImageRecognition());\r
                \r
+               automaticWildcard = new QCheckBox(tr("Automatically Wildcard All Searches"));\r
+               automaticWildcard.setChecked(Global.automaticWildcardSearches());\r
+               \r
                specialStrip = new QLineEdit();\r
                specialStrip.setText(Global.getSpecialIndexCharacters());\r
                \r
@@ -83,6 +87,7 @@ public class ConfigIndexPage extends QWidget {
                attachmentLayout.addWidget(indexTitle);\r
                attachmentLayout.addWidget(indexAttachmentsLocally);\r
                attachmentLayout.addWidget(indexImageRecognition);\r
+               attachmentLayout.addWidget(automaticWildcard);\r
                \r
                QHBoxLayout specialCharLayout = new QHBoxLayout();\r
                specialCharLayout.addWidget(new QLabel(tr("Special Word Characters")));\r
@@ -145,6 +150,9 @@ public class ConfigIndexPage extends QWidget {
        public boolean getIndexImageRecognition() {\r
                return indexImageRecognition.isChecked();\r
        }\r
+       public boolean getAutomaticWildcardSearches() {\r
+               return automaticWildcard.isChecked();\r
+       }\r
        \r
        //*****************************************\r
        //* Word length get/set methods \r
index 3fbbaa8..c6802e6 100644 (file)
@@ -33,6 +33,7 @@ import com.evernote.edam.type.Note;
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Tag;\r
 \r
+import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 \r
@@ -396,10 +397,19 @@ public class REnSearch {
                                searchPhrase=true;\r
                                searchPhrases.add(word.toLowerCase());\r
                        }\r
-                       if (!searchPhrase && pos < 0) \r
-                               if (word != null && word.length() > 0)\r
+                       if (!searchPhrase && pos < 0) {\r
+                               if (word != null && word.length() > 0 && !Global.automaticWildcardSearches())\r
                                        getWords().add(word); \r
+                               if (word != null && word.length() > 0 && Global.automaticWildcardSearches()) {\r
+                                       String wildcardWord = word;\r
+                                       if (!wildcardWord.startsWith("*"))\r
+                                               wildcardWord = "*"+wildcardWord;\r
+                                       if (!wildcardWord.endsWith("*"))\r
+                                               wildcardWord = wildcardWord+"*";\r
+                                       getWords().add(wildcardWord); \r
+                               }\r
 //                             getWords().add("*"+word+"*");           //// WILDCARD\r
+                       }\r
                        if (word.startsWith("intitle:")) \r
                                intitle.add("*"+word+"*");\r
                        if (word.startsWith("-intitle:")) \r