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