Beispiel #1
0
        public void SaveProfile(ThemeProfile profile)
        {
            ThemeProfileRecord record;

            if (profile.Id == 0)
            {
                record = new ThemeProfileRecord();
                Session.Save(record);
                profile.Id = record.Id;
            }
            else
            {
                record = Session.Get <ThemeProfileRecord>(profile.Id);
            }

            record.Name        = profile.Name;
            record.Description = profile.Description;
            record.Theme       = profile.Theme;
            record.Settings    = SerializeSettings(profile.Settings);
            record.IsCurrent   = profile.IsCurrent;

            // If the specified profile is marked as current, we need to mark any previous profile to be not current.
            if (record.IsCurrent)
            {
                var previousCurrentProfiles = Session.QueryOver <ThemeProfileRecord>().Where(x => x.IsCurrent && x.Id != record.Id).List();

                foreach (var previousCurrentProfile in previousCurrentProfiles)
                {
                    previousCurrentProfile.IsCurrent = false;
                }
            }
        }
        public ActionResult Create(string id, ProfileViewModel viewModel, FormCollection formCollection)
        {
            viewModel.Theme = _themeSettingsService.GetTheme(id);

            if (!ModelState.IsValid)
            {
                var settingsManifest = _themeSettingsService.GetSettingsManifest(id);
                var form             = _settingsFormBuilder.BuildForm(settingsManifest);
                _settingsFormBuilder.BindForm(form, formCollection);
                viewModel.SettingsForm = _settingsFormBuilder.BindForm(form, formCollection);
                return(View(viewModel));
            }

            var profile = new ThemeProfile
            {
                Name        = viewModel.Name.TrimSafe(),
                Description = viewModel.Description.TrimSafe(),
                Theme       = id,
                Settings    = ParseThemeSettings(formCollection),
                IsCurrent   = viewModel.IsCurrent
            };

            _themeSettingsService.SaveProfile(profile);
            _notifier.Information(T("The profile {0} for the {1} theme was succesfully created.", viewModel.Name, viewModel.Theme.Name));

            return(RedirectToAction("Edit", new { id = profile.Id }));
        }
Beispiel #3
0
        public ThemeProfile CloneProfile(ThemeProfile profile)
        {
            var clone = new ThemeProfile
            {
                Name        = String.Format("{0} - clone", profile.Name),
                Description = profile.Description,
                Theme       = profile.Theme,
                Settings    = profile.Settings.ToDictionary(x => x.Key, x => new ThemeSetting {
                    Name = x.Value.Name, Value = x.Value.Value
                }),
                IsCurrent = false
            };

            return(clone);
        }
Beispiel #4
0
 private static void Load(string file)
 {
     if (!File.Exists(file))
     {
         return;
     }
     try
     {
         var profile = ThemeProfile.Load(file);
         if (profile.ProfileVersion < ThemeProfile.CurrentProfileVersion)
         {
             MainWindowModel.ShowTaskDialog(
                 new TaskDialogOptions
             {
                 Title           = "テーマの互換性",
                 MainIcon        = VistaTaskDialogIcon.Warning,
                 MainInstruction = "テーマ ファイルを読み込めませんでした。",
                 Content         = "テーマ バージョンが古いため、互換性がありません。" + Environment.NewLine +
                                   file,
                 ExpandedInfo = "新しいバージョンのテーマを入手するか、最新のフォーマットに則った記述へ変更してください。" + Environment.NewLine +
                                "(default.xmlについてこのエラーが表示された場合は、自動的に最新のフォーマットに更新されます。)",
                 CommonButtons = TaskDialogCommonButtons.Close
             });
             return;
         }
         ThemeProfiles[profile.Name] = profile;
     }
     catch (Exception ex)
     {
         MainWindowModel.ShowTaskDialog(
             new TaskDialogOptions
         {
             Title           = "テーマ エラー",
             MainIcon        = VistaTaskDialogIcon.Error,
             MainInstruction = "テーマ ファイルを読み込めませんでした。",
             Content         = "XMLの記述に誤りがあります:" + Environment.NewLine +
                               file,
             ExpandedInfo  = ex.Message,
             CommonButtons = TaskDialogCommonButtons.Close
         });
     }
 }
Beispiel #5
0
 private static void Load(string file)
 {
     if (!File.Exists(file))
     {
         return;
     }
     try
     {
         var profile = ThemeProfile.Load(file);
         if (profile.ProfileVersion < ThemeProfile.CurrentProfileVersion)
         {
             MainWindowModel.ShowTaskDialog(
                 new TaskDialogOptions
             {
                 Title           = SettingModelResources.ThemeIncompatibleTitle,
                 MainIcon        = VistaTaskDialogIcon.Warning,
                 MainInstruction = SettingModelResources.ThemeIncompatibleInst,
                 Content         = SettingModelResources.ThemeIncompatibleContent + Environment.NewLine + file,
                 ExpandedInfo    = SettingModelResources.ThemeIncompatibleExInfo,
                 CommonButtons   = TaskDialogCommonButtons.Close
             });
             return;
         }
         ThemeProfiles[profile.Name] = profile;
     }
     catch (Exception ex)
     {
         MainWindowModel.ShowTaskDialog(
             new TaskDialogOptions
         {
             Title           = SettingModelResources.ThemeErrorTitle,
             MainIcon        = VistaTaskDialogIcon.Error,
             MainInstruction = SettingModelResources.ThemeErrorInst,
             Content         = SettingModelResources.ThemeErrorContent + Environment.NewLine + file,
             ExpandedInfo    = ex.Message,
             CommonButtons   = TaskDialogCommonButtons.Close
         });
     }
 }
Beispiel #6
0
 public static string GetThemeSetting(this HtmlHelper html, ThemeProfile profile, string name, string defaultValue = null)
 {
     return(profile != null && profile.Settings.ContainsKey(name) ? profile.Settings[name].Value : defaultValue);
 }