Skip to content

Commit

Permalink
Added "Sort" attribute for configuration items
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheusxx committed Nov 1, 2014
1 parent 95e57fe commit 4e4e3a1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
Expand Up @@ -40,6 +40,7 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
{
string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
string text = null;
string sort = null;
string iconSmallPath = null;
string iconLargePath = null;
foreach (KeyValuePair<string, string> attr in itemData.Attributes)
Expand All @@ -49,6 +50,9 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
case "Text":
text = attr.Value;
break;
case "Sort":
sort = attr.Value;
break;
case "IconSmallPath":
iconSmallPath = attr.Value;
break;
Expand All @@ -61,7 +65,7 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
}
if (text == null)
throw new ArgumentException("'ConfigSection' item needs an attribute 'Text'");
return new ConfigSectionMetadata(location, text,
return new ConfigSectionMetadata(location, text, sort,
plugin.Metadata.GetAbsolutePath(iconSmallPath),
plugin.Metadata.GetAbsolutePath(iconLargePath));
}
Expand All @@ -71,27 +75,32 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
{
string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
string text = null;
string sort = null;
foreach (KeyValuePair<string, string> attr in itemData.Attributes)
{
switch (attr.Key)
{
case "Text":
text = attr.Value;
break;
case "Sort":
sort = attr.Value;
break;
default:
throw new ArgumentException("'ConfigGroup' builder doesn't define an attribute '" + attr.Key + "'");
}
}
if (text == null)
throw new ArgumentException("'ConfigGroup' item needs an attribute 'Text'");
return new ConfigGroupMetadata(location, text);
return new ConfigGroupMetadata(location, text, sort);
}

protected static ConfigSettingMetadata BuildSetting(
PluginItemMetadata itemData, PluginRuntime plugin)
{
string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
string text = null;
string sort = null;
string className = null;
string helpText = null;
ICollection<string> listenTo = null;
Expand All @@ -102,6 +111,9 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
case "Text":
text = attr.Value;
break;
case "Sort":
sort = attr.Value;
break;
case "ClassName":
className = attr.Value;
break;
Expand All @@ -117,14 +129,15 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
}
if (text == null)
throw new ArgumentException("'ConfigSetting' item needs an attribute 'Text'");
return new ConfigSettingMetadata(location, text, className, helpText, listenTo);
return new ConfigSettingMetadata(location, text, sort, className, helpText, listenTo);
}

protected static ConfigSettingMetadata BuildCustomSetting(
PluginItemMetadata itemData, PluginRuntime plugin)
{
string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
string text = null;
string sort = null;
string className = null;
string helpText = null;
IDictionary<string, string> additionalData = null;
Expand All @@ -137,6 +150,9 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
case "Text":
text = attr.Value;
break;
case "Sort":
sort = attr.Value;
break;
case "ClassName":
className = attr.Value;
break;
Expand All @@ -158,7 +174,7 @@ protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData,
}
if (text == null)
throw new ArgumentException("'ConfigSetting' item needs an attribute 'Text'");
ConfigSettingMetadata result = new ConfigSettingMetadata(location, text, className, helpText, listenTo)
ConfigSettingMetadata result = new ConfigSettingMetadata(location, text, sort, className, helpText, listenTo)
{
AdditionalData = additionalData,
AdditionalTypes = additionalTypes
Expand Down Expand Up @@ -243,4 +259,4 @@ public bool NeedsPluginActive(PluginItemMetadata itemData, PluginRuntime plugin)

#endregion
}
}
}
Expand Up @@ -133,7 +133,7 @@ protected void LoadChildren()
continue;
logger.Warn("Configuration: Configuration section '{0}' was found in the tree but not explicitly registered as section (config items in this section are registered by those plugins: {1})",
childLocation, StringUtils.Join(", ", FindPluginRegistrations(childLocation)));
ConfigSectionMetadata dummyMetadata = new ConfigSectionMetadata(childLocation, Constants.INVALID_SECTION_TEXT, null, null);
ConfigSectionMetadata dummyMetadata = new ConfigSectionMetadata(childLocation, Constants.INVALID_SECTION_TEXT, null, null, null);
ConfigSection dummySection = new ConfigSection();
dummySection.SetMetadata(dummyMetadata);
AddChildNode(dummySection);
Expand Down Expand Up @@ -332,6 +332,11 @@ public string Location
}
}

public string Sort
{
get { return _configObj == null ? string.Empty : _configObj.Metadata.Sort; }
}

public ConfigBase ConfigObj
{
get { return _configObj; }
Expand Down Expand Up @@ -362,4 +367,4 @@ public IConfigurationNode GetSubNodeById(string id)

#endregion
}
}
}
Expand Up @@ -39,6 +39,7 @@ public class ConfigBaseMetadata

protected string _location;
protected string _text;
protected string _sort;

#endregion

Expand Down Expand Up @@ -85,6 +86,14 @@ public string Text
get { return _text; }
}

/// <summary>
/// Returns a string used for ordering of items.
/// </summary>
public string Sort
{
get { return _sort; }
}

#endregion

#region Constructors
Expand All @@ -95,10 +104,12 @@ public string Text
/// <param name="location">The location of the new instance. This must contain the parent location
/// if there is a parent, and the Id of this setting registration as last location path element.</param>
/// <param name="text">The text to be displayed for this setting registration.</param>
public ConfigBaseMetadata(string location, string text)
/// <param name="sort">Sorting information.</param>
public ConfigBaseMetadata(string location, string text, string sort)
{
_location = location;
_text = text;
_sort = sort;
}

#endregion
Expand Down Expand Up @@ -173,4 +184,4 @@ public static string RemoveTrailingSlash(string location)

#endregion
}
}
}
Expand Up @@ -29,6 +29,6 @@ namespace MediaPortal.Common.Configuration
/// </summary>
public class ConfigGroupMetadata : ConfigBaseMetadata
{
public ConfigGroupMetadata(string location, string text) : base(location, text) { }
public ConfigGroupMetadata(string location, string text, string sort) : base(location, text, sort) { }
}
}
}
Expand Up @@ -32,8 +32,8 @@ public class ConfigSectionMetadata : ConfigBaseMetadata
protected string _iconSmallFilePath;
protected string _iconLargeFilePath;

public ConfigSectionMetadata(string location, string text, string iconSmall, string iconLarge)
: base(location, text)
public ConfigSectionMetadata(string location, string text, string sort, string iconSmall, string iconLarge)
: base(location, text, sort)
{
_iconSmallFilePath = iconSmall;
_iconLargeFilePath = iconLarge;
Expand All @@ -49,4 +49,4 @@ public string IconLargeFilePath
get { return _iconLargeFilePath; }
}
}
}
}
Expand Up @@ -38,8 +38,8 @@ public class ConfigSettingMetadata : ConfigBaseMetadata
protected IDictionary<string, string> _additionalData = null;
protected IDictionary<string, Type> _additionalTypes = null;

public ConfigSettingMetadata(string location, string text, string className,
string helpText, ICollection<string> listenTo) : base(location, text)
public ConfigSettingMetadata(string location, string text, string sort, string className,
string helpText, ICollection<string> listenTo) : base(location, text, sort)
{
_className = className;
_helpText = helpText;
Expand Down Expand Up @@ -79,4 +79,4 @@ public ICollection<string> ListenTo
set { _additionalTypes = value; }
}
}
}
}
Expand Up @@ -42,6 +42,11 @@ public interface IConfigurationNode
/// </summary>
string Location { get; }

/// <summary>
/// Gets a custom sort string.
/// </summary>
string Sort { get; }

/// <summary>
/// Gets the setting related to the node.
/// </summary>
Expand Down
Expand Up @@ -477,7 +477,7 @@ public void UpdateMenuActions(NavigationContext context, IDictionary<Guid, Workf
new Guid[] {context.WorkflowState.StateId}, newState, res)
{
DisplayCategory = ACTIONS_WORKFLOW_CATEGORY,
SortOrder = res.Evaluate(),
SortOrder = childNode.Sort ?? res.Evaluate(),
WorkflowNavigationContextVariables = new Dictionary<string, object>
{
{CONFIG_LOCATION_KEY, childNode.Location}
Expand Down

0 comments on commit 4e4e3a1

Please sign in to comment.