public SettingsViewModel()
        {
            m_okCommand = new RelayCommand(Ok, CanOk);
            m_cancelCommand = new RelayCommand(Cancel);
            m_clearDatasheetsCacheCommand = new RelayCommand(ClearDatasheetsCache);
            m_clearImagesCacheCommand = new RelayCommand(ClearImagesCache);
            m_clearSavedDatasheetsCommand = new RelayCommand(ClearSavedDatasheets);
            m_checkUpdatesCommand = new RelayCommand(CheckUpdates);
            m_selectAppDataPathCommand = new RelayCommand(SelectAppDataPath);

            m_validators = new ValidatorCollection(() => m_okCommand.RaiseCanExecuteChanged());

            m_maxCacheSize = new IntegerValidator(0, 100000);
            m_maxCacheSize.ValidValue = (int)(Global.Configuration.MaxDatasheetsCacheSize / (1024 * 1024));
            m_validators.Add(m_maxCacheSize);

            LanguagePair pair = new LanguagePair(string.Empty);
            m_availableLanguages.Add(pair);
            m_selectedLanguage = pair;
            pair = new LanguagePair("en-US");
            if (Global.Configuration.Language == pair.Name) m_selectedLanguage = pair;
            m_availableLanguages.Add(pair);
            foreach (var langPath in Directory.EnumerateFiles(Global.LanguagesDirectory))
            {
                string[] tokens = Path.GetFileName(langPath).Split('.');
                if (tokens.Length < 2) continue;
                pair = new LanguagePair(tokens[1]);
                m_availableLanguages.Add(pair);
                if (pair.Name == Global.Configuration.Language) m_selectedLanguage = pair;
            }

            m_initialPath = AppDataPath = Global.AppDataPath;
            m_favouritesOnStart = Global.Configuration.FavouritesOnStart;
        }
Example #2
0
        public void RaisingCanExecuteChangedRaisesCanExecuteChanged()
        {
            var command = new RelayCommand(o => { });
            command.MonitorEvents();

            command.RaiseCanExecuteChanged();

            command.ShouldRaise("CanExecuteChanged");
        }
        public ComponentTitleViewModel(string title, IWindowService windowService)
        {
            if (windowService == null) throw new ArgumentNullException(nameof(windowService));

            _title = title;
            _oldTitle = title;

            _windowService = windowService;

            ConfirmCommand = new RelayCommand(ExecuteConfirmCommand, CanCloseDialog);
            CancelCommand = new RelayCommand(ExecuteCancelCommand);

            this.ForProperty(nameof(Title))
                .Subscribe(() => { ConfirmCommand.RaiseCanExecuteChanged(); });
        }
        private EditPartViewModel()
        {
            m_okCommand = new RelayCommand(Ok);
            m_cancelCommand = new RelayCommand(Cancel);
            m_refreshCommand = new RelayCommand(Refresh, CanRefresh);
            m_rebuildTagsCommand = new RelayCommand(RebuildTags);
            m_selectImageCommand = new RelayCommand(SelectImage);

            m_validators = new ValidatorCollection(() => m_okCommand.RaiseCanExecuteChanged());

            m_name = new NoWhitespaceValidator();
            m_validators.Add(m_name);

            m_tags = new SeparatedValuesValidator(',');
            m_validators.Add(m_tags);
        }
Example #5
0
        public void Given_CanExecuteDelegate_When_RaiseCanExecuteCalled_EventFires()
        {
            var eventFired = false;
            var handler = new EventHandler((o, e) =>
            {
                eventFired = true;
            });

            var sut = new RelayCommand<object>(Delegate1, CanChange);
            sut.CanExecuteChanged += handler;

            sut.RaiseCanExecuteChanged();

            Assert.IsTrue(eventFired);

            sut.CanExecuteChanged -= handler;
        }
        public void AccessorShouldToggleEnabledFalse()
        {
            bool canExecute = false;
            bool isInvoked = false;
            var parameter = new object();
            var command = new RelayCommand(o => { }, o =>
            {
                o.ShouldEqual(parameter);
                isInvoked = true;
                return canExecute;
            }, this);
            bool isEnabled = true;
            IAttachedBindingMemberInfo<object, bool> member =
                AttachedBindingMember.CreateMember<object, bool>(AttachedMemberConstants.Enabled,
                    (info, o) => isEnabled,
                    (info, o, v) => isEnabled = v);
            var memberProvider = new BindingMemberProvider();
            memberProvider.Register(typeof(object), member, false);
            BindingServiceProvider.MemberProvider = memberProvider;

            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var accessor = GetAccessor(source, BindingSourceModel.EventName, new DataContext(BindingBuilderConstants.ToggleEnabledState.ToValue(false)), false, d => parameter);
            srcAccessor.GetValue = (info, context, arg3) => command;

            isEnabled.ShouldBeTrue();
            accessor.SetValue(srcAccessor, EmptyContext, true);
            isInvoked.ShouldBeFalse();
            isEnabled.ShouldBeTrue();

            isInvoked = false;
            canExecute = true;
            command.RaiseCanExecuteChanged();
            isInvoked.ShouldBeFalse();
            isEnabled.ShouldBeTrue();
        }
        public void AccessorShouldUseCommandParameterCanExecuteOneTimeModeAfterDispose()
        {
            bool isInvoked = false;
            var parameter = new object();
            var command = new RelayCommand(o => { }, o =>
            {
                o.ShouldEqual(parameter);
                isInvoked = true;
                return false;
            }, this);
            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var ctx = new DataContext(BindingBuilderConstants.Behaviors.ToValue(new List<IBindingBehavior> { new OneTimeBindingMode() }));
            var accessor = GetAccessor(source, BindingSourceModel.EventName, ctx, false, d => parameter);
            srcAccessor.GetValue = (info, context, arg3) => command;

            accessor.SetValue(srcAccessor, EmptyContext, true);
            accessor.Dispose();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            isInvoked.ShouldBeTrue();

            isInvoked = false;
            command.RaiseCanExecuteChanged();
            isInvoked.ShouldBeTrue();
            source.ToString();//TO KEEP ALIVE
        }
        public void SetValueShouldUpdateIsEnabledPropertyOneTimeModeAfterDispose()
        {
            bool canExecute = false;
            var command = new RelayCommand(o => { }, o => canExecute, this);

            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var ctx = new DataContext(BindingBuilderConstants.Behaviors.ToValue(new List<IBindingBehavior> { new OneTimeBindingMode() }));
            var accessor = GetAccessor(source, BindingSourceModel.EventName, ctx, false);
            srcAccessor.GetValue = (info, context, arg3) => command;
            accessor.SetValue(srcAccessor, EmptyContext, true);
            accessor.Dispose();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            source.IsEnabled.ShouldBeFalse();
            canExecute = true;
            command.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldBeTrue();
        }
        public void AccessorShouldUseOnlyOneCmd()
        {
            bool isEnabled = false;
            var oldCmd = new RelayCommand(o => { }, o => false, this);
            var command = new RelayCommand(o => { }, o => isEnabled, this);
            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false);
            srcAccessor.GetValue = (info, context, arg3) => oldCmd;

            accessor.SetValue(srcAccessor, EmptyContext, true);
            source.IsEnabled.ShouldBeFalse();
            oldCmd.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldBeFalse();

            srcAccessor.GetValue = (info, context, arg3) => command;
            accessor.SetValue(srcAccessor, EmptyContext, true);
            isEnabled = true;
            command.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldEqual(isEnabled);

            oldCmd.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldEqual(isEnabled);

            srcAccessor.GetValue = (info, context, arg3) => null;
            accessor.SetValue(srcAccessor, EmptyContext, true);
            isEnabled = false;
            command.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldBeTrue();
        }
        public void AccessorShouldUseCommandParameterCanExecute()
        {
            bool isInvoked = false;
            var parameter = new object();
            var command = new RelayCommand(o => { }, o =>
            {
                o.ShouldEqual(parameter);
                isInvoked = true;
                return false;
            }, this);
            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false, d => parameter);
            srcAccessor.GetValue = (info, context, arg3) => command;

            accessor.SetValue(srcAccessor, EmptyContext, true);
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            command.RaiseCanExecuteChanged();
            isInvoked.ShouldBeTrue();
        }
        public void SetValueShouldUpdateIsEnabledProperty()
        {
            bool canExecute = false;
            var command = new RelayCommand(o => { }, o => canExecute, this);

            var srcAccessor = new BindingSourceAccessorMock();
            var source = new BindingSourceModel();
            var accessor = GetAccessor(source, BindingSourceModel.EventName, EmptyContext, false);
            srcAccessor.GetValue = (info, context, arg3) => command;

            accessor.SetValue(srcAccessor, EmptyContext, true);
            source.IsEnabled.ShouldBeFalse();
            canExecute = true;
            command.RaiseCanExecuteChanged();
            source.IsEnabled.ShouldBeTrue();
        }
        public MainWindowViewModel(IItemFilterScriptRepository itemFilterScriptRepository,
                                   IItemFilterScriptTranslator itemFilterScriptTranslator,
                                   IReplaceColorsViewModel replaceColorsViewModel,
                                   IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel,
                                   ISettingsPageViewModel settingsPageViewModel,
                                   IThemeProvider themeProvider,
                                   IThemeService themeService,
                                   IMessageBoxService messageBoxService,
                                   IClipboardService clipboardService)
        {
            _itemFilterScriptRepository = itemFilterScriptRepository;
            _itemFilterScriptTranslator = itemFilterScriptTranslator;
            _replaceColorsViewModel = replaceColorsViewModel;
            _avalonDockWorkspaceViewModel = avalonDockWorkspaceViewModel;
            SettingsPageViewModel = settingsPageViewModel;
            _themeProvider = themeProvider;
            _themeService = themeService;
            _messageBoxService = messageBoxService;
            _clipboardService = clipboardService;

            NewScriptCommand = new RelayCommand(OnNewScriptCommand);
            CopyScriptCommand = new RelayCommand(OnCopyScriptCommand, () => ActiveDocumentIsScript);
            OpenScriptCommand = new RelayCommand(async () => await OnOpenScriptCommand());
            OpenThemeCommand = new RelayCommand(async () => await OnOpenThemeCommandAsync());

            SaveCommand = new RelayCommand(async () => await OnSaveDocumentCommandAsync(), ActiveDocumentIsEditable);
            SaveAsCommand = new RelayCommand(async () => await OnSaveAsCommandAsync(), ActiveDocumentIsEditable);
            CloseCommand = new RelayCommand(OnCloseDocumentCommand, ActiveDocumentIsEditable);

            CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            PasteCommand = new RelayCommand(OnPasteCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            PasteBlockStyleCommand = new RelayCommand(OnPasteBlockStyleCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);

            MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);

            AddBlockCommand = new RelayCommand(OnAddBlockCommand, () => ActiveDocumentIsScript);
            AddSectionCommand = new RelayCommand(OnAddSectionCommand, () => ActiveDocumentIsScript);
            DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
            DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
            EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
            OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
            ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript);

            CreateThemeCommand = new RelayCommand(OnCreateThemeCommand, () => ActiveDocumentIsScript);
            ApplyThemeToScriptCommand = new RelayCommand(async () => await OnApplyThemeToScriptCommandAsync(), () => ActiveDocumentIsScript);
            EditMasterThemeCommand = new RelayCommand(OnEditMasterThemeCommand, () => ActiveDocumentIsScript);

            AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
            AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
            AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
            DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable && _avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);

            ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
            CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand, () => ActiveDocumentIsScript);

            ToggleShowAdvancedCommand = new RelayCommand<bool>(OnToggleShowAdvancedCommand, s => ActiveDocumentIsScript);
            ClearFiltersCommand = new RelayCommand(OnClearFiltersCommand, () => ActiveDocumentIsScript);

            if (string.IsNullOrEmpty(_itemFilterScriptRepository.GetItemFilterScriptDirectory()))
            {
                SetItemFilterScriptDirectory();
            }

            var icon = new BitmapImage();
            icon.BeginInit();
            icon.UriSource = new Uri("pack://application:,,,/Filtration;component/Resources/Icons/filtration_icon.png");
            icon.EndInit();
            Icon = icon;

            Messenger.Default.Register<ThemeClosedMessage>(this, message =>
            {
                if (message.ClosedViewModel == null) return;
                AvalonDockWorkspaceViewModel.CloseDocument(message.ClosedViewModel);
            });

            Messenger.Default.Register<NotificationMessage>(this, message =>
            {
                switch (message.Notification)
                {
                    case "ActiveDocumentChanged":
                    {
                        CopyScriptCommand.RaiseCanExecuteChanged();
                        SaveCommand.RaiseCanExecuteChanged();
                        SaveAsCommand.RaiseCanExecuteChanged();
                        CloseCommand.RaiseCanExecuteChanged();
                        CopyBlockCommand.RaiseCanExecuteChanged();
                        PasteCommand.RaiseCanExecuteChanged();
                        ReplaceColorsCommand.RaiseCanExecuteChanged();
                        ApplyThemeToScriptCommand.RaiseCanExecuteChanged();
                        EditMasterThemeCommand.RaiseCanExecuteChanged();
                        CreateThemeCommand.RaiseCanExecuteChanged();
                        RaisePropertyChanged("ActiveDocumentIsScript");
                        RaisePropertyChanged("ActiveDocumentIsTheme");
                        RaisePropertyChanged("ShowAdvancedStatus");
                        break;
                    }
                    case "NewScript":
                    {
                        OnNewScriptCommand();
                        break;
                    }
                    case "OpenScript":
                    {
#pragma warning disable 4014
                        OnOpenScriptCommand();
#pragma warning restore 4014
                        break;
                    }
                    case "ShowLoadingBanner":
                    {
                        ShowLoadingBanner = true;
                        break;
                    }
                    case "HideLoadingBanner":
                    {
                        ShowLoadingBanner = false;
                        break;
                    }
                }
            });
        }