예제 #1
0
        private string getContextHtmlText(DiffPosition position, IGitCommandService git, out string stylesheet)
        {
            stylesheet = String.Empty;

            DiffContext?context;

            try
            {
                ContextDepth  depth            = new ContextDepth(0, 3);
                IContextMaker textContextMaker = new SimpleContextMaker(git);
                context = textContextMaker.GetContext(position, depth);
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is ContextMakingException)
                {
                    string errorMessage = "Cannot render HTML context.";
                    ExceptionHandlers.Handle(errorMessage, ex);
                    return(String.Format("<html><body>{0} See logs for details</body></html>", errorMessage));
                }
                throw;
            }

            Debug.Assert(context.HasValue);
            DiffContextFormatter formatter =
                new DiffContextFormatter(WinFormsHelpers.GetFontSizeInPixels(htmlPanelContext), 2);

            stylesheet = formatter.GetStylesheet();
            return(formatter.GetBody(context.Value));
        }
예제 #2
0
        private void setServiceDiscussionNoteText(Control noteControl, DiscussionNote note)
        {
            if (note == null)
            {
                Debug.Assert(false);
                return;
            }

            // We need to zero the control size before SetText call to allow HtmlPanel to compute the size
            noteControl.Width  = 0;
            noteControl.Height = 0;

            Debug.Assert(noteControl is HtmlPanel);
            HtmlPanel htmlPanel = noteControl as HtmlPanel;

            htmlPanel.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}",
                                                     Properties.Resources.Common_CSS,
                                                     WinFormsHelpers.GetFontSizeInPixels(noteControl));

            string body = MarkDownUtils.ConvertToHtml(note.Body, _imagePath, _specialDiscussionNoteMarkdownPipeline);

            noteControl.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body);

            resizeFullSizeHtmlPanel(noteControl as HtmlPanel);
        }
예제 #3
0
        internal void setDiscussionNoteText(Control noteControl, DiscussionNote note)
        {
            if (note == null)
            {
                // this is possible when noteControl detaches from parent
                return;
            }

            Debug.Assert(noteControl is HtmlPanel);
            HtmlPanel htmlPanel = noteControl as HtmlPanel;

            htmlPanel.BaseStylesheet = String.Format(
                "{0} body div {{ font-size: {1}px; padding-left: 4px; padding-right: {2}px; }}",
                Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(noteControl),
                SystemInformation.VerticalScrollBarWidth * 2); // this is really weird

            // We need to zero the control size before SetText call to allow HtmlPanel to compute the size
            int prevWidth = noteControl.Width;

            noteControl.Width  = 0;
            noteControl.Height = 0;

            string body = MarkDownUtils.ConvertToHtml(note.Body, _imagePath, _specialDiscussionNoteMarkdownPipeline);

            noteControl.Text = String.Format(MarkDownUtils.HtmlPageTemplate, addPrefix(body, note, _firstNoteAuthor));
            resizeLimitedWidthHtmlPanel(htmlPanel, prevWidth);

            _htmlDiscussionNoteToolTip.BaseStylesheet =
                String.Format("{0} body div {{ font-size: {1}px; }}",
                              Properties.Resources.Common_CSS,
                              WinFormsHelpers.GetFontSizeInPixels(noteControl));
            _htmlDiscussionNoteToolTip.SetToolTip(noteControl, getNoteTooltipHtml(note));
        }
예제 #4
0
        private void setDiffContextText(Control diffContextControl)
        {
            double fontSizePx = WinFormsHelpers.GetFontSizeInPixels(diffContextControl);

            DiscussionNote note = getNoteFromControl(diffContextControl);

            Debug.Assert(note.Type == "DiffNote");
            DiffPosition position = PositionConverter.Convert(note.Position);

            Debug.Assert(diffContextControl is HtmlPanel);
            HtmlPanel htmlPanel = diffContextControl as HtmlPanel;

            // We need to zero the control size before SetText call to allow HtmlPanel to compute the size
            int prevWidth = htmlPanel.Width;

            htmlPanel.Width  = 0;
            htmlPanel.Height = 0;

            string html = getContext(_panelContextMaker, position, _diffContextDepth, fontSizePx, out string css);

            htmlPanel.BaseStylesheet = css;
            htmlPanel.Text           = html;
            resizeLimitedWidthHtmlPanel(htmlPanel, prevWidth);

            string tooltipHtml = getContext(_tooltipContextMaker, position,
                                            _tooltipContextDepth, fontSizePx, out string tooltipCSS);

            _htmlDiffContextToolTip.BaseStylesheet =
                String.Format("{0} .htmltooltip {{ padding: 1px; }}", tooltipCSS);
            _htmlDiffContextToolTip.SetToolTip(htmlPanel, tooltipHtml);
        }
예제 #5
0
        private string getContextHtmlText(DiffPosition position, HtmlPanel htmlPanel, out string stylesheet)
        {
            stylesheet = String.Empty;
            double fontSizePx = WinFormsHelpers.GetFontSizeInPixels(htmlPanel);
            var    getContext = isCurrentNoteNew() ? _getNewDiscussionDiffContext(position) : _getDiffContext(position);

            return(DiffContextFormatter.GetHtml(getContext, fontSizePx, 2, true));
        }
예제 #6
0
        private void tabControlMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControlMode.SelectedTab == tabPagePreview)
            {
                htmlPanelPreview.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}",
                                                                Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(htmlPanelPreview));

                Markdig.MarkdownPipeline pipeline = MarkDownUtils.CreatePipeline(Program.ServiceManager.GetJiraServiceUrl());
                string body = MarkDownUtils.ConvertToHtml(textBox.Text, _uploadsPrefix, pipeline);
                htmlPanelPreview.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body);
            }
        }
예제 #7
0
        private void updatePreview(HtmlPanel previewPanel, string text)
        {
            previewPanel.BaseStylesheet = String.Format("{0} body div {{ font-size: {1}px; }}",
                                                        Properties.Resources.Common_CSS, WinFormsHelpers.GetFontSizeInPixels(previewPanel));

            var    pipeline = MarkDownUtils.CreatePipeline(Program.ServiceManager.GetJiraServiceUrl());
            string body     = MarkDownUtils.ConvertToHtml(text, String.Empty, pipeline);

            previewPanel.Text = String.Format(MarkDownUtils.HtmlPageTemplate, body);
        }