Search in sources :

Example 1 with SourceFileSavedEvent

use of org.rstudio.studio.client.workbench.views.source.events.SourceFileSavedEvent in project rstudio by rstudio.

the class TextEditingTarget method saveNewFileWithEncoding.

private void saveNewFileWithEncoding(String suggestedPath, final String encoding, final Command executeOnSuccess) {
    view_.ensureVisible();
    FileSystemItem fsi;
    if (suggestedPath != null)
        fsi = FileSystemItem.createFile(suggestedPath);
    else
        fsi = getSaveFileDefaultDir();
    fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {

        public void execute(final FileSystemItem saveItem, ProgressIndicator indicator) {
            if (saveItem == null)
                return;
            try {
                workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
                final TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(saveItem);
                final Command saveCommand = new Command() {

                    @Override
                    public void execute() {
                        if (!getPath().equals(saveItem.getPath())) {
                            // breakpoints are file-specific, so when saving
                            // as a different file, clear the display of
                            // breakpoints from the old file name
                            docDisplay_.removeAllBreakpoints();
                            // update publish settings 
                            syncPublishPath(saveItem.getPath());
                        }
                        fixupCodeBeforeSaving();
                        docUpdateSentinel_.save(saveItem.getPath(), fileType.getTypeId(), encoding, new SaveProgressIndicator(saveItem, fileType, executeOnSuccess));
                        events_.fireEvent(new SourceFileSavedEvent(getId(), saveItem.getPath()));
                    }
                };
                // to a non-R file type then confirm
                if (fileType_.isR() && !fileType.isR()) {
                    globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Confirm Change File Type", "This file was created as an R script however " + "the file extension you specified will change " + "it into another file type that will no longer " + "open as an R script.\n\n" + "Are you sure you want to change the type of " + "the file so that it is no longer an R script?", new Operation() {

                        @Override
                        public void execute() {
                            saveCommand.execute();
                        }
                    }, false);
                } else {
                    saveCommand.execute();
                }
            } catch (Exception e) {
                indicator.onError(e.toString());
                return;
            }
            indicator.onCompleted();
        }
    });
}
Also used : SourceFileSavedEvent(org.rstudio.studio.client.workbench.views.source.events.SourceFileSavedEvent) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) CppCompletionOperation(org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)

Aggregations

RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Command (com.google.gwt.user.client.Command)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 CppCompletionOperation (org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)1 SourceFileSavedEvent (org.rstudio.studio.client.workbench.views.source.events.SourceFileSavedEvent)1