int Run(MonoDevelopOptions options) { LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationLongName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo("Build Information{0}{1}", Environment.NewLine, SystemInformation.GetBuildInformation()); LoggingService.LogInfo("Running on {0}", IdeVersionInfo.GetRuntimeInfo()); //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); GettextCatalog.Initialize(); LoggingService.LogInfo("Operating System: {0}", SystemInformation.GetOperatingSystemDescription()); if (!Platform.IsWindows) { // The assembly resolver for MSBuild 15 assemblies needs to be defined early on. // Whilst Runtime.Initialize loads the MSBuild 15 assemblies from Mono this seems // to be too late to prevent the MEF composition and the static registrar from // failing to load the MonoDevelop.Ide assembly which now uses MSBuild 15 assemblies. ResolveMSBuildAssemblies(); } Counters.Initialization.BeginTiming(); if (options.PerfLog) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.perf-log"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.Initialization.Trace("Initializing GTK"); if (Platform.IsWindows && !CheckWindowsGtk()) { return(1); } SetupExceptionManager(); // explicit GLib type system initialization for GLib < 2.36 before any other type system access GLib.GType.Init(); IdeApp.Customizer = options.IdeCustomizer ?? new IdeCustomizer(); try { IdeApp.Customizer.Initialize(); } catch (UnauthorizedAccessException ua) { LoggingService.LogError("Unauthorized access: " + ua.Message); return(1); } try { GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } var args = options.RemainingArgs.ToArray(); IdeTheme.InitializeGtk(BrandingService.ApplicationName, ref args); LoggingService.LogInfo("Using GTK+ {0}", IdeVersionInfo.GetGtkVersion()); // XWT initialization FilePath p = typeof(IdeStartup).Assembly.Location; Runtime.LoadAssemblyFrom(p.ParentDirectory.Combine("Xwt.Gtk.dll")); Xwt.Application.InitializeAsGuest(Xwt.ToolkitType.Gtk); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarWindowBackend, GtkExtendedTitleBarWindowBackend> (); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarDialogBackend, GtkExtendedTitleBarDialogBackend> (); IdeTheme.SetupXwtTheme(); //default to Windows IME on Windows if (Platform.IsWindows && GtkWorkarounds.GtkMinorVersion >= 16) { var settings = Gtk.Settings.Default; var val = GtkWorkarounds.GetProperty(settings, "gtk-im-module"); if (string.IsNullOrEmpty(val.Val as string)) { GtkWorkarounds.SetProperty(settings, "gtk-im-module", new GLib.Value("ime")); } } string socket_filename = null; EndPoint ep = null; DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(DispatchService.SynchronizationContext); Runtime.MainSynchronizationContext = SynchronizationContext.Current; // Initialize Roslyn's synchronization context RoslynServices.RoslynService.Initialize(); AddinManager.AddinLoadError += OnAddinError; var startupInfo = new StartupInfo(args); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { Counters.Initialization.Trace("Pre-Initializing Runtime to load files in existing window"); Runtime.Initialize(true); foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } Counters.Initialization.Trace("Initializing Runtime"); Runtime.Initialize(true); IdeApp.Customizer.OnCoreInitialized(); Counters.Initialization.Trace("Initializing theme"); IdeTheme.SetupGtkTheme(); ProgressMonitor monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); monitor.BeginTask(GettextCatalog.GetString("Starting {0}", BrandingService.ApplicationName), 2); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.Initialization.Trace("Initializing Platform Service"); DesktopService.Initialize(); monitor.Step(1); if (options.IpcTcp) { listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); ep = new IPEndPoint(IPAddress.Loopback, ipcBasePort + HashSdbmBounded(Environment.UserName)); } else { socket_filename = "/tmp/md-" + Environment.GetEnvironmentVariable("USER") + "-socket"; listen_socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); ep = new UnixEndPoint(socket_filename); } // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles) { try { StringBuilder builder = new StringBuilder(); foreach (var file in startupInfo.RequestedFileList) { builder.AppendFormat("{0};{1};{2}\n", file.FileName, file.Line, file.Column); } listen_socket.Connect(ep); listen_socket.Send(Encoding.UTF8.GetBytes(builder.ToString())); return(0); } catch { // Reset the socket if (null != socket_filename && File.Exists(socket_filename)) { File.Delete(socket_filename); } } } Counters.Initialization.Trace("Checking System"); CheckFileWatcher(); Exception error = null; int reportedFailures = 0; try { Counters.Initialization.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); LocalizationService.Initialize(); // If we display an error dialog before the main workbench window on OS X then a second application menu is created // which is then replaced with a second empty Apple menu. // XBC #33699 Counters.Initialization.Trace("Initializing IdeApp"); IdeApp.Initialize(monitor); if (errorsList.Count > 0) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false)) { if (!dlg.Run()) { return(1); } } reportedFailures = errorsList.Count; } if (!CheckSCPlugin()) { return(1); } // Load requested files Counters.Initialization.Trace("Opening Files"); // load previous combine RecentFile openedProject = null; if (IdeApp.Preferences.LoadPrevSolutionOnStartup && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen) { openedProject = DesktopService.RecentFiles.MostRecentlyUsedProject; if (openedProject != null) { var metadata = GetOpenWorkspaceOnStartupMetadata(); IdeApp.Workspace.OpenWorkspaceItem(openedProject.FileName, true, true, metadata).ContinueWith(t => IdeApp.OpenFiles(startupInfo.RequestedFileList, metadata), TaskScheduler.FromCurrentSynchronizationContext()); startupInfo.OpenedRecentProject = true; } } if (openedProject == null) { IdeApp.OpenFiles(startupInfo.RequestedFileList, GetOpenWorkspaceOnStartupMetadata()); startupInfo.OpenedFiles = startupInfo.HasFiles; } monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { string message = BrandingService.BrandApplicationName(GettextCatalog.GetString("MonoDevelop failed to start")); MessageService.ShowFatalError(message, null, error); return(1); } if (errorsList.Count > reportedFailures) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), true)) dlg.Run(); } errorsList = null; AddinManager.AddinLoadError -= OnAddinError; // FIXME: we should probably track the last 'selected' one // and do this more cleanly try { listen_socket.Bind(ep); listen_socket.Listen(5); listen_socket.BeginAccept(new AsyncCallback(ListenCallback), listen_socket); } catch { // Socket already in use } initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(IdeApp.Workbench.RootWindow); Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); StartLockupTracker(); startupTimer.Stop(); CreateStartupMetadata(startupInfo); GLib.Idle.Add(OnIdle); IdeApp.Run(); IdeApp.Customizer.OnIdeShutdown(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } lockupCheckRunning = false; Runtime.Shutdown(); IdeApp.Customizer.OnCoreShutdown(); InstrumentationService.Stop(); MonoDevelop.Components.GtkWorkarounds.Terminate(); return(0); }
int Run(MonoDevelopOptions options) { Counters.Initialization.BeginTiming(); if (options.LogCounters) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.clog"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.Initialization.Trace("Initializing GTK"); SetupExceptionManager(); try { MonoDevelop.Ide.Gui.GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } //OSXFIXME var args = options.RemainingArgs.ToArray(); Gtk.Application.Init("monodevelop", ref args); //default to Windows IME on Windows if (Platform.IsWindows && Mono.TextEditor.GtkWorkarounds.GtkMinorVersion >= 16) { var settings = Gtk.Settings.Default; var val = Mono.TextEditor.GtkWorkarounds.GetProperty(settings, "gtk-im-module"); if (string.IsNullOrEmpty(val.Val as string)) { Mono.TextEditor.GtkWorkarounds.SetProperty(settings, "gtk-im-module", new GLib.Value("ime")); } } InternalLog.Initialize(); string socket_filename = null; EndPoint ep = null; DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(new GtkSynchronizationContext()); AddinManager.AddinLoadError += OnAddinError; var startupInfo = new StartupInfo(args); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { Counters.Initialization.Trace("Pre-Initializing Runtime to load files in existing window"); Runtime.Initialize(true); foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } DefaultTheme = Gtk.Settings.Default.ThemeName; if (!string.IsNullOrEmpty(IdeApp.Preferences.UserInterfaceTheme)) { Gtk.Settings.Default.ThemeName = IdeApp.Preferences.UserInterfaceTheme; } //don't show the splash screen on the Mac, so instead we get the expected "Dock bounce" effect //this also enables the Mac platform service to subscribe to open document events before the GUI loop starts. if (Platform.IsMac) { options.NoLogo = true; } IProgressMonitor monitor; if (options.NoLogo) { monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); } else { monitor = SplashScreenForm.SplashScreen; SplashScreenForm.SplashScreen.ShowAll(); } Counters.Initialization.Trace("Initializing Runtime"); monitor.BeginTask(GettextCatalog.GetString("Starting {0}", BrandingService.ApplicationName), 3); monitor.Step(1); Runtime.Initialize(true); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.Initialization.Trace("Initializing Platform Service"); DesktopService.Initialize(); monitor.Step(1); if (options.IpcTcp) { listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); ep = new IPEndPoint(IPAddress.Loopback, ipcBasePort + HashSdbmBounded(Environment.UserName)); } else { socket_filename = "/tmp/md-" + Environment.GetEnvironmentVariable("USER") + "-socket"; listen_socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); ep = new UnixEndPoint(socket_filename); } // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles) { try { StringBuilder builder = new StringBuilder(); foreach (var file in startupInfo.RequestedFileList) { builder.AppendFormat("{0};{1};{2}\n", file.FileName, file.Line, file.Column); } listen_socket.Connect(ep); listen_socket.Send(Encoding.UTF8.GetBytes(builder.ToString())); return(0); } catch { // Reset the socket if (null != socket_filename && File.Exists(socket_filename)) { File.Delete(socket_filename); } } } Counters.Initialization.Trace("Checking System"); string version = Assembly.GetEntryAssembly().GetName().Version.Major + "." + Assembly.GetEntryAssembly().GetName().Version.Minor; if (Assembly.GetEntryAssembly().GetName().Version.Build != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Build; } if (Assembly.GetEntryAssembly().GetName().Version.Revision != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Revision; } // System checks if (!CheckBug77135()) { return(1); } if (!CheckQtCurve()) { return(1); } CheckFileWatcher(); Exception error = null; int reportedFailures = 0; try { Counters.Initialization.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); if (errorsList.Count > 0) { if (monitor is SplashScreenForm) { SplashScreenForm.SplashScreen.Hide(); } AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false); if (!dlg.Run()) { return(1); } if (monitor is SplashScreenForm) { SplashScreenForm.SplashScreen.Show(); } reportedFailures = errorsList.Count; } // no alternative for Application.ThreadException? // Application.ThreadException += new ThreadExceptionEventHandler(ShowErrorBox); Counters.Initialization.Trace("Initializing IdeApp"); IdeApp.Initialize(monitor); // Load requested files Counters.Initialization.Trace("Opening Files"); IdeApp.OpenFiles(startupInfo.RequestedFileList); monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { LoggingService.LogFatalError(null, error); MessageService.ShowException(error, GettextCatalog.GetString("MonoDevelop failed to start. The following error has been reported: ") + error.Message); return(1); } if (errorsList.Count > reportedFailures) { AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), true); dlg.Run(); } errorsList = null; // FIXME: we should probably track the last 'selected' one // and do this more cleanly try { listen_socket.Bind(ep); listen_socket.Listen(5); listen_socket.BeginAccept(new AsyncCallback(ListenCallback), listen_socket); } catch { // Socket already in use } initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); IdeApp.Run(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } Runtime.Shutdown(); InstrumentationService.Stop(); return(0); }
/// <summary> /// Places and runs a transient dialog. Does not destroy it, so values can be retrieved from its widgets. /// </summary> public static int RunCustomDialog(Dialog dlg, Window parent) { // if dialog is modal, make sure it's parented on any existing modal dialog Gtk.Dialog dialog = dlg; if (dialog.Modal) { parent = DesktopService.GetParentForModalWindow(); } //ensure the dialog has a parent if (parent == null) { if (dialog.TransientFor != null) { parent = dialog.TransientFor; } else { parent = RootWindow; } } //TODO: use native parenting API for native windows if (parent.nativeWidget is Gtk.Window) { dialog.TransientFor = parent; dialog.DestroyWithParent = true; } MonoDevelop.Components.IdeTheme.ApplyTheme(dialog); if (dialog.Title == null) { dialog.Title = BrandingService.ApplicationName; } #if MAC Runtime.RunInMainThread(() => { // If there is a native NSWindow model window running, we need // to show the new dialog over that window. if (NSApplication.SharedApplication.ModalWindow != null || (parent.nativeWidget is NSWindow && dialog.Modal)) { EventHandler shownHandler = null; shownHandler = (s, e) => { ShowCustomModalDialog(dialog, parent); dialog.Shown -= shownHandler; }; dialog.Shown += shownHandler; } else { PlaceDialog(dialog, parent); } }).Wait(); #endif var initialRootWindow = Xwt.MessageDialog.RootWindow; try { Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(dialog); IdeApp.DisableIdleActions(); int result = GtkWorkarounds.RunDialogWithNotification(dialog); // Focus parent window once the dialog is ran, as focus gets lost if (parent != null) { DesktopService.FocusWindow(parent); } return(result); } finally { Xwt.MessageDialog.RootWindow = initialRootWindow; IdeApp.EnableIdleActions(); } }
int Run(MonoDevelopOptions options) { LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo("Running on {0}", IdeVersionInfo.GetRuntimeInfo()); //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); IdeApp.Customizer = options.IdeCustomizer ?? new IdeCustomizer(); IdeApp.Customizer.Initialize(); Counters.Initialization.BeginTiming(); if (options.PerfLog) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.perf-log"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.Initialization.Trace("Initializing GTK"); if (Platform.IsWindows && !CheckWindowsGtk()) { return(1); } SetupExceptionManager(); try { GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } SetupTheme(); var args = options.RemainingArgs.ToArray(); Gtk.Application.Init(BrandingService.ApplicationName, ref args); LoggingService.LogInfo("Using GTK+ {0}", IdeVersionInfo.GetGtkVersion()); // XWT initialization FilePath p = typeof(IdeStartup).Assembly.Location; Assembly.LoadFrom(p.ParentDirectory.Combine("Xwt.Gtk.dll")); Xwt.Application.InitializeAsGuest(Xwt.ToolkitType.Gtk); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarWindowBackend, GtkExtendedTitleBarWindowBackend> (); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarDialogBackend, GtkExtendedTitleBarDialogBackend> (); //default to Windows IME on Windows if (Platform.IsWindows && Mono.TextEditor.GtkWorkarounds.GtkMinorVersion >= 16) { var settings = Gtk.Settings.Default; var val = Mono.TextEditor.GtkWorkarounds.GetProperty(settings, "gtk-im-module"); if (string.IsNullOrEmpty(val.Val as string)) { Mono.TextEditor.GtkWorkarounds.SetProperty(settings, "gtk-im-module", new GLib.Value("ime")); } } InternalLog.Initialize(); string socket_filename = null; EndPoint ep = null; DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(new GtkSynchronizationContext()); Runtime.MainSynchronizationContext = SynchronizationContext.Current; AddinManager.AddinLoadError += OnAddinError; var startupInfo = new StartupInfo(args); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { Counters.Initialization.Trace("Pre-Initializing Runtime to load files in existing window"); Runtime.Initialize(true); foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } Counters.Initialization.Trace("Initializing Runtime"); Runtime.Initialize(true); IdeApp.Customizer.OnCoreInitialized(); Counters.Initialization.Trace("Initializing theme"); DefaultTheme = Gtk.Settings.Default.ThemeName; string theme = IdeApp.Preferences.UserInterfaceTheme; if (string.IsNullOrEmpty(theme)) { theme = DefaultTheme; } ValidateGtkTheme(ref theme); if (theme != DefaultTheme) { Gtk.Settings.Default.ThemeName = theme; } IProgressMonitor monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); monitor.BeginTask(GettextCatalog.GetString("Starting {0}", BrandingService.ApplicationName), 2); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.Initialization.Trace("Initializing Platform Service"); DesktopService.Initialize(); monitor.Step(1); if (options.IpcTcp) { listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); ep = new IPEndPoint(IPAddress.Loopback, ipcBasePort + HashSdbmBounded(Environment.UserName)); } else { socket_filename = "/tmp/md-" + Environment.GetEnvironmentVariable("USER") + "-socket"; listen_socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); ep = new UnixEndPoint(socket_filename); } // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles) { try { StringBuilder builder = new StringBuilder(); foreach (var file in startupInfo.RequestedFileList) { builder.AppendFormat("{0};{1};{2}\n", file.FileName, file.Line, file.Column); } listen_socket.Connect(ep); listen_socket.Send(Encoding.UTF8.GetBytes(builder.ToString())); return(0); } catch { // Reset the socket if (null != socket_filename && File.Exists(socket_filename)) { File.Delete(socket_filename); } } } Counters.Initialization.Trace("Checking System"); string version = Assembly.GetEntryAssembly().GetName().Version.Major + "." + Assembly.GetEntryAssembly().GetName().Version.Minor; if (Assembly.GetEntryAssembly().GetName().Version.Build != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Build; } if (Assembly.GetEntryAssembly().GetName().Version.Revision != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Revision; } CheckFileWatcher(); Exception error = null; int reportedFailures = 0; try { Counters.Initialization.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); if (errorsList.Count > 0) { AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false); if (!dlg.Run()) { return(1); } reportedFailures = errorsList.Count; } if (!CheckSCPlugin()) { return(1); } // no alternative for Application.ThreadException? // Application.ThreadException += new ThreadExceptionEventHandler(ShowErrorBox); Counters.Initialization.Trace("Initializing IdeApp"); IdeApp.Initialize(monitor); // Load requested files Counters.Initialization.Trace("Opening Files"); // load previous combine if (IdeApp.Preferences.LoadPrevSolutionOnStartup && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen) { var proj = DesktopService.RecentFiles.GetProjects().FirstOrDefault(); if (proj != null) { IdeApp.Workspace.OpenWorkspaceItem(proj.FileName).WaitForCompleted(); } } IdeApp.OpenFiles(startupInfo.RequestedFileList); monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { string message = BrandingService.BrandApplicationName(GettextCatalog.GetString("MonoDevelop failed to start")); MessageService.ShowFatalError(message, null, error); return(1); } if (errorsList.Count > reportedFailures) { AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), true); dlg.Run(); } errorsList = null; // FIXME: we should probably track the last 'selected' one // and do this more cleanly try { listen_socket.Bind(ep); listen_socket.Listen(5); listen_socket.BeginAccept(new AsyncCallback(ListenCallback), listen_socket); } catch { // Socket already in use } initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); StartLockupTracker(); IdeApp.Run(); IdeApp.Customizer.OnIdeShutdown(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } lockupCheckRunning = false; Runtime.Shutdown(); IdeApp.Customizer.OnCoreShutdown(); InstrumentationService.Stop(); AddinManager.AddinLoadError -= OnAddinError; return(0); }
public int Run(string[] args) { Counters.Initialization.BeginTiming(); var options = new MonoDevelopOptions(); var optionsSet = new Mono.Options.OptionSet() { { "nologo", "Do not display splash screen.", s => options.NoLogo = true }, { "ipc-tcp", "Use the Tcp channel for inter-process comunication.", s => options.IpcTcp = true }, { "newwindow", "Do not open in an existing instance of MonoDevelop", s => options.NewWindow = true }, { "h|?|help", "Show help", s => options.ShowHelp = true }, { "clog", "Log internal counter data", s => options.LogCounters = true }, { "clog-interval=", "Interval between counter logs (in miliseconds)", s => options.LogCountersInterval = int.Parse(s) }, }; var remainingArgs = optionsSet.Parse(args); if (options.ShowHelp) { Console.WriteLine("MonoDevelop IDE " + MonoDevelop.Ide.BuildVariables.PackageVersionLabel); Console.WriteLine("Options:"); optionsSet.WriteOptionDescriptions(Console.Out); return(0); } if (options.LogCounters) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.clog"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.Initialization.Trace("Initializing GTK"); SetupExceptionManager(); try { MonoDevelop.Ide.Gui.GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } //OSXFIXME Gtk.Application.Init("monodevelop", ref args); InternalLog.Initialize(); string socket_filename = null; EndPoint ep = null; AddinManager.AddinLoadError += OnAddinError; var startupInfo = new StartupInfo(remainingArgs); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { Counters.Initialization.Trace("Pre-Initializing Runtime to load files in existing window"); Runtime.Initialize(true); // foreach (var file in startupInfo.RequestedFileList) { // if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile (file.FileName)) { // options.NewWindow = true; // break; // } // } } DefaultTheme = Gtk.Settings.Default.ThemeName; if (!string.IsNullOrEmpty(IdeApp.Preferences.UserInterfaceTheme)) { Gtk.Settings.Default.ThemeName = IdeApp.Preferences.UserInterfaceTheme; } //don't show the splash screen on the Mac, so instead we get the expected "Dock bounce" effect //this also enables the Mac platform service to subscribe to open document events before the GUI loop starts. if (PropertyService.IsMac) { options.NoLogo = true; } IProgressMonitor monitor; if (options.NoLogo) { monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); } else { monitor = SplashScreenForm.SplashScreen; SplashScreenForm.SplashScreen.ShowAll(); } Counters.Initialization.Trace("Initializing Runtime"); monitor.BeginTask(GettextCatalog.GetString("Starting MonoDevelop"), 2); monitor.Step(1); Runtime.Initialize(true); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.Initialization.Trace("Initializing Platform Service"); DesktopService.Initialize(); monitor.Step(1); monitor.EndTask(); monitor.Step(1); if (options.IpcTcp) { listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); ep = new IPEndPoint(IPAddress.Loopback, ipcBasePort + HashSDBMBounded(Environment.UserName)); } else { socket_filename = "/tmp/md-unity-" + Environment.GetEnvironmentVariable("USER") + "-socket"; listen_socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); ep = new UnixEndPoint(socket_filename); } // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles) { try { StringBuilder builder = new StringBuilder(); foreach (var file in startupInfo.RequestedFileList) { builder.AppendFormat("{0};{1};{2}\n", file.FileName, file.Line, file.Column); } listen_socket.Connect(ep); listen_socket.Send(Encoding.UTF8.GetBytes(builder.ToString())); listen_socket.Close(); return(0); } catch { // Reset the socket if (null != socket_filename && File.Exists(socket_filename)) { File.Delete(socket_filename); } if (options.IpcTcp) { try { listen_socket.Close(); listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); } catch (Exception exc) { LoggingService.LogError("Error resetting TCP socket", exc); } } } } Counters.Initialization.Trace("Checking System"); string version = Assembly.GetEntryAssembly().GetName().Version.Major + "." + Assembly.GetEntryAssembly().GetName().Version.Minor; if (Assembly.GetEntryAssembly().GetName().Version.Build != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Build; } if (Assembly.GetEntryAssembly().GetName().Version.Revision != 0) { version += "." + Assembly.GetEntryAssembly().GetName().Version.Revision; } // System checks if (!CheckBug77135()) { return(1); } if (!CheckQtCurve()) { return(1); } CheckFileWatcher(); Exception error = null; int reportedFailures = 0; try { Counters.Initialization.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); if (errorsList.Count > 0) { if (monitor is SplashScreenForm) { SplashScreenForm.SplashScreen.Hide(); } AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false); if (!dlg.Run()) { return(1); } if (monitor is SplashScreenForm) { SplashScreenForm.SplashScreen.Show(); } reportedFailures = errorsList.Count; } // no alternative for Application.ThreadException? // Application.ThreadException += new ThreadExceptionEventHandler(ShowErrorBox); Counters.Initialization.Trace("Initializing IdeApp"); IdeApp.Initialize(monitor); // Load requested files Counters.Initialization.Trace("Opening Files"); IdeApp.OpenFiles(startupInfo.RequestedFileList); monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { MessageService.ShowException(error, GettextCatalog.GetString("MonoDevelop failed to start. The following error has been reported: ") + error.Message); return(1); } if (errorsList.Count > reportedFailures) { AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), true); dlg.Run(); } errorsList = null; // FIXME: we should probably track the last 'selected' one // and do this more cleanly try { listen_socket.Bind(ep); listen_socket.Listen(5); listen_socket.BeginAccept(new AsyncCallback(ListenCallback), listen_socket); } catch { // Socket already in use } initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); IdeApp.Run(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } Runtime.Shutdown(); InstrumentationService.Stop(); System.Environment.Exit(0); return(0); }