Skip to content

Commit

Permalink
Merge pull request #51 from skowront/issue39v2
Browse files Browse the repository at this point in the history
Issue #39 v2
  • Loading branch information
krzysztof-lorenc authored Jun 16, 2020
2 parents 8dced65 + f20b292 commit 610a667
Show file tree
Hide file tree
Showing 10 changed files with 792 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="TagOutline" />
<TextBlock Padding="10,0,0,0" Text="Copy latest build label" />
<TextBlock Padding="10,0,0,0" Text="Copy latest build label" IsEnabled="{Binding RenameCommand.canExecuteState}"/>
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding RenameCommand}">
<MenuItem Command="{Binding RenameCommand}" IsEnabled="{Binding RenameCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Rename" />
<TextBlock Padding="10,0,0,0" Text="Rename" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding EditCommand}">
<MenuItem Command="{Binding EditCommand}" IsEnabled="{Binding EditCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Edit" />
Expand All @@ -44,7 +44,7 @@
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding ExportCommand}">
<MenuItem Command="{Binding ExportCommand}" IsEnabled="{Binding ExportCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Export" />
Expand Down Expand Up @@ -85,7 +85,7 @@
</DataTemplate>

<DataTemplate DataType="{x:Type connectorTreeView:ConnectorViewModel}">
<DockPanel Width="Auto" ContextMenu="{DynamicResource BuildServerProjectContextMenu}" ToolTip="Yow">
<DockPanel Width="Auto" ContextMenu="{DynamicResource BuildServerProjectContextMenu}">
<buildServer:BuildInformationIconControl DataContext="{Binding CurrentStatus}" DockPanel.Dock="Left">
<buildServer:BuildInformationIconControl.ToolTip>
<StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,6 @@ private async void DeleteConnector(object sender, DeleteTreeItemEventArgs e)
if (e.DeleteItem is ConnectorViewModel model)
{
this.OnDeleteItem(this, e);
var canceled = await e.CheckCanceled();
if (!canceled && this.ConnectorViewModels.Remove(model))
{
this.OnConfigurationChanged(this, EventArgs.Empty);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Soloplan.WhatsON.GUI.Common.ConnectorTreeView
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GongSolutions.Wpf.DragDrop;
using NLog;
Expand All @@ -33,6 +35,11 @@ public class ConnectorTreeViewModel : NotifyPropertyChanged, IHandleDoubleClick,
/// </summary>
private ObservableCollection<ConnectorGroupViewModel> connectorGroups;

/// <summary>
/// Copy of currently selected connectors in case of multiple actions on viewmodel/>.
/// </summary>
private Collection<ConnectorViewModel> selectedConnectors;

/// <summary>
/// Flag indicating that <see cref="ConfigurationChanged"/> event is triggered - used to ignore updates of model.
/// </summary>
Expand All @@ -48,6 +55,11 @@ public class ConnectorTreeViewModel : NotifyPropertyChanged, IHandleDoubleClick,
/// </summary>
private bool prevOneGroupValue;

/// <summary>
/// Previous value of relative instert position.
/// </summary>
private Collection<ConnectorViewModel> connectorsToDrop = new Collection<ConnectorViewModel>();

private int fontSize;

private int fontSizeSmall;
Expand Down Expand Up @@ -185,6 +197,7 @@ public void DragOver(IDropInfo dropInfo)
/// <param name="dropInfo">Information about the drop.</param>
public void Drop(IDropInfo dropInfo)
{

if (dropInfo.Effects != DragDropEffects.Move)
{
log.Warn("Unexpected drop operation. {data}", new { Effect = dropInfo.Effects, dropInfo.Data, Target = dropInfo.TargetItem });
Expand All @@ -198,7 +211,36 @@ public void Drop(IDropInfo dropInfo)
}
else if (dropInfo.Data is ConnectorViewModel draggedConnector)
{
changesExist = this.DropConnector(dropInfo, draggedConnector);
if (this.connectorsToDrop.Count != 0)
{
if (dropInfo.InsertPosition == GongSolutions.Wpf.DragDrop.RelativeInsertPosition.BeforeTargetItem)
{
var targetGroup = this.GetConnectorGroup((ConnectorViewModel)dropInfo.TargetItem);
foreach (var element in this.connectorsToDrop.Reverse())
{
var sourceGroup = this.GetConnectorGroup(element);
MoveObject(sourceGroup, targetGroup, dropInfo.InsertPosition);
targetGroup = this.GetConnectorGroup(element);
}
}
else
{
var targetGroup = this.GetConnectorGroup((ConnectorViewModel)dropInfo.TargetItem);
foreach (var element in this.connectorsToDrop)
{
var sourceGroup = this.GetConnectorGroup(element);
MoveObject(sourceGroup, targetGroup, dropInfo.InsertPosition);
targetGroup = this.GetConnectorGroup(element);
}
}

this.connectorsToDrop = new Collection<ConnectorViewModel>();
this.OnConfigurationChanged(this, EventArgs.Empty);
}
else
{
changesExist = this.DropConnector(dropInfo, draggedConnector);
}
}

if (changesExist)
Expand Down Expand Up @@ -401,6 +443,13 @@ protected void OnConfigurationChanged(object sender, EventArgs args)
}
}

public bool UpdateConnectorsToDrop(Collection<ConnectorViewModel> list)
{
this.connectorsToDrop = list;
return true;
}


/// <summary>
/// Moves object given by <paramref name="source"/> to <paramref name="target"/>.
/// </summary>
Expand Down Expand Up @@ -556,8 +605,77 @@ private void ExportHandler(object sender, ValueEventArgs<TreeItemViewModel> e)
this.ExportItem?.Invoke(sender, e);
}

private async void DeleteGroup(object sender, DeleteTreeItemEventArgs e)
/// <summary>
/// Removes any empty rpesent groups.
/// </summary>
private void ClearEmptyGroups()
{
foreach (var group in this.connectorGroups.ToList())
{
if (group.ConnectorViewModels.Count == 0)
{
this.connectorGroups.Remove(group);
}
}
}

/// <summary>
/// Performs a deletion of all selected connectors.
/// </summary>
private void DeleteSelectedConnectors()
{
bool madeChanges = false;
foreach (var connectorGroup in this.connectorGroups.ToList())
{
foreach (var connector in connectorGroup.ConnectorViewModels.ToList())
{
for (int i = 0; i < this.selectedConnectors.Count;)
{
if (this.selectedConnectors[i].Identifier == connector.Identifier)
{
connectorGroup.ConnectorViewModels.Remove(this.selectedConnectors[i]);
this.selectedConnectors.RemoveAt(i);
madeChanges = true;
i--;
}

i++;
}
}
}

this.ClearEmptyGroups();

if (madeChanges)
{
this.OnConfigurationChanged(this, EventArgs.Empty);
this.FireOneGroupChanged();
}
}

public async void DeleteGroup(object sender, DeleteTreeItemEventArgs e)
{
if (e.DeleteItem is ConnectorViewModel clickedConnector)
{
if (this.selectedConnectors.Count > 1)
{
e.NoOtherSelections = false;
}
else
{
e.NoOtherSelections = true;
}

this.DeleteItem?.Invoke(sender, e);
var canceled = await e.CheckCanceled();
if (!canceled)
{
this.DeleteSelectedConnectors();
}

return;
}

this.DeleteItem?.Invoke(sender, e);
if (e.DeleteItem is ConnectorGroupViewModel group)
{
Expand Down Expand Up @@ -591,10 +709,18 @@ private void SetConnectionModifiedInTree(bool value)
}
}

/// <summary>
/// Updates the currently selected items form view
/// </summary>
public void UpdateSelectedConnectors(Collection<ConnectorViewModel> selectedConnectors)
{
this.selectedConnectors = selectedConnectors;
}

/// <summary>
/// Helper class with information about where the moved object is or should be in <see cref="List"/>.
/// </summary>
private class MovedObjectLocation
public class MovedObjectLocation
{
public MovedObjectLocation(IList list, int index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected virtual BuildStatusViewModel GetStatusViewModel()
protected override CustomCommand CreateEditCommand()
{
var command = base.CreateEditCommand();
command.CanExecuteExternal += (s, e) => e.Cancel = this.ConfigurationModifiedInTree;
command.CanExecuteExternal += (s, e) => { e.Cancel = this.ConfigurationModifiedInTree || !this.isOnlyOneSelected; };
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
</ResourceDictionary>
</UserControl.Resources>

<TreeView Name="mainTreeView"
<TreeView Name="mainTreeView"
HorizontalContentAlignment="Stretch"
dd:DragDrop.DropHandler="{Binding}"
dd:DragDrop.IsDragSource="True"
Expand All @@ -207,9 +207,15 @@
<TreeView.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type TreeViewItem}}" TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="OnTreeItemDoubleClick" />
<EventSetter Event="MouseLeftButtonDown" Handler="OnTreeItemLeftMouseDown"/>
<EventSetter Event="MouseLeftButtonUp" Handler="OnTreeItemLeftMouseUp"/>
<EventSetter Event="MouseRightButtonDown" Handler="OnTreeItemRightMouseDown"/>
<EventSetter Event="Drop" Handler="OnTreeViewItemDrop"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="IsExpanded" Value="{Binding IsNodeExpanded, Mode=TwoWay}" />
<Setter Property="Padding" Value="{Binding DataContext.ItemPadding, Mode=OneWay, RelativeSource={RelativeSource AncestorType=local:ConnectorsTreeView}}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Background" Value="Orange"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Expand Down
Loading

0 comments on commit 610a667

Please sign in to comment.