30
30
import javafx .scene .control .SplitPane ;
31
31
import javafx .scene .control .Tab ;
32
32
import javafx .scene .control .TabPane ;
33
- import javafx .scene .control .TextInputControl ;
34
33
import javafx .scene .control .ToolBar ;
35
34
import javafx .scene .control .Tooltip ;
36
35
import javafx .scene .control .skin .TabPaneSkin ;
@@ -487,13 +486,13 @@ private Node createToolbar() {
487
486
factory .createIconButton (StandardActions .NEW_ARTICLE , new NewEntryAction (this , StandardEntryType .Article , dialogService , Globals .prefs , stateManager )),
488
487
factory .createIconButton (StandardActions .NEW_ENTRY , new NewEntryAction (this , dialogService , Globals .prefs , stateManager )),
489
488
factory .createIconButton (StandardActions .NEW_ENTRY_FROM_PLAIN_TEXT , new ExtractBibtexAction (stateManager )),
490
- factory .createIconButton (StandardActions .DELETE_ENTRY , new OldDatabaseCommandWrapper ( Actions . DELETE , this , stateManager )),
489
+ factory .createIconButton (StandardActions .DELETE_ENTRY , new EditAction ( StandardActions . DELETE_ENTRY , this , stateManager )),
491
490
new Separator (Orientation .VERTICAL ),
492
491
factory .createIconButton (StandardActions .UNDO , new OldDatabaseCommandWrapper (Actions .UNDO , this , stateManager )),
493
492
factory .createIconButton (StandardActions .REDO , new OldDatabaseCommandWrapper (Actions .REDO , this , stateManager )),
494
- factory .createIconButton (StandardActions .CUT , new OldDatabaseCommandWrapper ( Actions .CUT , this , stateManager )),
495
- factory .createIconButton (StandardActions .COPY , new OldDatabaseCommandWrapper ( Actions .COPY , this , stateManager )),
496
- factory .createIconButton (StandardActions .PASTE , new OldDatabaseCommandWrapper ( Actions .PASTE , this , stateManager )),
493
+ factory .createIconButton (StandardActions .CUT , new EditAction ( StandardActions .CUT ,this , stateManager )),
494
+ factory .createIconButton (StandardActions .COPY , new EditAction ( StandardActions .COPY ,this , stateManager )),
495
+ factory .createIconButton (StandardActions .PASTE , new EditAction ( StandardActions .PASTE ,this , stateManager )),
497
496
new Separator (Orientation .VERTICAL ),
498
497
pushToApplicationButton ,
499
498
factory .createIconButton (StandardActions .GENERATE_CITE_KEYS , new OldDatabaseCommandWrapper (Actions .MAKE_KEY , this , stateManager )),
@@ -577,6 +576,9 @@ public void init() {
577
576
}
578
577
});
579
578
579
+ // Wait for the scene to be created, otherwise focusOwnerProperty is not provided
580
+ Platform .runLater (() -> stateManager .focusOwnerProperty ().bind (
581
+ EasyBind .map (mainStage .getScene ().focusOwnerProperty (), Optional ::ofNullable )));
580
582
/*
581
583
* The following state listener makes sure focus is registered with the
582
584
* correct database when the user switches tabs. Without this,
@@ -701,9 +703,9 @@ private MenuBar createMenu() {
701
703
702
704
new SeparatorMenuItem (),
703
705
704
- factory .createMenuItem (StandardActions .CUT , new EditAction (Actions .CUT )),
706
+ factory .createMenuItem (StandardActions .CUT , new EditAction (StandardActions .CUT , this , stateManager )),
705
707
706
- factory .createMenuItem (StandardActions .COPY , new EditAction (Actions .COPY )),
708
+ factory .createMenuItem (StandardActions .COPY , new EditAction (StandardActions .COPY , this , stateManager )),
707
709
factory .createSubMenu (StandardActions .COPY_MORE ,
708
710
factory .createMenuItem (StandardActions .COPY_TITLE , new CopyMoreAction (StandardActions .COPY_TITLE , dialogService , stateManager , Globals .clipboardManager , prefs )),
709
711
factory .createMenuItem (StandardActions .COPY_KEY , new CopyMoreAction (StandardActions .COPY_KEY , dialogService , stateManager , Globals .clipboardManager , prefs )),
@@ -713,7 +715,7 @@ private MenuBar createMenu() {
713
715
factory .createMenuItem (StandardActions .COPY_CITATION_PREVIEW , new CopyCitationAction (CitationStyleOutputFormat .HTML , dialogService , stateManager , Globals .clipboardManager , prefs .getPreviewPreferences ())),
714
716
factory .createMenuItem (StandardActions .EXPORT_SELECTED_TO_CLIPBOARD , new ExportToClipboardAction (this , dialogService ))),
715
717
716
- factory .createMenuItem (StandardActions .PASTE , new EditAction (Actions .PASTE )),
718
+ factory .createMenuItem (StandardActions .PASTE , new EditAction (StandardActions .PASTE , this , stateManager )),
717
719
718
720
new SeparatorMenuItem (),
719
721
@@ -743,7 +745,7 @@ private MenuBar createMenu() {
743
745
library .getItems ().addAll (
744
746
factory .createMenuItem (StandardActions .NEW_ENTRY , new NewEntryAction (this , dialogService , Globals .prefs , stateManager )),
745
747
factory .createMenuItem (StandardActions .NEW_ENTRY_FROM_PLAIN_TEXT , new ExtractBibtexAction (stateManager )),
746
- factory .createMenuItem (StandardActions .DELETE_ENTRY , new OldDatabaseCommandWrapper ( Actions . DELETE , this , stateManager )),
748
+ factory .createMenuItem (StandardActions .DELETE_ENTRY , new EditAction ( StandardActions . DELETE_ENTRY , this , stateManager )),
747
749
748
750
new SeparatorMenuItem (),
749
751
@@ -1244,63 +1246,6 @@ public void execute() {
1244
1246
}
1245
1247
}
1246
1248
1247
- /**
1248
- * Class for handling general actions; cut, copy and paste. The focused component is kept track of by
1249
- * Globals.focusListener, and we call the action stored under the relevant name in its action map.
1250
- */
1251
- private class EditAction extends SimpleCommand {
1252
-
1253
- private final Actions command ;
1254
-
1255
- public EditAction (Actions command ) {
1256
- this .command = command ;
1257
- }
1258
-
1259
- @ Override
1260
- public String toString () {
1261
- return this .command .toString ();
1262
- }
1263
-
1264
- @ Override
1265
- public void execute () {
1266
- Node focusOwner = mainStage .getScene ().getFocusOwner ();
1267
- if (focusOwner != null ) {
1268
- if (focusOwner instanceof TextInputControl ) {
1269
- // Focus is on text field -> copy/paste/cut selected text
1270
- TextInputControl textInput = (TextInputControl ) focusOwner ;
1271
- switch (command ) {
1272
- case COPY :
1273
- textInput .copy ();
1274
- break ;
1275
- case CUT :
1276
- textInput .cut ();
1277
- break ;
1278
- case PASTE :
1279
- // handled by FX in TextInputControl#paste
1280
- break ;
1281
- default :
1282
- throw new IllegalStateException ("Only cut/copy/paste supported but got " + command );
1283
- }
1284
- } else {
1285
- // Not sure what is selected -> copy/paste/cut selected entries
1286
- switch (command ) {
1287
- case COPY :
1288
- getCurrentBasePanel ().copy ();
1289
- break ;
1290
- case CUT :
1291
- getCurrentBasePanel ().cut ();
1292
- break ;
1293
- case PASTE :
1294
- // handled by FX in TextInputControl#paste
1295
- break ;
1296
- default :
1297
- throw new IllegalStateException ("Only cut/copy/paste supported but got " + command );
1298
- }
1299
- }
1300
- }
1301
- }
1302
- }
1303
-
1304
1249
private class CloseDatabaseAction extends SimpleCommand {
1305
1250
1306
1251
@ Override
0 commit comments