use of com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest in project tactview by helospark.
the class DefaultWindowMenuItemConfiguration method saveLayoutMenuItem.
@Bean
@Order(3997)
public SelectableMenuContribution saveLayoutMenuItem(MessagingService messagingService, QuerySaveFilenameService querySaveFilenameService, @Value("${tactview.homedirectory}") String homeDirectory, AlertDialogFactory alertDialogFactory) {
return new DefaultMenuContribution(List.of(WINDOW_MENU_ITEM, "Save layout"), e -> {
QuerySaveFileNameRequest request = QuerySaveFileNameRequest.builder().withInitialDirectory(homeDirectory).withTitle("Save layout file").build();
Optional<String> optionalFileName = querySaveFilenameService.queryUserAboutFileName(request);
if (optionalFileName.isPresent()) {
try {
String fileName = optionalFileName.get();
if (!fileName.endsWith("." + TACTVIEW_LAYOUT_EXTENSION)) {
fileName += ("." + TACTVIEW_LAYOUT_EXTENSION);
}
DetachableTabPaneLoadModel data = dockableTabRepository.extractLoadModel();
String result = objectMapper.writeValueAsString(data);
try (FileOutputStream fos = new FileOutputStream(new File(fileName))) {
fos.write(result.getBytes(StandardCharsets.UTF_8));
}
} catch (Exception e1) {
alertDialogFactory.showExceptionDialog("Unable to save layout", e1);
LOGGER.error("Unable to save layout", e1);
}
}
});
}
use of com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest in project tactview by helospark.
the class UiSaveHandler method saveAsTemplate.
public void saveAsTemplate() {
QuerySaveFileNameRequest request = QuerySaveFileNameRequest.builder().withInitialDirectory(lastOpenedDirectoryName).withTitle("Save Project as template").build();
Optional<String> fileName = querySaveFilenameService.queryUserAboutFileName(request);
if (fileName.isPresent()) {
Optional<Set<ExposedDescriptorDescriptor>> result = subtimelineWindowOpener.openWindow();
if (result.isPresent()) {
String resultFilePath = fileName.get();
if (!resultFilePath.endsWith(".tvt")) {
resultFilePath += ".tvt";
}
File resultFile = new File(resultFilePath);
lastOpenedDirectoryName = resultFile.getParentFile().getAbsolutePath();
templateSaveHandler.save(createSaveTemplateRequest(resultFilePath, result.get()));
dirtyRepository.setDirty(false);
}
}
}
use of com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest in project tactview by helospark.
the class UiSaveHandler method saveAs.
public void saveAs() {
QuerySaveFileNameRequest request = QuerySaveFileNameRequest.builder().withInitialDirectory(lastOpenedDirectoryName).withTitle("Save Project").build();
Optional<String> fileName = querySaveFilenameService.queryUserAboutFileName(request);
if (fileName.isPresent()) {
String resultFilePath = fileName.get();
if (!resultFilePath.endsWith(".tvs")) {
resultFilePath += ".tvs";
}
File resultFile = new File(resultFilePath);
lastOpenedDirectoryName = resultFile.getParentFile().getAbsolutePath();
saveAndLoadHandler.save(createSaveRequest(resultFilePath));
dirtyRepository.setDirty(false);
recentlyAccessedRepository.addNewRecentlySavedElement(resultFile);
}
}
use of com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest in project tactview by helospark.
the class UiSaveHandler method executeSave.
private boolean executeSave() {
Optional<String> currentSavedFile = currentProjectSavedFileRepository.getCurrentSavedFile();
if (currentSavedFile.isPresent()) {
dirtyRepository.setDirty(false);
String filePath = currentSavedFile.get();
saveAndLoadHandler.save(createSaveRequest(filePath));
recentlyAccessedRepository.addNewRecentlySavedElement(new File(filePath));
return true;
} else {
QuerySaveFileNameRequest request = QuerySaveFileNameRequest.builder().withInitialDirectory(lastOpenedDirectoryName).withTitle("Save Project").build();
Optional<String> fileName = querySaveFilenameService.queryUserAboutFileName(request);
if (fileName.isPresent()) {
String pathName = fileName.get();
if (!pathName.endsWith(".tvs")) {
pathName += ".tvs";
}
lastOpenedDirectoryName = new File(pathName).getParentFile().getAbsolutePath();
dirtyRepository.setDirty(false);
saveAndLoadHandler.save(createSaveRequest(pathName));
recentlyAccessedRepository.addNewRecentlySavedElement(new File(pathName));
currentProjectSavedFileRepository.setCurrentSavedFile(pathName);
return true;
}
}
return false;
}
Aggregations