Exemple #1
0
        public StartupViewModel(IShell shell, IAppModel appModel)
        {
            this.shell    = shell as IDistinctShell;
            this.appModel = appModel;

            this.appModel.LoadConfig();

            var recent = this.appModel.GetRecentDocuments();

            BaseList = new ReactiveList <string>(recent.Take(3));

            AccentChangeCommand =
                ReactiveCommand.Create <string>(color =>
                                                ThemeManager.ChangeAppStyle(Application.Current,
                                                                            ThemeManager.GetAccent(color),
                                                                            ThemeManager.GetAppTheme("baselight")));

            OpenRecentDbCommand = ReactiveCommand.Create <string>(uri =>
            {
                if (OpenBoardView(uri))
                {
                    return;
                }

                RemoveRecent(uri);
                DialogCoordinator.Instance.ShowMessageAsync(this, "Ошибка",
                                                            "Файл был удалён или перемещён из данной папки");
            });

            RemoveRecentCommand = ReactiveCommand.Create <string>(RemoveRecent);

            NewFileCommand = ReactiveCommand.Create(() =>
                                                    this.shell.ShowDistinctView <WizardView>("Creating new file", new WizardViewRequest {
                InExistedFile = false
            }));

            NewBoardCommand = ReactiveCommand.Create(() =>
            {
                var dialog = new OpenFileDialog
                {
                    Filter = @"SQLite DataBase | *.db",
                    Title  = @"Выбор существующего файла базы данных"
                };

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var uri = dialog.FileName;

                    AddRecent(uri);
                    this.shell.ShowDistinctView <WizardView>($"Creating new board in {uri}", new WizardViewRequest
                    {
                        InExistedFile = true,
                        Uri           = uri
                    });
                }
            });

            OpenFileCommand = ReactiveCommand.Create(() =>
            {
                var dialog = new OpenFileDialog
                {
                    Filter = @"SQLite DataBase | *.db",
                    Title  = @"Выбор существующего файла базы данных"
                };

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var uri = dialog.FileName;
                    OpenBoardView(uri);
                    AddRecent(uri);
                }
            });
        } //ctor
        public WizardViewModel(IAppModel appModel, IShell shell)
        {
            this.appModel = appModel;
            this.shell    = shell as IDistinctShell;
            validator     = new WizardValidator();
            Title         = "Creating new file";
            FullTitle     = "Creating new file";
            BoardsInFile  = new ReactiveList <string>();

            this.WhenAnyValue(x => x.BoardName)
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(v =>
            {
                if (!InExistedFile)
                {
                    FileName = BoardNameToFileName(v);
                }
            });

            BoardName = "My Board";

            FolderName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            SelectFolderCommand = ReactiveCommand.Create(SelectFolder);

            ColumnList = new ReactiveList <LocalDimension>
            {
                new LocalDimension("Backlog"),
                new LocalDimension("In progress"),
                new LocalDimension("Done")
            };

            AddColumnCommand =
                ReactiveCommand.Create(() => ColumnList.Add(new LocalDimension("New column")));

            DeleteColumnCommand = ReactiveCommand
                                  .Create <LocalDimension>(column =>
            {
                ColumnList.Remove(column);
                UpdateDimensionList(ColumnList);
            });


            RowList = new ReactiveList <LocalDimension>()
            {
                new LocalDimension("Important"),
                new LocalDimension("So-so"),
                new LocalDimension("Trash")
            };

            AddRowCommand =
                ReactiveCommand.Create(() => RowList.Add(new LocalDimension("New row")));

            DeleteRowCommand = ReactiveCommand
                               .Create <LocalDimension>(row =>
            {
                RowList.Remove(row);
                UpdateDimensionList(RowList);
            });

            CreateCommand = ReactiveCommand.CreateFromTask(Create);

            CancelCommand = ReactiveCommand.Create(Close);

            this.WhenAnyObservable(s => s.ColumnList.ItemChanged)
            .Subscribe(_ =>
                       UpdateDimensionList(ColumnList));

            this.WhenAnyObservable(s => s.RowList.ItemChanged)
            .Subscribe(_ =>
                       UpdateDimensionList(RowList));

            this.WhenAnyObservable(s => s.ColumnList.ItemsAdded)
            .Subscribe(_ => UpdateDimensionList(ColumnList));

            this.WhenAnyObservable(s => s.RowList.ItemsAdded)
            .Subscribe(_ => UpdateDimensionList(RowList));

            this.WhenAnyObservable(s => s.AllErrors.Changed)
            .Subscribe(_ => CanCreate = !AllErrors.Any() &&
                                        ColumnList.Count(col => col.HasErrors) == 0 &&
                                        RowList.Count(row => row.HasErrors) == 0);
        }