Пример #1
0
 private static void AddFileDialogSettings(FileDialog dlg)
 {
     dlg.FileName = "Document";
     dlg.DefaultExt = ".dpad";
     dlg.Filter = "dynamicpad scripts (.dpad)|*.dpad";
     dlg.InitialDirectory = GetDynamicPadDirectory();
 }
 /// <summary>
 /// Runs new openfile dialog
 /// </summary>
 /// <returns>Stream to the file</returns>
 public Stream CreateOpenFileDialog()
 {
     _fileDialog = new OpenFileDialog();
     InitializeDialog();
     Stream streamToFile = CreateStream();
     return streamToFile;
 }
 /// <summary>
 /// Runs new save as dialog
 /// </summary>
 /// <returns>Stream to the file</returns>
 public Stream CreateSaveAsDialog()
 {
     _fileDialog = new SaveFileDialog();
     InitializeDialog();
     Stream streamToFile = CreateStream();
     return streamToFile;
 }
Пример #4
0
        private static FileDialogResult ShowFileDialog(object owner, FileDialog dialog, IEnumerable<FileType> fileTypes, 
            FileType defaultFileType, string defaultFileName)
        {
            int filterIndex = fileTypes.ToList().IndexOf(defaultFileType);
            if (filterIndex >= 0) { dialog.FilterIndex = filterIndex + 1; }
            if (!string.IsNullOrEmpty(defaultFileName))
            {
                dialog.FileName = Path.GetFileName(defaultFileName);
                string directory = Path.GetDirectoryName(defaultFileName);
                if (!string.IsNullOrEmpty(directory))
                {
                    dialog.InitialDirectory = directory;
                }
            }

            dialog.Filter = CreateFilter(fileTypes);
            if (dialog.ShowDialog(owner as Window) == true)
            {
                filterIndex = dialog.FilterIndex - 1;
                if (filterIndex >= 0 && filterIndex < fileTypes.Count())
                {
                    defaultFileType = fileTypes.ElementAt(filterIndex);
                }
                else
                {
                    defaultFileType = null;
                }
                return new FileDialogResult(dialog.FileName, defaultFileType);
            }
            else
            {
                return new FileDialogResult();
            }
        }
 private static void InitFileDialog(FileDialog dlg)
 {
     dlg.FileName = "default csharp";
     dlg.DefaultExt = ".cs";
     dlg.Filter = "C#(.cs)|*.cs";
     dlg.InitialDirectory = @"D:\study\programming\CSharp\WPF\WalkthroughWpf\Dialogs";
 }
        private FileDialogResult ShowDialog(FileDialog dialog, FileDialogOptions options)
        {
            if (dialog == null) throw new ArgumentNullException(nameof(dialog));

            if (options != null)
            {
                SetDialogProperties(dialog, options);
            }

            bool? result;

            //Try to get the active window
            var owner = WindowUtil.GetActiveWindow();

            if (owner == null)
            {
                result = dialog.ShowDialog();
            }
            else
            {
                result = dialog.ShowDialog(owner);
            }

            if (result == true)
            {
                return new FileDialogResult()
                {
                    FileName = dialog.FileName,
                    FileNames = dialog.FileNames
                };
            }

            return null;
        }
Пример #7
0
 public void Apply(FileDialog dialog)
 {
     dialog.Filter = Filter;
     dialog.FileName = FileNameWithoutExt;
     dialog.DefaultExt = DefaultExt;
     if (!string.IsNullOrEmpty(DefaultExt))
         dialog.AddExtension = true;
     dialog.Filter = Filter;
 }
Пример #8
0
        private FileInfo GetFileFromDialog(FileDialog fileDialog)
        {
            fileDialog.Filter = "Program Files|*.prg";
            fileDialog.ShowDialog();

            if (string.IsNullOrWhiteSpace(fileDialog.FileName))
                return null;
            else
                return new FileInfo(fileDialog.FileName);
        }
Пример #9
0
        /// <summary>
        ///  Show the given dialog and return its result.
        /// </summary>
        /// <param name="title">The title for the dialog.</param>
        /// <param name="filter">The file extension filter.</param>
        /// <param name="owner">The owning window for the browse dialog.</param>
        /// <param name="dialog">The dialog to show.</param>
        /// <returns>The selected path or null.</returns>
        private static IEnumerable<string> RunDialog(string title, string filter, Window owner, FileDialog dialog)
        {
            dialog.Title = title;
            dialog.Filter = filter;
            bool? fileCaptured = dialog.ShowDialog(owner);
            if (fileCaptured == true)
            {
                return dialog.FileNames;
            }

            return new List<string>();
        }
Пример #10
0
 private BrowseResult OpenDialog(FileDialog dialog, BrowseParams browseParams)
 {
     using (new PreserveWorkingDirectory())
     {
         browseParams.Apply(dialog);
         if (dialog.ShowDialog().GetValueOrDefault())
         {
             return new BrowseResult(true, dialog.FileName);
         }
         return new BrowseResult(false, null);
     }
 }
Пример #11
0
        public void trySavePoints(ObservableCollection<PointWrapper> points)
        {
            if (fileDialog == null)
            {
                fileDialog = new SaveFileDialog();
            }

            string fileName = getFileName();

            if (fileName != null)
            {
                savePoints(fileName, points);
            }
        }
Пример #12
0
 bool TryGetFilename(FileDialog dialog, out string filename)
 {
     bool ok = false;
     filename = null;
     dialog.DefaultExt = _defaultExt;
     dialog.Filter = _filter;
     dialog.ValidateNames = true;
     var dr = dialog.ShowDialog();
     if (dr.HasValue && dr.Value) {
         filename = dialog.FileName;
         ok = true;
     }
     return ok;
 }
        /// <summary>
        ///   Configures a <see cref = "FileDialog" /> and shows it to the user.
        /// </summary>
        /// <returns>
        ///   The full path to the file or null if no file was selected.
        /// </returns>
        private static string _ShowFilePrompt(FileDialog dialog, string filter)
        {
            dialog.AddExtension = true;
            dialog.CheckPathExists = true;
            dialog.DereferenceLinks = true;
            dialog.Filter = filter;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() ?? false)
            {
                return dialog.FileName;
            }

            return null;
        }
        private void SetDialogProperties(FileDialog dialog, FileDialogOptions options)
        {
            if (dialog == null) throw new ArgumentNullException(nameof(dialog));
            if (options == null) throw new ArgumentNullException(nameof(options));

            dialog.AddExtension = options.AddExtension;
            dialog.CheckFileExists = options.CheckFileExists;
            dialog.CheckPathExists = options.CheckPathExists;
            dialog.DefaultExt = options.DefaultExt;
            dialog.FileName = options.FileName;
            dialog.FilterIndex = options.FilterIndex;
            dialog.InitialDirectory = options.InitialDirectory;
            dialog.Title = options.Title;
            dialog.ValidateNames = options.ValidateNames;
            dialog.Filter = options.Filter;
        }
Пример #15
0
        private bool RunLegacyDialog(IntPtr hwndOwner)
        {
            NativeMethods.WndProc        lpfnHook       = new NativeMethods.WndProc(this.HookProc);
            NativeMethods.OPENFILENAME_I openfilename_I = new NativeMethods.OPENFILENAME_I();
            bool result;

            try
            {
                this._charBuffer = NativeMethods.CharBuffer.CreateBuffer(8192);
                if (this._fileNames != null)
                {
                    this._charBuffer.PutString(this._fileNames[0]);
                }
                openfilename_I.lStructSize     = Marshal.SizeOf(typeof(NativeMethods.OPENFILENAME_I));
                openfilename_I.hwndOwner       = hwndOwner;
                openfilename_I.hInstance       = IntPtr.Zero;
                openfilename_I.lpstrFilter     = FileDialog.MakeFilterString(this._filter, this.DereferenceLinks);
                openfilename_I.nFilterIndex    = this._filterIndex;
                openfilename_I.lpstrFile       = this._charBuffer.AllocCoTaskMem();
                openfilename_I.nMaxFile        = this._charBuffer.Length;
                openfilename_I.lpstrInitialDir = this._initialDirectory.Value;
                openfilename_I.lpstrTitle      = this._title.Value;
                openfilename_I.Flags           = (this.Options | 8912928);
                openfilename_I.lpfnHook        = lpfnHook;
                openfilename_I.FlagsEx         = 16777216;
                if (this._defaultExtension != null && this.AddExtension)
                {
                    openfilename_I.lpstrDefExt = this._defaultExtension;
                }
                result = this.RunFileDialog(openfilename_I);
            }
            finally
            {
                this._charBuffer = null;
                if (openfilename_I.lpstrFile != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(openfilename_I.lpstrFile);
                }
            }
            return(result);
        }
 public static string Show(FileDialog fileDialog, string filename, string filter)
 {
     try
     {
         if (!String.IsNullOrEmpty(filename))
         {
             fileDialog.FileName = filename;
         }
         if (!String.IsNullOrEmpty(filter))
         {
             fileDialog.Filter = filter;
         }
         bool? result = fileDialog.ShowDialog();
         if (result.HasValue && result.Value)
         {
             if (!string.IsNullOrEmpty(fileDialog.FileName)) return fileDialog.FileName;
         }
     }
     catch { }
     return string.Empty;
 }
Пример #17
0
        private static FileDialogResult ShowFileDialog(FileDialog dialog, IEnumerable<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
        {
            int filterIndex = fileTypes.ToList().IndexOf(defaultFileType);
            if (filterIndex >= 0) { dialog.FilterIndex = filterIndex + 1; }
            if (!string.IsNullOrEmpty(defaultFileName)) { dialog.FileName = defaultFileName; }

            dialog.Filter = CreateFilter(fileTypes);
            if (dialog.ShowDialog() == true)
            {
                if (dialog.FilterIndex - 1 < fileTypes.Count())
                {
                    defaultFileType = fileTypes.ElementAt(dialog.FilterIndex - 1);
                }
                else
                {
                    defaultFileType = null;
                }
                return new FileDialogResult(dialog.FileName, defaultFileType);
            }
            else
            {
                return new FileDialogResult();
            }
        }
Пример #18
0
        /// <summary>
        /// Configures the file dialog.
        /// </summary>
        /// <param name="fileDialog">The file dialog.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="fileDialog"/> is <c>null</c>.</exception>
        protected void ConfigureFileDialog(FileDialog fileDialog)
        {
            Argument.IsNotNull("fileDialog", fileDialog);

            string initialDirectory = string.Empty;
            if (!string.IsNullOrEmpty(InitialDirectory))
            {
                initialDirectory = IO.Path.AppendTrailingSlash(InitialDirectory);
            }

            fileDialog.Filter = Filter;
            fileDialog.FileName = FileName;

            fileDialog.AddExtension = AddExtension;
            fileDialog.CheckFileExists = CheckFileExists;
            fileDialog.CheckPathExists = CheckPathExists;
            fileDialog.FilterIndex = FilterIndex;
            fileDialog.InitialDirectory = initialDirectory;
            fileDialog.Title = Title;
            fileDialog.ValidateNames = ValidateNames;
        }
Пример #19
0
 FileDialogResult IUIServiceWpf.ShowFileDialog(FileDialog dialog)
 {
     var result = dialog.ShowDialog(this);
     return new FileDialogResult { FileName = dialog.FileName, DialogResult = result };
 }
Пример #20
0
        public bool? ShowDialog()
        {
            if (!IsEnabled)
                return null;

            try
            {
                switch (Mode)
                {
                    case Mode.None:
                        return null;
                    case Mode.Open:
                        dialog = new OpenFileDialog();
                        dialog.Filter = Filter;
                        break;
                    case Mode.Save:
                        dialog = new SaveFileDialog();
                        dialog.FileName = "default";
                        break;
                    default:
                        return null;
                }

                dialog.DefaultExt = DefaultExt;

                IsVisible = true;

                DialogResult = dialog.ShowDialog(_owner);

                if (Closing != null)
                    Closing(this, new CancelEventArgs(DialogResult != true));

                IsVisible = false;

                if (DialogResult == true)
                {
                    FileNames = dialog.FileNames;
                }

                if (Closed != null)
                    Closed(this, EventArgs.Empty);
            }
            finally
            {
                if (dialog != null)
                {
                    dialog = null;
                }
            }
            return DialogResult;
        }
Пример #21
0
 private static string AssemblyPaths(FileDialog dialog)
 {
     return dialog.FileNames.Aggregate("", (e, n) => e + n + Environment.NewLine);
 }
 private void SetFileDialogProperties(FileDialog dialog)
 {
     dialog.FileName = "BodyOrientation Savedata";
     dialog.AddExtension = true;
     dialog.DefaultExt = ".csd";
     dialog.Filter = "Combined save data (*csd)|*.csd";
     dialog.FilterIndex = 0;
 }
Пример #23
0
 void InitializeFileDialog(FileDialog fileDialog)
 {
     if (string.IsNullOrEmpty(Settings.Default.FileName))
     {
         fileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
     }
     else
     {
         fileDialog.InitialDirectory = new FileInfo(Settings.Default.FileName).DirectoryName;
     }
     fileDialog.DefaultExt = ".emir";
     fileDialog.Filter = "EmIR Files|*.emir|All Files|*.*";
 }
Пример #24
0
        private FileDialogResult ShowFileDialog(object ownerViewModel, FileDialog dialog, string title, IList<FileType> fileTypes, FileType defaultFileType, string defaultFileName)
        {
            if (!string.IsNullOrEmpty(title))
                dialog.Title = title;
            List<FileType> fileTypesList = fileTypes.ToList();
            int filterIndex = fileTypesList.IndexOf(defaultFileType);
            if (filterIndex >= 0) { dialog.FilterIndex = filterIndex + 1; }
            if (!string.IsNullOrEmpty(defaultFileName))
            {
                dialog.FileName = Path.GetFileName(defaultFileName);
                string directory = Path.GetDirectoryName(defaultFileName);
                if (!string.IsNullOrEmpty(directory))
                {
                    dialog.InitialDirectory = directory;
                }
            }

            dialog.Filter = CreateFilter(fileTypesList);
            if (dialog.ShowDialog(FindOwnerWindow(ownerViewModel)) == true)
            {
                filterIndex = dialog.FilterIndex - 1;
                if (filterIndex >= 0 && filterIndex < fileTypesList.Count)
                {
                    defaultFileType = fileTypesList[filterIndex];
                }
                else
                {
                    defaultFileType = null;
                }
                return new FileDialogResult(dialog.FileName, defaultFileType);
            }

            return new FileDialogResult();
        }
Пример #25
0
 private static void SetupGameFileDialog(FileDialog dlg)
 {
     dlg.DefaultExt = "clueBuddy";
     dlg.Filter = "ClueBuddy games (*.clueBuddy)|*.clueBuddy|All Files|*.*";
     dlg.FilterIndex = 0;
 }
 private static void FillLabelWithFilePath(Label label, FileDialog dlg)
 {
     label.Content = dlg.ShowDialog() == true ? dlg.FileName : "Non Selected";
 }
Пример #27
0
 private static string GetDialogText(Microsoft.Win32.FileDialog fileDialog) =>
 fileDialog.ShowDialog() != true || string.IsNullOrEmpty(fileDialog.FileName)
         ? null
         : fileDialog.FileName;
 private static string ShowDialogToGetPath(FileDialog dialog)
 {
     dialog.Filter = IMAGE_FILE_FILTER;
     return dialog.ShowDialog() == true ? dialog.FileName : null;
 }
Пример #29
0
        private void ShowFileDialog(FileDialog dlg, DialogResult dlgResult)
        {
            dlg.DefaultExt = ".stf";
            dlg.Filter = _filter;

            var result = dlg.ShowDialog();

            if (result == true)
            {
                if (dlg.FilterIndex == 1)
                    dlgResult.SelectedFileType = SecureFileType.Encrypted;
                else
                    dlgResult.SelectedFileType = SecureFileType.ClearText;

                dlgResult.FilePath = dlg.FileName;
                //dlgResult.DialogType = dlg.GetType() == typeof(OpenFileDialog) ? FileDialogType.Open : FileDialogType.Save;

                _main.ProcessDialog(dlgResult);
            }
        }
 protected DefaultFileDialogService(FileDialog fd)
 {
     _fd = fd;
 }
        private void SetGetLogicFileDialogExtensionAndFilter(FileDialog fileDialog)
        {
            fileDialog.DefaultExt = FileIOLogic.DefaultAlgorithmsLogicFileExtension;

            fileDialog.Filter =
                String.Format("NeuralNetworks2 Logic File (*{0})|*{0}|All files (*.*)|*.*",
                FileIOLogic.DefaultAlgorithmsLogicFileExtension);
        }
Пример #32
0
 private void SetFilenameIfAvailable(FileDialog dlg)
 {
     if (_saveFile.IsSaveFileDefined)
         dlg.FileName = _saveFile.FileName;
 }