~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Extras/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/CombinedDesignView.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// CombinedDesignView.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Ide.Gui.Content;
 
33
using MonoDevelop.Ide.Gui;
 
34
using MonoDevelop.Ide.Gui.Search;
 
35
using MonoDevelop.Ide.Commands;
 
36
using MonoDevelop.Components.Commands;
 
37
using MonoDevelop.Core.Execution;
 
38
using MonoDevelop.Projects.Text;
 
39
using MonoDevelop.Projects.Parser;
 
40
 
 
41
using Gtk;
 
42
using Gdk;
 
43
 
 
44
namespace MonoDevelop.GtkCore.GuiBuilder
 
45
{
 
46
        public class CombinedDesignView : AbstractViewContent, IEditableTextBuffer, IPositionable, IBookmarkBuffer, IDebuggableEditor, ICodeStyleOperations,
 
47
                IDocumentInformation, IEncodedTextContent
 
48
        {
 
49
                IViewContent content;
 
50
                Gtk.Notebook notebook;
 
51
                VBox box;
 
52
                Toolbar toolbar;
 
53
                
 
54
                bool updating;
 
55
                
 
56
                public CombinedDesignView (IViewContent content)
 
57
                {
 
58
                        this.content = content;
 
59
                        
 
60
                        content.ContentChanged += new EventHandler (OnTextContentChanged);
 
61
                        content.DirtyChanged += new EventHandler (OnTextDirtyChanged);
 
62
                        
 
63
                        notebook = new Gtk.Notebook ();
 
64
                        
 
65
                        // Main notebook
 
66
                        
 
67
                        notebook.TabPos = Gtk.PositionType.Bottom;
 
68
                        notebook.ShowTabs = false;
 
69
                        notebook.Show ();
 
70
                        box = new VBox ();
 
71
                        
 
72
                        // Bottom toolbar
 
73
                        
 
74
                        toolbar = new Toolbar ();
 
75
                        toolbar.IconSize = IconSize.SmallToolbar;
 
76
                        toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
 
77
                        toolbar.ShowArrow = false;
 
78
                        
 
79
                        AddButton (GettextCatalog.GetString ("Source Code"), content.Control).Active = true;
 
80
                        
 
81
                        toolbar.ShowAll ();
 
82
                        
 
83
                        box.PackStart (notebook, true, true, 0);
 
84
                        box.PackStart (toolbar, false, false, 0);
 
85
                        
 
86
                        box.Show ();
 
87
                        
 
88
                        IdeApp.Workbench.ActiveDocumentChanged += new EventHandler (OnActiveDocumentChanged);
 
89
                }
 
90
                
 
91
                protected ToggleToolButton AddButton (string label, Gtk.Widget page)
 
92
                {
 
93
                        updating = true;
 
94
                        ToggleToolButton button = new ToggleToolButton ();
 
95
                        button.Label = label;
 
96
                        button.IsImportant = true;
 
97
                        button.Clicked += new EventHandler (OnButtonToggled);
 
98
                        button.ShowAll ();
 
99
                        toolbar.Insert (button, -1);
 
100
                        notebook.AppendPage (page, new Gtk.Label ());
 
101
                        updating = false;
 
102
                        return button;
 
103
                }
 
104
                
 
105
                public override MonoDevelop.Projects.Project Project {
 
106
                        get { return base.Project; }
 
107
                        set { 
 
108
                                base.Project = value; 
 
109
                                content.Project = value; 
 
110
                        }
 
111
                }
 
112
                
 
113
                protected override void OnWorkbenchWindowChanged (EventArgs e)
 
114
                {
 
115
                        base.OnWorkbenchWindowChanged (e);
 
116
                        content.WorkbenchWindow = WorkbenchWindow;
 
117
                }
 
118
                
 
119
                void OnButtonToggled (object s, EventArgs args)
 
120
                {
 
121
                        int i = Array.IndexOf (toolbar.Children, s);
 
122
                        if (i != -1)
 
123
                                ShowPage (i);
 
124
                }
 
125
                
 
126
                protected void ShowPage (int npage)
 
127
                {
 
128
                        if (notebook.CurrentPage == npage)
 
129
                                return;
 
130
                                
 
131
                        if (updating) return;
 
132
                        updating = true;
 
133
                        
 
134
                        notebook.CurrentPage = npage;
 
135
                        Gtk.Widget[] buttons = toolbar.Children;
 
136
                        for (int n=0; n<buttons.Length; n++) {
 
137
                                ToggleToolButton b = (ToggleToolButton) buttons [n];
 
138
                                b.Active = (n == npage);
 
139
                        }
 
140
 
 
141
                        updating = false;
 
142
                }
 
143
                
 
144
                public override void Dispose ()
 
145
                {
 
146
                        content.ContentChanged -= new EventHandler (OnTextContentChanged);
 
147
                        content.DirtyChanged -= new EventHandler (OnTextDirtyChanged);
 
148
                        IdeApp.Workbench.ActiveDocumentChanged -= new EventHandler (OnActiveDocumentChanged);
 
149
                        base.Dispose ();
 
150
                }
 
151
                
 
152
                public override void Load (string fileName)
 
153
                {
 
154
                        ContentName = fileName;
 
155
                        content.Load (fileName);
 
156
                }
 
157
                
 
158
                public override Gtk.Widget Control {
 
159
                        get { return box; }
 
160
                }
 
161
                
 
162
                public override void Save (string fileName)
 
163
                {
 
164
                        content.Save (fileName);
 
165
                }
 
166
                
 
167
                public override bool IsDirty {
 
168
                        get {
 
169
                                return content.IsDirty;
 
170
                        }
 
171
                        set {
 
172
                                content.IsDirty = value;
 
173
                        }
 
174
                }
 
175
                
 
176
                public override bool IsReadOnly
 
177
                {
 
178
                        get {
 
179
                                return content.IsReadOnly;
 
180
                        }
 
181
                }
 
182
                
 
183
                public virtual void AddCurrentWidgetToClass ()
 
184
                {
 
185
                }
 
186
                
 
187
                public virtual void JumpToSignalHandler (Stetic.Signal signal)
 
188
                {
 
189
                }
 
190
                
 
191
                void OnTextContentChanged (object s, EventArgs args)
 
192
                {
 
193
                        OnContentChanged (args);
 
194
                }
 
195
                
 
196
                void OnTextDirtyChanged (object s, EventArgs args)
 
197
                {
 
198
                        OnDirtyChanged (args);
 
199
                }
 
200
                
 
201
                void OnActiveDocumentChanged (object s, EventArgs args)
 
202
                {
 
203
                        if (IdeApp.Workbench.ActiveDocument.Content == this)
 
204
                                OnDocumentActivated ();
 
205
                }
 
206
                
 
207
                protected virtual void OnDocumentActivated ()
 
208
                {
 
209
                }
 
210
                
 
211
                /* IEditableTextBuffer **********************/
 
212
                
 
213
                public IClipboardHandler ClipboardHandler {
 
214
                        get { return ((IEditableTextBuffer)content).ClipboardHandler; }
 
215
                }
 
216
                
 
217
                public void Undo()
 
218
                {
 
219
                        ((IEditableTextBuffer)content).Undo ();
 
220
                }
 
221
                
 
222
                public void Redo()
 
223
                {
 
224
                        ((IEditableTextBuffer)content).Redo ();
 
225
                }
 
226
                
 
227
                public string SelectedText {
 
228
                        get { return ((IEditableTextBuffer)content).SelectedText; } 
 
229
                        set { ((IEditableTextBuffer)content).SelectedText = value; }
 
230
                }
 
231
                
 
232
                public event EventHandler TextChanged {
 
233
                        add { ((IEditableTextBuffer)content).TextChanged += value; }
 
234
                        remove { ((IEditableTextBuffer)content).TextChanged -= value; }
 
235
                }
 
236
                
 
237
                public void InsertText (int position, string text)
 
238
                {
 
239
                        ((IEditableTextBuffer)content).InsertText (position, text);
 
240
                }
 
241
                
 
242
                public void DeleteText (int position, int length)
 
243
                {
 
244
                        ((IEditableTextBuffer)content).DeleteText (position, length);
 
245
                }
 
246
                
 
247
                /* IEncodedTextContent **************/
 
248
                
 
249
                public string SourceEncoding {
 
250
                        get { return ((IEncodedTextContent)content).SourceEncoding; }
 
251
                }
 
252
                
 
253
                public void Save (string fileName, string encoding)
 
254
                {
 
255
                        ((IEncodedTextContent)content).Save (fileName, encoding);
 
256
                }
 
257
                
 
258
                public void Load (string fileName, string encoding)
 
259
                {
 
260
                        ((IEncodedTextContent)content).Load (fileName, encoding);
 
261
                }
 
262
                
 
263
                /* ITextBuffer **********************/
 
264
                
 
265
                public string Name {
 
266
                        get { return ((ITextFile)content).Name; } 
 
267
                }
 
268
                
 
269
                public int Length {
 
270
                        get { return ((ITextFile)content).Length; } 
 
271
                }
 
272
                
 
273
                public string Text {
 
274
                        get { return ((IEditableTextFile)content).Text; }
 
275
                        set { ((IEditableTextFile)content).Text = value; }
 
276
                }
 
277
                
 
278
                public int CursorPosition {
 
279
                        get { return ((ITextBuffer)content).CursorPosition; } 
 
280
                        set { ((ITextBuffer)content).CursorPosition = value; }
 
281
                }
 
282
 
 
283
                public int SelectionStartPosition {
 
284
                        get { return ((ITextBuffer)content).SelectionStartPosition; } 
 
285
                }
 
286
                public int SelectionEndPosition {
 
287
                        get { return ((ITextBuffer)content).SelectionEndPosition; } 
 
288
                }
 
289
                
 
290
                public string GetText (int startPosition, int endPosition)
 
291
                {
 
292
                        return ((ITextBuffer)content).GetText (startPosition, endPosition);
 
293
                }
 
294
                
 
295
                public void Select (int startPosition, int endPosition)
 
296
                {
 
297
                        ((ITextBuffer)content).Select (startPosition, endPosition);
 
298
                }
 
299
                
 
300
                public void ShowPosition (int position)
 
301
                {
 
302
                        ((ITextBuffer)content).ShowPosition (position);
 
303
                }
 
304
                
 
305
                public int GetPositionFromLineColumn (int line, int column)
 
306
                {
 
307
                        return ((ITextBuffer)content).GetPositionFromLineColumn (line, column);
 
308
                }
 
309
                
 
310
                public void GetLineColumnFromPosition (int position, out int line, out int column)
 
311
                {
 
312
                        ((ITextBuffer)content).GetLineColumnFromPosition (position, out line, out column);
 
313
                }
 
314
                
 
315
                /* IPositionable **********************/
 
316
                
 
317
                public void JumpTo(int line, int column)
 
318
                {
 
319
                        ShowPage (0);
 
320
                        ((IPositionable)content).JumpTo (line, column);
 
321
                }
 
322
                
 
323
                /* IBookmarkBuffer **********************/
 
324
                
 
325
                public void SetBookmarked (int position, bool mark)
 
326
                {
 
327
                        ((IBookmarkBuffer)content).SetBookmarked (position, mark);
 
328
                }
 
329
                
 
330
                public bool IsBookmarked (int position)
 
331
                {
 
332
                        return ((IBookmarkBuffer)content).IsBookmarked (position);
 
333
                }
 
334
                
 
335
                public void PrevBookmark ()
 
336
                {
 
337
                        ((IBookmarkBuffer)content).PrevBookmark ();
 
338
                }
 
339
                
 
340
                public void NextBookmark ()
 
341
                {
 
342
                        ((IBookmarkBuffer)content).NextBookmark ();
 
343
                }
 
344
                
 
345
                public void ClearBookmarks ()
 
346
                {
 
347
                        ((IBookmarkBuffer)content).ClearBookmarks ();
 
348
                }
 
349
                
 
350
                /* IDebuggableEditor **********************/
 
351
                
 
352
                public void ExecutingAt (int lineNumber)
 
353
                {
 
354
                        ((IDebuggableEditor)content).ExecutingAt (lineNumber);
 
355
                }
 
356
                
 
357
                public void ClearExecutingAt (int lineNumber)
 
358
                {
 
359
                        ((IDebuggableEditor)content).ExecutingAt (lineNumber);
 
360
                }
 
361
                
 
362
                /* ICodeStyleOperations **********************/
 
363
                
 
364
                public void CommentCode ()
 
365
                {
 
366
                        ((ICodeStyleOperations)content).CommentCode ();
 
367
                }
 
368
                
 
369
                public void UncommentCode ()
 
370
                {
 
371
                        ((ICodeStyleOperations)content).UncommentCode ();
 
372
                }
 
373
                
 
374
                public void IndentSelection ()
 
375
                {
 
376
                        ((ICodeStyleOperations)content).IndentSelection ();
 
377
                }
 
378
                
 
379
                public void UnIndentSelection ()
 
380
                {
 
381
                        ((ICodeStyleOperations)content).UnIndentSelection ();
 
382
                }
 
383
                                
 
384
                /* IDocumentInformation **********************/
 
385
                
 
386
                public string FileName {
 
387
                        get { return ((IDocumentInformation)content).FileName; }
 
388
                }
 
389
                
 
390
                public ITextIterator GetTextIterator ()
 
391
                {
 
392
                        return ((IDocumentInformation)content).GetTextIterator ();
 
393
                }
 
394
                
 
395
                public string GetLineTextAtOffset (int offset)
 
396
                {
 
397
                        return ((IDocumentInformation)content).GetLineTextAtOffset (offset);
 
398
                }
 
399
        }
 
400
}
 
401