Esempio n. 1
0
        int Run(MonoDevelopOptions options)
        {
            LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationLongName, 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());

            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();

            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;

            Platform.AssemblyLoad(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;

            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.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;
            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();
            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);
        }
Esempio n. 2
0
        async Task <int> MainLoop(MonoDevelopOptions options, StartupInfo startupInfo)
        {
            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");

            var desktopService = await Runtime.GetService <DesktopService> ();

            var commandService = await Runtime.GetService <CommandManager> ();

            // load the global menu for the welcome window to avoid unresponsive menus on Mac
            desktopService.SetGlobalMenu(commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath);

            IdeStartupTracker.StartupTracker.MarkSection("PlatformInitialization");

            monitor.Step(1);

            Counters.Initialization.Trace("Checking System");

            CheckFileWatcher();

            IdeStartupTracker.StartupTracker.MarkSection("FileWatcherInitialization");

            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();

                IdeStartupTracker.StartupTracker.MarkSection("ImageInitialization");

                // 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");

                hideWelcomePage = options.NoStartWindow || startupInfo.HasFiles || IdeApp.Preferences.StartupBehaviour.Value != OnStartupBehaviour.ShowStartWindow;
                await IdeApp.Initialize(monitor, hideWelcomePage);

                IdeStartupTracker.StartupTracker.MarkSection("AppInitialization");

                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.StartupBehaviour.Value == OnStartupBehaviour.LoadPreviousSolution && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen)
                {
                    openedProject = IdeServices.DesktopService.RecentFiles.MostRecentlyUsedProject;
                    if (openedProject != null)
                    {
                        var metadata = GetOpenWorkspaceOnStartupMetadata();
                        IdeApp.Workspace.OpenWorkspaceItem(openedProject.FileName, true, true, metadata).ContinueWith(t => IdeApp.OpenFilesAsync(startupInfo.RequestedFileList, metadata), TaskScheduler.FromCurrentSynchronizationContext()).Ignore();
                        startupInfo.OpenedRecentProject = true;
                    }
                }
                if (openedProject == null)
                {
                    IdeApp.OpenFilesAsync(startupInfo.RequestedFileList, GetOpenWorkspaceOnStartupMetadata()).Ignore();
                    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"));
                message = message + "\n\n" + error.Message;
                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;

            IdeStartupTracker.StartupTracker.MarkSection("BasicInitializationCompleted");

            instanceConnection.FileOpenRequested += (sender, a) => {
                foreach (var e in a)
                {
                    OpenFile(e.FileName);
                }
            };

            instanceConnection.StartListening();

            IdeStartupTracker.StartupTracker.MarkSection("SocketInitialization");

            initialized = true;
            MessageService.RootWindow    = IdeApp.Workbench.RootWindow;
            Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(IdeApp.Workbench.RootWindow);

            IdeStartupTracker.StartupTracker.MarkSection("WindowOpened");

            Thread.CurrentThread.Name = "GUI Thread";
            Counters.Initialization.Trace("Running IdeApp");
            Counters.Initialization.EndTiming();

            AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged);
            StartLockupTracker();

            // This call is important so the current event loop is run before we run the main loop.
            // On Mac, the OpenDocuments event gets handled here, so we need to get the timeout
            // it queues before the OnIdle event so we can start opening a solution before
            // we show the main window.
            await Task.Yield();

            IdeStartupTracker.StartupTracker.MarkSection("PumpEventLoop");
            IdeStartupTracker.StartupTracker.Stop(startupInfo);

            GLib.Idle.Add(OnIdle);

            return(0);
        }
Esempio n. 3
0
 static void UpdateInstrumentationIcon()
 {
     if (IdeApp.Preferences.EnableInstrumentation)
     {
         if (instrumentationStatusIcon == null)
         {
             instrumentationStatusIcon          = IdeApp.Workbench.StatusBar.ShowStatusIcon(ImageService.GetIcon(MonoDevelop.Ide.Gui.Stock.StatusInstrumentation));
             instrumentationStatusIcon.ToolTip  = "Instrumentation service enabled";
             instrumentationStatusIcon.Clicked += delegate {
                 InstrumentationService.StartMonitor();
             };
         }
     }
     else if (instrumentationStatusIcon != null)
     {
         instrumentationStatusIcon.Dispose();
     }
 }
Esempio n. 4
0
		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 ();
			sectionTimings ["PlatformInitialization"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.Restart ();

			GettextCatalog.Initialize ();
			sectionTimings ["GettextInitialization"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.Restart ();

			// Initialize Roslyn's synchronization context
			RoslynServices.RoslynService.Initialize ();

			sectionTimings["RoslynInitialization"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.Restart ();

			bool restartRequested = PropertyService.Get ("MonoDevelop.Core.RestartRequested", false);
			startupInfo.Restarted = restartRequested;
			PropertyService.Set ("MonoDevelop.Core.RestartRequested", false);

			IdeApp.Customizer.OnCoreInitialized ();

			Counters.Initialization.Trace ("Initializing theme");

			IdeTheme.SetupGtkTheme ();

			sectionTimings["ThemeInitialized"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
				startupSectionTimer.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");

				hideWelcomePage = startupInfo.HasFiles;
				IdeApp.Initialize (monitor, hideWelcomePage);
				sectionTimings ["AppInitialization"] = startupSectionTimer.ElapsedMilliseconds;
				startupSectionTimer.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"));
				message = message + "\n\n" + error.Message;
				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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.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"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.Restart ();

			initialized = true;
			MessageService.RootWindow = IdeApp.Workbench.RootWindow;
			Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow (IdeApp.Workbench.RootWindow);

			sectionTimings["WindowOpened"] = startupSectionTimer.ElapsedMilliseconds;
			startupSectionTimer.Restart ();

			Thread.CurrentThread.Name = "GUI Thread";
			Counters.Initialization.Trace ("Running IdeApp");
			Counters.Initialization.EndTiming ();
				
			AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged);
			StartLockupTracker ();

			// This call is important so the current event loop is run before we run the main loop.
			// On Mac, the OpenDocuments event gets handled here, so we need to get the timeout
			// it queues before the OnIdle event so we can start opening a solution before
			// we show the main window.
			DispatchService.RunPendingEvents ();

			sectionTimings ["PumpEventLoop"] = startupSectionTimer.ElapsedMilliseconds;
			startupTimer.Stop ();
			startupSectionTimer.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 += CompleteSolutionTimeToCode;
			IdeApp.Workbench.DocumentOpened += CompleteFileTimeToCode;

			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;
		}
Esempio n. 5
0
 static void UpdateInstrumentationIcon()
 {
     if (IdeApp.Preferences.EnableInstrumentation)
     {
         if (instrumentationStatusIcon == null)
         {
             instrumentationStatusIcon          = IdeApp.Workbench.StatusBar.ShowStatusIcon(ImageService.GetIcon(MonoDevelop.Ide.Gui.Stock.StatusInstrumentation));
             instrumentationStatusIcon.Title    = GettextCatalog.GetString("Instrumentation");
             instrumentationStatusIcon.ToolTip  = GettextCatalog.GetString("Instrumentation service enabled");
             instrumentationStatusIcon.Help     = GettextCatalog.GetString("Information about the Instrumentation Service");
             instrumentationStatusIcon.Clicked += delegate {
                 InstrumentationService.StartMonitor();
             };
         }
     }
     else if (instrumentationStatusIcon != null)
     {
         instrumentationStatusIcon.Dispose();
     }
 }
        public DocumentSwitcher(Gtk.Window parent, bool startWithNext) : base(Gtk.WindowType.Toplevel)
        {
            IdeApp.CommandService.IsEnabled = false;
            this.documents = new List <MonoDevelop.Ide.Gui.Document> (
                IdeApp.Workbench.Documents.OrderByDescending(d => d.LastTimeActive));
            this.TransientFor = parent;

            this.Decorated         = false;
            this.DestroyWithParent = true;
            this.CanDefault        = true;

            this.Modal          = true;
            this.WindowPosition = Gtk.WindowPosition.CenterOnParent;
            this.TypeHint       = WindowTypeHint.Dialog;

            this.ModifyBg(StateType.Normal, this.Style.Base(StateType.Normal));

            VBox vBox = new VBox();
            HBox hBox = new HBox();

            var hBox2 = new HBox();

            hBox2.PackStart(hBox, false, false, 8);

            hBox.PackStart(imageTitle, true, false, 2);
            labelTitle.Xalign        = 0;
            labelTitle.HeightRequest = 24;
            hBox.PackStart(labelTitle, true, true, 2);
            vBox.PackStart(hBox2, false, false, 6);

            labelType.Xalign        = 0;
            labelType.HeightRequest = 16;
            hBox = new HBox();
            hBox.PackStart(labelType, false, false, 8);
            vBox.PackStart(hBox, false, false, 2);

            hBox = new HBox();
            hBox.PackStart(documentList, true, true, 1);
            vBox.PackStart(hBox, false, false, 0);

            labelFileName.Xalign    = 0;
            labelFileName.Ellipsize = Pango.EllipsizeMode.Start;
            hBox = new HBox();
            hBox.PackStart(labelFileName, true, true, 8);
            vBox.PackEnd(hBox, false, false, 6);

            Add(vBox);

            var padCategory = new  DocumentList.Category(GettextCatalog.GetString("Pads"));

            DocumentList.Item activeItem = null;

            foreach (Pad pad in IdeApp.Workbench.Pads)
            {
                if (!pad.Visible)
                {
                    continue;
                }
                var item = new DocumentList.Item()
                {
                    Icon  = ImageService.GetPixbuf(pad.Icon.Name ?? MonoDevelop.Ide.Gui.Stock.MiscFiles, IconSize.Menu),
                    Title = pad.Title,
                    Tag   = pad
                };
                if (pad.Window.Content.Control.HasFocus)
                {
                    activeItem = item;
                }
                padCategory.AddItem(item);
            }
            documentList.AddCategory(padCategory);

            var documentCategory = new  DocumentList.Category(GettextCatalog.GetString("Documents"));

            foreach (var doc in documents)
            {
                var item = new DocumentList.Item()
                {
                    Icon        = GetIconForDocument(doc, IconSize.Menu),
                    Title       = System.IO.Path.GetFileName(doc.Name),
                    ListTitle   = doc.Window.Title,
                    Description = doc.Window.DocumentType,
                    Path        = doc.Name,
                    Tag         = doc
                };
                if (doc.Window.ActiveViewContent.Control.HasFocus)
                {
                    activeItem = item;
                }
                documentCategory.AddItem(item);
            }
            documentList.AddCategory(documentCategory);

            documentList.ActiveItemChanged += delegate
            {
                if (documentList.ActiveItem == null)
                {
                    labelFileName.Text = labelType.Text = labelTitle.Text = "";
                    return;
                }
                imageTitle.Pixbuf  = documentList.ActiveItem.Icon;
                labelFileName.Text = documentList.ActiveItem.Path;
                labelType.Markup   = "<span size=\"small\">" + documentList.ActiveItem.Description + "</span>";
                labelTitle.Markup  = "<span size=\"xx-large\" weight=\"bold\">" + documentList.ActiveItem.Title + "</span>";
            };

            if (activeItem == null)
            {
                if (documentCategory.Items.Count > 0)
                {
                    activeItem = documentCategory.Items [0];
                }
                else if (padCategory.Items.Count > 0)
                {
                    activeItem = padCategory.Items [0];
                }
                else
                {
                    DestroyWindow();
                    return;
                }
            }

            documentList.ActiveItem = activeItem;
            documentList.NextItem(true);
            documentList.RequestClose += delegate(object sender, DocumentList.RequestActionEventArgs e)
            {
                try
                {
                    if (e.SelectItem)
                    {
                        if (documentList.ActiveItem.Tag is Pad)
                        {
                            ((Pad)documentList.ActiveItem.Tag).BringToFront(true);
                        }
                        else
                        {
                            ((MonoDevelop.Ide.Gui.Document)documentList.ActiveItem.Tag).Select();
                        }
                    }
                }
                finally
                {
                    DestroyWindow();
                }
            };

            this.ShowAll();
            documentList.GrabFocus();
            this.GrabDefault();
        }
Esempio n. 7
0
        public DocumentSwitcher(Gtk.Window parent, string category, bool startWithNext, out bool dialogHasContent) : base(Gtk.WindowType.Toplevel)
        {
            if (string.IsNullOrEmpty(category))
            {
                category = GettextCatalog.GetString("Documents");
            }

            IdeApp.CommandService.IsEnabled = false;
            this.documents = new List <MonoDevelop.Ide.Gui.Document> (
                IdeApp.Workbench.Documents.OrderByDescending(d => d.LastTimeActive));
            this.TransientFor = parent;

            this.Decorated         = false;
            this.DestroyWithParent = true;
            this.CanDefault        = true;

            this.Modal          = true;
            this.WindowPosition = Gtk.WindowPosition.CenterOnParent;
            this.TypeHint       = WindowTypeHint.Dialog;

            this.ModifyBg(StateType.Normal, Styles.BaseBackgroundColor.ToGdkColor());

            VBox vBox = new VBox();
            HBox hBox = new HBox();

            var hBox2 = new HBox();

            hBox2.PackStart(hBox, false, false, 8);

            hBox.PackStart(imageTitle.ToGtkWidget(), true, false, 2);
            labelTitle.Xalign        = 0;
            labelTitle.HeightRequest = 24;
            hBox.PackStart(labelTitle, true, true, 2);
            vBox.PackStart(hBox2, false, false, 6);

            labelType.Xalign        = 0;
            labelType.HeightRequest = 16;
            hBox = new HBox();
            hBox.PackStart(labelType, false, false, 8);
            vBox.PackStart(hBox, false, false, 2);

            hBox = new HBox();
            hBox.PackStart(documentList, true, true, 1);
            vBox.PackStart(hBox, false, false, 0);

            labelFileName.Xalign    = 0;
            labelFileName.Ellipsize = Pango.EllipsizeMode.Start;
            hBox = new HBox();
            hBox.PackStart(labelFileName, true, true, 8);
            vBox.PackEnd(hBox, false, false, 6);

            Add(vBox);

            var padCategory = new  DocumentList.Category(GettextCatalog.GetString("Pads"));

            DocumentList.Item activeItem = null;

            foreach (Pad pad in IdeApp.Workbench.Pads)
            {
                if (!pad.Visible)
                {
                    continue;
                }
                var item = new DocumentList.Item()
                {
                    Icon  = ImageService.GetIcon(pad.Icon.Name ?? MonoDevelop.Ide.Gui.Stock.GenericFile, IconSize.Menu),
                    Title = pad.Title,
                    Tag   = pad
                };
                if (category == padCategory.Title)
                {
                    if (activeItem == null || (pad.InternalContent.Initialized && pad.Window.HasFocus))
                    {
                        activeItem = item;
                    }
                }
                padCategory.AddItem(item);
            }
            documentList.AddCategory(padCategory);

            var documentCategory = new  DocumentList.Category(GettextCatalog.GetString("Documents"));

            foreach (var doc in documents)
            {
                var item = new DocumentList.Item()
                {
                    Icon        = doc.Icon.WithSize(IconSize.Menu),
                    Title       = doc.Name,
                    ListTitle   = doc.Window.Title,
                    Description = doc.DocumentControllerDescription?.Name ?? "",
                    Path        = doc.Name,
                    Tag         = doc
                };
                if (category == padCategory.Title)
                {
                    if (activeItem == null || doc == IdeApp.Workbench.ActiveDocument)
                    {
                        activeItem = item;
                    }
                }
                documentCategory.AddItem(item);
            }
            documentList.AddCategory(documentCategory);

            documentList.ActiveItemChanged += delegate {
                if (documentList.ActiveItem == null)
                {
                    labelFileName.Text = labelType.Text = labelTitle.Text = "";
                    return;
                }
                imageTitle.Image   = documentList.ActiveItem.Icon;
                labelFileName.Text = documentList.ActiveItem.Path;
                labelType.Markup   = "<span size=\"small\">" + documentList.ActiveItem.Description + "</span>";
                labelTitle.Markup  = "<span size=\"xx-large\" weight=\"bold\">" + documentList.ActiveItem.Title + "</span>";
            };

            if (activeItem == null)
            {
                if (documentCategory.Items.Count > 0)
                {
                    activeItem = documentCategory.Items [0];
                }
                else if (padCategory.Items.Count > 0)
                {
                    activeItem = padCategory.Items [0];
                }
                else
                {
                    // We can't destroy the window in the constructor
                    // so we need to let the caller know that there are no items
                    dialogHasContent = false;
                    return;
                }
            }

            documentList.ActiveItem = activeItem;

            ModifierType modifiers;

            if (Gtk.Global.GetCurrentEventState(out modifiers) && modifiers.HasFlag(ModifierType.ShiftMask))
            {
                documentList.PrevItem(true);
            }
            else
            {
                documentList.NextItem(true);
            }

            documentList.RequestClose += delegate(object sender, DocumentList.RequestActionEventArgs e) {
                object item = e.SelectItem ? documentList.ActiveItem.Tag : null;
                DestroyWindow();

                // The selected document has to be focused *after* this window is destroyed, becasuse the window
                // destruction focuses its parent window.
                if (item != null)
                {
                    if (item is Pad)
                    {
                        ((Pad)item).BringToFront(true);
                    }
                    else
                    {
                        ((MonoDevelop.Ide.Gui.Document)item).Select();
                    }
                }
            };

            this.ShowAll();
            documentList.GrabFocus();
            this.GrabDefault();

            dialogHasContent = true;
        }
Esempio n. 8
0
 static void UpdateInstrumentationIcon()
 {
     if (IdeApp.Preferences.EnableInstrumentation)
     {
         if (instrumentationStatusIcon == null)
         {
             instrumentationStatusIcon         = IdeApp.Workbench.StatusBar.ShowStatusIcon(ImageService.GetPixbuf(Gtk.Stock.DialogInfo));
             instrumentationStatusIcon.ToolTip = "Instrumentation service enabled";
             instrumentationStatusIcon.EventBox.ButtonPressEvent += delegate {
                 InstrumentationService.StartMonitor();
             };
         }
     }
     else if (instrumentationStatusIcon != null)
     {
         instrumentationStatusIcon.Dispose();
     }
 }