コード例 #1
0
 /// <summary>
 /// フィルタパターンリスト文字列からファイル保存ダイアログパラメータのFiltersを設定する。
 /// </summary>
 /// <param name="self">設定対象のパラメータ</param>
 /// <param name="filtersText">フィルタパターンリスト文字列</param>
 public static void SetFiltersFrom(this ShellSaveFileDialogParameter self, string filtersText)
 {
     setFilters(self.Filters, filtersText);
 }
コード例 #2
0
 /// <summary>
 /// パスリスト文字列からファイル保存ダイアログパラメータのAdditionalPlacesを設定する。
 /// </summary>
 /// <param name="self">設定対象のパラメータ</param>
 /// <param name="placesText">パスリスト文字列</param>
 public static void SetAdditionalPlaces(this ShellSaveFileDialogParameter self, string placesText)
 {
     setPlaces(self.AdditionalPlaces, placesText);
 }
コード例 #3
0
        // 構築
        #region コンストラクタ
        /// <summary>
        /// デフォルトコンストラクタ
        /// </summary>
        public SaveFileDialogViewModel()
        {
            // ダイアログ表示用インタラクションヘルパ
            var showInteraction = new ReactiveInteraction <ShellSaveFileDialogActionParameter>();

            // ダイアログ表示用インタラクションのトリガソース
            this.ShowDialogRequest = showInteraction.Source;

            // ビューのエラー状態
            this.HasViewError = new ReactivePropertySlim <bool>()
                                .AddTo(this.Disposables);

            // ダイアログ結果設定用デリゲート
            var dlgResultFilter = default(Action <uint?>);
            var dlgResultItem   = default(Action <string>);

            // ダイアログ表示コマンド
            this.ShowDialogCommand = new[]
            {
                this.HasViewError.Inverse(),
            }
            .CombineLatestValuesAreAllTrue()
            .ToReactiveCommand()
            .WithSubscribe(() => showSaveDialog())
            .AddTo(this.Disposables);

            // デフォルト設定参照用
            var defParam = new ShellSaveFileDialogParameter();

            #region 動作設定:状態設定
            this.Directory = new ReactivePropertySlim <string>(defParam.Directory)
                             .AddTo(this.Disposables);

            this.InitialFileName = new ReactivePropertySlim <string>(defParam.InitialFileName)
                                   .AddTo(this.Disposables);

            this.DefaultExtension = new ReactivePropertySlim <string>(defParam.DefaultExtension)
                                    .AddTo(this.Disposables);

            this.Filters = new ReactivePropertySlim <string>(string.Join("\n", new[]
            {
                "画像ファイル|*.png;*.jpg;*.gif;*.bmp",
                "テキストファイル|*.txt;*.text;",
                "全てのファイル|*.*",
            }))
                           .AddTo(this.Disposables);

            this.InitialFilterIndex = new ReactivePropertySlim <uint>(defParam.InitialFilterIndex)
                                      .AddTo(this.Disposables);

            this.DefaultDirectory = new ReactivePropertySlim <string>(defParam.DefaultDirectory)
                                    .AddTo(this.Disposables);

            this.ClientGuid = new ReactivePropertySlim <Guid>(defParam.ClientGuid)
                              .AddTo(this.Disposables);
            #endregion

            #region 動作設定:オプション
            this.OverwritePrompt = new ReactivePropertySlim <bool>(defParam.OverwritePrompt)
                                   .AddTo(this.Disposables);

            this.StrictFileTypes = new ReactivePropertySlim <bool>(defParam.StrictFileTypes)
                                   .AddTo(this.Disposables);

            this.NoChangeDirectory = new ReactivePropertySlim <bool>(defParam.NoChangeDirectory)
                                     .AddTo(this.Disposables);

            this.ForceFileSystem = new ReactivePropertySlim <bool>(defParam.ForceFileSystem)
                                   .AddTo(this.Disposables);

            this.AllNonStorageItems = new ReactivePropertySlim <bool>(defParam.AllNonStorageItems)
                                      .AddTo(this.Disposables);

            this.NoValidate = new ReactivePropertySlim <bool>(defParam.NoValidate)
                              .AddTo(this.Disposables);

            this.PathMustExist = new ReactivePropertySlim <bool>(defParam.PathMustExist)
                                 .AddTo(this.Disposables);

            this.FileMustExist = new ReactivePropertySlim <bool>(defParam.FileMustExist)
                                 .AddTo(this.Disposables);

            this.CreatePrompt = new ReactivePropertySlim <bool>(defParam.CreatePrompt)
                                .AddTo(this.Disposables);

            this.ShareAware = new ReactivePropertySlim <bool>(defParam.ShareAware)
                              .AddTo(this.Disposables);

            this.NoReadOnlyReturn = new ReactivePropertySlim <bool>(defParam.NoReadOnlyReturn)
                                    .AddTo(this.Disposables);

            this.NoTestFileCreate = new ReactivePropertySlim <bool>(defParam.NoTestFileCreate)
                                    .AddTo(this.Disposables);

            this.HidePinnedPlaces = new ReactivePropertySlim <bool>(defParam.HidePinnedPlaces)
                                    .AddTo(this.Disposables);

            this.NoDereferenceLinks = new ReactivePropertySlim <bool>(defParam.NoDereferenceLinks)
                                      .AddTo(this.Disposables);

            this.OkButtonNeedsInteraction = new ReactivePropertySlim <bool>(defParam.OkButtonNeedsInteraction)
                                            .AddTo(this.Disposables);

            this.DontAddToRecent = new ReactivePropertySlim <bool>(defParam.DontAddToRecent)
                                   .AddTo(this.Disposables);

            this.ForceShowHidden = new ReactivePropertySlim <bool>(defParam.ForceShowHidden)
                                   .AddTo(this.Disposables);
            #endregion

            #region 動作設定:ダイアログカスタマイズ
            this.Title = new ReactivePropertySlim <string>(defParam.Title)
                         .AddTo(this.Disposables);

            this.AcceptButtonLabel = new ReactivePropertySlim <string>(defParam.AcceptButtonLabel)
                                     .AddTo(this.Disposables);

            this.FileNameLabel = new ReactivePropertySlim <string>(defParam.FileNameLabel)
                                 .AddTo(this.Disposables);

            this.AdditionalPlaces = new ReactivePropertySlim <string>(string.Join("\n", new[]
            {
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
            }))
                                    .AddTo(this.Disposables);
            #endregion

            #region ダイアログ結果
            this.ResultFilterIndex = Observable.FromEvent <uint?>(h => dlgResultFilter += h, h => dlgResultFilter -= h)
                                     .ToReadOnlyReactivePropertySlim()
                                     .AddTo(this.Disposables);

            this.ResultItems = Observable.FromEvent <string>(h => dlgResultItem += h, h => dlgResultItem -= h)
                               .ToReadOnlyReactivePropertySlim()
                               .AddTo(this.Disposables);
            #endregion

            #region ローカル関数
            // ファイルオープンダイアログ表示ローカル関数
            void showSaveDialog()
            {
                // ダイアログパラメータを準備
                var dlgParam = new ShellSaveFileDialogParameter();

                dlgParam.Directory        = this.Directory.ValueIfNotEmpty();
                dlgParam.InitialFileName  = this.InitialFileName.ValueIfNotEmpty();
                dlgParam.DefaultExtension = this.DefaultExtension.ValueIfNotEmpty();
                dlgParam.SetFiltersFrom(this.Filters.Value);
                dlgParam.InitialFilterIndex = this.InitialFilterIndex.Value;
                dlgParam.DefaultDirectory   = this.DefaultDirectory.ValueIfNotEmpty();
                dlgParam.ClientGuid         = this.ClientGuid.Value;

                dlgParam.OverwritePrompt          = this.OverwritePrompt.Value;
                dlgParam.StrictFileTypes          = this.StrictFileTypes.Value;
                dlgParam.NoChangeDirectory        = this.NoChangeDirectory.Value;
                dlgParam.ForceFileSystem          = this.ForceFileSystem.Value;
                dlgParam.AllNonStorageItems       = this.AllNonStorageItems.Value;
                dlgParam.NoValidate               = this.NoValidate.Value;
                dlgParam.PathMustExist            = this.PathMustExist.Value;
                dlgParam.FileMustExist            = this.FileMustExist.Value;
                dlgParam.CreatePrompt             = this.CreatePrompt.Value;
                dlgParam.ShareAware               = this.ShareAware.Value;
                dlgParam.NoReadOnlyReturn         = this.NoReadOnlyReturn.Value;
                dlgParam.NoTestFileCreate         = this.NoTestFileCreate.Value;
                dlgParam.HidePinnedPlaces         = this.HidePinnedPlaces.Value;
                dlgParam.NoDereferenceLinks       = this.NoDereferenceLinks.Value;
                dlgParam.OkButtonNeedsInteraction = this.OkButtonNeedsInteraction.Value;
                dlgParam.DontAddToRecent          = this.DontAddToRecent.Value;
                dlgParam.ForceShowHidden          = this.ForceShowHidden.Value;

                dlgParam.Title             = this.Title.ValueIfNotEmpty();
                dlgParam.AcceptButtonLabel = this.AcceptButtonLabel.ValueIfNotEmpty();
                dlgParam.FileNameLabel     = this.FileNameLabel.ValueIfNotEmpty();
                dlgParam.SetAdditionalPlaces(this.AdditionalPlaces.Value);

                // ダイアログ表示インタラクションパラメータを準備
                var actionParam = new ShellSaveFileDialogActionParameter();

                actionParam.Parameter = dlgParam;

                // ダイアログ表示要求を発行
                showInteraction.Raise(actionParam);

                // 結果をプロパティに設定
                if (actionParam.Exception != null)
                {
                    // なんらか例外が生じた
                    dlgResultItem?.Invoke(actionParam.Exception.Message);
                    dlgResultFilter?.Invoke(null);
                }
                else if (actionParam.Result != null)
                {
                    // ダイアログ結果。表示してキャンセルした場合を含む。
                    var item = actionParam.Result.Item ?? "<cancelled>";
                    dlgResultItem?.Invoke(item);
                    dlgResultFilter?.Invoke(actionParam.Result.FilterIndex);
                }
                else
                {
                    // 通常あり得ない状態。
                    dlgResultItem?.Invoke("<no result>");
                    dlgResultFilter?.Invoke(null);
                }
            }

            #endregion
        }