diff --git a/src/index.js b/src/index.js index 1f49d8b..9d56d42 100644 --- a/src/index.js +++ b/src/index.js @@ -27,16 +27,14 @@ let menu_template = [ { label: "Save", accelerator: "Ctrl+S", - click: function () { - let window = BrowserWindow.getFocusedWindow(); + click: function (item, window, event) { window.webContents.send("save", false); } }, { label: "Save As", accelerator: "Ctrl+Shift+S", - click: function () { - let window = BrowserWindow.getFocusedWindow(); + click: function (item, window, event) { window.webContents.send("save", true); } }, @@ -63,15 +61,26 @@ let menu_template = [ label: "Edit", submenu: [ { - label: "Copy", - accelerator: "Ctrl+C", - click: function () { - let window = BrowserWindow.getFocusedWindow(); - window.webContents.send("copy-to-clipboard"); - } + label: "Cut", + role: "cut", }, + { + label: "Copy", + role: "copy", + }, + { + label: "Paste", + role: "paste", + }, + { + label: "Select All", + accelerator: "Ctrl+A", + click: function (item, window, event) { + window.webContents.send("select-all"); + } + } ] - } + }, ] // Handle creating/removing shortcuts on Windows when installing/uninstalling. @@ -121,7 +130,7 @@ function createSplashScreen() { splash_screen.loadFile(path.join(app.getAppPath(), "src/splash.html")); // Open the DevTools. - // splash_screen.webContents.openDevTools(); + splash_screen.webContents.openDevTools(); // store.openInEditor(); } @@ -142,7 +151,7 @@ function createEditorWindow(json) { main_window.webContents.send("open", json); }); // Open the DevTools. - // main_window.webContents.openDevTools(); + main_window.webContents.openDevTools(); return main_window; } diff --git a/src/js/editor.js b/src/js/editor.js index 39bbec2..e74be8a 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -3,7 +3,7 @@ let json_data; let tables_data; let current_table; let selected_cells = []; -let selected_cell_data; +let selection_data; let is_positioning = false; let nav = $("nav"); let nav_scroll = nav.scrollLeft(); @@ -32,8 +32,7 @@ function clearPage() { $("#tables").empty(); nav.empty(); $("#details input, #details textarea").val(""); - selected_cells = []; - selected_cell_data = null; + selection_data = null; } function refreshPage() { @@ -168,7 +167,7 @@ function generateTables() { function updateDetailsPanel() { if (!is_positioning) { - let data = getSelectedCellData(true); + let data = getSelectionData(true); detail_tab_name.val(data["tab_name"]); detail_table_name.val(data["table_name"]); detail_table_description.val(data["table_description"]); @@ -215,17 +214,18 @@ function selectCells(cell_ids) { if (!Array.isArray(cell_ids)) { cell_ids = [cell_ids]; } - selected_cells = cell_ids; updateDetailsPanel(); } -function getSelectedCellData(force_update=false) { - if (!force_update && selected_cell_data) { - return selected_cell_data; +function getSelectionData(force_update=false) { + let selected_cells = getSelectedCells(); + if (!force_update && selection_data && selection_data["selection_count"] === selected_cells.length) { + return selection_data; } let cell_data = {}; $.each(tables_data, (i, table_data) => { if (table_data["id"] === current_table) { + cell_data["selection_count"] = selected_cells.length; cell_data["table_index"] = i; cell_data["table_name"] = table_data["name"]; cell_data["tab_name"] = table_data["tab_name"]; @@ -259,13 +259,15 @@ function getSelectedCellData(force_update=false) { return false; } }) + } else { + cell_data["row_index"] = -1; } } return false; } }) - selected_cell_data = cell_data; - return selected_cell_data; + selection_data = cell_data; + return selection_data; } function addTable() { @@ -300,7 +302,7 @@ function addTable() { ] } tables_data.push(table_data); - getSelectedCellData(true); + getSelectionData(true); generateTable(table_data); } @@ -369,7 +371,7 @@ function insertColumn(table_id, index=-1) { tr.children(`td:nth-child(${index + 1})`) .insert(cell) }); - getSelectedCellData(true); + getSelectionData(true); return false; } }) @@ -377,7 +379,7 @@ function insertColumn(table_id, index=-1) { selectable.add(cells_to_add); } -function insertRow(table_id, index) { +function insertRow(table_id, index=-1) { let cells_to_add = []; $.each(tables_data, (i, table_data) => { if (table_data["id"] === table_id) { @@ -418,7 +420,7 @@ function insertRow(table_id, index) { } $(`#${table_id} > tbody > tr:nth-child(${index+1})`) .insert(tr); - getSelectedCellData(true); + getSelectionData(true); return false; } }) @@ -465,8 +467,12 @@ function deleteRow(table_id, row_index) { function cellContextMenu(event, cell_id) { if (is_positioning) {return;} - if (!selected_cells.includes(cell_id)) { - selectCell(cell_id); + if (!getSelectedCells().includes(cell_id)) { + let selectable = getSelectable(); + selectable.selectAll(); + selectable.invert(); + selectable.select($("#"+cell_id)[0]); + getSelectionData(true); } let menu = $("
") .attr("id", "context-menu-"+cell_id) @@ -477,37 +483,37 @@ function cellContextMenu(event, cell_id) { .append($("