Ejemplo n.º 1
0
        public void BuildMenu()
        {
            string content = File.ReadAllText(Core.InputConfPath);
            var    items   = CommandItem.GetItems(content);

            if (!content.Contains("#menu:"))
            {
                var defaultItems = CommandItem.GetItems(Properties.Resources.input_conf);

                foreach (CommandItem item in items)
                {
                    foreach (CommandItem defaultItem in defaultItems)
                    {
                        if (item.Command == defaultItem.Command)
                        {
                            defaultItem.Input = item.Input;
                        }
                    }
                }

                items = defaultItems;
            }

            foreach (CommandItem item in items)
            {
                var tempItem = item;

                if (string.IsNullOrEmpty(tempItem.Path))
                {
                    continue;
                }

                var menuItem = MenuHelp.Add(ContextMenu.Items, tempItem.Path);

                if (menuItem != null)
                {
                    menuItem.Click += (sender, args) => {
                        try {
                            App.RunTask(() => {
                                MenuAutoResetEvent.WaitOne();
                                System.Windows.Application.Current.Dispatcher.Invoke(
                                    DispatcherPriority.Background, new Action(delegate { }));
                                if (!string.IsNullOrEmpty(tempItem.Command))
                                {
                                    Core.Command(tempItem.Command);
                                }
                            });
                        }
                        catch (Exception ex) {
                            Msg.ShowException(ex);
                        }
                    };

                    menuItem.InputGestureText = tempItem.Input;
                }
            }
        }
Ejemplo n.º 2
0
        public void BuildMenu()
        {
            string content = File.ReadAllText(core.InputConfPath);
            var    items   = CommandItem.GetItems(content);

            if (!content.Contains("#menu:"))
            {
                var defaultItems = CommandItem.GetItems(Properties.Resources.input_conf);

                foreach (CommandItem item in items)
                {
                    foreach (CommandItem defaultItem in defaultItems)
                    {
                        if (item.Command == defaultItem.Command)
                        {
                            defaultItem.Input = item.Input;
                        }
                    }
                }

                items = defaultItems;
            }

            foreach (CommandItem item in items)
            {
                if (string.IsNullOrEmpty(item.Path))
                {
                    continue;
                }

                string path = item.Path.Replace("&", "&&");

                MenuItem menuItem = ContextMenu.Add(path, () => {
                    try {
                        core.command(item.Command);
                    } catch (Exception ex) {
                        Msg.ShowException(ex);
                    }
                });

                if (menuItem != null)
                {
                    menuItem.ShortcutKeyDisplayString = item.Input + "    ";
                }
            }
        }