Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Oct 20, 2019
1 parent 8a8820d commit 0fceb63
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/main/java/snowflake/components/files/editor/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> styles = factory.keySet();
String stylesArr[] = new String[styles.size()];
Expand Down Expand Up @@ -110,6 +110,8 @@ public void changedUpdate(DocumentEvent e) {
});

selectStyle(info.getName());

setHasChanges(false);
}

public void saveContentsToLocal() throws Exception {
Expand All @@ -135,7 +137,7 @@ public boolean hasUnsavedChanges() {
}

public void setHasChanges(boolean value) {
editor.hasUnsavedChanges(value);
header.setTitle(getInfo().getName() + (value ? "*" : ""));
this.hasChanges = value;
}

Expand Down
30 changes: 20 additions & 10 deletions src/main/java/snowflake/components/files/editor/TextEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,16 @@ 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());
}

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
Expand Down Expand Up @@ -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 ? "*" : ""));
// }
}

0 comments on commit 0fceb63

Please sign in to comment.