Replace FileSelectedEvent with OpenFileEvent
This commit is contained in:
parent
02c738e761
commit
581bb0ad3b
@ -26,7 +26,6 @@ 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.FileOperations;
|
||||
import app.service.LanguageOperations;
|
||||
@ -181,7 +180,7 @@ public class EditorController implements Initializable, Controller {
|
||||
* Updates Code Area (read from file) whenever the FileSelected is changed
|
||||
*/
|
||||
@Subscribe
|
||||
public void handle(FileSelectedEvent event) {
|
||||
public void handle(OpenFileEvent event) {
|
||||
String newContent =
|
||||
event
|
||||
.getPath()
|
||||
|
@ -16,7 +16,7 @@ import java.util.ResourceBundle;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import app.events.FileSelectedEvent;
|
||||
import app.events.OpenFileEvent;
|
||||
import app.events.OpenProjectEvent;
|
||||
import app.events.SaveFileEvent;
|
||||
import app.model.Model;
|
||||
@ -77,7 +77,7 @@ public class FiletreeController implements Initializable, Controller {
|
||||
Path path = FiletreeOperations.getPathOfTreeItem(item);
|
||||
|
||||
if (!Files.isDirectory(path)) {
|
||||
this.eventBus.post(new FileSelectedEvent(Optional.ofNullable(path)));
|
||||
this.eventBus.post(new OpenFileEvent(Optional.ofNullable(path)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import com.google.common.eventbus.Subscribe;
|
||||
import app.events.CopyEvent;
|
||||
import app.events.CutEvent;
|
||||
import app.events.ExitApplicationEvent;
|
||||
import app.events.FileSelectedEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.OpenFileEvent;
|
||||
import app.events.OpenLinkInBrowserEvent;
|
||||
import app.events.OpenProjectEvent;
|
||||
import app.events.PasteEvent;
|
||||
@ -65,7 +65,7 @@ public class MenubarController implements Initializable, Controller {
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@FXML
|
||||
private void handleNewFile() {
|
||||
this.eventBus.post(new FileSelectedEvent(Optional.empty()));
|
||||
this.eventBus.post(new OpenFileEvent(Optional.empty()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -87,7 +87,7 @@ public class MenubarController implements Initializable, Controller {
|
||||
try {
|
||||
File file = FileOperations.openFileWithDialog(stage);
|
||||
|
||||
this.eventBus.post(new FileSelectedEvent(Optional.ofNullable(file.toPath())));
|
||||
this.eventBus.post(new OpenFileEvent(Optional.ofNullable(file.toPath())));
|
||||
} catch (FileNotFoundException e) {
|
||||
DialogBoxes.showErrorMessage("File not found!");
|
||||
}
|
||||
@ -105,9 +105,7 @@ public class MenubarController implements Initializable, Controller {
|
||||
|
||||
// TODO: Move Model modification inside event
|
||||
this.eventBus.post(new OpenProjectEvent(dir.toPath()));
|
||||
} catch (FileNotFoundException e) {
|
||||
DialogBoxes.showErrorMessage("Folder not found!");
|
||||
}
|
||||
} catch (FileNotFoundException e) {}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -127,7 +125,7 @@ public class MenubarController implements Initializable, Controller {
|
||||
*/
|
||||
@FXML
|
||||
private void handleSaveAsFile() {
|
||||
handleSaveFile();
|
||||
this.eventBus.post(new SaveFileEvent(false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,36 +0,0 @@
|
||||
package app.events;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import app.model.Model;
|
||||
|
||||
/**
|
||||
* Event signalizing that a file was selected in the filetree.
|
||||
*
|
||||
* Not to be confused with {@link OpenFileEvent}
|
||||
*/
|
||||
public class FileSelectedEvent extends Event {
|
||||
|
||||
private Optional<Path> path;
|
||||
|
||||
/**
|
||||
* Event signalizing that a file was selected in the filetree.
|
||||
*
|
||||
* Not to be confused with {@link OpenFileEvent}
|
||||
* @param path The path of the selected file
|
||||
*/
|
||||
public FileSelectedEvent(Optional<Path> path) {
|
||||
this.path = path;
|
||||
Model.setActiveFilePath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The path of the selected file
|
||||
*/
|
||||
public Optional<Path> getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
}
|
@ -7,8 +7,6 @@ import app.model.Model;
|
||||
|
||||
/**
|
||||
* Event signalizing that a file outside the current project is supposed to be opened in the editor.
|
||||
*
|
||||
* Not to be confused with {@link FileSelectedEvent}
|
||||
*/
|
||||
public class OpenFileEvent extends Event {
|
||||
|
||||
|
@ -8,15 +8,20 @@ public class SaveFileEvent extends Event {
|
||||
|
||||
/**
|
||||
* Event signalizing that a file is to be saved.
|
||||
*
|
||||
* Not to be confused with {@link FileSelectedEvent}
|
||||
*
|
||||
* @param isNewFile The path of the selected file
|
||||
*/
|
||||
public SaveFileEvent() {
|
||||
this.isNewFile = Model.getActiveFilePath().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Event signalizing that a file is to be saved.
|
||||
*
|
||||
* @param isNewFile The path of the selected file
|
||||
*/
|
||||
public SaveFileEvent(boolean isNewFile) {
|
||||
this.isNewFile = isNewFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not
|
||||
*/
|
||||
|
@ -38,7 +38,7 @@ import app.service.FileOperations;
|
||||
import app.service.LanguageOperations;
|
||||
import app.events.CopyEvent;
|
||||
import app.events.CutEvent;
|
||||
import app.events.FileSelectedEvent;
|
||||
import app.events.OpenFileEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.PasteEvent;
|
||||
import app.events.RedoEvent;
|
||||
@ -80,8 +80,8 @@ public class EditorControllerTest extends FxTestTemplate {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test handling of FileSelectedEvent with a real file")
|
||||
public void testFileSelectedEventWithRealFile() throws IOException {
|
||||
@DisplayName("Test handling of OpenFileEvent with a real file")
|
||||
public void testOpenFileEventWithRealFile() throws IOException {
|
||||
|
||||
String resourcePath = "/testfile.txt";
|
||||
String filePath = getClass().getResource(resourcePath).getPath();
|
||||
@ -91,18 +91,18 @@ public class EditorControllerTest extends FxTestTemplate {
|
||||
mocked.when(() -> FileOperations.readFile(any()))
|
||||
.thenReturn("");
|
||||
|
||||
eventBus.post(new FileSelectedEvent(Optional.of(file.toPath())));
|
||||
eventBus.post(new OpenFileEvent(Optional.of(file.toPath())));
|
||||
|
||||
mocked.verify(() -> FileOperations.readFile(any()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test handling of FileSelectedEvent with a file that doesn't exist")
|
||||
public void testFileSelectedEventWithUnrealFile() throws IOException {
|
||||
@DisplayName("Test handling of OpenFileEvent with a file that doesn't exist")
|
||||
public void testOpenFileEventWithUnrealFile() throws IOException {
|
||||
|
||||
String brokenFilePath = "/doesNotExist.txt";
|
||||
eventBus.post(new FileSelectedEvent(Optional.ofNullable(new File(brokenFilePath).toPath())));
|
||||
eventBus.post(new OpenFileEvent(Optional.ofNullable(new File(brokenFilePath).toPath())));
|
||||
|
||||
verify(editor, never()).clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user