From 471f462878a5e9d0635a8e0cbefa81a554129965 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 2 Sep 2021 20:50:56 -0700 Subject: [PATCH] New Empty Database... menu option, closes #30 --- main.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.js b/main.js index e5b246d..091042c 100644 --- a/main.js +++ b/main.js @@ -269,6 +269,32 @@ function createWindow() { postConfigure(newWindow); }, }, + { type: "separator" }, + { + label: "New Empty Database…", + accelerator: "CommandOrControl+Shift+N", + click: async () => { + const filepath = dialog.showSaveDialogSync({defaultPath: "database.db", title: "Create Empty Database"}) + const response = await request( + `http://localhost:${port}/-/new-empty-database-file`, + { + method: "POST", + body: JSON.stringify({ path: filepath }), + } + ); + const responseJson = await response.json(); + if (!responseJson.ok) { + console.log(responseJson); + dialog.showMessageBox({ + type: "error", + title: "Datasette", + message: responseJson.error + }); + } else { + datasette.openPath(responseJson.path); + } + }, + }, { label: "Open CSV…", accelerator: "CommandOrControl+O",