Beispiel #1
0
        public static bool Show(out string[] Paths, string Title = "", DialogProviderMode DialogProviderMode = DialogProviderMode.OpenFile, DialogProviderSelectionMode DialogProviderSelectionMode = DialogProviderSelectionMode.Single, IEnumerable <string> Extensions = null, string DefaultPath = "")
        {
            Paths = new string[0];

            var Dialog = GetDialog(Title, DialogProviderMode, DialogProviderSelectionMode, Extensions, DefaultPath);

            var Result = Dialog.ShowDialog();

            if (Result == CommonFileDialogResult.Ok)
            {
                switch (DialogProviderMode)
                {
                case DialogProviderMode.Open:
                case DialogProviderMode.OpenFile:
                case DialogProviderMode.OpenFolder:
                    Paths = (Dialog as CommonOpenFileDialog).FileNames.ToArray <string>();
                    break;

                case DialogProviderMode.SaveFile:
                    Paths = new string[]
                    {
                        (Dialog as CommonSaveFileDialog).FileName
                    };
                    break;
                }
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public static bool Show(out string Path, string Title = "", DialogProviderMode DialogProviderMode = DialogProviderMode.OpenFile, IEnumerable <string> Extensions = null, string DefaultPath = "")
        {
            Path = string.Empty;

            var Dialog = GetDialog(Title, DialogProviderMode, DialogProviderSelectionMode.Single, Extensions, DefaultPath);

            var Result = Dialog.ShowDialog();

            if (Result == CommonFileDialogResult.Ok)
            {
                Path = (Dialog as CommonFileDialog).FileName;
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        static CommonFileDialog GetDialog(string Title, DialogProviderMode DialogProviderMode, DialogProviderSelectionMode DialogProviderSelectionMode, IEnumerable <string> Extensions, string DefaultPath)
        {
            var Result = default(CommonFileDialog);

            var f = DialogProviderMode == DialogProviderMode.OpenFolder;

            switch (DialogProviderMode)
            {
            case DialogProviderMode.Open:
            case DialogProviderMode.OpenFile:
            case DialogProviderMode.OpenFolder:
                Result = new CommonOpenFileDialog()
                {
                    AddToMostRecentlyUsedList = true,
                    AllowNonFileSystemItems   = f,
                    DefaultDirectory          = Environment.SpecialFolder.Desktop.GetPath(),
                    DefaultFileName           = DefaultPath.IsNull() ? string.Empty : DefaultPath,
                    EnsureValidNames          = true,
                    EnsureFileExists          = !f,
                    EnsurePathExists          = true,
                    InitialDirectory          = DefaultPath,
                    IsFolderPicker            = f,
                    Multiselect        = DialogProviderSelectionMode == DialogProviderSelectionMode.Multiple || f,
                    NavigateToShortcut = true,
                    ShowHiddenItems    = true,
                    ShowPlacesList     = true,
                    Title = Title.IsNullOrEmpty() ? DefaultTitle.Open : Title,
                };
                break;

            case DialogProviderMode.SaveFile:
                Result = new CommonSaveFileDialog()
                {
                    AddToMostRecentlyUsedList    = true,
                    AlwaysAppendDefaultExtension = true,
                    DefaultDirectory             = Environment.SpecialFolder.Desktop.GetPath(),
                    EnsureValidNames             = true,
                    InitialDirectory             = DefaultPath,
                    IsExpandedMode     = true,
                    NavigateToShortcut = true,
                    OverwritePrompt    = true,
                    ShowHiddenItems    = true,
                    ShowPlacesList     = true,
                    Title = Title.IsNullOrEmpty() ? DefaultTitle.Save : Title,
                };
                break;
            }
            if (Extensions != null && !f)
            {
                foreach (var i in Extensions)
                {
                    Result.Filters.Add(new CommonFileDialogFilter(i.ToUpper() + " Files", "*." + i));
                }
            }

            if (!f)
            {
                Result.Filters.Add(new CommonFileDialogFilter("(*) All Files", "*"));
            }

            return(Result);
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Value"></param>
 protected virtual void OnBrowseModeChanged(DialogProviderMode Value)
 {
     OnCanValidateChanged(CanValidate);
 }