Ejemplo n.º 1
0
        public void HandleAction(IActionContext actionContext)
        {
            void SetIfNotEmpty(string path)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    SettingValue = path;
                }
            }

            FileDialogOptions options = new FileDialogOptions(_filter, initialDirectory: SettingValue);

            if (IsFolderPicker)
            {
                string folderPath = _dialogService.ShowSelectFolderDialog(options);
                SetIfNotEmpty(folderPath);

                return;
            }

            string filePath = IsSaveFilePicker
                                ? _dialogService.ShowSaveFileDialog(options)
                                : _dialogService.ShowOpenFileDialog(options);

            SetIfNotEmpty(filePath);
        }
Ejemplo n.º 2
0
        Optional <FileDialogResult> OpenFileSync(FileDialogOptions options)
        {
            var ofd = new Microsoft.Win32.OpenFileDialog
            {
                Title           = options.Caption,
                Filter          = options.Filters.CreateFilterString(),
                CheckPathExists = true,
                CheckFileExists = true,
            };

            FilterString.Parse(ofd.Filter).Each(f => Console.WriteLine(f));

            if (options.Directory != null)
            {
                ofd.InitialDirectory = options.Directory.NativePath;
            }

            var success = _window == null?ofd.ShowDialog() : ofd.ShowDialog(_window);

            var filename = ofd.FileName;
            var result   = new FileDialogResult();

            if (success.Value)
            {
                result.Path   = AbsoluteFilePath.Parse(ofd.FileName);
                result.Filter = FilterAtIndex(ofd.Filter, ofd.FilterIndex);
            }

            Focus();

            return(success.Value
                                ? Optional.Some(result)
                                : Optional.None <FileDialogResult>());
        }
Ejemplo n.º 3
0
        Optional <FileDialogResult> OpenFileSync(FileDialogOptions options)
        {
            var dialog = new OpenDialog(options.Filters)
            {
                Title       = options.Caption,
                Multiselect = false
            };

            if (options.Directory != null)
            {
                dialog.Directory = options.Directory;
            }

            var success = dialog.Run();

            FileDialogResult result = new FileDialogResult();

            if (success)
            {
                result = new FileDialogResult(dialog.FilePath, dialog.CurrentFilter);
            }

            return(success
                                ? Optional.Some(result)
                                : Optional.None <FileDialogResult>());
        }
Ejemplo n.º 4
0
        public void SelectPath()
        {
            void SetIfNotEmpty(string path)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    Path = path;
                }
            }

            FileDialogOptions options = new FileDialogOptions(Filter, Window.GetWindow(this), Path);

            if (IsFolderPicker)
            {
                string folderPath = DialogService.ShowSelectFolderDialog(options);
                SetIfNotEmpty(folderPath);

                return;
            }

            string filePath = IsSaveFilePicker
                                ? DialogService.ShowSaveFileDialog(options)
                                : DialogService.ShowOpenFileDialog(options);

            SetIfNotEmpty(filePath);
        }
Ejemplo n.º 5
0
        Optional <IEnumerable <FileDialogResult> > OpenFilesSync(FileDialogOptions options)
        {
            var dialog = new OpenDialog(options.Filters)
            {
                Title       = options.Caption,
                Multiselect = true
            };

            if (options.Directory != null)
            {
                dialog.Directory = options.Directory;
            }

            var success = dialog.Run();

            IEnumerable <FileDialogResult> result = null;

            if (success)
            {
                result = dialog.FilePaths.Select(f => new FileDialogResult(f, dialog.CurrentFilter));
            }

            return(success
                                ? Optional.Some(result)
                                : Optional.None <IEnumerable <FileDialogResult> >());
        }
Ejemplo n.º 6
0
        Optional <FileDialogResult> SaveFileSync(FileDialogOptions options)
        {
            var ofd = new Microsoft.Win32.SaveFileDialog
            {
                Title           = options.Caption,
                Filter          = options.Filters.CreateFilterString(),
                OverwritePrompt = true,
            };

            if (options.Directory != null)
            {
                ofd.InitialDirectory = options.Directory.NativePath;
            }

            var success = _window == null?ofd.ShowDialog() : ofd.ShowDialog(_window);

            var filename = ofd.FileName;
            var result   = new FileDialogResult();

            if (success.Value)
            {
                result.Path   = AbsoluteFilePath.Parse(ofd.FileName);
                result.Filter = FilterAtIndex(ofd.Filter, ofd.FilterIndex);
            }
            Focus();

            return(success.Value
                                ? Optional.Some(result)
                                : Optional.None <FileDialogResult>());
        }
Ejemplo n.º 7
0
        public DialogResponse FileOpen64(string message, FileDialogOptions options)
        {
            var ofn = new WindowsInterop.OPENFILENAME_64();

            ofn.lstructSize = Marshal.SizeOf(ofn);

            if (Directory.Exists(options.Directory))
            {
                ofn.lpstrInitialDir = options.Directory;
            }

            ofn.lpstrFilter = options.Filters
                              .Select(f => $"{f.Name}\0*.{f.Extension}\0")
                              .Aggregate("", (s1, s2) => s1 + s2)
                              + "\0";

            ofn.lpstrFile = new string(' ', 4096);
            ofn.lMaxFile  = ofn.lpstrFile.Length;

            ofn.lpstrTitle    = options.Title;
            ofn.lMaxFileTitle = ofn.lpstrTitle.Length;

            ofn.lFlags = WindowsInterop.OFN_EXPLORER;
            if (options.MustExist)
            {
                ofn.lFlags |= WindowsInterop.OFN_PATHMUSTEXIST | WindowsInterop.OFN_FILEMUSTEXIST;
            }

            var ok = WindowsInterop.GetOpenFileName64(ofn);

            return(new DialogResponse {
                IsCanceled = !ok, Value = ofn.lpstrFile
            });
        }
Ejemplo n.º 8
0
        Optional <FileDialogResult> SaveFileSync(FileDialogOptions options)
        {
            var dialog = new SaveDialog(options.Filters)
            {
                Title = options.Caption,
            };

            if (options.Directory != null)
            {
                dialog.Directory = options.Directory;
            }

            var success = dialog.Run(_window);

            FileDialogResult result = new FileDialogResult();

            if (success)
            {
                result = new FileDialogResult(dialog.FilePath, dialog.CurrentFilter);
            }

            return(success
                                ? Optional.Some(result)
                                : Optional.None <FileDialogResult>());
        }
Ejemplo n.º 9
0
        public App(LocalNotificationManager manager)
        {
            this.manager = manager;
            formatter    = new JsonFormatter();
            FileDialogOptions readOptions = new FileDialogOptions
            {
                StartLocation  = PickerLocationId.DocumentsLibrary,
                FileExtensions = new[]
                {
                    new FileExtension {
                        Name = "JSON", FileSuffix = "json"
                    },
                    new FileExtension {
                        Name = "TEXT", FileSuffix = "txt"
                    }
                }
            };

            FileDialogOptions writeOptions = new FileDialogOptions
            {
                StartLocation   = PickerLocationId.DocumentsLibrary,
                DefaultFileName = "formattedJson",
                FileExtensions  = new[]
                {
                    new FileExtension {
                        Name = "JSON", FileSuffix = "json"
                    },
                }
            };

            reader = new FileReader(readOptions);
            writer = new FileWriter(writeOptions);
        }
Ejemplo n.º 10
0
        public DialogResponse FileOpen(string message, FileDialogOptions options)
        {
            var widget   = IntPtr.Zero;
            var response = GtkInterop.ResponseType.GTK_RESPONSE_OK;
            var ok       = GtkInterop.AllocGtkString("OK");
            var cancel   = GtkInterop.AllocGtkString("Cancel");
            var fileName = "";

            try
            {
                widget = GtkInterop.gtk_file_chooser_dialog_new(options.Title, IntPtr.Zero,
                                                                GtkInterop.FileChooserAction.GTK_FILE_CHOOSER_ACTION_OPEN,
                                                                ok, (int)GtkInterop.ResponseType.GTK_RESPONSE_OK,
                                                                cancel, (int)GtkInterop.ResponseType.GTK_RESPONSE_CANCEL,
                                                                IntPtr.Zero);

                if (!string.IsNullOrEmpty(options.Directory) && Directory.Exists(options.Directory))
                {
                    GtkInterop.gtk_file_chooser_set_current_folder(widget, options.Directory);
                }
                if (options.MustExist)
                {
                    Log.Error("FileOpen option MustExist not supported.");
                }

                foreach (var fileFilter in options.Filters)
                {
                    var filter = GtkInterop.gtk_file_filter_new();
                    GtkInterop.gtk_file_filter_set_name(filter, fileFilter.Name);
                    GtkInterop.gtk_file_filter_add_pattern(filter, $"*.{fileFilter.Extension}");
                    GtkInterop.gtk_file_chooser_add_filter(widget, filter);
                }

                response = GtkInterop.gtk_dialog_run(widget);
                if (response == GtkInterop.ResponseType.GTK_RESPONSE_OK)
                {
                    fileName = Uri.UnescapeDataString(GtkInterop.gtk_file_chooser_get_filename(widget));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                GtkInterop.gtk_widget_destroy(widget);
                GtkInterop.g_free(ok);
                GtkInterop.g_free(cancel);
            }

            return(new DialogResponse
            {
                IsCanceled = response != GtkInterop.ResponseType.GTK_RESPONSE_OK,
                Value = fileName
            });
        }
Ejemplo n.º 11
0
 public FileReader(FileDialogOptions fileDialogOptions)
 {
     fileOpen = new FileOpenPicker
     {
         ViewMode = PickerViewMode.Thumbnail,
         SuggestedStartLocation = fileDialogOptions.StartLocation
     };
     foreach (var extension in fileDialogOptions.FileExtensions)
     {
         fileOpen.FileTypeFilter.Add(extension.FileSuffix);
     }
 }
Ejemplo n.º 12
0
        private void SaveFile()
        {
            var options = new FileDialogOptions()
            {
                Filter = Filter
            };

            var result = _fileDialogService.ShowSaveFileDialog(options);

            if (result != null)
            {
                FileName = result.FileName;
            }
        }
Ejemplo n.º 13
0
 public FileWriter(FileDialogOptions fileDialogOptions)
 {
     fileSave = new FileSavePicker
     {
         SuggestedStartLocation = fileDialogOptions.StartLocation
     };
     foreach (var extension in fileDialogOptions.FileExtensions)
     {
         fileSave.FileTypeChoices.Add(extension.Name, new List <string> {
             extension.FileSuffix
         });
     }
     defaultFileName            = fileDialogOptions.DefaultFileName;
     fileSave.SuggestedFileName = defaultFileName;
 }
Ejemplo n.º 14
0
        private DialogResponse SelectFolderInternal(string message, FileDialogOptions options)
        {
            if (Directory.Exists(options.Directory))
            {
                _initialPath = options.Directory;
            }
            var pIdList       = IntPtr.Zero;
            var sb            = new StringBuilder(256);
            var bufferAddress = Marshal.AllocHGlobal(256);
            var bi            = new WindowsInterop.BROWSEINFO
            {
                hwndOwner      = IntPtr.Zero,
                pidlRoot       = IntPtr.Zero,
                pszDisplayName = message,
                lpszTitle      = options.Title,
                ulFlags        = WindowsInterop.BIF_NEWDIALOGSTYLE | WindowsInterop.BIF_SHAREABLE,
                lpfn           = OnBrowseEvent,
                lParam         = IntPtr.Zero,
                iImage         = 0
            };

            try
            {
                pIdList = WindowsInterop.SHBrowseForFolder(ref bi);
                if (pIdList == IntPtr.Zero)
                {
                    return(new DialogResponse {
                        IsCanceled = true
                    });
                }
                if (true != WindowsInterop.SHGetPathFromIDList(pIdList, bufferAddress))
                {
                    return(new DialogResponse {
                        Value = string.Empty
                    });
                }
                sb.Append(Marshal.PtrToStringAuto(bufferAddress));
            }
            finally
            {
                // Caller is responsible for freeing this memory.
                Marshal.FreeCoTaskMem(pIdList);
            }

            return(new DialogResponse {
                Value = sb.ToString()
            });
        }
        private void Open()
        {
            var options = new FileDialogOptions()
            {
                Filter = FileFilter
            };

            var result = _fileDialogService.ShowOpenFileDialog(options);

            if (result != null)
            {
                var metadata = HostPersistor.LoadFromFile(result.FileName);

                Filename = result.FileName;

                Program = new ProgramViewModel(metadata.Functions);
            }
        }
        private bool SaveAs()
        {
            var options = new FileDialogOptions()
            {
                Filter = FileFilter
            };

            var result = _fileDialogService.ShowSaveFileDialog(options);

            if (result != null)
            {
                Filename = result.FileName;

                SaveInner();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        private bool SaveAs()
        {
            var options = new FileDialogOptions()
            {
                Filter = Filter
            };

            var result = _fileDialogService.ShowSaveFileDialog(options);

            if (result == null)
            {
                return(false);
            }

            File.WriteAllText(result.FileName, Text);
            Path = result.FileName;
            _dirtyService.MarkClean();

            return(true);
        }
Ejemplo n.º 18
0
        public DialogResponse SelectFolder(string message, FileDialogOptions options)
        {
            var result = new DialogResponse {
                IsCanceled = true
            };
            var th = new Thread(() =>
            {
                WindowsInterop.OleInitialize(IntPtr.Zero);
                result = SelectFolderInternal(message, options);
            })
            {
#pragma warning disable 618
                ApartmentState = ApartmentState.STA
#pragma warning restore 618
            };

            th.Start();
            th.Join();
            return(result);
        }
Ejemplo n.º 19
0
        private void Open()
        {
            if (!SaveIfDirty())
            {
                return;
            }

            var options = new FileDialogOptions()
            {
                Filter = Filter
            };

            var result = _fileDialogService.ShowOpenFileDialog(options);

            if (result != null)
            {
                Path = result.FileName;
                Text = File.ReadAllText(result.FileName);

                _dirtyService.MarkClean();
            }
        }
Ejemplo n.º 20
0
        public DialogResponse SelectFolder(string message, FileDialogOptions options)
        {
            var widget   = IntPtr.Zero;
            var response = GtkInterop.ResponseType.GTK_RESPONSE_OK;
            var ok       = GtkInterop.AllocGtkString("OK");
            var cancel   = GtkInterop.AllocGtkString("Cancel");
            var folder   = "";

            try
            {
                widget = GtkInterop.gtk_file_chooser_dialog_new(options.Title, IntPtr.Zero,
                                                                GtkInterop.FileChooserAction.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
                                                                ok, (int)GtkInterop.ResponseType.GTK_RESPONSE_OK,
                                                                cancel, (int)GtkInterop.ResponseType.GTK_RESPONSE_CANCEL,
                                                                IntPtr.Zero);
                response = GtkInterop.gtk_dialog_run(widget);
                if (response == GtkInterop.ResponseType.GTK_RESPONSE_OK)
                {
                    var uri = new Uri(GtkInterop.gtk_file_chooser_get_uri(widget));
                    folder = Uri.UnescapeDataString(uri.AbsolutePath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                GtkInterop.gtk_widget_destroy(widget);
                GtkInterop.g_free(ok);
                GtkInterop.g_free(cancel);
            }

            return(new DialogResponse
            {
                IsCanceled = response != GtkInterop.ResponseType.GTK_RESPONSE_OK,
                Value = folder
            });
        }
Ejemplo n.º 21
0
        Optional <IEnumerable <FileDialogResult> > OpenFilesSync(FileDialogOptions options)
        {
            var ofd = new Microsoft.Win32.OpenFileDialog
            {
                Title           = options.Caption,
                Filter          = options.Filters.CreateFilterString(),
                CheckPathExists = true,
                CheckFileExists = true,
                Multiselect     = true,
            };

            Console.WriteLine(FilterString.Parse(ofd.Filter));

            if (options.Directory != null)
            {
                ofd.InitialDirectory = options.Directory.NativePath;
            }

            var success = _window == null?ofd.ShowDialog() : ofd.ShowDialog(_window);

            var filenames = ofd.FileNames;

            filenames.Select(AbsoluteFilePath.Parse);
            IEnumerable <FileDialogResult> results = null;

            if (success.Value)
            {
                var f = FilterAtIndex(ofd.Filter, ofd.FilterIndex);
                results = ofd.FileNames.Select(
                    p => new FileDialogResult(AbsoluteFilePath.Parse(p), f)
                    );
            }

            Focus();

            return(success.Value
                                ? Optional.Some(results)
                                : Optional.None <IEnumerable <FileDialogResult> >());
        }
Ejemplo n.º 22
0
 public DialogResponse FileOpen(string message, FileDialogOptions options)
 {
     return(Environment.Is64BitProcess
         ? FileOpen64(message, options)
         : FileOpen32(message, options));
 }
Ejemplo n.º 23
0
 public DialogResponse FileSave(string message, string fileName, FileDialogOptions options)
 {
     return(Environment.Is64BitProcess
         ? FileSave64(message, fileName, options)
         : FileSave32(message, fileName, options));
 }
Ejemplo n.º 24
0
 public Task <Optional <IEnumerable <FileDialogResult> > > OpenFiles(FileDialogOptions options)
 {
     return(_dispatcher.InvokeAsync(() => OpenFilesSync(options)).Task);
 }
Ejemplo n.º 25
0
        /// <summary>
        ///     ファイルダイアログオプションを設定します。
        /// </summary>
        /// <param name="fileDialogOptions"></param>
        public void SetOptions(FileDialogOptions fileDialogOptions)
        {
            var options = FILEOPENDIALOGOPTIONS.FOS_NOTESTFILECREATE | (FILEOPENDIALOGOPTIONS)fileDialogOptions;

            this.FileDialogNative.SetOptions(options);
        }
Ejemplo n.º 26
0
 public Task <Optional <IEnumerable <FileDialogResult> > > OpenFiles(FileDialogOptions options)
 {
     return(Fusion.Application.MainThread.InvokeAsync(() => OpenFilesSync(options)));
 }
Ejemplo n.º 27
0
 public Task <Optional <FileDialogResult> > SaveFile(FileDialogOptions options)
 {
     return(Fusion.Application.MainThread.InvokeAsync(() => SaveFileSync(options)));
 }
Ejemplo n.º 28
0
 public static Task <Optional <FileDialogResult> > OpenFile(FileDialogOptions options, Optional <IControl> windowControl = default(Optional <IControl>))
 {
     return(Implementation(windowControl).OpenFile(options));
 }
Ejemplo n.º 29
0
 public Task <Optional <FileDialogResult> > SaveFile(FileDialogOptions options)
 {
     return(_dispatcher.InvokeAsync(() => SaveFileSync(options)).Task);
 }