Пример #1
0
        public bool Save(bool save_as)
        {
            if (String.IsNullOrEmpty(this.Path) || save_as)
            {
                var settings = new MvvmDialogs.FrameworkDialogs.SaveFile.SaveFileDialogSettings()
                {
                    Filter          = Resources.Document_DefaultFilterLua,
                    DefaultExt      = Resources.Document_DefaultExtension,
                    OverwritePrompt = true,
                    CheckPathExists = true,
                    CheckFileExists = false,
                    FileName        = this.FileName,
                    Title           = "Save file"
                };

                if (this.parent.ShowSaveFileDialog(settings) == true)
                {
                    this.Path = settings.FileName;
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                if (File.Exists(this.Path))
                {
                    File.Delete(this.Path);
                }

                using (var writer = File.CreateText(this.Path))
                {
                    this.Document.WriteTextTo(writer);
                    writer.Flush();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                this.parent.ShowError($"Error saving file {this.Path}", "IO Error");
                return(false);
            }

            this.FileName   = System.IO.Path.GetFileName(this.Path);
            this.ToolTip    = this.Path;
            this.IsModified = false;
            return(true);
        }
Пример #2
0
        protected async Task DownloadFileToDiskExecute()
        {
            string filename = this.SelectedFile.Name.Trim();

            if (filename.Length == 0)
            {
                return;
            }

            var settings = new MvvmDialogs.FrameworkDialogs.SaveFile.SaveFileDialogSettings()
            {
                Filter          = Resources.Document_DefaultFilterLuaLc,
                DefaultExt      = Resources.Document_DefaultExtension,
                OverwritePrompt = true,
                CheckPathExists = true,
                CheckFileExists = false,
                FileName        = filename,
                Title           = "Download file to disk"
            };

            if (this.parent.ShowSaveFileDialog(settings) == true)
            {
                // Delete file if already exists
                var path = settings.FileName;
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Write file to FileStream
                var token = this.parent.CreateCancellationToken();
                using (var stream = File.OpenWrite(path))
                {
                    await this.Terminal.ReadFile(filename, this.SelectedFile.Size, stream, token);
                }
            }
        }
Пример #3
0
 public bool?ShowSaveFileDialog(MvvmDialogs.FrameworkDialogs.SaveFile.SaveFileDialogSettings settings)
 {
     return(this.DialogService.ShowSaveFileDialog(this, settings));
 }