Skip to content

Commit

Permalink
apply custom text snippet to mind map; clear snippet view when no fil…
Browse files Browse the repository at this point in the history
…e is opened
  • Loading branch information
mindolph committed Dec 17, 2024
1 parent 35fe8e1 commit 9cca971
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,29 @@ public SnippetView() {

// for switching snippets by listening file activation.
EventBus.getIns().subscribeFileActivated(fileChange -> {
NodeData nodeData = fileChange.newData();
if (fileChange.oldData() != null && fileChange.newData() != null
&& fileChange.oldData().isSameFileType(fileChange.newData())) {
NodeData activatedData = fileChange.newData();
if (fileChange.oldData() != null && activatedData != null
&& fileChange.oldData().isSameFileType(activatedData)) {
return;
}
if (nodeData == null) {
if (activatedData == null) {
this.reload(null, null);
return;
}
switch (nodeData.getNodeType()) {
switch (activatedData.getNodeType()) {
case FOLDER -> {
this.reload(null, null);
}
case FILE -> {
if (nodeData.isPlantUml()) {
if (activatedData.isPlantUml()) {
currentFileType = TYPE_PLANTUML;
this.reloadForFileType(TYPE_PLANTUML);
}
else if (nodeData.isMindMap()) {
else if (activatedData.isMindMap()) {
currentFileType = TYPE_MIND_MAP;
this.reloadForFileType(TYPE_MIND_MAP);
}
else if (nodeData.isMarkdown()) {
else if (activatedData.isMarkdown()) {
currentFileType = TYPE_MARKDOWN;
this.reloadForFileType(TYPE_MARKDOWN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public SnippetDialog(String fileType, Snippet<?> snippet) {

dialog = new CustomDialogBuilder<Snippet<?>>()
.owner(DialogFactory.DEFAULT_WINDOW)
.title(snippet == null ? "New" : "Edit" + " Snippet")
.title("%s Snippet".formatted(snippet == null ? "New" : "Edit"))
.fxmlUri("dialog/snippet_dialog.fxml")
.buttons(ButtonType.OK, ButtonType.CANCEL)
.icon(ButtonType.OK, FontIconManager.getIns().getIcon(IconKey.OK))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public class FileTabView extends BaseView {
public FileTabView() {
super("/view/file_tab_view.fxml");
tabPane.getSelectionModel().selectedItemProperty().addListener((observable, selectedTab, selectingTab) -> {
Object oldData = selectedTab == null ? null : selectedTab.getUserData();
if (selectingTab != null && selectedTab != selectingTab && !selectingTab.isDisabled()) {
// disabled tab means it is closing, no need to be loaded(for close all or close others from context menu)
log.debug("Tab selection changed from %s to %s".formatted(selectedTab == null ? "null" : selectedTab.getText(), selectingTab.getText()));
Object oldData = selectedTab == null ? null : selectedTab.getUserData();
TabManager.getIns().activeTab(selectingTab);
BaseEditor editor = (BaseEditor) tabEditorMap.get(selectingTab);
Object tabUserData = selectingTab.getUserData();
Expand All @@ -95,6 +95,7 @@ public FileTabView() {
else {
this.updateMenuState(null);
EventBus.getIns().notifyOutline(null); // clear the outline view since there is no tab exists.
EventBus.getIns().notifyFileActivated(new FileActivatedEvent((NodeData) oldData, null));
}
});
tabPane.setOnMouseClicked(mouseEvent -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ public void onSnippet(Snippet snippet) {
if (StringUtils.isNotBlank(snippet.getFilePath())) {
ImagePopUpMenuExtension.loadImageFileToSelectedTopics((ExtensionContext) mindMapView, new File(snippet.getFilePath()));
}
else {
mindMapView.appendTextAsTopicTree(snippet.getCode(), "");
}
}
}

Expand Down

0 comments on commit 9cca971

Please sign in to comment.