80
80
LoggingService.LogInfo ("Logging instrumentation service data to file: " + logFile);
81
81
InstrumentationService.StartAutoSave (logFile, 1000);
84
//ensure native libs initialized before we hit anything that p/invokes
85
Platform.Initialize ();
84
87
Counters.Initialization.Trace ("Initializing GTK");
88
if (Platform.IsWindows) {
85
91
SetupExceptionManager ();
89
95
} catch (Exception ex) {
90
96
LoggingService.LogError ("Error initialising GLib logging.", ex);
94
101
var args = options.RemainingArgs.ToArray ();
95
Gtk.Application.Init ("monodevelop", ref args);
102
Gtk.Application.Init (BrandingService.ApplicationName, ref args);
104
FilePath p = typeof(IdeStartup).Assembly.Location;
105
Assembly.LoadFrom (p.ParentDirectory.Combine ("Xwt.Gtk.dll"));
106
Xwt.Application.Initialize (Xwt.ToolkitType.Gtk);
107
Xwt.Engine.Toolkit.ExitUserCode (null);
97
109
//default to Windows IME on Windows
98
110
if (Platform.IsWindows && Mono.TextEditor.GtkWorkarounds.GtkMinorVersion >= 16) {
99
111
var settings = Gtk.Settings.Default;
143
Counters.Initialization.Trace ("Initializing Runtime");
144
Runtime.Initialize (true);
146
Counters.Initialization.Trace ("Initializing theme and splash window");
131
148
DefaultTheme = Gtk.Settings.Default.ThemeName;
132
if (!string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceTheme))
133
Gtk.Settings.Default.ThemeName = IdeApp.Preferences.UserInterfaceTheme;
149
if (!string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceTheme)) {
151
if (!ValidateGtkTheme (IdeApp.Preferences.UserInterfaceTheme, out theme))
153
Gtk.Settings.Default.ThemeName = theme;
135
156
//don't show the splash screen on the Mac, so instead we get the expected "Dock bounce" effect
136
157
//this also enables the Mac platform service to subscribe to open document events before the GUI loop starts.
137
158
if (Platform.IsMac)
138
159
options.NoSplash = true;
140
IProgressMonitor monitor;
142
if (options.NoSplash) {
161
IProgressMonitor monitor = null;
162
if (!options.NoSplash) {
164
monitor = new SplashScreenForm ();
165
((SplashScreenForm)monitor).ShowAll ();
166
} catch (Exception ex) {
167
LoggingService.LogError ("Failed to create splash screen", ex);
170
if (monitor == null) {
143
171
monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor ();
145
monitor = SplashScreenForm.SplashScreen;
146
SplashScreenForm.SplashScreen.ShowAll ();
149
Counters.Initialization.Trace ("Initializing Runtime");
150
monitor.BeginTask (GettextCatalog.GetString ("Starting {0}", BrandingService.ApplicationName), 3);
152
Runtime.Initialize (true);
174
monitor.BeginTask (GettextCatalog.GetString ("Starting {0}", BrandingService.ApplicationName), 2);
154
176
//make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events
155
177
Counters.Initialization.Trace ("Initializing Platform Service");
156
178
DesktopService.Initialize ();
211
226
if (errorsList.Count > 0) {
212
227
if (monitor is SplashScreenForm)
213
SplashScreenForm.SplashScreen.Hide ();
228
((SplashScreenForm)monitor).Hide ();
214
229
AddinLoadErrorDialog dlg = new AddinLoadErrorDialog ((AddinError[]) errorsList.ToArray (typeof(AddinError)), false);
217
232
if (monitor is SplashScreenForm)
218
SplashScreenForm.SplashScreen.Show ();
233
((SplashScreenForm)monitor).Show ();
219
234
reportedFailures = errorsList.Count;
301
// Use the bundled gtkrc only if the Xamarin theme is installed
302
if (File.Exists (Path.Combine (Gtk.Rc.ModuleDir, "libxamarin.so")) || File.Exists (Path.Combine (Gtk.Rc.ModuleDir, "libxamarin.dll"))) {
304
if (Platform.IsWindows) {
306
} else if (Platform.IsMac) {
309
Environment.SetEnvironmentVariable ("GTK2_RC_FILES", PropertyService.EntryAssemblyPath.Combine (gtkrc));
313
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
314
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
315
static extern bool SetDllDirectory (string lpPathName);
317
static void CheckWindowsGtk ()
319
string location = null;
320
using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\InstallFolder")) {
322
location = key.GetValue (null) as string;
325
if (location == null || !File.Exists (Path.Combine (location, "bin", "libgtk-win32-2.0-0.dll"))) {
326
LoggingService.LogError ("Did not find registered GTK# installation");
329
var path = Path.Combine (location, @"bin");
331
if (SetDllDirectory (path)) {
334
} catch (EntryPointNotFoundException) {
336
LoggingService.LogError ("Unable to set GTK# dll directory");
284
339
public bool Initialized {
285
340
get { return initialized; }
355
410
IdeApp.Workbench.Present ();
414
internal readonly static string[] FailingGtkThemes = new string[] {
419
internal static string[] gtkThemeFallbacks = new string[] {
422
"Radiance", // Ubuntu 'light' theme (MD looks better with the light theme in 4.0 - if that changes switch this one)
423
"Clearlooks" // GTK theme
426
bool ValidateGtkTheme (string requestedTheme, out string validTheme)
361
if (Gtk.Settings.Default.ThemeName == "QtCurve") {
362
string msg = "QtCurve theme not supported";
363
string desc = "Your system is using the QtCurve GTK+ theme. This theme is known to cause stability issues in MonoDevelop. Please select another theme in the GTK+ Theme Selector.\n\nIf you click on Proceed, MonoDevelop will switch to the default GTK+ theme.";
364
AlertButton res = MessageService.GenericAlert (Gtk.Stock.DialogWarning, msg, desc, AlertButton.Cancel, AlertButton.Proceed);
365
if (res == AlertButton.Cancel)
367
Gtk.Settings.Default.ThemeName = "Gilouche";
428
foreach (var theme in FailingGtkThemes) {
429
if (requestedTheme == theme) {
430
string msg = theme +" theme not supported";
431
string desc = "Your system is using the " + theme + " GTK+ theme. This theme is known to cause stability issues in MonoDevelop. Please select another theme in the GTK+ Theme Selector.\n\nIf you click on Proceed, MonoDevelop will switch to the default GTK+ theme.";
432
AlertButton res = MessageService.GenericAlert (Gtk.Stock.DialogWarning, msg, desc, AlertButton.Cancel, AlertButton.Proceed);
433
if (res == AlertButton.Cancel) {
437
var themes = MonoDevelop.Ide.Gui.OptionPanels.IDEStyleOptionsPanelWidget.InstalledThemes;
438
string fallback = null;
439
foreach (string fb in gtkThemeFallbacks) {
440
var foundTheme = themes.FirstOrDefault (t => string.Compare (fb, t, StringComparison.OrdinalIgnoreCase) == 0);
441
if (foundTheme != null) {
442
fallback = foundTheme;
447
validTheme = fallback ?? themes.FirstOrDefault () ?? requestedTheme;
448
return validTheme != null;
452
validTheme = requestedTheme;
380
464
string msg = "Inotify watch limit is too low (" + n + ").\n";
381
465
msg += "MonoDevelop will switch to managed file watching.\n";
382
466
msg += "See http://monodevelop.com/Inotify_Watches_Limit for more info.";
383
LoggingService.LogWarning (msg);
467
LoggingService.LogWarning (BrandingService.BrandApplicationName (msg));
384
468
Runtime.ProcessService.EnvironmentVariableOverrides["MONO_MANAGED_WATCHER"] =
385
469
Environment.GetEnvironmentVariable ("MONO_MANAGED_WATCHER");
386
470
Environment.SetEnvironmentVariable ("MONO_MANAGED_WATCHER", "1");
390
474
LoggingService.LogWarning ("There was a problem checking whether to use managed file watching", e);
394
bool CheckBug77135 ()
397
// Check for bug 77135. Some versions of gnome-vfs2 and libgda
398
// make MD crash in the file open dialog or in FileIconLoader.
401
string path = "/etc/SuSE-release";
402
if (!File.Exists (path))
405
// Only run the check for SUSE 10
406
StreamReader sr = File.OpenText (path);
407
string txt = sr.ReadToEnd ();
410
if (txt.IndexOf ("SUSE LINUX 10") == -1)
413
string current_libgda;
414
string current_gnomevfs;
415
string required_libgda = "1.3.91.5.4";
416
string required_gnomevfs = "2.12.0.9.2";
418
StringWriter sw = new StringWriter ();
419
ProcessWrapper pw = Runtime.ProcessService.StartProcess ("rpm", "--qf %{version}.%{release} -q libgda", null, sw, null, null);
421
current_libgda = sw.ToString ().Trim (' ','\n');
423
sw = new StringWriter ();
424
pw = Runtime.ProcessService.StartProcess ("rpm", "--qf %{version}.%{release} -q gnome-vfs2", null, sw, null, null);
426
current_gnomevfs = sw.ToString ().Trim (' ','\n');
428
bool fail1 = Addin.CompareVersions (current_libgda, required_libgda) == 1;
429
bool fail2 = Addin.CompareVersions (current_gnomevfs, required_gnomevfs) == 1;
431
if (fail1 || fail2) {
432
string msg = GettextCatalog.GetString ("Some packages installed in your system are not compatible with MonoDevelop:\n");
434
msg += "\nlibgda " + current_libgda + " ("+ GettextCatalog.GetString ("version required: {0}", required_libgda) + ")";
436
msg += "\ngnome-vfs2 " + current_gnomevfs + " ("+ GettextCatalog.GetString ("version required: {0}", required_gnomevfs) + ")";
438
msg += GettextCatalog.GetString ("You need to upgrade the previous packages to start using MonoDevelop.");
440
SplashScreenForm.SplashScreen.Hide ();
441
Gtk.MessageDialog dlg = new Gtk.MessageDialog (null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg);
451
// Just ignore for now.
452
Console.WriteLine (ex);
457
478
void SetupExceptionManager ()
480
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, e) => {
481
HandleException (e.Exception.Flatten (), false);
459
484
GLib.ExceptionManager.UnhandledException += delegate (GLib.UnhandledExceptionArgs args) {
460
485
HandleException ((Exception)args.ExceptionObject, args.IsTerminating);
462
487
AppDomain.CurrentDomain.UnhandledException += delegate (object sender, UnhandledExceptionEventArgs args) {
463
488
HandleException ((Exception)args.ExceptionObject, args.IsTerminating);
490
Xwt.Application.UnhandledException += (sender, e) => {
491
HandleException (e.ErrorException, false);
467
495
void HandleException (Exception ex, bool willShutdown)
498
526
bool retry = false;
501
Runtime.SetProcessName (BrandingService.ApplicationName);
529
var exename = Path.GetFileNameWithoutExtension (Assembly.GetEntryAssembly ().Location);
530
if (!Platform.IsMac && !Platform.IsWindows)
531
exename = exename.ToLower ();
532
Runtime.SetProcessName (exename);
502
533
var app = new IdeStartup ();
503
534
ret = app.Run (options);
505
536
} catch (Exception ex) {
506
537
if (!retry && AddinManager.IsInitialized) {
507
LoggingService.LogWarning (BrandingService.ApplicationName + " failed to start. Rebuilding addins registry.");
538
LoggingService.LogWarning (BrandingService.ApplicationName + " failed to start. Rebuilding addins registry.", ex);
508
539
AddinManager.Registry.Rebuild (new Mono.Addins.ConsoleProgressStatus (true));
509
LoggingService.LogInfo ("Addin registry rebuilt. Restarting MonoDevelop.");
540
LoggingService.LogInfo ("Addin registry rebuilt. Restarting {0}.", BrandingService.ApplicationName);
512
LoggingService.LogFatalError (BrandingService.ApplicationName + " failed to start. Some of the assemblies required to run MonoDevelop (for example gtk-sharp, gnome-sharp or gtkhtml-sharp) may not be properly installed in the GAC.", ex);
543
LoggingService.LogFatalError (
545
"{0} failed to start. Some of the assemblies required to run {0} (for example gtk-sharp)" +
546
"may not be properly installed in the GAC.",
547
BrandingService.ApplicationName