Ejemplo n.º 1
0
        void GlobalSetup()
        {
            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e)
                {
                    // We can only attempt to quit safely if all windows are GTK windows and not modal
                    if (!IsModalDialogRunning())
                    {
                        e.UserCancelled = !IdeApp.Exit();
                        e.Handled       = true;
                        return;
                    }

                    // When a modal dialog is running, things are much harder. We can't just shut down MD behind the
                    // dialog, and aborting the dialog may not be appropriate.
                    //
                    // There's NSTerminateLater but I'm not sure how to access it from carbon, maybe
                    // we need to swizzle methods into the app's NSApplicationDelegate.
                    // Also, it stops the main CFRunLoop and enters a special runloop mode, not sure how that would
                    // interact with GTK+.

                    // For now, just bounce
                    NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
                    // and abort the quit.
                    e.UserCancelled = true;
                    e.Handled       = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();
                        IdeApp.Workbench.RootWindow.Visible = true;

                        IdeApp.Workbench.RootWindow.Present();
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc =>
                                                            new FileOpenInformation(doc.Key, doc.Value, 1, OpenDocumentOptions.Default)));
                        return(false);
                    });
                    e.Handled = true;
                };

                //if not running inside an app bundle (at dev time), need to do some additional setup
                if (NSBundle.MainBundle.InfoDictionary ["CFBundleIdentifier"] == null)
                {
                    SetupWithoutBundle();
                }
            } catch (Exception ex) {
                LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }
Ejemplo n.º 2
0
 public void ExitApp()
 {
     try {
         IdeApp.Exit();
     } catch (Exception e) {
         Console.WriteLine(e);
     }
 }
Ejemplo n.º 3
0
		public void ExitApp ()
		{
			Sync (delegate {
				IdeApp.Exit ().ContinueWith ((arg) => {
					if (arg.IsFaulted)
						Console.WriteLine (arg.Exception);
				});
				return true;
			});
		}
Ejemplo n.º 4
0
 public void ExitApp()
 {
     Sync(delegate {
         try {
             IdeApp.Exit();
         } catch (Exception e) {
             Console.WriteLine(e);
         }
         return(true);
     });
 }
Ejemplo n.º 5
0
        static void GlobalSetup()
        {
            if (initedGlobal || setupFail)
            {
                return;
            }
            initedGlobal = true;

            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e) {
                    if (!IdeApp.Exit())
                    {
                        e.UserCancelled = true;
                    }
                    e.Handled = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();
                        IdeApp.Workbench.RootWindow.Visible = true;
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc =>
                                                            new FileOpenInformation(doc.Key, doc.Value, 1, OpenDocumentOptions.Default)));
                        return(false);
                    });
                    e.Handled = true;
                };

                //if not running inside an app bundle, assume usual MD build layout and load the app icon
                FilePath exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                if (!exePath.ToString().Contains("MonoDevelop.app"))
                {
                    var mdSrcMain = exePath.ParentDirectory.ParentDirectory.ParentDirectory;
                    var icons     = mdSrcMain.Combine("theme-icons", "Mac", "monodevelop.icns");
                    if (File.Exists(icons))
                    {
                        NSApplication.SharedApplication.ApplicationIconImage = new NSImage(icons);
                    }
                }
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }
Ejemplo n.º 6
0
        static void GlobalSetup()
        {
            if (initedGlobal || setupFail)
            {
                return;
            }
            initedGlobal = true;

            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e) {
                    if (!IdeApp.Exit())
                    {
                        e.UserCancelled = true;
                    }
                    e.Handled = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();
                        IdeApp.Workbench.RootWindow.Visible = true;
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc => new FileOpenInformation(doc.Key, doc.Value, 1, true)));
                        return(false);
                    });
                    e.Handled = true;
                };
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }
Ejemplo n.º 7
0
            public override void HandleException(string message, Exception e)
            {
                base.HandleException(message, e);

                if (e is IOException)
                {
                    return;
                }

                if (!IdeApp.IsInitialized)
                {
                    Console.WriteLine(e);
                    return;
                }

                var text          = GettextCatalog.GetString("There was a problem loading one or more extensions and {0} needs to be restarted.", BrandingService.ApplicationName);
                var quitButton    = new AlertButton(Strings.Quit);
                var restartButton = new AlertButton(Strings.Restart);

                var result = MessageService.GenericAlert(
                    IdeServices.DesktopService.GetFocusedTopLevelWindow(),
                    Gui.Stock.Error,
                    text,
                    secondaryText: null,
                    defaultButton: 1,
                    quitButton,
                    restartButton
                    );

                if (result == restartButton)
                {
                    IdeApp.Restart(false).Ignore();
                }
                else
                {
                    IdeApp.Exit().Ignore();
                }
            }
Ejemplo n.º 8
0
 protected override void Run()
 {
     IdeApp.Exit().Ignore();
 }
Ejemplo n.º 9
0
        void GlobalSetup()
        {
            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e)
                {
                    // We can only attempt to quit safely if all windows are GTK windows and not modal
                    if (!IsModalDialogRunning())
                    {
                        e.UserCancelled = !IdeApp.Exit();
                        e.Handled       = true;
                        return;
                    }

                    // When a modal dialog is running, things are much harder. We can't just shut down MD behind the
                    // dialog, and aborting the dialog may not be appropriate.
                    //
                    // There's NSTerminateLater but I'm not sure how to access it from carbon, maybe
                    // we need to swizzle methods into the app's NSApplicationDelegate.
                    // Also, it stops the main CFRunLoop and enters a special runloop mode, not sure how that would
                    // interact with GTK+.

                    // For now, just bounce
                    NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
                    // and abort the quit.
                    e.UserCancelled = true;
                    e.Handled       = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();
                        IdeApp.Workbench.RootWindow.Visible = true;

                        IdeApp.Workbench.RootWindow.Present();
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc =>
                                                            new FileOpenInformation(doc.Key, doc.Value, 1, OpenDocumentOptions.Default)));
                        return(false);
                    });
                    e.Handled = true;
                };

                ApplicationEvents.OpenUrls += delegate(object sender, ApplicationUrlEventArgs e) {
                    GLib.Timeout.Add(10, delegate {
                        // Open files via the monodevelop:// URI scheme, compatible with the
                        // common TextMate scheme: http://blog.macromates.com/2007/the-textmate-url-scheme/
                        IdeApp.OpenFiles(e.Urls.Select(url => {
                            try {
                                var uri = new Uri(url);
                                if (uri.Host != "open")
                                {
                                    return(null);
                                }

                                var qs      = System.Web.HttpUtility.ParseQueryString(uri.Query);
                                var fileUri = new Uri(qs ["file"]);

                                int line, column;
                                if (!Int32.TryParse(qs ["line"], out line))
                                {
                                    line = 1;
                                }
                                if (!Int32.TryParse(qs ["column"], out column))
                                {
                                    column = 1;
                                }

                                return(new FileOpenInformation(fileUri.AbsolutePath,
                                                               line, column, OpenDocumentOptions.Default));
                            } catch (Exception ex) {
                                LoggingService.LogError("Invalid TextMate URI: " + url, ex);
                                return(null);
                            }
                        }).Where(foi => foi != null));
                        return(false);
                    });
                };

                //if not running inside an app bundle (at dev time), need to do some additional setup
                if (NSBundle.MainBundle.InfoDictionary ["CFBundleIdentifier"] == null)
                {
                    SetupWithoutBundle();
                }
            } catch (Exception ex) {
                LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }
Ejemplo n.º 10
0
 public void Quit()
 {
     IdeApp.Exit();
 }
Ejemplo n.º 11
0
        static void GlobalSetup()
        {
            if (initedGlobal || setupFail)
            {
                return;
            }
            initedGlobal = true;

            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e) {
                    //FIXME: can we avoid replying to the message until the app quits?
                    //There's NSTerminateLate but I'm not sure how to access it from carbon, maybe
                    //we need to swizzle methods into the app's NSApplicationDelegate.
                    //Also, it stops the main CFRunLoop, hopefully GTK dialogs use a child runloop.
                    //For now, just bounce.
                    var topDialog = MessageService.GetDefaultModalParent() as Gtk.Dialog;
                    if (topDialog != null && topDialog.Modal)
                    {
                        NSApplication.SharedApplication.RequestUserAttention(
                            NSRequestUserAttentionType.CriticalRequest);
                    }
                    //FIXME: delay this until all existing modal dialogs were closed
                    if (!IdeApp.Exit())
                    {
                        e.UserCancelled = true;
                    }
                    e.Handled = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();

                        // This is a workaround to a GTK+ bug. The HasTopLevelFocus flag is not properly
                        // set when the main window is restored. The workaround is to hide and re-show it.
                        // Since this happens before the next mainloop cycle, the window isn't actually affected.
                        IdeApp.Workbench.RootWindow.Hide();
                        IdeApp.Workbench.RootWindow.Show();

                        IdeApp.Workbench.RootWindow.Present();
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc =>
                                                            new FileOpenInformation(doc.Key, doc.Value, 1, OpenDocumentOptions.Default)));
                        return(false);
                    });
                    e.Handled = true;
                };

                //if not running inside an app bundle, assume usual MD build layout and load the app icon
                FilePath exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                if (!exePath.ToString().Contains("MonoDevelop.app"))
                {
                    var mdSrcMain = exePath.ParentDirectory.ParentDirectory.ParentDirectory;
                    var icons     = mdSrcMain.Combine("theme-icons", "Mac", "monodevelop.icns");
                    if (File.Exists(icons))
                    {
                        NSApplication.SharedApplication.ApplicationIconImage = new NSImage(icons);
                    }
                }
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }
Ejemplo n.º 12
0
        void GlobalSetup()
        {
            //FIXME: should we remove these when finalizing?
            try {
                ApplicationEvents.Quit += delegate(object sender, ApplicationQuitEventArgs e)
                {
                    // We can only attempt to quit safely if all windows are GTK windows and not modal
                    if (GtkQuartz.GetToplevels().All(t => t.Value != null && (!t.Value.Visible || !t.Value.Modal)))
                    {
                        e.UserCancelled = !IdeApp.Exit();
                        e.Handled       = true;
                        return;
                    }

                    // When a modal dialog is running, things are much harder. We can't just shut down MD behind the
                    // dialog, and aborting the dialog may not be appropriate.
                    //
                    // There's NSTerminateLater but I'm not sure how to access it from carbon, maybe
                    // we need to swizzle methods into the app's NSApplicationDelegate.
                    // Also, it stops the main CFRunLoop and enters a special runloop mode, not sure how that would
                    // interact with GTK+.

                    // For now, just bounce
                    NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest);
                    // and abort the quit.
                    e.UserCancelled = true;
                    e.Handled       = true;
                };

                ApplicationEvents.Reopen += delegate(object sender, ApplicationEventArgs e) {
                    if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null)
                    {
                        IdeApp.Workbench.RootWindow.Deiconify();

                        // This is a workaround to a GTK+ bug. The HasTopLevelFocus flag is not properly
                        // set when the main window is restored. The workaround is to hide and re-show it.
                        // Since this happens before the next mainloop cycle, the window isn't actually affected.
                        IdeApp.Workbench.RootWindow.Hide();
                        IdeApp.Workbench.RootWindow.Show();

                        IdeApp.Workbench.RootWindow.Present();
                        e.Handled = true;
                    }
                };

                ApplicationEvents.OpenDocuments += delegate(object sender, ApplicationDocumentEventArgs e) {
                    //OpenFiles may pump the mainloop, but can't do that from an AppleEvent, so use a brief timeout
                    GLib.Timeout.Add(10, delegate {
                        IdeApp.OpenFiles(e.Documents.Select(doc =>
                                                            new FileOpenInformation(doc.Key, doc.Value, 1, OpenDocumentOptions.Default)));
                        return(false);
                    });
                    e.Handled = true;
                };

                //if not running inside an app bundle, assume usual MD build layout and load the app icon
                FilePath exePath  = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string   iconFile = null;

                iconFile = BrandingService.GetString("ApplicationIcon");
                if (iconFile != null)
                {
                    iconFile = BrandingService.GetFile(iconFile);
                }
                else if (!exePath.ToString().Contains("MonoDevelop.app"))
                {
                    var mdSrcMain = exePath.ParentDirectory.ParentDirectory.ParentDirectory;
                    iconFile = mdSrcMain.Combine("theme-icons", "Mac", "monodevelop.icns");
                }
                else
                {
                    //HACK: override the app image
                    //NSApplication doesn't seem to pick up the image correctly, probably due to the
                    //getting confused about the bundle root because of the launch script
                    var bundleContents = exePath.ParentDirectory.ParentDirectory.ParentDirectory
                                         .ParentDirectory.ParentDirectory;
                    iconFile = bundleContents.Combine("Resources", "monodevelop.icns");
                }
                if (File.Exists(iconFile))
                {
                    NSApplication.SharedApplication.ApplicationIconImage = new NSImage(iconFile);
                }
            } catch (Exception ex) {
                LoggingService.LogError("Could not install app event handlers", ex);
                setupFail = true;
            }
        }