~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/ClassOutlineTextEditorExtension.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
                TreeStore outlineTreeStore;
50
50
                bool refreshingOutline;
51
51
                bool disposed;
 
52
                bool outlineReady;
52
53
 
53
54
                public override bool ExtendsEditor (Document doc, IEditableTextBuffer editor)
54
55
                {
70
71
                        disposed = true;
71
72
                        if (Document != null)
72
73
                                Document.DocumentParsed -= UpdateDocumentOutline;
 
74
                        RemoveRefillOutlineStoreTimeout ();
73
75
                        base.Dispose ();
74
76
                }
75
77
 
100
102
                        outlineTreeView.HeadersVisible = false;
101
103
                        
102
104
                        outlineTreeView.Selection.Changed += delegate {
103
 
                                TreeIter iter;
104
 
                                if (!outlineTreeView.Selection.GetSelected (out iter))
105
 
                                        return;
106
 
                                object o = outlineTreeStore.GetValue (iter, 0);
107
 
                                int line = -1, col = -1;
108
 
                                if (o is IType) {
109
 
                                        line = ((IType)o).BodyRegion.Start.Line;
110
 
                                        col = ((IType)o).BodyRegion.Start.Column;
111
 
                                } else if (o is IMember) {
112
 
                                        line = ((IMember)o).BodyRegion.Start.Line;
113
 
                                        col = ((IMember)o).BodyRegion.Start.Column;
114
 
                                }
115
 
                                if (line > -1) {
116
 
                                        Editor.JumpTo (line, Math.Max (1, col));
117
 
                                }
 
105
                                JumpToDeclaration (false);
 
106
                        };
 
107
                        
 
108
                        outlineTreeView.RowActivated += delegate {
 
109
                                JumpToDeclaration (true);
118
110
                        };
119
111
 
120
112
                        this.lastCU = Document.ParsedDocument;
126
118
                        sw.ShowAll ();
127
119
                        return sw;
128
120
                }
 
121
                
 
122
                void JumpToDeclaration (bool focusEditor)
 
123
                {
 
124
                        if (!outlineReady)
 
125
                                return;
 
126
                        TreeIter iter;
 
127
                        if (!outlineTreeView.Selection.GetSelected (out iter))
 
128
                                return;
 
129
                        object o = outlineTreeStore.GetValue (iter, 0);
 
130
                        
 
131
                        IdeApp.ProjectOperations.JumpToDeclaration (o as INode);
 
132
                        if (focusEditor)
 
133
                                IdeApp.Workbench.ActiveDocument.Select ();
 
134
                }
129
135
 
130
136
                void OutlineTreeIconFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
131
137
                {
163
169
                        outlineTreeStore = null;
164
170
                        outlineTreeView = null;
165
171
                }
166
 
 
 
172
                
 
173
                void RemoveRefillOutlineStoreTimeout ()
 
174
                {
 
175
                        if (refillOutlineStoreId == 0)
 
176
                                return;
 
177
                        GLib.Source.Remove (refillOutlineStoreId);
 
178
                        refillOutlineStoreId = 0;
 
179
                }
 
180
                
 
181
                uint refillOutlineStoreId;
167
182
                void UpdateDocumentOutline (object sender, EventArgs args)
168
183
                {
169
 
                        bool refreshNow = lastCU == null;
170
184
                        lastCU = Document.ParsedDocument;
 
185
                        //limit update rate to 3s
171
186
                        if (!refreshingOutline) {
172
187
                                refreshingOutline = true;
173
 
                                if (refreshNow) {
174
 
                                        RefillOutlineStore (); 
175
 
                                } else {
176
 
                                        //limit update rate to 1s
177
 
                                        GLib.Timeout.Add (1000, new GLib.TimeoutHandler (RefillOutlineStore));
178
 
                                }
 
188
                                refillOutlineStoreId = GLib.Timeout.Add (3000, new GLib.TimeoutHandler (RefillOutlineStore));
179
189
                        }
180
190
                }
181
191
 
184
194
                        DispatchService.AssertGuiThread ();
185
195
                        Gdk.Threads.Enter ();
186
196
                        refreshingOutline = false;
187
 
                        if (outlineTreeStore == null || !outlineTreeView.IsRealized)
 
197
                        if (outlineTreeStore == null || !outlineTreeView.IsRealized) {
 
198
                                refillOutlineStoreId = 0;
188
199
                                return false;
189
 
 
 
200
                        }
 
201
                        
 
202
                        outlineReady = false;
190
203
                        outlineTreeStore.Clear ();
191
204
                        if (lastCU != null) {
192
205
                                BuildTreeChildren (outlineTreeStore, TreeIter.Zero, lastCU);
 
206
                                TreeIter it;
 
207
                                if (outlineTreeStore.GetIterFirst (out it))
 
208
                                        outlineTreeView.Selection.SelectIter (it);
193
209
                                outlineTreeView.ExpandAll ();
194
210
                        }
 
211
                        outlineReady = true;
195
212
 
196
213
                        Gdk.Threads.Leave ();
197
214
 
198
215
                        //stop timeout handler
 
216
                        refillOutlineStoreId = 0;
199
217
                        return false;
200
218
                }
201
219
 
270
288
 
271
289
                static DomRegion GetRegion (object o)
272
290
                {
273
 
                        if (o is IMember)
274
 
                                return ((IMember)o).BodyRegion;
 
291
                        if (o is IField) {
 
292
                                var f = (IField)o;
 
293
                                return new DomRegion (f.Location, f.Location);
 
294
                        }
 
295
                        
 
296
                        if (o is IMember) {
 
297
                                var m = (IMember)o;
 
298
                                return m.BodyRegion.IsEmpty ? new DomRegion (m.Location, m.Location) : m.BodyRegion;
 
299
                        }
275
300
                        throw new InvalidOperationException (o.GetType ().ToString ());
276
301
                }
277
302
 
278
303
                static bool OuterEndsAfterInner (DomRegion outer, DomRegion inner)
279
304
                {
280
 
                        return ((outer.End.Line > 0 && outer.End.Line > inner.End.Line) || (outer.End.Line == inner.End.Line && outer.End.Column > inner.End.Column));
 
305
                        return ((outer.End.Line > 1 && outer.End.Line > inner.End.Line) || (outer.End.Line == inner.End.Line && outer.End.Column > inner.End.Column));
281
306
                }
282
307
        }
283
308
}