Add textwrap feature
This commit is contained in:
parent
bcbf6b5153
commit
4661495683
@ -76,8 +76,6 @@ public class Main extends Application {
|
||||
|
||||
window.setScene(scene);
|
||||
window.show();
|
||||
|
||||
getHostServices().showDocument("https://google.com");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.fxmisc.richtext.model.TwoDimensional.Position;
|
||||
import app.events.EditorChangedEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.ToggleCommentEvent;
|
||||
import app.events.ToggleWrapTextEvent;
|
||||
import app.events.FileSaveStateChangedEvent;
|
||||
import app.model.Model;
|
||||
import app.service.LanguageOperations;
|
||||
@ -99,10 +100,14 @@ public class EditorController implements Initializable, Controller {
|
||||
}
|
||||
}
|
||||
|
||||
private void setWrapText(boolean isWrapText) {
|
||||
this.editor.setWrapText(isWrapText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event whenever the content of the editor is changed.
|
||||
*/
|
||||
public void editorChanged() {
|
||||
private void editorChanged() {
|
||||
int offset = this.editor.getCaretPosition();
|
||||
Position pos = this.editor.offsetToPosition(offset, Bias.Forward);
|
||||
this.eventBus.post(new EditorChangedEvent(pos.getMajor() + 1, pos.getMinor()));
|
||||
@ -131,4 +136,9 @@ public class EditorController implements Initializable, Controller {
|
||||
this.toggleComment();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void handle(ToggleWrapTextEvent event) {
|
||||
this.setWrapText(event.getIsWrapped());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ import app.events.ExitApplicationEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.OpenLinkInBrowserEvent;
|
||||
import app.events.ToggleCommentEvent;
|
||||
import app.events.ToggleWrapTextEvent;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.CheckMenuItem;
|
||||
import javafx.scene.control.MenuBar;
|
||||
import javafx.scene.control.RadioMenuItem;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
@ -99,6 +101,12 @@ public class MenubarController implements Initializable, Controller {
|
||||
((RadioMenuItem) event.getSource()).getText()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleToggleWraptext(ActionEvent event) {
|
||||
var isSelected = ((CheckMenuItem) event.getSource()).selectedProperty().get();
|
||||
this.eventBus.post(new ToggleWrapTextEvent(isSelected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event where there was an exit request from the menu.
|
||||
* @param event
|
||||
|
15
src/main/java/app/events/ToggleWrapTextEvent.java
Normal file
15
src/main/java/app/events/ToggleWrapTextEvent.java
Normal file
@ -0,0 +1,15 @@
|
||||
package app.events;
|
||||
|
||||
public class ToggleWrapTextEvent extends Event {
|
||||
|
||||
private boolean isWrapped;
|
||||
|
||||
public ToggleWrapTextEvent(boolean isWrapped) {
|
||||
this.isWrapped = isWrapped;
|
||||
}
|
||||
|
||||
public boolean getIsWrapped() {
|
||||
return this.isWrapped;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user