Filetreefix
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package app.controllers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
@@ -23,6 +26,7 @@ import app.events.ToggleCommentEvent;
|
||||
import app.events.ToggleWrapTextEvent;
|
||||
import app.events.UndoEvent;
|
||||
import app.events.FileSaveStateChangedEvent;
|
||||
import app.events.FileSelectedEvent;
|
||||
import app.model.Model;
|
||||
import app.service.LanguageOperations;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -43,9 +47,7 @@ public class EditorController implements Initializable, Controller {
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
editor.setParagraphGraphicFactory(LineNumberFactory.get(editor));
|
||||
|
||||
editor
|
||||
.textProperty()
|
||||
.addListener((obs, oldV, newV) -> this.editorChanged());
|
||||
editor.textProperty().addListener((obs, oldV, newV) -> this.editorChanged());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,8 +73,8 @@ public class EditorController implements Initializable, Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Model.language to determine whether the current line/selection
|
||||
* is commented or not, and toggles the comment.
|
||||
* Uses Model.language to determine whether the current line/selection is
|
||||
* commented or not, and toggles the comment.
|
||||
*/
|
||||
private void toggleComment() {
|
||||
if (editor.getSelectedText().equals("")) {
|
||||
@@ -84,13 +86,7 @@ public class EditorController implements Initializable, Controller {
|
||||
else
|
||||
newText = Model.getLanguage().commentLine(currentLine);
|
||||
|
||||
editor.replaceText(
|
||||
editor.getCurrentParagraph(),
|
||||
0,
|
||||
editor.getCurrentParagraph(),
|
||||
currentLine.length(),
|
||||
newText
|
||||
);
|
||||
editor.replaceText(editor.getCurrentParagraph(), 0, editor.getCurrentParagraph(), currentLine.length(), newText);
|
||||
|
||||
} else { // Comment selection
|
||||
|
||||
@@ -105,7 +101,7 @@ public class EditorController implements Initializable, Controller {
|
||||
}
|
||||
}
|
||||
|
||||
private void setWrapText(boolean isWrapText) {
|
||||
private void setWrapText(boolean isWrapText) {
|
||||
this.editor.setWrapText(isWrapText);
|
||||
}
|
||||
|
||||
@@ -125,8 +121,24 @@ public class EditorController implements Initializable, Controller {
|
||||
|
||||
/**
|
||||
* Refreshes the editor whenever the language is changed.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
|
||||
@Subscribe
|
||||
private void handle(FileSelectedEvent event) {
|
||||
try {
|
||||
Scanner sc = new Scanner(new File(event.getPath()));
|
||||
editor.clear();
|
||||
while (sc.hasNextLine()) {
|
||||
editor.appendText(sc.nextLine());
|
||||
editor.appendText("\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println(event.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
this.refreshHighlighting();
|
||||
@@ -134,6 +146,7 @@ public class EditorController implements Initializable, Controller {
|
||||
|
||||
/**
|
||||
* Toggles a language specific comment of the line/selection
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Subscribe
|
||||
|
||||
Reference in New Issue
Block a user