2
// CombinedDesignView.cs
7
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
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.
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;
44
namespace MonoDevelop.GtkCore.GuiBuilder
46
public class CombinedDesignView : AbstractViewContent, IEditableTextBuffer, IPositionable, IBookmarkBuffer, IDebuggableEditor, ICodeStyleOperations,
47
IDocumentInformation, IEncodedTextContent
50
Gtk.Notebook notebook;
56
public CombinedDesignView (IViewContent content)
58
this.content = content;
60
content.ContentChanged += new EventHandler (OnTextContentChanged);
61
content.DirtyChanged += new EventHandler (OnTextDirtyChanged);
63
notebook = new Gtk.Notebook ();
67
notebook.TabPos = Gtk.PositionType.Bottom;
68
notebook.ShowTabs = false;
74
toolbar = new Toolbar ();
75
toolbar.IconSize = IconSize.SmallToolbar;
76
toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
77
toolbar.ShowArrow = false;
79
AddButton (GettextCatalog.GetString ("Source Code"), content.Control).Active = true;
83
box.PackStart (notebook, true, true, 0);
84
box.PackStart (toolbar, false, false, 0);
88
IdeApp.Workbench.ActiveDocumentChanged += new EventHandler (OnActiveDocumentChanged);
91
protected ToggleToolButton AddButton (string label, Gtk.Widget page)
94
ToggleToolButton button = new ToggleToolButton ();
96
button.IsImportant = true;
97
button.Clicked += new EventHandler (OnButtonToggled);
99
toolbar.Insert (button, -1);
100
notebook.AppendPage (page, new Gtk.Label ());
105
public override MonoDevelop.Projects.Project Project {
106
get { return base.Project; }
108
base.Project = value;
109
content.Project = value;
113
protected override void OnWorkbenchWindowChanged (EventArgs e)
115
base.OnWorkbenchWindowChanged (e);
116
content.WorkbenchWindow = WorkbenchWindow;
119
void OnButtonToggled (object s, EventArgs args)
121
int i = Array.IndexOf (toolbar.Children, s);
126
protected void ShowPage (int npage)
128
if (notebook.CurrentPage == npage)
131
if (updating) return;
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);
144
public override void Dispose ()
146
content.ContentChanged -= new EventHandler (OnTextContentChanged);
147
content.DirtyChanged -= new EventHandler (OnTextDirtyChanged);
148
IdeApp.Workbench.ActiveDocumentChanged -= new EventHandler (OnActiveDocumentChanged);
152
public override void Load (string fileName)
154
ContentName = fileName;
155
content.Load (fileName);
158
public override Gtk.Widget Control {
162
public override void Save (string fileName)
164
content.Save (fileName);
167
public override bool IsDirty {
169
return content.IsDirty;
172
content.IsDirty = value;
176
public override bool IsReadOnly
179
return content.IsReadOnly;
183
public virtual void AddCurrentWidgetToClass ()
187
public virtual void JumpToSignalHandler (Stetic.Signal signal)
191
void OnTextContentChanged (object s, EventArgs args)
193
OnContentChanged (args);
196
void OnTextDirtyChanged (object s, EventArgs args)
198
OnDirtyChanged (args);
201
void OnActiveDocumentChanged (object s, EventArgs args)
203
if (IdeApp.Workbench.ActiveDocument.Content == this)
204
OnDocumentActivated ();
207
protected virtual void OnDocumentActivated ()
211
/* IEditableTextBuffer **********************/
213
public IClipboardHandler ClipboardHandler {
214
get { return ((IEditableTextBuffer)content).ClipboardHandler; }
219
((IEditableTextBuffer)content).Undo ();
224
((IEditableTextBuffer)content).Redo ();
227
public string SelectedText {
228
get { return ((IEditableTextBuffer)content).SelectedText; }
229
set { ((IEditableTextBuffer)content).SelectedText = value; }
232
public event EventHandler TextChanged {
233
add { ((IEditableTextBuffer)content).TextChanged += value; }
234
remove { ((IEditableTextBuffer)content).TextChanged -= value; }
237
public void InsertText (int position, string text)
239
((IEditableTextBuffer)content).InsertText (position, text);
242
public void DeleteText (int position, int length)
244
((IEditableTextBuffer)content).DeleteText (position, length);
247
/* IEncodedTextContent **************/
249
public string SourceEncoding {
250
get { return ((IEncodedTextContent)content).SourceEncoding; }
253
public void Save (string fileName, string encoding)
255
((IEncodedTextContent)content).Save (fileName, encoding);
258
public void Load (string fileName, string encoding)
260
((IEncodedTextContent)content).Load (fileName, encoding);
263
/* ITextBuffer **********************/
266
get { return ((ITextFile)content).Name; }
270
get { return ((ITextFile)content).Length; }
274
get { return ((IEditableTextFile)content).Text; }
275
set { ((IEditableTextFile)content).Text = value; }
278
public int CursorPosition {
279
get { return ((ITextBuffer)content).CursorPosition; }
280
set { ((ITextBuffer)content).CursorPosition = value; }
283
public int SelectionStartPosition {
284
get { return ((ITextBuffer)content).SelectionStartPosition; }
286
public int SelectionEndPosition {
287
get { return ((ITextBuffer)content).SelectionEndPosition; }
290
public string GetText (int startPosition, int endPosition)
292
return ((ITextBuffer)content).GetText (startPosition, endPosition);
295
public void Select (int startPosition, int endPosition)
297
((ITextBuffer)content).Select (startPosition, endPosition);
300
public void ShowPosition (int position)
302
((ITextBuffer)content).ShowPosition (position);
305
public int GetPositionFromLineColumn (int line, int column)
307
return ((ITextBuffer)content).GetPositionFromLineColumn (line, column);
310
public void GetLineColumnFromPosition (int position, out int line, out int column)
312
((ITextBuffer)content).GetLineColumnFromPosition (position, out line, out column);
315
/* IPositionable **********************/
317
public void JumpTo(int line, int column)
320
((IPositionable)content).JumpTo (line, column);
323
/* IBookmarkBuffer **********************/
325
public void SetBookmarked (int position, bool mark)
327
((IBookmarkBuffer)content).SetBookmarked (position, mark);
330
public bool IsBookmarked (int position)
332
return ((IBookmarkBuffer)content).IsBookmarked (position);
335
public void PrevBookmark ()
337
((IBookmarkBuffer)content).PrevBookmark ();
340
public void NextBookmark ()
342
((IBookmarkBuffer)content).NextBookmark ();
345
public void ClearBookmarks ()
347
((IBookmarkBuffer)content).ClearBookmarks ();
350
/* IDebuggableEditor **********************/
352
public void ExecutingAt (int lineNumber)
354
((IDebuggableEditor)content).ExecutingAt (lineNumber);
357
public void ClearExecutingAt (int lineNumber)
359
((IDebuggableEditor)content).ExecutingAt (lineNumber);
362
/* ICodeStyleOperations **********************/
364
public void CommentCode ()
366
((ICodeStyleOperations)content).CommentCode ();
369
public void UncommentCode ()
371
((ICodeStyleOperations)content).UncommentCode ();
374
public void IndentSelection ()
376
((ICodeStyleOperations)content).IndentSelection ();
379
public void UnIndentSelection ()
381
((ICodeStyleOperations)content).UnIndentSelection ();
384
/* IDocumentInformation **********************/
386
public string FileName {
387
get { return ((IDocumentInformation)content).FileName; }
390
public ITextIterator GetTextIterator ()
392
return ((IDocumentInformation)content).GetTextIterator ();
395
public string GetLineTextAtOffset (int offset)
397
return ((IDocumentInformation)content).GetLineTextAtOffset (offset);