Skip to content

Commit c5b60a9

Browse files
committed
Refresh file view improvements
1 parent ec0a2a6 commit c5b60a9

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

src/main/java/com/kodedu/controller/ApplicationController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public void refreshWorkingDir() {
557557
if (currentPath.isPresent()) {
558558
directoryService.changeWorkigDir(currentPath.get());
559559
} else {
560-
fileBrowser.refresh();
560+
fileBrowser.cleanRefresh();
561561
}
562562

563563
}
@@ -3431,4 +3431,8 @@ public void showSupportAsciidocFX() {
34313431
},true);
34323432
}
34333433
}
3434+
3435+
public void refreshFileView(ActionEvent actionEvent) {
3436+
fileBrowser.cleanRefresh();
3437+
}
34343438
}

src/main/java/com/kodedu/service/ui/FileBrowseService.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ public FileBrowseService(final PathOrderService pathOrder, final ThreadService t
6666
this.current = current;
6767
}
6868

69-
public void refresh() {
69+
public void cleanRefresh() {
7070
if (Objects.nonNull(browsedPath)) {
7171
cleanPathMaps();
72+
refresh();
73+
}
74+
}
75+
76+
public void refresh() {
77+
if (Objects.nonNull(browsedPath)) {
7278
browse(browsedPath);
7379
treeView.requestFocus();
7480
}
@@ -179,23 +185,7 @@ public void addPathToTree(Path path, final TreeItem<Item> treeItem, Path changed
179185

180186
restoreTreeSelectionState();
181187

182-
if (Objects.nonNull(changedPath)) {
183-
TreeItem<Item> item = pathItemMap.get(changedPath);
184-
if (Objects.nonNull(item)) {
185-
treeView.getSelectionModel().clearSelection();
186-
treeView.getSelectionModel().select(item);
187-
if (Objects.equals(item, treeView.getSelectionModel().getSelectedItem())) {
188-
treeView.scrollTo(treeView.getSelectionModel().getSelectedIndex());
189-
}
190-
191-
TreeItem<Item> parent = item.getParent();
192-
if (Objects.nonNull(parent)) {
193-
if (!parent.isExpanded()) {
194-
parent.setExpanded(true);
195-
}
196-
}
197-
}
198-
}
188+
focusPath(changedPath);
199189

200190
fileWatchService.registerPathWatcher(path);
201191
});
@@ -208,6 +198,27 @@ public void addPathToTree(Path path, final TreeItem<Item> treeItem, Path changed
208198

209199
}
210200

201+
public void focusPath(Path path) {
202+
if (Objects.nonNull(path)) {
203+
TreeItem<Item> item = pathItemMap.get(path);
204+
if (Objects.nonNull(item)) {
205+
TreeItem<Item> parent = item.getParent();
206+
while (Objects.nonNull(parent)) {
207+
if (!parent.isExpanded()) {
208+
parent.setExpanded(true);
209+
}
210+
parent = parent.getParent();
211+
}
212+
213+
treeView.getSelectionModel().clearSelection();
214+
treeView.getSelectionModel().select(item);
215+
if (Objects.equals(item, treeView.getSelectionModel().getSelectedItem())) {
216+
treeView.scrollTo(treeView.getSelectionModel().getSelectedIndex());
217+
}
218+
}
219+
}
220+
}
221+
211222
private void restoreTreeSelectionState() {
212223
MultipleSelectionModel<TreeItem<Item>> selectionModel = treeView.getSelectionModel();
213224
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
@@ -246,7 +257,7 @@ public void refreshPathToTree(Path path, Path changedPath) {
246257
treeView.setRoot(rootItem);
247258
rootItem.setExpanded(true);
248259
addPathToTree(browsedPath, rootItem, changedPath);
249-
treeView.requestFocus();
260+
// treeView.requestFocus();
250261
});
251262
}
252263

src/main/java/com/kodedu/spell/dictionary/DictionaryService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ public void processTokens(EditorPane editorPane, String jsonToken, String mode)
9292
}
9393
})
9494
.peek(t -> {
95-
final List<String> suggestions = languageSpeller.findSuggestions(t.getValue());
96-
t.setEmptySuggestion(suggestions.isEmpty());
97-
suggestionMap.put(t.getValue(), suggestions);
95+
try {
96+
final List<String> suggestions = languageSpeller.findSuggestions(t.getValue());
97+
t.setEmptySuggestion(suggestions.isEmpty());
98+
suggestionMap.put(t.getValue(), suggestions);
99+
} catch (Exception e) {
100+
logger.info("Couldn't find suggestions for value {}", t.getValue(), e);
101+
}
98102
})
99103
.collect(Collectors.toList());
100104

src/main/resources/scenes/AsciidocFX_Scene.fxml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
<items>
242242
<MenuItem fx:id="openFileTreeItem"
243243
mnemonicParsing="false" text="Open"/>
244+
<MenuItem onAction="#refreshFileView"
245+
mnemonicParsing="false" text="Refresh"/>
244246
<MenuItem id="openFolderTreeItem"
245247
fx:id="openFolderTreeItem"
246248
mnemonicParsing="false"

0 commit comments

Comments
 (0)