Skip to content

Commit

Permalink
Added information in the tool tip for undo and redo and disabled when…
Browse files Browse the repository at this point in the history
… no undo/redo is available
  • Loading branch information
oscargus committed Jul 26, 2016
1 parent 0075cc5 commit f69b7ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe
// AutoCompleter used in the search bar
private AutoCompleter<String> searchAutoCompleter;
// The undo manager.
private final CountingUndoManager undoManager = new CountingUndoManager(this);
private final UndoAction undoAction = new UndoAction();

private final RedoAction redoAction = new RedoAction();
private final CountingUndoManager undoManager = new CountingUndoManager(this);

private final List<BibEntry> previousEntries = new ArrayList<>();

private final List<BibEntry> nextEntries = new ArrayList<>();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2247,4 +2247,20 @@ public void setFetcherToggle(boolean enabled) {
public void setPreviewToggle(boolean enabled) {
previewToggle.setSelected(enabled);
}

public void setUndoText(String undoPresentationName) {
undo.putValue(Action.SHORT_DESCRIPTION, undoPresentationName);
}

public void setRedoText(String undoPresentationName) {
redo.putValue(Action.SHORT_DESCRIPTION, undoPresentationName);
}

public void enableUndo(boolean value) {
undo.setEnabled(value);
}

public void enableRedo(boolean value) {
redo.setEnabled(value);
}
}
32 changes: 30 additions & 2 deletions src/main/java/net/sf/jabref/gui/undo/CountingUndoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package net.sf.jabref.gui.undo;

import java.util.Objects;

import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
import javax.swing.undo.UndoableEdit;

import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.logic.l10n.Localization;

public class CountingUndoManager extends UndoManager {

Expand All @@ -30,26 +33,31 @@ public class CountingUndoManager extends UndoManager {

public CountingUndoManager(BasePanel basePanel) {
super();
panel = basePanel;
panel = Objects.requireNonNull(basePanel);
updateTexts();
}

@Override
public synchronized boolean addEdit(UndoableEdit edit) {
current++;
return super.addEdit(edit);
boolean returnvalue = super.addEdit(edit);
updateTexts();
return returnvalue;
}

@Override
public synchronized void undo() throws CannotUndoException {
super.undo();
current--;
updateTexts();
panel.updateEntryEditorIfShowing();
}

@Override
public synchronized void redo() throws CannotUndoException {
super.redo();
current++;
updateTexts();
panel.updateEntryEditorIfShowing();
}

Expand All @@ -60,4 +68,24 @@ public synchronized void markUnchanged() {
public synchronized boolean hasChanged() {
return (current != unchangedPoint);
}

private void updateTexts() {
if (panel.frame() != null) {
if (super.canUndo()) {
panel.frame().setUndoText(super.editToBeUndone().getUndoPresentationName());
panel.frame().enableUndo(true);
} else {
panel.frame().setUndoText(Localization.lang("Undo"));
panel.frame().enableUndo(false);
}

if (super.canRedo()) {
panel.frame().setRedoText(super.editToBeRedone().getRedoPresentationName());
panel.frame().enableRedo(true);
} else {
panel.frame().setRedoText(Localization.lang("Redo"));
panel.frame().enableRedo(false);
}
}
}
}

0 comments on commit f69b7ea

Please sign in to comment.