public CRUDViewStateSelectCommandManager(IViewStateService stateService)
        {
            _stateService = stateService ?? throw new ArgumentException(nameof(CRUDViewStateSelectCommandManager));

            AddCommand(CRUDStateCommands.CreateStateCommand, new RelayCommand(() => { _stateService.ViewState = CRUDStates.CreateState; }, () => true));
            AddCommand(CRUDStateCommands.ReadStateCommand, new RelayCommand(() => { _stateService.ViewState = CRUDStates.ReadState; }, () => true));
            AddCommand(CRUDStateCommands.UpdateStateCommand, new RelayCommand(() => { _stateService.ViewState = CRUDStates.UpdateState; }, () => true));
            AddCommand(CRUDStateCommands.DeleteStateCommand, new RelayCommand(() => { _stateService.ViewState = CRUDStates.DeleteState; }, () => true));
        }
Пример #2
0
 protected PageViewModelWithState(ICatalog <TViewData> catalog)
     : base(catalog)
 {
     // These will be initialised in sub-classes,
     // with specific services/commands
     _controlStateService = null;
     _viewStateService    = null;
     _dataCommands        = null;
     _stateCommands       = null;
 }
 protected MasterDetailsViewModelWithState(IViewModelFactory <TVMO> viewModelFactory, ICatalog <TVMO> catalog)
     : base(viewModelFactory, catalog)
 {
     // These will be initialised in sub-classes,
     // with specific services/commands
     _controlStateService = null;
     _viewStateService    = null;
     _dataCommands        = null;
     _stateCommands       = null;
 }
Пример #4
0
        public MainViewModel(
            IDialogService dialogService,
            IViewStateService viewStateService,
            IFontColourLookupService fontColourLookupService,
            IFontFamilyLookupService fontFamilyLookupService,
            IFontZoomLookupService fontZoomLookupService,
            IFileModelService fileModelService)
        {
            if (dialogService is null)
            {
                throw new ArgumentNullException(nameof(dialogService));
            }
            if (viewStateService is null)
            {
                throw new ArgumentNullException(nameof(viewStateService));
            }
            if (fontColourLookupService is null)
            {
                throw new ArgumentNullException(nameof(fontColourLookupService));
            }
            if (fontFamilyLookupService is null)
            {
                throw new ArgumentNullException(nameof(fontFamilyLookupService));
            }
            if (fontZoomLookupService is null)
            {
                throw new ArgumentNullException(nameof(fontZoomLookupService));
            }
            if (fileModelService is null)
            {
                throw new ArgumentNullException(nameof(fileModelService));
            }

            _fileModelService = fileModelService;

            _dialogService             = dialogService;
            _dialogService.DialogDone += OnDialogDone;

            const string filter = "Text Documents|*.txt|All files (*.*)|*.*";

            _openFileDialog = _dialogService.GetFileDialog <OpenFileDialog>();
            if (_openFileDialog != null)
            {
                _openFileDialog.Filter = filter;
            }

            _saveFileDialog = _dialogService.GetFileDialog <SaveFileDialog>();
            if (_saveFileDialog != null)
            {
                _saveFileDialog.Filter = filter;
            }

            _viewStateService = viewStateService;
            ViewState         = _viewStateService.Open();

            FontColours = fontColourLookupService.GetIndex();
            ApplySelectedOnFontColour();

            FontFamilyNames = fontFamilyLookupService.GetIndex();
            ApplySelectedOnFontFamily();

            _fontZoomIndex = fontZoomLookupService.GetIndex();
            _defaultZoom   = fontZoomLookupService.GetDefault().Zoom;
            _isFontZoomMin =
                ViewState.SelectedFontZoom.Key == _fontZoomIndex.First().Key;
            _isFontZoomMax =
                ViewState.SelectedFontZoom.Key == _fontZoomIndex.Last().Key;

            _busyRegister = new List <string>();

            SelectedItem = new FileModel();

            NewCmd                = new RelayCommand(OnNew, () => CanExecute);
            OpenCmd               = new RelayCommand(OnOpen, () => CanExecuteOpen);
            SaveCmd               = new RelayCommand(OnSave, () => CanExecute);
            SaveAsCmd             = new RelayCommand(OnSaveAs, () => CanExecute);
            ExitCmd               = new RelayCommand(OnExit, () => CanExecute);
            FindCmd               = new RelayCommand(OnFind, () => CanExecuteFind);
            FindNextCmd           = new RelayCommand(OnFindNext, () => CanExecuteFindNext);
            EscCmd                = new RelayCommand(OnEsc, () => CanExecuteEsc);
            ReplaceCmd            = new RelayCommand(OnReplace, () => CanExecuteReplace);
            GoToCmd               = new RelayCommand(OnGoTo, () => CanExecute);
            TimeDateCmd           = new RelayCommand(OnTimeDate, () => CanExecute);
            WordWrapCmd           = new RelayCommand(OnWordWrap, () => CanExecute);
            ZoomInCmd             = new RelayCommand(OnZoomIn, () => CanExecuteZoomIn);
            ZoomOutCmd            = new RelayCommand(OnZoomOut, () => CanExecuteZoomOut);
            RestoreDefaultZoomCmd = new RelayCommand(
                OnRestoreDefaultZoom, () => CanExecute);
            StatusBarCmd  = new RelayCommand(OnStatusBar, () => CanExecute);
            HelpCmd       = new RelayCommand(OnHelp, () => CanExecute);
            AboutCmd      = new RelayCommand(OnAbout, () => CanExecute);
            FontColourCmd = new RelayCommand <FontColourModel>(
                OnFontColour, (b) => CanExecute);
            FontFamilyCmd = new RelayCommand <FontFamilyModel>(
                OnFontFamily, (b) => CanExecute);
            PrettifyJsonCmd = new RelayCommand(
                OnPrettifyJson, () => CanExecutePrettifyJson);

            _findDialog = _dialogService
                          .GetDialogViewModel <IFindDialogViewModel>();
            if (_findDialog != null)
            {
                _findDialog.FindNextRaisedByDialog +=
                    OnFindNextRaisedByDialog;
                _findDialog.ReplaceCmd       = ReplaceCmd;
                _findDialog.GoToCmd          = GoToCmd;
                _findDialog.PropertyChanged += OnFindDialogPropertyChanged;
            }

            _replaceDialog = _dialogService
                             .GetDialogViewModel <IReplaceDialogViewModel>();
            if (_replaceDialog != null)
            {
                _replaceDialog.FindNextRaisedByDialog   += OnFindNextRaisedByDialog;
                _replaceDialog.ReplaceRaisedByDialog    += OnReplaceRaisedByDialog;
                _replaceDialog.ReplaceAllRaisedByDialog += OnReplaceAllRaisedByDialog;
                _replaceDialog.FindCmd          = FindCmd;
                _replaceDialog.GoToCmd          = GoToCmd;
                _replaceDialog.PropertyChanged += OnFindDialogPropertyChanged;
            }
        }
Пример #5
0
        public void Init()
        {
            _fontZoomLookupService   = new FontZoomLookupService();
            _fontFamilyLookupService = new FontFamilyLookupService();
            _fontColourLookupService = new FontColourLookupService();

            var exampleViewStateModel = new ViewStateModel(
                _fontColourLookupService.GetDefault(),
                _fontFamilyLookupService.GetDefault(),
                _fontZoomLookupService.GetDefault());

            var mockViewStateService = new Mock <IViewStateService>();

            mockViewStateService.Setup(s => s.Open())
            .Returns(exampleViewStateModel);
            _viewStateService = mockViewStateService.Object;


            MockDialogService = new Mock <IDialogService>();
            MockDialogService.Setup(
                s => s.GetFileDialog <OpenFileDialog>())
            .Returns(It.IsAny <OpenFileDialog>());
            MockDialogService.Setup(
                s => s.GetFileDialog <SaveFileDialog>())
            .Returns(It.IsAny <SaveFileDialog>());


            var mockGoToVm = new Mock <IGoToDialogViewModel>();

            mockGoToVm.SetupGet(vm => vm.LineNumber)
            .Returns(DefaultLineToGoTo);

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IGoToDialogViewModel>())
            .Returns(mockGoToVm.Object);

            var findVm = new FindDialogViewModel();

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IFindDialogViewModel>())
            .Returns(findVm);


            var replaceVm = new ReplaceDialogViewModel();

            MockDialogService.Setup(
                s => s.GetDialogViewModel <IReplaceDialogViewModel>())
            .Returns(replaceVm);

            MockDialogService.Setup(
                s => s.ShowDialog(mockGoToVm.Object)).Returns(true);

            _dialogService = MockDialogService.Object;

            var mockFileModelService = new Mock <IFileModelService>();

            // TODO mock Load and Save
            _fileModelService = mockFileModelService.Object;

            MainVm = new MainViewModel(
                _dialogService,
                _viewStateService,
                _fontColourLookupService,
                _fontFamilyLookupService,
                _fontZoomLookupService,
                _fileModelService);

            MainVm.SelectedItem.Content = DefaultContent;

            MainVm.GoToRequested += OnGoToRequested;
        }