diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index 0bf159a3fb..57efda84ec 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -489,4 +489,19 @@ + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs index acde94bb1b..94e6e8659a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs @@ -6,6 +6,7 @@ // using System; +using System.ComponentModel; using System.Diagnostics; using System.Collections.Generic; using System.Linq; @@ -88,6 +89,11 @@ namespace ICSharpCode.WpfDesign.Designer.Controls /// Decides whether to permanently display the handle or not. /// public bool ShouldBeVisible { get; set; } + + /// + /// Decides whether stub has to be only displayed. + /// + public bool DisplayOnlyStub { get; set; } public MarginHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation) { @@ -148,16 +154,22 @@ namespace ICSharpCode.WpfDesign.Designer.Controls /// /// public void DecideVisiblity(double handleLength) - { - if(ShouldBeVisible){ - marginStub.Visibility = handleLength == 0.0 ? Visibility.Visible : Visibility.Hidden; - this.Visibility = handleLength != 0.0 ? Visibility.Visible : Visibility.Hidden; - if (this.lineArrow != null){ - lineArrow.Visibility = handleLength < 23 ? Visibility.Hidden : Visibility.Visible; - } + { + if(!DisplayOnlyStub){ + if(ShouldBeVisible){ + marginStub.Visibility = handleLength == 0.0 ? Visibility.Visible : Visibility.Hidden; + this.Visibility = handleLength != 0.0 ? Visibility.Visible : Visibility.Hidden; + if (this.lineArrow != null){ + lineArrow.Visibility = handleLength < 23 ? Visibility.Hidden : Visibility.Visible; + } + } } - } - + else { + DisplayOnlyStub=false; + DecideVisiblity(this.HandleLength); + } + } + public override void OnApplyTemplate() { base.OnApplyTemplate(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs new file mode 100644 index 0000000000..91aca1d11e --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs @@ -0,0 +1,133 @@ +// +// +// +// +// $Revision: $ +// +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace ICSharpCode.WpfDesign.Designer.Controls +{ + /// + /// A Small icon which shows up a menu containing common properties + /// + public class QuickOperationMenu : Control + { + static QuickOperationMenu() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof (QuickOperationMenu), new FrameworkPropertyMetadata(typeof (QuickOperationMenu))); + } + + private MenuItem _mainHeader; + + /// + /// Contains Default values in the Sub menu for example "HorizontalAlignment" has "HorizontalAlignment.Stretch" as it's value. + /// + private readonly Dictionary _defaults = new Dictionary(); + + /// + /// Is the main header menu which brings up all the menus. + /// + public MenuItem MainHeader { + get { return _mainHeader; } + } + + /// + /// Add a submenu with checkable values. + /// + /// The parent menu under which to add. + /// All the values of an enum to be showed in the menu + /// The default value out of all the enums. + /// The presently set value out of the enums + public void AddSubMenuCheckable(MenuItem parent, Array enumValues, string defaultValue, string setValue) + { + foreach (var enumValue in enumValues) { + var menuItem = new MenuItem {Header = enumValue.ToString(), IsCheckable = true}; + parent.Items.Add(menuItem); + if (enumValue.ToString() == defaultValue) + _defaults.Add(parent, menuItem); + if (enumValue.ToString() == setValue) + menuItem.IsChecked = true; + } + } + + /// + /// Add a menu in the main header. + /// + /// The menu to add. + public void AddSubMenuInTheHeader(MenuItem menuItem) + { + if (_mainHeader != null) + _mainHeader.Items.Add(menuItem); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + var mainHeader = Template.FindName("MainHeader", this) as MenuItem; + if (mainHeader != null) { + _mainHeader = mainHeader; + _mainHeader.MouseLeave += OnMouseOut; + } + } + + /// + /// Checks a menu item and making it exclusive. If the check was toggled then the default menu item is selected. + /// + /// The parent item of the sub menu + /// The Item clicked on + /// Returns the Default value if the checkable menu item is toggled or otherwise the new checked menu item. + public string UncheckChildrenAndSelectClicked(MenuItem parent, MenuItem clickedOn) + { + MenuItem defaultMenuItem; + _defaults.TryGetValue(parent, out defaultMenuItem); + if (IsAnyItemChecked(parent)) { + foreach (var item in parent.Items) { + var menuItem = item as MenuItem; + if (menuItem != null) menuItem.IsChecked = false; + } + clickedOn.IsChecked = true; + return (string) clickedOn.Header; + } else { + if (defaultMenuItem != null) { + defaultMenuItem.IsChecked = true; + return (string) defaultMenuItem.Header; + } + } + return null; + } + + /// + /// Checks in the sub-menu whether aby items has been checked or not + /// + /// + /// + private bool IsAnyItemChecked(MenuItem parent) + { + bool check = false; + if (parent.HasItems) { + foreach (var item in parent.Items) { + var menuItem = item as MenuItem; + if (menuItem != null && menuItem.IsChecked) + check = true; + } + } + return check; + } + + protected override void OnMouseEnter(MouseEventArgs e) + { + base.OnMouseEnter(e); + MainHeader.IsSubmenuOpen = true; + } + + private void OnMouseOut(object sender, MouseEventArgs e) + { + MainHeader.IsSubmenuOpen = false; + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs index f7167b9831..eba1ea6999 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs @@ -47,6 +47,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public void HideHandles() { + if (_leftHandle != null && _topHandle != null && _rightHandle != null && _bottomHandle != null) { _leftHandle.Visibility=Visibility.Hidden; _leftHandle.ShouldBeVisible=false; _topHandle.Visibility=Visibility.Hidden; @@ -55,11 +56,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _rightHandle.ShouldBeVisible=false; _bottomHandle.Visibility=Visibility.Hidden; _bottomHandle.ShouldBeVisible=false; - + } } public void ShowHandles() { + if (_leftHandle != null && _topHandle != null && _rightHandle != null && _bottomHandle != null){ _leftHandle.Visibility=Visibility.Visible; _leftHandle.ShouldBeVisible=true; _leftHandle.DecideVisiblity(_leftHandle.HandleLength); @@ -72,6 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _bottomHandle.Visibility=Visibility.Visible; _bottomHandle.ShouldBeVisible=true; _bottomHandle.DecideVisiblity(_bottomHandle.HandleLength); + } } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs new file mode 100644 index 0000000000..8479e12d24 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs @@ -0,0 +1,111 @@ +// +// +// +// +// $Revision: $ +// +using System; +using System.Windows; +using System.Windows.Controls; + +using ICSharpCode.WpfDesign.Designer.Controls; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Adorners; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + /// + /// Extends the Quick operation menu for the designer. + /// + [ExtensionFor(typeof (FrameworkElement))] + class QuickOperationMenuExtension : PrimarySelectionAdornerProvider + { + private QuickOperationMenu _menu; + + protected override void OnInitialized() + { + base.OnInitialized(); + _menu = new QuickOperationMenu(); + _menu.Loaded += OnMenuLoaded; + var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7}; + this.AddAdorners(placement, _menu); + } + + private void OnMenuLoaded(object sender, EventArgs e) + { + _menu.MainHeader.Click += MainHeaderClick; + int menuItemsAdded = 0; + var view = this.ExtendedItem.View; + + if (view != null) { + string setValue; + if (view is StackPanel) { + var ch = new MenuItem() {Header = "Change Orientation"}; + _menu.AddSubMenuInTheHeader(ch); + setValue = this.ExtendedItem.Properties[StackPanel.OrientationProperty].ValueOnInstance.ToString(); + _menu.AddSubMenuCheckable(ch, Enum.GetValues(typeof (Orientation)), Orientation.Vertical.ToString(), setValue); + _menu.MainHeader.Items.Add(new Separator()); + menuItemsAdded++; + } + + var ha = new MenuItem() {Header = "Horizontal Alignment"}; + _menu.AddSubMenuInTheHeader(ha); + setValue = this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance.ToString(); + _menu.AddSubMenuCheckable(ha, Enum.GetValues(typeof (HorizontalAlignment)), HorizontalAlignment.Stretch.ToString(), setValue); + menuItemsAdded++; + + var va = new MenuItem() {Header = "Vertical Alignment"}; + _menu.AddSubMenuInTheHeader(va); + setValue = this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance.ToString(); + _menu.AddSubMenuCheckable(va, Enum.GetValues(typeof (VerticalAlignment)), VerticalAlignment.Stretch.ToString(), setValue); + menuItemsAdded++; + } + + if (menuItemsAdded == 0) { + OnRemove(); + } + } + + private void MainHeaderClick(object sender, RoutedEventArgs e) + { + var clickedOn = e.Source as MenuItem; + if (clickedOn != null) { + var parent = clickedOn.Parent as MenuItem; + if (parent != null) { + if ((string) parent.Header == "Change Orientation") { + var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn); + if (value != null) { + var orientation = Enum.Parse(typeof (Orientation), value); + if (orientation != null) + this.ExtendedItem.Properties[StackPanel.OrientationProperty].SetValue(orientation); + } + } + + if ((string) parent.Header == "Horizontal Alignment") { + var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn); + if (value != null) { + var ha = Enum.Parse(typeof (HorizontalAlignment), value); + if (ha != null) + this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(ha); + } + } + + if ((string) parent.Header == "Vertical Alignment") { + var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn); + if (value != null) { + var va = Enum.Parse(typeof (VerticalAlignment), value); + if (va != null) + this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(va); + } + } + } + } + } + + protected override void OnRemove() + { + base.OnRemove(); + _menu.Loaded -= OnMenuLoaded; + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 5ac8276a68..b82cacdbe4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -95,6 +95,7 @@ + @@ -123,6 +124,7 @@ + Code