static Commands() { _CommandBindings = new CommandBindingCollection(); _CommandBindings.Add(new CommandBinding(ExitCommand, ExitCommandExecuted)); _CommandBindings.Add(new CommandBinding(ClearCommand, ClearCommandExecuted)); _CommandBindings.Add(new CommandBinding(SettingsCommand, SettingsCommandExecuted)); }
public static void AddCommand(CommandBindingCollection CommandBindings) { CommandBindings.Add(new CommandBinding(Commands.New_File, delegate { MessageBox.Show("新規ファイルの作成"); })); CommandBindings.Add(new CommandBinding(Commands.New_Project, delegate { MessageBox.Show("新規プロジェクトの作成"); })); CommandBindings.Add(new CommandBinding(Commands.View_NetWork, delegate { })); }
public static void SetCommandBinding(CommandBindingCollection commandCollection, ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute = null) { var binding = (canExecute == null) ? new CommandBinding(command, executed) : new CommandBinding(command, executed, canExecute); commandCollection.Remove(binding); commandCollection.Add(binding); }
private void Register(CommandBindingCollection bindings, ICommand command, OnCommandDel onCmd) { bindings.Add(new CommandBinding(command, delegate(object target, ExecutedRoutedEventArgs args) { onCmd(args.Parameter); args.Handled = true; })); }
public MainWindowViewModel(MainWindow mainWindow) { statesUndo = new Stack<IMemento>(); statesRedo = new Stack<IMemento>(); commandBindings = mainWindow.CommandBindings; inkCanvas = mainWindow.InkCanvasWithUndo1; inkCanvas.MouseUp += InkCanvasWithUndo1_MouseUp; //Create a command binding for the save command var saveBindingUndo = new CommandBinding(ApplicationCommands.Undo, OnExecutedCommandsUndo); var saveBindingRedo = new CommandBinding(ApplicationCommands.Redo, OnExecutedCommandsRedo); //Register the binding to the class CommandManager.RegisterClassCommandBinding(typeof (MainWindowViewModel), saveBindingUndo); //Adds the binding to the CommandBindingCollection commandBindings.Add(saveBindingUndo); commandBindings.Add(saveBindingRedo); StoreState(); }
public static void Start(ClientOrchestrator orchestrator, TriviaViewModel viewModel, CommandBindingCollection bindings, TriviaClient window) { Contract.Requires(orchestrator != null); bindings.Add(new CommandBinding(TriviaCommands.WrongAnswer, (object source, ExecutedRoutedEventArgs e) => { AnswerViewModel a = (AnswerViewModel)e.Parameter; a.WhoCalledIn = TriviaClient.PlayerName; orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false); })); bindings.Add(new CommandBinding(TriviaCommands.CorrectAnswer, (object source, ExecutedRoutedEventArgs e) => { CorrectAnswerData cad = (CorrectAnswerData)e.Parameter; AnswerViewModel a = cad.Answer; a.WhoCalledIn = TriviaClient.PlayerName; orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false); QuestionChanges questionChanges = new QuestionChanges(new QuestionId(a.Hour, a.Number)) { Open = false, Correct = true, Answer = a.Text, PhoneBankOperator = cad.PhoneBankOperator }; // Update the correct answer orchestrator.SendUpdateQuestionRequest(questionChanges); })); bindings.Add(new CommandBinding(TriviaCommands.PartialAnswer, (object source, ExecutedRoutedEventArgs e) => { AnswerViewModel a = (AnswerViewModel)e.Parameter; a.WhoCalledIn = TriviaClient.PlayerName; a.Partial = true; orchestrator.SendUpdateAnswerRequest(a.CreateModel(), true); // Flag as a partial })); bindings.Add(new CommandBinding(TriviaCommands.EditAnswer, (object source, ExecutedRoutedEventArgs e) => { // An edited answer was already modified by the command sender, so just update it to the server // Note: this is usually done by fixing the text of a partial answer AnswerViewModel a = (AnswerViewModel)e.Parameter; orchestrator.SendUpdateAnswerRequest(a.CreateModel(), false); // Flag not "partial changed". We don't know it to be the case, but that's the behavior we want })); bindings.Add(new CommandBinding(TriviaCommands.ShowSubmitAnswerDialog, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel question = (QuestionViewModel)e.Parameter; SubmitAnswerDialog submitAnswerDialog = new SubmitAnswerDialog(question); submitAnswerDialog.Owner = window; bool? submitted = submitAnswerDialog.ShowDialog(); if (submitted == true) { // 2014 - don't think this is true, but preserving the comment... Must execute the command against "this" current window so the commandbindings are hit TriviaCommands.SubmitAnswer.Execute(submitAnswerDialog.AnswerSubmitted, null); // Using "null" as the target means we avoid weird bugs where the event actually doesn't fire } })); bindings.Add(new CommandBinding(TriviaCommands.SubmitAnswer, (object source, ExecutedRoutedEventArgs e) => { Answer a = (Answer)e.Parameter; QuestionViewModel q; if (!(viewModel.TryGetQuestion(a, out q))) { throw new InvalidOperationException("Couldn't get question for answer submitted, that's really odd..."); } if (ContestConfiguration.PreventDuplicateAnswerSubmission && CommandHandler.ShouldStopAnswerSubmission(a, q, window)) { return; } orchestrator.SendSubmitAnswerRequest(a); // Inform the server // If you're submitting an answer, it's likely to assume you're researching the question if (!(q.IsBeingResearched)) { q.IsBeingResearched = true; TriviaCommands.ResearcherChanged.Execute(q, null); } })); bindings.Add(new CommandBinding(TriviaCommands.OpenQuestion, (object source, ExecutedRoutedEventArgs e) => { QuestionId questionId = (QuestionId)e.Parameter; orchestrator.SendOpenQuestionRequest(questionId.Hour, questionId.Number); })); bindings.Add(new CommandBinding(TriviaCommands.EditQuestion, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel question = (QuestionViewModel)e.Parameter; EditingQuestionData data = new EditingQuestionData() { HourNumber = question.Identifier.Hour, QuestionNumber = question.Identifier.Number, WhoEditing = TriviaClient.PlayerName }; // Tell everyone else that "I'm editing this question, so back off!" orchestrator.SendEditingQuestionMessage(data); EditQuestionDialog dialog = new EditQuestionDialog(orchestrator, question, false); dialog.Owner = window; bool? result = dialog.ShowDialog(); if (!(result.HasValue) || result.Value == false) { data.WhoEditing = null; // Signal that the edit was cancelled orchestrator.SendEditingQuestionMessage(data); // If the user made a change to the question (in-memory viewmodel), should refresh from the server (it's just the easiest thing to do) if (dialog.GetChangesMade().Changes != QuestionChanges.Change.None) { orchestrator.SendGetCompleteHourDataRequest(question.Identifier.Hour); } return; // Cancelled / Closed without saving } QuestionChanges changes = dialog.GetChangesMade(); if (changes.Changes == QuestionChanges.Change.None) { return; // No changes actually were made even though the user clicked the Save button } orchestrator.SendUpdateQuestionRequest(changes); })); bindings.Add(new CommandBinding(TriviaCommands.UpdateQuestionPoints, (object source, ExecutedRoutedEventArgs e) => { // Only Beerpigs use this QuestionChanges changes = (QuestionChanges)e.Parameter; orchestrator.SendUpdateQuestionRequest(changes); })); bindings.Add(new CommandBinding(TriviaCommands.PlayAudioTrivia, (object source, ExecutedRoutedEventArgs e) => { string audioTriviaFileName = (string)e.Parameter; CommandHandler.PlayAudioTrivia(audioTriviaFileName, window); })); bindings.Add(new CommandBinding(TriviaCommands.ShowAddNoteDialog, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel question = (QuestionViewModel)e.Parameter; Note note = new Note(); note.Submitter = TriviaClient.PlayerName; note.HourNumber = question.Identifier.Hour; note.QuestionNumber = question.Identifier.Number; AddNoteDialog dialog = new AddNoteDialog(note); dialog.Owner = window; bool? result = dialog.ShowDialog(); if (!(result.HasValue) || result.Value == false) { return; // Cancelled / Closed without saving } note.Text = note.Text.Trim(); // Trim it. // Save the note orchestrator.SendAddNoteMessage(note); // If you're adding a note, it's likely to assume you're researching the question if (!(question.IsBeingResearched)) { question.IsBeingResearched = true; TriviaCommands.ResearcherChanged.Execute(question, null); } })); bindings.Add(new CommandBinding(TriviaCommands.CorrectAnswerWithoutSubmission, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel question = (QuestionViewModel)e.Parameter; Answer answer = new Answer(); answer.Hour = question.Identifier.Hour; answer.Number = question.Identifier.Number; answer.WhoCalledIn = TriviaClient.PlayerName; AnswerViewModel answerViewModel = new AnswerViewModel(answer); // Show the "blank" dialog CorrectAnswerDialog dialog = new CorrectAnswerDialog(answerViewModel); dialog.Owner = window; bool? result = dialog.ShowDialog(); if (!(result.HasValue) || result.Value == false) { return; // Cancelled / Closed without saving } QuestionChanges changes = new QuestionChanges(question.Identifier) { Open = false, Correct = true, Answer = dialog.Answer.Text, PhoneBankOperator = dialog.PhoneBankOperator }; // Update the correct answer orchestrator.SendUpdateQuestionRequest(changes); })); bindings.Add(new CommandBinding(TriviaCommands.ResearcherChanged, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel questionThatChanged = (QuestionViewModel)e.Parameter; if (questionThatChanged.IsBeingResearched == false) { // User said they're not researching this question (and by extension, aren't researching *anything* anymore) orchestrator.SendResearcherChangedRequest( new ResearcherChange { HourNumber = 0, // Signaling that current user is researching nothing QuestionNumber = 0, // Signaling that current user is researching nothing Name = TriviaClient.PlayerName }); } else { orchestrator.SendResearcherChangedRequest( new ResearcherChange { HourNumber = questionThatChanged.Identifier.Hour, QuestionNumber = questionThatChanged.Identifier.Number, Name = TriviaClient.PlayerName }); } })); bindings.Add(new CommandBinding(TriviaCommands.ShowEditPartialsDialog, (object source, ExecutedRoutedEventArgs e) => { ListCollectionView partials = (ListCollectionView)e.Parameter; EditPartialsDialog dialog = new EditPartialsDialog(); dialog.DataContext = partials; dialog.Owner = window; dialog.ShowDialog(); })); bindings.Add(new CommandBinding(TriviaCommands.ShowCombinePartialsDialog, (object source, ExecutedRoutedEventArgs e) => { QuestionViewModel question = (QuestionViewModel)e.Parameter; string combinationAnswer = string.Join("\n", question.PartialAnswers.Cast<AnswerViewModel>().Select(avm => avm.Text)); SubmitAnswerDialog submitAnswerDialog = new SubmitAnswerDialog(question, combinationAnswer); submitAnswerDialog.Owner = window; bool? submitted = submitAnswerDialog.ShowDialog(); if (submitted == true) { // 2014, don't think this is true, ubt pres3erving the original comment..... Must execute the command against "this" current window so the commandbindings are hit TriviaCommands.SubmitAnswer.Execute(submitAnswerDialog.AnswerSubmitted, null); // Using "null" as the target means we avoid weird bugs where the event actually doesn't fire } })); bindings.Add(new CommandBinding(TriviaCommands.ShowAddLinkDialog, (object source, ExecutedRoutedEventArgs e) => { AddLinkDialog dialog = new AddLinkDialog(); dialog.Owner = window; bool? result = dialog.ShowDialog(); if (!(result.HasValue) || result.Value == false) { return; // Cancelled / Closed without saving } dialog.Link.Description = dialog.Link.Description.Trim(); dialog.Link.Url = dialog.Link.Url.Trim(); // Save the link orchestrator.SendAddLinkRequest(dialog.Link); })); bindings.Add(new CommandBinding(TriviaCommands.DeleteNote, (object source, ExecutedRoutedEventArgs e) => { orchestrator.SendDeleteNoteMessage((Note)e.Parameter); })); }
public static void RegisterCommands(CommandBindingCollection commandBindings) { commandBindings.Add( new CommandBinding(_displayLogin, ExecuteDisplayLogin, CanExecuteDisplayLogin)); commandBindings.Add( new CommandBinding(_displayAddContact, ExecuteDisplayAddContact, CanExecuteDisplayAddContact)); commandBindings.Add( new CommandBinding(_displayWizard, ExecuteDisplayWizard, CanExecuteDisplayWizard)); commandBindings.Add( new CommandBinding(_displayHeadlines, ExecuteDisplayHeadlines, CanExecuteDisplayHeadlines)); commandBindings.Add( new CommandBinding(_history, ExecuteDisplayHistory, CanExecuteDisplayHistory)); commandBindings.Add( new CommandBinding(_displayMucMarks, ExecuteDisplayMucMarks, CanExecuteDisplayMucMarks)); commandBindings.Add( new CommandBinding(_login, ExecuteLogin, CanExecuteLogin)); commandBindings.Add( new CommandBinding(_displayChat, ExecuteDisplayChat, CanExecuteDisplayChat)); }
private static void CheckCommandBinding( TextBox textBox, TextCommandFlags textCommandFlags, IEnumerable<CommandBinding> commandBindings, CommandBindingCollection commandBindingCollection, RoutedUICommand command, TextCommandFlags commandFlag, TextCommandType commandType) { var commandBinding = commandBindings.FirstOrDefault(cb => cb.Command == command); if (textCommandFlags.HasFlag(commandFlag) && commandBinding == null) { commandBindingCollection.Add(TextCommandBindings.CreateCommandBinding(textBox, commandType)); } else if (!textCommandFlags.HasFlag(commandFlag) && commandBinding != null) { commandBindingCollection.Remove(commandBinding); } }
protected override void OnBindCommands(CommandBindingCollection bindings) { DebugHelper.AssertUIThread(); base.OnBindCommands(bindings); if (bindings != null) { { ICommand cmd = FindResource("KinectStudioPlugin.ZoomPercentageCommand") as ICommand; if (cmd != null) { bindings.Add(new CommandBinding(cmd, (source2, e2) => { DebugHelper.AssertUIThread(); string str = e2.Parameter as string; if (str == null) { this.IsZoomToFit = true; } else { int newZoom; if (int.TryParse(str, out newZoom)) { e2.Handled = true; Zoom = newZoom; } } }, (source2, e2) => { e2.Handled = true; e2.CanExecute = true; })); } } { ICommand cmd = FindResource("KinectStudioPlugin.ZoomInOutCommand") as ICommand; if (cmd != null) { bindings.Add(new CommandBinding(cmd, (source2, e2) => { DebugHelper.AssertUIThread(); string str = e2.Parameter as string; switch (str) { case "+": e2.Handled = true; this.ZoomIn(); break; case "-": e2.Handled = true; this.ZoomOut(); break; } }, (source2, e2) => { string str = e2.Parameter as string; switch (str) { case "+": e2.Handled = true; e2.CanExecute = (this.Zoom <= 2273); break; case "-": e2.Handled = true; e2.CanExecute = (this.Zoom >= 11); break; } })); } } } }
public void BindCommands(CommandBindingCollection bindings, InputBindingCollection inputBindings) { //Switch View bindings.Add(new CommandBinding(Commands.SwitchView, delegate(object target, ExecutedRoutedEventArgs args) { OnSwitchView(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.SwitchView, new KeyGesture(Key.Enter))); //Display Next bindings.Add(new CommandBinding(Commands.DisplayNext, delegate(object target, ExecutedRoutedEventArgs args) { OnDisplayNext(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.DisplayNext, new KeyGesture(Key.PageDown))); //Display Prev bindings.Add(new CommandBinding(Commands.DisplayPrev, delegate(object target, ExecutedRoutedEventArgs args) { OnDisplayPrev(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.DisplayPrev, new KeyGesture(Key.PageUp))); //Display First bindings.Add(new CommandBinding(Commands.DisplayFirst, delegate(object target, ExecutedRoutedEventArgs args) { OnDisplayFirst(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.DisplayFirst, new KeyGesture(Key.Home))); //Display Last bindings.Add(new CommandBinding(Commands.DisplayLast, delegate(object target, ExecutedRoutedEventArgs args) { OnDisplayLast(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.DisplayLast, new KeyGesture(Key.End))); //Zoom To Fit bindings.Add(new CommandBinding(Commands.ZoomToFit, delegate(object target, ExecutedRoutedEventArgs args) { OnZoomToFit(); args.Handled = true; })); inputBindings.Add(new InputBinding(Commands.ZoomToFit, new KeyGesture(Key.Insert))); }
protected override void OnBindCommands(CommandBindingCollection bindings) { DebugHelper.AssertUIThread(); base.OnBindCommands(bindings); if (bindings != null) { { ICommand cmd = FindResource("KinectStudioPlugin.CameraViewCommand") as ICommand; if (cmd != null) { bindings.Add(new CommandBinding(cmd, (source2, e2) => { DebugHelper.AssertUIThread(); switch (e2.Parameter.ToString()) { case "Default": e2.Handled = true; ViewDefault(); break; case "Front": e2.Handled = true; ViewFront(); break; case "Left": e2.Handled = true; ViewLeft(); break; case "Top": e2.Handled = true; ViewTop(); break; } }, (source2, e2) => { e2.Handled = true; e2.CanExecute = true; })); } } { ICommand cmd = FindResource("KinectStudioPlugin.ZoomInOutCommand") as ICommand; if (cmd != null) { bindings.Add(new CommandBinding(cmd, (source2, e2) => { DebugHelper.AssertUIThread(); string str = e2.Parameter as string; switch (str) { case "+": e2.Handled = true; this.ZoomIn(); break; case "-": e2.Handled = true; this.ZoomOut(); break; } }, (source2, e2) => { e2.Handled = true; e2.CanExecute = true; })); } } } }
public RepositoryViewModel() { CommandBindings = new CommandBindingCollection(); this.DriveManager = new DriveManager(); m_deviceRepository = new DeviceRepository(); m_vehicles = new ListCollectionView(PersonalDomain.Domain.Vehicles); m_vehicles.CurrentChanged += new EventHandler(Vehicles_CurrentChanged); m_selectedTracks = new TrackCollection(); m_playbackManager = new PlaybackManager(m_selectedTracks); SearchFrom = DateTime.Today; SearchTo = DateTime.Today + TimeSpan.FromMinutes(23 * 60 + 59); SearchAll = true; SearchMode = SearchMode.Recent; AutoPlay = true; AllPlay = true; OpenCommand = new DelegateCommand<object>(DoOpen, CanOpen); SearchCommand = new DelegateCommand<object>(DoSearch, CanSearch); PlaybackCommand = new DelegateCommand<object>(DoPlayback, CanPlayback); SaveCommand = new DelegateCommand(DoSave, CanSave); ArrangeCommand = new DelegateCommand(DoArrange, CanArrange); DeleteCommand = new RoutedUICommand("삭제", "삭제", typeof(RepositoryViewModel)); CommandBinding binding = new CommandBinding(DeleteCommand, DoDelete, CanDelete); CommandManager.RegisterClassCommandBinding(typeof(RepositoryViewModel), binding); CommandBindings.Add(binding); RegisterGlobalEvents(); }
/// <summary> /// コマンドをバインディングします。 /// </summary> public static void Binding(ShogiUIElement3D control, CommandBindingCollection bindings) { bindings.Add( new CommandBinding( LoadKifFile, (_, e) => ExecuteLoadKifFile(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( SaveKifFile, (_, e) => ExecuteSaveKifFile(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( PasteKifFile, (_, e) => ExecutePasteKifFile(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( CopyKifFile, (_, e) => ExecuteCopyKifFile(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( SetReverseBoard, (_, e) => ExecuteSetReverseBoard(control, e), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( GotoFirstState, (_, e) => ExecuteGotoFirstState(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( GotoLastState, (_, e) => ExecuteGotoLastState(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( MoveUndo, (_, e) => ExecuteMoveUndo(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( MoveRedo, (_, e) => ExecuteMoveRedo(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( MoveUndoContinue, (_, e) => ExecuteMoveUndoContinue(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( MoveRedoContinue, (_, e) => ExecuteMoveRedoContinue(control), (_, e) => CanExecute(control, e))); bindings.Add( new CommandBinding( MoveStop, (_, e) => ExecuteMoveStop(control), (_, e) => CanExecute(control, e))); }
// Let the chord command in front, so that the chord command (e.g. Ctrl+E,Ctrl+V) will match // before the (e.g. Ctrl+V). void ReorderCommandBindings() { CommandBindingCollection chordCommandBindings = new CommandBindingCollection(); CommandBindingCollection basicCommandBindings = new CommandBindingCollection(); foreach (CommandBinding binding in this.CommandBindings) { RoutedCommand cmd = binding.Command as RoutedCommand; if (ContainsChordKeyGestures(cmd.InputGestures)) { chordCommandBindings.Add(binding); } else { basicCommandBindings.Add(binding); } } this.CommandBindings.Clear(); this.CommandBindings.AddRange(chordCommandBindings); this.CommandBindings.AddRange(basicCommandBindings); }
protected virtual void OnBindCommands(CommandBindingCollection bindings) { DebugHelper.AssertUIThread(); if (bindings != null) { ICommand cmd = FindResource("KinectStudioPlugin.ShowSettingsCommand") as ICommand; if (cmd != null) { bindings.Add(new CommandBinding(cmd, (source2, e2) => { DebugHelper.AssertUIThread(); this.ShowSettings(); e2.Handled = true; }, (source2, e2) => { e2.Handled = true; e2.CanExecute = true; })); } } }
internal void RegisterGlobalCommands(CommandBindingCollection commandBindings) { commandBindings.Add(new CommandBinding(ApplicationCommands.Find, ExecuteFind)); commandBindings.Add(new CommandBinding(SearchCommands.FindNext, ExecuteFindNext, CanExecuteWithOpenSearchPanel)); commandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, ExecuteFindPrevious, CanExecuteWithOpenSearchPanel)); }