Skip to content

Commit

Permalink
shortcut for reopen closed file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogefest committed Sep 29, 2021
1 parent 71812ed commit dbe1627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/notepack/app/domain/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class App {
private Theme theme;
private ClipboardManager clipboardManager;
private ArrayList<Note> activeNotes = new ArrayList<>();
private ArrayList<Note> archiveNotes = new ArrayList<>();
private ArrayList<Workspace> activeWorkspace = new ArrayList<>();
private ArrayList<Todo> activeTodo = new ArrayList<>();

Expand All @@ -40,11 +41,16 @@ public App(SessionStorage sessionStorage, Settings settings) {
@Override
public void onOpen(Note n) {
activeNotes.add(n);
int index = archiveNotes.indexOf(n);
if (index >= 0) {
archiveNotes.remove(index);
}
}

@Override
public void onClose(Note n) {
activeNotes.remove(n);
archiveNotes.add(n);
}

@Override
Expand Down Expand Up @@ -100,6 +106,12 @@ public void addTask(Task task) {
messageBus.addTask(task);
}

public void reopenLastClosedNote() {
if (archiveNotes.size() > 0) {
messageBus.addTask(new NoteOpen(archiveNotes.get(archiveNotes.size() - 1)));
}
}

public void openNote(String path, Workspace workspace, String name) {
Note note = new Note(path, workspace, name);
messageBus.addTask(new NoteOpen(note));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/notepack/app/task/InitializeShortcuts.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public void guiWork(TaskUtil taskUtil, App app) {
KeyCombination kcCloseNote = new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN);
notes.getScene().getAccelerators().put(kcCloseNote, () -> app.addTask(new NoteClose(taskUtil.getCurrentNote())));

KeyCombination kcReopenNote = new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN);
notes.getScene().getAccelerators().put(kcReopenNote, () -> app.reopenLastClosedNote());

KeyCombination kcTodoNote = new KeyCodeCombination(KeyCode.T, KeyCombination.CONTROL_DOWN);
notes.getScene().getAccelerators().put(kcTodoNote, () -> {
Tab t = taskUtil.getNotesContainer().getSelectionModel().getSelectedItem();
Expand Down

0 comments on commit dbe1627

Please sign in to comment.