Add Save/Modified display in modeline
This commit is contained in:
parent
d4aff39f55
commit
06276bcda1
@ -8,7 +8,7 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import app.events.FileSaveStateChangedEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.model.Model;
|
||||
|
||||
@ -59,6 +59,7 @@ public class Main extends Application {
|
||||
private void setupDefaults() {
|
||||
MainController mainController = fxmlLoader.getController();
|
||||
mainController.getEventBus().post(new LanguageChangedEvent("Java"));
|
||||
mainController.getEventBus().post(new FileSaveStateChangedEvent(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@ package app.controllers;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
@ -16,6 +15,7 @@ import org.fxmisc.richtext.model.TwoDimensional.Position;
|
||||
|
||||
import app.events.EditorChangedEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.FileSaveStateChangedEvent;
|
||||
import app.model.Model;
|
||||
import app.service.LanguageOperations;
|
||||
import javafx.fxml.FXML;
|
||||
@ -71,6 +71,10 @@ public class EditorController implements Initializable, Controller {
|
||||
Position pos = this.editor.offsetToPosition(offset, Bias.Forward);
|
||||
this.eventBus.post(new EditorChangedEvent(pos.getMajor() + 1, pos.getMinor()));
|
||||
|
||||
|
||||
if (Model.getFileIsSaved())
|
||||
this.eventBus.post(new FileSaveStateChangedEvent(false));
|
||||
|
||||
this.refreshHighlighting();
|
||||
}
|
||||
|
||||
|
@ -8,13 +8,16 @@ import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import app.events.EditorChangedEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.model.Model;
|
||||
import app.events.FileSaveStateChangedEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
public class ModelineController implements Initializable, Controller {
|
||||
|
||||
@FXML
|
||||
private Label saveState;
|
||||
|
||||
@FXML
|
||||
private Label columnrow;
|
||||
|
||||
@ -53,6 +56,15 @@ public class ModelineController implements Initializable, Controller {
|
||||
this.setColumnRow(event.getColumn(), event.getLineNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the saveState label whenever the file either is saved or modified
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
private void handle(FileSaveStateChangedEvent event) {
|
||||
this.saveState.setText(event.getIsSaved() ? "Saved!" : "Modified");
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the modeline to display a new language
|
||||
* whenever it is changed.
|
||||
|
18
src/main/java/app/events/FileSaveStateChangedEvent.java
Normal file
18
src/main/java/app/events/FileSaveStateChangedEvent.java
Normal file
@ -0,0 +1,18 @@
|
||||
package app.events;
|
||||
|
||||
import app.model.Model;
|
||||
|
||||
public class FileSaveStateChangedEvent {
|
||||
|
||||
private boolean isSaved;
|
||||
|
||||
public FileSaveStateChangedEvent(boolean isSaved) {
|
||||
this.isSaved = isSaved;
|
||||
Model.setFileIsSaved(isSaved);
|
||||
}
|
||||
|
||||
public boolean getIsSaved() {
|
||||
return this.isSaved;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import javafx.scene.Scene;
|
||||
* by multiple pieces in the application, including the primary scene.
|
||||
*/
|
||||
public class Model {
|
||||
private static boolean fileIsSaved;
|
||||
private static String activeFilePath;
|
||||
private static String currentProjectPath;
|
||||
private static ProgrammingLanguage currentProgrammingLanguage;
|
||||
@ -30,6 +31,10 @@ public class Model {
|
||||
return scene;
|
||||
}
|
||||
|
||||
public static boolean getFileIsSaved() {
|
||||
return fileIsSaved;
|
||||
}
|
||||
|
||||
public static void setLanguage(ProgrammingLanguage language) {
|
||||
Model.currentProgrammingLanguage = language;
|
||||
}
|
||||
@ -37,4 +42,9 @@ public class Model {
|
||||
public static void setScene(Scene scene) {
|
||||
Model.scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFileIsSaved(boolean fileIsSaved) {
|
||||
Model.fileIsSaved = fileIsSaved;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user