Ejemplo n.º 1
0
        public void Load(CodeSnippetCollection collection)
        {
            BeginUpdate();

            Counter = collection.Counter;

            try
            {
                foreach (CodeSnippet snippet in collection.Items)
                {
                    if (string.IsNullOrWhiteSpace(snippet.GetPath()))
                    {
                        snippet.SetPath(Constants.UNNAMED, out bool _changed);
                    }

                    snippet.Refresh();
                }
            }
            catch { }


            TreeNodes.Clear();
            CodeSnippets.Clear();
            CodeSnippets.AddRange(collection.Items);
            if (collection.DocumentId.Equals(Guid.Empty))
            {
                DocumentId = Guid.NewGuid();
            }
            else
            {
                DocumentId = collection.DocumentId;
            }

            if (Counter < collection.Items.Count)
            {
                Counter = collection.Items.Count;
            }

            if (ClipboardMonitor != null)
            {
                ClipboardMonitor.Order = -1;
                ClipboardMonitor.SetPath("Clipboard Monitor", out bool _changed);
            }
            if (Trashcan != null)
            {
                Trashcan.Order = -2;
                Trashcan.SetPath("Trashcan", out bool _changed);
            }

            EndUpdate();
        }
Ejemplo n.º 2
0
        public void LoadLegacy(CodeSnippetCollectionOld collection)
        {
            BeginUpdate();

            Cleanup(collection);

            Counter = collection.Counter;

            CodeSnippetCollection _newCollection = new CodeSnippetCollection();

            _newCollection.Items.Clear();

            foreach (CodeSnippetOld _old in collection.Items)
            {
                if (string.IsNullOrWhiteSpace(_old.Path))
                {
                    _old.Path = Constants.UNNAMED;
                }

                CodeSnippet _new = new CodeSnippet()
                {
                    DefaultChildCodeType        = _old.DefaultChildCodeType,
                    DefaultChildCodeTypeEnabled = _old.DefaultChildCodeTypeEnabled,
                    DefaultChildName            = _old.DefaultChildName,
                    Name        = _old.Name,
                    Blob        = _old.Blob,
                    AlarmActive = _old.AlarmActive,
                    AlarmDate   = _old.AlarmDate,
                    CodeLastModificationDate = _old.CodeLastModificationDate,
                    CodeType        = _old.CodeType,
                    CreationDate    = _old.CreationDate,
                    CurrentLine     = _old.CurrentLine,
                    Expanded        = _old.Expanded,
                    Flag            = _old.Flag,
                    HtmlPreview     = _old.HtmlPreview,
                    Id              = _old.Id,
                    Important       = _old.Important,
                    Locked          = _old.Locked,
                    Order           = _old.Order,
                    ReferenceLinkId = _old.ReferenceLinkId,
                    RTFAlwaysWhite  = _old.RTFAlwaysWhite,
                    RTFOwnTheme     = _old.RTFOwnTheme,
                    RTFTheme        = _old.RTFTheme,
                    ShortCutKeys    = _old.ShortCutKeys,
                    Wordwrap        = _old.Wordwrap
                };

                if (_old.Path.Equals(@"Trashcan"))
                {
                }

                if (_old.Path.Equals(@"C#\Classes\VersionNumber"))
                {
                }

                bool _changed = false;
                _new.SetPath(_old.Path, out _changed);
                _new.SetCode(_old.Code, out _changed);
                _new.SetRtf(_old.RTF, out _changed);
                _new.SetDefaultChildCode(_old.DefaultChildCode, out _changed);
                _new.SetDefaultChildRtf(_old.DefaultChildRtf, out _changed);


                _newCollection.Items.Add(_new);
            }

            TreeNodes.Clear();
            CodeSnippets.Clear();
            CodeSnippets.AddRange(_newCollection.Items);

            if (Counter < collection.Items.Count)
            {
                Counter = collection.Items.Count;
            }

            if (ClipboardMonitor != null)
            {
                ClipboardMonitor.Order = -1;
                ClipboardMonitor.SetPath("Clipboard Monitor", out bool _changed);
            }
            if (Trashcan != null)
            {
                Trashcan.Order = -2;
                Trashcan.SetPath("Trashcan", out bool _changed);
            }

            DocumentId = Guid.NewGuid(); // Legacy always new DocumentId

            EndUpdate();
        }