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
setValue(rowIndex, columnIndex, 2);
}
fireModelEvent(rowIndex);
}
private void setValue(int rowIndex, int columnIndex, int val) {
int actVal = undoManager.getActual().getValue(rowIndex, columnIndex);
if (actVal != val) {
try {
undoManager.apply(truthTable -> truthTable.setValue(rowIndex, columnIndex, val));
} catch (ModifyException e) {
e.printStackTrace();
}
fireModelEvent(rowIndex);
}
}
private void fireModelEvent(int rowIndex) {

View File

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

View File

@ -45,6 +45,7 @@ public class UndoManager<A extends Copyable<A>> {
modifications = new ArrayList<>();
modificationCounter = 0;
savedCounter = 0;
fireChangedEvent();
}
@ -187,9 +188,11 @@ public class UndoManager<A extends Copyable<A>> {
* Adds a listener
*
* @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);
return listener;
}
/**