Example #1
0
 private static void AddApplication(WindowsThemes windowsThemes, ApplicationThemes applicationThemes)
 {
     if (windowsThemes.Applications.All(a => a.Name != applicationThemes.Name))
     {
         windowsThemes.Applications.Add(applicationThemes);
     }
 }
Example #2
0
        /// <summary>
        /// CTOR
        /// </summary>
        public ShellSettingsFlyoutViewModel()
        {
            localizerService = Container.Resolve <ILocalizerService>(ServiceNames.LocalizerService);

            // create metro theme color menu items for the demo
            ApplicationThemes = ThemeManager.AppThemes
                                .Select(a => new ApplicationTheme()
            {
                Name             = a.Name,
                BorderColorBrush = a.Resources["BlackColorBrush"] as Brush,
                ColorBrush       = a.Resources["WhiteColorBrush"] as Brush
            })
                                .ToList();

            // create accent colors list
            AccentColors = ThemeManager.Accents
                           .Select(a => new AccentColor()
            {
                Name = a.Name, ColorBrush = a.Resources["AccentColorBrush"] as Brush
            })
                           .ToList();

            SelectedTheme       = ApplicationThemes.Where(c => c.Name.Equals(Properties.Settings.Default.Theme)).FirstOrDefault();
            SelectedAccentColor = AccentColors.Where(c => c.Name.Equals(Properties.Settings.Default.Color)).FirstOrDefault();
            SelectedLanguage    = SupportedLanguages.Where(c => c.Name.Equals(Properties.Settings.Default.Language)).FirstOrDefault();

            Container.Resolve <ILoggerFacade>().Log("ShellSettingsFlyoutViewModel created", Category.Info, Priority.None);
        }
Example #3
0
        static StyleSettings()
        {
            applicationName = GetAppName();
            var windowsThemes = LoadWindowsThemes();

            if (windowsThemes.Applications == null)
            {
                windowsThemes.Applications = new List <ApplicationThemes>();
            }

            applicationTheme = FindApplication(windowsThemes, applicationName);
            theme            = GetTheme(applicationTheme?.Theme);
        }
Example #4
0
        internal static void SaveWindowTheme(BaseWindow?window, Pik.Metro.Theme wTheme, bool isOnlyThisWindow)
        {
            try
            {
                var windowsThemes = LoadWindowsThemes();
                applicationTheme = FindApplication(windowsThemes, applicationName);
                if (applicationTheme == null)
                {
                    applicationTheme = new ApplicationThemes {
                        Name = applicationName
                    };
                    windowsThemes.Applications.Add(applicationTheme);
                }

                if (isOnlyThisWindow && window != null)
                {
                    var windowTheme = FindWindowTheme(window);
                    if (windowTheme == null)
                    {
                        windowTheme = new WindowTheme {
                            Window = GetWindowName(window)
                        };
                        applicationTheme.Windows.Add(windowTheme);
                        AddApplication(windowsThemes, applicationTheme);
                    }

                    windowTheme.Theme = wTheme.Name;
                }
                else
                {
                    var windowTheme = FindWindowTheme(window);
                    if (windowTheme != null)
                    {
                        applicationTheme.Windows.Remove(windowTheme);
                    }

                    theme = wTheme;
                    applicationTheme.Theme = theme.Name;
                    Change?.Invoke(null, EventArgs.Empty);
                }

                var file = GetWindowsThemesFile();
                Save(file, windowsThemes);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "SaveWindowTheme");
            }
        }
Example #5
0
        [ExcludeFromCodeCoverage] // TODO: could maybe remove after creating a test of this
        public SettingsFlyoutViewModel()
        {
//            localizerService = Container.Resolve<ILocalizerService>(ServiceNames.LOCALIZER_SERVICE);

            // create metro theme color menu items for the demo
            ApplicationThemes = ThemeManager.AppThemes.Select(a => new ApplicationTheme
            {
                Name             = a.Name,
                BorderColorBrush = a.Resources["BlackColorBrush"] as Brush,
                ColorBrush       = a.Resources["WhiteColorBrush"] as Brush
            }).ToList();

            // create accent colors list
            AccentColors = ThemeManager.Accents.Select(a => new AccentColor
            {
                Name       = a.Name,
                ColorBrush = a.Resources["AccentColorBrush"] as Brush
            }).ToList();

            SelectedTheme       = ApplicationThemes.FirstOrDefault(t => t.Name.Equals("BaseDark"));
            SelectedAccentColor = AccentColors.FirstOrDefault(c => c.Name.Equals("Cobalt"));
        }
        /// <summary>
        /// This procedure changes the current WPF Application Theme into another theme
        /// while the application is running (re-boot should not be required).
        /// </summary>
        /// <param name="e"></param>
        /// <param name="disp"></param>
        private void ChangeThemeCmd_Executed(object s,
                                             ExecutedRoutedEventArgs e,
                                             System.Windows.Threading.Dispatcher disp)
        {
            string oldTheme = Factory.DefaultThemeName;

            try
            {
                if (e == null)
                {
                    return;
                }

                if (e.Parameter == null)
                {
                    return;
                }

                string newThemeName = e.Parameter as string;

                // Check if request is available
                if (newThemeName == null)
                {
                    return;
                }

                oldTheme = _SettingsManager.SettingData.CurrentTheme;

                // The Work to perform on another thread
                ThreadStart start = delegate
                {
                    // This works in the UI tread using the dispatcher with highest Priority
                    disp.Invoke(DispatcherPriority.Send,
                                (Action)(() =>
                    {
                        try
                        {
                            if (ApplicationThemes.SetSelectedTheme(newThemeName) == false)
                            {
                                return;
                            }

                            _SettingsManager.SettingData.CurrentTheme = newThemeName;
                            ResetTheme();                        // Initialize theme in process
                        }
                        catch (Exception exp)
                        {
                            Logger.Error(exp.Message, exp);
                            _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton,
                                         _AppCore.IssueTrackerLink,
                                         _AppCore.IssueTrackerLink,
                                         Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true);
                        }
                    }));
                };

                // Create the thread and kick it started!
                Thread thread = new Thread(start);

                thread.Start();
            }
            catch (Exception exp)
            {
                _SettingsManager.SettingData.CurrentTheme = oldTheme;

                Logger.Error(exp.Message, exp);
                _MsgBox.Show(exp, Edi.Util.Local.Strings.STR_MSG_IssueTrackerTitle, MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton,
                             _AppCore.IssueTrackerLink,
                             _AppCore.IssueTrackerLink,
                             Edi.Util.Local.Strings.STR_MSG_IssueTrackerText, null, true);
            }
        }