示例#1
0
文件: Main.cs 项目: mfcallahan/Pinta
        public static void Main(string[] args)
        {
            if (SystemManager.GetOperatingSystem() == OS.Mac)
            {
                MacInterop.Environment.Init();
            }

            string locale_dir = Path.Combine(SystemManager.GetDataRootDirectory(), "locale");

            try {
                Translations.Init("pinta", locale_dir);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }

            int  threads      = -1;
            bool show_help    = false;
            bool show_version = false;

            var p = new OptionSet()
            {
                { "h|help", Translations.GetString("Show this message and exit."), v => show_help = v != null },
                { "v|version", Translations.GetString("Display the application version."), v => show_version = v != null },
                { "rt|render-threads=", Translations.GetString("number of threads to use for rendering"), (int v) => threads = v }
            };

            List <string> extra;

            try {
                extra = p.Parse(args);
            } catch (OptionException e) {
                Console.WriteLine(e.Message);
                ShowHelp(p);
                return;
            }

            if (show_version)
            {
                Console.WriteLine(PintaCore.ApplicationVersion);
                return;
            }

            if (show_help)
            {
                ShowHelp(p);
                return;
            }

            GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(ExceptionManager_UnhandledException);

            Application.Init();

            // For testing a dark variant of the theme.
            //Gtk.Settings.Default.SetProperty("gtk-application-prefer-dark-theme", new GLib.Value(true));

            // Add our icons to the search path.
            Gtk.IconTheme.Default.AppendSearchPath(Pinta.Core.SystemManager.GetDataRootDirectory() + "/icons");

            var app = new MainWindow();

            if (threads != -1)
            {
                Pinta.Core.PintaCore.System.RenderThreads = threads;
            }

            if (SystemManager.GetOperatingSystem() == OS.Mac)
            {
                RegisterForAppleEvents();
            }

            // TODO-GTK3 - try using the GTK command line parsing once GtkSharp supports it.
            app.Activated += (_, _) => OpenFilesFromCommandLine(extra);
            app.Run("pinta", Array.Empty <string> ());
        }