Exemple #1
0
        void ShowContextMenu(object sender, RoutedEventArgs e)
        {
            var s = sender as FrameworkElement;

            if (e.Source != _uiScope)
            {
                QuickInfo.QuickInfoOverrider.HoldQuickInfo(s, true);
                return;
            }
            if (s.ContextMenu == null)
            {
                var m = new ContextMenu {
                    Resources  = SharedDictionaryManager.ContextMenu,
                    Foreground = ThemeHelper.ToolWindowTextBrush,
                    IsEnabled  = true
                };
                m.SetBackgroundForCrispImage(ThemeHelper.TitleBackgroundColor);
                var newItem = new ThemedMenuItem {
                    Icon = ThemeHelper.GetImage(IconIds.Copy), Header = "Copy selection"
                };
                newItem.Click += HandleMouseCopy;
                m.Items.Add(newItem);
                m.Closed     += ReleaseQuickInfo;
                s.ContextMenu = m;
            }
            QuickInfo.QuickInfoOverrider.HoldQuickInfo(s, true);
            s.ContextMenu.IsOpen = true;
        }
Exemple #2
0
 void HandleSelectStart(object sender, MouseButtonEventArgs e)
 {
     _uiScope.PreviewMouseLeftButtonDown -= HandleSelectStart;
     _uiScope.Focus();
     // don't mess so much if not selected
     // lazy initialization (only when selection is started)
     if (_uiScope.ContextMenu == null)
     {
         _uiScope.PreviewKeyUp += HandleCopyShortcut;
         //_uiScope.ContextMenuOpening += ShowContextMenu;
         _uiScope.Style = new Style(_uiScope.GetType())
         {
             Setters =
             {
                 new Setter(System.Windows.Controls.Primitives.TextBoxBase.SelectionBrushProperty, ThemeHelper.TextSelectionHighlightBrush)
             }
         };
         var m = new ContextMenu {
             Resources  = SharedDictionaryManager.ContextMenu,
             Foreground = ThemeHelper.ToolWindowTextBrush,
             IsEnabled  = true
         };
         m.SetBackgroundForCrispImage(ThemeHelper.TitleBackgroundColor);
         var newItem = new ThemedMenuItem {
             Icon = ThemeHelper.GetImage(IconIds.Copy), Header = R.CMD_CopySelection
         };
         newItem.Click += HandleMouseCopy;
         m.Items.Add(newItem);
         m.Items.AddRange(Config.Instance.SearchEngines.ConvertAll(s => new ThemedMenuItem(IconIds.SearchWebSite, R.CMD_SearchWith.Replace("<NAME>", s.Name), (_, args) => ExternalCommand.OpenWithWebBrowser(s.Pattern, TextRangeTextProp.GetValue(TextSelectionProp.GetValue(_editor)) as string))));
         _uiScope.ContextMenu         = m;
         _uiScope.ContextMenuOpening += HandleContextMenuOpening;
         _uiScope.ContextMenuClosing += HandleContextMenuClosing;
     }
 }