Can open multiple files at once now
File paths can be given as command line arguments Files can be drop into the splash screen to open
This commit is contained in:
parent
f9f50cd562
commit
5037bf41be
@ -63,6 +63,7 @@
|
|||||||
"jquery": "^3.5.1",
|
"jquery": "^3.5.1",
|
||||||
"jsdom": "^16.4.0",
|
"jsdom": "^16.4.0",
|
||||||
"jsonschema": "^1.4.0",
|
"jsonschema": "^1.4.0",
|
||||||
|
"minimist": "^1.2.5",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
33
src/index.ts
33
src/index.ts
@ -13,6 +13,7 @@ import * as fs from "fs";
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import * as log from "electron-log";
|
import * as log from "electron-log";
|
||||||
|
import * as parseArgs from "minimist";
|
||||||
import { Validator } from "jsonschema";
|
import { Validator } from "jsonschema";
|
||||||
import * as jsdom from "jsdom";
|
import * as jsdom from "jsdom";
|
||||||
const { JSDOM } = jsdom;
|
const { JSDOM } = jsdom;
|
||||||
@ -149,10 +150,22 @@ app.on("before-quit", (event) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
if (process.argv.includes("--debug")) {
|
let args = parseArgs(process.argv.slice(1));
|
||||||
|
if (args["_"][0] == ".") {
|
||||||
|
args["_"].splice(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args["debug"]) {
|
||||||
debug = true;
|
debug = true;
|
||||||
}
|
}
|
||||||
createSplashScreen();
|
if (args["_"].length > 0) {
|
||||||
|
for (let file_path of args["_"]) {
|
||||||
|
log.info(file_path);
|
||||||
|
openFile(file_path, true, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
createSplashScreen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSplashScreen() {
|
function createSplashScreen() {
|
||||||
@ -240,7 +253,7 @@ function chooseFile(title, for_save=false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openFile(file_path="", new_file=false) {
|
function openFile(file_path="", make_new_file=false, make_new_window=false) {
|
||||||
if (file_path === "") {
|
if (file_path === "") {
|
||||||
file_path = chooseFile("Open website data");
|
file_path = chooseFile("Open website data");
|
||||||
}
|
}
|
||||||
@ -249,10 +262,12 @@ function openFile(file_path="", new_file=false) {
|
|||||||
if (result) {
|
if (result) {
|
||||||
let json = getUpdatedJson(result);
|
let json = getUpdatedJson(result);
|
||||||
updateRecentFiles(file_path);
|
updateRecentFiles(file_path);
|
||||||
if (new_file) {
|
if (make_new_file) {
|
||||||
let old_window = BrowserWindow.getFocusedWindow();
|
let old_window = BrowserWindow.getFocusedWindow();
|
||||||
createEditorWindow(file_path, json);
|
createEditorWindow(file_path, json);
|
||||||
old_window.close();
|
if (old_window && !make_new_window) {
|
||||||
|
old_window.close();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let window = BrowserWindow.getFocusedWindow();
|
let window = BrowserWindow.getFocusedWindow();
|
||||||
window.webContents.send("open", file_path, json);
|
window.webContents.send("open", file_path, json);
|
||||||
@ -416,12 +431,16 @@ ipcMain.on("save", (event, file_name, json_data) => {
|
|||||||
saveFile(file_name, json_data);
|
saveFile(file_name, json_data);
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on("open", (event, file_path="", new_file=false) => {
|
ipcMain.on("open", (event, file_path="", new_file=false, new_window=false) => {
|
||||||
openFile(file_path, new_file)
|
openFile(file_path, new_file)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on("quit", (event) => {
|
ipcMain.on("quit", (event) => {
|
||||||
app.exit();
|
if (BrowserWindow.getAllWindows().length > 1) {
|
||||||
|
BrowserWindow.getFocusedWindow().destroy();
|
||||||
|
} else {
|
||||||
|
app.exit();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on("close-window", (event) => {
|
ipcMain.on("close-window", (event) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import * as $ from "../../third_party/js/jquery-3.5.1.js";
|
import * as $ from "../../third_party/js/jquery-3.5.1.js";
|
||||||
let recent_files_div = $("#recent-files")
|
let recent_files_div = $("#recent-files");
|
||||||
|
|
||||||
async function showRecentFiles() {
|
async function showRecentFiles() {
|
||||||
let recent_files = await ipcRenderer.invoke("get-store-value", "recent_files");
|
let recent_files = await ipcRenderer.invoke("get-store-value", "recent_files");
|
||||||
@ -42,3 +42,36 @@ $("#create-new").on("click", () => {
|
|||||||
$("#open-file").on("click", () => {
|
$("#open-file").on("click", () => {
|
||||||
ipcRenderer.send("open", "", true);
|
ipcRenderer.send("open", "", true);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#file-drop").on('drop', (event) => {
|
||||||
|
if (event.originalEvent.dataTransfer.types.includes("Files")) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
let files = event.originalEvent.dataTransfer.files;
|
||||||
|
for (const f of files) {
|
||||||
|
ipcRenderer.send("open", f.path, true, true);
|
||||||
|
}
|
||||||
|
$("#file-drop").css("display", "none");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('dragover', (event) => {
|
||||||
|
if (event.originalEvent.dataTransfer.types.includes("Files")) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
$("#file-drop").css("display", "block");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('dragleave', (event) => {
|
||||||
|
if (event.originalEvent.dataTransfer.types.includes("Files")) {
|
||||||
|
$("#file-drop").css("display", "none");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$(window).on('dragenter', (event) => {
|
||||||
|
if (event.originalEvent.dataTransfer.types.includes("Files")) {
|
||||||
|
let width = $(document).width();
|
||||||
|
let height = $(document).height();
|
||||||
|
$("#file-drop").css({"display": "block", "width": width, "height": height});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<button id="open-file" class="btn btn-secondary">Open</button>
|
<button id="open-file" class="btn btn-secondary">Open</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="file-drop" style="display: none; width: 100%; height: 100%; background: white; opacity: 50%; position: absolute">
|
||||||
|
<div class="position-absolute top-50 start-50 translate-middle" style="pointer-events: none">Drop files here</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
if (typeof module === 'object') {
|
if (typeof module === 'object') {
|
||||||
window.module = module;
|
window.module = module;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user