~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Base/Project/Src/Bookmarks/BookmarkConverter.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.ComponentModel;
 
6
using System.Globalization;
 
7
using System.Text;
 
8
using System.Windows;
 
9
 
 
10
using ICSharpCode.Core;
 
11
using ICSharpCode.NRefactory;
 
12
 
 
13
namespace ICSharpCode.SharpDevelop.Bookmarks
 
14
{
 
15
        public sealed class BookmarkConverter : TypeConverter
 
16
        {
 
17
                public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
 
18
                {
 
19
                        if (sourceType == typeof(string)) {
 
20
                                return true;
 
21
                        } else {
 
22
                                return base.CanConvertFrom(context, sourceType);
 
23
                        }
 
24
                }
 
25
                
 
26
                public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 
27
                {
 
28
                        if (value is string) {
 
29
                                string[] v = ((string)value).Split('|');
 
30
                                
 
31
                                FileName fileName = FileName.Create(v[1]);
 
32
                                int lineNumber = int.Parse(v[2], culture);
 
33
                                int columnNumber = int.Parse(v[3], culture);
 
34
                                if (lineNumber < 0)
 
35
                                        return null;
 
36
                                if (columnNumber < 0)
 
37
                                        return null;
 
38
                                SDBookmark bookmark;
 
39
                                switch (v[0]) {
 
40
                                        case "Breakpoint":
 
41
                                                Debugging.BreakpointAction action = Debugging.BreakpointAction.Break;
 
42
                                                string scriptLanguage = "";
 
43
                                                string script = "";
 
44
                                                action = (Debugging.BreakpointAction)Enum.Parse(typeof(Debugging.BreakpointAction), v[5]);
 
45
                                                scriptLanguage = v[6];
 
46
                                                script = v[7];
 
47
                                        
 
48
                                                var bbm = new Debugging.BreakpointBookmark(fileName, new Location(columnNumber, lineNumber), action, scriptLanguage, script);
 
49
                                                bbm.IsEnabled = bool.Parse(v[4]);
 
50
                                                bbm.Action = action;
 
51
                                                bbm.ScriptLanguage = scriptLanguage;
 
52
                                                bbm.Condition = script;
 
53
                                                bookmark = bbm;
 
54
                                                break;
 
55
                                        case "PinBookmark":
 
56
                                                var pin = new PinBookmark(fileName, new Location(columnNumber, lineNumber));
 
57
                                                pin.Comment = v[4];
 
58
                                                pin.PinPosition = 
 
59
                                                        new Point
 
60
                                                        { 
 
61
                                                                X = double.Parse(v[5], culture),
 
62
                                                                Y = double.Parse(v[6], culture)
 
63
                                                        };
 
64
                                                                
 
65
                                                // pop-up nodes
 
66
                                                pin.SavedNodes = new System.Collections.Generic.List<Tuple<string, string, string>>();
 
67
                                                for (int i = 7; i < v.Length; i+=3) {
 
68
                                                        pin.SavedNodes.Add(new Tuple<string, string, string>(v[i], v[i+1], v[i+2]));
 
69
                                                }
 
70
                                                
 
71
                                                bookmark = pin;
 
72
                                                break;
 
73
                                        default:
 
74
                                                bookmark = new Bookmark(fileName, new Location(columnNumber, lineNumber));
 
75
                                                break;
 
76
                                }
 
77
                                return bookmark;
 
78
                        } else {
 
79
                                return base.ConvertFrom(context, culture, value);
 
80
                        }
 
81
                }
 
82
                
 
83
                public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 
84
                {
 
85
                        SDBookmark bookmark = value as SDBookmark;
 
86
                        if (destinationType == typeof(string) && bookmark != null) {
 
87
                                StringBuilder b = new StringBuilder();
 
88
                                if (bookmark is Debugging.BreakpointBookmark) {
 
89
                                        b.Append("Breakpoint");
 
90
                                } else {
 
91
                                        if (bookmark is PinBookmark)
 
92
                                                b.Append("PinBookmark");        
 
93
                                        else
 
94
                                                b.Append("Bookmark");
 
95
                                }
 
96
                                b.Append('|');
 
97
                                b.Append(bookmark.FileName);
 
98
                                b.Append('|');
 
99
                                b.Append(bookmark.LineNumber);
 
100
                                b.Append('|');
 
101
                                b.Append(bookmark.ColumnNumber);
 
102
                                
 
103
                                if (bookmark is Debugging.BreakpointBookmark) {
 
104
                                        Debugging.BreakpointBookmark bbm = (Debugging.BreakpointBookmark)bookmark;
 
105
                                        b.Append('|');
 
106
                                        b.Append(bbm.IsEnabled.ToString());
 
107
                                        b.Append('|');
 
108
                                        b.Append(bbm.Action.ToString());
 
109
                                        b.Append('|');
 
110
                                        b.Append(bbm.ScriptLanguage);
 
111
                                        b.Append('|');
 
112
                                        b.Append(bbm.Condition);
 
113
                                }
 
114
                                
 
115
                                if (bookmark is PinBookmark) {
 
116
                                        var pin = (PinBookmark)bookmark;
 
117
                                        b.Append('|');
 
118
                                        b.Append(pin.Comment ?? string.Empty);
 
119
                                        
 
120
                                        // popup position
 
121
                                        b.Append('|');
 
122
                                        b.Append(pin.PinPosition.Value.X);
 
123
                                        b.Append('|');
 
124
                                        b.Append(pin.PinPosition.Value.Y);
 
125
                                                                                
 
126
                                        //popup nodes
 
127
                                        foreach(var node in pin.Nodes) {
 
128
                                                b.Append('|');
 
129
                                                b.Append(node.ImageName);
 
130
                                                b.Append('|');
 
131
                                                b.Append(node.FullName);
 
132
                                                b.Append('|');
 
133
                                                b.Append(node.Text);
 
134
                                        }                                               
 
135
                                }
 
136
                                return b.ToString();
 
137
                        } else {
 
138
                                return base.ConvertTo(context, culture, value, destinationType);
 
139
                        }
 
140
                }
 
141
        }
 
142
}