diff --git a/gimp/down.xcf b/gimp/down.xcf new file mode 100644 index 0000000..2c325f8 Binary files /dev/null and b/gimp/down.xcf differ diff --git a/gimp/up.xcf b/gimp/up.xcf new file mode 100644 index 0000000..cd242b6 Binary files /dev/null and b/gimp/up.xcf differ diff --git a/zaaReloaded2/Icons/down.png b/zaaReloaded2/Icons/down.png new file mode 100644 index 0000000..c7faaf3 Binary files /dev/null and b/zaaReloaded2/Icons/down.png differ diff --git a/zaaReloaded2/Icons/up.png b/zaaReloaded2/Icons/up.png new file mode 100644 index 0000000..22ff0a0 Binary files /dev/null and b/zaaReloaded2/Icons/up.png differ diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index fdf149b..2ead6db 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -280,6 +280,34 @@ namespace zaaReloaded2.ViewModels } } + public DelegatingCommand MoveElementUpCommand + { + get + { + if (_moveElementUpCommand == null) + { + _moveElementUpCommand = new DelegatingCommand( + param => DoMoveElementUp(), + param => CanMoveElementUp()); + } + return _moveElementUpCommand; + } + } + + public DelegatingCommand MoveElementDownCommand + { + get + { + if (_moveElementDownCommand == null) + { + _moveElementDownCommand = new DelegatingCommand( + param => DoMoveElementDown(), + param => CanMoveElementDown()); + } + return _moveElementDownCommand; + } + } + #endregion #region Public methods @@ -436,6 +464,201 @@ namespace zaaReloaded2.ViewModels bool CanCopyElement() { return LastSelectedElement != null && LastSelectedElement.IsSelected; } + void DoMoveElementUp() + { + if (CanMoveElementUp()) + { + // We need to get a hold of the LastSelectedElement because a TreeView + // might reset the selection when we move elements around. + ElementViewModel lastSelectedElement = LastSelectedElement; + // Top-level elements are either control elements or format elements; + // child elements on the second level however are always format elements + // and must be treated differently. + if (IsTopLevelElement()) + { + int index = Elements.IndexOf(lastSelectedElement); + if (lastSelectedElement is ControlElementViewModel || + Elements[index - 1] is FormatElementViewModel || + !((ControlElementViewModel)Elements[index - 1]).CanHaveChildren + ) + { + // Simple case: top-level control element -- just move it up; + // if the selected element is a format element and the element + // above it is a format element too, just move it up as well. + // If the element above the selected element is a control element, + // but cannot have children, move the selected element up as well. + Elements.RemoveAt(index); + Elements.Insert(index - 1, lastSelectedElement); + _settings.Elements.RemoveAt(index); + _settings.Elements.Insert( + index - 1, + LastSelectedElement.RevealModelObject() as ElementBase); + } + else + { + // If we get here, the selected element is a format element + // and the element above it is a control element that can + // have child elements, i.e. the selected element is demoted + // to a child element of the control element above it. + ControlElementViewModel controlElementAbove = + Elements[index - 1] as ControlElementViewModel; + Elements.RemoveAt(index); + controlElementAbove.AddChildElement( + lastSelectedElement as FormatElementViewModel); + FormatElementBase model = lastSelectedElement.RevealModelObject() as FormatElementBase; + ControlElementBase modelAbove = _settings.Elements[index - 1] as ControlElementBase; + _settings.Elements.RemoveAt(index); + modelAbove.Children.Add(model); + } + } + else + { + // The selected element is a child element. + // If it is at the top of the child elements list, promote it + // to a top-level element; if not, just move it up in the + // child elements list. + FormatElementViewModel selected = lastSelectedElement as FormatElementViewModel; + int index = selected.Parent.Elements.IndexOf(selected); + if (index == 0) + { + // Promote the element from the top of the children list + // to a top-level element above its parent. + int parentIndex = Elements.IndexOf(selected.Parent); + selected.Parent.Elements.RemoveAt(0); + Elements.Insert(parentIndex, selected); + FormatElementBase model = selected.RevealModelObject() as FormatElementBase; + ControlElementBase parentModel = selected.Parent.RevealModelObject() as ControlElementBase; + parentModel.Children.RemoveAt(0); + _settings.Elements.Insert(parentIndex, model); + selected.Parent = null; + } + else + { + selected.Parent.Elements.Move(index, index - 1); + ControlElementBase parentModel = selected.Parent.RevealModelObject() as ControlElementBase; + FormatElementBase selectedModel = parentModel.Children[index]; + parentModel.Children.RemoveAt(index); + parentModel.Children.Insert(index - 1, selectedModel); + } + } + // Select the last selected element again. + lastSelectedElement.IsSelected = true; + } + } + + bool CanMoveElementUp() + { + if (IsTopLevelElement()) + { + return Elements.IndexOf(LastSelectedElement) > 0; + } + else + { + // If the selected element is a child element, it can always be moved + // up before the parent element. + return LastSelectedElement != null && LastSelectedElement.IsSelected; + } + } + + void DoMoveElementDown() + { + if (CanMoveElementDown()) + { + // We need to get a hold of the LastSelectedElement because a TreeView + // might reset the selection when we move elements around. + ElementViewModel lastSelectedElement = LastSelectedElement; + // Top-level elements are either control elements or format elements; + // child elements on the second level however are always format elements + // and must be treated differently. + if (IsTopLevelElement()) + { + int index = Elements.IndexOf(lastSelectedElement); + if (lastSelectedElement is ControlElementViewModel || + Elements[index + 1 ] is FormatElementViewModel || + !((ControlElementViewModel)Elements[index + 1]).CanHaveChildren + ) + { + // Simple case: top-level control element -- just move it down; + // if the selected element is a format element and the element + // below it is a format element too, just move it down as well. + // If the element below the selected element is a control element, + // but cannot have children, move the selected element down as well. + Elements.RemoveAt(index); + Elements.Insert(index + 1, lastSelectedElement); + _settings.Elements.RemoveAt(index); + _settings.Elements.Insert( + index + 1, + LastSelectedElement.RevealModelObject() as ElementBase); + } + else + { + // If we get here, the selected element is a format element + // and the element below it is a control element that can + // have child elements, i.e. the selected element is demoted + // to a child element of the control element below it. + ControlElementViewModel controlElementBelow = + Elements[index + 1] as ControlElementViewModel; + Elements.RemoveAt(index); + controlElementBelow.Elements.Insert( + 0, + lastSelectedElement as FormatElementViewModel); + ((FormatElementViewModel)lastSelectedElement).Parent = controlElementBelow; + FormatElementBase model = lastSelectedElement.RevealModelObject() as FormatElementBase; + ControlElementBase modelBelow = _settings.Elements[index + 1] as ControlElementBase; + _settings.Elements.RemoveAt(index); + modelBelow.Children.Insert(0, model); + } + } + else + { + // The selected element is a child element. + // If it is at the bottom of the child elements list, promote it + // to a top-level element; if not, just move it down in the + // child elements list. + FormatElementViewModel selected = lastSelectedElement as FormatElementViewModel; + int index = selected.Parent.Elements.IndexOf(selected); + if (index == selected.Parent.Elements.Count - 1) + { + // Promote the element from the bottom of the children list + // to a top-level element below its parent. + int parentIndex = Elements.IndexOf(selected.Parent); + selected.Parent.Elements.RemoveAt(selected.Parent.Elements.Count - 1); + Elements.Insert(parentIndex + 1, selected); + FormatElementBase model = selected.RevealModelObject() as FormatElementBase; + ControlElementBase parentModel = selected.Parent.RevealModelObject() as ControlElementBase; + parentModel.Children.RemoveAt(parentModel.Children.Count - 1); + _settings.Elements.Insert(parentIndex + 1, model); + selected.Parent = null; + } + else + { + selected.Parent.Elements.Move(index, index + 1); + ControlElementBase parentModel = selected.Parent.RevealModelObject() as ControlElementBase; + FormatElementBase selectedModel = parentModel.Children[index]; + parentModel.Children.RemoveAt(index); + parentModel.Children.Insert(index + 1, selectedModel); + } + } + // Select the last selected element again. + lastSelectedElement.IsSelected = true; + } + + } + + bool CanMoveElementDown() + { + if (IsTopLevelElement()) + { + return Elements.IndexOf(LastSelectedElement) < Elements.Count - 1; + } + else + { + // If the selected element is a child element, it can always be moved + // down after the parent element. + return LastSelectedElement != null && LastSelectedElement.IsSelected; + } + } + /// /// Sets LastSelectedElement property whenever the IsSelected /// property of an ElementViewModel changes @@ -458,7 +681,8 @@ namespace zaaReloaded2.ViewModels /// bool IsTopLevelElement() { - return (LastSelectedElement is ControlElementViewModel || + return LastSelectedElement != null && + (LastSelectedElement is ControlElementViewModel || ((FormatElementViewModel)LastSelectedElement).Parent == null); } @@ -490,6 +714,8 @@ namespace zaaReloaded2.ViewModels DelegatingCommand _editElementCommand; DelegatingCommand _deleteElementCommand; DelegatingCommand _copyElementCommand; + DelegatingCommand _moveElementUpCommand; + DelegatingCommand _moveElementDownCommand; Message _addElementMessage; Message _addChildElementMessage; Message _editElementMessage; diff --git a/zaaReloaded2/Views/SettingsView.xaml b/zaaReloaded2/Views/SettingsView.xaml index 1a706c8..7870078 100755 --- a/zaaReloaded2/Views/SettingsView.xaml +++ b/zaaReloaded2/Views/SettingsView.xaml @@ -23,7 +23,8 @@ xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:action="clr-namespace:Bovender.Mvvm.Actions;assembly=Bovender" - Width="500" Height="440" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False" + Width="460" Height="400" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False" + MinWidth="460" MinHeight="400" WindowStyle="ToolWindow" Topmost="True" b:WindowState.CenterScreen="True" b:WindowState.Save="True" Title="Stil bearbeiten" @@ -66,21 +67,30 @@ - - - - - + + + + + + + + + + diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 853000a..56cf87f 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -401,6 +401,10 @@ + + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)