Browse Source

Implement redo, add a menu for cancel/redo

implement-cancel
Tissevert 7 months ago
parent
commit
93d0e35910
3 changed files with 50 additions and 17 deletions
  1. +10
    -1
      index.html
  2. +39
    -15
      js/GUI/Editor.js
  3. +1
    -1
      js/XML/ALTO.js

+ 10
- 1
index.html View File

@ -17,6 +17,12 @@
<li id="loadScoria" class="disabled">Importer des scories</li>
<li id="saveScoria" class="disabled">Exporter les scories</li>
</ul>
</div><div id="edit" class="menu">
<span>Édition</span>
<ul>
<li id="editCancel" class="disabled">Annuler</li>
<li id="editRedo" class="disabled">Refaire</li>
</ul>
</div><div id="help" class="menu">
<span>Aide</span>
<ul>
@ -43,7 +49,10 @@
<option value="blockOrder">Ordre des blocs</option>
</select>
</span>
<button id="cancel" title="Annuler" disabled></button>
<span>
<button id="cancel" title="Annuler" disabled></button>
<button id="redo" title="Refaire" disabled></button>
</span>
<span id="zoom">
<button id="fitWidth" title="Pleine largeur" ></button>
<input type="number" id="zoomAmount" value="100" step="10" min="30" max="250" title="Zoom"/>


+ 39
- 15
js/GUI/Editor.js View File

@ -1,38 +1,62 @@
import cancel as cancelButton from GUI;
import GUI;
import bind from GUI.Keys;
import toggleWord from Scoria;
var edits = [];
var cursor = -1;
cancelButton.addEventListener('click', cancel);
GUI.cancel.addEventListener('click', cancel);
GUI.editCancel.addEventListener('click', cancel);
GUI.redo.addEventListener('click', redo);
GUI.editRedo.addEventListener('click', redo);
bind('Ctrl+z', cancel);
bind('Ctrl+y', redo);
return {
push: push
};
function cancel() {
var edit = edits.pop();
if(edit != undefined) {
edit.wordIds.forEach(function(wordId) {toggleWord(wordId);});
updateButton();
function cancel(e) {
if(cursor >= 0) {
edits[cursor--].wordIds.forEach(function(wordId) {toggleWord(wordId);});
updateButtons();
} else if(e != undefined) {
e.stopPropagation();
}
}
function redo(e) {
if(cursor < edits.length - 1) {
edits[++cursor].wordIds.forEach(function(wordId) {toggleWord(wordId);});
updateButtons();
} else if(e != undefined) {
e.stopPropagation();
}
}
function push(description, wordIds, perform) {
edits.push({description: description, wordIds: wordIds});
edits.length = ++cursor + 1;
edits[cursor] = {description: description, wordIds: wordIds};
if(perform) {
wordIds.forEach(function(wordId) {toggleWord(wordId);});
}
updateButton();
updateButtons();
}
function updateButton() {
if(edits.length > 0) {
cancelButton.title = 'Annuler ' + edits[edits.length - 1].description;
cancelButton.disabled = false;
function setState(action, disabled) {
if(action == 'redo') {
var label = 'Refaire' + (disabled ? '' : ' ' + edits[cursor + 1].description);
} else {
cancelButton.title = 'Annuler';
cancelButton.disabled = true;
var label = 'Annuler' + (disabled ? '' : ' ' + edits[cursor].description);
}
GUI[action].title = label;
GUI[action].disabled = disabled;
var menuElem = GUI['edit' + action[0].toUpperCase() + action.slice(1)];
menuElem.textContent = label;
menuElem.classList.toggle('disabled', disabled);
}
function updateButtons() {
setState('cancel', cursor < 0);
setState('redo', cursor >= edits.length - 1);
}

+ 1
- 1
js/XML/ALTO.js View File

@ -50,7 +50,7 @@ function setAttributes(element, attributes) {
attributes.onClick = function(e) {
if(GUI.mode.value == 'edit') {
var word = e.target;
var action = isScoria(word.id) ? "la suppression" : "l'ajout"
var action = isScoria(word.id) ? "l'ajout" : "la suppression";
push(action + ' du mot «' + word.textContent + '»', [word.id], true);
}
};


Loading…
Cancel
Save