Add themes
This commit is contained in:
parent
4661495683
commit
8ddcb9743e
@ -20,10 +20,10 @@ Probably tastes better than any Apple editor and NetBeans combined.
|
|||||||
- [X] Shortcuts
|
- [X] Shortcuts
|
||||||
- [X] Change languages
|
- [X] Change languages
|
||||||
- [X] Toggle line comment
|
- [X] Toggle line comment
|
||||||
- [ ] Soft wrap
|
- [X] Soft wrap
|
||||||
- [ ] Darkmode/Lightmode or color themes
|
- [X] Darkmode/Lightmode or color themes
|
||||||
- [ ] Add icons for files/folders in filetree
|
- [ ] Add icons for files/folders in filetree
|
||||||
- [ ] Add [code coverage check](https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html) to verify quality of unit tests
|
- [X] Add [code coverage check](https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html) to verify quality of unit tests
|
||||||
|
|
||||||
## Maybe TODO?
|
## Maybe TODO?
|
||||||
- [ ] List Chooser
|
- [ ] List Chooser
|
||||||
|
@ -10,6 +10,7 @@ import javafx.scene.image.Image;
|
|||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import app.events.FileSaveStateChangedEvent;
|
import app.events.FileSaveStateChangedEvent;
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
|
import app.events.ThemeChangedEvent;
|
||||||
import app.model.Model;
|
import app.model.Model;
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
@ -46,17 +47,15 @@ public class Main extends Application {
|
|||||||
Model.setScene(scene);
|
Model.setScene(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyCSS() {
|
|
||||||
scene.getStylesheets().add(
|
|
||||||
getClass().getResource("/styling/themes/monokai.css").toExternalForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up default values and settings for the editor.
|
* Set up default values and settings for the editor.
|
||||||
*/
|
*/
|
||||||
private void setupDefaults() {
|
private void setupDefaults() {
|
||||||
|
scene.getStylesheets().setAll("", "");
|
||||||
|
|
||||||
MainController mainController = fxmlLoader.getController();
|
MainController mainController = fxmlLoader.getController();
|
||||||
mainController.getEventBus().post(new LanguageChangedEvent("Java"));
|
mainController.getEventBus().post(new LanguageChangedEvent("Java"));
|
||||||
|
mainController.getEventBus().post(new ThemeChangedEvent("Monokai"));
|
||||||
mainController.getEventBus().post(new FileSaveStateChangedEvent(true));
|
mainController.getEventBus().post(new FileSaveStateChangedEvent(true));
|
||||||
mainController.setHostServices(getHostServices());
|
mainController.setHostServices(getHostServices());
|
||||||
}
|
}
|
||||||
@ -71,7 +70,6 @@ public class Main extends Application {
|
|||||||
setupWindow(window);
|
setupWindow(window);
|
||||||
loadFXML();
|
loadFXML();
|
||||||
createScene();
|
createScene();
|
||||||
applyCSS();
|
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
|
|
||||||
window.setScene(scene);
|
window.setScene(scene);
|
||||||
|
@ -11,6 +11,7 @@ import app.controllers.*;
|
|||||||
import app.events.ExitApplicationEvent;
|
import app.events.ExitApplicationEvent;
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
import app.events.OpenLinkInBrowserEvent;
|
import app.events.OpenLinkInBrowserEvent;
|
||||||
|
import app.events.ThemeChangedEvent;
|
||||||
import app.model.Model;
|
import app.model.Model;
|
||||||
import javafx.application.HostServices;
|
import javafx.application.HostServices;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@ -65,26 +66,28 @@ public class MainController implements Initializable {
|
|||||||
this.hostServices = hostServices;
|
this.hostServices = hostServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCSSAt(int position, String cssPath) {
|
||||||
|
String nextStyleSheet =
|
||||||
|
getClass()
|
||||||
|
.getResource(cssPath)
|
||||||
|
.toExternalForm();
|
||||||
|
|
||||||
|
Model.getScene().getStylesheets().set(position, nextStyleSheet);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the CSS according to which language is being used.
|
* Change the CSS according to which language is being used.
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void handle(LanguageChangedEvent event) {
|
private void handle(LanguageChangedEvent event) {
|
||||||
|
this.setCSSAt(1, "/styling/languages/" + event.getLanguage().toLowerCase() + ".css");
|
||||||
boolean containsSeveralStylesheets = Model.getScene().getStylesheets().size() != 1;
|
|
||||||
|
|
||||||
if (containsSeveralStylesheets)
|
|
||||||
Model.getScene().getStylesheets().remove(1);
|
|
||||||
|
|
||||||
String nextStyleSheet =
|
|
||||||
getClass()
|
|
||||||
.getResource("/styling/language/" + event.getLanguage().toLowerCase() + ".css")
|
|
||||||
.toExternalForm();
|
|
||||||
|
|
||||||
Model.getScene().getStylesheets().add(nextStyleSheet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
private void handle(ThemeChangedEvent event) {
|
||||||
|
this.setCSSAt(0, "/styling/themes/" + event.getTheme().toLowerCase().replace(" ", "-") + ".css");
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void handle(OpenLinkInBrowserEvent event) {
|
private void handle(OpenLinkInBrowserEvent event) {
|
||||||
|
@ -10,6 +10,7 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import app.events.ExitApplicationEvent;
|
import app.events.ExitApplicationEvent;
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
import app.events.OpenLinkInBrowserEvent;
|
import app.events.OpenLinkInBrowserEvent;
|
||||||
|
import app.events.ThemeChangedEvent;
|
||||||
import app.events.ToggleCommentEvent;
|
import app.events.ToggleCommentEvent;
|
||||||
import app.events.ToggleWrapTextEvent;
|
import app.events.ToggleWrapTextEvent;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
@ -107,6 +108,13 @@ public class MenubarController implements Initializable, Controller {
|
|||||||
this.eventBus.post(new ToggleWrapTextEvent(isSelected));
|
this.eventBus.post(new ToggleWrapTextEvent(isSelected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void handleThemeChange(ActionEvent event) {
|
||||||
|
this.eventBus.post(
|
||||||
|
new ThemeChangedEvent(
|
||||||
|
((RadioMenuItem) event.getSource()).getText()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the event where there was an exit request from the menu.
|
* Handles the event where there was an exit request from the menu.
|
||||||
* @param event
|
* @param event
|
||||||
|
15
src/main/java/app/events/ThemeChangedEvent.java
Normal file
15
src/main/java/app/events/ThemeChangedEvent.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package app.events;
|
||||||
|
|
||||||
|
public class ThemeChangedEvent {
|
||||||
|
|
||||||
|
private String theme;
|
||||||
|
|
||||||
|
public ThemeChangedEvent(String theme) {
|
||||||
|
this.theme = theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTheme() {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
<?import javafx.scene.control.SeparatorMenuItem?>
|
<?import javafx.scene.control.SeparatorMenuItem?>
|
||||||
<?import javafx.scene.control.ToggleGroup?>
|
<?import javafx.scene.control.ToggleGroup?>
|
||||||
<?import javafx.scene.control.RadioMenuItem?>
|
<?import javafx.scene.control.RadioMenuItem?>
|
||||||
|
<?import javafx.scene.control.CheckMenuItem?>
|
||||||
|
|
||||||
<MenuBar
|
<MenuBar
|
||||||
fx:id="menubar"
|
fx:id="menubar"
|
||||||
@ -18,13 +19,13 @@
|
|||||||
<Menu mnemonicParsing="false" text="File">
|
<Menu mnemonicParsing="false" text="File">
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" text="New File" accelerator="Shortcut+n"/>
|
<MenuItem mnemonicParsing="false" text="New File" accelerator="Shortcut+n"/>
|
||||||
<MenuItem mnemonicParsing="false" text="New Folder" accelerator="Shortcut+N"/>
|
<MenuItem mnemonicParsing="false" text="New Folder" accelerator="Shortcut+Shift+N"/>
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o" onAction="#handleOpenFile"/>
|
<MenuItem mnemonicParsing="false" text="Open File" accelerator="Shortcut+o" onAction="#handleOpenFile"/>
|
||||||
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+O" onAction="#handleOpenProject"/>
|
<MenuItem mnemonicParsing="false" text="Open Project" accelerator="Shortcut+Shift+O" onAction="#handleOpenProject"/>
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
<MenuItem mnemonicParsing="false" text="Save" accelerator="Shortcut+s"/>
|
<MenuItem mnemonicParsing="false" text="Save" accelerator="Shortcut+s"/>
|
||||||
<MenuItem mnemonicParsing="false" text="Save as" accelerator="Shortcut+S"/>
|
<MenuItem mnemonicParsing="false" text="Save as" accelerator="Shortcut+Shift+S"/>
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
|
|
||||||
<fx:define>
|
<fx:define>
|
||||||
@ -44,6 +45,28 @@
|
|||||||
toggleGroup="$languageToggleGroup"/>
|
toggleGroup="$languageToggleGroup"/>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
<SeparatorMenuItem/>
|
||||||
|
<CheckMenuItem mnemonicParsing="false" text="Wrap text" accelerator="Alt+z" onAction="#handleToggleWraptext"/>
|
||||||
|
<SeparatorMenuItem/>
|
||||||
|
|
||||||
|
<fx:define>
|
||||||
|
<ToggleGroup fx:id="themeToggleGroup"/>
|
||||||
|
</fx:define>
|
||||||
|
|
||||||
|
<Menu mnemonicParsing="false" text="Change color theme">
|
||||||
|
<items>
|
||||||
|
<!-- TODO: Generate buttons based on classes -->
|
||||||
|
<RadioMenuItem text="Monokai"
|
||||||
|
selected="true"
|
||||||
|
onAction="#handleThemeChange"
|
||||||
|
toggleGroup="$themeToggleGroup"/>
|
||||||
|
<RadioMenuItem text="Solarized Light"
|
||||||
|
onAction="#handleThemeChange"
|
||||||
|
toggleGroup="$themeToggleGroup"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
<SeparatorMenuItem/>
|
<SeparatorMenuItem/>
|
||||||
<MenuItem mnemonicParsing="false" text="Exit" accelerator="Shortcut+w" onAction="#handleExitApplication"/>
|
<MenuItem mnemonicParsing="false" text="Exit" accelerator="Shortcut+w" onAction="#handleExitApplication"/>
|
||||||
</items>
|
</items>
|
||||||
|
0
src/main/resources/styling/languages/empty.css
Normal file
0
src/main/resources/styling/languages/empty.css
Normal file
Loading…
x
Reference in New Issue
Block a user