OSDN Git Service

Remove some of the popup note edit options from the main menu. For some reason they...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / ShortcutKeys.java
1 /*\r
2  * This file is part of NixNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \r
22 import java.io.File;\r
23 import java.io.FileNotFoundException;\r
24 import java.util.HashMap;\r
25 import java.util.Scanner;\r
26 import java.util.Vector;\r
27 \r
28 import cx.fbn.nevernote.Global;\r
29 \r
30 public class ShortcutKeys {\r
31         public String File_Note_Add;                            // Add a new note\r
32         public String File_Note_Reindex;                        // Reindex the current note\r
33         public String File_Note_Modify_Tags;            // Change current note tags\r
34         public String File_Note_Delete;                         // Delete a tag\r
35         public String File_Note_Restore;                        // Undelete a note\r
36         public String File_Note_Duplicate;                      // duplicate a note\r
37         public String File_Notebook_Add;                        // Add a notebook\r
38         public String File_Notebook_Edit;                       // Edit an existing notebook\r
39         public String File_Notebook_Delete;                     // Delete the existing notebook\r
40         public String File_Notebook_Open;                       // Open a closed (i.e. archived) notebook\r
41         public String File_Notebook_Close;                      // Close (i.e. archive) a notebook\r
42         public String File_Tag_Add;                                     // Add a notebook\r
43         public String File_Tag_Edit;                            // Edit an existing notebook\r
44         public String File_Tag_Delete;                          // Delete the existing notebook\r
45         public String File_SavedSearch_Add;                     // Add a notebook\r
46         public String File_SavedSearch_Edit;            // Edit an existing notebook\r
47         public String File_SavedSearch_Delete;          // Delete the existing notebook\r
48         public String File_Email;                                       // Email note\r
49         public String File_Print;                                       // Print\r
50         public String File_Backup;                                      // Backup the database\r
51         public String File_Restore;                                     // Restore the database\r
52         public String File_Empty_Trash;                         // Purge all delete notes\r
53         public String File_Exit;                                        // I'm outahere\r
54 \r
55         public String Edit_Find_In_Note;                        // Search only within the current note\r
56         public String Edit_Undo;                                        // Undo last change\r
57         public String Edit_Redo;                                        // Redo the last undone change\r
58         public String Edit_Cut;                                         // Cut current selection to the clipboard\r
59         public String Edit_Copy;                                        // Copy the current selection to the clipboard\r
60         public String Edit_Paste;                                       // Paste\r
61         public String Edit_Paste_Without_Formatting; // Paste as plain text\r
62         public String Edit_Preferences;                         // Settings dialog box\r
63         public String Edit_Insert_Hyperlink;            // Encrypt selected text\r
64         public String Edit_Insert_Table;                        // Insert table into note\r
65         public String Edit_Insert_Table_Row;            // Insert row into table\r
66         public String Edit_Delete_Table_Row;            // Delete a table row\r
67         public String Edit_Insert_Todo;                         // Insert todo\r
68         public String Edit_Encrypt_Text;                        // Encrypt selected text\r
69         public String Edit_Rotate_Image_Right;          // Rotate an image right\r
70         public String Edit_Rotate_Image_Left;           // Rotate an image left\r
71 \r
72         public String View_Extended_Information;        // View details on the current note\r
73         public String View_Thumbnail;                           // View Image Thumbnail\r
74         public String View_Show_Note_List;                      // Show current notes\r
75         public String View_Show_Notebooks;                      // Show notebooks\r
76         public String View_Show_Tags;                           // Show the tags window\r
77         public String View_Show_Attribute_Searches;     // Show the attribute selection tree\r
78         public String View_Show_SavedSearches;          // Show the saved search tree\r
79         public String View_Show_Trash;                          // Show the trash window\r
80         public String View_Show_Editor_Button_Bar;      // Hide the editor button bar\r
81         public String View_Show_Left_Side;                      // Hide all left hand windows\r
82 \r
83         public String Format_Bold;                                      // Bold (duh)\r
84         public String Format_Underline;                         // Underline\r
85         public String Format_Italic;                            // Italic\r
86         public String Format_Strikethrough;                     // Strikethrough\r
87         public String Format_Horizontal_Line;           // Href line\r
88         public String Format_Superscript;                       // Set superscript\r
89         public String Format_Subscript;                         // Subscript\r
90         public String Format_Alignment_Left;            // Left align text\r
91         public String Format_Alignment_Center;          // Center text\r
92         public String Format_Alignment_Right;           // Right align text\r
93         public String Format_List_Bullet;                       // Bullet list\r
94         public String Format_List_Numbered;                     // Numbered list \r
95         public String Format_Indent_Increase;           // Increase the indentation\r
96         public String Format_Indent_Decrease;           // Decrease the indent\r
97 \r
98         public String Online_Note_History;                      // Synchronize with Evernote\r
99         \r
100         public String Online_Synchronize;                       // Synchronize with Evernote\r
101         public String Online_Connect;                           // Connect to Evernote\r
102         public String Tools_Account_Information;        // Show account information\r
103         public String Tools_Reindex_Database;           // Reindex the entire database\r
104         public String Tools_Disable_Note_Indexing;      // Disable note indexing\r
105         public String Tools_Compact_Database;           // Free unused database space\r
106         public String Tools_Database_Status;            // Current database information\r
107 \r
108         public String About_Release_Notes;                      // Current version's release notes\r
109         public String About_Log;                                        // Message log\r
110         public String About_About;                                      // About dialog box\r
111         \r
112         public String Focus_Title;                                      // Switch focus to the title bar\r
113         public String Focus_Tag;                                        // Switch focus to the tag edit\r
114         public String Focus_Note;                                       // Switch focus to the note\r
115         public String Focus_Author;                                     // Switch focus to the author\r
116         public String Focus_Url;                                        // Switch focus to the URL\r
117         \r
118         public String Insert_DateTime;                          // Insert the current date/time\r
119         \r
120         HashMap<String, String> actionMap;\r
121         HashMap<String, String> shortcutMap;\r
122         \r
123         public ShortcutKeys() {\r
124                 File_Note_Add = new String("Ctrl+N");           // Add a new note\r
125                 File_Note_Reindex = new String();                       // Reindex the current note\r
126                 File_Note_Modify_Tags = new String();           // Change current note tags\r
127                 File_Note_Delete = new String();                        // Delete a tag\r
128                 File_Note_Restore = new String();                       // Undelete a note\r
129                 File_Note_Duplicate = new String();                     // Duplicate a note\r
130                 File_Notebook_Add = new String();                       // Add a notebook\r
131                 File_Notebook_Edit = new String();                      // Edit an existing notebook\r
132                 File_Notebook_Delete = new String();            // Delete the existing notebook\r
133                 File_Notebook_Open = new String();                      // Open a closed (i.e. archived) notebook\r
134                 File_Notebook_Close = new String();                     // Close (i.e. archive) a notebook\r
135                 File_Tag_Add = new String("Ctrl+Shift+T");      // Add a notebook\r
136                 File_Tag_Edit = new String();                           // Edit an existing notebook\r
137                 File_Tag_Delete = new String();                         // Delete the existing notebook\r
138                 File_SavedSearch_Add = new String();            // Add a notebook\r
139                 File_SavedSearch_Edit = new String();           // Edit an existing notebook\r
140                 File_SavedSearch_Delete = new String();         // Delete the existing notebook\r
141                 File_Email = new String("Ctrl+Shift+E");        // Email note\r
142                 File_Print = new String("Ctrl+P");                      // Print\r
143                 File_Backup = new String("");                           // Backup\r
144                 File_Restore = new String("");                          // Restore\r
145                 File_Empty_Trash = new String();                        // Purge all delete notes\r
146                 File_Exit = new String("Ctrl+Q");                       // I'm outahere\r
147 \r
148                 Edit_Find_In_Note = new String("Ctrl+F");       // Search only within the current note\r
149                 Edit_Undo = new String("Ctrl+Z");                       // Undo last change\r
150                 Edit_Redo = new String("Ctrl+Y");                       // Redo the last undone change\r
151                 Edit_Cut = new String("Ctrl+X");                        // Cut current selection to the clipboard\r
152                 Edit_Copy = new String("Ctrl+C");                       // Copy the current selection to the clipboard\r
153                 Edit_Paste = new String("Ctrl+V");                      // Paste\r
154                 Edit_Paste_Without_Formatting = new String("Ctrl+Shift+P"); // Paste as plain text\r
155                 Edit_Preferences = new String();                        // Settings dialog box\r
156                 \r
157                 Edit_Insert_Hyperlink = new String("Ctrl+K");   // Insert a hyperlink\r
158                 Edit_Insert_Table = new String();                               // Insert a table\r
159                 Edit_Insert_Table_Row = new String();                   // Insert a table row\r
160                 Edit_Delete_Table_Row = new String();                   // Delete a table row\r
161                 Edit_Insert_Todo = new String();\r
162                 Edit_Encrypt_Text = new String();\r
163                 Edit_Rotate_Image_Right = new String();\r
164                 Edit_Rotate_Image_Left = new String();\r
165 \r
166                 View_Extended_Information = new String("F8");   // View details on the current note\r
167                 View_Thumbnail = new String();                          // View the thumbnail\r
168                 View_Show_Note_List = new String("F10");        // Show current notes\r
169                 View_Show_Notebooks = new String();                     // Show notebooks\r
170                 View_Show_Tags = new String();                          // Show the tags window\r
171                 View_Show_Attribute_Searches = new String();    // Show the attribute selection tree\r
172                 View_Show_SavedSearches = new String();         // Show the saved search tree\r
173                 View_Show_Trash = new String();                         // Show the trash window\r
174                 View_Show_Editor_Button_Bar = new String();     // Hide the editor button bar\r
175                 View_Show_Left_Side = new String("F11");        // Hide all left hand windows\r
176 \r
177                 Format_Bold = new String("Ctrl+B");                     // Bold (duh)\r
178                 Format_Underline = new String("Ctrl+U");                // Underline\r
179                 Format_Italic = new String("Ctrl+I");                   // Italic\r
180                 Format_Strikethrough = new String("Ctrl+-");    // Strikethrough\r
181                 Format_Horizontal_Line = new String();          // Href line\r
182                 Format_Superscript = new String("Ctrl+=");      // Set superscript\r
183                 Format_Subscript = new String("Ctrl+Shift+=");  // Subscript\r
184                 Format_Alignment_Left = new String("Ctrl+L");   // Left align text\r
185                 Format_Alignment_Center = new String("Ctrl+E"); // Center text\r
186                 Format_Alignment_Right = new String("Ctrl+R");  // Right align text\r
187                 Format_List_Bullet = new String("Ctrl+Shift+B");        // Bullet list\r
188                 Format_List_Numbered = new String("Ctrl+Shift+N");      // Numbered list \r
189                 Format_Indent_Increase = new String("Ctrl+M");          // Increase the indentation\r
190                 Format_Indent_Decrease = new String("Ctrl+Shift+M");    // Decrease the indent\r
191 \r
192                 Online_Note_History = new String();\r
193                 \r
194                 Online_Synchronize = new String("F9");          // Synchronize with Evernote\r
195                 Online_Connect = new String();                          // Connect to Evernote\r
196                 Tools_Account_Information = new String();       // Show account information\r
197                 Tools_Reindex_Database = new String();          // Reindex the entire database\r
198                 Tools_Disable_Note_Indexing = new String();     // Disable note indexing\r
199                 Tools_Compact_Database = new String();          // Free unused database space\r
200                 Tools_Database_Status = new String();           // Current database information\r
201 \r
202                 About_Release_Notes = new String();                     // Current version's release notes\r
203                 About_Log = new String();                                       // Message log\r
204                 About_About = new String();                                     // About dialog box\r
205                 \r
206                 Insert_DateTime = new String("Ctrl+;");\r
207                 \r
208                 Focus_Title = new String();\r
209                 Focus_Tag = new String("Ctrl+Shift+T");\r
210                 Focus_Note = new String();\r
211                 Focus_Author = new String();\r
212                 Focus_Url = new String();\r
213                 \r
214                 // Setup value Array\r
215                 shortcutMap = new HashMap<String, String>();\r
216                 actionMap = new HashMap<String, String>();\r
217                 \r
218                 // Load the defaults\r
219                 loadKey("File_Note_Add", File_Note_Add);\r
220                 loadKey("File_Tag_Add", File_Tag_Add);\r
221                 loadKey("File_Email", File_Email);\r
222                 loadKey("File_Print", File_Print);\r
223                 loadKey("File_Backup", File_Backup);\r
224                 loadKey("File_Restore", File_Restore);\r
225                 loadKey("File_Exit", File_Exit);\r
226                 \r
227                 loadKey("Edit_Find_In_Note", Edit_Find_In_Note);\r
228                 loadKey("Edit_Undo", Edit_Undo);\r
229                 loadKey("Edit_Redo", Edit_Redo);\r
230                 loadKey("Edit_Cut", Edit_Cut);\r
231                 loadKey("Edit_Copy", Edit_Copy);\r
232                 loadKey("Edit_Paste", Edit_Paste);\r
233                 loadKey("Edit_Paste_Without_Formatting", Edit_Paste_Without_Formatting);\r
234                 loadKey("Edit_Insert_Hyperlink", Edit_Insert_Hyperlink);\r
235                 loadKey("Edit_Insert_Table_Row", Edit_Insert_Table_Row);\r
236                 loadKey("Edit_Delete_Table_Row", Edit_Delete_Table_Row);\r
237                 loadKey("Edit_Insert_Todo", Edit_Insert_Todo);\r
238                 loadKey("Edit_Rotate_Image_Right", Edit_Rotate_Image_Right);\r
239                 loadKey("Edit_Rotate_Image_Left", Edit_Rotate_Image_Left);\r
240                 \r
241                 loadKey("View_Extended_Information", View_Extended_Information);\r
242                 loadKey("View_Thumbnail", View_Thumbnail);\r
243                 loadKey("View_Show_Note_List", View_Show_Note_List);\r
244                 loadKey("View_Show_Left_Side",View_Show_Left_Side);\r
245                 \r
246                 loadKey("Format_Bold", Format_Bold);\r
247                 loadKey("Format_Underline", Format_Underline);\r
248                 loadKey("Format_Italic", Format_Italic);\r
249                 loadKey("Format_Strikethrough", Format_Strikethrough);\r
250                 loadKey("Format_Superscript", Format_Superscript);\r
251                 loadKey("Format_Subscript", Format_Subscript);\r
252                 loadKey("Format_Alignment_Left", Format_Alignment_Left);\r
253                 loadKey("Format_Alignment_Center", Format_Alignment_Center);\r
254                 loadKey("Format_Alignment_Right", Format_Alignment_Right);\r
255                 loadKey("Format_List_Bullet", Format_List_Bullet);\r
256                 loadKey("Format_List_Numbered", Format_List_Numbered);\r
257                 loadKey("Format_Indent_Increase", Format_Indent_Increase);\r
258                 loadKey("Format_Indent_Decrease", Format_Indent_Decrease);\r
259                 loadKey("Tools_Synchronize", Online_Synchronize);\r
260 \r
261 \r
262                 loadKey("Focus_Title", Focus_Title);\r
263                 loadKey("Focus_Tag", Focus_Tag);\r
264                 loadKey("Focus_Note", Focus_Note);\r
265                 loadKey("Focus_Author", Focus_Author);\r
266                 loadKey("Focus_Url", Focus_Url);\r
267                 \r
268                 loadKey("Insert_DateTime", Insert_DateTime);\r
269                 \r
270                 loadCustomKeys();\r
271                 \r
272         }\r
273         \r
274         // Read in the custom keys (if they exist)\r
275         private void loadCustomKeys() {\r
276                 File file = Global.getFileManager().getHomeDirFile("shortcuts.txt");\r
277                 try {\r
278                         Scanner scanner = new Scanner(file);\r
279                         while ( scanner.hasNextLine() ){\r
280                                 String line = scanner.nextLine();\r
281                                 line = line.replace("\t", " ");  // Replace tab characters\r
282                                 line = line.replace("\n", " "); // replace newline\r
283                                 line = line.replace("\r", " "); // replace carrage return\r
284                                 line = line.trim();             // compress the line\r
285                                 String split[] = line.split(" ");\r
286                                 Vector<String> keyVector = new Vector<String>();\r
287                                 for (int i=0; i<split.length; i++) {\r
288                                         if (!split[i].trim().equals("") && !split[i].trim().startsWith("//"))\r
289                                                 keyVector.add(split[i]);\r
290                                         if (split[i].trim().startsWith("//"))\r
291                                                 i=split.length;\r
292                                 }\r
293                                 if (keyVector.size() == 1)\r
294                                         removeByAction(keyVector.get(0));\r
295                                 if (keyVector.size() >=2) \r
296                                         loadKey(keyVector.get(0), keyVector.get(1));\r
297                                 \r
298                         }\r
299                 } catch (FileNotFoundException e) {\r
300                         return;\r
301                 }\r
302         }\r
303         \r
304         \r
305         // Load a key value into the map for later use\r
306         public void loadKey(String action, String shortcut) {\r
307                 shortcut = shortcut.trim().toLowerCase();\r
308                 action = action.trim().toLowerCase();\r
309                 \r
310                 // If we have an existing one, remove it.\r
311                 if (actionMap.containsKey(action))\r
312                         removeByAction(action);\r
313                 if (shortcutMap.containsKey(shortcut))\r
314                         removeByShortcut(shortcut);\r
315                 \r
316                 if (shortcut.equals("")) {\r
317                         removeByShortcut(shortcut);\r
318                         return;\r
319                 }\r
320                 \r
321                 // Add the new value\r
322                 actionMap.put(action.toLowerCase(), shortcut);\r
323                 shortcutMap.put(shortcut.toLowerCase(), action);\r
324         }\r
325         \r
326         // Remove a shortcut by the Shortcut key\r
327         public void removeByShortcut(String shortcut) {\r
328                 String action = shortcutMap.get(shortcut.toLowerCase());\r
329                 shortcutMap.remove(shortcut.toLowerCase());\r
330                 if (action != null)\r
331                         actionMap.remove(action.toLowerCase());\r
332         }\r
333         \r
334         // Remove a shortcut by the action itself\r
335         public void removeByAction(String action) {\r
336                 String shortcut = actionMap.get(action.toLowerCase());\r
337                 actionMap.remove(action.toLowerCase());\r
338                 if (shortcut != null)\r
339                         shortcutMap.remove(shortcut.toLowerCase());\r
340         }\r
341         \r
342         // Check if a shortcut key exists\r
343         public boolean containsShortcut(String shortcut) {\r
344                 return shortcutMap.containsKey(shortcut.toLowerCase());\r
345         }\r
346         \r
347         // Check if an action exists\r
348         public boolean containsAction(String action) {\r
349                 return actionMap.containsKey(action.toLowerCase());\r
350         }\r
351         \r
352         // Get a key based upon the action\r
353         public String getShortcut(String action) {\r
354                 return actionMap.get(action.toLowerCase());\r
355         }\r
356         \r
357         // Get an action based upon the key\r
358         public String getAction(String shortcut) {\r
359                 return shortcutMap.get(shortcut.toLowerCase());\r
360         }\r
361         \r
362 }\r