[longomatch] Add OS X integration for menus and dock
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add OS X integration for menus and dock
- Date: Fri, 30 Jan 2015 10:54:36 +0000 (UTC)
commit dcb6b4608590db95ff7e3439b33360026abdfb8c
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Fri Jan 30 11:52:56 2015 +0100
Add OS X integration for menus and dock
LongoMatch.GUI/Gui/MainWindow.cs | 22 ++-
LongoMatch/GtkOSXApplication.cs | 386 ++++++++++++++++++++++++++++++++++++++
LongoMatch/LongoMatch.csproj | 1 +
LongoMatch/Main.cs | 13 ++
LongoMatch/Makefile.am | 1 +
5 files changed, 415 insertions(+), 8 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index 11accee..ac60e59 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -72,6 +72,11 @@ namespace LongoMatch.Gui
}
}
+ public MenuShell Menu {
+ get {
+ return menubar1;
+ }
+ }
public void SetPanel (Widget panel)
{
if (panel == null) {
@@ -147,6 +152,15 @@ namespace LongoMatch.Gui
panel.Name = "newprojectpanel";
SetPanel (panel);
}
+
+ public void CloseAndQuit ()
+ {
+ Config.EventsBroker.EmitCloseOpenedProject ();
+ if (openedProject == null) {
+ Config.EventsBroker.EmitQuitApplication ();
+ }
+ }
+
#endregion
#region Private Methods
protected override bool OnKeyPressEvent (EventKey evnt)
@@ -265,14 +279,6 @@ namespace LongoMatch.Gui
SaveProjectAction.Sensitive = sensitive2;
}
- private void CloseAndQuit ()
- {
- Config.EventsBroker.EmitCloseOpenedProject ();
- if (openedProject == null) {
- Config.EventsBroker.EmitQuitApplication ();
- }
- }
-
protected override bool OnDeleteEvent (Event evnt)
{
CloseAndQuit ();
diff --git a/LongoMatch/GtkOSXApplication.cs b/LongoMatch/GtkOSXApplication.cs
new file mode 100644
index 0000000..047efdf
--- /dev/null
+++ b/LongoMatch/GtkOSXApplication.cs
@@ -0,0 +1,386 @@
+// This file was generated by the Gtk# code generator.
+// Any changes made will be lost if regenerated.
+
+#if OSTYPE_OS_X
+namespace LongoMatch {
+
+ using System;
+ using System.Collections;
+ using System.Runtime.InteropServices;
+
+#region Autogenerated code
+ public class GtkOSXApplication : GLib.Object {
+
+ [Obsolete]
+ protected GtkOSXApplication(GLib.GType gtype) : base(gtype) {}
+ public GtkOSXApplication(IntPtr raw) : base(raw) {}
+
+ public GtkOSXApplication() : base(IntPtr.Zero)
+ {
+ CreateNativeObject (new string [0], new GLib.Value [0]);
+ }
+
+ [GLib.CDeclCallback]
+ delegate void NSApplicationWillResignActiveVMDelegate (IntPtr inst);
+
+ static NSApplicationWillResignActiveVMDelegate NSApplicationWillResignActiveVMCallback;
+
+ static void nsapplicationwillresignactive_cb (IntPtr inst)
+ {
+ try {
+ GtkOSXApplication inst_managed = GLib.Object.GetObject (inst, false) as
GtkOSXApplication;
+ inst_managed.OnNSApplicationWillResignActive ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ }
+ }
+
+ private static void OverrideNSApplicationWillResignActive (GLib.GType gtype)
+ {
+ if (NSApplicationWillResignActiveVMCallback == null)
+ NSApplicationWillResignActiveVMCallback = new
NSApplicationWillResignActiveVMDelegate (nsapplicationwillresignactive_cb);
+ OverrideVirtualMethod (gtype, "NSApplicationWillResignActive",
NSApplicationWillResignActiveVMCallback);
+ }
+
+ [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.GtkOSXApplication),
ConnectionMethod="OverrideNSApplicationWillResignActive")]
+ protected virtual void OnNSApplicationWillResignActive ()
+ {
+ GLib.Value ret = GLib.Value.Empty;
+ GLib.ValueArray inst_and_params = new GLib.ValueArray (1);
+ GLib.Value[] vals = new GLib.Value [1];
+ vals [0] = new GLib.Value (this);
+ inst_and_params.Append (vals [0]);
+ g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
+ foreach (GLib.Value v in vals)
+ v.Dispose ();
+ }
+
+ [GLib.Signal("NSApplicationWillResignActive")]
+ public event System.EventHandler NSApplicationWillResignActive {
+ add {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationWillResignActive");
+ sig.AddDelegate (value);
+ }
+ remove {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationWillResignActive");
+ sig.RemoveDelegate (value);
+ }
+ }
+
+ [GLib.CDeclCallback]
+ delegate void NSApplicationDidBecomeActiveVMDelegate (IntPtr inst);
+
+ static NSApplicationDidBecomeActiveVMDelegate NSApplicationDidBecomeActiveVMCallback;
+
+ static void nsapplicationdidbecomeactive_cb (IntPtr inst)
+ {
+ try {
+ GtkOSXApplication inst_managed = GLib.Object.GetObject (inst, false) as
GtkOSXApplication;
+ inst_managed.OnNSApplicationDidBecomeActive ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ }
+ }
+
+ private static void OverrideNSApplicationDidBecomeActive (GLib.GType gtype)
+ {
+ if (NSApplicationDidBecomeActiveVMCallback == null)
+ NSApplicationDidBecomeActiveVMCallback = new
NSApplicationDidBecomeActiveVMDelegate (nsapplicationdidbecomeactive_cb);
+ OverrideVirtualMethod (gtype, "NSApplicationDidBecomeActive",
NSApplicationDidBecomeActiveVMCallback);
+ }
+
+ [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.GtkOSXApplication),
ConnectionMethod="OverrideNSApplicationDidBecomeActive")]
+ protected virtual void OnNSApplicationDidBecomeActive ()
+ {
+ GLib.Value ret = GLib.Value.Empty;
+ GLib.ValueArray inst_and_params = new GLib.ValueArray (1);
+ GLib.Value[] vals = new GLib.Value [1];
+ vals [0] = new GLib.Value (this);
+ inst_and_params.Append (vals [0]);
+ g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
+ foreach (GLib.Value v in vals)
+ v.Dispose ();
+ }
+
+ [GLib.Signal("NSApplicationDidBecomeActive")]
+ public event System.EventHandler NSApplicationDidBecomeActive {
+ add {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationDidBecomeActive");
+ sig.AddDelegate (value);
+ }
+ remove {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationDidBecomeActive");
+ sig.RemoveDelegate (value);
+ }
+ }
+
+ [GLib.CDeclCallback]
+ delegate bool NSApplicationOpenFileVMDelegate (IntPtr inst, IntPtr p0);
+
+ static NSApplicationOpenFileVMDelegate NSApplicationOpenFileVMCallback;
+
+ static bool nsapplicationopenfile_cb (IntPtr inst, IntPtr p0)
+ {
+ try {
+ GtkOSXApplication inst_managed = GLib.Object.GetObject (inst, false) as
GtkOSXApplication;
+ return inst_managed.OnNSApplicationOpenFile
(GLib.Marshaller.PtrToStringGFree(p0));
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, true);
+ // NOTREACHED: above call doesn't return
+ throw e;
+ }
+ }
+
+ private static void OverrideNSApplicationOpenFile (GLib.GType gtype)
+ {
+ if (NSApplicationOpenFileVMCallback == null)
+ NSApplicationOpenFileVMCallback = new NSApplicationOpenFileVMDelegate
(nsapplicationopenfile_cb);
+ OverrideVirtualMethod (gtype, "NSApplicationOpenFile",
NSApplicationOpenFileVMCallback);
+ }
+
+ [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.GtkOSXApplication),
ConnectionMethod="OverrideNSApplicationOpenFile")]
+ protected virtual bool OnNSApplicationOpenFile (string p0)
+ {
+ GLib.Value ret = new GLib.Value (GLib.GType.Boolean);
+ GLib.ValueArray inst_and_params = new GLib.ValueArray (2);
+ GLib.Value[] vals = new GLib.Value [2];
+ vals [0] = new GLib.Value (this);
+ inst_and_params.Append (vals [0]);
+ vals [1] = new GLib.Value (p0);
+ inst_and_params.Append (vals [1]);
+ g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
+ foreach (GLib.Value v in vals)
+ v.Dispose ();
+ bool result = (bool) ret;
+ ret.Dispose ();
+ return result;
+ }
+
+ [GLib.Signal("NSApplicationOpenFile")]
+ public event NSApplicationOpenFileHandler NSApplicationOpenFile {
+ add {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationOpenFile", typeof
(LongoMatch.NSApplicationOpenFileArgs));
+ sig.AddDelegate (value);
+ }
+ remove {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationOpenFile", typeof
(LongoMatch.NSApplicationOpenFileArgs));
+ sig.RemoveDelegate (value);
+ }
+ }
+
+ [GLib.CDeclCallback]
+ delegate void NSApplicationWillTerminateVMDelegate (IntPtr inst);
+
+ static NSApplicationWillTerminateVMDelegate NSApplicationWillTerminateVMCallback;
+
+ static void nsapplicationwillterminate_cb (IntPtr inst)
+ {
+ try {
+ GtkOSXApplication inst_managed = GLib.Object.GetObject (inst, false) as
GtkOSXApplication;
+ inst_managed.OnNSApplicationWillTerminate ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, false);
+ }
+ }
+
+ private static void OverrideNSApplicationWillTerminate (GLib.GType gtype)
+ {
+ if (NSApplicationWillTerminateVMCallback == null)
+ NSApplicationWillTerminateVMCallback = new
NSApplicationWillTerminateVMDelegate (nsapplicationwillterminate_cb);
+ OverrideVirtualMethod (gtype, "NSApplicationWillTerminate",
NSApplicationWillTerminateVMCallback);
+ }
+
+ [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.GtkOSXApplication),
ConnectionMethod="OverrideNSApplicationWillTerminate")]
+ protected virtual void OnNSApplicationWillTerminate ()
+ {
+ GLib.Value ret = GLib.Value.Empty;
+ GLib.ValueArray inst_and_params = new GLib.ValueArray (1);
+ GLib.Value[] vals = new GLib.Value [1];
+ vals [0] = new GLib.Value (this);
+ inst_and_params.Append (vals [0]);
+ g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
+ foreach (GLib.Value v in vals)
+ v.Dispose ();
+ }
+
+ [GLib.Signal("NSApplicationWillTerminate")]
+ public event System.EventHandler NSApplicationWillTerminate {
+ add {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationWillTerminate");
+ sig.AddDelegate (value);
+ }
+ remove {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationWillTerminate");
+ sig.RemoveDelegate (value);
+ }
+ }
+
+ [GLib.CDeclCallback]
+ delegate bool NSApplicationBlockTerminationVMDelegate (IntPtr inst);
+
+ static NSApplicationBlockTerminationVMDelegate NSApplicationBlockTerminationVMCallback;
+
+ static bool nsapplicationblocktermination_cb (IntPtr inst)
+ {
+ try {
+ GtkOSXApplication inst_managed = GLib.Object.GetObject (inst, false) as
GtkOSXApplication;
+ return inst_managed.OnNSApplicationBlockTermination ();
+ } catch (Exception e) {
+ GLib.ExceptionManager.RaiseUnhandledException (e, true);
+ // NOTREACHED: above call doesn't return
+ throw e;
+ }
+ }
+
+ private static void OverrideNSApplicationBlockTermination (GLib.GType gtype)
+ {
+ if (NSApplicationBlockTerminationVMCallback == null)
+ NSApplicationBlockTerminationVMCallback = new
NSApplicationBlockTerminationVMDelegate (nsapplicationblocktermination_cb);
+ OverrideVirtualMethod (gtype, "NSApplicationBlockTermination",
NSApplicationBlockTerminationVMCallback);
+ }
+
+ [GLib.DefaultSignalHandler(Type=typeof(LongoMatch.GtkOSXApplication),
ConnectionMethod="OverrideNSApplicationBlockTermination")]
+ protected virtual bool OnNSApplicationBlockTermination ()
+ {
+ GLib.Value ret = new GLib.Value (GLib.GType.Boolean);
+ GLib.ValueArray inst_and_params = new GLib.ValueArray (1);
+ GLib.Value[] vals = new GLib.Value [1];
+ vals [0] = new GLib.Value (this);
+ inst_and_params.Append (vals [0]);
+ g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
+ foreach (GLib.Value v in vals)
+ v.Dispose ();
+ bool result = (bool) ret;
+ ret.Dispose ();
+ return result;
+ }
+
+ [GLib.Signal("NSApplicationBlockTermination")]
+ public event NSApplicationBlockTerminationHandler NSApplicationBlockTermination {
+ add {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationBlockTermination",
typeof (LongoMatch.NSApplicationBlockTerminationArgs));
+ sig.AddDelegate (value);
+ }
+ remove {
+ GLib.Signal sig = GLib.Signal.Lookup (this, "NSApplicationBlockTermination",
typeof (LongoMatch.NSApplicationBlockTerminationArgs));
+ sig.RemoveDelegate (value);
+ }
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_ready(IntPtr raw);
+
+ public void Ready() {
+ gtk_osxapplication_ready(Handle);
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_set_dock_icon_resource(IntPtr raw, IntPtr name, IntPtr
type, IntPtr subdir);
+
+ public void SetDockIconResource(string name, string type, string subdir) {
+ IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
+ IntPtr native_type = GLib.Marshaller.StringToPtrGStrdup (type);
+ IntPtr native_subdir = GLib.Marshaller.StringToPtrGStrdup (subdir);
+ gtk_osxapplication_set_dock_icon_resource(Handle, native_name, native_type,
native_subdir);
+ GLib.Marshaller.Free (native_name);
+ GLib.Marshaller.Free (native_type);
+ GLib.Marshaller.Free (native_subdir);
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern int gtk_osxapplication_attention_request(IntPtr raw, int type);
+
+ public int AttentionRequest(GtkOSXApplicationAttentionType type) {
+ int raw_ret = gtk_osxapplication_attention_request(Handle, (int) type);
+ int ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_cancel_attention_request(IntPtr raw, int id);
+
+ public void CancelAttentionRequest(int id) {
+ gtk_osxapplication_cancel_attention_request(Handle, id);
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_sync_menubar(IntPtr raw);
+
+ public void SyncMenubar() {
+ gtk_osxapplication_sync_menubar(Handle);
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_set_menu_bar(IntPtr raw, IntPtr menu);
+
+ public void SetMenuBar (Gtk.MenuShell menu) {
+ gtk_osxapplication_set_menu_bar (Handle, menu.Handle);
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_set_use_quartz_accelerators(IntPtr raw, bool
use_quartz_accelerators);
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern bool gtk_osxapplication_use_quartz_accelerators(IntPtr raw);
+
+ public bool UseQuartzAccelerators {
+ set {
+ gtk_osxapplication_set_use_quartz_accelerators(Handle, value);
+ }
+ get {
+ bool raw_ret = gtk_osxapplication_use_quartz_accelerators(Handle);
+ bool ret = raw_ret;
+ return ret;
+ }
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern IntPtr gtk_osxapplication_get_type();
+
+ public static new GLib.GType GType {
+ get {
+ IntPtr raw_ret = gtk_osxapplication_get_type();
+ GLib.GType ret = new GLib.GType(raw_ret);
+ return ret;
+ }
+ }
+
+ [DllImport("libgtkmacintegration.0.dylib")]
+ static extern void gtk_osxapplication_cleanup(IntPtr raw);
+
+ public void Cleanup() {
+ gtk_osxapplication_cleanup(Handle);
+ }
+
+ static bool initialized = false;
+ static GtkOSXApplication ()
+ {
+ if (initialized)
+ return;
+ GLib.GType.Register (GtkOSXApplication.GType, typeof (GtkOSXApplication));
+ initialized = true;
+ }
+#endregion
+ }
+
+ public delegate void NSApplicationOpenFileHandler(object o, NSApplicationOpenFileArgs args);
+ public class NSApplicationOpenFileArgs : GLib.SignalArgs {
+ public string P0{
+ get {
+ return (string) Args [0];
+ }
+ }
+ }
+
+ public delegate void NSApplicationBlockTerminationHandler(object o, NSApplicationBlockTerminationArgs
args);
+ public class NSApplicationBlockTerminationArgs : GLib.SignalArgs {}
+
+ public class GtkMacAttentionRequest : GLib.Opaque {
+ public GtkMacAttentionRequest(IntPtr raw) : base(raw) {}
+ }
+
+ public enum GtkOSXApplicationAttentionType {
+ CriticalRequest = 0,
+ InfoRequest = 10,
+ }
+}
+#endif
\ No newline at end of file
diff --git a/LongoMatch/LongoMatch.csproj b/LongoMatch/LongoMatch.csproj
index f3dc817..9632d23 100644
--- a/LongoMatch/LongoMatch.csproj
+++ b/LongoMatch/LongoMatch.csproj
@@ -41,6 +41,7 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
+ <Compile Include="GtkOSXApplication.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
diff --git a/LongoMatch/Main.cs b/LongoMatch/Main.cs
index dfa3c6d..0647516 100644
--- a/LongoMatch/Main.cs
+++ b/LongoMatch/Main.cs
@@ -84,6 +84,19 @@ namespace LongoMatch
}
AddinsManager.LoadDashboards (Config.CategoriesTemplatesProvider);
AddinsManager.LoadImportProjectAddins (CoreServices.ProjectsImporter);
+
+ #if OSTYPE_OS_X
+ GtkOSXApplication app = new GtkOSXApplication ();
+ MainWindow window = Config.GUIToolkit.MainController as MainWindow;
+ app.NSApplicationBlockTermination += (o, a) => {
+ window.CloseAndQuit();
+ };
+ app.SetMenuBar (window.Menu);
+ window.Menu.Visible = false;
+ app.UseQuartzAccelerators = false;
+ app.Ready ();
+ #endif
+
Application.Run ();
} catch (AddinRequestShutdownException arse) {
// Abort gracefully
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index 977a241..7879793 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -3,6 +3,7 @@ TARGET = exe
LINK = $(REF_DEP_LONGOMATCH)
SOURCES = AssemblyInfo.cs \
+ GtkOSXApplication.cs \
Main.cs
IMAGES = $(top_srcdir)/images/logo.svg \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]