Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
npx electron-builder
10 changes: 8 additions & 2 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
"directories": {
"output": "dist"
},
"files": ["!filePresets/**"],
"extraResources": [{ "from": "filePresets", "to": "../filePresets" }],
"files": ["!filePresets/**", "!front/editor/highlighter.css"],
"extraResources": [
{ "from": "filePresets", "to": "../filePresets" },
{
"from": "front/editor/highlighter.css",
"to": "../front/editor/highlighter.css"
}
],
"icon": "resources/icon/icon.ico",
"win": {
"target": "zip",
Expand Down
1 change: 0 additions & 1 deletion front/editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebBox</title>
<link rel="stylesheet" href="highlighter.css" />
<link rel="stylesheet" href="editor.css" />
</head>
<body>
Expand Down
94 changes: 71 additions & 23 deletions front/editor/editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
///////////////////////////////////////////////////////////////
Index - Search with Ctrl + F (VSCode)
editor.js / Index - Search with Ctrl + F (VSCode)
///////////////////////////////////////////////////////////////

- Module Import
Expand All @@ -22,6 +22,8 @@
- New File Dialog
- Open Viewer
- Pick Opened Display Dialog
- Load Highlighter
- Handle Window Deletion
- Others

*/
Expand All @@ -41,6 +43,7 @@ const {
const highlighter = require("./highlight");
const { getCaretPosition, setCaretPosition } = require("./modules/caret");
const fs = require("fs");
const path = require("path");

///////////////////////////////////////////////////////////////
// Setup Needle DB
Expand Down Expand Up @@ -382,11 +385,9 @@ document.addEventListener("keydown", async (event) => {
}
} else if (event.key.toLowerCase() === "w") {
event.preventDefault();
if (currentFile === null) return;
if (event.shiftKey) {
if (
currentFile === null ||
(!currentFile.endsWith(".html") && !currentFile.endsWith(".htm"))
) {
if (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) {
ipcRenderer.send("new-window");
} else {
ipcRenderer.invoke("new-window-set", currentFile).then((response) => {
Expand Down Expand Up @@ -575,8 +576,19 @@ async function refreshEditor() {
});

OpenedDisplays.forEach((e) => {
Array.from(document.getElementById("windowPicker").children).forEach(
(child) => {
child.remove();
}
);
// <option value="none">(none)</option>
const noOption = document.createElement("option");
noOption.value = "none";
noOption.innerHTML = "(none)";
document.getElementById("windowPicker").appendChild(noOption);

const option = document.createElement("option");
option.value = e.window;
option.value = e.fileLink;
const splittedFileLink = e.fileLink.split("\\");
option.innerHTML = `${splittedFileLink[splittedFileLink.length - 2]}\\${splittedFileLink[splittedFileLink.length - 1]}`;
document.getElementById("windowPicker").appendChild(option);
Expand Down Expand Up @@ -746,20 +758,33 @@ createBtn.addEventListener("click", () => {
if (args.dir == null || args.name == null || args.preset == null) {
alert("Argument missing.");
} else {
ipcRenderer.invoke("createFile", args).then((response) => {
if (response == 0) {
openFile(`${args.dir}\\${args.name}`, () => {
loadFileIntoEditor(`${args.dir}\\${args.name}`);
});
document.getElementById("filenameField").value = "";
dir = null;
document.getElementById("fileDirLbl").innerHTML = "No folder selected";
document.getElementById("presetPicker").value = "none";
document.getElementById("newFileDialog").close();
} else {
alert("Error in file creation");
let filedata = "";

if (args.preset !== "none") {
filedata = fs.readFileSync(args.preset, { encoding: "utf-8" });
}

let ans = 0;

fs.writeFile(`${args.dir}\\${args.name}`, filedata, function (err) {
if (err) {
ans = err;
throw err;
}
});

if (ans == 0) {
openFile(`${args.dir}\\${args.name}`, () => {
loadFileIntoEditor(`${args.dir}\\${args.name}`);
});
document.getElementById("filenameField").value = "";
dir = null;
document.getElementById("fileDirLbl").innerHTML = "No folder selected";
document.getElementById("presetPicker").value = "none";
document.getElementById("newFileDialog").close();
} else {
alert("Error in file creation");
}
}
});

Expand All @@ -770,11 +795,9 @@ createBtn.addEventListener("click", () => {
const openViewerBtn = document.getElementById("OpenViewerBtn");

openViewerBtn.addEventListener("click", (event) => {
if (currentFile === null) return;
if (event.shiftKey) {
if (
currentFile === null ||
(!currentFile.endsWith(".html") && !currentFile.endsWith(".htm"))
) {
if (!currentFile.endsWith(".html") && !currentFile.endsWith(".htm")) {
ipcRenderer.send("new-window");
} else {
ipcRenderer.invoke("new-window-set", currentFile).then((response) => {
Expand Down Expand Up @@ -807,17 +830,42 @@ cancelDisplayPickBtn.addEventListener("click", () => {
const pickWindowBtn = document.getElementById("pickWindowBtn");

pickWindowBtn.addEventListener("click", () => {
if (document.getElementById("windowPicker").value != "none") {
if (document.getElementById("windowPicker").value !== "none") {
OpenedFiles.SET(
OpenedFiles.FINDQUICKINDEX("fileLink", currentFile),
"linkedDisplay",
document.getElementById("windowPicker").value
);
pickOpenedDisplayDialog.close();
document.getElementById("windowPicker").value = "none";
} else {
pickOpenedDisplayDialog.close();
}
});

//////////////////////////////////////////////////////////
// Load Highlighter
/////////////////////////////////////////////////////////

const cssPath = path.join(process.cwd(), "front", "editor", "highlighter.css");

const link = document.createElement("link");
link.rel = "stylesheet";
link.href = `file://${cssPath}`;
document.head.appendChild(link);

//////////////////////////////////////////////////////////
// Handle Window Deletion
/////////////////////////////////////////////////////////

ipcRenderer.on("deleteWindow", (event, fileLink) => {
const linkedEditors = OpenedFiles.SEARCH("linkedDisplay", fileLink);

linkedEditors.forEach((e) => {
OpenedFiles.SET(e, "linkedDisplay", null);
});
});

/////////////////////////////////////////////////////////
// Others
/////////////////////////////////////////////////////////
Expand Down
Loading