async Task <bool> SaveAsTask(string filename) { if (Window.ViewContent.IsViewOnly || !Window.ViewContent.IsFile) { return(false); } Encoding encoding = null; var tbuffer = GetContent <ITextSource> (); if (tbuffer != null) { encoding = tbuffer.Encoding; if (encoding == null) { encoding = Encoding.UTF8; } } if (filename == null) { var dlg = new OpenFileDialog(GettextCatalog.GetString("Save as..."), MonoDevelop.Components.FileChooserAction.Save) { TransientFor = IdeApp.Workbench.RootWindow, Encoding = encoding, ShowEncodingSelector = (tbuffer != null), }; if (Window.ViewContent.IsUntitled) { dlg.InitialFileName = Window.ViewContent.UntitledName; } else { dlg.CurrentFolder = Path.GetDirectoryName((string)Window.ViewContent.ContentName); dlg.InitialFileName = Path.GetFileName((string)Window.ViewContent.ContentName); } if (!dlg.Run()) { return(false); } filename = dlg.SelectedFile; encoding = dlg.Encoding; } if (!FileService.IsValidPath(filename)) { MessageService.ShowMessage(GettextCatalog.GetString("File name {0} is invalid", filename)); return(false); } // detect preexisting file if (File.Exists(filename)) { if (!MessageService.Confirm(GettextCatalog.GetString("File {0} already exists. Overwrite?", filename), AlertButton.OverwriteFile)) { return(false); } } // save backup first if (IdeApp.Preferences.CreateFileBackupCopies) { if (tbuffer != null && encoding != null) { TextFileUtility.WriteText(filename + "~", tbuffer.Text, encoding); } else { await Window.ViewContent.Save(new FileSaveInformation (filename + "~", encoding)); } } TypeSystemService.RemoveSkippedfile(FileName); // do actual save Window.ViewContent.ContentName = filename; Window.ViewContent.Project = Workbench.GetProjectContainingFile(filename); await Window.ViewContent.Save(new FileSaveInformation (filename, encoding)); DesktopService.RecentFiles.AddFile(filename, (Project)null); OnSaved(EventArgs.Empty); await UpdateParseDocument(); return(true); }
public void Activate(bool giveFocus) { CreateContent(); Workbench.ActivatePad(codon, giveFocus); }