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