Ejemplo n.º 1
0
 public void SetUp()
 {
     _findVm = MockDialogService.Object
               .GetDialogViewModel <IFindDialogViewModel>();
 }
Ejemplo n.º 2
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;
            }
        }