package org.jabref.gui.edit;

import javafx.scene.control.TextInputControl;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
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;

            this.executable.bind(ActionHelper.needsEntriesSelected(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:
                            frame.getCurrentBasePanel().paste();
                            break;
                        case DELETE_ENTRY:
                            frame.getCurrentBasePanel().delete(false);
                            break;
                        default:
                            throw new IllegalStateException("Only cut/copy/paste supported but got " + action);
                    }
                }
        });
    }
}

@@ -536,20 +536,16 @@
 mand %7B%0A%0A
-    
     priv
@@ -573,28 +573,24 @@
  frame;%0A    
-  
-  
 private fina
@@ -611,28 +611,24 @@
 ons action;%0A
-    
     private 
@@ -657,28 +657,24 @@
 teManager;%0A%0A
-    
     public E
@@ -759,28 +759,24 @@
 ) %7B%0A        
-    
 this.action 
@@ -789,28 +789,24 @@
 on;%0A        
-   
- 
 this.frame =
@@ -813,20 +813,16 @@
  frame;%0A
-    
         
@@ -856,20 +856,16 @@
 nager;%0A%0A
-    
         
@@ -935,35 +935,27 @@
 ager));%0A    
-   
- 
 %7D%0A%0A
-    
     @Overrid
@@ -948,36 +948,32 @@
 %0A%0A    @Override%0A
-    
     public Strin
@@ -995,20 +995,16 @@
         
-  
-  
 return t
@@ -1030,27 +1030,19 @@
 ();%0A    
-    %7D%0A%0A    
+%7D%0A%0A
     @Ove
@@ -1051,20 +1051,16 @@
 ide%0A    
-  
-  
 public v
@@ -1071,28 +1071,24 @@
 execute() %7B%0A
-    
         stat
@@ -1150,20 +1150,16 @@
         
-    
 if (focu
@@ -1212,20 +1212,16 @@
         
- 
-   
 // Focus
@@ -1270,20 +1270,16 @@
 ed text%0A
-    
         
@@ -1354,36 +1354,32 @@
                 
-    
 switch (action) 
@@ -1392,36 +1392,32 @@
                 
- 
-   
 case COPY:%0A     
@@ -1403,36 +1403,32 @@
      case COPY:%0A
-    
                 
@@ -1445,36 +1445,32 @@
 xtInput.copy();%0A
-    
                 
@@ -1496,36 +1496,32 @@
                 
-    
 case CUT:%0A      
@@ -1506,36 +1506,32 @@
       case CUT:%0A
-    
                 
@@ -1547,36 +1547,32 @@
 extInput.cut();%0A
-    
                 
@@ -1598,36 +1598,32 @@
                 
-    
 case PASTE:%0A    
@@ -1610,36 +1610,32 @@
     case PASTE:%0A
-    
                 
@@ -1701,36 +1701,32 @@
                 
-   
- 
 break;%0A         
@@ -1728,32 +1728,198 @@
                 
+case DELETE_ENTRY:%0A                        // DELETE_ENTRY in text field should do forward delete%0A                        textInput.deleteNextChar();%0A                
     default:%0A   
@@ -1911,35 +1911,24 @@
    default:%0A
-           
             
@@ -1924,32 +1924,39 @@
                 
+       
 throw new Illega
@@ -2055,34 +2055,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -2082,20 +2082,16 @@
  else %7B%0A
-    
         
@@ -2163,20 +2163,16 @@
 ntries%0A%0A
-    
         
@@ -2257,36 +2257,32 @@
                 
-    
 switch (action) 
@@ -2295,36 +2295,32 @@
                 
-    
 case COPY:%0A     
@@ -2306,36 +2306,32 @@
      case COPY:%0A
-    
                 
@@ -2394,39 +2394,31 @@
             
-    
 break;%0A
-    
             
@@ -2451,36 +2451,32 @@
                 
-   
- 
 frame.getCurrent
@@ -2514,39 +2514,31 @@
             
-    
 break;%0A
-    
             
@@ -2573,36 +2573,32 @@
                 
-   
- 
 frame.getCurrent
@@ -2638,39 +2638,31 @@
             
-    
 break;%0A
-    
             
@@ -2704,36 +2704,32 @@
                 
-  
-  
 frame.getCurrent
@@ -2775,39 +2775,31 @@
             
-    
 break;%0A
-    
             
@@ -2831,36 +2831,32 @@
                 
- 
-   
 throw new Illega
@@ -2935,34 +2935,26 @@
             
-    %7D%0A    
+%7D%0A
             

Update EditAction.java