public MainViewModel() { var adjustmentFactory = new ResourceAdjustmentFactory(); _commandFactory = new DelegateCommandFactory(); _woodCache = new ObservableResourceCache(new ResourceCache(), () => { NotifyPropertyChanged(nameof(Wood)); NotifyPropertyChanged(nameof(Lumbermill)); }); Lumbermill = new Lumbermill(_woodCache, adjustmentFactory); Increment = _commandFactory.CreateFor( () => _woodCache.Apply(adjustmentFactory.CreateIncreaseEqualTo(1))); UpgradeLumbermill = _commandFactory.CreateFor(Lumbermill.Upgrade); _loop = new GameLoop(ticksPerSecond: 100); _loop.Tick += (tickDuration) => { Lumbermill.Generate(tickDuration); }; _loop.Start(); _woodCache.Apply(adjustmentFactory.CreateIncreaseEqualTo(20)); }
public TileNavBaseViewModel() { Messenger.Default.Register <NavigationMessage>(this, OnNavigationMessage); _Categories = new ObservableCollection <TileNavBaseItemViewModel>(TileNavBaseViewModelDataProvider.CreateCategories()); _Actions = new ObservableCollection <TileNavBaseItemViewModel>(TileNavBaseViewModelDataProvider.CreateActions()); BackCommand = DelegateCommandFactory.Create(OnBackCommand, CanBackCommand); }
public BranchViewModel(GitLabWrapper gitLabWrapper, RepositoryViewModel repository, string branch) { this.gitLabWrapper = gitLabWrapper; Repository = repository; Name = branch; ForceBuildCommand = DelegateCommandFactory.Create(ForceBuild, CanForceBuild); }
List <CommandViewModel> CreateToolbarCommands() { var newProjectRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); var addNewItemRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); var openRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); CommandViewModel newProject = new CommandViewModel("New Project", newProjectRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/NewProject_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel newFile = new CommandViewModel("Add New Item", addNewItemRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/File_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control) }; CommandViewModel openFile = new CommandViewModel("Open File", openRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenFile_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control) }; CommandViewModel save = new CommandViewModel("Save") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Save_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control) }; CommandViewModel saveAll = new CommandViewModel("Save All") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/SaveAll_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel cut = new CommandViewModel("Cut") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Cut_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel copy = new CommandViewModel("Copy") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Copy_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel paste = new CommandViewModel("Paste") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Paste_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel undo = new CommandViewModel("Undo") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Undo_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel redo = new CommandViewModel("Redo") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Redo_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; return(new List <CommandViewModel>() { newProject, newFile, openFile, save, saveAll, GetSeparator(), cut, copy, paste, GetSeparator(), undo, redo }); }
public void CreateCommand_Test(Func <CommandSchema, ICommand> factoryMethod, CommandSchema commandSchema) { // Arrange var factory = new DelegateCommandFactory(factoryMethod); // Act var command = factory.CreateCommand(commandSchema); // Assert command.Should().BeOfType(commandSchema.Type); }
public EditMergeRequestTestsViewModel() { Messenger.Default.Register <Message>(this, OnMessageReceived); CancelTestsCommand = DelegateCommandFactory.Create(PerformCancelTests, CanPerformCancelTests); ShowLogCommand = DelegateCommandFactory.Create <CommitViewModel>(PerformShowLogs, CanPerformShowLogs); ForceTestCommand = DelegateCommandFactory.Create <CommitViewModel>(PerformForceTest, CanPerformForceTest); AbortTestCommand = DelegateCommandFactory.Create <CommitViewModel>(PerformAbortTest, CanPerformAbortTest); UseCommitDescriptionCommand = DelegateCommandFactory.Create <CommitViewModel>(UseCommitDescription, CanUseCommitDescription); Initialize(); }
public EditBranchViewModel() { Messenger.Default.Register <Message>(this, OnMessageReceived); CreateMergeRequestCommand = DelegateCommandFactory.Create(PerformCreateMergeRequest, CanPerformCreateMergeRequest); CloseMergeRequestCommand = DelegateCommandFactory.Create(PerformCloseMergeRequest, CanPerformCloseMergeRequest); ShowMergeRequestCommand = DelegateCommandFactory.Create(PerformShowMergeRequest, CanShowMergeRequest); CopyMergeRequestLinkCommand = DelegateCommandFactory.Create(PerformCopyMergeRequestLink, CanCopyMergeRequestLink); ForceBuildCommand = DelegateCommandFactory.Create(PerformForceBuild, CanPerformForceBuild); RefreshSelectedBranch(); }
protected virtual List <CommandViewModel> CreateFileCommands() { var openDocumentRelayCommand = DelegateCommandFactory.Create <object>(OnOpenDocument); CommandViewModel openDocument = new CommandViewModel("Open...", openDocumentRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/Open_16x16.png"), IsEnabled = true }; return(new List <CommandViewModel>() { openDocument }); }
public RootViewModel() { Config = ConfigSerializer.GetConfig(); UpdateAppearance(); dispatcher = Dispatcher.CurrentDispatcher; FarmIntegrator.Start(FarmRefreshed); UpdateCommand = DelegateCommandFactory.Create(PerformUpdate, CanPerformUpdate); SettingsCommand = DelegateCommandFactory.Create(ShowSettings, CanShowSettings); ShowLogCommand = DelegateCommandFactory.Create(PerformShowLog); LoadTestLogCommand = DelegateCommandFactory.Create(PerformLoadTestLog, CanPerformLoadTestLog); InitializeCommand = DelegateCommandFactory.Create(PerformInitialize, CanPerformInitialize); ActivateCommand = DelegateCommandFactory.Create(PerformActivate, CanPerformActivate); LogViewModel = new LoggingViewModel(); Version = $"Git tools {VersionInfo.Version}"; }
public void CanExecuteChangedTest2() { Button control = new Button(); bool isCommandEnabled = true; DelegateCommand command = DelegateCommandFactory.Create( () => { }, () => { return(isCommandEnabled); }, false); ConfirmationBehavior b = new ConfirmationBehavior(); b.Command = command; Interaction.GetBehaviors(control).Add(b); Assert.IsTrue(control.IsEnabled); isCommandEnabled = false; command.RaiseCanExecuteChanged(); Assert.IsFalse(control.IsEnabled); }
protected virtual List <CommandViewModel> CreateViewCommands() { var showToolboxPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowToolboxPanel); var showSolutionExplorerPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowSolutionExplorerPanel); var showPropertiesPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowPropertiesPanel); var showErrorListPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowErrorListPanel); var showOutputPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowOutputPanel); var showSearchResultsPanelRelayCommand = DelegateCommandFactory.Create <object>(OnShowSearchResultsPanel); CommandViewModel toolbox = new CommandViewModel(_ToolboxViewModel, showToolboxPanelRelayCommand); CommandViewModel solutionExplorer = new CommandViewModel(_SolutionExplorerViewModel, showSolutionExplorerPanelRelayCommand); CommandViewModel properties = new CommandViewModel(_PropertiesViewModel, showPropertiesPanelRelayCommand); CommandViewModel errorList = new CommandViewModel(_ErrorListViewModel, showErrorListPanelRelayCommand); CommandViewModel output = new CommandViewModel(_OutputViewModel, showOutputPanelRelayCommand); CommandViewModel searchResults = new CommandViewModel(_SearchResultsViewModel, showSearchResultsPanelRelayCommand); return(new List <CommandViewModel>() { toolbox, solutionExplorer, properties, errorList, output, searchResults }); }
public void SourceChangedFireCount1() { var panel = new StackPanel(); panel.Children.Add(new Button() { Name = "button1" }); panel.Children.Add(new Button() { Name = "button2" }); int gotFocusCount = 0; var eventToCommand = new EventToCommand() { SourceObject = panel.Children[0], EventName = "GotFocus", Command = DelegateCommandFactory.Create(() => gotFocusCount++, false) }; Interaction.GetBehaviors(panel).Add(eventToCommand); Window.Content = panel; EnqueueShowWindow(); EnqueueCallback(() => { Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount); eventToCommand.SourceName = "button2"; Assert.AreEqual(1, eventToCommand.RaiseSourceChangedCount); Assert.AreEqual(0, gotFocusCount); ((Button)panel.Children[1]).Focus(); }); EnqueueConditional(() => gotFocusCount == 0); EnqueueCallback(() => { ((Button)panel.Children[0]).Focus(); }); EnqueueConditional(() => gotFocusCount == 1); EnqueueTestComplete(); }
public TileNavBaseItemViewModel() { Items = new ObservableCollection <TileNavBaseItemViewModel>(); BackCommand = DelegateCommandFactory.Create(OnBackCommand); ShowNotificationCommand = DelegateCommandFactory.Create <string>(OnShowNotificationCommand); }
public TileNavPaneViewModel() { Messenger.Default.Register <NotificationMessage>(this, OnNotificationMessage); ShowNotificationCommand = DelegateCommandFactory.Create <string>(OnShowNotificationCommand); }
public EditMergeRequestViewModel() { Messenger.Default.Register <Message>(this, OnMessageReceived); ApplyCommand = DelegateCommandFactory.Create(PerformApply, CanPerformApply); RefreshSelectedBranch(); }
public TestViewModel() { PrismDelegate = new Microsoft.Practices.Prism.Commands.DelegateCommand(Execute, CanExecute); MyDelegate = new DelegateCommandWrapper(Execute, CanExecute); MyDelegateFromFactory = new DelegateCommandFactory().CreateCommand(Execute, CanExecute); }
protected override List <CommandViewModel> CreateFileCommands() { var projectRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); var fileRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); var fileOpenRelayCommand = DelegateCommandFactory.Create <object>(OnNewFileExecuted); var closeFileRelayCommand = DelegateCommandFactory.Create <object>(OnCloseFileExecuted); CommandViewModel newCommand = new CommandViewModel("New") { IsSubItem = true }; CommandViewModel newProject = new CommandViewModel("Project...", projectRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/NewProject_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel newFile = new CommandViewModel("File...", fileRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/File_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control) }; newCommand.Commands = new List <CommandViewModel>() { newProject, newFile }; CommandViewModel openCommand = new CommandViewModel("Open") { IsSubItem = true, }; CommandViewModel openProject = new CommandViewModel("Project/Solution...") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenSolution_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control | ModifierKeys.Shift), IsEnabled = false }; CommandViewModel openFile = new CommandViewModel("File...", fileOpenRelayCommand) { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenFile_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control) }; openCommand.Commands = new List <CommandViewModel>() { openProject, openFile }; CommandViewModel closeFile = new CommandViewModel("Close", closeFileRelayCommand); CommandViewModel closeSolution = new CommandViewModel("Close Solution") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/CloseSolution_16x16.png") }; CommandViewModel save = new CommandViewModel("Save") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Save_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control) }; CommandViewModel saveAll = new CommandViewModel("Save All") { Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/SaveAll_16x16.png"), KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control | ModifierKeys.Shift) }; CommandViewModel recentFilesCommand = new CommandViewModel("Recent files") { IsSubItem = true, }; CommandViewModel recentProjectsCommand = new CommandViewModel("Recent projects and solutions") { IsSubItem = true, }; return(new List <CommandViewModel>() { newCommand, openCommand, GetSeparator(), closeFile, closeSolution, GetSeparator(), save, saveAll, GetSeparator(), recentFilesCommand, recentProjectsCommand }); }