internal string SelectFilePath(FilterIndex filterIndex = FilterIndex.Default) { filterIndex = EvalFilterIndex(filterIndex); OpenFileDialog.FilterIndex = (int)filterIndex; InitFolderPath(OpenFileDialog, filterIndex); if (OpenFileDialog.ShowDialog() != DialogResult.OK) { return(null); } return(OpenFileDialog.FileName); }
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }
internal bool SaveAs(FilterIndex filterIndex = FilterIndex.Default) { if (string.IsNullOrWhiteSpace(FilePath)) { OnFilePathRequest(); } SaveFileDialog.FileName = FilePath; filterIndex = EvalFilterIndex(filterIndex); InitFolderPath(SaveFileDialog, filterIndex); SaveFileDialog.FilterIndex = (int)filterIndex; return(SaveFileDialog.ShowDialog() == DialogResult.OK && SaveToFile(SaveFileDialog.FileName)); }
private void InitFolderPath(FileDialog dialog, FilterIndex filterIndex) { var folderPath = string.Empty; if (!string.IsNullOrWhiteSpace(dialog.FileName)) { folderPath = Path.GetDirectoryName(dialog.FileName); } if (string.IsNullOrWhiteSpace(folderPath)) { dialog.InitialDirectory = AppController.GetDefaultFolder(filterIndex); } }
internal static string GetDefaultFolder(FilterIndex filterIndex) { switch (filterIndex) { case FilterIndex.File: return(Options.FilesFolderPath); case FilterIndex.Template: return(Options.TemplatesFolderPath); default: return(string.Empty); } }
private FilterIndex EvalFilterIndex(FilterIndex filterIndex) { if (filterIndex == FilterIndex.Default) { switch (Path.GetExtension(FilePath)) { case ".tgt": return(FilterIndex.Template); case ".tgf": default: return(FilterIndex.File); } } return(filterIndex); }
internal bool Save(FilterIndex filterIndex = FilterIndex.Default) => string.IsNullOrEmpty(FilePath) ? SaveAs(filterIndex) : SaveToFile(FilePath);
private SceneController OpenFile(FilterIndex filterIndex = FilterIndex.File) => OpenFile(JsonController.SelectFilePath(filterIndex));
private WorldCon OpenFile(FilterIndex filterIndex = FilterIndex.File) => OpenFile(JsonCon.SelectFilePath(filterIndex));
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } try { if (!string.IsNullOrEmpty(initialDirectory) && !initialDirectory.Contains("\\")) { Enum.TryParse(initialDirectory, out Environment.SpecialFolder specialfolder); initialDirectory = Environment.GetFolderPath(specialfolder); } } catch (Exception) { throw; } if (!string.IsNullOrEmpty(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }