[mapguide-commits] r5661 - in trunk/Tools/Maestro/Maestro.Base:
Services Templates UI
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Mon Mar 28 06:29:00 EDT 2011
Author: jng
Date: 2011-03-28 03:29:00 -0700 (Mon, 28 Mar 2011)
New Revision: 5661
Modified:
trunk/Tools/Maestro/Maestro.Base/Services/NewItemTemplateService.cs
trunk/Tools/Maestro/Maestro.Base/Templates/ItemTemplate.cs
trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.Designer.cs
trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.cs
trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.resx
Log:
#1642: Change category view in New Resource Dialog to support multiple selection. The available templates view now shows all matching templates ordered by name and grouped by category.
Modified: trunk/Tools/Maestro/Maestro.Base/Services/NewItemTemplateService.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/NewItemTemplateService.cs 2011-03-24 10:47:22 UTC (rev 5660)
+++ trunk/Tools/Maestro/Maestro.Base/Services/NewItemTemplateService.cs 2011-03-28 10:29:00 UTC (rev 5661)
@@ -92,20 +92,51 @@
return values.ToArray();
}
- public ItemTemplate[] GetItemTemplates(string category, Version siteVersion)
+ public class TemplateSet
{
- if (_templates.ContainsKey(category))
+ private Dictionary<string, List<ItemTemplate>> _templates;
+
+ internal TemplateSet(IEnumerable<ItemTemplate> templates)
{
- var templates = new List<ItemTemplate>();
- foreach (var tpl in _templates[category])
+ _templates = new Dictionary<string,List<ItemTemplate>>();
+ foreach (var tpl in templates)
{
- if (siteVersion >= tpl.MinimumSiteVersion)
- templates.Add(tpl);
+ if (!_templates.ContainsKey(tpl.Category))
+ _templates[tpl.Category] = new List<ItemTemplate>();
+
+ _templates[tpl.Category].Add(tpl);
}
- return templates.ToArray();
+ foreach (var key in _templates.Keys)
+ {
+ _templates[key].Sort();
+ }
}
- return new ItemTemplate[0];
+ public IEnumerable<string> GetCategories() { return _templates.Keys; }
+
+ public IEnumerable<ItemTemplate> GetTemplatesForCategory(string category)
+ {
+ return _templates[category];
+ }
}
+
+ public TemplateSet GetItemTemplates(string[] categories, Version siteVersion)
+ {
+ List<ItemTemplate> templates = new List<ItemTemplate>();
+ foreach (var cat in categories)
+ {
+ if (_templates.ContainsKey(cat))
+ {
+ var matches = new List<ItemTemplate>();
+ foreach (var tpl in _templates[cat])
+ {
+ if (siteVersion >= tpl.MinimumSiteVersion)
+ matches.Add(tpl);
+ }
+ templates.AddRange(matches);
+ }
+ }
+ return new TemplateSet(templates.ToArray());
+ }
}
}
Modified: trunk/Tools/Maestro/Maestro.Base/Templates/ItemTemplate.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Templates/ItemTemplate.cs 2011-03-24 10:47:22 UTC (rev 5660)
+++ trunk/Tools/Maestro/Maestro.Base/Templates/ItemTemplate.cs 2011-03-28 10:29:00 UTC (rev 5661)
@@ -28,7 +28,7 @@
namespace Maestro.Base.Templates
{
- public abstract class ItemTemplate
+ public abstract class ItemTemplate : IComparable<ItemTemplate>
{
public string Name { get; set; }
@@ -57,5 +57,10 @@
/// <param name="conn">The server connection</param>
/// <returns>a new resource, null if the user cancelled during this process</returns>
public abstract IResource CreateItem(IServerConnection conn);
+
+ public int CompareTo(ItemTemplate other)
+ {
+ return this.Name.CompareTo(other.Name);
+ }
}
}
Modified: trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.Designer.cs 2011-03-24 10:47:22 UTC (rev 5660)
+++ trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.Designer.cs 2011-03-28 10:29:00 UTC (rev 5661)
@@ -54,6 +54,7 @@
resources.ApplyResources(this.lstCategories, "lstCategories");
this.lstCategories.FormattingEnabled = true;
this.lstCategories.Name = "lstCategories";
+ this.lstCategories.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.lstCategories.SelectedIndexChanged += new System.EventHandler(this.lstCategories_SelectedIndexChanged);
//
// label1
Modified: trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.cs 2011-03-24 10:47:22 UTC (rev 5660)
+++ trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.cs 2011-03-28 10:29:00 UTC (rev 5661)
@@ -33,7 +33,7 @@
{
public partial class NewResourceDialog : Form
{
- private static string _lastSelectedCategory;
+ private static List<string> _lastSelectedCategoies = new List<string>();
private NewResourceDialog()
{
@@ -56,11 +56,16 @@
{
lstCategories.DataSource = _nits.GetCategories();
- if (!string.IsNullOrEmpty(_lastSelectedCategory))
+ if (_lastSelectedCategoies.Count > 0)
{
- var idx = lstCategories.Items.IndexOf(_lastSelectedCategory);
- if (idx >= 0)
- lstCategories.SelectedIndex = idx;
+ foreach (var cat in _lastSelectedCategoies)
+ {
+ var idx = lstCategories.Items.IndexOf(cat);
+ if (idx >= 0)
+ {
+ lstCategories.SetSelected(idx, true);
+ }
+ }
}
}
@@ -69,48 +74,81 @@
this.DialogResult = DialogResult.Cancel;
}
+ private string[] GetSelectedCategories()
+ {
+ List<string> categories = new List<string>();
+ foreach (var item in lstCategories.SelectedItems)
+ {
+ categories.Add(item.ToString());
+ }
+ return categories.ToArray();
+ }
+
private void lstCategories_SelectedIndexChanged(object sender, EventArgs e)
{
- if (lstCategories.SelectedItem != null)
+ if (lstCategories.SelectedItems.Count > 0)
{
string cat = lstCategories.SelectedItem.ToString();
- LoadTemplates(_nits.GetItemTemplates(cat, _siteVersion));
+ LoadTemplates(_nits.GetItemTemplates(GetSelectedCategories(), _siteVersion));
txtDescription.Text = string.Empty;
btnOK.Enabled = false;
}
+ else
+ {
+ lstTemplates.Clear();
+ lstTemplates.Groups.Clear();
+ tplImgList.Images.Clear();
+ }
}
private ImageList tplImgList = new ImageList();
- private void LoadTemplates(ItemTemplate[] templates)
+ private void LoadTemplates(Maestro.Base.Services.NewItemTemplateService.TemplateSet templSet)
{
lstTemplates.Clear();
tplImgList.Images.Clear();
- tplImgList.Images.Add(Properties.Resources.document);
- foreach (var tpl in templates)
+ lstTemplates.Groups.Clear();
+ Dictionary<string, ListViewGroup> groups = new Dictionary<string, ListViewGroup>();
+ foreach (var cat in templSet.GetCategories())
{
- var li = new ListViewItem();
- li.Name = tpl.Name;
- li.Text = tpl.Name;
- li.ToolTipText = tpl.Description;
+ var grp = new ListViewGroup();
+ grp.Name = cat;
+ grp.Header = cat;
- if (tpl.Icon == null)
+ lstTemplates.Groups.Add(grp);
+
+ groups.Add(cat, grp);
+ }
+ foreach (var cat in templSet.GetCategories())
+ {
+ tplImgList.Images.Add(Properties.Resources.document);
+ foreach (var tpl in templSet.GetTemplatesForCategory(cat))
{
- li.ImageIndex = 0;
- }
- else
- {
- tplImgList.Images.Add(tpl.Icon);
- li.ImageIndex = tplImgList.Images.Count - 1;
- }
+ var li = new ListViewItem();
+ li.Name = tpl.Name;
+ li.Text = tpl.Name;
+ li.ToolTipText = tpl.Description;
- li.Tag = tpl;
+ if (tpl.Icon == null)
+ {
+ li.ImageIndex = 0;
+ }
+ else
+ {
+ tplImgList.Images.Add(tpl.Icon);
+ li.ImageIndex = tplImgList.Images.Count - 1;
+ }
- lstTemplates.Items.Add(li);
+ li.Tag = tpl;
+
+ li.Group = groups[cat];
+
+ lstTemplates.Items.Add(li);
+ }
+ lstTemplates.SmallImageList = tplImgList;
+ lstTemplates.LargeImageList = tplImgList;
}
- lstTemplates.SmallImageList = tplImgList;
- lstTemplates.LargeImageList = tplImgList;
}
private void lstTemplates_SelectedIndexChanged(object sender, EventArgs e)
@@ -143,7 +181,7 @@
private void btnOK_Click(object sender, EventArgs e)
{
- RememberSelectedCategory();
+ RememberSelectedCategories();
this.DialogResult = DialogResult.OK;
}
@@ -162,9 +200,13 @@
}
}
- private void RememberSelectedCategory()
+ private void RememberSelectedCategories()
{
- _lastSelectedCategory = lstCategories.SelectedItem.ToString();
+ _lastSelectedCategoies.Clear();
+ foreach (var item in lstCategories.SelectedItems)
+ {
+ _lastSelectedCategoies.Add(item.ToString());
+ }
}
private void lstTemplates_MouseDoubleClick(object sender, MouseEventArgs e)
@@ -175,7 +217,7 @@
lstTemplates.SelectedItems.Clear();
item.Selected = true;
- RememberSelectedCategory();
+ RememberSelectedCategories();
this.DialogResult = DialogResult.OK;
}
}
Modified: trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.resx 2011-03-24 10:47:22 UTC (rev 5660)
+++ trunk/Tools/Maestro/Maestro.Base/UI/NewResourceDialog.resx 2011-03-28 10:29:00 UTC (rev 5661)
@@ -178,13 +178,13 @@
<value>15, 13</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
- <value>57, 13</value>
+ <value>159, 13</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<data name="label1.Text" xml:space="preserve">
- <value>Categories</value>
+ <value>Categories (Filtered by selection)</value>
</data>
<data name=">>label1.Name" xml:space="preserve">
<value>label1</value>
More information about the mapguide-commits
mailing list