OSDN Git Service

Add some shortcuts to external browser window.
authorRandy Baumgarte <randy@fbn.cx>
Fri, 14 Jan 2011 18:16:40 +0000 (13:16 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Sun, 30 Jan 2011 13:36:36 +0000 (08:36 -0500)
src/cx/fbn/nevernote/gui/ExternalBrowse.java
src/cx/fbn/nevernote/gui/ExternalBrowserMenuBar.java [new file with mode: 0644]

index f2acd41..ff0f5e0 100644 (file)
 \r
 package cx.fbn.nevernote.gui;\r
 \r
+import java.awt.Desktop;\r
 import java.util.List;\r
 \r
+import com.trolltech.qt.core.QUrl;\r
 import com.trolltech.qt.core.Qt.WidgetAttribute;\r
+import com.trolltech.qt.gui.QAction;\r
 import com.trolltech.qt.gui.QCloseEvent;\r
+import com.trolltech.qt.gui.QDesktopServices;\r
+import com.trolltech.qt.gui.QDialog;\r
 import com.trolltech.qt.gui.QMdiSubWindow;\r
+import com.trolltech.qt.gui.QPrintDialog;\r
+import com.trolltech.qt.gui.QPrinter;\r
 \r
 import cx.fbn.nevernote.Global;\r
+import cx.fbn.nevernote.dialog.FindDialog;\r
 import cx.fbn.nevernote.sql.DatabaseConnection;\r
 \r
 public class ExternalBrowse extends QMdiSubWindow {\r
@@ -34,6 +42,10 @@ public class ExternalBrowse extends QMdiSubWindow {
        public Signal4<String, String, Boolean, BrowserWindow> contentsChanged;\r
        public Signal1<String>  windowClosing;\r
        boolean noteDirty;\r
+       private QAction editFind;\r
+       private final FindDialog        find;                                           // Text search in note dialog\r
+//     ExternalBrowserMenuBar          menu;\r
+       ExternalBrowserMenuBar  menu;\r
        \r
        // Constructor\r
        public ExternalBrowse(DatabaseConnection c) {\r
@@ -43,10 +55,17 @@ public class ExternalBrowse extends QMdiSubWindow {
                contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();\r
                windowClosing = new Signal1<String>();\r
                browser = new BrowserWindow(conn);\r
+               menu = new ExternalBrowserMenuBar(this);\r
+               for (int i=0; i<menu.actions().size(); i++) {\r
+                       addAction(menu.actions().get(i));\r
+               }\r
+               \r
                setWidget(browser);\r
                noteDirty = false;\r
                browser.titleLabel.textChanged.connect(this, "titleChanged(String)");\r
                browser.getBrowser().page().contentsChanged.connect(this, "contentChanged()");\r
+               find = new FindDialog();\r
+               find.getOkButton().clicked.connect(this, "doFindText()");\r
        }\r
        \r
        @SuppressWarnings("unused")\r
@@ -106,4 +125,40 @@ public class ExternalBrowse extends QMdiSubWindow {
                }\r
        }\r
 \r
+       \r
+    @SuppressWarnings("unused")\r
+       private void findText() {\r
+       find.show();\r
+       find.setFocusOnTextField();\r
+    }\r
+    @SuppressWarnings("unused")\r
+       private void doFindText() {\r
+       browser.getBrowser().page().findText(find.getText(), find.getFlags());\r
+       find.setFocus();\r
+    }\r
+\r
+       \r
+    @SuppressWarnings("unused")\r
+       private void printNote() {\r
+\r
+       QPrintDialog dialog = new QPrintDialog();\r
+       if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {\r
+               QPrinter printer = dialog.printer();\r
+               browser.getBrowser().print(printer);\r
+       }\r
+    }\r
+    \r
+    // Listener triggered when the email button is pressed\r
+    @SuppressWarnings("unused")\r
+       private void emailNote() {\r
+        if (Desktop.isDesktopSupported()) {\r
+            Desktop desktop = Desktop.getDesktop();\r
+            \r
+            String text2 = browser.getContentsToEmail();\r
+            QUrl url = new QUrl("mailto:");\r
+            url.addQueryItem("subject", browser.getTitle());\r
+            url.addQueryItem("body", text2);\r
+            QDesktopServices.openUrl(url);\r
+        }\r
+    }\r
 }\r
diff --git a/src/cx/fbn/nevernote/gui/ExternalBrowserMenuBar.java b/src/cx/fbn/nevernote/gui/ExternalBrowserMenuBar.java
new file mode 100644 (file)
index 0000000..13d330e
--- /dev/null
@@ -0,0 +1,276 @@
+/*\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
+package cx.fbn.nevernote.gui;\r
+\r
+import com.trolltech.qt.gui.QAction;\r
+import com.trolltech.qt.gui.QMenu;\r
+import com.trolltech.qt.gui.QMenuBar;\r
+\r
+import cx.fbn.nevernote.Global;\r
+\r
+public class ExternalBrowserMenuBar extends QMenuBar {\r
+\r
+       private final ExternalBrowse            parent;\r
+       public QAction                  printAction;                            // Action when a user selects Print from the file menu\r
+       public QAction                  emailAction;                            // Action when a user selects "email"\r
+\r
+       public QAction                  editFind;                                       // find text in the current note\r
+       public QAction                  editUndo;                                       // Undo last change\r
+       public QAction                  editRedo;                                       // Redo last change\r
+       public QAction                  editCut;                                        // Cut selected text\r
+       public QAction                  editPaste;                                      // Paste selected text\r
+       public QAction                  editPasteWithoutFormat;         // Paste selected text\r
+       public QAction                  editCopy;                                       // Copy selected text;\r
+               \r
+       public QAction                  formatBold;                                     // Bold selected text\r
+       public QAction                  formatItalic;                           // Italics selected text\r
+       public QAction                  formatUnderline;                        // Underline selected text\r
+       public QAction                  formatStrikethrough;            // Strikethrough selected text\r
+       public QAction                  formatSuperscript;                      // Superscript selected text\r
+       public QAction                  formatSubscript;                        // Subscript selected text\r
+       public QAction                  formatNumberList;                       // insert a numbered list\r
+       public QAction                  formatBulletList;                       // insert a bulleted list;\r
+       public QAction                  alignLeftAction;                        // Left justify text\r
+       public QAction                  alignRightAction;                       // Right justify text\r
+       public QAction                  alignCenterAction;                      // Center text\r
+       public QAction                  horizontalLineAction;           // Insert a horizontal line\r
+       public QAction                  indentAction;                           // Indent\r
+       public QAction                  outdentAction;                          // outdent menu action\r
+       \r
+       public QAction                  spellCheckAction;                       // Spell checker\r
+       \r
+       \r
+       //**************************************************************************\r
+       //* External Browser Menu Bar.  \r
+       //* We don't actually show this, but we use it to setup shortcuts.\r
+       //**************************************************************************\r
+       \r
+       public QMenu                    fileMenu;                                       // File menu\r
+\r
+       public QMenu                    editMenu;                                       // Edit menu\r
+\r
+       private QMenu                   formatMenu;                                     // Text format menu\r
+       private QMenu                   listMenu;                                       // bullet or numbered list\r
+       private QMenu                   indentMenu;                                     // indent or outdent menu\r
+       private QMenu                   alignMenu;                                      // Left/Right/Center justify\r
+       \r
+       public ExternalBrowserMenuBar(ExternalBrowse p) {\r
+               parent = p;\r
+               \r
+               \r
+               printAction = new QAction(tr("Print"), this);\r
+               printAction.setToolTip("Print the current note");\r
+               printAction.triggered.connect(parent, "printNote()");\r
+               setupShortcut(printAction, "File_Print");\r
+               \r
+               emailAction = new QAction(tr("Email"), this);\r
+               emailAction.setToolTip("Email the current note");\r
+               emailAction.triggered.connect(parent, "emailNote()");\r
+               setupShortcut(emailAction, "File_Email");\r
+               \r
+               editFind = new QAction(tr("Find In Note"), this);\r
+               editFind.setToolTip(tr("Find a string in the current note"));\r
+               editFind.triggered.connect(parent, "findText()");\r
+               setupShortcut(editFind, "Edit_Find_In_Note");\r
+               //editFind.setShortcut("Ctrl+F");\r
+               \r
+               editUndo = new QAction(tr("Undo"), this);\r
+               editUndo.setToolTip(tr("Undo"));\r
+               editUndo.triggered.connect(parent.getBrowserWindow(), "undoClicked()"); \r
+               setupShortcut(editUndo, "Edit_Undo");\r
+               //editUndo.setShortcut("Ctrl+Z");\r
+               \r
+               editRedo = new QAction(tr("Redo"), this);\r
+               editRedo.setToolTip(tr("Redo"));\r
+               editRedo.triggered.connect(parent.getBrowserWindow(), "redoClicked()");\r
+               setupShortcut(editRedo, "Edit_Redo");\r
+               //editRedo.setShortcut("Ctrl+Y");\r
+       \r
+               editCut = new QAction(tr("Cut"), this);\r
+               editCut.setToolTip(tr("Cut"));\r
+               editCut.triggered.connect(parent.getBrowserWindow(), "cutClicked()");\r
+               setupShortcut(editCut, "Edit_Cut");\r
+               //editCut.setShortcut("Ctrl+X");\r
+               \r
+               editCopy = new QAction(tr("Copy"), this);\r
+               editCopy.setToolTip(tr("Copy"));\r
+               editCopy.triggered.connect(parent.getBrowserWindow(), "copyClicked()");\r
+               setupShortcut(editCopy, "Edit_Copy");\r
+               //editCopy.setShortcut("Ctrl+C");\r
+               \r
+               editPaste = new QAction(tr("Paste"), this);\r
+               editPaste.setToolTip(tr("Paste"));\r
+               editPaste.triggered.connect(parent.getBrowserWindow(), "pasteClicked()");\r
+               setupShortcut(editPaste, "Edit_Paste");\r
+\r
+               editPasteWithoutFormat = new QAction(tr("Paste Without Formatting"), this);\r
+               editPasteWithoutFormat.setToolTip(tr("Paste Without Formatting"));\r
+               editPasteWithoutFormat.triggered.connect(parent.getBrowserWindow(), "pasteWithoutFormattingClicked()");\r
+               setupShortcut(editPasteWithoutFormat, "Edit_Paste_Without_Formatting");\r
+               \r
+\r
+               alignLeftAction = new QAction(tr("Left"), this);\r
+               alignLeftAction.setToolTip(tr("Left Align"));\r
+               alignLeftAction.triggered.connect(parent.getBrowserWindow(), "justifyLeftClicked()");\r
+               setupShortcut(alignLeftAction, "Format_Alignment_Left");\r
+               //alignLeftAction.setShortcut("Ctrl+L");\r
+               \r
+               alignRightAction = new QAction(tr("Right"), this);\r
+               alignRightAction.setToolTip(tr("Right Align"));\r
+               alignRightAction.triggered.connect(parent.getBrowserWindow(), "justifyRightClicked()");\r
+               setupShortcut(alignRightAction, "Format_Alignment_Right");\r
+               //alignRightAction.setShortcut("Ctrl+R");\r
+               \r
+               alignCenterAction = new QAction(tr("Center"), this);\r
+               alignCenterAction.setToolTip(tr("Center Align"));\r
+               alignCenterAction.triggered.connect(parent.getBrowserWindow(), "justifyCenterClicked()");\r
+               setupShortcut(alignCenterAction, "Format_Alignment_Center");\r
+               //alignCenterAction.setShortcut("Ctrl+C");\r
+               \r
+               formatBold = new QAction(tr("Bold"), this);\r
+               formatBold.setToolTip(tr("Bold"));\r
+               formatBold.triggered.connect(parent.getBrowserWindow(), "boldClicked()");\r
+               setupShortcut(formatBold, "Format_Bold");\r
+               //formatBold.setShortcut("Ctrl+B");\r
+               \r
+               formatItalic = new QAction(tr("Italic"), this);\r
+               formatItalic.setToolTip(tr("Italic"));\r
+               formatItalic.triggered.connect(parent.getBrowserWindow(), "italicClicked()");\r
+               setupShortcut(formatItalic, "Format_Italic");\r
+               //formatItalic.setShortcut("Ctrl+I");\r
+               \r
+               formatUnderline = new QAction(tr("Underline"), this);\r
+               formatUnderline.setToolTip(tr("Underline"));\r
+               formatUnderline.triggered.connect(parent.getBrowserWindow(), "underlineClicked()");\r
+               setupShortcut(formatUnderline, "Format_Underline");\r
+//             formatUnderline.setShortcut("Ctrl+U");\r
+\r
+               \r
+               formatSuperscript = new QAction(tr("Superscript"), this);\r
+               formatSuperscript.setToolTip(tr("Superscript"));\r
+               formatSuperscript.triggered.connect(parent.getBrowserWindow(), "superscriptClicked()");\r
+               setupShortcut(formatSuperscript, "Format_Superscript");\r
+\r
+\r
+               formatSubscript = new QAction(tr("Subscript"), this);\r
+               formatSubscript.setToolTip(tr("Subscript"));\r
+               formatSubscript.triggered.connect(parent.getBrowserWindow(), "subscriptClicked()");\r
+               setupShortcut(formatSubscript, "Format_Subscript");\r
+\r
+               \r
+               formatStrikethrough = new QAction(tr("Strikethrough"), this);\r
+               formatStrikethrough.setToolTip(tr("Strikethrough"));\r
+               formatStrikethrough.triggered.connect(parent.getBrowserWindow(), "strikethroughClicked()");\r
+               setupShortcut(formatStrikethrough, "Format_Strikethrough");\r
+\r
+               horizontalLineAction = new QAction(tr("Horizontal Line"), this);\r
+               horizontalLineAction.setToolTip(tr("Horizontal Line"));\r
+               horizontalLineAction.triggered.connect(parent.getBrowserWindow(), "hlineClicked()");\r
+               setupShortcut(horizontalLineAction, "Format_Horizontal_Line");\r
+               \r
+               formatBulletList = new QAction(tr("Bulleted List"), this);\r
+//             formatBulletList.setText(tr("Numbered List"));\r
+               formatBulletList.triggered.connect(parent.getBrowserWindow(), "bulletListClicked()");\r
+               setupShortcut(formatBulletList, "Format_List_Bullet");\r
+//             formatBulletList.setShortcut("Ctrl+Shift+B");\r
+               \r
+               formatNumberList = new QAction(tr("Numbered List"), this);\r
+               formatNumberList.setText(tr("Numbered list"));\r
+               formatNumberList.triggered.connect(parent.getBrowserWindow(), "numberListClicked()");\r
+               setupShortcut(formatNumberList, "Format_List_Numbered");\r
+//             formatNumberList.setShortcut("Ctrl+Shift+O");\r
+\r
+               indentAction = new QAction(tr(">> Increase"), this);\r
+               indentAction.setText(tr(">> Increase"));\r
+               indentAction.triggered.connect(parent.getBrowserWindow(), "indentClicked()");\r
+               setupShortcut(indentAction, "Format_Indent_Increase");\r
+               //indentAction.setShortcut("Ctrl+M");\r
+\r
+               outdentAction = new QAction(tr("<< Decrease"), this);\r
+               outdentAction.setText(tr("<< Decrease"));\r
+               outdentAction.triggered.connect(parent.getBrowserWindow(), "outdentClicked()");\r
+               setupShortcut(outdentAction, "Format_Indent_Decrease");\r
+               //outdentAction.setShortcut("Ctrl+Shift+M");\r
+               \r
+               \r
+               spellCheckAction = new QAction(tr("Spell Check"), this);\r
+               spellCheckAction.setToolTip("Check for spelling errors");\r
+               spellCheckAction.triggered.connect(parent.getBrowserWindow(), "spellCheckClicked()");\r
+               setupShortcut(spellCheckAction, "Tools_Spell_Check");\r
+               \r
+               setupMenuBar();\r
+       }\r
+       \r
+       public void setupMenuBar() {\r
+               fileMenu = addMenu(tr("&File"));\r
+               \r
+               fileMenu.addSeparator();\r
+               fileMenu.addAction(emailAction);\r
+               fileMenu.addAction(printAction);\r
+               fileMenu.addSeparator();\r
+\r
+               editMenu = addMenu(tr("&Edit"));\r
+               editMenu.addAction(editFind);\r
+               editMenu.addSeparator();\r
+               editMenu.addAction(editUndo);\r
+               editMenu.addAction(editRedo);\r
+               editMenu.addSeparator();\r
+               editMenu.addAction(editCut);\r
+               editMenu.addAction(editCopy);\r
+               editMenu.addAction(editPaste);\r
+               editMenu.addAction(editPasteWithoutFormat);\r
+               \r
+               formatMenu = addMenu(tr("&Format"));\r
+               formatMenu.addAction(formatBold);\r
+               formatMenu.addAction(formatUnderline);\r
+               formatMenu.addAction(formatItalic);\r
+               formatMenu.addSeparator();\r
+               formatMenu.addAction(formatStrikethrough);\r
+               formatMenu.addAction(horizontalLineAction);\r
+               formatMenu.addSeparator();\r
+               formatMenu.addAction(formatSuperscript);\r
+               formatMenu.addAction(formatSubscript);\r
+               formatMenu.addSeparator();\r
+\r
+               alignMenu = formatMenu.addMenu(tr("Alignment"));\r
+               alignMenu.addAction(alignLeftAction);\r
+               alignMenu.addAction(alignCenterAction);\r
+               alignMenu.addAction(alignRightAction);\r
+               \r
+               listMenu = formatMenu.addMenu(tr("Lists"));\r
+               listMenu.addAction(formatBulletList);\r
+               listMenu.addAction(formatNumberList);\r
+               indentMenu = formatMenu.addMenu(tr("Indent"));\r
+               indentMenu.addAction(indentAction);\r
+               indentMenu.addAction(outdentAction);\r
+               \r
+               \r
+               addMenu(fileMenu);\r
+               addMenu(editMenu);\r
+               addMenu(formatMenu);\r
+\r
+       }\r
+       \r
+       private void setupShortcut(QAction action, String text) {\r
+               if (!Global.shortcutKeys.containsAction(text))\r
+                       return;\r
+               action.setShortcut(Global.shortcutKeys.getShortcut(text));\r
+       }\r
+\r
+}\r