Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        internal static string GetDefaultFolder(FilterIndex filterIndex)
        {
            switch (filterIndex)
            {
            case FilterIndex.File:
                return(Options.FilesFolderPath);

            case FilterIndex.Template:
                return(Options.TemplatesFolderPath);

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 internal bool Save(FilterIndex filterIndex = FilterIndex.Default) =>
 string.IsNullOrEmpty(FilePath)
     ? SaveAs(filterIndex)
     : SaveToFile(FilePath);
Ejemplo n.º 8
0
 private SceneController OpenFile(FilterIndex filterIndex = FilterIndex.File) =>
 OpenFile(JsonController.SelectFilePath(filterIndex));
Ejemplo n.º 9
0
 private WorldCon OpenFile(FilterIndex filterIndex = FilterIndex.File) => OpenFile(JsonCon.SelectFilePath(filterIndex));
Ejemplo n.º 10
0
        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);
        }