Пример #1
0
 public void ApplyTheme(UserInterfaceTheme theme)
 {
     ApplyButtonColor(buildButton, theme.BuildColor);
     ApplyButtonColor(projectButton, theme.ProjectColor);
     ApplyButtonColor(staffButton, theme.StaffColor);
     ApplyButtonColor(infoButton, theme.InfoColor);
     ApplyButtonColor(systemButton, theme.SystemColor);
 }
Пример #2
0
        internal static void UpdateGtkTheme()
        {
            if (DefaultTheme == null)
            {
                SetupGtkTheme();
            }

            string current_theme = IdeApp.Preferences.UserInterfaceThemeName;

            if (!Platform.IsLinux)
            {
                UserInterfaceTheme = IdeApp.Preferences.UserInterfaceThemeName == "Dark" ? Theme.Dark : Theme.Light;
                if (current_theme != UserInterfaceTheme.ToString())                  // Only theme names allowed on Win/Mac
                {
                    current_theme = UserInterfaceTheme.ToString();
                }
            }

            var use_bundled_theme = false;


            // Use the bundled gtkrc only if the Xamarin theme is installed
            if (File.Exists(Path.Combine(Gtk.Rc.ModuleDir, "libxamarin.so")) || File.Exists(Path.Combine(Gtk.Rc.ModuleDir, "libxamarin.dll")))
            {
                use_bundled_theme = true;
            }
            // on Windows we can't rely on Gtk.Rc.ModuleDir to be valid
            // and test additionally the default installation dir
            if (!use_bundled_theme && Platform.IsWindows)
            {
                var gtkBasePath = Environment.GetEnvironmentVariable("GTK_BASEPATH");
                if (String.IsNullOrEmpty(gtkBasePath))
                {
                    gtkBasePath = "C:\\Program Files (x86)\\GtkSharp\\2.12\\";
                }
                if (File.Exists(Path.Combine(gtkBasePath, "lib\\gtk-2.0\\2.10.0\\engines\\libxamarin.dll")))
                {
                    use_bundled_theme = true;
                }
            }

            if (use_bundled_theme)
            {
                if (!Directory.Exists(UserProfile.Current.ConfigDir))
                {
                    Directory.CreateDirectory(UserProfile.Current.ConfigDir);
                }

                if (Platform.IsWindows)
                {
                    // HACK: Gtk Bug: Rc.ReparseAll () and the include "[rcfile]" gtkrc statement are broken on Windows.
                    //                We must provide our own XDG folder structure to switch bundled themes.
                    var rc_themes      = UserProfile.Current.ConfigDir.Combine("share", "themes");
                    var rc_theme_light = rc_themes.Combine("Light", "gtk-2.0", "gtkrc");
                    var rc_theme_dark  = rc_themes.Combine("Dark", "gtk-2.0", "gtkrc");
                    if (!Directory.Exists(rc_theme_light.ParentDirectory))
                    {
                        Directory.CreateDirectory(rc_theme_light.ParentDirectory);
                    }
                    if (!Directory.Exists(rc_theme_dark.ParentDirectory))
                    {
                        Directory.CreateDirectory(rc_theme_dark.ParentDirectory);
                    }

                    string gtkrc = PropertyService.EntryAssemblyPath.Combine("gtkrc");
                    File.Copy(gtkrc + ".win32", rc_theme_light, true);
                    File.Copy(gtkrc + ".win32-dark", rc_theme_dark, true);

                    var themeDir = UserProfile.Current.ConfigDir;
                    if (!themeDir.IsAbsolute)
                    {
                        themeDir = themeDir.ToAbsolute(Environment.CurrentDirectory);
                    }
                    Environment.SetEnvironmentVariable("GTK_DATA_PREFIX", themeDir);

                    // set the actual theme and reset the environment only after Gtk has been fully
                    // initialized. See SetupGtkTheme ().
                    if (Gtk.Settings.Default != null)
                    {
                        LoggingService.LogInfo("GTK: Using Gtk theme from {0}", Path.Combine(Gtk.Rc.ThemeDir, current_theme));
                        Gtk.Settings.Default.ThemeName = current_theme;
                        Environment.SetEnvironmentVariable("GTK_DATA_PREFIX", DefaultGtkDataFolder);
                    }
                }
                else if (Platform.IsMac)
                {
                    var gtkrc = "gtkrc.mac";
                    if (IdeApp.Preferences.UserInterfaceTheme == Theme.Dark)
                    {
                        gtkrc += "-dark";
                    }
                    gtkrc = PropertyService.EntryAssemblyPath.Combine(gtkrc);

                    LoggingService.LogInfo("GTK: Using gtkrc from {0}", gtkrc);

                    // Generate a dummy rc file and use that to include the real rc. This allows changing the rc
                    // on the fly. All we have to do is rewrite the dummy rc changing the include and call ReparseAll
                    var rcFile = UserProfile.Current.ConfigDir.Combine("gtkrc");
                    File.WriteAllText(rcFile, "include \"" + gtkrc + "\"");
                    Environment.SetEnvironmentVariable("GTK2_RC_FILES", rcFile);

                    Gtk.Rc.ReparseAll();

                    // reset the environment only after Gtk has been fully initialized. See SetupGtkTheme ().
                    if (Gtk.Settings.Default != null)
                    {
                        Environment.SetEnvironmentVariable("GTK2_RC_FILES", DefaultGtk2RcFiles);
                    }
                }
            }
            else if (Gtk.Settings.Default != null && current_theme != Gtk.Settings.Default.ThemeName)
            {
                LoggingService.LogInfo("GTK: Using Gtk theme from {0}", Path.Combine(Gtk.Rc.ThemeDir, current_theme));
                Gtk.Settings.Default.ThemeName = current_theme;
            }

            // let Gtk realize the new theme
            // Style is being updated by DefaultWorkbench.OnStyleSet ()
            // This ensures that the theme and all styles have been loaded when
            // the Styles.Changed event is raised.
            //GLib.Timeout.Add (50, delegate { UpdateStyles(); return false; });
        }