Esempio n. 1
1
        private void AddCustomCommandAction(OpenStreetMapProvider provider, string poi)
        {
            string commandText = string.Format("Find {0}", poi);
            string commandName = string.Format("Find{0}Command", poi);

            CommandDescription commandDescription = new CommandDescription();
            commandDescription.Command = new RoutedUICommand(commandText, commandName, typeof(OpenStreetMapProvider));
            commandDescription.CommandParameter = poi;
            commandDescription.DataTemplate = this.LayoutRoot.Resources["CustomCommandDataTemplate"] as DataTemplate;

            string imagePath = string.Format(ImagePathFormat, poi);
            commandDescription.ImageUri = new Uri(imagePath, UriKind.RelativeOrAbsolute);

            CommandBinding commandBinding = new CommandBinding(commandDescription.Command, ExecuteCustomCommand);
            provider.Commands.Add(commandDescription);
            provider.CommandBindingCollection.Add(commandBinding);
        }
Esempio n. 2
0
        private void Initialize()
        {
            InitializeComponent();
            CommandBinding commandBinding = new CommandBinding();

            commandBinding.Command   = ApplicationCommands.Close;
            commandBinding.Executed += CloseCmd_Executed;
            uinf_close.CommandBindings.Add(commandBinding);

            CommandBinding commandBinding1 = new CommandBinding();

            commandBinding1.Command   = ApplicationCommands.Save;
            commandBinding1.Executed += SaveCmd_Executed;
            uinf_save.CommandBindings.Add(commandBinding1);

            CommandBinding commandBindingDelete = new CommandBinding();

            commandBindingDelete.Command   = ApplicationCommands.Delete;
            commandBindingDelete.Executed += DeleteCmd_Executed;
            uinf_delete.CommandBindings.Add(commandBindingDelete);
        }
Esempio n. 3
0
        public MainWindow()
        {
            InitializeComponent();

            shape            = new Shape();
            data.DataContext = shape;
            bg_tb.Background = new SolidColorBrush(shape.BackgroundColor);
            sc_tb.Background = new SolidColorBrush(shape.StrokeColor);

            CommandBinding bindingSave = new CommandBinding(ApplicationCommands.Save);

            bindingSave.Executed   += Save_Executed;
            bindingSave.CanExecute += Save_CanExecute;
            this.CommandBindings.Add(bindingSave);

            CommandBinding bindingOpen = new CommandBinding(ApplicationCommands.Open);

            bindingOpen.Executed   += Open_Executed;
            bindingOpen.CanExecute += Open_CanExecute;
            this.CommandBindings.Add(bindingOpen);
        }
Esempio n. 4
0
        public MainViewModel()
        {
            if (_mvm == null)
            {
                _mvm = this;
            }
            // Commands initialisieren
            TextChangedCommand = new RelayCommand(TextChangedExecute, TextChangedCanExecute);

            // CommandBindings erzeugen
            _saveCommandBinding   = new CommandBinding(ApplicationCommands.Save, SaveExecuted, SaveCanExecute);
            _saveAsCommandBinding = new CommandBinding(ApplicationCommands.SaveAs, SaveAsExecuted, SaveAsCanExecute);
            _openCommandBinding   = new CommandBinding(ApplicationCommands.Open, OpenExecuted, OpenCanExecute);
            _printCommandBinding  = new CommandBinding(ApplicationCommands.Print, PrintExecuted, PrintCanExecute);
            _closeCommandBinding  = new CommandBinding(ApplicationCommands.Close, CloseExecuted, CloseCanExecuted);

            //Standardwerte setzen
            _defaultPath    = Properties.Settings.Default.LoadDefoldPath;
            _saveEdidedPath = Properties.Settings.Default.SaveEditedSongPath;
            _maxSonglines   = Properties.Settings.Default.MaxDisplaySonglines;
        }
        private MenuItem BuildScriptWpdcMenuItem(DatabaseMenuCommandParameters databaseMenuCommandParameters,
                                                 CommandBinding scriptDcCommandBinding, DatabaseType dbType)
        {
            var scriptWpdcMenuItem = new MenuItem
            {
                Header           = "Add Windows Phone DataContext to current Project...",
                Icon             = ImageHelper.GetImageFromResource("../resources/Schema_16xLG.png"),
                Command          = DatabaseMenuCommands.DatabaseCommand,
                CommandParameter = databaseMenuCommandParameters,
                Tag = false
            };

            scriptWpdcMenuItem.CommandBindings.Add(scriptDcCommandBinding);
            scriptWpdcMenuItem.IsEnabled = Helpers.RepositoryHelper.IsV35Installed() &&
                                           Helpers.RepositoryHelper.IsV35DbProviderInstalled();
            if (dbType != DatabaseType.SQLCE35)
            {
                scriptWpdcMenuItem.IsEnabled = false;
            }
            return(scriptWpdcMenuItem);
        }
        public ContentViewerPane()
        {
            InitializeComponent();

            SyntaxHighlightingHelper.RegisterHightingExtensions();

            // set the Syntax Highlighting definitions
            LanguageBox.ItemsSource = HighlightingManager.Instance.HighlightingDefinitions;

            // disable unnecessary editor features
            contentBox.Options.CutCopyWholeLine       = false;
            contentBox.Options.EnableEmailHyperlinks  = false;
            contentBox.Options.EnableHyperlinks       = false;
            contentBox.TextArea.SelectionCornerRadius = 0;

#pragma warning disable CS0618 // Type or member is obsolete
            var searchInput = new SearchInputHandler(contentBox.TextArea);
#pragma warning restore CS0618 // Type or member is obsolete
            _findCommand = searchInput.CommandBindings.FirstOrDefault(binding => binding.Command == ApplicationCommands.Find);
            contentBox.TextArea.DefaultInputHandler.NestedInputHandlers.Add(searchInput);
        }
Esempio n. 7
0
        internal static CommandBinding CreateComplexNormalBinding(
            string name,
            Action <KeyInput> action,
            CommandFlags flags = CommandFlags.None)
        {
            Func <KeyInput, BindResult <NormalCommand> > func = keyInput =>
            {
                action(keyInput);
                return(BindResult <NormalCommand> .NewComplete(NormalCommand.NewPutAfterCaret(false)));
            };

            var bindData = new BindData <NormalCommand>(
                KeyRemapMode.None,
                func.ToFSharpFunc());
            var bindDataStorage = BindDataStorage <NormalCommand> .NewSimple(bindData);

            return(CommandBinding.NewComplexNormalBinding(
                       KeyNotationUtil.StringToKeyInputSet(name),
                       flags,
                       bindDataStorage));
        }
Esempio n. 8
0
        public CrossPanel()
        {
            //  Do :定位到中心位置
            {
                CommandBinding binding = new CommandBinding(CommandService.Selected);

                this.CommandBindings.Add(binding);

                binding.Executed += (l, k) =>
                {
                    if (k.Parameter is UIElement element)
                    {
                        int index = this.Children.IndexOf(element);

                        this.StartIndex = index;
                    }
                };

                binding.CanExecute += (l, k) => { k.CanExecute = true; };
            }
        }
Esempio n. 9
0
        private static void SetCommandBinding()
        {
            CommandBinding Cb1         = new CommandBinding(Cmd1, RunCommand);
            CommandBinding Cb2         = new CommandBinding(Cmd2, RunCommand);
            CommandBinding Cb3         = new CommandBinding(Cmd3, RunCommand);
            CommandBinding Cb4         = new CommandBinding(Cmd4, RunCommand);
            CommandBinding Cb5         = new CommandBinding(Cmd5, RunCommand);
            CommandBinding Cb6         = new CommandBinding(Cmd6, RunCommand);
            CommandBinding Cb7         = new CommandBinding(Cmd7, RunCommand);
            CommandBinding Cb8         = new CommandBinding(Cmd8, RunCommand);
            CommandBinding Cb9         = new CommandBinding(Cmd9, RunCommand);
            CommandBinding Cb0         = new CommandBinding(Cmd0, RunCommand);
            CommandBinding CbDot       = new CommandBinding(CmdDot, RunCommand);
            CommandBinding CbBackspace = new CommandBinding(CmdBackspace, RunCommand);


            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb1);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb2);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb3);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb4);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb5);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb6);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb7);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb8);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb9);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), Cb0);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), CbDot);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), CbBackspace);


            CommandBinding CbEnter = new CommandBinding(CmdEnter, RunCommand);

            CommandBinding CbClear = new CommandBinding(CmdClear, RunCommand);
            CommandBinding CbClose = new CommandBinding(CmdClose, RunCommand);

            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), CbEnter);

            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), CbClear);
            CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeypad), CbClose);
        }
Esempio n. 10
0
        public MainWindow()
        {
            InitializeComponent();
            AddDoubleClickEventStyle(lbUsers, dGSerials_MouseDoubleClick);
            ResourceDictionary myResourceDictionary = new ResourceDictionary();

            myResourceDictionary.Source = new Uri("Styles.xaml", UriKind.Relative);
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);

            try
            {
                LogIn dialog = new LogIn();
                if (dialog.ShowDialog() == true)
                {
                    client = new ChatClient(dialog.username.Text, "127.0.0.1", 11000, this);
                    client.Connect();

                    AddLobbyTab();
                    lbUsers.ItemsSource    = client.users;
                    client.PrivateMessage += PrivateMessageHandler;
                    client.ReciveMessageAsync();
                }
                else
                {
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.Close();
            }

            CommandBinding binding = new CommandBinding(Commands.SendMessageCommand);

            binding.CanExecute += binding_CanExecute;
            binding.Executed   += binding_Executed;
            this.CommandBindings.Add(binding);
            btnSend.Command = Commands.SendMessageCommand;
        }
        public MainWindow()
        {
            InitializeComponent();
            CommandBinding btnLoadGifCommandBinding = new CommandBinding();

            btnLoadGifCommandBinding.Command   = ApplicationCommands.Open;
            btnLoadGifCommandBinding.Executed += BtnLoadGifCommandBinding_Executed;
            btnLoadGif.CommandBindings.Add(btnLoadGifCommandBinding);

            CommandBinding btnLoadGifCommandBinding_B = new CommandBinding();

            btnLoadGifCommandBinding_B.Command   = ApplicationCommands.Open;
            btnLoadGifCommandBinding_B.Executed += BtnLoadGifCommandBinding_B_Executed;
            btnLoadGif_B.CommandBindings.Add(btnLoadGifCommandBinding_B);

            CommandBinding btnLoadFileCommandBinding = new CommandBinding();

            btnLoadFileCommandBinding.Command   = ApplicationCommands.Open;
            btnLoadFileCommandBinding.Executed += BtnLoadFileCommandBinding_Executed;
            btnLoadFile.CommandBindings.Add(btnLoadFileCommandBinding);

            CommandBinding saveButtonCommandBinding = new CommandBinding();

            saveButtonCommandBinding.Command   = ApplicationCommands.Save;
            saveButtonCommandBinding.Executed += SaveButtonCommandBinding_Executed;
            btnSave.CommandBindings.Add(saveButtonCommandBinding);

            CommandBinding saveButtonCommandBinding_B = new CommandBinding();

            saveButtonCommandBinding_B.Command   = ApplicationCommands.Save;
            saveButtonCommandBinding_B.Executed += SaveButtonCommandBinding_B_Executed;
            btnSave_B.CommandBindings.Add(saveButtonCommandBinding_B);

            CommandBinding exitButtonCommandBinding = new CommandBinding();

            exitButtonCommandBinding.Command   = ApplicationCommands.Close;
            exitButtonCommandBinding.Executed += ExitButtonCommandBinding_Executed;
            btnExit.CommandBindings.Add(exitButtonCommandBinding);
            btnExit_B.CommandBindings.Add(exitButtonCommandBinding);
        }
Esempio n. 12
0
        static SearchUI()
        {
            Type ownerType = typeof(SearchUI);

            DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));

            InputGestureCollection findGestures = new InputGestureCollection();

            findGestures.Add(new KeyGesture(Key.F3));

            InputGestureCollection replaceNextGestures = new InputGestureCollection();

            replaceNextGestures.Add(new KeyGesture(Key.R, ModifierKeys.Alt));

            InputGestureCollection replaceAllGestures = new InputGestureCollection();

            replaceAllGestures.Add(new KeyGesture(Key.A, ModifierKeys.Alt));

            InputGestureCollection closeGestures = new InputGestureCollection();

            closeGestures.Add(new KeyGesture(Key.Escape));

            FindCommand        = new RoutedCommand("FindCommand", ownerType, findGestures);
            ReplaceNextCommand = new RoutedCommand("ReplaceNextCommand", ownerType, replaceNextGestures);
            ReplaceAllCommand  = new RoutedCommand("ReplaceAllCommand", ownerType, replaceAllGestures);
            ToggleModeCommand  = new RoutedCommand("ToggleModeCommand", ownerType);
            CloseCommand       = new RoutedCommand("CloseCommand", ownerType, closeGestures);

            CommandBinding find        = new CommandBinding(FindCommand, FindExecuted);
            CommandBinding replaceNext = new CommandBinding(ReplaceNextCommand, ReplaceNextExecuted);
            CommandBinding replaceAll  = new CommandBinding(ReplaceAllCommand, ReplaceAllExecuted);
            CommandBinding toggle      = new CommandBinding(ToggleModeCommand, ToggleModeExecuted);
            CommandBinding close       = new CommandBinding(CloseCommand, CloseExecuted);

            CommandManager.RegisterClassCommandBinding(ownerType, find);
            CommandManager.RegisterClassCommandBinding(ownerType, replaceNext);
            CommandManager.RegisterClassCommandBinding(ownerType, replaceAll);
            CommandManager.RegisterClassCommandBinding(ownerType, toggle);
            CommandManager.RegisterClassCommandBinding(ownerType, close);
        }
Esempio n. 13
0
        public void InitializeCommands()
        {
            var nextCommand = new CommandBinding(DataCommands.NextRecord,
                                                 OnNextRecord);

            commandBindings.Add(nextCommand);


            //      var previousCommand = new CommandBinding(DataCommands.PreviousRecord,
            //          OnPreviousRecord);
            //    commandBindings.Add(previousCommand);

            //       var firstCommand = new CommandBinding(DataCommands.FirstRecord,
            //         OnFirstRecord);
            //    commandBindings.Add(firstCommand);

            //var previousCommand = new CommandBinding(DataCommands.PreviousRecord,
            //   OnPreviousRecord);
            //commandBindings.Add(previousCommand);

            //var firstCommand = new CommandBinding(DataCommands.FirstRecord,
            //    OnFirstRecord);
            //commandBindings.Add(firstCommand);

            //var previousCommand = new CommandBinding(DataCommands.PreviousRecord,
            //   OnPreviousRecord);
            //commandBindings.Add(previousCommand);

            //var firstCommand = new CommandBinding(DataCommands.FirstRecord,
            //    OnFirstRecord);
            //commandBindings.Add(firstCommand);

            //var previousCommand = new CommandBinding(DataCommands.PreviousRecord,
            //   OnPreviousRecord);
            //commandBindings.Add(previousCommand);

            //var firstCommand = new CommandBinding(DataCommands.FirstRecord,
            //    OnFirstRecord);
            //commandBindings.Add(firstCommand);
        }
        public SlidingTableDataInputDialog(Fanuc fanuc, PmcBomItem pmc, LimitBomItem limit, string title)
        {
            InitializeComponent();
            this.DataContext = new SlidingTableDataInputDialogViewModel(fanuc, pmc, limit, title);

            this.inputdata.Focus();

            CommandBinding Cb0         = new CommandBinding(_Cmd0, RunCommand_0);
            CommandBinding Cb1         = new CommandBinding(_Cmd1, RunCommand_1);
            CommandBinding Cb2         = new CommandBinding(_Cmd2, RunCommand_2);
            CommandBinding Cb3         = new CommandBinding(_Cmd3, RunCommand_3);
            CommandBinding Cb4         = new CommandBinding(_Cmd4, RunCommand_4);
            CommandBinding Cb5         = new CommandBinding(_Cmd5, RunCommand_5);
            CommandBinding Cb6         = new CommandBinding(_Cmd6, RunCommand_6);
            CommandBinding Cb7         = new CommandBinding(_Cmd7, RunCommand_7);
            CommandBinding Cb8         = new CommandBinding(_Cmd8, RunCommand_8);
            CommandBinding Cb9         = new CommandBinding(_Cmd9, RunCommand_9);
            CommandBinding CbShortLine = new CommandBinding(_CmdShortLine, RunCommand_ShortLine);
            CommandBinding CbPoint     = new CommandBinding(_CmdPoint, RunCommand_Point);
            CommandBinding CbBackSpace = new CommandBinding(_CmdBackSpace, RunCommand_BackSpace);

            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb0);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb1);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb2);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb3);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb4);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb5);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb6);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb7);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb8);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), Cb9);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), CbShortLine);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), CbPoint);
            CommandManager.RegisterClassCommandBinding(typeof(SlidingTableDataInputDialog), CbBackSpace);

            Messenger.Default.Register <bool>(this, "SlidingTableDataInputDialogQuitMsg", msg =>
            {
                this.Close();
            });
        }
Esempio n. 15
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static NetworkView()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(NetworkView), new FrameworkPropertyMetadata(typeof(NetworkView)));

            InputGestureCollection inputs = new InputGestureCollection();

            inputs.Add(new KeyGesture(Key.A, ModifierKeys.Control));
            SelectAllCommand = new RoutedCommand("SelectAll", typeof(NetworkView), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.Escape));
            SelectNoneCommand = new RoutedCommand("SelectNone", typeof(NetworkView), inputs);

            inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.I, ModifierKeys.Control));
            InvertSelectionCommand = new RoutedCommand("InvertSelection", typeof(NetworkView), inputs);

            CancelConnectionDraggingCommand = new RoutedCommand("CancelConnectionDragging", typeof(NetworkView));

            CommandBinding binding = new CommandBinding();

            binding.Command   = SelectAllCommand;
            binding.Executed += new ExecutedRoutedEventHandler(SelectAll_Executed);
            CommandManager.RegisterClassCommandBinding(typeof(NetworkView), binding);

            binding           = new CommandBinding();
            binding.Command   = SelectNoneCommand;
            binding.Executed += new ExecutedRoutedEventHandler(SelectNone_Executed);
            CommandManager.RegisterClassCommandBinding(typeof(NetworkView), binding);

            binding           = new CommandBinding();
            binding.Command   = InvertSelectionCommand;
            binding.Executed += new ExecutedRoutedEventHandler(InvertSelection_Executed);
            CommandManager.RegisterClassCommandBinding(typeof(NetworkView), binding);

            binding           = new CommandBinding();
            binding.Command   = CancelConnectionDraggingCommand;
            binding.Executed += new ExecutedRoutedEventHandler(CancelConnectionDragging_Executed);
            CommandManager.RegisterClassCommandBinding(typeof(NetworkView), binding);
        }
Esempio n. 16
0
        public Explorer()
        {
            {
                CommandBinding binding = new CommandBinding(Next, (l, k) =>
                {
                    int index = this.History.IndexOf(HistorySelectedItem);

                    //this.RefreshPath(this.History[index + 1]?.Model.FullName);

                    this.HistorySelectedItem = this.History[index + 1];
                }, (l, k) =>
                {
                    int index = this.History.IndexOf(HistorySelectedItem);

                    k.CanExecute = index < this.History.Count - 1;
                });

                this.CommandBindings.Add(binding);
            }

            {
                CommandBinding binding = new CommandBinding(Previous, (l, k) =>
                {
                    int index = this.History.IndexOf(HistorySelectedItem);

                    //this.RefreshPath(this.History[index - 1]?.Model.FullName);

                    this.HistorySelectedItem = this.History[index - 1];
                }, (l, k) =>
                {
                    int index = this.History.IndexOf(HistorySelectedItem);

                    k.CanExecute = index > 0;
                });

                this.CommandBindings.Add(binding);
            }

            this.RefreshPath(null);
        }
        /// <summary>
        /// Initializes MetadataWindow with given data
        /// </summary>
        /// <param name="metadata">data to show in window</param>
        public MetadataWindow(Metadata metadata)
        {
            InitializeComponent();

            if (metadata == null)
            {
                return;
            }

            string textContent = "";

            if (metadata.Sysno != null)
            {
                textContent += "SYSNO\t" + metadata.Sysno + "\n";
            }

            foreach (var fixfield in metadata.FixedFields)
            {
                textContent += fixfield.Key + "\t" + fixfield.Value + "\n";
            }
            foreach (var varfield in metadata.VariableFields)
            {
                textContent += varfield.TagName + varfield.Indicator1 + varfield.Indicator2 + "\t";
                foreach (var sf in varfield.Subfields)
                {
                    textContent += " |" + sf.Key + " " + sf.Value;
                }
                textContent += "\n";
            }
            this.metadataLabel.Text = textContent;

            // close on Esc
            CommandBinding cb = new CommandBinding(closeCommand, CloseExecuted, CloseCanExecute);

            this.CommandBindings.Add(cb);
            KeyGesture   kg = new KeyGesture(Key.Escape);
            InputBinding ib = new InputBinding(closeCommand, kg);

            this.InputBindings.Add(ib);
        }
        public ColorPickerDialog()
        {
            InitializeComponent();
            SelectedColors.ItemsSource = __SavedColors;
            CommandBinding cb = new CommandBinding(ColorPicker.AddToSelected);

            cb.Executed   += new ExecutedRoutedEventHandler(AddToSelected);
            cb.CanExecute += new CanExecuteRoutedEventHandler(CanAddToSelected);
            CommandBindings.Add(cb);

            cb             = new CommandBinding(ColorPickerDialog.RemoveColorCommand);
            cb.Executed   += new ExecutedRoutedEventHandler(RemoveColor);
            cb.CanExecute += new CanExecuteRoutedEventHandler(CanExecuteAlways);
            CommandBindings.Add(cb);

            cb             = new CommandBinding(ColorPickerDialog.RemoveAllColorsCommand);
            cb.Executed   += new ExecutedRoutedEventHandler(RemoveAllColors);
            cb.CanExecute += new CanExecuteRoutedEventHandler(CanExecuteAlways);
            CommandBindings.Add(cb);

            SelectedColors.Focus();
        }
Esempio n. 19
0
        private void InitalizeCommand()
        {
            ////把命令赋值给命令源(发送者)并指定快捷键
            button1.Command = this.clearCmd;

            //声明键盘命令Alt+C
            clearCmd.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Alt));

            //指定目标
            button1.CommandTarget = textBoxA;

            ////创建命令关联
            CommandBinding cb = new CommandBinding();

            cb.Command     = clearCmd;
            cb.CanExecute += new CanExecuteRoutedEventHandler(cb_CanExecute);;
            cb.Executed   += new ExecutedRoutedEventHandler(cb_Executed);

            ////把命令关联安置在外围控件上
            ////标志着Stackpanel范围内按动Alt+C 均能将textBoxA清空
            stackPanel.CommandBindings.Add(cb);
        }
Esempio n. 20
0
        public MainWindow()
        {
            try
            {
                InitializeComponent();

                //ICodeStash3ViewModel viewModelIF = new CodeStash3ViewModel();
                this.DataContext = viewModelIF;
                CommandBinding binding = new CommandBinding(ApplicationCommands.New);
                //binding.Executed += viewModelIF.AddCommand;
                binding.Executed += AddCommand;
                this.CommandBindings.Add(binding);
                codeChanged       = false;
                codeCanChange     = false;
                languageChanged   = false;
                languageCanChange = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong");
            }
        }
Esempio n. 21
0
        public FlowWorkspace(MainWindowCommandButtonHandler mainWindowCommandButtonHandler, TabItem writer)
        {
            this.m_MainWindowCommandButtonHandler = mainWindowCommandButtonHandler;
            this.m_Writer         = writer;
            this.m_SystemIdentity = YellowstonePathology.Business.User.SystemIdentity.Instance;

            this.CommandBindingApplicationClosing = new CommandBinding(MainWindow.ApplicationClosingCommand, this.ApplicationClosing);
            this.CommandBindings.Add(this.CommandBindingApplicationClosing);

            this.m_DocumentViewer = new DocumentWorkspace();

            this.m_FlowUI = new YellowstonePathology.Business.Flow.FlowUI(this.m_Writer);

            InitializeComponent();

            this.DataContext = this.m_FlowUI;

            this.tabItemDocumentViewer.Content    = this.m_DocumentViewer;
            this.tabControlFlow.SelectionChanged += new SelectionChangedEventHandler(tabControlFlow_SelectionChanged);

            this.Unloaded += new RoutedEventHandler(FlowWorkspace_Unloaded);
        }
Esempio n. 22
0
        public MainWindow()
        {
            InitializeComponent();
            //creare obiect binding pentru comanda
            CommandBinding cmd1 = new CommandBinding();

            //asociere comanda
            cmd1.Command = ApplicationCommands.Print;
            //asociem un handler
            //input gesture: I + Alt
            ApplicationCommands.Print.InputGestures.Add(
                new KeyGesture(Key.I, ModifierKeys.Alt));
            cmd1.Executed += new ExecutedRoutedEventHandler(CtrlP_CommandHandler);
            //adaugam la colectia CommandBindings
            this.CommandBindings.Add(cmd1);
            CommandBinding cmd2 = new CommandBinding();

            cmd2.Command   = CustomCommands.StopCommand.Launch;
            cmd2.Executed += new
                             ExecutedRoutedEventHandler(CtrlS_CommandHandler);//asociem handler
            this.CommandBindings.Add(cmd2);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            try
            {
                this.InitializeComponent();

                this.txtProxyDetails.Text    = "Starting Azure Proxy";
                this.lstRequests.ItemsSource = this.requestMap;
                CommandBinding cb = new CommandBinding(ApplicationCommands.Copy, this.CopyCmdExecuted, this.CopyCmdCanExecute);
                this.lstRequestHeaders.CommandBindings.Add(cb);
                this.lstResponseHeaders.CommandBindings.Add(cb);
                this.txtRedirectionUrl.Text = TunnelRelayStateManager.ApplicationData.RedirectionUrl;

                this.btnExportSettings.IsEnabled = false;
                this.StartRelayEngine();
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Init failed");
                MessageBox.Show("Failed to start Tunnel relay!!", "Engine start failure", MessageBoxButton.OKCancel, MessageBoxImage.Error);
            }
        }
Esempio n. 24
0
        private void InitializeComponent()
        {
            this.Width = this.Height = 300;
            this.Top   = this.Left = 300;

            var dockPanel = new DockPanel();

            var commandButton = new Button();

            commandButton.Content = "Command Button";
            commandButton.Command = ApplicationCommands.New;

            var commandButton2 = new Button();

            commandButton2.Content          = "Command Button2";
            commandButton2.Command          = ApplicationCommands.New;
            commandButton2.CommandParameter = "10086";

            #region CommandBinding
            CommandBinding commandBinding = new CommandBinding(ApplicationCommands.New);
            commandBinding.Executed += (sender, e) =>
            {
                var button = e.Source as Button;

                MessageBox.Show("Command Test Command." + sender + "\n" + button?.Content);
            };
            this.CommandBindings.Add(commandBinding);


            #endregion

            DockPanel.SetDock(commandButton, Dock.Top);
            DockPanel.SetDock(commandButton2, Dock.Top);

            dockPanel.Children.Add(commandButton);
            dockPanel.Children.Add(commandButton2);

            this.Content = dockPanel;
        }
Esempio n. 25
0
        private void SetCommandBindings()
        {
            CommandBinding cmdBindingNew = new CommandBinding(ApplicationCommands.New);

            cmdBindingNew.Executed += NewCommandHandler;
            CommandBindings.Add(cmdBindingNew);

            CommandBinding cmdBindingOpen = new CommandBinding(ApplicationCommands.Open);

            cmdBindingOpen.Executed += OpenCommandHandler;
            CommandBindings.Add(cmdBindingOpen);

            CommandBinding cmdBindingSave = new CommandBinding(ApplicationCommands.Save);

            cmdBindingSave.Executed += SaveCommandHandler;
            CommandBindings.Add(cmdBindingSave);

            CommandBinding cmdBindingSaveAs = new CommandBinding(ApplicationCommands.SaveAs);

            cmdBindingSaveAs.Executed += SaveAsCommandHandler;
            CommandBindings.Add(cmdBindingSaveAs);
        }
Esempio n. 26
0
        public MainWindow()
        {
            this.InitializeComponent();
            this.Dispatcher.UnhandledException += this.Dispatcher_UnhandledException;
            CommandBinding cb = new CommandBinding(ApplicationCommands.Copy, this.CopyCmdExecuted, this.CopyCmdCanExecute);

            this.ConversationView.ConversationHistory.CommandBindings.Add(cb);
            this.ActivitiesPane.CommandBindings.Add(cb);
            this.ActivityPayloadPane.CommandBindings.Add(cb);
            this.DataContext             = this;
            this.player.PlaybackStopped += this.Player_PlaybackStopped;
            Services.Tracker.Configure(this.settings).Apply();

            this.renderer = new AdaptiveCardRenderer();
            this.renderer.UseXceedElementRenderers();
            var configFile = Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "AdaptiveCardsHostConfig.json");

            if (File.Exists(configFile))
            {
                this.renderer.HostConfig = AdaptiveHostConfig.FromJson(File.ReadAllText(configFile));
            }
        }
Esempio n. 27
0
        void InitializeSplitCommandBinding()
        {
            HorizontalSplitCommand        = new RoutedUICommand("Horizontal Split", "HorizontalSplit", typeof(EventPolygon));
            horizontalSplitCommandBinding = new CommandBinding(
                HorizontalSplitCommand,
                HorizontalSplitExecuted,
                HorizontalSplitCanExecute);

            Polygon.CommandBindings.Add(horizontalSplitCommandBinding);
            Polygon.InputBindings.Add(
                new MouseBinding(HorizontalSplitCommand, new MouseGesture(MouseAction.LeftClick, ModifierKeys.Alt)));

            VerticalSplitCommand        = new RoutedUICommand("Vertical Split", "VerticalSplit", typeof(EventPolygon));
            verticalSplitCommandBinding = new CommandBinding(
                VerticalSplitCommand,
                VerticalSplitExecuted,
                VerticalSplitCanExecute);

            Polygon.CommandBindings.Add(verticalSplitCommandBinding);
            Polygon.InputBindings.Add(
                new MouseBinding(VerticalSplitCommand, new MouseGesture(MouseAction.LeftClick, ModifierKeys.Control | ModifierKeys.Alt)));
        }
        public ClientOrderWorkspace(MainWindowCommandButtonHandler mainWindowCommandButtonHandler, TabItem writer)
        {
            this.m_MainWindowCommandButtonHandler = mainWindowCommandButtonHandler;
            this.m_LoadedHasRun = false;
            this.m_Writer       = writer;

            this.CommandBindingRemoveTab = new CommandBinding(MainWindow.RemoveTabCommand, RemoveTab);
            this.CommandBindings.Add(this.CommandBindingRemoveTab);

            this.m_ClientOrderUI  = new ClientOrderUI(this.m_Writer);
            this.m_DocumentViewer = new DocumentWorkspace();

            this.m_BarcodeScanPort = YellowstonePathology.Business.BarcodeScanning.BarcodeScanPort.Instance;

            InitializeComponent();

            this.TabItemDocumentWorkspace.Content = this.m_DocumentViewer;
            this.DataContext = this.m_ClientOrderUI;

            this.Loaded   += new RoutedEventHandler(ClientOrderWorkspace_Loaded);
            this.Unloaded += new RoutedEventHandler(ClientOrderWorkspace_Unloaded);
        }
        public MainWindow()
        {
            InitializeComponent();

            CommandBinding cutCommand = new CommandBinding(ApplicationCommands.Cut);

            this.CommandBindings.Add(cutCommand);
            cutCommand.Executed += new ExecutedRoutedEventHandler(cutCommand_Executed);

            CommandBinding copyCommand = new CommandBinding(ApplicationCommands.Copy);

            this.CommandBindings.Add(copyCommand);
            copyCommand.Executed += new ExecutedRoutedEventHandler(copyCommand_Executed);

            CommandBinding pasteCommand = new CommandBinding(ApplicationCommands.Paste);

            this.CommandBindings.Add(pasteCommand);
            pasteCommand.Executed += new ExecutedRoutedEventHandler(pasteCommand_Executed);

            CommandBinding newCharCommand = new CommandBinding(ApplicationCommands.New);

            this.CommandBindings.Add(newCharCommand);
            newCharCommand.Executed += new ExecutedRoutedEventHandler(newCharCommand_Executed);

            CommandBinding loadCharCommand = new CommandBinding(ApplicationCommands.Open);

            this.CommandBindings.Add(loadCharCommand);
            loadCharCommand.Executed += new ExecutedRoutedEventHandler(loadCharCommand_Executed);

            CommandBinding quitCommand = new CommandBinding(ApplicationCommands.Close);

            this.CommandBindings.Add(quitCommand);
            quitCommand.Executed += new ExecutedRoutedEventHandler(quitCommand_Executed);

            /// CommandBinding customCommand = new CommandBinding();
            /// this.CommandBindings.Add(customCommand);
            /// customCommand = new CommandBinding(CommandBindings.customCommand);
            /// customCommand.Executed += new ExecutedRoutedEventHandler(customCommand_Executed);
        }
Esempio n. 30
0
        public MainWindow()
        {
            InitializeComponent();
            ObservableCollection <String> lst = new ObservableCollection <string>();

            lst.Add("jen");
            lst.Add("dva");
            lst.Add("tri");
            dg.ItemsSource = lst;

            RoutedUICommand komanda = new RoutedUICommand();
            CommandBinding  cb      = new CommandBinding();

            cb.Executed           += Foo;
            cb.CanExecute         += Test;
            cb.Command             = komanda;
            dugme.Command          = komanda;
            dugme.CommandTarget    = dg;
            dugme.CommandParameter = lst;

            this.CommandBindings.Add(cb);
        }
Esempio n. 31
0
    static void FigureViewBinding(CommandBinding binding)
    {
        var sobj   = new SerializedObject(binding);
        var vcprop = sobj.FindProperty("_target");
        var veprop = sobj.FindProperty("_targetEvent");

        if (string.IsNullOrEmpty(veprop.stringValue))
        {
            return;
        }

        var vcomp = vcprop.objectReferenceValue as Component;

        if (vcomp == null)
        {
            return;
        }

        var @event = PropertyBindingEditor.GetEvent(vcomp, veprop);

        if (@event != null)
        {
            // Fixing adding multiple command binding event handlers when using prefabs
            var eventCount = @event.GetPersistentEventCount();
            for (var idx = 0; idx < eventCount; idx++)
            {
                var perTarget = @event.GetPersistentTarget(idx);
                // if we find a duplicate event skip over adding it
                if (perTarget == binding)
                {
                    return;
                }
            }

            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(@event, binding.ExecuteCommand);
        }

        sobj.ApplyModifiedProperties();
    }
Esempio n. 32
0
		public static void Bind(Entity entity, Main main, Func<BEPUphysics.Entities.Entity, BEPUphysics.Entities.Entity, Vector3, Vector3, Vector3, ISpaceObject> createJoint, bool allowRotation, bool creating = false, bool directional = true)
		{
			Transform mapTransform = entity.GetOrCreate<Transform>("MapTransform");
			mapTransform.Selectable.Value = false;

			Transform transform = entity.GetOrCreate<Transform>("Transform");

			Factory.Get<DynamicVoxelFactory>().InternalBind(entity, main, creating, mapTransform);

			DynamicVoxel map = entity.Get<DynamicVoxel>();

			Components.Joint jointData = entity.GetOrCreate<Components.Joint>("Joint");

			Action refreshMapTransform = delegate()
			{
				Entity parent = jointData.Parent.Value.Target;
				if (parent != null && parent.Active)
				{
					Voxel staticMap = parent.Get<Voxel>();
					jointData.Coord.Value = staticMap.GetCoordinate(transform.Matrix.Value.Translation);
					mapTransform.Position.Value = staticMap.GetAbsolutePosition(staticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset.Value);
					if (allowRotation)
					{
						if (main.EditorEnabled)
							mapTransform.Quaternion.Value = transform.Quaternion;
					}
					else
					{
						Matrix parentOrientation = staticMap.Transform;
						parentOrientation.Translation = Vector3.Zero;
						mapTransform.Quaternion.Value = Quaternion.CreateFromRotationMatrix(parentOrientation);
					}
				}
				else
					mapTransform.Matrix.Value = transform.Matrix;
			};

			if (main.EditorEnabled)
				entity.Add(new NotifyBinding(refreshMapTransform, transform.Matrix, transform.Quaternion, map.Offset, jointData.Parent));

			ISpaceObject joint = null;
			CommandBinding jointDeleteBinding = null, parentPhysicsUpdateBinding = null;
			NotifyBinding parentStaticMoveBinding = null;

			Action updateJoint = null;

			Action rebuildJoint = null;
			rebuildJoint = delegate()
			{
				if (jointDeleteBinding != null)
					entity.Remove(jointDeleteBinding);
				jointDeleteBinding = null;

				if (parentPhysicsUpdateBinding != null)
					entity.Remove(parentPhysicsUpdateBinding);
				parentPhysicsUpdateBinding = null;

				updateJoint();
			};

			updateJoint = delegate()
			{
				if (joint != null)
				{
					if (joint.Space != null)
						main.Space.Remove(joint);
					joint = null;
				}
				if (parentStaticMoveBinding != null)
				{
					entity.Remove(parentStaticMoveBinding);
					parentStaticMoveBinding = null;
				}

				Entity parent = jointData.Parent.Value.Target;

				if (main.EditorEnabled)
					refreshMapTransform();
				else if (parent != null && parent.Active)
				{
					Voxel parentStaticMap = parent.Get<Voxel>();

					//map.PhysicsEntity.Position = mapTransform.Position;
					if (!allowRotation)
						map.PhysicsEntity.Orientation = mapTransform.Quaternion;

					if (jointData.Direction != Direction.None)
					{
						Vector3 relativeLineAnchor = parentStaticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + parentStaticMap.Offset + map.Offset;
						Vector3 lineAnchor = parentStaticMap.GetAbsolutePosition(relativeLineAnchor);
						DynamicVoxel parentDynamicMap = parent.Get<DynamicVoxel>();
						joint = createJoint(map.PhysicsEntity, parentDynamicMap == null ? null : parentDynamicMap.PhysicsEntity, lineAnchor, parentStaticMap.GetAbsoluteVector(jointData.Direction.Value.GetVector()), parentStaticMap.GetAbsolutePosition(jointData.Coord));
						main.Space.Add(joint);
						map.PhysicsEntity.ActivityInformation.Activate();

						if (parentDynamicMap != null && parentPhysicsUpdateBinding == null)
						{
							parentPhysicsUpdateBinding = new CommandBinding(parentDynamicMap.PhysicsUpdated, updateJoint);
							entity.Add(parentPhysicsUpdateBinding);
						}

						if (parentDynamicMap == null && joint is PrismaticJoint)
						{
							parentStaticMoveBinding = new NotifyBinding(delegate()
							{
								PrismaticJoint prismaticJoint = (PrismaticJoint)joint;
								Vector3 a = parentStaticMap.GetAbsolutePosition(relativeLineAnchor);
								prismaticJoint.PointOnLineJoint.LineAnchor = a;
								prismaticJoint.Limit.OffsetA = a;
								prismaticJoint.Motor.OffsetA = a;
							}, parentStaticMap.Transform);
							entity.Add(parentStaticMoveBinding);
						}

						if (jointDeleteBinding == null)
						{
							jointDeleteBinding = new CommandBinding(parent.Delete, delegate()
							{
								jointData.Parent.Value = null;
							});
							entity.Add(jointDeleteBinding);
						}
					}
				}
			};
			entity.Add(new CommandBinding(map.PhysicsUpdated, updateJoint));
			entity.Add(new NotifyBinding(rebuildJoint, jointData.Parent));
			entity.Add(new CommandBinding(entity.Delete, delegate()
			{
				if (joint != null && joint.Space != null)
				{
					main.Space.Remove(joint);
					joint = null;
				}
			}));
			
			entity.Add(new CommandBinding(map.OnSuspended, delegate()
			{
				if (joint != null && joint.Space != null)
					main.Space.Remove(joint);
			}));
			entity.Add(new CommandBinding(map.OnResumed, delegate()
			{
				if (joint != null && joint.Space == null)
					main.Space.Add(joint);
			}));
			
			entity.Add(new PostInitialization(rebuildJoint));

			if (main.EditorEnabled)
				JointFactory.attachEditorComponents(entity, main, directional);
		}
Esempio n. 33
0
		public static void Bind(Entity result, Main main, Func<BEPUphysics.Entities.Entity, BEPUphysics.Entities.Entity, Vector3, Vector3, Vector3, ISpaceObject> createJoint, bool allowRotation, bool creating = false)
		{
			Transform mapTransform = result.GetOrCreate<Transform>("MapTransform");

			Transform transform = result.GetOrCreate<Transform>("Transform");

			Factory.Get<DynamicMapFactory>().InternalBind(result, main, creating, mapTransform);

			DynamicMap map = result.Get<DynamicMap>();

			Property<Entity.Handle> parentMap = result.GetOrMakeProperty<Entity.Handle>("Parent");
			Property<Map.Coordinate> coord = result.GetOrMakeProperty<Map.Coordinate>("Coord");
			Property<Direction> dir = result.GetOrMakeProperty<Direction>("Direction", true);

			Action refreshMapTransform = delegate()
			{
				Entity parent = parentMap.Value.Target;
				if (parent != null)
				{
					if (!parent.Active)
						parent = null;
					else
					{
						Map staticMap = parent.Get<Map>();
						coord.Value = staticMap.GetCoordinate(transform.Position);
						mapTransform.Position.Value = staticMap.GetAbsolutePosition(staticMap.GetRelativePosition(coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset.Value);
						if (!allowRotation)
							mapTransform.Orientation.Value = parent.Get<Transform>().Orientation;
					}
				}
				else
					mapTransform.Matrix.Value = transform.Matrix;
			};
			if (main.EditorEnabled)
				result.Add(new NotifyBinding(refreshMapTransform, transform.Matrix, map.Offset));

			ISpaceObject joint = null;
			CommandBinding jointDeleteBinding = null, physicsUpdateBinding = null, parentPhysicsUpdateBinding = null;

			Action rebuildJoint = null;
			rebuildJoint = delegate()
			{
				if (joint != null)
				{
					if (joint.Space != null)
						main.Space.Remove(joint);
					result.Remove(jointDeleteBinding);

					if (parentPhysicsUpdateBinding != null)
						result.Remove(parentPhysicsUpdateBinding);
					parentPhysicsUpdateBinding = null;

					if (physicsUpdateBinding != null)
						result.Remove(physicsUpdateBinding);
					physicsUpdateBinding = null;

					joint = null;
					jointDeleteBinding = null;
				}

				Entity parent = parentMap.Value.Target;

				if (main.EditorEnabled)
				{
					refreshMapTransform();
					return;
				}

				if (parent != null)
				{
					if (!parent.Active)
						parent = null;
					else
					{
						Map parentStaticMap = parent.Get<Map>();

						map.PhysicsEntity.Position = mapTransform.Position;
						if (!allowRotation)
							map.PhysicsEntity.Orientation = mapTransform.Quaternion;

						if (dir != Direction.None)
						{
							Vector3 relativeLineAnchor = parentStaticMap.GetRelativePosition(coord) - new Vector3(0.5f) + parentStaticMap.Offset + map.Offset;
							Vector3 lineAnchor = parentStaticMap.GetAbsolutePosition(relativeLineAnchor);
							DynamicMap parentDynamicMap = parent.Get<DynamicMap>();
							joint = createJoint(map.PhysicsEntity, parentDynamicMap == null ? null : parentDynamicMap.PhysicsEntity, lineAnchor, parentStaticMap.GetAbsoluteVector(dir.Value.GetVector()), parentStaticMap.GetAbsolutePosition(coord));
							main.Space.Add(joint);
							map.PhysicsEntity.ActivityInformation.Activate();

							if (parentDynamicMap != null)
							{
								parentPhysicsUpdateBinding = new CommandBinding(parentDynamicMap.PhysicsUpdated, rebuildJoint);
								result.Add(parentPhysicsUpdateBinding);
							}

							physicsUpdateBinding = new CommandBinding(map.PhysicsUpdated, rebuildJoint);
							result.Add(physicsUpdateBinding);

							jointDeleteBinding = new CommandBinding(parent.Delete, delegate()
							{
								parentMap.Value = null;
							});
							result.Add(jointDeleteBinding);
						}
					}
				}
			};
			result.Add(new NotifyBinding(rebuildJoint, parentMap));
			result.Add(new CommandBinding(result.Delete, delegate()
			{
				if (joint != null && joint.Space != null)
				{
					main.Space.Remove(joint);
					joint = null;
				}
			}));
			
			result.Add(new CommandBinding(map.OnSuspended, delegate()
			{
				if (joint != null && joint.Space != null)
					main.Space.Remove(joint);
			}));
			result.Add(new CommandBinding(map.OnResumed, delegate()
			{
				if (joint != null && joint.Space == null)
					main.Space.Add(joint);
			}));
			
			rebuildJoint();
			Command rebuildJointCommand = new Command
			{
				Action = rebuildJoint,
			};
			result.Add("RebuildJoint", rebuildJointCommand);

			if (main.EditorEnabled)
				JointFactory.attachEditorComponents(result, main);
		}
Esempio n. 34
0
        /// <summary>
        /// Creates a new binding object or returns an existing one for the given
        /// string identifier.
        /// </summary>
        /// <example>
        /// Usage example to bind an identifier to a certain command:
        /// If("RunTestCommand").ThenExecute(new MyCommand());
        /// </example>
        /// <param name="id">The identifier to bind the command to.</param>
        /// <returns>A reference to the binding object.</returns>
        public CommandBinding If(string id)
        {
            CommandBinding binding = Get(id);

            if (binding == null)
            {
                binding = new CommandBinding(_container, this);

                _bindings.Add(binding);
                _ids.Add(id, _bindings.Count - 1);
            }

            return binding;
        }
Esempio n. 35
0
        /// <summary>
        /// Creates a new binding object or returns an existing one for the given
        /// key combination.
        /// </summary>
        /// <example>
        /// Usage example to bind a key combination to a certain command:
        /// If(Shortcut.CtrlT).ThenExecute(new MyCommand());
        /// </example>
        /// <param name="shortcut">The key combination to bind the command to.</param>
        /// <returns>A reference to the binding object.</returns>
        public CommandBinding If(Shortcut shortcut)
        {
            CommandBinding binding = Get(shortcut);

            if (binding == null)
            {
                binding = new CommandBinding(_container, this);

                _bindings.Add(binding);
                _shortcuts.Add((int)shortcut, _bindings.Count - 1);
            }

            return binding;
        }
Esempio n. 36
0
		public static void MakeAttachable(Entity entity, Main main, bool deleteIfRemoved = true, bool deleteIfMoved = false, Command deleteCommand = null)
		{
			Transform transform = entity.Get<Transform>();
			Property<float> attachOffset = entity.GetOrMakeProperty<float>("AttachmentOffset", true);
			Property<Entity.Handle> map = entity.GetOrMakeProperty<Entity.Handle>("AttachedMap");
			Property<Map.Coordinate> coord = entity.GetOrMakeProperty<Map.Coordinate>("AttachedCoordinate");

			if (main.EditorEnabled)
				return;

			Binding<Matrix> attachmentBinding = null;
			CommandBinding deleteBinding = null;
			CommandBinding<IEnumerable<Map.Coordinate>, Map> cellEmptiedBinding = null;

			entity.Add(new NotifyBinding(delegate()
			{
				if (attachmentBinding != null)
				{
					entity.Remove(attachmentBinding);
					entity.Remove(deleteBinding);
					entity.Remove(cellEmptiedBinding);
				}

				Map m = map.Value.Target.Get<Map>();
				coord.Value = m.GetCoordinate(Vector3.Transform(new Vector3(0, 0, attachOffset), transform.Matrix));

				Matrix offset = transform.Matrix * Matrix.Invert(Matrix.CreateTranslation(m.Offset) * m.Transform);

				attachmentBinding = new Binding<Matrix>(transform.Matrix, () => offset * Matrix.CreateTranslation(m.Offset) * m.Transform, m.Transform, m.Offset);
				entity.Add(attachmentBinding);

				if (deleteCommand == null)
					deleteCommand = entity.Delete;

				deleteBinding = new CommandBinding(m.Delete, deleteCommand);
				entity.Add(deleteBinding);

				cellEmptiedBinding = new CommandBinding<IEnumerable<Map.Coordinate>, Map>(m.CellsEmptied, delegate(IEnumerable<Map.Coordinate> coords, Map newMap)
				{
					foreach (Map.Coordinate c in coords)
					{
						if (c.Equivalent(coord))
						{
							if (newMap == null)
							{
								if (deleteIfRemoved)
									deleteCommand.Execute();
							}
							else
							{
								if (deleteIfMoved)
									deleteCommand.Execute();
								else
									map.Value = newMap.Entity;
							}
							break;
						}
					}
				});
				entity.Add(cellEmptiedBinding);
			}, map));

			entity.Add(new PostInitialization
			{
				delegate()
				{
					if (map.Value.Target == null)
					{
						Map closestMap = null;
						int closestDistance = 3;
						float closestFloatDistance = 3.0f;
						Vector3 target = Vector3.Transform(new Vector3(0, 0, attachOffset), transform.Matrix);
						foreach (Map m in Map.Maps)
						{
							Map.Coordinate targetCoord = m.GetCoordinate(target);
							Map.Coordinate? c = m.FindClosestFilledCell(targetCoord, closestDistance);
							if (c.HasValue)
							{
								float distance = (m.GetRelativePosition(c.Value) - m.GetRelativePosition(targetCoord)).Length();
								if (distance < closestFloatDistance)
								{
									closestFloatDistance = distance;
									closestDistance = (int)Math.Floor(distance);
									closestMap = m;
								}
							}
						}
						if (closestMap == null)
							deleteCommand.Execute();
						else
							map.Value = closestMap.Entity;
					}
					else
						map.Reset();
				}
			});
		}
Esempio n. 37
0
 /// <summary>
 /// Determines the unique id of the given command binding.
 /// </summary>
 /// <param name="binding">The command binding to retrieve the id for.</param>
 /// <returns>The unique id of the command binding</returns>
 private int GetBindingId(CommandBinding binding)
 {
     return _bindings.IndexOf(binding);
 }
Esempio n. 38
0
 /// <summary>
 /// Connects an existing binding object with the specified shortcut.
 /// </summary>
 /// <param name="binding">The binding object to connect.</param>
 /// <param name="shortcut">The shortcut that should execute the binding.</param>
 public void Connect(CommandBinding binding, Shortcut shortcut)
 {
     int bindingId = GetBindingId(binding);
     if (bindingId >= 0)
         _shortcuts.Add((int)shortcut, bindingId);
 }
Esempio n. 39
0
 /// <summary>
 /// Connects an existing binding object with the specified key combination.
 /// </summary>
 /// <param name="binding">The binding object to connect.</param>
 /// <param name="key">The key combination that should execute the binding.</param>
 public void Connect(CommandBinding binding, Keys key)
 {
     int bindingId = GetBindingId(binding);
     if (bindingId >= 0)
         _shortcuts.Add((int)key, bindingId);
 }
Esempio n. 40
0
 /// <summary>
 /// Connects an existing binding object with the specified command id.
 /// </summary>
 /// <param name="binding">The binding object to connect.</param>
 /// <param name="id">The command id that should execute the binding.</param>
 public void Connect(CommandBinding binding, string id)
 {
     int bindingId = GetBindingId(binding);
     if (bindingId >= 0)
         _ids.Add(id, bindingId);
 }