1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
using System;
using Gtk;
using Mono.Addins;
using TextEditor;
public partial class MainWindow: Gtk.Window
{
internal static MainWindow Instance;
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Instance = this;
Build ();
AddinManager.ExtensionChanged += OnExtensionChanged;
BuildToolbar ();
BuildMenu ();
}
public void ConsoleWrite (string txt)
{
console.Show ();
consoleView.Buffer.Text += txt;
consoleView.ScrollToMark (consoleView.Buffer.InsertMark, 0d, false, 0d, 0d);
}
void BuildToolbar ()
{
// Clean the toolbar
foreach (Gtk.Widget w in toolbar.Children)
toolbar.Remove (w);
// Add the new buttons
foreach (ToolbarNode node in AddinManager.GetExtensionNodes ("/TextEditor/ToolbarButtons"))
toolbar.Insert (node.GetToolItem (), -1);
toolbar.ShowAll ();
}
void BuildMenu ()
{
// Clean the toolbar
foreach (Gtk.Widget w in menubar.Children)
menubar.Remove (w);
// Add the new buttons
foreach (MenuNode node in AddinManager.GetExtensionNodes ("/TextEditor/MainMenu"))
menubar.Insert (node.GetMenuItem (), -1);
// Create the menu for creating documents from templates
Gtk.Menu menu = BuildTemplateItems (AddinManager.GetExtensionNodes ("/TextEditor/Templates"));
Gtk.MenuItem it = new MenuItem ("New From Template");
it.Submenu = menu;
Gtk.MenuItem men = (Gtk.MenuItem) menubar.Children [0];
((Gtk.Menu)men.Submenu).Insert (it, 1);
menubar.ShowAll ();
}
Gtk.Menu BuildTemplateItems (ExtensionNodeList nodes)
{
Gtk.Menu menu = new Gtk.Menu ();
foreach (ExtensionNode tn in nodes) {
Gtk.MenuItem item;
if (tn is TemplateCategoryNode) {
TemplateCategoryNode cat = (TemplateCategoryNode) tn;
item = new Gtk.MenuItem (cat.Name);
item.Submenu = BuildTemplateItems (cat.ChildNodes);
}
else {
FileTemplateNode t = (FileTemplateNode) tn;
item = new Gtk.MenuItem (t.Name);
item.Activated += delegate {
TextEditor.TextEditorApp.NewFile (t.GetContent ());
};
}
menu.Insert (item, -1);
}
return menu;
}
void OnExtensionChanged (object o, ExtensionEventArgs args)
{
if (args.PathChanged ("/TextEditor/ToolbarButtons"))
BuildToolbar ();
else if (args.PathChanged ("/TextEditor/MainMenu") || args.PathChanged ("/TextEditor/Templates"))
BuildMenu ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButton1Clicked(object sender, System.EventArgs e)
{
console.Hide ();
}
public Gtk.TextView View {
get { return textview; }
}
}
|