Skip to content

Commit fac26d2

Browse files
committed
fix for select
1 parent 4f79078 commit fac26d2

3 files changed

Lines changed: 24 additions & 22 deletions

File tree

SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ private void Select(SelectMode selectMode)
130130
if(!this.Selected)
131131
{
132132
this.Node.CommandUnSelectedAllConnectors.Execute();
133-
this.Selected = true;
133+
this.Node.CommandSetConnectorAsStartSelect.Execute(this);
134+
this.Selected = true;
135+
134136
}
135137

136138
break;

SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class ViewModelNode : ReactiveValidationObject<ViewModelNode>
5050

5151
public int Zindex { get; private set; }
5252

53+
[Reactive] public int IndexStartSelectConnectors { get; set; } = 0;
5354
public IObservableCollection<ViewModelConnector> Transitions { get; set; } = new ObservableCollectionExtended<ViewModelConnector>();
5455

5556

@@ -98,6 +99,7 @@ private void SetupConnectors()
9899
public SimpleCommandWithParameter<string> CommandValidateName { get; set; }
99100

100101
public SimpleCommandWithParameter<ViewModelConnector> CommandSelectWithShiftForConnectors { get; set; }
102+
public SimpleCommandWithParameter<ViewModelConnector> CommandSetConnectorAsStartSelect { get; set; }
101103
public SimpleCommand CommandUnSelectedAllConnectors { get; set; }
102104
public SimpleCommand CommandAddEmptyConnector { get; set; }
103105

@@ -119,6 +121,7 @@ private void SetupCommands()
119121
CommandAddEmptyConnector = new SimpleCommand(AddEmptyConnector);
120122
CommandCollapse = new SimpleCommandWithParameter<bool>(Collapse, NotSaved);
121123
CommandSelectWithShiftForConnectors = new SimpleCommandWithParameter<ViewModelConnector>(SelectWithShiftForConnectors);
124+
CommandSetConnectorAsStartSelect = new SimpleCommandWithParameter<ViewModelConnector>(SetConnectorAsStartSelect);
122125
CommandUnSelectedAllConnectors = new SimpleCommand(UnSelectedAllConnectors);
123126
//CommandTransitionsDragLeave = new SimpleCommand(TransitionsDragLeave);
124127
//CommandTransitionsDragEnter = new SimpleCommand(TransitionsDragEnter);
@@ -132,6 +135,7 @@ private void SetupCommands()
132135

133136

134137
}
138+
135139
private void NotSaved()
136140
{
137141
NodesCanvas.ItSaved = false;
@@ -206,34 +210,27 @@ private void UnSelectedAllConnectors()
206210
{
207211
transition.Selected = false;
208212
}
213+
214+
IndexStartSelectConnectors = 0;
215+
}
216+
private void SetConnectorAsStartSelect(ViewModelConnector viewModelConnector)
217+
{
218+
IndexStartSelectConnectors = Transitions.IndexOf(viewModelConnector) - 1;
209219
}
210220
private void SelectWithShiftForConnectors(ViewModelConnector viewModelConnector)
211221
{
212222
if (viewModelConnector == null)
213223
return;
214224

215225
var transitions = this.Transitions.Skip(1);
216-
217-
int index = transitions.IndexOf(viewModelConnector);
218-
219-
if ((!transitions.First().Selected) &&(transitions.Last().Selected))
226+
int indexCurrent = transitions.IndexOf(viewModelConnector);
227+
int indexStart = IndexStartSelectConnectors;
228+
UnSelectedAllConnectors();
229+
IndexStartSelectConnectors = indexStart;
230+
transitions = transitions.Skip(Math.Min(indexCurrent, indexStart)).SkipLast(Transitions.Count() - Math.Max(indexCurrent, indexStart) - 2);
231+
foreach (var transition in transitions)
220232
{
221-
UnSelectedAllConnectors();
222-
foreach (var transition in transitions.TakeLast(transitions.Count() - index))
223-
{
224-
transition.Selected = true;
225-
}
226-
return;
227-
}
228-
else
229-
{
230-
UnSelectedAllConnectors();
231-
//var t = transitions.Take(index);
232-
foreach (var transition in transitions.Take(index + 1))
233-
{
234-
transition.Selected = true;
235-
}
236-
return;
233+
transition.Selected = true;
237234
}
238235
}
239236
public XElement ToXElement()

SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ private void SelectedAll()
208208
private void UnSelectedAll()
209209
{
210210
foreach (var node in Nodes)
211-
{ node.Selected = false; }
211+
{
212+
node.Selected = false;
213+
node.CommandUnSelectedAllConnectors.Execute();
214+
}
212215
}
213216
private List<ViewModelNode> FullMoveAllNode(MyPoint delta, List<ViewModelNode> nodes = null)
214217
{

0 commit comments

Comments
 (0)