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(); sectionTimings ["PlatformInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); GettextCatalog.Initialize(); sectionTimings ["GettextInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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); sectionTimings["GtkInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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(); sectionTimings["XwtInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); //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; sectionTimings["DispatchInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); // Initialize Roslyn's synchronization context RoslynServices.RoslynService.Initialize(); sectionTimings["RoslynInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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); sectionTimings["RuntimeInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); IdeApp.Customizer.OnCoreInitialized(); Counters.Initialization.Trace("Initializing theme"); IdeTheme.SetupGtkTheme(); sectionTimings["ThemeInitialized"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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(); sectionTimings["PlatformInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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(); sectionTimings["FileWatcherInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); 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(); sectionTimings ["ImageInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); // 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); sectionTimings ["AppInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); if (errorsList.Count > 0) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog(errorsList.ToArray(), 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(errorsList.ToArray(), true)) dlg.Run(); } errorsList = null; AddinManager.AddinLoadError -= OnAddinError; sectionTimings["BasicInitializationCompleted"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); // 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 } sectionTimings["SocketInitialization"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(IdeApp.Workbench.RootWindow); sectionTimings["WindowOpened"] = startupTimer.ElapsedMilliseconds; startupTimer.Restart(); Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); StartLockupTracker(); startupTimer.Stop(); // Need to start this timer because we don't know yet if we've been asked to open a solution from the file manager. timeToCodeTimer.Start(); ttcMetadata = new TimeToCodeMetadata { StartupTime = startupTimer.ElapsedMilliseconds }; // Start this timer to limit the time to decide if the app was opened by a file manager IdeApp.StartFMOpenTimer(FMOpenTimerExpired); IdeApp.Workspace.FirstWorkspaceItemOpened += CompleteTimeToCode; CreateStartupMetadata(startupInfo, sectionTimings); 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); }
public static void Initialize(IProgressMonitor monitor) { Counters.Initialization.Trace("Creating Workbench"); workbench = new Workbench(); Counters.Initialization.Trace("Creating Root Workspace"); workspace = new RootWorkspace(); Counters.Initialization.Trace("Creating Services"); projectOperations = new ProjectOperations(); helpOperations = new HelpOperations(); commandService = new CommandManager(); ideServices = new IdeServices(); CustomToolService.Init(); AutoTestService.Start(commandService, Preferences.EnableAutomatedTesting); commandService.CommandTargetScanStarted += CommandServiceCommandTargetScanStarted; commandService.CommandTargetScanFinished += CommandServiceCommandTargetScanFinished; commandService.KeyBindingFailed += KeyBindingFailed; KeyBindingService.LoadBindingsFromExtensionPath("/MonoDevelop/Ide/KeyBindingSchemes"); KeyBindingService.LoadCurrentBindings("MD2"); commandService.CommandError += delegate(object sender, CommandErrorArgs args) { LoggingService.LogError(args.ErrorMessage, args.Exception); MessageService.ShowException(args.Exception, args.ErrorMessage); }; FileService.ErrorHandler = FileServiceErrorHandler; monitor.BeginTask(GettextCatalog.GetString("Loading Workbench"), 5); Counters.Initialization.Trace("Loading Commands"); commandService.LoadCommands("/MonoDevelop/Ide/Commands"); monitor.Step(1); Counters.Initialization.Trace("Initializing Workbench"); workbench.Initialize(monitor); monitor.Step(1); InternalLog.EnableErrorNotification(); MonoDevelop.Ide.WelcomePage.WelcomePageService.Initialize(); MonoDevelop.Ide.WelcomePage.WelcomePageService.ShowWelcomePage(); monitor.Step(1); Counters.Initialization.Trace("Restoring Workbench State"); workbench.Show("SharpDevelop.Workbench.WorkbenchMemento"); monitor.Step(1); Counters.Initialization.Trace("Flushing GUI events"); DispatchService.RunPendingEvents(); Counters.Initialization.Trace("Flushed GUI events"); MessageService.RootWindow = workbench.RootWindow; commandService.EnableIdleUpdate = true; // Default file format MonoDevelop.Projects.Services.ProjectServiceLoaded += delegate(object sender, EventArgs e) { ((ProjectService)sender).DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat; }; IdeApp.Preferences.DefaultProjectFileFormatChanged += delegate { IdeApp.Services.ProjectService.DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat; }; // Perser service initialization TypeSystemService.TrackFileChanges = true; TypeSystemService.ParseProgressMonitorFactory = new ParseProgressMonitorFactory(); // Startup commands Counters.Initialization.Trace("Running Startup Commands"); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged); monitor.Step(1); monitor.EndTask(); // Set initial run flags Counters.Initialization.Trace("Upgrading Settings"); if (PropertyService.Get("MonoDevelop.Core.FirstRun", false)) { isInitialRun = true; PropertyService.Set("MonoDevelop.Core.FirstRun", false); PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildInfo.Version); PropertyService.Set("MonoDevelop.Core.LastRunRevision", CurrentRevision); PropertyService.SaveProperties(); } string lastVersion = PropertyService.Get("MonoDevelop.Core.LastRunVersion", "1.9.1"); int lastRevision = PropertyService.Get("MonoDevelop.Core.LastRunRevision", 0); if (lastRevision != CurrentRevision && !isInitialRun) { isInitialRunAfterUpgrade = true; if (lastRevision == 0) { switch (lastVersion) { case "1.0": lastRevision = 1; break; case "2.0": lastRevision = 2; break; case "2.2": lastRevision = 3; break; case "2.2.1": lastRevision = 4; break; } } upgradedFromRevision = lastRevision; PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildInfo.Version); PropertyService.Set("MonoDevelop.Core.LastRunRevision", CurrentRevision); PropertyService.SaveProperties(); } // The ide is now initialized isInitialized = true; if (isInitialRun) { try { OnInitialRun(); } catch (Exception e) { LoggingService.LogError("Error found while initializing the IDE", e); } } if (isInitialRunAfterUpgrade) { try { OnUpgraded(upgradedFromRevision); } catch (Exception e) { LoggingService.LogError("Error found while initializing the IDE", e); } } if (initializedEvent != null) { initializedEvent(null, EventArgs.Empty); } // load previous combine if ((bool)PropertyService.Get("SharpDevelop.LoadPrevProjectOnStartup", false)) { var proj = DesktopService.RecentFiles.GetProjects().FirstOrDefault(); if (proj != null) { IdeApp.Workspace.OpenWorkspaceItem(proj.FileName).WaitForCompleted(); } } //FIXME: we should really make this on-demand. consumers can display a "loading help cache" message like VS MonoDevelop.Projects.HelpService.AsyncInitialize(); UpdateInstrumentationIcon(); IdeApp.Preferences.EnableInstrumentationChanged += delegate { UpdateInstrumentationIcon(); }; AutoTestService.NotifyEvent("MonoDevelop.Ide.IdeStart"); }
int Run(MonoDevelopOptions options) { LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo("Running on {0}", IdeVersionInfo.GetRuntimeInfo()); 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); } //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); Counters.Initialization.Trace("Initializing GTK"); if (Platform.IsWindows) { CheckWindowsGtk(); } 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()); FilePath p = typeof(IdeStartup).Assembly.Location; Assembly.LoadFrom(p.ParentDirectory.Combine("Xwt.Gtk.dll")); Xwt.Application.InitializeAsGuest(Xwt.ToolkitType.Gtk); //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; } } } Counters.Initialization.Trace("Initializing Runtime"); Runtime.Initialize(true); Counters.Initialization.Trace("Initializing theme and splash window"); 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; } //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.NoSplash = true; } IProgressMonitor monitor = null; if (!options.NoSplash) { try { monitor = new SplashScreenForm(); ((SplashScreenForm)monitor).ShowAll(); } catch (Exception ex) { LoggingService.LogError("Failed to create splash screen", ex); } } if (monitor == null) { 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) { if (monitor is SplashScreenForm) { ((SplashScreenForm)monitor).Hide(); } AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false); if (!dlg.Run()) { return(1); } if (monitor is SplashScreenForm) { ((SplashScreenForm)monitor).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); string message = BrandingService.BrandApplicationName(GettextCatalog.GetString( "MonoDevelop failed to start. The following error has been reported: {0}", error.Message )); MessageService.ShowException(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); }
public static void Initialize(ProgressMonitor monitor) { // Already done in IdeSetup, but called again since unit tests don't use IdeSetup. DispatchService.Initialize(); Counters.Initialization.Trace("Creating Workbench"); workbench = new Workbench(); Counters.Initialization.Trace("Creating Root Workspace"); workspace = new RootWorkspace(); Counters.Initialization.Trace("Creating Services"); projectOperations = new ProjectOperations(); helpOperations = new HelpOperations(); commandService = new CommandManager(); ideServices = new IdeServices(); CustomToolService.Init(); commandService.CommandTargetScanStarted += CommandServiceCommandTargetScanStarted; commandService.CommandTargetScanFinished += CommandServiceCommandTargetScanFinished; commandService.KeyBindingFailed += KeyBindingFailed; KeyBindingService.LoadBindingsFromExtensionPath("/MonoDevelop/Ide/KeyBindingSchemes"); KeyBindingService.LoadCurrentBindings("MD2"); commandService.CommandError += delegate(object sender, CommandErrorArgs args) { LoggingService.LogInternalError(args.ErrorMessage, args.Exception); }; FileService.ErrorHandler = FileServiceErrorHandler; monitor.BeginTask(GettextCatalog.GetString("Loading Workbench"), 6); Counters.Initialization.Trace("Loading Commands"); commandService.LoadCommands("/MonoDevelop/Ide/Commands"); monitor.Step(1); // Before startup commands. Counters.Initialization.Trace("Running Pre-Startup Commands"); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/PreStartupHandlers", OnExtensionChanged); monitor.Step(1); Counters.Initialization.Trace("Initializing Workbench"); workbench.Initialize(monitor); monitor.Step(1); MonoDevelop.Ide.WelcomePage.WelcomePageService.Initialize(); MonoDevelop.Ide.WelcomePage.WelcomePageService.ShowWelcomePage(); monitor.Step(1); Counters.Initialization.Trace("Restoring Workbench State"); workbench.Show("SharpDevelop.Workbench.WorkbenchMemento"); monitor.Step(1); Counters.Initialization.Trace("Flushing GUI events"); DispatchService.RunPendingEvents(); Counters.Initialization.Trace("Flushed GUI events"); MessageService.RootWindow = workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(workbench.RootWindow); commandService.EnableIdleUpdate = true; if (Customizer != null) { Customizer.OnIdeInitialized(); } // Startup commands Counters.Initialization.Trace("Running Startup Commands"); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged); monitor.Step(1); monitor.EndTask(); // Set initial run flags Counters.Initialization.Trace("Upgrading Settings"); if (PropertyService.Get("MonoDevelop.Core.FirstRun", false)) { isInitialRun = true; PropertyService.Set("MonoDevelop.Core.FirstRun", false); PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildInfo.Version); PropertyService.Set("MonoDevelop.Core.LastRunRevision", CurrentRevision); PropertyService.SaveProperties(); } string lastVersion = PropertyService.Get("MonoDevelop.Core.LastRunVersion", "1.9.1"); int lastRevision = PropertyService.Get("MonoDevelop.Core.LastRunRevision", 0); if (lastRevision != CurrentRevision && !isInitialRun) { isInitialRunAfterUpgrade = true; if (lastRevision == 0) { switch (lastVersion) { case "1.0": lastRevision = 1; break; case "2.0": lastRevision = 2; break; case "2.2": lastRevision = 3; break; case "2.2.1": lastRevision = 4; break; } } upgradedFromRevision = lastRevision; PropertyService.Set("MonoDevelop.Core.LastRunVersion", BuildInfo.Version); PropertyService.Set("MonoDevelop.Core.LastRunRevision", CurrentRevision); PropertyService.SaveProperties(); } // The ide is now initialized isInitialized = true; if (isInitialRun) { try { OnInitialRun(); } catch (Exception e) { LoggingService.LogError("Error found while initializing the IDE", e); } } if (isInitialRunAfterUpgrade) { try { OnUpgraded(upgradedFromRevision); } catch (Exception e) { LoggingService.LogError("Error found while initializing the IDE", e); } } if (initializedEvent != null) { initializedEvent(null, EventArgs.Empty); initializedEvent = null; } //FIXME: we should really make this on-demand. consumers can display a "loading help cache" message like VS MonoDevelop.Projects.HelpService.AsyncInitialize(); UpdateInstrumentationIcon(); IdeApp.Preferences.EnableInstrumentation.Changed += delegate { UpdateInstrumentationIcon(); }; AutoTestService.Start(commandService, Preferences.EnableAutomatedTesting); AutoTestService.NotifyEvent("MonoDevelop.Ide.IdeStart"); Gtk.LinkButton.SetUriHook((button, uri) => Xwt.Desktop.OpenUrl(uri)); }
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}", RuntimeVersionInfo.GetRuntimeInfo()); //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("PlatformInitialization"); GettextCatalog.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("GettextInitialization"); LoggingService.LogInfo("Operating System: {0}", SystemInformation.GetOperatingSystemDescription()); // 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(); var args = options.RemainingArgs.ToArray(); IdeTheme.InitializeGtk(BrandingService.ApplicationName, ref args); startupInfo = new StartupInfo(options, args); if (startupInfo.HasFiles) { // If files are present, consider started from the commandline as being the same as file manager. // On macOS, we need to wait until the DidFinishLaunching notification to find out we were launched from the Finder IdeApp.LaunchReason = IdeApp.LaunchType.LaunchedFromFileManager; } else if (!Platform.IsMac) { IdeApp.LaunchReason = IdeApp.LaunchType.Normal; } IdeApp.Customizer = options.IdeCustomizer ?? new IdeCustomizer(); try { IdeApp.Customizer.Initialize(startupInfo); } 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); } IdeStartupTracker.StartupTracker.MarkSection("GtkInitialization"); 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(); IdeStartupTracker.StartupTracker.MarkSection("XwtInitialization"); //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")); } } DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(DispatchService.SynchronizationContext); Runtime.MainSynchronizationContext = SynchronizationContext.Current; IdeStartupTracker.StartupTracker.MarkSection("DispatchInitialization"); // Initialize Roslyn's synchronization context RoslynServices.RoslynService.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("RoslynInitialization"); AddinManager.AddinLoadError += OnAddinError; Counters.Initialization.Trace("Initializing Runtime"); Runtime.Initialize(true); // Register services used by the IDE RegisterServices(); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } instanceConnection = new IdeInstanceConnection(); instanceConnection.Initialize(options.IpcTcp); // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles && instanceConnection.TryConnect(startupInfo)) { return(0); } IdeStartupTracker.StartupTracker.MarkSection("RuntimeInitialization"); bool restartRequested = PropertyService.Get("MonoDevelop.Core.RestartRequested", false); startupInfo.Restarted = restartRequested; PropertyService.Set("MonoDevelop.Core.RestartRequested", false); Counters.Initialization.Trace("Initializing theme"); IdeTheme.SetupGtkTheme(); IdeApp.Customizer.OnCoreInitialized(); IdeStartupTracker.StartupTracker.MarkSection("ThemeInitialized"); IdeApp.IsRunning = true; // Load the main menu before running the main loop var commandService = Runtime.GetService <CommandManager> ().Result; var desktopService = Runtime.GetService <DesktopService> ().Result; desktopService.SetGlobalMenu(commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath); // Run the main loop Gtk.Application.Invoke((s, e) => { MainLoop(options, startupInfo).Ignore(); }); Gtk.Application.Run(); IdeApp.IsRunning = false; IdeApp.Customizer.OnIdeShutdown(); instanceConnection.Dispose(); lockupCheckRunning = false; Runtime.Shutdown(); IdeApp.Customizer.OnCoreShutdown(); InstrumentationService.Stop(); MonoDevelop.Components.GtkWorkarounds.Terminate(); return(0); }
public static async Task Initialize(ProgressMonitor monitor, bool hideWelcomePage = false) { // Already done in IdeSetup, but called again since unit tests don't use IdeSetup. DispatchService.Initialize(); // Set initial run flags Counters.Initialization.Trace("Upgrading Settings"); if (PropertyService.Get("MonoDevelop.Core.FirstRun", true)) { isInitialRun = true; PropertyService.Set("MonoDevelop.Core.FirstRun", false); PropertyService.Set("MonoDevelop.Core.LastRunVersion", Runtime.Version.ToString()); PropertyService.SaveProperties(); } string lastVersionString = PropertyService.Get("MonoDevelop.Core.LastRunVersion", "1.0"); Version.TryParse(lastVersionString, out var lastVersion); if (Runtime.Version > lastVersion && !isInitialRun) { isInitialRunAfterUpgrade = true; upgradedFromVersion = lastVersion; PropertyService.Set("MonoDevelop.Core.LastRunVersion", Runtime.Version.ToString()); PropertyService.SaveProperties(); } Counters.Initialization.Trace("Initializing WelcomePage service"); WelcomePage.WelcomePageService.Initialize(hideWelcomePage).Ignore(); // Pump the UI thread to make the start window visible await Task.Yield(); Counters.Initialization.Trace("Creating Services"); var serviceInitialization = Task.WhenAll( Runtime.GetService <DesktopService> (), Runtime.GetService <FontService> (), Runtime.GetService <TaskService> (), Runtime.GetService <ProjectOperations> (), Runtime.GetService <TextEditorService> (), Runtime.GetService <NavigationHistoryService> (), Runtime.GetService <DisplayBindingService> (), Runtime.GetService <RootWorkspace> (), Runtime.GetService <HelpOperations> (), Runtime.GetService <HelpService> () ); commandService = await Runtime.GetService <CommandManager> (); await serviceInitialization; Counters.Initialization.Trace("Creating Workbench"); workbench = new Workbench(); Counters.Initialization.Trace("Creating Root Workspace"); CustomToolService.Init(); FileService.ErrorHandler = FileServiceErrorHandler; monitor.BeginTask(GettextCatalog.GetString("Loading Workbench"), 3); // Before startup commands. Counters.Initialization.Trace("Running Pre-Startup Commands"); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/PreStartupHandlers", OnExtensionChanged); monitor.Step(1); Counters.Initialization.Trace("Initializing Workbench"); await workbench.Initialize(monitor); monitor.Step(1); MessageService.RootWindow = workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(workbench.RootWindow); commandService.EnableIdleUpdate = true; if (Customizer != null) { Customizer.OnIdeInitialized(); } monitor.EndTask(); UpdateInstrumentationIcon(); IdeApp.Preferences.EnableInstrumentation.Changed += delegate { UpdateInstrumentationIcon(); }; AutoTestService.Start(commandService, Preferences.EnableAutomatedTesting); AutoTestService.NotifyEvent("MonoDevelop.Ide.IdeStart"); Gtk.LinkButton.SetUriHook((button, uri) => Xwt.Desktop.OpenUrl(uri)); // Start initializing the type system service in the background Runtime.GetService <TypeSystemService> ().Ignore(); // The ide is now initialized OnInitialized(); }
public void Dispose() { DispatchService.StopAnimation(this); }
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 " + BrandingService.ApplicationName, 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); //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(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 (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 " + 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-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) { 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); string logAgentEnabled = Environment.GetEnvironmentVariable("MONODEVELOP_LOG_AGENT_ENABLED"); if (string.Equals(logAgentEnabled, "true", StringComparison.OrdinalIgnoreCase)) { LaunchCrashMonitoringService(); } IdeApp.Run(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } Runtime.Shutdown(); InstrumentationService.Stop(); System.Environment.Exit(0); return(0); }
public void Pulse() { DispatchService.AssertGuiThread(); this.progressBar.Visible = true; this.progressBar.Pulse(); }
public void SetProgressFraction(double work) { DispatchService.AssertGuiThread(); this.progressBar.Fraction = work; }
public void ShowWarning(string warning) { DispatchService.AssertGuiThread(); ShowMessage(new Gtk.Image(MonoDevelop.Ide.Gui.Stock.Warning, IconSize.Menu), warning); }
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(); LoggingService.LogInfo("Operating System: {0}", SystemInformation.GetOperatingSystemDescription()); 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 && 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(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; } 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(); // 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.GetProjects().FirstOrDefault(); if (openedProject != null) { IdeApp.Workspace.OpenWorkspaceItem(openedProject.FileName).ContinueWith(t => IdeApp.OpenFiles(startupInfo.RequestedFileList), TaskScheduler.FromCurrentSynchronizationContext()); } } if (openedProject == null) { 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) { using (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); }