forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted BaseAction out of EditAction
- Loading branch information
Showing
8 changed files
with
98 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.jabref.gui; | ||
|
||
import javafx.scene.control.TextInputControl; | ||
|
||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.actions.StandardActions; | ||
|
||
/** | ||
* Class for handling general actions; cut, copy and paste. The focused component is kept track of by | ||
* Globals.focusListener, and we call the action stored under the relevant name in its action map. | ||
*/ | ||
public class EditAction extends SimpleCommand { | ||
|
||
private final JabRefFrame frame; | ||
private final StandardActions action; | ||
private final StateManager stateManager; | ||
|
||
public EditAction(StandardActions action, JabRefFrame frame, StateManager stateManager) { | ||
this.action = action; | ||
this.frame = frame; | ||
this.stateManager = stateManager; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.action.toString(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
stateManager.getFocusOwner().ifPresent(focusOwner -> { | ||
if (focusOwner instanceof TextInputControl) { | ||
// Focus is on text field -> copy/paste/cut selected text | ||
TextInputControl textInput = (TextInputControl) focusOwner; | ||
switch (action) { | ||
case COPY: | ||
textInput.copy(); | ||
break; | ||
case CUT: | ||
textInput.cut(); | ||
break; | ||
case PASTE: | ||
// handled by FX in TextInputControl#paste | ||
break; | ||
default: | ||
throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action); | ||
} | ||
} else { | ||
// Not sure what is selected -> copy/paste/cut selected entries | ||
|
||
// ToDo: Should be handled by BibDatabaseContext instead of BasePanel | ||
switch (action) { | ||
case COPY: | ||
frame.getCurrentBasePanel().copy(); | ||
break; | ||
case CUT: | ||
frame.getCurrentBasePanel().cut(); | ||
break; | ||
case PASTE: | ||
// handled by FX in TextInputControl#paste | ||
break; | ||
case DELETE_ENTRY: | ||
frame.getCurrentBasePanel().delete(false); | ||
break; | ||
default: | ||
throw new IllegalStateException("Only cut/copy/paste supported but got " + action); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
src/main/java/org/jabref/gui/actions/OldCommandWrapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters