Beispiel #1
0
 void HandleShowPreviewClick(object sender, EventArgs e)
 {
     if (package != null)
     {
         var window = package.GetMarkdownPreviewToolWindow(true);
         ((IVsWindowFrame)window.Frame).ShowNoActivate();
         backgroundParser.RequestParse(true);
     }
 }
Beispiel #2
0
 MarkdownPreviewToolWindow GetPreviewWindow(bool create)
 {
     return((package != null) ? package.GetMarkdownPreviewToolWindow(create) : null);
 }
Beispiel #3
0
        public Margin(IWpfTextView wpfTextView, MarkdownPackage package)
        {
            this.textView = wpfTextView;
            this.package  = package;

            this.Orientation = System.Windows.Controls.Orientation.Horizontal;
            this.Background  = Brushes.SlateGray;
            this.Height      = 25;

            Button showPreview = new Button()
            {
                Content = "Show preview window"
            };

            showPreview.Click += (sender, args) =>
            {
                if (package != null)
                {
                    var window = package.GetMarkdownPreviewToolWindow(true);
                    ((IVsWindowFrame)window.Frame).ShowNoActivate();
                }
            };

            this.Children.Add(showPreview);

            Button copyHtml = new Button()
            {
                Content = "Copy HTML to clipboard"
            };

            copyHtml.Click += (sender, args) =>
            {
                Clipboard.SetText(GetHTMLText());
            };

            this.Children.Add(copyHtml);

            sectionCombo = new ComboBox();
            sectionCombo.SelectionChanged += (sender, args) =>
            {
                if (ignoreComboChange)
                {
                    return;
                }

                ITextSnapshot snapshot = textView.TextSnapshot;

                int selectedIndex = sectionCombo.SelectedIndex;

                if (selectedIndex == 0)
                {
                    NavigateTo(new SnapshotPoint(snapshot, 0));
                }
                else
                {
                    selectedIndex--;

                    if (selectedIndex >= sections.Count)
                    {
                        Debug.Fail("An item in the combo was selected that isn't a valid section.");
                        return;
                    }

                    NavigateTo(sections[selectedIndex].Span.GetStartPoint(snapshot));
                }
            };
            RefreshComboItems(null, EventArgs.Empty);

            this.Children.Add(sectionCombo);

            BufferIdleEventUtil.AddBufferIdleEventListener(textView.TextBuffer, RefreshComboItems);
            textView.Closed += (sender, args) => BufferIdleEventUtil.RemoveBufferIdleEventListener(textView.TextBuffer, RefreshComboItems);

            textView.Caret.PositionChanged += (sender, args) => SetSectionComboToCaretPosition();
        }
Beispiel #4
0
        public Margin(IWpfTextView wpfTextView, MarkdownPackage package)
        {
            this.textView = wpfTextView;
            this.package = package;

            this.Orientation = System.Windows.Controls.Orientation.Horizontal;
            this.Background = Brushes.SlateGray;
            this.Height = 25;

            Button showPreview = new Button() { Content = "Show preview window" };
            showPreview.Click += (sender, args) =>
                {
                    if (package != null)
                    {
                        var window = package.GetMarkdownPreviewToolWindow(true);
                        ((IVsWindowFrame)window.Frame).ShowNoActivate();
                    }
                };

            this.Children.Add(showPreview);

            Button copyHtml = new Button() { Content = "Copy HTML to clipboard" };
            copyHtml.Click += (sender, args) =>
                {
                    Clipboard.SetText(GetHTMLText());
                };

            this.Children.Add(copyHtml);

            sectionCombo = new ComboBox();
            sectionCombo.SelectionChanged += (sender, args) =>
                {
                    if (ignoreComboChange)
                        return;

                    ITextSnapshot snapshot = textView.TextSnapshot;

                    int selectedIndex = sectionCombo.SelectedIndex;

                    if (selectedIndex == 0)
                    {
                        NavigateTo(new SnapshotPoint(snapshot, 0));
                    }
                    else
                    {
                        selectedIndex--;

                        if (selectedIndex >= sections.Count)
                        {
                            Debug.Fail("An item in the combo was selected that isn't a valid section.");
                            return;
                        }

                        NavigateTo(sections[selectedIndex].Span.GetStartPoint(snapshot));
                    }
                };
            RefreshComboItems(null, EventArgs.Empty);

            this.Children.Add(sectionCombo);

            BufferIdleEventUtil.AddBufferIdleEventListener(textView.TextBuffer, RefreshComboItems);
            textView.Closed += (sender, args) => BufferIdleEventUtil.RemoveBufferIdleEventListener(textView.TextBuffer, RefreshComboItems);

            textView.Caret.PositionChanged += (sender, args) => SetSectionComboToCaretPosition();
        }