コード例 #1
0
        /// <summary>
        /// Runs the application.
        /// </summary>
        /// <typeparam name="T">The type for the main window class.</typeparam>
        /// <param name="uniqueInstance">Unique instance string.</param>
        /// <param name="applicationInfo">The application description.</param>
        /// <param name="args">Command line arguments.</param>
        /// <param name="splashScreenImage">Splash screen image.</param>
        public static void RunApplication <T>(string uniqueInstance, IApplicationInfo applicationInfo, string[] args, string splashScreenImage) where T : Gtk.Window, IMainWindow, new()
        {
            // TODO: Single instance check / activate
            // Documentation of Gtk.Application.Init(progname, ref args) implies that
            // a single instance should be enforced. Sadly, that does not seem to work
            // as expected. Perhaps it's the C#iness of it all.

            // show splash screen
            AppInfo               = applicationInfo;
            _mainWindowType       = typeof(T);
            _splashScreenResource = splashScreenImage;
            Gtk.Application.Init(uniqueInstance, ref args);

            SettingsBase.LoadApplicationSettings();
            var window = new T();

            Instance.MainWindow  = window;
            Instance.ReadyState |= AppReadyState.MainWindowSourced;

            Gtk.Window.DefaultIcon = window.Icon;
            var splashImage  = _mainWindowType.LoadImageResource(_splashScreenResource);
            var splashScreen = new SplashScreen(splashImage); // creating also shows

            splashScreen.TransientFor   = window;
            window.Data["SplashScreen"] = splashScreen;
            GLib.Timeout.Add(1000, FinishInitialization);
            Gtk.Application.Run();
            foreach (var settings in Instance.Settings)
            {
                settings.Save();
            }
            SettingsBase.SaveApplicationSettings();
        }