shows modified status in the window title

This commit is contained in:
hneemann 2019-09-28 09:21:49 +02:00
parent 34ada97add
commit 6fd75f5705
3 changed files with 18 additions and 9 deletions

View File

@ -79,15 +79,18 @@ public class TruthTableTableModel implements TableModel {
else else
setValue(rowIndex, columnIndex, 2); setValue(rowIndex, columnIndex, 2);
} }
fireModelEvent(rowIndex);
} }
private void setValue(int rowIndex, int columnIndex, int val) { private void setValue(int rowIndex, int columnIndex, int val) {
int actVal = undoManager.getActual().getValue(rowIndex, columnIndex);
if (actVal != val) {
try { try {
undoManager.apply(truthTable -> truthTable.setValue(rowIndex, columnIndex, val)); undoManager.apply(truthTable -> truthTable.setValue(rowIndex, columnIndex, val));
} catch (ModifyException e) { } catch (ModifyException e) {
e.printStackTrace(); e.printStackTrace();
} }
fireModelEvent(rowIndex);
}
} }
private void fireModelEvent(int rowIndex) { private void fireModelEvent(int rowIndex) {

View File

@ -327,14 +327,17 @@ public class TableDialog extends JDialog {
} }
} }
}.setAcceleratorCTRLplus("Y"); }.setAcceleratorCTRLplus("Y");
edit.add(undo.createJMenuItem()); edit.add(undo.createJMenuItem());
edit.add(redo.createJMenuItem()); edit.add(redo.createJMenuItem());
undoManager.addListener(() -> { undoManager.addListener(() -> {
undo.setEnabled(undoManager.undoAvailable()); undo.setEnabled(undoManager.undoAvailable());
redo.setEnabled(undoManager.redoAvailable()); redo.setEnabled(undoManager.redoAvailable());
}); if (undoManager.isModified())
undo.setEnabled(undoManager.undoAvailable()); setTitle("*" + Lang.get("win_table"));
redo.setEnabled(undoManager.redoAvailable()); else
setTitle(Lang.get("win_table"));
}).hasChanged();
} }
/** /**

View File

@ -45,6 +45,7 @@ public class UndoManager<A extends Copyable<A>> {
modifications = new ArrayList<>(); modifications = new ArrayList<>();
modificationCounter = 0; modificationCounter = 0;
savedCounter = 0; savedCounter = 0;
fireChangedEvent();
} }
@ -187,9 +188,11 @@ public class UndoManager<A extends Copyable<A>> {
* Adds a listener * Adds a listener
* *
* @param listener the listener to add * @param listener the listener to add
* @return the given listener for chained calls.
*/ */
public void addListener(ChangedListener listener) { public ChangedListener addListener(ChangedListener listener) {
listeners.add(listener); listeners.add(listener);
return listener;
} }
/** /**