private string SnippetToText(CodeSnippet snippet, CodeType targetType)
        {
            string _result = string.Empty;

            if (snippet.CodeType == CodeType.ReferenceLink)
            {
                snippet = CodeLib.Instance.CodeSnippets.Get(snippet.ReferenceLinkId);
            }
            if (snippet.CodeType == CodeType.Image)
            {
                string _base64 = Convert.ToBase64String(snippet.Blob);
                switch (targetType)
                {
                case CodeType.MarkDown:
                    _result = string.Format(@"![{0}](data:image/png;base64,{1})", snippet.GetPath(), _base64);
                    break;

                default:
                    _result = string.Format(@"<img src=""data:image/png;base64,{0}"" />", _base64);
                    break;
                }
            }
            else
            {
                _result = snippet.GetCode();
            }
            return(_result);
        }
예제 #2
0
        public void SetState(CodeSnippet snippet)
        {
            _supressTextChanged = true;

            _StateSnippet         = snippet;
            _mainform.tbPath.Text = snippet.GetPath();
            _mainform.rtfEditor.ClearUndo();
            _mainform.rtfEditor.ResetText();

            _mainform.rtfEditor.OwnTheme = snippet.RTFOwnTheme;
            if (_mainform.rtfEditor.OwnTheme)
            {
                _mainform.rtfEditor.SetOwnTheme(snippet.RTFTheme);
            }
            else
            {
                _mainform.rtfEditor.Theme = Config.Theme;
            }

            _mainform.rtfEditor.Rtf = snippet.GetRTF();

            _mainform.rtfEditor.Zoom = Config.Zoom;

            _supressTextChanged = false;
        }
        public void SetState(CodeSnippet snippet)
        {
            _StateSnippet       = snippet;
            _supressTextChanged = true;
            _tb.BeginUpdate();

            _TextBoxHelper.SetEditorView(snippet);

            string _text = snippet.GetCode();

            _tb.Text = !string.IsNullOrEmpty(_text) ? _text : "";
            _tb.ClearUndo();
            _mainform.tbPath.Text = snippet.GetPath();// + $"    [C: {snippet.CreationDate},M:{snippet.CodeLastModificationDate:yyyy-MM-dd HH:mm:ss}]";
            _tb.WordWrap          = snippet.Wordwrap;
            _tb.SelectionStart    = 0;
            _tb.SelectionLength   = 0;
            _tb.ScrollControlIntoView(_tb);

            int _lines = _tb.LinesCount;

            try
            {
                if (_lines > snippet.CurrentLine)
                {
                    _tb.GotoLine(snippet.CurrentLine);
                }
            }
            catch { }

            _mainform.mnuWordwrap.Checked    = snippet.Wordwrap;
            _mainform.mnuHTMLPreview.Checked = snippet.HtmlPreview;

            _tb.EndUpdate();

            _supressTextChanged = false;
        }