|
|
@@ -15,14 +15,8 @@ namespace UnitEditor
|
|
|
{
|
|
|
public Gtk.UIManager uim = null;
|
|
|
public Gtk.MenuBar instance;
|
|
|
- /*
|
|
|
- The first required piece is the XML definition.
|
|
|
-
|
|
|
- The following is a hard-coded definition of a Gtk.MenuBar control (widget).
|
|
|
- However, automation can come into play here by constructing the inner-XElements and building out.
|
|
|
- Consider using a string formatting function to take a name in a list like "Zoom In", using that as-is
|
|
|
- for the name of the Gtk.MenuItem, and using it again (after removing spaces) for the action name.
|
|
|
- */
|
|
|
+
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
private XDocument UI = new XDocument (
|
|
|
new XElement ("ui",
|
|
|
new XElement ("menubar",
|
|
|
@@ -65,6 +59,7 @@ namespace UnitEditor
|
|
|
)
|
|
|
);
|
|
|
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
private Dictionary<string, string> keys = new Dictionary<string, string> () {
|
|
|
{"New", "<Control>n"},
|
|
|
{"Open", "<Control>o"},
|
|
|
@@ -91,6 +86,7 @@ namespace UnitEditor
|
|
|
{"GoToLine", "<Control>g"}
|
|
|
};
|
|
|
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
public Gtk.ActionEntry[] getActionEntries ()
|
|
|
{
|
|
|
return new Gtk.ActionEntry[] {
|
|
|
@@ -102,7 +98,7 @@ namespace UnitEditor
|
|
|
new Gtk.ActionEntry ("SaveAll", null, "Save All", (keys.ContainsKey ("SaveAll")) ? keys ["SaveAll"] : null, null, null),
|
|
|
new Gtk.ActionEntry ("Close", null, "Close", (keys.ContainsKey ("Close")) ? keys ["Close"] : null, null, null),
|
|
|
new Gtk.ActionEntry ("CloseAll", null, "Close All", (keys.ContainsKey ("CloseAll")) ? keys ["CloseAll"] : null, null, null),
|
|
|
- new Gtk.ActionEntry ("Quit", null, "Quit", (keys.ContainsKey ("Quit")) ? keys ["Quit"] : null, null, exit_cb),
|
|
|
+ new Gtk.ActionEntry ("Quit", null, "Quit", (keys.ContainsKey ("Quit")) ? keys ["Quit"] : null, null, (EventHandler)quit_cb),
|
|
|
|
|
|
new Gtk.ActionEntry ("EditMenu", null, "_Edit", null, null, null),
|
|
|
new Gtk.ActionEntry ("Undo", null, "Undo", (keys.ContainsKey ("Undo")) ? keys ["Undo"] : null, null, null),
|
|
|
@@ -125,32 +121,27 @@ namespace UnitEditor
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
public MainMenu ()
|
|
|
{
|
|
|
- Build ();
|
|
|
- // Create a random string to attach to our base action group name (see WARNING).
|
|
|
- Guid guid = Guid.NewGuid ();
|
|
|
- // Recreate the UIManager that links the action entries with controls (widgets) created from an XML definition.
|
|
|
uim = new Gtk.UIManager ();
|
|
|
|
|
|
- Gtk.ActionGroup actions = new Gtk.ActionGroup ("MenuBarActions" + guid.ToString ());
|
|
|
- // Get all the action entries (that is, actions for menu items, toggled menu items, radio menu items).
|
|
|
+ Gtk.ActionGroup actions = new Gtk.ActionGroup ("MenuBarActions" + Guid.NewGuid ());
|
|
|
+
|
|
|
actions.Add (getActionEntries ());
|
|
|
- // Put the action entry definitions into the UIManager's buffer.
|
|
|
uim.InsertActionGroup (actions, 0);
|
|
|
+
|
|
|
// Put the XML definition of the controls (widgets) into the UIManager's buffer -and- create controls (widgets).
|
|
|
uim.AddUiFromString (UI.ToString ());
|
|
|
- // Get the menubar created in the previous space.
|
|
|
+
|
|
|
instance = (Gtk.MenuBar)uim.GetWidget ("/menubar");
|
|
|
- // Mark everything on the menubar to be shown.
|
|
|
instance.ShowAll ();
|
|
|
}
|
|
|
|
|
|
- static void exit_cb (object o, EventArgs args)
|
|
|
- {
|
|
|
- Application.Quit ();
|
|
|
- }
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
+ static void new_cb(object sender, DeleteEventArgs args) {}
|
|
|
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
static void open_cb(object sender, System.EventArgs args)
|
|
|
{
|
|
|
Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("Open file", null, FileChooserAction.Open);
|
|
|
@@ -166,14 +157,19 @@ namespace UnitEditor
|
|
|
{
|
|
|
UnitEditor.MainClass.g_win.open_unit (fc.Filename);
|
|
|
}
|
|
|
-
|
|
|
- //Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
|
|
|
fc.Destroy();
|
|
|
}
|
|
|
|
|
|
- static void save_cb(object sender, DeleteEventArgs args)
|
|
|
+ //------------------------------------------------------------------------------
|
|
|
+ static void save_cb(object sender, DeleteEventArgs args) {}
|
|
|
+ static void saveas_cb(object sender, DeleteEventArgs args) {}
|
|
|
+ static void saveall_cb(object sender, DeleteEventArgs args) {}
|
|
|
+ static void close_cb(object sender, DeleteEventArgs args) {}
|
|
|
+ static void closeall_cb(object sender, DeleteEventArgs args) {}
|
|
|
+
|
|
|
+ static void quit_cb (object o, EventArgs args)
|
|
|
{
|
|
|
-
|
|
|
+ Application.Quit ();
|
|
|
}
|
|
|
}
|
|
|
}
|