Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Declare XAML GroupInto refactorings in .addin file instead of using m…
…enu builder (allows lazy loading of XamlBinding)
  • Loading branch information
dgrunwald committed Sep 28, 2010
1 parent ee5cb9d commit e030987
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 70 deletions.
Expand Up @@ -16,30 +16,15 @@

namespace ICSharpCode.XamlBinding.PowerToys.Commands
{
public class GroupIntoBorderBuilder : AbstractMenuItemBuilder
{
public override ICollection BuildItems(Codon codon, object owner)
{
List<MenuItem> items = new List<MenuItem>();

items.Add(CreateItem("Border", delegate { new GroupIntoBorderWithoutChild().Run(); }));
items.Add(CreateItem("Border With Root Grid", delegate { new GroupIntoBorderWithGrid().Run(); }));
items.Add(CreateItem("Border With Root StackPanel - Vertical", delegate { new GroupIntoBorderWithStackPanelVertical().Run(); }));
items.Add(CreateItem("Border With Root StackPanel - Horizontal", delegate { new GroupIntoBorderWithStackPanelHorizontal().Run(); }));

return items.OrderBy(item => item.Header).ToList();
}
}

class GroupIntoBorderWithoutChild : SimpleGroupIntoBase
public class GroupIntoBorderWithoutChild : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("Border", currentWpfNamespace));
}
}

class GroupIntoBorderWithGrid : GroupIntoBase
public class GroupIntoBorderWithGrid : GroupIntoBase
{
protected override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand All @@ -56,7 +41,7 @@ protected override bool GroupInto(XElement parent, IEnumerable<XElement> childre
}
}

class GroupIntoBorderWithStackPanelVertical : GroupIntoBase
public class GroupIntoBorderWithStackPanelVertical : GroupIntoBase
{
protected override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand All @@ -75,7 +60,7 @@ protected override bool GroupInto(XElement parent, IEnumerable<XElement> childre
}
}

class GroupIntoBorderWithStackPanelHorizontal : GroupIntoBase
public class GroupIntoBorderWithStackPanelHorizontal : GroupIntoBase
{
protected override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand All @@ -94,19 +79,7 @@ protected override bool GroupInto(XElement parent, IEnumerable<XElement> childre
}
}

public abstract class AbstractMenuItemBuilder : IMenuItemBuilder
{
public abstract ICollection BuildItems(Codon codon, object owner);

protected static MenuItem CreateItem(string header, Action clickAction)
{
MenuItem item = new MenuItem() { Header = header };
item.Click += new RoutedEventHandler(delegate { clickAction(); });
return item;
}
}

abstract class GroupIntoBase : XamlMenuCommand
public abstract class GroupIntoBase : XamlMenuCommand
{
protected string currentWpfNamespace;

Expand Down Expand Up @@ -140,7 +113,7 @@ protected override bool Refactor(ITextEditor editor, XDocument document)
protected abstract bool GroupInto(XElement parent, IEnumerable<XElement> children);
}

abstract class SimpleGroupIntoBase : GroupIntoBase
public abstract class SimpleGroupIntoBase : GroupIntoBase
{
protected sealed override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand All @@ -158,76 +131,55 @@ protected sealed override bool GroupInto(XElement parent, IEnumerable<XElement>
protected abstract XElement CreateParent();
}

public class GroupIntoBuilder : AbstractMenuItemBuilder
{
public override ICollection BuildItems(Codon codon, object owner)
{
List<MenuItem> items = new List<MenuItem>();

items.Add(CreateItem("Grid", delegate { new GroupIntoGrid().Run(); }));
items.Add(CreateItem("Canvas", delegate { new GroupIntoCanvas().Run(); }));
items.Add(CreateItem("DockPanel", delegate { new GroupIntoDockPanel().Run(); }));
items.Add(CreateItem("ScrollViewer With Root Grid", delegate { new GroupIntoScrollViewerWithGrid().Run(); }));
items.Add(CreateItem("StackPanel - Vertical", delegate { new GroupIntoStackPanelVertical().Run(); }));
items.Add(CreateItem("StackPanel - Horizontal", delegate { new GroupIntoStackPanelHorizontal().Run(); }));
items.Add(CreateItem("UniformGrid", delegate { new GroupIntoUniformGrid().Run(); }));
items.Add(CreateItem("Viewbox", delegate { new GroupIntoViewbox().Run(); }));
items.Add(CreateItem("WrapPanel", delegate { new GroupIntoWrapPanel().Run(); }));
items.Add(CreateItem("GroupBox With Root Grid", delegate { new GroupIntoGroupBoxWithGrid().Run(); }));

return items.OrderBy(item => item.Header).ToList();
}
}

class GroupIntoGrid : SimpleGroupIntoBase
public class GroupIntoGrid : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("Grid", currentWpfNamespace));
}
}

class GroupIntoCanvas : SimpleGroupIntoBase
public class GroupIntoCanvas : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("Canvas", currentWpfNamespace));
}
}

class GroupIntoDockPanel : SimpleGroupIntoBase
public class GroupIntoDockPanel : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("DockPanel", currentWpfNamespace));
}
}

class GroupIntoUniformGrid : SimpleGroupIntoBase
public class GroupIntoUniformGrid : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("UniformGrid", currentWpfNamespace));
}
}

class GroupIntoViewbox : SimpleGroupIntoBase
public class GroupIntoViewbox : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("Viewbox", currentWpfNamespace));
}
}

class GroupIntoWrapPanel : SimpleGroupIntoBase
public class GroupIntoWrapPanel : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
return new XElement(XName.Get("WrapPanel", currentWpfNamespace));
}
}

class GroupIntoStackPanelVertical : SimpleGroupIntoBase
public class GroupIntoStackPanelVertical : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
Expand All @@ -237,7 +189,7 @@ protected override XElement CreateParent()
}
}

class GroupIntoStackPanelHorizontal : SimpleGroupIntoBase
public class GroupIntoStackPanelHorizontal : SimpleGroupIntoBase
{
protected override XElement CreateParent()
{
Expand All @@ -247,7 +199,7 @@ protected override XElement CreateParent()
}
}

class GroupIntoScrollViewerWithGrid : GroupIntoBase
public class GroupIntoScrollViewerWithGrid : GroupIntoBase
{
protected override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand All @@ -264,7 +216,7 @@ protected override bool GroupInto(XElement parent, IEnumerable<XElement> childre
}
}

class GroupIntoGroupBoxWithGrid : GroupIntoBase
public class GroupIntoGroupBoxWithGrid : GroupIntoBase
{
protected override bool GroupInto(XElement parent, IEnumerable<XElement> children)
{
Expand Down
Expand Up @@ -76,13 +76,49 @@
label="${res:AddIns.XamlBinding.Menu.ExtractPropertiesAsStyle}" />
<MenuItem id="GroupInto" label="${res:AddIns.XamlBinding.Menu.GroupInto}" type="Menu">
<MenuItem id="GroupIntoBorder" label="Border" type="Menu">
<MenuItem id="GroupIntoBorderBuilder"
type="Builder"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBorderBuilder" />
<MenuItem id="GroupIntoBorderWithoutChild"
label="Border"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBorderWithoutChild" />
<MenuItem id="GroupIntoBorderWithGrid"
label="Border With Root Grid"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBorderWithGrid" />
<MenuItem id="GroupIntoBorderWithStackPanelVertical"
label="Border With Root StackPanel - Vertical"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBorderWithStackPanelVertical" />
<MenuItem id="GroupIntoBorderWithStackPanelHorizontal"
label="Border With Root StackPanel - Horizontal"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBorderWithStackPanelHorizontal" />
</MenuItem>
<MenuItem id="GroupIntoBuilder"
type="Builder"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoBuilder" />
<MenuItem id="GroupIntoCanvas"
label="Canvas"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoCanvas" />
<MenuItem id="GroupIntoDockPanel"
label="DockPanel"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoDockPanel" />
<MenuItem id="GroupIntoGrid"
label="Grid"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoGrid" />
<MenuItem id="GroupIntoGroupBoxWithGrid"
label="GroupBox With Root Grid"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoGroupBoxWithGrid" />
<MenuItem id="GroupIntoScrollViewerWithGrid"
label="ScrollViewer With Root Grid"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoScrollViewerWithGrid" />
<MenuItem id="GroupIntoStackPanelHorizontal"
label="StackPanel - Horizontal"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoStackPanelHorizontal" />
<MenuItem id="GroupIntoStackPanelVertical"
label="StackPanel - Vertical"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoStackPanelVertical" />
<MenuItem id="GroupIntoUniformGrid"
label="UniformGrid"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoUniformGrid" />
<MenuItem id="GroupIntoViewbox"
label="Viewbox"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoViewbox" />
<MenuItem id="GroupIntoWrapPanel"
label="WrapPanel"
class="ICSharpCode.XamlBinding.PowerToys.Commands.GroupIntoWrapPanel" />
</MenuItem>
<MenuItem id="EditGridColumnsAndRows"
class="ICSharpCode.XamlBinding.PowerToys.Commands.EditGridColumnsAndRowsCommand"
Expand Down

0 comments on commit e030987

Please sign in to comment.