Search in sources :

Example 1 with QuerySaveFileNameRequest

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);
            }
        }
    });
}
Also used : DefaultMenuContribution(com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution) FileOutputStream(java.io.FileOutputStream) DetachableTabPaneLoadModel(com.helospark.tactview.ui.javafx.tiwulfx.com.panemu.tiwulfx.control.DetachableTabPaneLoadModel) File(java.io.File) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) QuerySaveFileNameRequest(com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest) Order(com.helospark.lightdi.annotation.Order) Bean(com.helospark.lightdi.annotation.Bean)

Example 2 with QuerySaveFileNameRequest

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);
        }
    }
}
Also used : Set(java.util.Set) File(java.io.File) QuerySaveFileNameRequest(com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest)

Example 3 with QuerySaveFileNameRequest

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);
    }
}
Also used : File(java.io.File) QuerySaveFileNameRequest(com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest)

Example 4 with QuerySaveFileNameRequest

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;
}
Also used : File(java.io.File) QuerySaveFileNameRequest(com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest)

Aggregations

QuerySaveFileNameRequest (com.helospark.tactview.ui.javafx.save.QuerySaveFilenameService.QuerySaveFileNameRequest)4 File (java.io.File)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Bean (com.helospark.lightdi.annotation.Bean)1 Order (com.helospark.lightdi.annotation.Order)1 DefaultMenuContribution (com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution)1 DetachableTabPaneLoadModel (com.helospark.tactview.ui.javafx.tiwulfx.com.panemu.tiwulfx.control.DetachableTabPaneLoadModel)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Set (java.util.Set)1