Ejemplo n.º 1
0
        public static void ShowSoftDialog(DialogWindowViewModel vm)
        {
            Window window = new DialogWindow(vm);

            window.MousePosition();
            window.ShowSoftDialog();
        }
Ejemplo n.º 2
0
        public DialogWindow(string title, string message)
        {
            InitializeComponent();

            DialogWindowViewModel = new DialogWindowViewModel(title, message);
            DataContext           = DialogWindowViewModel;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="logger"></param>
        /// <param name="meal">食事モデル</param>
        public MealViewModel(ISettings settings, ILogger logger, MealModel meal)
        {
            this._settings = settings;
            this._logger   = logger;
            this.Meal      = meal.AddTo(this.CompositeDisposable);

            // Property
            // 食事ID
            this.MealId = this.Meal.MealId.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            // レシピリスト
            this.RecipeList = this.Meal.Recipes.ToReadOnlyReactiveCollection(recipe => Creator.CreateRecipeViewModelInstance(settings, logger, recipe)).AddTo(this.CompositeDisposable);
            // 食事タイプ
            this.MealType = this.Meal.MealType.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            // 食事タイプリスト
            this.MealTypes = this.Meal.MealTypes.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // Command
            // レシピ追加コマンド
            this.AddRecipeCommand.Subscribe(() => {
                using (var vm = new AddRecipeViewModel(this._settings, this._logger, Method.HistorySearch | Method.Download | Method.Original)) {
                    this.Messenger.Raise(new TransitionMessage(vm, "OpenSearchRecipeWindow"));
                    if (vm.IsSelectionCompleted.Value)
                    {
                        this.Meal.AddRecipe(vm.SelectionResult.Value.Recipe);
                    }
                }
            }).AddTo(this.CompositeDisposable);
            // レシピ削除コマンド
            this.RemoveRecipeCommand.Subscribe(rvm => {
                using (var vm = new DialogWindowViewModel(
                           "削除確認",
                           "食事からレシピを削除します。よろしいですか。",
                           DialogWindowViewModel.DialogResult.Yes,
                           DialogWindowViewModel.DialogResult.No
                           )) {
                    this.Messenger.Raise(new TransitionMessage(vm, TransitionMode.Modal, "OpenDialogWindow"));
                    if (vm.Result == DialogWindowViewModel.DialogResult.Yes)
                    {
                        this.Meal.RemoveRecipe(rvm.Recipe);
                    }
                }
            }).AddTo(this.CompositeDisposable);

            // 食事削除コマンド
            this.RemoveMealCommand.Subscribe(() => {
                using (var vm = new DialogWindowViewModel(
                           "削除確認",
                           "食事を削除します。よろしいですか。",
                           DialogWindowViewModel.DialogResult.Yes,
                           DialogWindowViewModel.DialogResult.No
                           )) {
                    this.Messenger.Raise(new TransitionMessage(vm, TransitionMode.Modal, "OpenDialogWindow"));
                    if (vm.Result == DialogWindowViewModel.DialogResult.Yes)
                    {
                        this.Meal.RemoveMeal();
                    }
                }
            }).AddTo(this.CompositeDisposable);
        }
Ejemplo n.º 4
0
        public bool ShowDialogWindow(string content, string title)
        {
            var dialog = new DialogWindowViewModel
            {
                Content = content,
                Title   = title
            };
            var window = new MessageDialog {
                DataContext = dialog
            };

            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.ShowDialog();
            return(dialog.DialogResult);
        }
Ejemplo n.º 5
0
        private DialogWindow(DialogWindowViewModel vm)
        {
            this.DataContext = vm;
            InitializeComponent();
            if (!string.IsNullOrEmpty(vm.Icon) && Application.Current.Resources.Contains(vm.Icon))
            {
                this.Resources["Icon"] = Application.Current.Resources[vm.Icon];
            }

            var owner = WpfUtil.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
        }
Ejemplo n.º 6
0
 public bool ShowDialogWindow(string content, string title)
 {
     return(App.Current.Dispatcher.Invoke <bool>(() =>
     {
         var dialog = new DialogWindowViewModel
         {
             Content = content,
             Title = title
         };
         var window = new MessageDialog {
             DataContext = dialog
         };
         window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
         window.ShowDialog();
         return dialog.DialogResult;
     }));
 }
Ejemplo n.º 7
0
        private DialogWindow CreateParameterDialog()
        {
            var window     = new DialogWindow();
            var _viewModel = new DialogWindowViewModel
            {
                Message =
                    "Pierwsza wartość to procentowa ilość sesji do przepracowania przed oceną, a druga to wartość delta różnicy między wynikiem dla DTMC R i H najlepiej w przedziale między 0.5 a 2 im mniejsza wartość tym bardziej wątpliwa ocena",
                KValue        = "75",
                DeltaValue    = "0.5",
                ButtonContent = "Zatwierdź"
            };

            window.viewmodel   = _viewModel;
            window.DataContext = _viewModel;

            return(window);
        }
Ejemplo n.º 8
0
        private DialogWindow(DialogWindowViewModel vm)
        {
            this.DataContext = vm;
            this.Title       = vm.Title;
            InitializeComponent();
            this.TbUcName.Text = nameof(DialogWindow);
            if (!string.IsNullOrEmpty(vm.Icon))
            {
                object obj = AppUtil.GetResource(vm.Icon);
                if (obj != null)
                {
                    this.Resources["Icon"] = obj;
                }
            }

            var owner = WpfUtil.GetTopWindow();

            if (this != owner)
            {
                this.Owner = owner;
            }
        }
Ejemplo n.º 9
0
        private void PrintWndVM_PrintFinished(object sender, Events.PrintedEventArgs e)
        {
            DialogPopupWindow     notifyWnd   = new DialogPopupWindow();
            DialogWindowViewModel notifyWndVM = null;

            if (e.PrintResult == true)
            {
                notifyWndVM = new DialogWindowViewModel()
                {
                    DialogType  = DialogWindowType.Info,
                    MessageText = "In thành công",
                    OKText      = "OK"
                };
            }
            else
            {
                notifyWndVM = new DialogWindowViewModel()
                {
                    DialogType  = DialogWindowType.Info,
                    MessageText = "Hủy bỏ in",
                    OKText      = "OK"
                };
            }
            notifyWnd.DataContext      = notifyWndVM;
            notifyWndVM.ButtonPressed += ButtonPressedHandler;

            notifyWnd.ShowDialog();
            this.DialogResult = e.PrintResult;
            this.Close();

            void ButtonPressedHandler(object s, DialogButtonPressedEventArgs ev)
            {
                notifyWnd.DialogResult = true;
                notifyWnd.Close();
            }
        }
Ejemplo n.º 10
0
 // 起编译时免导入DialogWindow所在的NTMiner.Views命名空间的作用
 public static void ShowDialog(this ViewModelBase vm, DialogWindowViewModel config)
 {
     DialogWindow.ShowDialog(config);
 }
Ejemplo n.º 11
0
        public SearchRecipeViewModel(ISettings settings, ILogger logger)
        {
            this._searchRecipe = new SearchRecipe(settings, logger).AddTo(this.CompositeDisposable);

            // Property

            // 現在ページ
            this.CurrentPage = this._searchRecipe.CurrentPage.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);

            // 最大ページ数
            this.MaxPage = this._searchRecipe.MaxPage.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);

            // 複数ページフラグ
            this.IsMultiPage = this.MaxPage.Select(x => x >= 2).ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);

            // ページリスト
            this.PageList =
                this.MaxPage
                .CombineLatest(this.CurrentPage, (max, current) => (max, current))
                .Select(x =>
                        Enumerable
                        .Range(x.current - 4, 10)
                        .Where(i => i >= 1 && i <= x.max)
                        .ToArray()
                        )
                .ToReadOnlyReactivePropertySlim()
                .AddTo(this.CompositeDisposable);

            // 検索ワード
            this.SearchWord = this._searchRecipe.SearchWord.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 検索対象フラグ:タイトル
            this.IsTitleSearchTarget = this._searchRecipe.IsTitleSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 検索対象フラグ:材料
            this.IsIngredientSearchTarget = this._searchRecipe.IsIngredientSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 検索対象フラグ:手順
            this.IsStepSearchTarget = this._searchRecipe.IsStepSearchTarget.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            // 最終利用日
            this.LastUsedDate = this._searchRecipe.LastUsedDate.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 最終利用日以前フラグ
            this.IsBeforeLastUsedDate = this._searchRecipe.IsBeforeLastUsedDate.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 利用回数
            this.UsageCount = this._searchRecipe.UsageCount.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 利用回数以上フラグ
            this.IsUsageCountMoreThan = this._searchRecipe.IsUsageCountMoreThan.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // アーカイブを含むかどうかのフラグ
            this.IncludingArchive = this._searchRecipe.IncludingArchive.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // 検索結果
            this.SearchResult =
                this._searchRecipe
                .Result
                .Select(x =>
                        x.Select(r =>
                                 Creator.CreateRecipeViewModelInstance(settings, logger, r)
                                 ).ToArray()
                        ).ToReadOnlyReactiveProperty()
                .AddTo(this.CompositeDisposable);

            // タグ候補
            this.TagList = this._searchRecipe.TagList.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // 評価
            this.Ratings = this._searchRecipe.Ratings.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // 追加したソート条件
            this.SortConditions = this._searchRecipe.SortConditions.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // 検索条件リスト
            this.SortItems = this._searchRecipe.SortItems.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // 検索条件プラグインリスト
            this.SearchConditionPlugins = this._searchRecipe.SearchConditionPlugins.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            // 追加されたプラグイン検索条件
            this.PluginSearchConditions = this._searchRecipe.PluginSearchConditions.ToReadOnlyReactiveCollection(x => {
                var(view, viewModel) = Creator.CreateRecipeSearchConditionViewAndViewModel(x);
                return(new ViewViewModelPair <UserControl, IRecipeSearchConditionViewModel>(view, viewModel));
            }).AddTo(this.CompositeDisposable);

            // ロード中フラグ
            this.IsBusy = this._searchRecipe.IsBusy.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);

            // Command
            // 検索
            this.SearchCommand.Subscribe(_ => this._searchRecipe.Search()).AddTo(this.CompositeDisposable);

            // ソート条件追加
            this.AddSortConditionCommand.Subscribe(() => this._searchRecipe.AddSortCondition()).AddTo(this.CompositeDisposable);

            // ソート条件削除
            this.RemoveSortConditionCommand.Subscribe(s => this._searchRecipe.RemoveSortCondition(s)).AddTo(this.CompositeDisposable);

            // プラグイン検索条件追加
            this.AddPluginSearchConditionCommand.Where(p => p != null).Subscribe(p =>
                                                                                 this._searchRecipe
                                                                                 .AddPluginSearchCondition(p)
                                                                                 ).AddTo(this.CompositeDisposable);

            // プラグイン検索条件削除
            this.RemovePluginSearchConditionCommand.Subscribe(c => this._searchRecipe.RemovePluginSearchCondition(c.RecipeSearchCondition)).AddTo(this.CompositeDisposable);

            // 前ページへ戻る
            this.PreviousCommand = this.CurrentPage.Select(c => c > 1).ToReactiveCommand().AddTo(this.CompositeDisposable);
            this.PreviousCommand.Subscribe(() => {
                this._searchRecipe.GoToPreviousPage();
            }).AddTo(this.CompositeDisposable);

            // 次ページへ進む
            this.NextCommand = this.CurrentPage.CombineLatest(this.MaxPage, (c, m) => c < m).ToReactiveCommand().AddTo(this.CompositeDisposable);
            this.NextCommand.Subscribe(() => {
                this._searchRecipe.GoToNextPage();
            }).AddTo(this.CompositeDisposable);

            // ページ遷移
            this.TransitionCommand.Subscribe(page => {
                this._searchRecipe.PageTransition(page);
            }).AddTo(this.CompositeDisposable);

            // レシピエディタ起動
            this.EditRecipeCommand.Subscribe(rvm => {
                var vm = new RecipeDetailViewModel(settings, logger);
                vm.RecipeViewModel.Value = rvm;
                vm.RecipeView.Value      = Creator.CreateRecipeEditorViewInstance(settings, logger, rvm);
                this.Messenger.Raise(new TransitionMessage(vm, "OpenEditRecipeWindow"));
            }).AddTo(this.CompositeDisposable);

            // レシピ削除
            this.DeleteRecipeCommand.Subscribe(rvm => {
                var vm = new DialogWindowViewModel("削除確認",
                                                   "レシピを削除します。よろしいですか。",
                                                   DialogWindowViewModel.DialogResult.Yes,
                                                   DialogWindowViewModel.DialogResult.No
                                                   );
                using (vm) {
                    this.Messenger.Raise(new TransitionMessage(vm, TransitionMode.Modal, "OpenDialogWindow"));
                    if (vm.Result != DialogWindowViewModel.DialogResult.Yes)
                    {
                        return;
                    }

                    rvm.DeleteRecipeCommand.Execute(this.Messenger);
                    // 結果を再読込
                    this.SearchCommand.Execute();
                }
            }).AddTo(this.CompositeDisposable);
        }
Ejemplo n.º 12
0
 public DialogWindows(string message = null)
 {
     InitializeComponent();
     _viewModel       = new DialogWindowViewModel(message);
     this.DataContext = _viewModel;
 }
Ejemplo n.º 13
0
        ///  <summary>
        ///  コンストラクタ
        ///  </summary>
        ///  <example>
        ///     <code>
        ///     public ConcreteViewModel() : base(new ConcreteRecipe()) {
        ///     }
        ///     </code>
        ///  </example>
        /// <param name="settings"></param>
        /// <param name="logger"></param>
        /// <param name="recipe">具象クラスで生成したレシピモデルインスタンス</param>
        protected RecipeViewModelBase(IBaseSettings settings, ILogger logger, IRecipe recipe)
        {
            this._settings = settings;
            this._logger   = logger;
            this.Recipe    = recipe.AddTo(this.CompositeDisposable);

            // Property
            this.IngredientDisplayMode = this._settings.States.IngredientDisplayMode.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);
            this.Id            = this.Recipe.Id.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Url           = this.Recipe.Url.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Title         = this.Recipe.Title.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Photo         = this.Recipe.Photo.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.PhotoFilePath =
                this.Recipe
                .PhotoFilePath
                .Where(x => x != null)
                .Select(x => Path.Combine(this._settings.GeneralSettings.ImageDirectoryPath, x))
                .ToReadOnlyReactiveProperty()
                .AddTo(this.CompositeDisposable);
            this.Thumbnail         = this.Recipe.Thumbnail.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.ThumbnailFilePath =
                this.Recipe
                .ThumbnailFilePath
                .Where(x => x != null)
                .Select(x => Path.Combine(this._settings.GeneralSettings.ImageDirectoryPath, x))
                .ToReadOnlyReactiveProperty()
                .AddTo(this.CompositeDisposable);
            this.Description       = this.Recipe.Description.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Yield             = this.Recipe.Yield.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.AdjustmentedYield = this.Recipe.AdjustedYeild.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);
            this.Ingredients       = this.Recipe.Ingredients.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);
            this.ShoppingList      = this.Recipe.ShoppingList.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);
            this.ShoppingInformationIncludedIngredients = this.Recipe.ShoppingInformationIncludedIngredients.ToReadOnlyReactiveProperty().AddTo(this.CompositeDisposable);
            this.Steps            = this.Recipe.Steps.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);
            this.Adjustment       = this.Recipe.Adjustment.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Memo             = this.Recipe.Memo.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.RequiredTime     = this.Recipe.RequiredTime.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.RegistrationDate = this.Recipe.RegistrationDate.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Tags             = this.Recipe.Tags.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);
            this.Ratings          = this.Recipe.Ratings.ToReadOnlyReactiveCollection().AddTo(this.CompositeDisposable);

            this.IsArchived = this.Recipe.IsArchived.ToReactivePropertyAsSynchronized(x => x.Value).AddTo(this.CompositeDisposable);

            // Command
            // レシピダウンロード
            this.DownloadCommand.Subscribe(async messenger => {
                var disposable =
                    this.Recipe.FailedNotification
                    .Where(x => x.Behavior == Behavior.Download)
                    .Subscribe(x => {
                    this._logger.Log(LogLevel.Warning, $"レシピダウンロード失敗 レシピURL={x.Sender.Url.Value}", x.Exception);
                    using (var vm = new DialogWindowViewModel("失敗通知", "レシピのダウンロードに失敗しました。", DialogWindowViewModel.DialogResult.Ok)) {
                        (messenger ?? this.Messenger).Raise(new TransitionMessage(vm, "OpenDialogWindow"));
                    }
                });
                using (disposable) {
                    await this.Recipe.DownloadRecipeAsync();
                }
            }).AddTo(this.CompositeDisposable);

            // レシピ登録
            this.RegisterRecipeCommand.Subscribe(async messenger => {
                var disposable =
                    this.Recipe.FailedNotification
                    .Where(x => x.Behavior == Behavior.Register)
                    .Subscribe(x => {
                    this._logger.Log(LogLevel.Warning, $"レシピ登録失敗 レシピID={x.Sender.Id.Value}", x.Exception);
                    using (var vm = new DialogWindowViewModel("失敗通知", "レシピの登録に失敗しました。", DialogWindowViewModel.DialogResult.Ok)) {
                        (messenger ?? this.Messenger).Raise(new TransitionMessage(vm, "OpenDialogWindow"));
                    }
                });
                using (disposable) {
                    await this.Recipe.RegistAsync();
                }
            }).AddTo(this.CompositeDisposable);

            // レシピ削除
            this.DeleteRecipeCommand.Subscribe(async messenger => {
                var disposable =
                    this.Recipe.FailedNotification
                    .Where(x => x.Behavior == Behavior.Delete)
                    .Subscribe(x => {
                    this._logger.Log(LogLevel.Warning, $"レシピ削除失敗 レシピID={x.Sender.Id.Value}", x.Exception);
                    using (var vm = new NotifyWindowViewModel("このレシピを使用している食事があるため、レシピの削除に失敗しました。", 5)) {
                        (messenger ?? this.Messenger).Raise(new TransitionMessage(vm, "OpenNotifyWindow"));
                    }
                });
                using (disposable) {
                    await this.Recipe.DeleteAsync();
                }
            }).AddTo(this.CompositeDisposable);

            // レシピビュワーで表示
            this.OpenRecipeDetailCommand.Subscribe(() => {
                settings.States.RecipesInRecipeViewer.Add(new RecipeInformation(this.Recipe.Id.Value, this.Adjustment.Value));
            }).AddTo(this.CompositeDisposable);

            // レシピ読み込み
            this.LoadRecipeCommand = this.Id.Select(x => x != 0).ToReactiveCommand().AddTo(this.CompositeDisposable);
            this.LoadRecipeCommand.ObserveOnUIDispatcher().Subscribe(_ => this.Recipe.Load()).AddTo(this.CompositeDisposable);

            // レシピ材料追加
            this.InsertIngredientCommand.Subscribe(index => {
                this.Recipe.InsertIngredient(index);
            }).AddTo(this.CompositeDisposable);

            // レシピ手順追加
            this.InsertStepCommand.Subscribe(index => {
                this.Recipe.InsertStep(index);
            }).AddTo(this.CompositeDisposable);

            // レシピ材料削除
            this.RemoveIngredientCommand.Subscribe(index => {
                this.Recipe.RemoveIngredientAt(index);
            }).AddTo(this.CompositeDisposable);

            // レシピ手順削除
            this.RemoveStepCommand.Subscribe(index => {
                this.Recipe.RemoveStepAt(index);
            }).AddTo(this.CompositeDisposable);

            // アーカイブ
            this.ArchiveCommand = this.IsArchived.Select(x => !x).ToReactiveCommand().AddTo(this.CompositeDisposable);
            this.ArchiveCommand.Subscribe(this.Recipe.Archive).AddTo(this.CompositeDisposable);

            // アーカイブ解除
            this.UnarchiveCommand = this.IsArchived.ToReactiveCommand().AddTo(this.CompositeDisposable);
            this.UnarchiveCommand.Subscribe(this.Recipe.Unarchive).AddTo(this.CompositeDisposable);


            // エラー時対処
            this.Recipe.FailedNotification.Where(x => x.Behavior == Behavior.Load).Subscribe(x => {
                // 抽象化の諦め
                // 他クライアントからの変更通知で例外が発生した場合、メッセージを表示するための画面を特定できず、LivetのMessengerを渡すのが困難なため。
                this._logger.Log(LogLevel.Warning, $"レシピ読み込み失敗 レシピID={x.Sender.Id.Value}", x.Exception);
                using (var vm = new DialogWindowViewModel("失敗通知", "レシピの読み込みに失敗しました。", DialogWindowViewModel.DialogResult.Ok)) {
                    var dialog = new DialogWindow()
                    {
                        DataContext = vm
                    };
                    DispatcherHelper.UIDispatcher.Invoke(() => {
                        dialog.ShowDialog();
                    });
                }
            }).AddTo(this.CompositeDisposable);
        }