OSDN Git Service

Fix tag line editor strangeness and add spell config dialog.
authorRandy Baumgarte <randy@fbn.cx>
Thu, 7 Oct 2010 11:38:58 +0000 (07:38 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 10 Oct 2010 14:03:59 +0000 (10:03 -0400)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/dialog/ConfigSpellPage.java [new file with mode: 0644]
src/cx/fbn/nevernote/gui/BrowserWindow.java
src/cx/fbn/nevernote/gui/TagLineEdit.java
src/cx/fbn/nevernote/icons/dictionary.png [new file with mode: 0644]

index 02ec7e8..0cdf3b9 100644 (file)
@@ -33,6 +33,7 @@ import com.evernote.edam.type.Accounting;
 import com.evernote.edam.type.PrivilegeLevel;\r
 import com.evernote.edam.type.User;\r
 import com.evernote.edam.type.UserAttributes;\r
+import com.swabunga.spell.engine.Configuration;\r
 import com.trolltech.qt.core.QByteArray;\r
 import com.trolltech.qt.core.QSettings;\r
 import com.trolltech.qt.gui.QPalette;\r
@@ -1044,6 +1045,31 @@ public class Global {
            return buf.toString();              \r
        }\r
 \r
+    public static boolean getSpellSetting(String value) {\r
+               settings.beginGroup("Spell");\r
+               String text = (String)settings.value(value, "");\r
+               settings.endGroup();\r
+               if (text.equalsIgnoreCase("true"))\r
+                       return true;\r
+               if (text.equalsIgnoreCase("false"))\r
+                       return false;\r
+               if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREDIGITWORDS))\r
+                       return true;\r
+               if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREINTERNETADDRESSES))\r
+                       return true;\r
+               if (value.equalsIgnoreCase(Configuration.SPELL_IGNOREUPPERCASE))\r
+                       return true;\r
+               return false;\r
+    }\r
+    public static void setSpellSetting(String setting, boolean val) {\r
+               settings.beginGroup("Spell");\r
+               if (val)\r
+                       settings.setValue(setting, "true");\r
+               else\r
+                       settings.setValue(setting, "false");\r
+               settings.endGroup();\r
+    }\r
+       \r
        \r
        // What to do with inactive tags?\r
        public static String tagBehavior() {\r
@@ -1093,7 +1119,6 @@ public class Global {
                startTraceTime = null;\r
        }\r
 \r
-\r
     public static FileManager getFileManager() {\r
         return fileManager;\r
     }\r
index 339daba..77ae85e 100644 (file)
@@ -46,6 +46,7 @@ public class ConfigDialog extends QDialog {
        private final ConfigConnectionPage              connectionPage;\r
        private final ConfigDebugPage                   debugPage;\r
        private final ConfigAppearancePage              appearancePage;\r
+       private final ConfigSpellPage                   spellPage;\r
        private final ConfigIndexPage                   indexPage;\r
        \r
        public ConfigDialog(QWidget parent) {\r
@@ -62,8 +63,10 @@ public class ConfigDialog extends QDialog {
                appearancePage = new ConfigAppearancePage(this);\r
                indexPage = new ConfigIndexPage(this);\r
                debugPage = new ConfigDebugPage(this);\r
+               spellPage = new ConfigSpellPage(this);\r
                pagesWidget.addWidget(appearancePage);\r
                pagesWidget.addWidget(indexPage);\r
+               pagesWidget.addWidget(spellPage);\r
                pagesWidget.addWidget(connectionPage);\r
                pagesWidget.addWidget(debugPage);\r
                \r
@@ -208,6 +211,12 @@ public class ConfigDialog extends QDialog {
                indexButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
                indexButton.setIcon(new QIcon(iconPath+"search_config.jpg"));\r
 \r
+               QListWidgetItem spellButton = new QListWidgetItem(contentsWidget);\r
+               spellButton.setText(tr("Spell Check"));\r
+               spellButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
+               spellButton.setFlags(ItemFlag.ItemIsSelectable, ItemFlag.ItemIsEnabled);\r
+               spellButton.setIcon(new QIcon(iconPath+"dictionary.png"));\r
+\r
                QListWidgetItem configButton = new QListWidgetItem(contentsWidget);\r
                configButton.setText(tr("Connection"));\r
                configButton.setTextAlignment(AlignmentFlag.AlignHCenter.value());\r
diff --git a/src/cx/fbn/nevernote/dialog/ConfigSpellPage.java b/src/cx/fbn/nevernote/dialog/ConfigSpellPage.java
new file mode 100644 (file)
index 0000000..f1f9120
--- /dev/null
@@ -0,0 +1,112 @@
+/*\r
+ * This file is part of NeverNote \r
+ * Copyright 2009 Randy Baumgarte\r
+ * \r
+ * This file may be licensed under the terms of of the\r
+ * GNU General Public License Version 2 (the ``GPL'').\r
+ *\r
+ * Software distributed under the License is distributed\r
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
+ * express or implied. See the GPL for the specific language\r
+ * governing rights and limitations.\r
+ *\r
+ * You should have received a copy of the GPL along with this\r
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
+ * or write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ *\r
+*/\r
+\r
+package cx.fbn.nevernote.dialog;\r
+\r
+import com.swabunga.spell.engine.Configuration;\r
+import com.trolltech.qt.gui.QCheckBox;\r
+import com.trolltech.qt.gui.QVBoxLayout;\r
+import com.trolltech.qt.gui.QWidget;\r
+\r
+import cx.fbn.nevernote.Global;\r
+\r
+public class ConfigSpellPage extends QWidget {\r
+       \r
+\r
+       private final QCheckBox ignoreDigitWords;\r
+       private final QCheckBox ignoreInternetAddresses;\r
+       private final QCheckBox ignoreMixedCase;\r
+       private final QCheckBox ignoreUpperCase;\r
+       private final QCheckBox ignoreSentenceCapitalization;\r
+\r
+       \r
+       public ConfigSpellPage(QWidget parent) {        \r
+               ignoreDigitWords = new QCheckBox(tr("Ignore words with numbers in them"));\r
+               ignoreInternetAddresses = new QCheckBox(tr("Ignore internet addresses (i.e. http:// ftp://)"));\r
+               ignoreMixedCase = new QCheckBox(tr("Ignore words with upper and lower cased letters"));\r
+               ignoreUpperCase = new QCheckBox(tr("Ignore upper cased words"));\r
+               ignoreSentenceCapitalization = new QCheckBox(tr("Ignore that sentences should begin with a capital letter"));\r
+               \r
+               setIgnoreDigitWords(Global.getSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS));\r
+               setIgnoreInternetAddresses(Global.getSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES));\r
+               setIgnoreMixedCase(Global.getSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE));\r
+               setIgnoreUpperCase(Global.getSpellSetting(Configuration.SPELL_IGNOREUPPERCASE));\r
+               setIgnoreSentenceCapitalization(Global.getSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION));\r
+               \r
+               QVBoxLayout mainLayout = new QVBoxLayout();\r
+               mainLayout.addWidget(ignoreDigitWords);\r
+               mainLayout.addWidget(ignoreInternetAddresses);\r
+               mainLayout.addWidget(ignoreMixedCase);\r
+               mainLayout.addWidget(ignoreUpperCase);\r
+               mainLayout.addWidget(ignoreSentenceCapitalization);\r
+               mainLayout.addStretch(1);\r
+               setLayout(mainLayout);\r
+       }\r
+       \r
+       //****************************************\r
+       //* Getter/Setter for ignore digit words *\r
+       //****************************************\r
+       public boolean getIgnoreDigitWords() {\r
+               return ignoreDigitWords.isChecked();\r
+       }\r
+       public void setIgnoreDigitWords(boolean value) {\r
+               ignoreDigitWords.setChecked(value);\r
+       }\r
+       \r
+       //***********************************************\r
+       //* Getter/Setter for ignore internet addresses *\r
+       //***********************************************\r
+       public boolean getIgnoreInternetAddresses() {\r
+               return ignoreInternetAddresses.isChecked();\r
+       }\r
+       public void setIgnoreInternetAddresses(boolean value) {\r
+               ignoreInternetAddresses.setChecked(value);\r
+       }\r
+       \r
+       //*********************************************\r
+       //* Getter/Setter for ignore Mixed Case words *\r
+       //*********************************************\r
+       public boolean getIgnoreMixedCase() {\r
+               return ignoreMixedCase.isChecked();\r
+       }\r
+       public void setIgnoreMixedCase(boolean value) {\r
+               ignoreMixedCase.setChecked(value);\r
+       }\r
+       \r
+       //*********************************************\r
+       //* Getter/Setter for ignore Mixed Case words *\r
+       //*********************************************\r
+       public boolean getUpperMixedCase() {\r
+               return ignoreUpperCase.isChecked();\r
+       }\r
+       public void setIgnoreUpperCase(boolean value) {\r
+               ignoreUpperCase.setChecked(value);\r
+       }\r
+       \r
+       //****************************************************************\r
+       //* Getter/Setter for ignore that sentences begin with a capital *\r
+       //****************************************************************\r
+       public boolean getSentenceCapitalization() {\r
+               return ignoreSentenceCapitalization.isChecked();\r
+       }\r
+       public void setIgnoreSentenceCapitalization(boolean value) {\r
+               ignoreSentenceCapitalization.setChecked(value);\r
+       }\r
+\r
+}\r
index db005a9..5b89fb9 100644 (file)
@@ -46,6 +46,7 @@ import com.evernote.edam.type.Notebook;
 import com.evernote.edam.type.Resource;\r
 import com.evernote.edam.type.ResourceAttributes;\r
 import com.evernote.edam.type.Tag;\r
+import com.swabunga.spell.engine.Configuration;\r
 import com.swabunga.spell.engine.SpellDictionary;\r
 import com.swabunga.spell.engine.SpellDictionaryHashMap;\r
 import com.swabunga.spell.engine.Word;\r
@@ -1439,11 +1440,21 @@ public class BrowserWindow extends QWidget {
 \r
                // We know something has changed...\r
                String oldTagArray[] = saveTagList.split(Global.tagDelimeter);\r
-               String newTagArray[] = tagEdit.text().split(Global.tagDelimeter);\r
-               \r
-               if (!completionText.equals("") && newTagArray.length > 0) {\r
-                       newTagArray[newTagArray.length-1] = completionText;\r
+               String newTagArray[];\r
+               if (!completionText.equals("")) {\r
+                       String before = tagEdit.text().substring(0,tagEdit.cursorPosition());\r
+                       before = before.substring(0,before.lastIndexOf(Global.tagDelimeter));\r
+                       String after = tagEdit.text().substring(tagEdit.cursorPosition());\r
+                       newTagArray = (before+Global.tagDelimeter+completionText+Global.tagDelimeter+after).split(Global.tagDelimeter);\r
+               }\r
+               else {\r
+                       newTagArray = tagEdit.text().split(Global.tagDelimeter);\r
                }\r
+               \r
+               // Remove any traling or leading blanks\r
+               for (int i=0; i<newTagArray.length; i++)\r
+                       newTagArray[i] = newTagArray[i].trim().replaceAll("^\\s+", "");;\r
+               \r
                // Remove any potential duplicates from the new list\r
                for (int i=0; i<newTagArray.length; i++) {\r
                        boolean foundOnce = false;\r
@@ -1473,7 +1484,7 @@ public class BrowserWindow extends QWidget {
                for (int i=0; i<newTagList.size(); i++) {\r
                        newDisplay = newDisplay+newTagList.get(i);\r
                        if (i<newTagList.size()-1)\r
-                               newDisplay = newDisplay+", ";\r
+                               newDisplay = newDisplay+Global.tagDelimeter +" ";\r
                }\r
                tagEdit.blockSignals(true);\r
                tagEdit.setText(newDisplay);\r
@@ -2671,6 +2682,19 @@ public class BrowserWindow extends QWidget {
                try {\r
                        dictionary = new SpellDictionaryHashMap(wordList);\r
                        spellChecker = new SpellChecker(dictionary);\r
+                       \r
+                       // Read user settings\r
+                       spellChecker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREDIGITWORDS, \r
+                                       Global.getSpellSetting(Configuration.SPELL_IGNOREDIGITWORDS));\r
+                       spellChecker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREINTERNETADDRESSES, \r
+                                       Global.getSpellSetting(Configuration.SPELL_IGNOREINTERNETADDRESSES));\r
+                       spellChecker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREMIXEDCASE, \r
+                                       Global.getSpellSetting(Configuration.SPELL_IGNOREMIXEDCASE));\r
+                       spellChecker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREUPPERCASE, \r
+                                       Global.getSpellSetting(Configuration.SPELL_IGNOREUPPERCASE));\r
+                       spellChecker.getConfiguration().setBoolean(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, \r
+                                       Global.getSpellSetting(Configuration.SPELL_IGNORESENTENCECAPITALIZATION));\r
+                       \r
                        File userWordList;\r
                        userWordList = new File(Global.getFileManager().getSpellDirPathUser()+"user.dic");\r
                        \r
index 50d5edf..8af1664 100644 (file)
@@ -21,6 +21,7 @@ package cx.fbn.nevernote.gui;
 \r
 import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.StringTokenizer;\r
 \r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.core.QEvent;\r
@@ -90,21 +91,19 @@ public class TagLineEdit extends QLineEdit {
        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
+               String after_text = text().substring(cursor_pos) +" " +Global.tagDelimeter;\r
                int prefix_len = before_text.lastIndexOf(Global.tagDelimeter);\r
                if (prefix_len == -1) {\r
                        prefix_len = cursor_pos;\r
                        before_text = "";\r
                } else {\r
-                       before_text = before_text.substring(0,cursor_pos-1);\r
+                       before_text = before_text.substring(0, prefix_len);\r
                }\r
-               int nextTagPos = after_text.indexOf(Global.tagDelimeter);\r
-               if (nextTagPos == -1) {\r
-                       nextTagPos = 0;\r
-                       after_text = "";\r
-               }\r
-               setText(before_text +text +Global.tagDelimeter +" " +after_text);\r
-               setCursorPosition(cursor_pos - prefix_len + text().length() +2);\r
+\r
+               setText(rebuildTags(before_text+Global.tagDelimeter+text+Global.tagDelimeter+after_text));\r
+//             setText(before_text +text +Global.tagDelimeter +" " +after_text);\r
+//             setCursorPosition(cursor_pos - prefix_len + text().length() +2);\r
+               setCursorPosition(text().length());\r
        }\r
 \r
        public void setTagList(List<Tag> t) {\r
@@ -115,8 +114,25 @@ public class TagLineEdit extends QLineEdit {
        @Override\r
        public boolean event(QEvent e) {\r
                if (e.type().equals(QEvent.Type.FocusOut)) {\r
+                       \r
                        focusLost.emit();\r
                }\r
                return super.event(e);\r
        }\r
+       \r
+       private String rebuildTags(String tags) {\r
+               StringBuffer tagBuffer = new StringBuffer(tags.length() *2);\r
+               StringTokenizer tokens = new StringTokenizer (tags, Global.tagDelimeter);\r
+               boolean first = true;\r
+               while (tokens.hasMoreElements()) {\r
+                       String token = tokens.nextToken().trim();\r
+                       if (!token.equals("")) {\r
+                               if (!first)\r
+                                       tagBuffer.append(Global.tagDelimeter+ " ");\r
+                               first = false;\r
+                               tagBuffer.append(token);\r
+                       }\r
+               }\r
+               return tagBuffer.toString();\r
+       }\r
 }\r
diff --git a/src/cx/fbn/nevernote/icons/dictionary.png b/src/cx/fbn/nevernote/icons/dictionary.png
new file mode 100644 (file)
index 0000000..e139423
Binary files /dev/null and b/src/cx/fbn/nevernote/icons/dictionary.png differ