public static void SetRegistration(UIElement element, CommandBindingCollection value)
 {
     if (element != null)
     {
         element.SetValue(Registration, value);
     }
 }
Example #2
0
 static Commands()
 {
     _CommandBindings = new CommandBindingCollection();
     _CommandBindings.Add(new CommandBinding(ExitCommand, ExitCommandExecuted));
     _CommandBindings.Add(new CommandBinding(ClearCommand, ClearCommandExecuted));
     _CommandBindings.Add(new CommandBinding(SettingsCommand, SettingsCommandExecuted));
 }
Example #3
0
 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;
                                 }));
 }
Example #4
0
 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);
 }
Example #5
0
        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 {

            }));
        }
Example #6
0
        private static void FindCommandBinding(CommandBindingCollection commandBindings, object sender, RoutedEventArgs e, ICommand command, bool execute)
        {
            int index = 0;

            while (true)
            {
                CommandBinding commandBinding = commandBindings.FindMatch(command, ref index);
                if (HandleCommandBinding(sender, e, commandBinding, execute))
                {
                    break;
                }
            }
        }
Example #7
0
        private static void FindCommandBinding(CommandBindingCollection commandBindings, object sender, RoutedEventArgs e, ICommand command, bool execute)
        {
            int index = 0;

            while (true)
            {
                CommandBinding commandBinding = commandBindings.FindMatch(command, ref index);
                if ((commandBinding == null) ||
                    (execute && ExecuteCommandBinding(sender, (ExecutedRoutedEventArgs)e, commandBinding)) ||
                    (!execute && CanExecuteCommandBinding(sender, (CanExecuteRoutedEventArgs)e, commandBinding)))
                {
                    break;
                }
            }
        }
    public static void RegisterClassCommandBinding(Type type, CommandBinding commandBinding)
    {
      if (type == null)
      {
        throw new ArgumentNullException("type");
      }

      CommandBindingCollection bindings = _commandBindings[type] as CommandBindingCollection;

      if (bindings == null)
      {
        _commandBindings[type] = bindings = new CommandBindingCollection();
      }

      bindings.Add(commandBinding);
    }
Example #9
0
        public static void RegisterClassCommandBinding(Type type, CommandBinding commandBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            CommandBindingCollection bindings = _commandBindings[type] as CommandBindingCollection;

            if (bindings == null)
            {
                _commandBindings[type] = bindings = new CommandBindingCollection();
            }

            bindings.Add(commandBinding);
        }
Example #10
0
        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 MainWindowViewModel()
        {
            this.fileList = new ObservableCollection<FileConversionInfo>();
            this.fileList.CollectionChanged += fileList_CollectionChanged;
            ImageFileList = this.fileList;

            this.Profiles = new ReadOnlyObservableCollection<KindleProfile>(new ObservableCollection<KindleProfile>(new KindleProfile[] { new Kindle3(), new KindlePaperWhite12(), new KindlePaperWhite3Voyage() }));
            this.SelectedProfile = this.Profiles.First();

            this._CommandBindings = new CommandBindingCollection();
            CommandBinding newBinding = new CommandBinding(ApplicationCommands.New, NewCmdExecuted, (s, e) => e.CanExecute = true);
            CommandBinding addFilesBinding = new CommandBinding(MainWindowCommands.AddFiles, AddFilesCmdExecuted, (s, e) => e.CanExecute = true);
            CommandBinding removeFilesBinding = new CommandBinding(MainWindowCommands.RemoveFiles, RemoveFilesCmdExecuted, RemoveFilesCanExecute);
            CommandBinding exportFilesBinding = new CommandBinding(MainWindowCommands.ExportFiles, ExportFilesCmdExecuted, ExportFilesCanExecute);
            CommandBinding moveUpBinding = new CommandBinding(ComponentCommands.MoveUp, MoveUpCmdExecuted, MoveCanExecute);
            CommandBinding moveDownBinding = new CommandBinding(ComponentCommands.MoveDown, MoveDownCmdExecuted, MoveCanExecute);
            this._CommandBindings.Add(newBinding);
            this._CommandBindings.Add(addFilesBinding);
            this._CommandBindings.Add(removeFilesBinding);
            this._CommandBindings.Add(exportFilesBinding);
            this._CommandBindings.Add(moveUpBinding);
            this._CommandBindings.Add(moveDownBinding);
        }
Example #12
0
        public void Bind(CommandBindingCollection commandBindings)
        {
            Register(commandBindings, Commands.OpenDocument,       delegate(object param) 
                                                                            { 
                                                                                _handler.OnOpenDocument(param as JadeCore.OpenFileCommandParams); 
                                                                            });

            Register(commandBindings, ApplicationCommands.New,     delegate { _handler.OnNewFile(); },         delegate { return _handler.CanNewFile(); });
            Register(commandBindings, ApplicationCommands.Open,    delegate(object param)
                                                                            { 
                                                                                _handler.OnOpenFile(param as JadeUtils.IO.IFileHandle); 
                                                                            },        delegate { return _handler.CanOpenFile(); });

            Register(commandBindings, ApplicationCommands.Save,    delegate { _handler.OnSaveFile(); },        delegate { return _handler.CanSaveFile(); });
            Register(commandBindings, ApplicationCommands.SaveAs,  delegate { _handler.OnSaveAsFile(); },      delegate { return _handler.CanSaveAsFile(); });
            Register(commandBindings, Commands.SaveAllFiles,       delegate { _handler.OnSaveAllFiles(); },    delegate { return _handler.CanSaveAllFiles(); });
            Register(commandBindings, Commands.CloseFile,          delegate { _handler.OnCloseFile(); },       delegate { return _handler.CanCloseFile(); });

            Register(commandBindings, Commands.Exit,               delegate { _handler.OnExit(); });
            Register(commandBindings, Commands.NewWorkspace,       delegate { _handler.OnNewWorkspace(); });
            Register(commandBindings, Commands.CloseWorkspace,     delegate { _handler.OnCloseWorkspace(); },  delegate { return _handler.CanCloseWorkspace(); });
            Register(commandBindings, Commands.PromptOpenWorkspace, delegate { _handler.OnPromptOpenWorkspace(); }, delegate { return _handler.CanPromptOpenWorkspace(); });
            Register(commandBindings, Commands.OpenWorkspace,      delegate(object param) { _handler.OnOpenWorkspace(param as string); },   delegate { return _handler.CanOpenWorkspace(); });
            Register(commandBindings, Commands.SaveWorkspace,      delegate { _handler.OnSaveWorkspace(); },   delegate { return _handler.CanSaveWorkspace(); });
            Register(commandBindings, Commands.SaveAsWorkspace,    delegate { _handler.OnSaveAsWorkspace(); }, delegate { return _handler.CanSaveAsWorkspace(); });

            Register(commandBindings, Commands.ViewLineNumbers,    delegate { _handler.OnViewLineNumbers(); }, delegate { return _handler.CanViewLineNumbers(); });
            Register(commandBindings, Commands.ViewWorkspaceWindow, delegate { _handler.OnViewWorkspaceWindow(); }, delegate { return _handler.CanViewWorkspaceWindow(); });
            Register(commandBindings, Commands.ViewSearchResultsWindow, delegate { _handler.OnViewSearchResultsWindow(); }, delegate { return _handler.CanViewSearchResultsWindow(); });

            Register(commandBindings, Commands.CloseAllDocuments,  delegate { _handler.OnCloseAllDocuments(); }, delegate { return _handler.CanCloseAllDocuments(); });

            Register(commandBindings, Commands.SearchInFiles, delegate { _handler.OnSearchInFiles(); }, delegate { return _handler.CanSearchInFiles(); });
            Register(commandBindings, Commands.SearchDisplayNext, delegate { _handler.OnDisplayNextSearchResult(); }, delegate { return _handler.CanDisplayNextSearchResult(); });
            Register(commandBindings, Commands.SearchDisplayPrev, delegate { _handler.OnDisplayPrevSearchResult(); }, delegate { return _handler.CanDisplayPrevSearchResult(); });
        }
Example #13
0
        /// <summary>
        ///     Register class level CommandBindings.
        /// </summary>
        /// <param name="type">Owner type</param>
        /// <param name="commandBinding">CommandBinding to register</param>
        public static void RegisterClassCommandBinding(Type type, CommandBinding commandBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (commandBinding == null)
            {
                throw new ArgumentNullException("commandBinding");
            }

            lock (_classCommandBindings.SyncRoot)
            {
                CommandBindingCollection bindings = _classCommandBindings[type] as CommandBindingCollection;

                if (bindings == null)
                {
                    bindings = new CommandBindingCollection();
                    _classCommandBindings[type] = bindings;
                }

                bindings.Add(commandBinding);
            }
        }
Example #14
0
        /// <summary>
        ///     Register class level CommandBindings.
        /// </summary>
        /// <param name="type">Owner type</param>
        /// <param name="commandBinding">CommandBinding to register</param>
        public static void RegisterClassCommandBinding(Type type, CommandBinding commandBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (commandBinding == null)
            {
                throw new ArgumentNullException("commandBinding");
            }

            lock (_classCommandBindings.SyncRoot)
            {
                CommandBindingCollection bindings = _classCommandBindings[type] as CommandBindingCollection;

                if (bindings == null)
                {
                    bindings = new CommandBindingCollection();
                    _classCommandBindings[type] = bindings;
                }

                bindings.Add(commandBinding);
            }
        }
        private void PageLoaded(object sender, RoutedEventArgs e)
        {
            // TODO: read from history
            FocusedExplorer = expLeft;

            //димина коллекция вотчеров не использую т.к. пока работает некорректно
            //_fileSystem.Watchers.DefaultChanged += OnChanged;
            //_fileSystem.Watchers.DefaultCreated += OnChanged;
            //_fileSystem.Watchers.DefaultDeleted += OnChanged;
            //_fileSystem.Watchers.DefaultRenamed += OnRenamed;

            //expLeft.Tag = _fileSystem.Watchers.Add(UcCurrentDirectory);
            //expRight.Tag = _fileSystem.Watchers.Add(UcCurrentDirectory);

            var watch = new FileSystemWatcher();
            expLeft.Tag = watch;
            InitializeWatcher(watch, UcCurrentDirectory);

            watch = new FileSystemWatcher();
            expRight.Tag = watch;
            InitializeWatcher(watch, UcCurrentDirectory);

            expLeft.CurrentPath = UcCurrentDirectory;
            expRight.CurrentPath = UcCurrentDirectory;

               var cmdBindCollection = new CommandBindingCollection
                                        {
                                            new CommandBinding(
                                                NavigationCommands.Refresh,
                                                RefreshOnExecute,
                                                RefreshCanExecute
                                                ),
                                            new CommandBinding(
                                                ApplicationCommands.Copy,
                                                CopyOnExecute,
                                                CopyCanExecute
                                                ),
                                            new CommandBinding(
                                                ApplicationCommands.Delete,
                                                DeleteOnExecute,
                                                DeleteCanExecute
                                                )
                                        };

            //cmdBindCollection.Add(new CommandBinding(
            //                                                        ApplicationCommands.Cut,
            //                                                        CutCanExecute,
            //                                                        CutOnExecute
            //

            expLeft.GridCommandBindings.AddRange(cmdBindCollection);
            expRight.GridCommandBindings.AddRange(cmdBindCollection);

            Application.Current.SessionEnding += ApplicationOnSessionEnding;
        }
Example #16
0
 public static void SetCustomCommandBindings(UIElement element, CommandBindingCollection value)
 {
     if (element != null)
         element.SetValue(CustomCommandBindingsProperty, value);
 }
        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;
                                    }
                                }));
                    }
                }
            }
        }
Example #18
0
        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);
                }));
        }
Example #19
0
        private static void FindCommandBinding(object sender, RoutedEventArgs e, ICommand command, bool execute)
        {
            // Check local command bindings
            CommandBindingCollection commandBindings = null;
            DependencyObject         senderAsDO      = sender as DependencyObject;

            if (InputElement.IsUIElement(senderAsDO))
            {
                commandBindings = ((UIElement)senderAsDO).CommandBindingsInternal;
            }
            else if (InputElement.IsContentElement(senderAsDO))
            {
                commandBindings = ((ContentElement)senderAsDO).CommandBindingsInternal;
            }
            else if (InputElement.IsUIElement3D(senderAsDO))
            {
                commandBindings = ((UIElement3D)senderAsDO).CommandBindingsInternal;
            }
            if (commandBindings != null)
            {
                FindCommandBinding(commandBindings, sender, e, command, execute);
            }

            // If no command binding is found, check class command bindings
            // First find the relevant command bindings, under the lock.
            // Most of the time there are no such bindings;  most of the rest of
            // the time there is only one.   Lazy-allocate with this in mind.
            Tuple <Type, CommandBinding>         tuple = null; // zero or one binding
            List <Tuple <Type, CommandBinding> > list  = null; // more than one

            lock (_classCommandBindings.SyncRoot)
            {
                // Check from the current type to all the base types
                Type classType = sender.GetType();
                while (classType != null)
                {
                    CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection;
                    if (classCommandBindings != null)
                    {
                        int index = 0;
                        while (true)
                        {
                            CommandBinding commandBinding = classCommandBindings.FindMatch(command, ref index);
                            if (commandBinding != null)
                            {
                                if (tuple == null)
                                {
                                    tuple = new Tuple <Type, CommandBinding>(classType, commandBinding);
                                }
                                else
                                {
                                    if (list == null)
                                    {
                                        list = new List <Tuple <Type, CommandBinding> >();
                                        list.Add(tuple);
                                    }
                                    list.Add(new Tuple <Type, CommandBinding>(classType, commandBinding));
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    classType = classType.BaseType;
                }
            }

            // execute the bindings.  This can call into user code, so it must
            // be done outside the lock to avoid deadlock.
            if (list != null)
            {
                // more than one binding
                ExecutedRoutedEventArgs   exArgs    = execute ? (ExecutedRoutedEventArgs)e : null;
                CanExecuteRoutedEventArgs canExArgs = execute ? null : (CanExecuteRoutedEventArgs)e;
                for (int i = 0; i < list.Count; ++i)
                {
                    // invoke the binding
                    if ((execute && ExecuteCommandBinding(sender, exArgs, list[i].Item2)) ||
                        (!execute && CanExecuteCommandBinding(sender, canExArgs, list[i].Item2)))
                    {
                        // if it succeeds, advance past the remaining bindings for this type
                        Type classType = list[i].Item1;
                        while (++i < list.Count && list[i].Item1 == classType)
                        {
                            // no body needed
                        }
                        --i;    // back up, so that the outer for-loop advances to the right place
                    }
                }
            }
            else if (tuple != null)
            {
                // only one binding
                if (execute)
                {
                    ExecuteCommandBinding(sender, (ExecutedRoutedEventArgs)e, tuple.Item2);
                }
                else
                {
                    CanExecuteCommandBinding(sender, (CanExecuteRoutedEventArgs)e, tuple.Item2);
                }
            }
        }
Example #20
0
 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);
     }
 }
Example #21
0
        private static void FindCommandBinding(object sender, RoutedEventArgs e, ICommand command, bool execute)
        {
            // Check local command bindings
            CommandBindingCollection commandBindings = sender switch
            {
                UIElement uiElement => uiElement.CommandBindingsInternal,
                ContentElement contentElement => contentElement.CommandBindingsInternal,
                UIElement3D uiElement3d => uiElement3d.CommandBindingsInternal,
                                     _ => default
            };

            if (commandBindings is not null)
            {
                FindCommandBinding(commandBindings, sender, e, command, execute);
            }

            Type senderType = sender.GetType();

            // If no command binding is found, check class command bindings
            // First find the relevant command bindings, under the lock.
            // Most of the time there are no such bindings;  most of the rest of
            // the time there is only one.   Lazy-allocate with this in mind.
            ValueTuple <Type, CommandBinding>?        tuple = default; // zero or one binding
            List <ValueTuple <Type, CommandBinding> > list  = default; // more than one

            lock (_classCommandBindings.SyncRoot)
            {
                // Check from the current type to all the base types
                Type classType = senderType;
                while (classType is not null)
                {
                    if (_classCommandBindings[classType] is CommandBindingCollection classCommandBindings)
                    {
                        int index = 0;
                        while (true)
                        {
                            CommandBinding commandBinding = classCommandBindings.FindMatch(command, ref index);
                            if (commandBinding is null)
                            {
                                break;
                            }

                            if (tuple is null)
                            {
                                tuple = ValueTuple.Create(classType, commandBinding);
                            }
                            else
                            {
                                list ??= new List <ValueTuple <Type, CommandBinding> >(8)
                                {
                                    // We know that tuple cannot be null here
                                    tuple.Value
                                };
                                list.Add(new ValueTuple <Type, CommandBinding>(classType, commandBinding));
                            }
                        }
                    }
                    classType = classType.BaseType;
                }
            }

            // execute the bindings.  This can call into user code, so it must
            // be done outside the lock to avoid deadlock.
            if (list is not null)
            {
                // more than one binding
                ExecutedRoutedEventArgs exArgs = execute ? (ExecutedRoutedEventArgs)e : default;

                CanExecuteRoutedEventArgs canExArgs = execute ? default : (CanExecuteRoutedEventArgs)e;
                                                      for (int i = 0; i < list.Count; ++i)
                                                      {
                                                          // invoke the binding
                                                          if ((!execute || !ExecuteCommandBinding(sender, exArgs, list[i].Item2)) &&
                                                              (execute || !CanExecuteCommandBinding(sender, canExArgs, list[i].Item2)))
                                                          {
                                                              continue;
                                                          }
                                                          // if it succeeds, advance past the remaining bindings for this type
                                                          Type classType = list[i].Item1;
                                                          while (++i < list.Count && list[i].Item1 == classType)
                                                          {
                                                              // no body needed
                                                          }
                                                          --i; // back up, so that the outer for-loop advances to the right place
                                                      }
            }
            else if (tuple is var(_, commandBinding))
            {
                // only one binding
                if (execute)
                {
                    ExecuteCommandBinding(sender, (ExecutedRoutedEventArgs)e, commandBinding);
                }
                else
                {
                    CanExecuteCommandBinding(sender, (CanExecuteRoutedEventArgs)e, commandBinding);
                }
            }
        }
		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));
		}
        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;
                                }));
                    }
                }
            }
        }
Example #24
0
		public void RegisterCommands(CommandBindingCollection commandBindings)
		{
			handler.RegisterGlobalCommands(commandBindings);
		}
 /// <summary>
 ///   Initializes a new instance of the <see cref="ViewModelBase"/> class.
 /// </summary>
 /// 
 public ViewModelBase()
 {
     dispatcher = Dispatcher.CurrentDispatcher;
     commandBindings = new CommandBindingCollection();
 }
Example #26
0
 private static void FindCommandBinding(CommandBindingCollection commandBindings, object sender, RoutedEventArgs e, ICommand command, bool execute)
 {
     int index = 0;
     while (true)
     {
         CommandBinding commandBinding = commandBindings.FindMatch(command, ref index);
         if ((commandBinding == null) ||
             (execute && ExecuteCommandBinding(sender, (ExecutedRoutedEventArgs)e, commandBinding)) ||
             (!execute && CanExecuteCommandBinding(sender, (CanExecuteRoutedEventArgs)e, commandBinding)))
         {
             break;
         }
     }
 }
        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();
        }
        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));
        }
 // 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);
 }
Example #30
0
        /// <summary>
        ///     Scans input and command bindings for matching gestures and executes the appropriate command
        /// </summary>
        /// <remarks>
        ///     Scans for command to execute in the following order:
        ///     - input bindings associated with the targetElement instance
        ///     - input bindings associated with the targetElement class
        ///     - command bindings associated with the targetElement instance
        ///     - command bindings associated with the targetElement class
        /// </remarks>
        /// <param name="targetElement">UIElement/ContentElement to be scanned for input and command bindings</param>
        /// <param name="inputEventArgs">InputEventArgs to be matched against for gestures</param>
        internal static void TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
        {
            if ((targetElement == null) || (inputEventArgs == null))
            {
                return;
            }

            ICommand      command   = null;
            IInputElement target    = null;
            object        parameter = null;

            // Determine UIElement/ContentElement/Neither type
            DependencyObject targetElementAsDO = targetElement as DependencyObject;
            bool             isUIElement       = InputElement.IsUIElement(targetElementAsDO);
            bool             isContentElement  = !isUIElement && InputElement.IsContentElement(targetElementAsDO);
            bool             isUIElement3D     = !isUIElement && !isContentElement && InputElement.IsUIElement3D(targetElementAsDO);

            // Step 1: Check local input bindings
            InputBindingCollection localInputBindings = null;

            if (isUIElement)
            {
                localInputBindings = ((UIElement)targetElement).InputBindingsInternal;
            }
            else if (isContentElement)
            {
                localInputBindings = ((ContentElement)targetElement).InputBindingsInternal;
            }
            else if (isUIElement3D)
            {
                localInputBindings = ((UIElement3D)targetElement).InputBindingsInternal;
            }
            if (localInputBindings != null)
            {
                InputBinding inputBinding = localInputBindings.FindMatch(targetElement, inputEventArgs);
                if (inputBinding != null)
                {
                    command   = inputBinding.Command;
                    target    = inputBinding.CommandTarget;
                    parameter = inputBinding.CommandParameter;
                }
            }

            // Step 2: If no command, check class input bindings
            if (command == null)
            {
                lock (_classInputBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        InputBindingCollection classInputBindings = _classInputBindings[classType] as InputBindingCollection;
                        if (classInputBindings != null)
                        {
                            InputBinding inputBinding = classInputBindings.FindMatch(targetElement, inputEventArgs);
                            if (inputBinding != null)
                            {
                                command   = inputBinding.Command;
                                target    = inputBinding.CommandTarget;
                                parameter = inputBinding.CommandParameter;
                                break;
                            }
                        }
                        classType = classType.BaseType;
                    }
                }
            }

            // Step 3: If no command, check local command bindings
            if (command == null)
            {
                // Check for the instance level ones Next
                CommandBindingCollection localCommandBindings = null;
                if (isUIElement)
                {
                    localCommandBindings = ((UIElement)targetElement).CommandBindingsInternal;
                }
                else if (isContentElement)
                {
                    localCommandBindings = ((ContentElement)targetElement).CommandBindingsInternal;
                }
                else if (isUIElement3D)
                {
                    localCommandBindings = ((UIElement3D)targetElement).CommandBindingsInternal;
                }
                if (localCommandBindings != null)
                {
                    command = localCommandBindings.FindMatch(targetElement, inputEventArgs);
                }
            }

            // Step 4: If no command, look at class command bindings
            if (command == null)
            {
                lock (_classCommandBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection;
                        if (classCommandBindings != null)
                        {
                            command = classCommandBindings.FindMatch(targetElement, inputEventArgs);
                            if (command != null)
                            {
                                break;
                            }
                        }
                        classType = classType.BaseType;
                    }
                }
            }

            // Step 5: If found a command, then execute it (unless it is
            // the special "NotACommand" command, which we simply ignore without
            // setting Handled=true, so that the input bubbles up to the parent)
            if (command != null && command != ApplicationCommands.NotACommand)
            {
                // We currently do not support declaring the element with focus as the target
                // element by setting target == null.  Instead, we interpret a null target to indicate
                // the element that we are routing the event through, e.g. the targetElement parameter.
                if (target == null)
                {
                    target = targetElement;
                }

                bool continueRouting = false;

                RoutedCommand routedCommand = command as RoutedCommand;
                if (routedCommand != null)
                {
                    if (routedCommand.CriticalCanExecute(parameter,
                                                         target,
                                                         inputEventArgs.UserInitiated /*trusted*/,
                                                         out continueRouting))
                    {
                        // If the command can be executed, we never continue to route the
                        // input event.
                        continueRouting = false;

                        ExecuteCommand(routedCommand, parameter, target, inputEventArgs);
                    }
                }
                else
                {
                    if (command.CanExecute(parameter))
                    {
                        command.Execute(parameter);
                    }
                }

                // If we mapped an input event to a command, we should always
                // handle the input event - regardless of whether the command
                // was executed or not.  Unless the CanExecute handler told us
                // to continue the route.
                inputEventArgs.Handled = !continueRouting;
            }
        }
 public static void SetRegisterCommandBindings(DependencyObject obj, CommandBindingCollection value)
 {
     obj.SetValue(RegisterCommandBindingsProperty, value);
 }
Example #32
0
        /// <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)));
        }
Example #33
0
 public ViewModelBase()
 {
     _commandBindings = new CommandBindingCollection();
 }
        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;
                            }));
                }
            }
        }
Example #35
0
        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)));
        }
Example #36
0
		static void Remove(CommandBindingCollection bindings, ICommand cmd) {
			for (int i = bindings.Count - 1; i >= 0; i--) {
				var b = bindings[i];
				if (b.Command == cmd)
					bindings.RemoveAt(i);
			}
		}
Example #37
0
 public static void SetRegisterCommandBindings(DependencyObject element, CommandBindingCollection value)
 {
     if (element != null)
         element.SetValue(RegisterCommandBindingsProperty, value);
 }