~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/MacPlatform.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
using MonoDevelop.Ide.Commands;
48
48
using MonoDevelop.Ide.Desktop;
49
49
using MonoDevelop.MacInterop;
 
50
using MonoDevelop.Components.MainToolbar;
 
51
using MonoDevelop.MacIntegration.MacMenu;
50
52
 
51
53
namespace MonoDevelop.MacIntegration
52
54
{
53
55
        public class MacPlatformService : PlatformService
54
56
        {
55
 
                static TimerCounter timer = InstrumentationService.CreateTimerCounter ("Mac Platform Initialization", "Platform Service");
56
 
                static TimerCounter mimeTimer = InstrumentationService.CreateTimerCounter ("Mac Mime Database", "Platform Service");
57
 
                
58
 
                static bool setupFail, initedApp, initedGlobal;
59
 
                
60
 
                static Lazy<Dictionary<string, string>> mimemap;
 
57
                const string monoDownloadUrl = "http://www.go-mono.com/mono-downloads/download.html";
 
58
 
 
59
                TimerCounter timer = InstrumentationService.CreateTimerCounter ("Mac Platform Initialization", "Platform Service");
 
60
                TimerCounter mimeTimer = InstrumentationService.CreateTimerCounter ("Mac Mime Database", "Platform Service");
 
61
 
 
62
                static bool initedGlobal;
 
63
                bool setupFail, initedApp;
 
64
                
 
65
                Lazy<Dictionary<string, string>> mimemap;
61
66
                
62
67
                //this is a BCD value of the form "xxyz", where x = major, y = minor, z = bugfix
63
68
                //eg. 0x1071 = 10.7.1
64
 
                static int systemVersion;
 
69
                int systemVersion;
65
70
 
66
 
                static MacPlatformService ()
 
71
                public MacPlatformService ()
67
72
                {
 
73
                        if (initedGlobal)
 
74
                                throw new Exception ("Only one MacPlatformService instance allowed");
 
75
                        initedGlobal = true;
 
76
 
68
77
                        timer.BeginTiming ();
69
78
                        
70
79
                        systemVersion = Carbon.Gestalt ("sysv");
71
80
                        
72
81
                        mimemap = new Lazy<Dictionary<string, string>> (LoadMimeMapAsync);
73
 
                        
74
 
                        CheckGtkVersion (2, 24, 0);
75
 
                        
 
82
 
76
83
                        //make sure the menu app name is correct even when running Mono 2.6 preview, or not running from the .app
77
84
                        Carbon.SetProcessName (BrandingService.ApplicationName);
78
85
                        
79
 
                        MonoDevelop.MacInterop.Cocoa.InitMonoMac ();
80
 
                        
 
86
                        Cocoa.InitMonoMac ();
 
87
 
 
88
                        CheckGtkVersion (2, 24, 14);
 
89
 
81
90
                        timer.Trace ("Installing App Event Handlers");
82
91
                        GlobalSetup ();
83
92
                        
84
93
                        timer.EndTiming ();
85
94
                }
86
 
                
87
 
                //Mac GTK+ behaviour isn't completely stable even between micro releases
 
95
 
88
96
                static void CheckGtkVersion (uint major, uint minor, uint micro)
89
97
                {
90
 
                        string url = "http://www.go-mono.com/mono-downloads/download.html";
91
 
                        
92
 
                        // to require exact version, also check : || Gtk.Global.CheckVersion (major, minor, micro + 1) == null
 
98
                        // to require exact version, also check
 
99
                        //: || Gtk.Global.CheckVersion (major, minor, micro + 1) == null
 
100
                        //
93
101
                        if (Gtk.Global.CheckVersion (major, minor, micro) != null) {
94
102
                                
95
 
                                MonoDevelop.Core.LoggingService.LogFatalError ("GTK+ version is incompatible with required version {0}.{1}.{2}.", major, minor, micro);
 
103
                                LoggingService.LogFatalError (
 
104
                                        "GTK+ version is incompatible with required version {0}.{1}.{2}.",
 
105
                                        major, minor, micro
 
106
                                );
96
107
                                
97
 
                                AlertButton downloadButton = new AlertButton ("Download...", null);
 
108
                                var downloadButton = new AlertButton ("Download Mono Framework", null);
98
109
                                if (downloadButton == MessageService.GenericAlert (
99
110
                                        Stock.Error,
100
 
                                        "Incompatible Mono Framework Version",
101
 
                                        "MonoDevelop requires a newer version of the Mono Framework.",
102
 
                                        new AlertButton ("Cancel", null), downloadButton))
 
111
                                        GettextCatalog.GetString ("Some dependencies need to be updated"),
 
112
                                        GettextCatalog.GetString (
 
113
                                                "{0} requires a newer version of GTK+, which is included with the Mono Framework. Please " +
 
114
                                                "download and install the latest stable Mono Framework package and restart {0}.",
 
115
                                                BrandingService.ApplicationName
 
116
                                        ),
 
117
                                        new AlertButton ("Quit", null), downloadButton))
103
118
                                {
104
 
                                        OpenUrl (url);
 
119
                                        OpenUrl (monoDownloadUrl);
105
120
                                }
106
121
                                
107
122
                                Environment.Exit (1);
110
125
 
111
126
                protected override string OnGetMimeTypeForUri (string uri)
112
127
                {
113
 
                        var ext = System.IO.Path.GetExtension (uri);
 
128
                        var ext = Path.GetExtension (uri);
114
129
                        string mime = null;
115
130
                        if (ext != null && mimemap.Value.TryGetValue (ext, out mime))
116
131
                                return mime;
124
139
                
125
140
                internal static void OpenUrl (string url)
126
141
                {
127
 
                        NSWorkspace.SharedWorkspace.OpenUrl (new NSUrl (url));
 
142
                        Gtk.Application.Invoke (delegate {
 
143
                                NSWorkspace.SharedWorkspace.OpenUrl (new NSUrl (url));
 
144
                        });
128
145
                }
129
146
                
130
147
                public override void OpenFile (string filename)
131
148
                {
132
 
                        NSWorkspace.SharedWorkspace.OpenFile (filename);
 
149
                        Gtk.Application.Invoke (delegate {
 
150
                                NSWorkspace.SharedWorkspace.OpenFile (filename);
 
151
                        });
133
152
                }
134
153
 
135
154
                public override string DefaultMonospaceFont {
136
 
                        get { return "Monaco 12"; }
 
155
                        get { return "Menlo 12"; }
137
156
                }
138
157
                
139
158
                public override string Name {
140
159
                        get { return "OSX"; }
141
160
                }
142
161
                
143
 
                private static Dictionary<string, string> LoadMimeMapAsync ()
 
162
                Dictionary<string, string> LoadMimeMapAsync ()
144
163
                {
145
164
                        var map = new Dictionary<string, string> ();
146
165
                        // All recent Macs should have this file; if not we'll just die silently
147
166
                        if (!File.Exists ("/etc/apache2/mime.types")) {
148
 
                                MonoDevelop.Core.LoggingService.LogError ("Apache mime database is missing");
 
167
                                LoggingService.LogError ("Apache mime database is missing");
149
168
                                return map;
150
169
                        }
151
170
                        
163
182
                                        }
164
183
                                }
165
184
                        } catch (Exception ex){
166
 
                                MonoDevelop.Core.LoggingService.LogError ("Could not load Apache mime database", ex);
 
185
                                LoggingService.LogError ("Could not load Apache mime database", ex);
167
186
                        }
168
187
                        mimeTimer.EndTiming ();
169
188
                        return map;
170
189
                }
171
190
                
172
 
                HashSet<object> ignoreCommands = new HashSet<object> () {
173
 
                        CommandManager.ToCommandId (HelpCommands.About),
174
 
                        CommandManager.ToCommandId (EditCommands.DefaultPolicies),
175
 
                        CommandManager.ToCommandId (EditCommands.MonodevelopPreferences),
176
 
                        CommandManager.ToCommandId (ToolCommands.AddinManager),
177
 
                        CommandManager.ToCommandId (FileCommands.Exit),
178
 
                };
179
 
                
180
 
                public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath)
 
191
                public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath, string appMenuAddinPath)
181
192
                {
182
193
                        if (setupFail)
183
194
                                return false;
184
 
                        
 
195
 
185
196
                        try {
186
197
                                InitApp (commandManager);
 
198
 
 
199
                                NSApplication.SharedApplication.HelpMenu = null;
 
200
 
 
201
                                var rootMenu = NSApplication.SharedApplication.MainMenu;
 
202
                                if (rootMenu == null) {
 
203
                                        rootMenu = new NSMenu ();
 
204
                                        NSApplication.SharedApplication.MainMenu = rootMenu;
 
205
                                } else {
 
206
                                        rootMenu.RemoveAllItems ();
 
207
                                }
 
208
 
 
209
                                CommandEntrySet appCes = commandManager.CreateCommandEntrySet (appMenuAddinPath);
 
210
                                rootMenu.AddItem (new MDSubMenuItem (commandManager, appCes));
 
211
 
187
212
                                CommandEntrySet ces = commandManager.CreateCommandEntrySet (commandMenuAddinPath);
188
 
                                MacMainMenu.Recreate (commandManager, ces, ignoreCommands);
 
213
                                foreach (CommandEntry ce in ces) {
 
214
                                        rootMenu.AddItem (new MDSubMenuItem (commandManager, (CommandEntrySet) ce));
 
215
                                }
189
216
                        } catch (Exception ex) {
190
217
                                try {
191
 
                                        MacMainMenu.Destroy (true);
 
218
                                        var m = NSApplication.SharedApplication.MainMenu;
 
219
                                        if (m != null) {
 
220
                                                m.Dispose ();
 
221
                                        }
 
222
                                        NSApplication.SharedApplication.MainMenu = null;
192
223
                                } catch {}
193
 
                                MonoDevelop.Core.LoggingService.LogError ("Could not install global menu", ex);
 
224
                                LoggingService.LogError ("Could not install global menu", ex);
194
225
                                setupFail = true;
195
226
                                return false;
196
227
                        }
197
 
                        
198
228
                        return true;
199
229
                }
 
230
 
 
231
                static void OnCommandActivating (object sender, CommandActivationEventArgs args)
 
232
                {
 
233
                        if (args.Source != CommandSource.Keybinding)
 
234
                                return;
 
235
                        var m = NSApplication.SharedApplication.MainMenu;
 
236
                        if (m != null) {
 
237
                                foreach (NSMenuItem item in m.ItemArray ()) {
 
238
                                        var submenu = item.Submenu as MDMenu;
 
239
                                        if (submenu != null && submenu.FlashIfContainsCommand (args.CommandId))
 
240
                                                return;
 
241
                                }
 
242
                        }
 
243
                }
200
244
                
201
 
                static void InitApp (CommandManager commandManager)
 
245
                void InitApp (CommandManager commandManager)
202
246
                {
203
247
                        if (initedApp)
204
248
                                return;
205
 
                        
206
 
                        MacMainMenu.AddCommandIDMappings (new Dictionary<object, CarbonCommandID> ()
207
 
                        {
208
 
                                { CommandManager.ToCommandId (EditCommands.Copy), CarbonCommandID.Copy },
209
 
                                { CommandManager.ToCommandId (EditCommands.Cut), CarbonCommandID.Cut },
210
 
                                //FIXME: for some reason mapping this causes two menu items to be created
211
 
                                // { EditCommands.MonodevelopPreferences, CarbonCommandID.Preferences }, 
212
 
                                { CommandManager.ToCommandId (EditCommands.Redo), CarbonCommandID.Redo },
213
 
                                { CommandManager.ToCommandId (EditCommands.Undo), CarbonCommandID.Undo },
214
 
                                { CommandManager.ToCommandId (EditCommands.SelectAll), CarbonCommandID.SelectAll },
215
 
                                { CommandManager.ToCommandId (FileCommands.NewFile), CarbonCommandID.New },
216
 
                                { CommandManager.ToCommandId (FileCommands.OpenFile), CarbonCommandID.Open },
217
 
                                { CommandManager.ToCommandId (FileCommands.Save), CarbonCommandID.Save },
218
 
                                { CommandManager.ToCommandId (FileCommands.SaveAs), CarbonCommandID.SaveAs },
219
 
                                { CommandManager.ToCommandId (FileCommands.CloseFile), CarbonCommandID.Close },
220
 
                                { CommandManager.ToCommandId (FileCommands.Exit), CarbonCommandID.Quit },
221
 
                                { CommandManager.ToCommandId (FileCommands.ReloadFile), CarbonCommandID.Revert },
222
 
                                { CommandManager.ToCommandId (HelpCommands.About), CarbonCommandID.About },
223
 
                                { CommandManager.ToCommandId (HelpCommands.Help), CarbonCommandID.AppHelp },
224
 
                        });
225
 
                        
 
249
 
 
250
                        commandManager.CommandActivating += OnCommandActivating;
 
251
 
226
252
                        //mac-ify these command names
227
253
                        commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences...");
228
254
                        commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies...");
229
 
                        commandManager.GetCommand (HelpCommands.About).Text = string.Format (GettextCatalog.GetString ("About {0}"), BrandingService.ApplicationName);
 
255
                        commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName);
 
256
                        commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName);
230
257
                        commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager...");
231
258
                        
232
259
                        initedApp = true;
233
 
                        MacMainMenu.SetAppQuitCommand (CommandManager.ToCommandId (FileCommands.Exit));
234
 
                        MacMainMenu.AddAppMenuItems (
235
 
                                commandManager,
236
 
                            CommandManager.ToCommandId (HelpCommands.About),
237
 
                                CommandManager.ToCommandId (MonoDevelop.Ide.Updater.UpdateCommands.CheckForUpdates),
238
 
                                CommandManager.ToCommandId (Command.Separator),
239
 
                                CommandManager.ToCommandId (EditCommands.MonodevelopPreferences),
240
 
                                CommandManager.ToCommandId (EditCommands.DefaultPolicies),
241
 
                                CommandManager.ToCommandId (ToolCommands.AddinManager));
242
260
                        
243
261
                        IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent;
 
262
 
 
263
                        if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) {
 
264
                                IdeApp.Workbench.RootWindow.Realized += (sender, args) => {
 
265
                                        var win = GtkQuartz.GetWindow ((Gtk.Window) sender);
 
266
                                        win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary;
 
267
                                };
 
268
                        }
244
269
                }
245
 
                
246
 
                static void GlobalSetup ()
 
270
 
 
271
                void GlobalSetup ()
247
272
                {
248
 
                        if (initedGlobal || setupFail)
249
 
                                return;
250
 
                        initedGlobal = true;
251
 
                        
252
273
                        //FIXME: should we remove these when finalizing?
253
274
                        try {
254
 
                                ApplicationEvents.Quit += delegate (object sender, ApplicationQuitEventArgs e) {
255
 
                                        //FIXME: can we avoid replying to the message until the app quits?
256
 
                                        //There's NSTerminateLate but I'm not sure how to access it from carbon, maybe
257
 
                                        //we need to swizzle methods into the app's NSApplicationDelegate.
258
 
                                        //Also, it stops the main CFRunLoop, hopefully GTK dialogs use a child runloop.
259
 
                                        //For now, just bounce.
260
 
                                        var topDialog = MessageService.GetDefaultModalParent () as Gtk.Dialog;
261
 
                                        if (topDialog != null && topDialog.Modal) {
262
 
                                                NSApplication.SharedApplication.RequestUserAttention (
263
 
                                                        NSRequestUserAttentionType.CriticalRequest);
 
275
                                ApplicationEvents.Quit += delegate (object sender, ApplicationQuitEventArgs e)
 
276
                                {
 
277
                                        // We can only attempt to quit safely if all windows are GTK windows and not modal
 
278
                                        if (GtkQuartz.GetToplevels ().All (t => t.Value != null && (!t.Value.Visible || !t.Value.Modal))) {
 
279
                                                e.UserCancelled = !IdeApp.Exit ();
 
280
                                                e.Handled = true;
 
281
                                                return;
264
282
                                        }
265
 
                                        //FIXME: delay this until all existing modal dialogs were closed
266
 
                                        if (!IdeApp.Exit ())
267
 
                                                e.UserCancelled = true;
 
283
 
 
284
                                        // When a modal dialog is running, things are much harder. We can't just shut down MD behind the
 
285
                                        // dialog, and aborting the dialog may not be appropriate.
 
286
                                        //
 
287
                                        // There's NSTerminateLater but I'm not sure how to access it from carbon, maybe
 
288
                                        // we need to swizzle methods into the app's NSApplicationDelegate.
 
289
                                        // Also, it stops the main CFRunLoop and enters a special runloop mode, not sure how that would
 
290
                                        // interact with GTK+.
 
291
 
 
292
                                        // For now, just bounce
 
293
                                        NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest);
 
294
                                        // and abort the quit.
 
295
                                        e.UserCancelled = true;
268
296
                                        e.Handled = true;
269
297
                                };
270
298
                                
296
324
                                //if not running inside an app bundle, assume usual MD build layout and load the app icon
297
325
                                FilePath exePath = System.Reflection.Assembly.GetExecutingAssembly ().Location;
298
326
                                string iconFile = null;
299
 
                                if (!exePath.ToString ().Contains ("MonoDevelop.app")) {
300
 
                                        var mdSrcMain = exePath.ParentDirectory.ParentDirectory.ParentDirectory;
301
 
                                        iconFile = mdSrcMain.Combine ("theme-icons", "Mac", "monodevelop.icns");
 
327
 
 
328
                                iconFile = BrandingService.GetString ("ApplicationIcon");
 
329
                                if (iconFile != null) {
 
330
                                        iconFile = BrandingService.GetFile (iconFile);
 
331
                                }
 
332
                                else if (!exePath.ToString ().Contains ("MonoDevelop.app")) {
 
333
                                                var mdSrcMain = exePath.ParentDirectory.ParentDirectory.ParentDirectory;
 
334
                                                iconFile = mdSrcMain.Combine ("theme-icons", "Mac", "monodevelop.icns");
302
335
                                } else {
303
336
                                        //HACK: override the app image
304
337
                                        //NSApplication doesn't seem to pick up the image correctly, probably due to the
311
344
                                        NSApplication.SharedApplication.ApplicationIconImage = new NSImage (iconFile);
312
345
                                }
313
346
                        } catch (Exception ex) {
314
 
                                MonoDevelop.Core.LoggingService.LogError ("Could not install app event handlers", ex);
 
347
                                LoggingService.LogError ("Could not install app event handlers", ex);
315
348
                                setupFail = true;
316
349
                        }
317
350
                }
320
353
                static void HandleDeleteEvent (object o, Gtk.DeleteEventArgs args)
321
354
                {
322
355
                        args.RetVal = true;
323
 
                        IdeApp.Workbench.RootWindow.Hide ();
 
356
                        NSApplication.SharedApplication.Hide (NSApplication.SharedApplication);
324
357
                }
325
358
 
326
359
                public static Gdk.Pixbuf GetPixbufFromNSImageRep (NSImageRep rep, int width, int height)
327
360
                {
328
 
                        var rect = new System.Drawing.RectangleF (0, 0, width, height);
 
361
                        var rect = new RectangleF (0, 0, width, height);
329
362
                        var bitmap = rep as NSBitmapImageRep;
330
363
                        
331
364
                        if (bitmap == null) {
332
 
                                using (var cgi = rep.AsCGImage (rect, null, null))
 
365
                                using (var cgi = rep.AsCGImage (ref rect, null, null))
333
366
                                        bitmap = new NSBitmapImageRep (cgi);
334
367
                        }
335
368
                        
439
472
                        //checkUniquePath.Add (thisPath);
440
473
                        
441
474
                        checkUniqueName.Add ("MonoDevelop");
 
475
                        checkUniqueName.Add (BrandingService.ApplicationName);
442
476
                        
443
477
                        string def = CoreFoundation.GetApplicationUrl (filename, CoreFoundation.LSRolesMask.All);
444
478
                        
519
553
                        window.Present ();
520
554
                        NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
521
555
                }
 
556
 
 
557
                static Cairo.Color ConvertColor (NSColor color)
 
558
                {
 
559
                        float r, g, b, a;
 
560
                        if (color.ColorSpaceName == NSColorSpace.DeviceWhite) {
 
561
                                a = 1.0f;
 
562
                                r = g = b = color.WhiteComponent;
 
563
                        } else {
 
564
                                color.GetRgba (out r, out g, out b, out a);
 
565
                        }
 
566
                        return new Cairo.Color (r, g, b, a);
 
567
                }
 
568
 
 
569
                static int GetTitleBarHeight ()
 
570
                {
 
571
                        var frame = new RectangleF (0, 0, 100, 100);
 
572
                        var rect = NSWindow.ContentRectFor (frame, NSWindowStyle.Titled);
 
573
                        return (int)(frame.Height - rect.Height);
 
574
                }
 
575
 
 
576
 
 
577
                static NSImage LoadImage (string resource)
 
578
                {
 
579
                        byte[] buffer;
 
580
                        using (var stream = typeof (MacPlatformService).Assembly.GetManifestResourceStream (resource)) {
 
581
                                buffer = new byte [stream.Length];
 
582
                                stream.Read (buffer, 0, (int)stream.Length);
 
583
                        }
 
584
 
 
585
                        // Workaround: loading from file name.
 
586
                        var tmp = Path.GetTempFileName ();
 
587
                        File.WriteAllBytes (tmp, buffer);
 
588
                        var img = new NSImage (tmp);
 
589
                        File.Delete (tmp);
 
590
                        return img;
 
591
                }
 
592
 
 
593
                internal override void SetMainWindowDecorations (Gtk.Window window)
 
594
                {
 
595
                        NSWindow w = GtkQuartz.GetWindow (window);
 
596
                        w.IsOpaque = false;
 
597
                        
 
598
                        var resource = "maintoolbarbg.png";
 
599
                        NSImage img = LoadImage (resource);
 
600
                        w.BackgroundColor = NSColor.FromPatternImage (img);
 
601
                        w.StyleMask |= NSWindowStyle.TexturedBackground;
 
602
                }
 
603
 
 
604
                internal override void RemoveWindowShadow (Gtk.Window window)
 
605
                {
 
606
                        if (window == null)
 
607
                                throw new ArgumentNullException ("window");
 
608
                        NSWindow w = GtkQuartz.GetWindow (window);
 
609
                        w.HasShadow = false;
 
610
                }
 
611
 
 
612
                internal override MainToolbar CreateMainToolbar (Gtk.Window window)
 
613
                {
 
614
                        NSApplication.Init ();
 
615
                        
 
616
                        NSWindow w = GtkQuartz.GetWindow (window);
 
617
                        w.IsOpaque = false;
 
618
                        
 
619
                        var resource = "maintoolbarbg.png";
 
620
                        NSImage img = LoadImage (resource);
 
621
                        var c = NSColor.FromPatternImage (img);
 
622
                        w.BackgroundColor = c;
 
623
                        w.StyleMask |= NSWindowStyle.TexturedBackground;
 
624
 
 
625
                        var result = new MainToolbar () {
 
626
                                Background = MonoDevelop.Components.CairoExtensions.LoadImage (typeof (MacPlatformService).Assembly, resource),
 
627
                                TitleBarHeight = GetTitleBarHeight ()
 
628
                        };
 
629
                        return result;
 
630
                }
 
631
 
 
632
                protected override RecentFiles CreateRecentFilesProvider ()
 
633
                {
 
634
                        return new FdoRecentFiles (UserProfile.Current.LocalConfigDir.Combine ("RecentlyUsed.xml"));
 
635
                }
 
636
 
 
637
                public override bool GetIsFullscreen (Gtk.Window window)
 
638
                {
 
639
                        if (MacSystemInformation.OsVersion < MacSystemInformation.Lion) {
 
640
                                return base.GetIsFullscreen (window);
 
641
                        }
 
642
 
 
643
                        NSWindow nswin = GtkQuartz.GetWindow (window);
 
644
                        return (nswin.StyleMask & NSWindowStyle.FullScreenWindow) != 0;
 
645
                }
 
646
 
 
647
                public override void SetIsFullscreen (Gtk.Window window, bool isFullscreen)
 
648
                {
 
649
                        if (MacSystemInformation.OsVersion < MacSystemInformation.Lion) {
 
650
                                base.SetIsFullscreen (window, isFullscreen);
 
651
                                return;
 
652
                        }
 
653
 
 
654
                        NSWindow nswin = GtkQuartz.GetWindow (window);
 
655
                        if (isFullscreen != ((nswin.StyleMask & NSWindowStyle.FullScreenWindow) != 0)) {
 
656
                                //HACK: workaround for MonoMac not allowing null as argument
 
657
                                MonoMac.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (
 
658
                                        nswin.Handle,
 
659
                                        MonoMac.ObjCRuntime.Selector.GetHandle ("toggleFullScreen:"),
 
660
                                        IntPtr.Zero);
 
661
                        }
 
662
                }
522
663
        }
523
664
}