示例#1
0
文件: Editors.cs 项目: u89012/Bootpad
        private void WalkAddingMenuItems(XmlNodeList nodes, ToolStripMenuItem parent)
        {
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ToolStripMenuItem curItem = null;

                    if (parent == null)
                    {
                        curItem = ContextMenuStrip.Items.Add(n.Attributes["name"].Value) as ToolStripMenuItem;
                    }
                    else
                    {
                        curItem = parent.DropDownItems.Add(n.Attributes["name"].Value) as ToolStripMenuItem;
                    }

                    curItem.Name = n.Attributes["name"].Value;

                    var snippets = n.SelectNodes("snip");
                    foreach (XmlNode snippet in snippets)
                    {
                        curItem.DropDownItems.Add(snippet.Attributes["name"].Value, null, delegate {
                            var sel      = Environment.NewLine + SelectedText.Trim() + Environment.NewLine;
                            SelectedText = string.Format(snippet.InnerText.Trim(), sel) + Environment.NewLine;
                        });
                    }

                    WalkAddingMenuItems(n.SelectNodes("node"), curItem);
                }
            }
        }
 void MenuActionCopy(object sender, EventArgs e)
 {
     Clipboard.Clear();
     if (!((String.IsNullOrEmpty(SelectedText) || SelectedText.Trim().Length == 0)))
     {
         Clipboard.SetText(base.SelectedText);
     }
 }
示例#3
0
        //hack - might be a better way than using OnMouseUp...
        protected override void OnMouseUp(MouseEventArgs mevent)
        {
            base.OnMouseUp(mevent);

            string trimmed = SelectedText.Trim();

            if (trimmed.Length > 1)
            {
                Clipboard.SetText(trimmed, TextDataFormat.UnicodeText);
            }
            ResetSelection();
        }
示例#4
0
文件: Editor.cs 项目: firleju/ScnEdit
 public void ToggleComment()
 {
     if (Language == FastColoredTextBoxNS.Language.Custom)
     {
         Selection = GetLinesFromSelection();
         if (SelectedText.Trim().StartsWith("//"))
         {
             UncommentSelectedLines();
         }
         else
         {
             CommentSelectedLines();
         }
     }
     else
     {
         CommentSelected();
     }
     OnSyntaxHighlight(new TextChangedEventArgs(Selection));
 }
        /// <summary>
        /// Event raised when the user right-clicks in the textbox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _context_Popup(object sender, EventArgs e)
        {
            string word = SelectedText.Trim();

            if (word.Length > 0)
            {
                // Show the wait cursor in case the web service call takes a little while.
                System.Windows.Forms.Cursor c = Cursor;
                base.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                base.ContextMenu.MenuItems.Clear();

                _context = new System.Windows.Forms.ContextMenu();

                List <string> rhymingWords = RhymingWords.GetRhymes(word);

                // Assign the click events to the same handler and determine what was picked there.
                foreach (string rhymedWord in rhymingWords)
                {
                    _context.MenuItems.Add(new System.Windows.Forms.MenuItem(rhymedWord, _menuClickDelegate));
                }

                if (rhymingWords.Count == 0)
                {
                    System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem("[No rhymes found]");
                    mi.Enabled = false;
                    _context.MenuItems.Add(mi);
                }

                // Show the menu of the rhyming words.
                base.ContextMenu = _context;
                base.Cursor      = c;
                base.ContextMenu.Show(this, _mouseLocation);

                // Seem to have to unsubscribe and resubscribe
                // or this popup menu handler isn't called.
                base.ContextMenu.Popup -= _popupDelegate;
                base.ContextMenu.Popup += _popupDelegate;
            }
        }
        public void ShowDictionaryPopup()
        {
            var dict = Svc <PDFPlugin> .Plugin.DictionaryPlugin;

            if (dict == null || dict.CredentialsAvailable == false || IsTextSelectionValid() == false)
            {
                return;
            }

            string text = SelectedText?.Trim(' ',
                                             '\t',
                                             '\r',
                                             '\n');

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            /*
             * int    spaceIdx = text.IndexOfAny(new[] { ' ', '\r' });
             *
             * if (spaceIdx > 0)
             * text = text.Substring(0,
             *                      spaceIdx);
             *
             * if (spaceIdx == 0 || string.IsNullOrWhiteSpace(text))
             * return;
             */

            var pageIdx   = SelectInfo.StartPage;
            var startIdx  = SelectInfo.StartIndex;
            var textInfos = Document.Pages[pageIdx].Text.GetTextInfo(startIdx,
                                                                     text.Length);

            if (textInfos?.Rects == null || textInfos.Rects.Any() == false)
            {
                Show.Window()
                .For(new Alert($"ShowDictionaryPopup: Failed to get selected text info ({startIdx}:{text.Length}@{pageIdx}).",
                               "Error"));
                return;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            var wdw = Window.GetWindow(this);

            if (wdw == null)
            {
                LogTo.Error("ShowDictionaryPopup: Window.GetWindow(this) returned null");
                Show.Window()
                .For(new Alert("ShowDictionaryPopup: Window.GetWindow(this) returned null",
                               "Error"));
                return;
            }

            var cts             = new RemoteCancellationTokenSource();
            var entryResultTask = LookupWordEntryAsync(cts.Token,
                                                       text,
                                                       dict);

            var pagePt = PageToClient(pageIdx,
                                      new Point(textInfos.Rects.Last().right,
                                                textInfos.Rects.Last().top));

            DictionaryPopup.HorizontalOffset = pagePt.X;
            DictionaryPopup.VerticalOffset   = pagePt.Y;
            DictionaryPopup.DataContext      = new PendingEntryResult(cts,
                                                                      entryResultTask,
                                                                      dict);
            DictionaryPopup.IsOpen = true;
        }