Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klesun authored and klesun committed Jan 10, 2016
1 parent 844cb77 commit 66d0228
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/org/klesun_model/SnapshotStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.common.collect.EvictingQueue;
import org.json.JSONObject;
import org.shmidusic.sheet_music.SheetMusic;

import java.util.ArrayDeque;
import java.util.Deque;
Expand Down Expand Up @@ -34,11 +35,13 @@ public void add(JSONObject snapshot)

public Explain<JSONObject> undo()
{
if (snapshots.size() >= 2) {
if (!snapshots.isEmpty()) {
JSONObject current = snapshots.pollLast();
redoSnapshots.add(current);

return new Explain<>(snapshots.peekLast());
return new Explain<>(!snapshots.isEmpty()
? snapshots.peekLast()
: new SheetMusic().getJsonRepresentation());
} else {
return new Explain<>(false, "Here History Starts");
}
Expand Down
12 changes: 9 additions & 3 deletions src/org/shmidusic/MajesticWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.swing.*;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.*;
import java.util.List;

Expand Down Expand Up @@ -116,7 +117,12 @@ private JMenuItem makeActionMenuItem(Combo key, ContextAction action, Class<? ex
if (context != null) {
Explain explain = action.redo(context);
if (explain.isSuccess()) {
shmidusicPanel.snapshotStorage.add(context.getModel().getJsonRepresentation());
// TODO: ctrl-z/ctrl-y probably should not be normal action at all!
if (!key.equals(new Combo(KeyEvent.CTRL_MASK, KeyEvent.VK_Z)) &&
!key.equals(new Combo(KeyEvent.CTRL_MASK, KeyEvent.VK_Y)))
{
shmidusicPanel.snapshotStorage.add(context.getModel().getJsonRepresentation());
}
updateMenuBar();
} else {
JOptionPane.showMessageDialog(this, explain.getExplanation());
Expand Down Expand Up @@ -156,8 +162,8 @@ private IComponent findFocusedByClass(Class<? extends IComponent> cls)

// the Great idea behind this is to refresh menu bar each time we change focus
// i.e. when we're pointing note we have Menus: [BlockSpace, Scroll, staff, chord, note], when Paragraph - [BlockSpace, Scroll, article, Paragraph] etc
public void updateMenuBar() {

public void updateMenuBar()
{
menus.values().forEach(m -> {
m.setEnabled(false);
m.setToolTipText("Instance Not Focused");
Expand Down

0 comments on commit 66d0228

Please sign in to comment.