OSDN Git Service

Add insert/delete columns to tables.
authorRandy Baumgarte <randy@fbn.cx>
Mon, 10 Jan 2011 01:05:11 +0000 (20:05 -0500)
committerRandy Baumgarte <randy@fbn.cx>
Mon, 10 Jan 2011 01:15:21 +0000 (20:15 -0500)
src/cx/fbn/nevernote/gui/BrowserWindow.java
src/cx/fbn/nevernote/gui/ContentView.java

index 4da0b3c..e800124 100644 (file)
@@ -2364,6 +2364,7 @@ public class BrowserWindow extends QWidget {
                browser.rotateImageRight.setEnabled(false);\r
                browser.insertTableAction.setEnabled(true);\r
                browser.insertTableRowAction.setEnabled(false);\r
                browser.rotateImageRight.setEnabled(false);\r
                browser.insertTableAction.setEnabled(true);\r
                browser.insertTableRowAction.setEnabled(false);\r
+               browser.insertTableColumnAction.setEnabled(false);\r
                browser.deleteTableRowAction.setEnabled(false);\r
                browser.insertLinkAction.setText(tr("Insert Hyperlink"));\r
                insertHyperlink = true;\r
                browser.deleteTableRowAction.setEnabled(false);\r
                browser.insertLinkAction.setText(tr("Insert Hyperlink"));\r
                insertHyperlink = true;\r
@@ -2431,8 +2432,34 @@ public class BrowserWindow extends QWidget {
                browser.page().mainFrame().evaluateJavaScript(js);\r
                contentChanged();\r
        }\r
                browser.page().mainFrame().evaluateJavaScript(js);\r
                contentChanged();\r
        }\r
+       \r
+       public void insertTableColumn() {\r
+               String js = new String( "function insertTableColumn() {"\r
+                               +"   var selObj = window.getSelection();"\r
+                               +"   var selRange = selObj.getRangeAt(0);"\r
+                               +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
+                               +"   var current = 0;"\r
+                               +"   while (workingNode.nodeName.toLowerCase() != 'table' && workingNode != null) {"\r
+                               +"       if (workingNode.nodeName.toLowerCase() == 'td') {"\r
+                               +"          var td = workingNode;"\r
+                               +"          while (td.previousSibling != null) { " \r
+                               +"             current = current+1; td = td.previousSibling;"\r
+                               +"          }"\r
+                               +"       }"\r
+                               +"       workingNode = workingNode.parentNode; "\r
+                               +"   }"\r
+                               +"   if (workingNode == null) return;"\r
+                               +"   for (var i=0; i<workingNode.rows.length; i++) { " \r
+                               +"      var cell = workingNode.rows[i].insertCell(current+1); "                 \r
+                               +"      cell.innerHTML = '&nbsp'; "\r
+                               +"   }"\r
+                               +"} insertTableColumn();");\r
+                       browser.page().mainFrame().evaluateJavaScript(js);\r
+                       contentChanged();\r
+       }\r
+       \r
        //****************************************************************\r
        //****************************************************************\r
-       //* Insert a table row\r
+       //* Delete a table row\r
        //****************************************************************\r
        public void deleteTableRow() {\r
                \r
        //****************************************************************\r
        public void deleteTableRow() {\r
                \r
@@ -2452,8 +2479,35 @@ public class BrowserWindow extends QWidget {
                browser.page().mainFrame().evaluateJavaScript(js);\r
                contentChanged();\r
        }\r
                browser.page().mainFrame().evaluateJavaScript(js);\r
                contentChanged();\r
        }\r
+\r
+       public void deleteTableColumn() {\r
+               String js = new String( "function deleteTableColumn() {"\r
+                               +"   var selObj = window.getSelection();"\r
+                               +"   var selRange = selObj.getRangeAt(0);"\r
+                               +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
+                               +"   var current = 0;"\r
+                               +"   while (workingNode.nodeName.toLowerCase() != 'table' && workingNode != null) {"\r
+                               +"       if (workingNode.nodeName.toLowerCase() == 'td') {"\r
+                               +"          var td = workingNode;"\r
+                               +"          while (td.previousSibling != null) { " \r
+                               +"             current = current+1; td = td.previousSibling;"\r
+                               +"          }"\r
+                               +"       }"\r
+                               +"       workingNode = workingNode.parentNode; "\r
+                               +"   }"\r
+                               +"   if (workingNode == null) return;"\r
+                               +"   for (var i=0; i<workingNode.rows.length; i++) { " \r
+                               +"      workingNode.rows[i].deleteCell(current); "                      \r
+                               +"   }"\r
+                               +"} deleteTableColumn();");\r
+                       browser.page().mainFrame().evaluateJavaScript(js);\r
+                       contentChanged();\r
+       }\r
+       \r
+       \r
        public void setInsideTable() {\r
                browser.insertTableRowAction.setEnabled(true);\r
        public void setInsideTable() {\r
                browser.insertTableRowAction.setEnabled(true);\r
+               browser.insertTableColumnAction.setEnabled(true);\r
                browser.deleteTableRowAction.setEnabled(true);\r
                browser.insertTableAction.setEnabled(false);\r
                browser.encryptAction.setEnabled(false);\r
                browser.deleteTableRowAction.setEnabled(true);\r
                browser.insertTableAction.setEnabled(false);\r
                browser.encryptAction.setEnabled(false);\r
index 81ecdfd..2dfef1f 100644 (file)
@@ -66,8 +66,12 @@ public class ContentView extends QWebView {
        QShortcut insertTableShortcut;\r
        QAction insertTableRowAction;\r
        QShortcut insertTableRowShortcut;\r
        QShortcut insertTableShortcut;\r
        QAction insertTableRowAction;\r
        QShortcut insertTableRowShortcut;\r
+       QAction insertTableColumnAction;\r
+       QShortcut insertTableColumnShortcut;\r
        QAction deleteTableRowAction;\r
        QShortcut deleteTableRowShortcut;\r
        QAction deleteTableRowAction;\r
        QShortcut deleteTableRowShortcut;\r
+       QAction deleteTableColumnAction;\r
+       QShortcut deleteTableColumnShortcut;\r
        QAction openAction;\r
        \r
        QAction redBackgroundColor;\r
        QAction openAction;\r
        \r
        QAction redBackgroundColor;\r
@@ -185,6 +189,14 @@ public class ContentView extends QWebView {
                setupShortcut(insertTableRowShortcut, "Edit_Insert_Table_Row");\r
                insertTableRowShortcut.activated.connect(parent, "insertTableRow()");\r
                \r
                setupShortcut(insertTableRowShortcut, "Edit_Insert_Table_Row");\r
                insertTableRowShortcut.activated.connect(parent, "insertTableRow()");\r
                \r
+               insertTableColumnAction = new QAction(tr("Insert Column"), this);\r
+               insertTableColumnAction.triggered.connect(parent, "insertTableColumn()");\r
+               setupShortcut(insertTableColumnAction, "Edit_Insert_Table_Column");\r
+               tableMenu.addAction(insertTableColumnAction);\r
+               insertTableColumnShortcut = new QShortcut(this);\r
+               setupShortcut(insertTableColumnShortcut, "Edit_Insert_Table_Column");\r
+               insertTableColumnShortcut.activated.connect(parent, "insertTableColumn()");\r
+               \r
                deleteTableRowAction = new QAction(tr("Delete Row"), this);\r
                deleteTableRowAction.triggered.connect(parent, "deleteTableRow()");\r
                setupShortcut(deleteTableRowAction, "Edit_Delete_Table_Row");\r
                deleteTableRowAction = new QAction(tr("Delete Row"), this);\r
                deleteTableRowAction.triggered.connect(parent, "deleteTableRow()");\r
                setupShortcut(deleteTableRowAction, "Edit_Delete_Table_Row");\r
@@ -193,6 +205,15 @@ public class ContentView extends QWebView {
                setupShortcut(deleteTableRowShortcut, "Edit_Delete_Table_Row");\r
                deleteTableRowShortcut.activated.connect(parent, "deleteTableRow()");\r
                \r
                setupShortcut(deleteTableRowShortcut, "Edit_Delete_Table_Row");\r
                deleteTableRowShortcut.activated.connect(parent, "deleteTableRow()");\r
                \r
+               deleteTableColumnAction = new QAction(tr("Delete Column"), this);\r
+               deleteTableColumnAction.triggered.connect(parent, "deleteTableColumn()");\r
+               setupShortcut(deleteTableColumnAction, "Edit_Delete_Table_Column");\r
+               tableMenu.addAction(deleteTableColumnAction);\r
+               deleteTableColumnShortcut = new QShortcut(this);\r
+               setupShortcut(deleteTableColumnShortcut, "Edit_Delete_Table_Column");\r
+               deleteTableColumnShortcut.activated.connect(parent, "deleteTableColumn()");\r
+               \r
+               \r
                insertDateTimeShortcut = new QShortcut(this);\r
                insertDateTimeShortcut.activated.connect(parent, "insertDateTime()");\r
                setupShortcut(insertDateTimeShortcut, "Insert_DateTime");\r
                insertDateTimeShortcut = new QShortcut(this);\r
                insertDateTimeShortcut.activated.connect(parent, "insertDateTime()");\r
                setupShortcut(insertDateTimeShortcut, "Insert_DateTime");\r