Skip to content

Commit 62e6a05

Browse files
committed
do some code polishing
1 parent 39ea298 commit 62e6a05

5 files changed

Lines changed: 68 additions & 64 deletions

File tree

src/main/java/gr/sqlbrowserfx/nodes/FileSearchPopOver.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ protected void updateItem(String item, boolean empty) {
7171
}
7272
}
7373
});
74-
filesListView.setPrefSize(600, 400);
74+
filesListView.setPrefSize(800, 500);
7575

7676
searchField = new TextField();
7777
// searchField.setPrefWidth(576);
78-
searchField.setPromptText("Search for file...");
78+
searchField.setPromptText("Search for file (syntax: <pattern>.<suffix>)...");
7979
searchField.setOnKeyPressed(keyEvent -> {
8080
if (keyEvent.getCode() == KeyCode.ENTER) {
8181
search();
@@ -125,6 +125,10 @@ protected void updateItem(String item, boolean empty) {
125125
String filePath = filesListView.getSelectionModel().getSelectedItem();
126126
action.run(new File(filePath));
127127
}
128+
129+
if (keyEvent.getCode() == KeyCode.ESCAPE) {
130+
this.hide();
131+
}
128132
});
129133
filesListView.setOnMouseClicked(mouseEvent -> {
130134
if (mouseEvent.getClickCount() == 2) {
@@ -148,7 +152,7 @@ private void search() {
148152

149153
executor = Executors.newSingleThreadScheduledExecutor();
150154
executor.schedule(() -> {
151-
Set<String> filesPathsFound = FilesUtils.walk(rootPath, pattern);
155+
Set<String> filesPathsFound = FilesUtils.walk(rootPath, pattern, 10);
152156
Platform.runLater(() -> {
153157
filesListView.setItems(FXCollections.observableArrayList(filesPathsFound));
154158
searchField.setDisable(false);

src/main/java/gr/sqlbrowserfx/nodes/FilesTreeView.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@
4242

4343
public class FilesTreeView extends TreeView<TreeViewFile> implements ContextMenuOwner, InputMapOwner {
4444

45-
private final String rootPath;
45+
@FunctionalInterface
46+
public interface Action {
47+
void run(File selectedFile);
48+
}
49+
50+
private Action action;
51+
private String rootPath;
4652
private TreeItem<TreeViewFile> rootItem, selectedRootItem;
4753

4854
private final SimpleBooleanProperty isFileProperty = new SimpleBooleanProperty(false);
@@ -122,13 +128,33 @@ public FilesTreeView(String rootPath) {
122128
});
123129
this.setInputMap();
124130
}
131+
132+
public void setOnFileOpen(Action action) {
133+
this.action = action;
134+
}
125135

126136
private void openSelectedFile() {
127137
var file = this.getSelectionModel().getSelectedItem().getValue().asFile();
128138

129139
if (file.isFile()) {
130-
var sqlConsolePane = SqlBrowserFXAppManager.getFirstActiveDSqlConsolePane();
131-
sqlConsolePane.openNewFileTab(file);
140+
if (action != null) {
141+
action.run(file);
142+
}
143+
else {
144+
var sqlConsolePane = SqlBrowserFXAppManager.getFirstActiveDSqlConsolePane();
145+
sqlConsolePane.openNewFileTab(file);
146+
}
147+
}
148+
}
149+
150+
private void openSelectedFileAsFile() {
151+
var file = this.getSelectionModel().getSelectedItem().getValue().asFile();
152+
153+
if (file.isFile()) {
154+
var filesTabPane = SqlBrowserFXAppManager.getFirstActiveFilesTabPane();
155+
if (filesTabPane != null) {
156+
filesTabPane.openNewFileTab(file);
157+
}
132158
}
133159
}
134160

@@ -346,6 +372,12 @@ private void collapseAll(TreeItem<TreeViewFile> treeItem) {
346372
treeItem.setExpanded(false);
347373
}
348374

375+
public void setRootAndRefresh(String rootPath) {
376+
this.rootPath = rootPath;
377+
this.refresh();
378+
379+
}
380+
349381
@Override
350382
public void refresh() {
351383
this.setRoot(this.fillTreeView(rootPath));
@@ -419,6 +451,10 @@ public ContextMenu createContextMenu() {
419451
var openFile = new MenuItem("Open", JavaFXUtils.createIcon("/icons/code-file.png"));
420452
openFile.disableProperty().bind(this.isFileProperty.not());
421453
openFile.setOnAction(event -> this.openSelectedFile());
454+
455+
var openAsFile = new MenuItem("Open As File", JavaFXUtils.createIcon("/icons/code-file.png"));
456+
openAsFile.disableProperty().bind(this.isFileProperty.not());
457+
openAsFile.setOnAction(event -> this.openSelectedFileAsFile());
422458

423459
var newFile = new MenuItem("New File", JavaFXUtils.createIcon("/icons/add.png"));
424460
newFile.disableProperty().bind(this.isFileProperty);
@@ -470,7 +506,7 @@ public ContextMenu createContextMenu() {
470506
restoreRoot.setOnAction(event -> this.setRoot(this.rootItem));
471507
restoreRoot.disableProperty().bind(this.getSelectionModel().selectedItemProperty().isEqualTo(this.rootItem));
472508

473-
contextMenu.getItems().addAll(openFile, new SeparatorMenuItem(),
509+
contextMenu.getItems().addAll(openFile, openAsFile, new SeparatorMenuItem(),
474510
newFile, newDir, renameFile, copyFiles, pasteFiles, deleteFile, new SeparatorMenuItem(),
475511
search, collapseAll, new SeparatorMenuItem(), setAsRoot, refresh, new SeparatorMenuItem(),
476512
restoreRoot);

src/main/java/gr/sqlbrowserfx/nodes/codeareas/AutoCompleteCodeArea.java

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import gr.sqlbrowserfx.nodes.ContextMenuOwner;
2727
import gr.sqlbrowserfx.nodes.InputMapOwner;
2828
import gr.sqlbrowserfx.nodes.SearchAndReplacePopOver;
29-
import gr.sqlbrowserfx.nodes.SearchInFilesPopOver;
3029
import gr.sqlbrowserfx.nodes.codeareas.sql.SimpleLineNumberFactory;
3130
import gr.sqlbrowserfx.utils.JavaFXUtils;
3231
import javafx.application.Platform;
@@ -59,7 +58,6 @@ public abstract class AutoCompleteCodeArea<T extends CodeAreaSyntaxProvider> ext
5958
private ListView<Keyword> suggestionsList;
6059
private Popup autoCompletePopup;
6160
protected SearchAndReplacePopOver searchAndReplacePopOver;
62-
protected SearchInFilesPopOver searchInFilesPopOver;
6361
private final SimpleBooleanProperty showLinesProperty = new SimpleBooleanProperty(true);
6462
private final SimpleBooleanProperty autoCompleteProperty = new SimpleBooleanProperty(true);
6563
private final SimpleBooleanProperty isTextSelectedProperty = new SimpleBooleanProperty(false);
@@ -110,10 +108,6 @@ protected Boolean isAutoCompletePopupShowing() {
110108
return this.autoCompletePopup != null && this.autoCompletePopup.isShowing();
111109
}
112110

113-
protected Boolean isSearchInFilesPopOverShowing() {
114-
return this.searchInFilesPopOver != null && this.searchInFilesPopOver.isShowing();
115-
}
116-
117111
protected Boolean isSearchAndReplacePopOverShowing() {
118112
return this.searchAndReplacePopOver != null && this.searchAndReplacePopOver.isShowing();
119113
}
@@ -124,10 +118,6 @@ protected void onMouseClicked() {
124118
hideAutocompletePopup();
125119
}
126120

127-
if (isSearchInFilesPopOverShowing()) {
128-
searchInFilesPopOver.hide();
129-
}
130-
131121
if (isSearchAndReplacePopOverShowing()) {
132122
searchAndReplacePopOver.hide();
133123
}
@@ -232,15 +222,11 @@ public void setInputMap() {
232222
action -> this.replaceSelection("(" + getSelectedText() + ")"));
233223

234224

235-
var searchInFiles = InputMap.consume(
236-
EventPattern.keyPressed(KeyCode.H, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN),
237-
action -> this.showSearchInFilesPopup());
238225

239226
Nodes.addFallbackInputMap(this, addTabs);
240227
Nodes.addFallbackInputMap(this, removeTabs);
241228
Nodes.addInputMap(this, autocomplete);
242229
Nodes.addInputMap(this, searchAndReplace);
243-
Nodes.addInputMap(this, searchInFiles);
244230
Nodes.addInputMap(this, delete);
245231
Nodes.addInputMap(this, toUpper);
246232
Nodes.addInputMap(this, toLower);
@@ -267,25 +253,25 @@ private void setKeys() {
267253
// FIXME Desired behaviour can't be achieved with input map autocomplete popover
268254
// does not hide.
269255
// Use traditional javafx way for this specific case
270-
this.setOnKeyPressed(keyEvent -> {
271-
if (keyEvent.isControlDown() && (keyEvent.getCode() == KeyCode.MINUS || keyEvent.getCode() == KeyCode.EQUALS)) {
272-
// do not consume event to enable global zoom in/out (if applied)
273-
return;
274-
}
275-
if (keyEvent.getCode() == KeyCode.LEFT || keyEvent.getCode() == KeyCode.RIGHT) {
276-
this.hideAutocompletePopup();
277-
}
278-
if (keyEvent.getCode() == KeyCode.BACK_SPACE) {
279-
this.hideAutocompletePopup();
280-
// uncomment this to activate autocomplete on backspace
281-
// this.autoCompleteAction(keyEvent, auoCompletePopup);
282-
}
283-
// These keycodes must be excluded to delegate event to queries tab pane
284-
if (keyEvent.getCode() != KeyCode.ESCAPE && keyEvent.getCode() != KeyCode.N
285-
&& keyEvent.getCode() != KeyCode.O) {
286-
keyEvent.consume();
287-
}
288-
});
256+
// this.setOnKeyPressed(keyEvent -> {
257+
// if (keyEvent.isControlDown() && (keyEvent.getCode() == KeyCode.MINUS || keyEvent.getCode() == KeyCode.EQUALS)) {
258+
// // do not consume event to enable global zoom in/out (if applied)
259+
// return;
260+
// }
261+
// if (keyEvent.getCode() == KeyCode.LEFT || keyEvent.getCode() == KeyCode.RIGHT) {
262+
// this.hideAutocompletePopup();
263+
// }
264+
// if (keyEvent.getCode() == KeyCode.BACK_SPACE) {
265+
// this.hideAutocompletePopup();
266+
// // uncomment this to activate autocomplete on backspace
267+
//// this.autoCompleteAction(keyEvent, auoCompletePopup);
268+
// }
269+
// // These keycodes must be excluded to delegate event to queries tab pane
270+
// if (keyEvent.getCode() != KeyCode.ESCAPE && keyEvent.getCode() != KeyCode.N
271+
// && keyEvent.getCode() != KeyCode.O) {
272+
// keyEvent.consume();
273+
// }
274+
// });
289275
this.setOnKeyTyped(keyEvent -> {
290276
if (
291277
this.autoCompleteProperty.get() &&
@@ -323,14 +309,6 @@ protected void showSearchAndReplacePopup() {
323309
searchAndReplacePopOver.show(getParent(), boundsInScene.getMaxX() - 400, boundsInScene.getMinY());
324310
}
325311

326-
protected void showSearchInFilesPopup() {
327-
var boundsInScene = this.localToScreen(this.getBoundsInLocal());
328-
if (this.searchInFilesPopOver == null) {
329-
this.searchInFilesPopOver = new SearchInFilesPopOver();
330-
}
331-
this.searchInFilesPopOver.show(getParent(), boundsInScene.getMinX(), boundsInScene.getMinY());
332-
}
333-
334312
// FIXME: we override copy method as it the default method seems broken for strings containing '{' or '}'
335313
@Override
336314
public void copy() {
@@ -362,9 +340,6 @@ public ContextMenu createContextMenu() {
362340

363341
var menuItemSearchAndReplace = new MenuItem("Search...", JavaFXUtils.createIcon("/icons/magnify.png"));
364342
menuItemSearchAndReplace.setOnAction(action -> this.showSearchAndReplacePopup());
365-
366-
var menuItemSearchInFiles = new MenuItem("Search In Files...", JavaFXUtils.createIcon("/icons/magnify.png"));
367-
menuItemSearchInFiles.setOnAction(action -> this.showSearchInFilesPopup());
368343

369344
var menuItemUperCase = new MenuItem("To Upper Case", JavaFXUtils.createIcon("/icons/uppercase.png"));
370345
menuItemUperCase.setOnAction(action -> this.convertSelectedTextToUpperCase());
@@ -418,7 +393,7 @@ public ContextMenu createContextMenu() {
418393
new SeparatorMenuItem(),
419394
menuItemFormat, menuItemFormat3,
420395
new SeparatorMenuItem(),
421-
menuItemSearchAndReplace, menuItemSearchInFiles, menuItemGoToLine, menuItemSuggestions,
396+
menuItemSearchAndReplace, menuItemGoToLine, menuItemSuggestions,
422397
new SeparatorMenuItem(),
423398
menuItemSaveAs);
424399
return menu;

src/main/java/gr/sqlbrowserfx/nodes/codeareas/java/JavaCodeAreaSyntaxProvider.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,8 @@ public class JavaCodeAreaSyntaxProvider implements CodeAreaSyntaxProvider<String
6363
+ "|(?<FUNCTION>" + FUNCTIONS_PATTERN + ")"
6464
);
6565

66-
public static void init(String dbType) {
67-
init();
68-
}
69-
70-
private static void init() {
71-
}
7266

73-
74-
@Override
67+
@Override
7568
public Set<Keyword> getKeywords() {
7669
return KEYWORDS_lIST;
7770
}

src/main/java/gr/sqlbrowserfx/nodes/sqlpane/DraggingTabPaneSupport.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
import gr.sqlbrowserfx.utils.JavaFXUtils;
66
import javafx.collections.ListChangeListener.Change;
77
import javafx.scene.Node;
8-
import javafx.scene.control.ContextMenu;
98
import javafx.scene.control.Label;
10-
import javafx.scene.control.MenuItem;
119
import javafx.scene.control.Tab;
1210
import javafx.scene.control.TabPane;
13-
import javafx.scene.control.TextField;
1411
import javafx.scene.input.ClipboardContent;
1512
import javafx.scene.input.Dragboard;
16-
import javafx.scene.input.KeyCode;
1713
import javafx.scene.input.TransferMode;
1814

1915
public class DraggingTabPaneSupport {

0 commit comments

Comments
 (0)