From 2bb0452a87d262d002db37748f020f103aee75fd Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 12 Aug 2015 22:03:25 +0200 Subject: [PATCH] Implement moving of elements. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NEU: Elemente können verschoben werden. --- gimp/down.xcf | Bin 0 -> 2778 bytes gimp/up.xcf | Bin 0 -> 2766 bytes zaaReloaded2/Icons/down.png | Bin 0 -> 545 bytes zaaReloaded2/Icons/up.png | Bin 0 -> 537 bytes zaaReloaded2/ViewModels/SettingsViewModel.cs | 228 ++++++++++++++++++- zaaReloaded2/Views/SettingsView.xaml | 42 ++-- zaaReloaded2/zaaReloaded2.csproj | 4 + 7 files changed, 257 insertions(+), 17 deletions(-) create mode 100644 gimp/down.xcf create mode 100644 gimp/up.xcf create mode 100644 zaaReloaded2/Icons/down.png create mode 100644 zaaReloaded2/Icons/up.png diff --git a/gimp/down.xcf b/gimp/down.xcf new file mode 100644 index 0000000000000000000000000000000000000000..2c325f8fb21ca6ed78e72515ebc21d41ba0825dd GIT binary patch literal 2778 zcmeH}PjBNy7{({fUnfnIY5@TP$>c(N@NP>NwTDunvaCdVK?13l3dv2Jtf^yHwu2Hb zd;t*JL|U$ukl2+tb4Q4UOTGa&!~ubTBfA)n_jxAvZWgjy?GcHQrt|YV<9Y4peKKy( z?w{$yc31D(jwR5ZO*?rNJ(t6u3+R>ouZ3VodkVdPUPgZ=Wv+V~>kly2d)U@!d;PxU zhPW1-tY0x*+j8_n-y8%CHq|P-Z}u#s=i42|urOCy3&N3O>9!kMeqgmj+jE2U>RPwg z_8iaG*VJJ6y%SU4xVWL(0@zHa)^Y2}f?KnB{n5Z%hryZIw%wk-ndL%ov?!RyjDc&1 zc=+};i%&iDy4}DE?>`{#{=dH7c9k+$4dLTJm`6-JinMRW>V`0>*(F^CcwJwdOe zj6rB~{K6bp=eU+K_hTOJL$0TcK{U|0uSk+aVqo>TjxBRU9{fBy<4fptgokl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*Ttwr%U-}W?4 zXjip3PI8HamIVt6>w-mvHNmn%T~Jq87OW{O3f2`C1eX=&wD|jJX*!MAWLliYzv0I- zwoKxOY!pFx#y!;PiWd~u6qgk1iYtoCimQr?iWe0Z6fY@ezaQe&IF7Wz|8IyQ=O{}u z{>wRh|3F+iPJTTQmyX4yATAw?OF`anEN=+n(y_P{#HC|#DTqtQ;!+Toj>V-QE**{vFfN60DU3^D zTngh-IHyIm5AUzsk6mm^$v#${Q_tv`!LbDA9q4jE%by@ScrPC4OKDujtWf1JretSx zHic06j7zpB!z*&mOG#rD`M1dD^WMHlKT3Yt7wJbLJ&5!pksd_)kw_0B{Yaz-k$xo7 zgGfIT=|Q9)iS!`Sk3@P9>GiGB*7P`uu5T5$;&qXJ^QR!sv~)UsOUvIq zEuO|7GyCi#oO$I7Hj1FU7QuDJ3yN!sONw>H6~$%6RmDZci;4@1mlWqF(U))BSh*4R IC$CO^2Nyx?CIA2c literal 0 HcmV?d00001 diff --git a/zaaReloaded2/Icons/down.png b/zaaReloaded2/Icons/down.png new file mode 100644 index 0000000000000000000000000000000000000000..c7faaf347c92e83d9041b903f92f11321a509c6b GIT binary patch literal 545 zcmV++0^a?JP)@xrW02FjZSad^gZEa<4bO1zQZfRv~AWL##b#u8!DU1LB0e(qDK~zY` zy_LO6#6T2`C^6NbkNHp z$({kCE-2LiDL^1mDZUTESBJn%KU54skz}vH7HEN4cfKD12f(~+s%?kJfm9ct0~f%` zot4ER?Yk|T>eNzE47}SEc0fH)Sua;rh(#p_R+2&wr~)Mg)9!&A)9Kx%5KmKWU6xJt z;*Vf3Qt9n9S;SYDTyFGSgN51GK2LlZ4BTNxCM?3f2xZ9E}QDwIJ}c?p-O2{ zB-w+b=vt~l1et?1i|&D>EwHV|8dyl_dGFHHRRVYeKL3a}?rz4OE|3G~z}3*+I;Ir^ zkNPs%TGaXoNyKAk;1qHZ`wqD$G=^9bSOY89L+LS#-1TFaEMz{wLoFIDBoX_}z$)Y- jo^q3SLSu;k?Wy<$37@la3oFAK00000NkvXXu0mjfWLnaH literal 0 HcmV?d00001 diff --git a/zaaReloaded2/Icons/up.png b/zaaReloaded2/Icons/up.png new file mode 100644 index 0000000000000000000000000000000000000000..22ff0a05ab13197225f5b08ed35ed0ba9e025c51 GIT binary patch literal 537 zcmV+!0_OdRP)uGjYW%M60wl3s+0CS;+Vr4_k>6 z8>_m5#72tfH!|(=o7Uy3sFzX ztQbk5OYn&eIAN%zTwAji#HHJD<2WQSkgx>C(W{7|w?Kt{tgrGlNg(e1DkM@NvZxy( z6(h$)s*M~Hg-&Uut(lftaR5AYZF;4xnbxi!z(t#2Ll&(xL@Gv(i3Vj>yZ|=|mwX7E z4}m>kzN>HP4mbi%QU$|Ao_vsx_2a8jg1UCl`qEQ^qC=@`gro-f0lkb 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)