From 0fceb63337f52706eac12159d0beb7ed3b5f845b Mon Sep 17 00:00:00 2001 From: subhra74 Date: Sun, 20 Oct 2019 12:03:10 +0200 Subject: [PATCH] misc --- .../components/files/editor/EditorTab.java | 10 ++++--- .../components/files/editor/TextEditor.java | 30 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/snowflake/components/files/editor/EditorTab.java b/src/main/java/snowflake/components/files/editor/EditorTab.java index b16a75b2..9f494e5f 100644 --- a/src/main/java/snowflake/components/files/editor/EditorTab.java +++ b/src/main/java/snowflake/components/files/editor/EditorTab.java @@ -35,9 +35,11 @@ public class EditorTab extends JPanel implements SearchListener { private GoToDialog goToDialog; private boolean wrapText = false; private TextEditor editor; + private TabHeader header; - public EditorTab(FileInfo info, String text, String localFile, TextEditor editor) { + public EditorTab(FileInfo info, String text, String localFile, TextEditor editor, TabHeader header) { super(new BorderLayout()); + this.header = header; this.info = info; this.localFile = localFile; this.textArea = new RSyntaxTextArea(); @@ -75,8 +77,6 @@ public EditorTab(FileInfo info, String text, String localFile, TextEditor editor replaceToolBar.add(xp, BorderLayout.EAST); - hasChanges = false; - TokenMakerFactory factory = TokenMakerFactory.getDefaultInstance(); Set styles = factory.keySet(); String stylesArr[] = new String[styles.size()]; @@ -110,6 +110,8 @@ public void changedUpdate(DocumentEvent e) { }); selectStyle(info.getName()); + + setHasChanges(false); } public void saveContentsToLocal() throws Exception { @@ -135,7 +137,7 @@ public boolean hasUnsavedChanges() { } public void setHasChanges(boolean value) { - editor.hasUnsavedChanges(value); + header.setTitle(getInfo().getName() + (value ? "*" : "")); this.hasChanges = value; } diff --git a/src/main/java/snowflake/components/files/editor/TextEditor.java b/src/main/java/snowflake/components/files/editor/TextEditor.java index 0ac44c05..6f7b0f3c 100644 --- a/src/main/java/snowflake/components/files/editor/TextEditor.java +++ b/src/main/java/snowflake/components/files/editor/TextEditor.java @@ -491,6 +491,7 @@ private StringBuilder readTempFile(String file) { } private void setTabContent(StringBuilder sb) { + System.out.println("Setting tab content"); this.reloading = false; ((EditorTab) tabs.getSelectedComponent()).setText(sb.toString()); } @@ -498,8 +499,8 @@ private void setTabContent(StringBuilder sb) { private void createNewTab(FileInfo fileInfo, StringBuilder sb, String tempFile) { cardLayout.show(content, "Tabs"); int index = tabs.getTabCount(); - EditorTab tab = new EditorTab(fileInfo, sb.toString(), tempFile, this); TabHeader tabHeader = new TabHeader(fileInfo.getName()); + EditorTab tab = new EditorTab(fileInfo, sb.toString(), tempFile, this, tabHeader); int count = tabs.getTabCount(); tabHeader.getBtnClose().addMouseListener(new MouseAdapter() { @Override @@ -601,13 +602,22 @@ private void wrapText(boolean selected) { } } - public void hasUnsavedChanges(boolean value) { - int index = tabs.getSelectedIndex(); - if (index < 0) { - return; - } - TabHeader header = (TabHeader) tabs.getTabComponentAt(index); - EditorTab tab = (EditorTab) tabs.getSelectedComponent(); - header.setTitle(tab.getInfo().getName() + (value ? "*" : "")); - } +// public void hasUnsavedChanges(EditorTab editorTab) { +// int index = tabs.getSelectedIndex(); +// +// if (index < 0) { +// return; +// } +// +// for (int i = 0; i < tabs.getComponentCount(); i++) { +// if (tabs.getComponent(i) == editorTab) { +// TabHeader header = (TabHeader) tabs.getTabComponentAt(index); +// header.setTitle(tab.getInfo().getName() + (value ? "*" : "")); +// } +// } +// +//// TabHeader header = (TabHeader) tabs.getTabComponentAt(index); +//// EditorTab tab = (EditorTab) tabs.getSelectedComponent(); +//// header.setTitle(tab.getInfo().getName() + (value ? "*" : "")); +// } }