Can remove recent files now
This commit is contained in:
parent
7d444006d1
commit
4ec53eb4b9
34
src/index.js
34
src/index.js
@ -102,6 +102,8 @@ function createSplashScreen() {
|
||||
|
||||
if (!store.has("recent_files")) {
|
||||
store.set("recent_files", []);
|
||||
} else {
|
||||
updateRecentFiles();
|
||||
}
|
||||
|
||||
splash_screen.loadFile(path.join(app.getAppPath(), "src/splash.html"));
|
||||
@ -200,13 +202,25 @@ function saveFile(json_data, create_new_file) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateRecentFiles(new_file) {
|
||||
store.set("default_dir", new_file);
|
||||
function updateRecentFiles(new_file=null) {
|
||||
let recent_files = store.get("recent_files");
|
||||
if (recent_files.includes(new_file)) {
|
||||
recent_files.splice(recent_files.indexOf(new_file), 1);
|
||||
if (new_file != null) {
|
||||
store.set("default_dir", new_file);
|
||||
if (recent_files.includes(new_file)) {
|
||||
recent_files.splice(recent_files.indexOf(new_file), 1);
|
||||
}
|
||||
recent_files.splice(0, 0, new_file);
|
||||
}
|
||||
let files_to_delete = [];
|
||||
$.each(recent_files, (i, file) => {
|
||||
if (!fs.existsSync(file)) {
|
||||
console.log(file);
|
||||
files_to_delete.push(i);
|
||||
}
|
||||
});
|
||||
for (let index of files_to_delete) {
|
||||
recent_files.splice(index, 1);
|
||||
}
|
||||
recent_files.splice(0, 0, new_file);
|
||||
store.set("recent_files", recent_files);
|
||||
updateMenuBar();
|
||||
}
|
||||
@ -295,10 +309,20 @@ function duplicateJson(json) {
|
||||
return JSON.parse(JSON.stringify(json));
|
||||
}
|
||||
|
||||
function removeRecentFile(file) {
|
||||
let recent_files = store.get("recent_files");
|
||||
recent_files.splice(recent_files.indexOf(file), 1);
|
||||
store.set("recent_files", recent_files);
|
||||
}
|
||||
|
||||
ipcMain.handle("get-store-value", (event, key) => {
|
||||
return store.get(key)
|
||||
})
|
||||
|
||||
ipcMain.handle("remove-recent-file", (event, file) => {
|
||||
removeRecentFile(file);
|
||||
})
|
||||
|
||||
ipcMain.on("create-new", (event) => {
|
||||
createNew();
|
||||
})
|
||||
|
@ -3,29 +3,35 @@ const fs = require("fs");
|
||||
|
||||
async function showRecentFiles() {
|
||||
let recent_files = await ipcRenderer.invoke("get-store-value", "recent_files");
|
||||
let valid_recent_files = [];
|
||||
for (let file of recent_files) {
|
||||
if (fs.existsSync(file)) {
|
||||
valid_recent_files.push(file);
|
||||
}
|
||||
}
|
||||
if (valid_recent_files.length === 0) {
|
||||
$("#recent-files").empty();
|
||||
if (recent_files.length === 0) {
|
||||
$("#recent-files").css("display", "none");
|
||||
$("#splash").css("width", "100%")
|
||||
} else {
|
||||
for (let file of valid_recent_files) {
|
||||
let recent_file_link = $("<a>")
|
||||
.addClass("btn list-group-item list-group-item-action")
|
||||
for (let file of recent_files) {
|
||||
let recent_file_link = $("<button>")
|
||||
.addClass("list-group-item list-group-item-action d-flex justify-content-between align-items-center")
|
||||
.text(file.replace(/^.*[\\\/]/, ''))
|
||||
.attr({"data-bs-toggle": "tooltip", "data-bs-placement": "bottom", "title": file})
|
||||
.on("click", () => {
|
||||
ipcRenderer.send("open", file);
|
||||
});
|
||||
})
|
||||
.append($("<a>")
|
||||
.addClass("btn-close")
|
||||
.on("click", () => {
|
||||
recent_file_link.remove();
|
||||
removeRecentFile(file);
|
||||
}));
|
||||
$("#recent-files").append(recent_file_link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function removeRecentFile(file) {
|
||||
await ipcRenderer.invoke("remove-recent-file", file);
|
||||
showRecentFiles();
|
||||
}
|
||||
|
||||
showRecentFiles();
|
||||
|
||||
$("#create-new").on("click", () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user