Exemplo n.º 1
0
        public Theme LoadTheme()
        {
            var path = Path.Combine(PathFactory.GetAppDataPath(), Resx.ThemesFolder);

            PathFactory.EnsurePathExists(path);

            using (var dialog = new OpenFileDialog())
            {
                dialog.DefaultExt         = "xml";
                dialog.Filter             = "Theme files (*.xml)|*.xml|All files (*.*)|*.*";
                dialog.Multiselect        = false;
                dialog.Title              = "Open Style Theme";
                dialog.ShowHelp           = true;       // stupid, but this is needed to avoid hang
                dialog.AutoUpgradeEnabled = true;       // simpler UI, faster
                dialog.InitialDirectory   = path;

                if (dialog.ShowDialog(owner) != DialogResult.OK)
                {
                    return(null);
                }

                var theme = new ThemeProvider(dialog.FileName).Theme;
                if (theme != null)
                {
                    var styles = theme.GetStyles();
                    if (styles.Count > 0)
                    {
                        return(theme);
                    }
                }

                UIHelper.ShowError("could not load theme file or them contains no styles");
                return(null);
            }
        }