Commit 1e1beaa3 authored by ransome1's avatar ransome1
Browse files

Fixed add/edit window mix up, added undo and redo for MacOS

parent 3ae947ec
...@@ -226,6 +226,8 @@ function setDueDate(days) { ...@@ -226,6 +226,8 @@ function setDueDate(days) {
} }
function show(todo, templated) { function show(todo, templated) {
try { try {
// remove any previously set data-item attributes
modalForm.removeAttribute("data-item");
// adjust size of recurrence picker input field // adjust size of recurrence picker input field
if(userData.useTextarea) toggleInputSize("input"); if(userData.useTextarea) toggleInputSize("input");
// in case the more toggle menu is open we close it // in case the more toggle menu is open we close it
...@@ -266,7 +268,6 @@ function show(todo, templated) { ...@@ -266,7 +268,6 @@ function show(todo, templated) {
modalTitle.innerHTML = translations.editTodo; modalTitle.innerHTML = translations.editTodo;
btnItemStatus.classList.add("is-active"); btnItemStatus.classList.add("is-active");
} }
//btnItemStatus.classList.add("is-active");
// only show the complete button on open items // only show the complete button on open items
if(todo.complete === false) { if(todo.complete === false) {
btnItemStatus.innerHTML = translations.done; btnItemStatus.innerHTML = translations.done;
...@@ -309,7 +310,7 @@ function submitForm() { ...@@ -309,7 +310,7 @@ function submitForm() {
try { try {
// check if there is an input in the text field, otherwise indicate it to the user // check if there is an input in the text field, otherwise indicate it to the user
// input value and data item are the same, nothing has changed, nothing will be written // input value and data item are the same, nothing has changed, nothing will be written
if (modalForm.getAttribute("data-item")===modalForm.elements[0].value) { if(modalForm.getAttribute("data-item")===modalForm.elements[0].value) {
// close and reset any modal // close and reset any modal
resetModal().then(function(result) { resetModal().then(function(result) {
console.log(result); console.log(result);
...@@ -318,7 +319,7 @@ function submitForm() { ...@@ -318,7 +319,7 @@ function submitForm() {
}); });
return Promise.resolve("Info: Nothing has changed, won't write anything."); return Promise.resolve("Info: Nothing has changed, won't write anything.");
// Edit todo // Edit todo
} else if(modalForm.getAttribute("data-item")!=null) { } else if(modalForm.getAttribute("data-item")) {
// get index of todo // get index of todo
const index = items.objects.map(function(item) {return item.toString(); }).indexOf(modalForm.getAttribute("data-item")); const index = items.objects.map(function(item) {return item.toString(); }).indexOf(modalForm.getAttribute("data-item"));
// create a todo.txt object // create a todo.txt object
......
...@@ -408,17 +408,20 @@ const createWindow = async function() { ...@@ -408,17 +408,20 @@ const createWindow = async function() {
{ {
label: translations.edit, label: translations.edit,
submenu: [ submenu: [
{ role: "undo", accelerator: "CmdOrCtrl+Z" },
{ role: "redo", accelerator: "CmdOrCtrl+Shift+Z" },
{ type: "separator" },
{ label: translations.cut, accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: translations.copy, accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: translations.paste, accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ role: "selectAll", accelerator: "CmdOrCtrl+A" },
{ type: "separator" },
{ {
label: translations.settings, label: translations.settings,
click: function () { click: function () {
mainWindow.webContents.send("triggerFunction", "showContent", ["modalSettings"]); mainWindow.webContents.send("triggerFunction", "showContent", ["modalSettings"]);
} }
}, }
{ type: "separator" },
{ label: translations.cut, accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: translations.copy, accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: translations.paste, accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ role: "selectAll", accelerator: "CmdOrCtrl+A" }
]}, ]},
{ {
label: translations.todos, label: translations.todos,
...@@ -708,7 +711,7 @@ app ...@@ -708,7 +711,7 @@ app
if(appData.channel==="AppImage") autoUpdater.checkForUpdatesAndNotify(); if(appData.channel==="AppImage") autoUpdater.checkForUpdatesAndNotify();
}) })
.on("window-all-closed", () => { .on("window-all-closed", () => {
if(appData.os!=="mac") app.quit() if (process.platform !== "darwin") app.quit()
}) })
.on("activate", () => { .on("activate", () => {
if (BrowserWindow.getAllWindows().length===0) createWindow() if (BrowserWindow.getAllWindows().length===0) createWindow()
......
...@@ -657,7 +657,12 @@ function registerKeyboardShortcuts() { ...@@ -657,7 +657,12 @@ function registerKeyboardShortcuts() {
modal.forEach(function(element) { modal.forEach(function(element) {
element.addEventListener("keydown", function(event) { element.addEventListener("keydown", function(event) {
if(event.key === "Escape" && !autoCompleteContainer.classList.contains("is-active")) { if(event.key === "Escape" && !autoCompleteContainer.classList.contains("is-active")) {
this.classList.remove("is-active"); //this.classList.remove("is-active");
resetModal(this).then(function(result) {
console.log(result);
}).catch(function(error) {
handleError(error);
});
} }
}); });
}); });
...@@ -693,26 +698,27 @@ function resetFilters() { ...@@ -693,26 +698,27 @@ function resetFilters() {
return Promise.reject(error); return Promise.reject(error);
} }
} }
function resetModal() { function resetModal(modal) {
try { try {
if(modal) {
// remove is-active from modal
modal.classList.remove("is-active");
// remove any previously set data-item attributes
modal.removeAttribute("data-item");
}
// reset priority setting // reset priority setting
priorityPicker.selectedIndex = 0; priorityPicker.selectedIndex = 0;
// if recurrence picker was open it is now being closed // if recurrence picker was open it is now being closed
//recurrencePickerContainer.classList.remove("is-active"); recurrencePickerContainer.classList.remove("is-active");
// clear previous recurrence selection // clear previous recurrence selection
//recurrencePickerInput.value = null; recurrencePickerInput.value = null;
// if file chooser was open it is now being closed // if file chooser was open it is now being closed
modalChangeFile.classList.remove("is-active"); modalChangeFile.classList.remove("is-active");
// hide suggestion box if it was open // hide suggestion box if it was open
autoCompleteContainer.classList.remove("is-active"); autoCompleteContainer.classList.remove("is-active");
// remove focus from suggestion container // remove focus from suggestion container
autoCompleteContainer.blur(); autoCompleteContainer.blur();
// defines when the composed filter is being filled with content and when it is emptied // close
//let startComposing = false;
// in case a category will be selected from suggestion box we need to remove the category from input value that has been written already
//let autoCompleteValue = "";
// + or @
//let autoCompletePrefix = "";
modalForm.classList.remove("is-active"); modalForm.classList.remove("is-active");
// remove the data item as we don't need it anymore // remove the data item as we don't need it anymore
modalForm.removeAttribute("data-item"); modalForm.removeAttribute("data-item");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment