Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a delete button to preset #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion src/dat/gui/GUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ common.extend(
});

if (this.autoPlace) {
// Set save row width
// Set save row width and increase to accomodate buttons
this.width += 40;
setWidth(this, this.width);
}
},
Expand Down Expand Up @@ -858,6 +859,17 @@ common.extend(
}
},

deleteSave: function() {
// Not allowed to remove Default preset
if (this.preset === DEFAULT_DEFAULT_PRESET_NAME || !confirm(`Delete preset "${this.preset}". Are you sure?`)) {
return;
}

delete this.load.remembered[this.preset];
this.preset = removeCurrentPresetOption(this);
this.saveToLocalStorageIfPossible();
},

listen: function(controller) {
const init = this.__listening.length === 0;
this.__listening.push(controller);
Expand Down Expand Up @@ -1191,6 +1203,11 @@ function addPresetOption(gui, name, setSelected) {
}
}

function removeCurrentPresetOption(gui) {
gui.__preset_select.removeChild(gui.__preset_select.options[gui.__preset_select.selectedIndex]);
return gui.__preset_select.options[gui.__preset_select.selectedIndex].value;
}

function showHideExplain(gui, explain) {
explain.style.display = gui.useLocalStorage ? 'block' : 'none';
}
Expand Down Expand Up @@ -1224,6 +1241,11 @@ function addSaveMenu(gui) {
dom.addClass(button3, 'button');
dom.addClass(button3, 'revert');

const button4 = document.createElement('span');
button4.innerHTML = 'Delete';
dom.addClass(button4, 'button');
dom.addClass(button4, 'delete');

const select = gui.__preset_select = document.createElement('select');

if (gui.load && gui.load.remembered) {
Expand All @@ -1247,6 +1269,7 @@ function addSaveMenu(gui) {
div.appendChild(button);
div.appendChild(button2);
div.appendChild(button3);
div.appendChild(button4);

if (SUPPORTS_LOCAL_STORAGE) {
const explain = document.getElementById('dg-local-explain');
Expand Down Expand Up @@ -1298,6 +1321,10 @@ function addSaveMenu(gui) {
gui.revert();
});

dom.bind(button4, 'click', function() {
gui.deleteSave();
});

// div.appendChild(button2);
}

Expand Down