public ContextMenuPluginEventArgs(IContextMenuEntry entry, IList<int> logLines, ILogLineColumnizer columnizer, ILogExpertCallback callback)
		{
			this.Entry = entry;
			this.LogLines = logLines;
			this.Columnizer = columnizer;
			this.Callback = callback;
		}
 public ContextMenuPluginEventArgs(IContextMenuEntry entry, IList <int> logLines, ILogLineColumnizer columnizer, ILogExpertCallback callback)
 {
     this.Entry      = entry;
     this.LogLines   = logLines;
     this.Columnizer = columnizer;
     this.Callback   = callback;
 }
Esempio n. 3
0
        void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            SharpTreeNode[] selectedNodes = treeView.GetTopLevelSelection().ToArray();
            if (selectedNodes.Length == 0)
            {
                e.Handled = true;                 // don't show the menu
                return;
            }
            ContextMenu menu = new ContextMenu();

            foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
            {
                bool needSeparatorForCategory = true;
                foreach (var entryPair in category)
                {
                    IContextMenuEntry entry = entryPair.Value;
                    if (entry.IsVisible(selectedNodes))
                    {
                        if (needSeparatorForCategory && menu.Items.Count > 0)
                        {
                            menu.Items.Add(new Separator());
                            needSeparatorForCategory = false;
                        }
                        MenuItem menuItem = new MenuItem();
                        menuItem.Header = entryPair.Metadata.Header;
                        if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                        {
                            menuItem.Icon = new Image {
                                Width  = 16,
                                Height = 16,
                                Source = Images.LoadImage(entry, entryPair.Metadata.Icon)
                            };
                        }
                        if (entryPair.Value.IsEnabled(selectedNodes))
                        {
                            menuItem.Click += delegate
                            {
                                entry.Execute(selectedNodes);
                            };
                        }
                        else
                        {
                            menuItem.IsEnabled = false;
                        }
                        menu.Items.Add(menuItem);
                    }
                }
            }
            if (menu.Items.Count > 0)
            {
                treeView.ContextMenu = menu;
            }
            else
            {
                // hide the context menu.
                e.Handled = true;
            }
        }
Esempio n. 4
0
		public static void InstallTreeViewAndTextEditorCommand(RoutedCommand routedCmd, IContextMenuEntry treeViewCmd, IContextMenuEntry textEditorCmd, ModifierKeys modifiers, Key key) {
			if (treeViewCmd != null) {
				var elem = MainWindow.Instance.treeView;
				elem.AddCommandBinding(routedCmd, new TreeViewCommandProxy(treeViewCmd));
				bool keyBindingExists = elem.InputBindings.OfType<KeyBinding>().Any(a => a.Key == key && a.Modifiers == modifiers);
				if (!keyBindingExists)
					elem.InputBindings.Add(new KeyBinding(routedCmd, key, modifiers));
			}
			if (textEditorCmd != null)
				MainWindow.Instance.CodeBindings.Add(routedCmd, new TextEditorCommandProxy(textEditorCmd), modifiers, key);
		}
Esempio n. 5
0
 bool ShowContextMenu(ContextMenuEntryContext context, out ContextMenu menu)
 {
     menu = new ContextMenu();
     foreach (var category in MefState.Instance.entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
     {
         bool needSeparatorForCategory = menu.Items.Count > 0;
         foreach (var entryPair in category)
         {
             IContextMenuEntry entry = entryPair.Value;
             if (entry.IsVisible(context))
             {
                 if (needSeparatorForCategory)
                 {
                     menu.Items.Add(new Separator());
                     needSeparatorForCategory = false;
                 }
                 MenuItem menuItem = new MenuItem();
                 menuItem.Header = entryPair.Metadata.Header;
                 bool isEnabled;
                 if (entryPair.Value.IsEnabled(context))
                 {
                     menuItem.Click += (s, e) => {
                         // Clear this before executing the command since MainWindow might
                         // fail to give focus to new elements if it still thinks the menu
                         // is opened.
                         isMenuOpened = false;
                         entry.Execute(context);
                     };
                     isEnabled = true;
                 }
                 else
                 {
                     menuItem.IsEnabled = false;
                     isEnabled          = false;
                 }
                 if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                 {
                     MainWindow.CreateMenuItemImage(menuItem, entry, entryPair.Metadata.Icon, BackgroundType.ContextMenuItem, isEnabled);
                 }
                 menuItem.InputGestureText = entryPair.Metadata.InputGestureText ?? string.Empty;
                 var entry2 = entry as IContextMenuEntry2;
                 if (entry2 != null)
                 {
                     entry2.Initialize(context, menuItem);
                 }
                 menu.Items.Add(menuItem);
             }
         }
     }
     menu.Opened += (s, e) => isMenuOpened = true;
     menu.Closed += (s, e) => { isMenuOpened = false; ClearReferences(); };
     return(menu.Items.Count > 0);
 }
Esempio n. 6
0
 bool ShowContextMenu(TextViewContext context, out ContextMenu menu)
 {
     menu = new ContextMenu();
     foreach (var category in MefState.Instance.entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
     {
         bool needSeparatorForCategory = menu.Items.Count > 0;
         foreach (var entryPair in category)
         {
             IContextMenuEntry entry = entryPair.Value;
             if (entry.IsVisible(context))
             {
                 if (needSeparatorForCategory)
                 {
                     menu.Items.Add(new Separator());
                     needSeparatorForCategory = false;
                 }
                 MenuItem menuItem = new MenuItem();
                 menuItem.Header = entryPair.Metadata.Header;
                 bool isEnabled;
                 if (entryPair.Value.IsEnabled(context))
                 {
                     menuItem.Click += delegate { entry.Execute(context); };
                     isEnabled       = true;
                 }
                 else
                 {
                     menuItem.IsEnabled = false;
                     isEnabled          = false;
                 }
                 if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                 {
                     MainWindow.CreateMenuItemImage(menuItem, entry, entryPair.Metadata.Icon, BackgroundType.ContextMenuItem, isEnabled);
                 }
                 menuItem.InputGestureText = entryPair.Metadata.InputGestureText ?? string.Empty;
                 var entry2 = entry as IContextMenuEntry2;
                 if (entry2 != null)
                 {
                     entry2.Initialize(context, menuItem);
                 }
                 menu.Items.Add(menuItem);
             }
         }
     }
     menu.Opened += (s, e) => Interlocked.Increment(ref menuCount);
     menu.Closed += (s, e) => { Interlocked.Decrement(ref menuCount); ClearReferences(); };
     return(menu.Items.Count > 0);
 }
Esempio n. 7
0
 bool ShowContextMenu(TextViewContext context, out ContextMenu menu)
 {
     menu = new ContextMenu();
     foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
     {
         bool needSeparatorForCategory = menu.Items.Count > 0;
         foreach (var entryPair in category)
         {
             IContextMenuEntry entry = entryPair.Value;
             if (entry.IsVisible(context))
             {
                 if (needSeparatorForCategory)
                 {
                     menu.Items.Add(new Separator());
                     needSeparatorForCategory = false;
                 }
                 MenuItem menuItem = new MenuItem();
                 menuItem.Header           = MainWindow.GetResourceString(entryPair.Metadata.Header);
                 menuItem.InputGestureText = entryPair.Metadata.InputGestureText;
                 if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                 {
                     object image = Images.Load(entryPair.Value, entryPair.Metadata.Icon);
                     if (!(image is Viewbox))
                     {
                         image = new Image {
                             Width  = 16,
                             Height = 16,
                             Source = (ImageSource)image
                         };
                     }
                     menuItem.Icon = image;
                 }
                 if (entryPair.Value.IsEnabled(context))
                 {
                     menuItem.Click += delegate { entry.Execute(context); };
                 }
                 else
                 {
                     menuItem.IsEnabled = false;
                 }
                 menu.Items.Add(menuItem);
             }
         }
     }
     return(menu.Items.Count > 0);
 }
Esempio n. 8
0
        bool ShowContextMenu(TextViewContext context, out ContextMenu menu)
        {
            IList <IControl> items = new List <IControl>();

            foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category))
            {
                bool needSeparatorForCategory = items.Count > 0;
                foreach (var entryPair in category)
                {
                    IContextMenuEntry entry = entryPair.Value;
                    if (entry.IsVisible(context))
                    {
                        if (needSeparatorForCategory)
                        {
                            items.Add(new Separator());
                            needSeparatorForCategory = false;
                        }
                        MenuItem menuItem = new MenuItem();
                        menuItem.Header = entryPair.Metadata.Header;
                        if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                        {
                            menuItem.Icon = new Image {
                                Width  = 16,
                                Height = 16,
                                Source = Images.LoadImage(entry, entryPair.Metadata.Icon)
                            };
                        }
                        if (entryPair.Value.IsEnabled(context))
                        {
                            menuItem.Click += delegate { entry.Execute(context); };
                        }
                        else
                        {
                            menuItem.IsEnabled = false;
                        }
                        items.Add(menuItem);
                    }
                }
            }
            menu       = new ContextMenu();
            menu.Items = items;
            return(items.Count > 0);
        }
Esempio n. 9
0
        private bool TryAsContextMenu(Type type)
        {
            IContextMenuEntry me = TryInstantiate <IContextMenuEntry>(type);

            if (me != null)
            {
                this.RegisteredContextMenuPlugins.Add(me);
                if (me is ILogExpertPluginConfigurator)
                {
                    ((ILogExpertPluginConfigurator)me).LoadConfig(ConfigManager.ConfigDir);
                }
                if (me is ILogExpertPlugin)
                {
                    this.pluginList.Add(me as ILogExpertPlugin);
                    (me as ILogExpertPlugin).PluginLoaded();
                }
                _logger.Info("Added context menu plugin {0}", type);
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
 public TextEditorCommandProxy(IContextMenuEntry cmd)
     : base(cmd)
 {
 }
Esempio n. 11
0
 protected ContextMenuEntryCommandProxy(IContextMenuEntry cmd)
 {
     this.cmd = cmd;
 }
Esempio n. 12
0
		public static void InstallSettingsCommand(IContextMenuEntry treeViewCmd, IContextMenuEntry textEditorCmd) {
			InstallTreeViewAndTextEditorCommand(SettingsRoutedCommand, treeViewCmd, textEditorCmd, ModifierKeys.Alt, Key.Enter);
		}
Esempio n. 13
0
 public TreeViewCommandProxy(IContextMenuEntry cmd)
     : base(cmd)
 {
 }
Esempio n. 14
0
 public TextEditorCommandProxy(IContextMenuEntry cmd)
     : base(cmd)
 {
 }
Esempio n. 15
0
 public TreeViewCommandProxy(IContextMenuEntry cmd)
     : base(cmd)
 {
 }
Esempio n. 16
0
 public static void InstallTreeViewAndTextEditorCommand(RoutedCommand routedCmd, IContextMenuEntry treeViewCmd, IContextMenuEntry textEditorCmd, ModifierKeys modifiers, Key key)
 {
     if (treeViewCmd != null)
     {
         var elem = MainWindow.Instance.treeView;
         elem.AddCommandBinding(routedCmd, new TreeViewCommandProxy(treeViewCmd));
         bool keyBindingExists = elem.InputBindings.OfType <KeyBinding>().Any(a => a.Key == key && a.Modifiers == modifiers);
         if (!keyBindingExists)
         {
             elem.InputBindings.Add(new KeyBinding(routedCmd, key, modifiers));
         }
     }
     if (textEditorCmd != null)
     {
         MainWindow.Instance.CodeBindings.Add(routedCmd, new TextEditorCommandProxy(textEditorCmd), modifiers, key);
     }
 }
Esempio n. 17
0
 public static void InstallSettingsCommand(IContextMenuEntry treeViewCmd, IContextMenuEntry textEditorCmd)
 {
     InstallTreeViewAndTextEditorCommand(SettingsRoutedCommand, treeViewCmd, textEditorCmd, ModifierKeys.Alt, Key.Enter);
 }
		protected ContextMenuEntryCommandProxy(IContextMenuEntry cmd) {
			this.cmd = cmd;
		}
Esempio n. 19
0
        bool ShowContextMenu(TextViewContext context, out ContextMenu menu)
        {
            menu = new ContextMenu();
            var menuGroups = new Dictionary <string, Lazy <IContextMenuEntry, IContextMenuEntryMetadata>[]>();

            Lazy <IContextMenuEntry, IContextMenuEntryMetadata>[] topLevelGroup = null;
            foreach (var group in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.ParentMenuID))
            {
                if (group.Key == null)
                {
                    topLevelGroup = group.ToArray();
                }
                else
                {
                    menuGroups.Add(group.Key, group.ToArray());
                }
            }
            BuildMenu(topLevelGroup ?? Array.Empty <Lazy <IContextMenuEntry, IContextMenuEntryMetadata> >(), menu.Items);
            return(menu.Items.Count > 0);

            void BuildMenu(Lazy <IContextMenuEntry, IContextMenuEntryMetadata>[] menuGroup, ItemCollection parent)
            {
                foreach (var category in menuGroup.GroupBy(c => c.Metadata.Category))
                {
                    bool needSeparatorForCategory = parent.Count > 0;
                    foreach (var entryPair in category)
                    {
                        IContextMenuEntry entry = entryPair.Value;
                        if (entry.IsVisible(context))
                        {
                            if (needSeparatorForCategory)
                            {
                                parent.Add(new Separator());
                                needSeparatorForCategory = false;
                            }
                            MenuItem menuItem = new MenuItem();
                            menuItem.Header           = MainWindow.GetResourceString(entryPair.Metadata.Header);
                            menuItem.InputGestureText = entryPair.Metadata.InputGestureText;
                            if (!string.IsNullOrEmpty(entryPair.Metadata.Icon))
                            {
                                menuItem.Icon = new Image {
                                    Width  = 16,
                                    Height = 16,
                                    Source = Images.Load(entryPair.Value, entryPair.Metadata.Icon)
                                };
                            }
                            if (entryPair.Value.IsEnabled(context))
                            {
                                menuItem.Click += delegate { entry.Execute(context); };
                            }
                            else
                            {
                                menuItem.IsEnabled = false;
                            }
                            parent.Add(menuItem);

                            if (entryPair.Metadata.MenuID != null && menuGroups.TryGetValue(entryPair.Metadata.MenuID, out var group))
                            {
                                BuildMenu(group, menuItem.Items);
                            }
                        }
                    }
                }
            }
        }