Skip to content

Commit

Permalink
Remove GlobalFocusListener and old TextField entry editor (#4336)
Browse files Browse the repository at this point in the history
* Remove GlobalFocusListener and old TextField entry editor

Fixes #4324.

* Add default to switch
  • Loading branch information
tobiasdiez authored Sep 12, 2018
1 parent 7775e05 commit fef1b8a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 339 deletions.
9 changes: 0 additions & 9 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javafx.stage.Screen;

import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.GlobalFocusListener;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
Expand Down Expand Up @@ -60,8 +59,6 @@ public class Globals {
public static ExporterFactory exportFactory;
// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
// Background tasks
private static GlobalFocusListener focusListener;
private static DefaultFileUpdateMonitor fileUpdateMonitor;
private static ThemeLoader themeLoader;
private static TelemetryClient telemetryClient;
Expand All @@ -79,8 +76,6 @@ public static synchronized KeyBindingRepository getKeyPrefs() {

// Background tasks
public static void startBackgroundTasks() {
Globals.focusListener = new GlobalFocusListener();

Globals.fileUpdateMonitor = new DefaultFileUpdateMonitor();
JabRefExecutorService.INSTANCE.executeInterruptableTask(Globals.fileUpdateMonitor, "FileUpdateMonitor");

Expand Down Expand Up @@ -117,10 +112,6 @@ private static void startTelemetryClient() {
telemetryClient.trackSessionState(SessionState.Start);
}

public static GlobalFocusListener getFocusListener() {
return focusListener;
}

public static FileUpdateMonitor getFileUpdateMonitor() {
return fileUpdateMonitor;
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ private void setupActions() {
actions.put(Actions.SAVE_SELECTED_AS_PLAIN, new SaveSelectedAction(SavePreferences.DatabaseSaveType.PLAIN_BIBTEX));

// The action for copying selected entries.
actions.put(Actions.COPY, mainTable::copy);
actions.put(Actions.COPY, this::copy);

actions.put(Actions.PRINT_PREVIEW, new PrintPreviewAction());

actions.put(Actions.CUT, mainTable::cut);
actions.put(Actions.CUT, this::cut);

actions.put(Actions.DELETE, () -> delete(false));

Expand All @@ -319,7 +319,7 @@ private void setupActions() {
// This allows you to (a) paste entire bibtex entries from a text editor, web browser, etc
// (b) copy and paste entries between multiple instances of JabRef (since
// only the text representation seems to get as far as the X clipboard, at least on my system)
actions.put(Actions.PASTE, mainTable::paste);
actions.put(Actions.PASTE, this::paste);

actions.put(Actions.SELECT_ALL, mainTable.getSelectionModel()::selectAll);

Expand Down Expand Up @@ -1379,6 +1379,18 @@ public Path getTempFile() {
return changeMonitor.map(DatabaseChangeMonitor::getTempFile).orElse(null);
}

public void copy() {
mainTable.copy();
}

public void paste() {
mainTable.paste();
}

public void cut() {
mainTable.cut();
}

private static class SearchAndOpenFile {

private final BibEntry entry;
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/org/jabref/gui/GlobalFocusListener.java

This file was deleted.

44 changes: 36 additions & 8 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.awt.Component;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -18,7 +17,6 @@
import java.util.stream.Collectors;

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
Expand All @@ -39,6 +37,7 @@
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextInputControl;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.input.DataFormat;
Expand Down Expand Up @@ -284,8 +283,7 @@ private void init() {
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class));
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
// TODO: Can't notify focus listener since it is expecting a swing component
//Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());

setWindowTitle();
// Update search autocompleter with information for the correct database:
currentBasePanel.updateSearchManager();
Expand Down Expand Up @@ -1442,10 +1440,40 @@ public EditAction(Actions command) {

@Override
public void execute() {
JComponent source = Globals.getFocusListener().getFocused();
Action action = source.getActionMap().get(command);
if (action != null) {
action.actionPerformed(new ActionEvent(source, 0, command.name()));
Node focusOwner = mainStage.getScene().getFocusOwner();
if (focusOwner != null) {
if (focusOwner instanceof TextInputControl) {
// Focus is on text field -> copy/paste/cut selected text
TextInputControl textInput = (TextInputControl) focusOwner;
switch (command) {
case COPY:
textInput.copy();
break;
case CUT:
textInput.cut();
break;
case PASTE:
textInput.paste();
break;
default:
throw new IllegalStateException("Only cut/copy/paste supported but got " + command);
}
} else {
// Not sure what is selected -> copy/paste/cut selected entries
switch (command) {
case COPY:
getCurrentBasePanel().copy();
break;
case CUT:
getCurrentBasePanel().cut();
break;
case PASTE:
getCurrentBasePanel().paste();
break;
default:
throw new IllegalStateException("Only cut/copy/paste supported but got " + command);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import javafx.fxml.Initializable;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;

import com.sun.javafx.scene.control.skin.TextFieldSkin;

public class EditorTextField extends javafx.scene.control.TextField implements Initializable, ContextMenuAddable {
public class EditorTextField extends TextField implements Initializable, ContextMenuAddable {

public EditorTextField() {
this("");
Expand Down
72 changes: 0 additions & 72 deletions src/main/java/org/jabref/gui/fieldeditors/FieldEditor.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit fef1b8a

Please sign in to comment.