Exemplo n.º 1
0
        /// <summary>Converts a value. </summary>
        /// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            IEnumerable <IPresetObject> presets = value as IEnumerable <IPresetObject>;

            if (presets == null)
            {
                return(null);
            }

            List <object> groupedMenu = new List <object>();

            // Generate the Preset Manager Item
            if (parameter != null && "true".Equals(parameter))
            {
                MenuItem savePresetMenuItem = new MenuItem
                {
                    Header  = Resources.MainView_SaveNewPreset,
                    Tag     = null,
                    Command = new AddPresetCommand()
                };
                groupedMenu.Add(savePresetMenuItem);

                MenuItem presetManagerMenuItem = new MenuItem
                {
                    Header  = Resources.PresetManger_Title,
                    Tag     = null,
                    Command = new OpenPresetManagerCommand()
                };
                groupedMenu.Add(presetManagerMenuItem);


                groupedMenu.Add(new Separator());
            }

            IEnumerable <IPresetObject> presetObjects = presets.ToList();

            PresetDisplayMode mode = userSettingService.GetUserSetting <PresetDisplayMode>(UserSettingConstants.PresetMenuDisplayMode);

            switch (mode)
            {
            case PresetDisplayMode.Flat:
                GenerateFlatList(groupedMenu, presetObjects.ToList());
                break;

            case PresetDisplayMode.Partial:
                GenerateUserPresets(groupedMenu, presetObjects.FirstOrDefault(p => p.Category == PresetService.UserPresetCategoryName));
                GeneratePresets(groupedMenu, presetObjects.ToList(), mode);
                break;

            case PresetDisplayMode.Category:
                GeneratePresets(groupedMenu, presetObjects.ToList(), mode);
                break;
            }

            return(groupedMenu);
        }
Exemplo n.º 2
0
        private void GeneratePresets(List <object> groupedMenu, IList <IPresetObject> userPresets, PresetDisplayMode displayMode)
        {
            if (!userPresets.Any(s => s.Category != PresetService.UserPresetCategoryName))
            {
                return;
            }

            if (displayMode == PresetDisplayMode.Partial)
            {
                groupedMenu.Add(GenerateMenuHeader(Resources.Main_Presets));
                groupedMenu.Add(new Separator());
            }

            foreach (IPresetObject presetCategory in userPresets)
            {
                if (displayMode == PresetDisplayMode.Partial && PresetService.UserPresetCategoryName.Equals(presetCategory.Category))
                {
                    continue; // In Partially Flat mode, we show the user presets flat so no need to include the category.
                }

                PresetDisplayCategory category = presetCategory as PresetDisplayCategory;
                if (category != null)
                {
                    groupedMenu.Add(GeneratePresetGroup(category));
                }
            }
        }