Skip to content

Commit

Permalink
Fixup cut/copy/paste (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Apr 6, 2023
1 parent 6ae4ada commit 85930b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/SerialLoops/Controls/ScriptCommandListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void InitializeComponent()
_commands[entry.Command.Section][i].Index++;
}
}
((ScriptEditor)_editor).PopulateScriptCommands(true);
_editor.UpdateTabTitle(false);
};
Viewer.DeleteCommand += (o, e) =>
Expand Down Expand Up @@ -112,20 +113,22 @@ void InitializeComponent()
entry.Command.Section.Objects.Remove(command);
_commands[entry.Command.Section].Remove(entry.Command);
}
((ScriptEditor)_editor).PopulateScriptCommands(true);
_editor.UpdateTabTitle(false);
};
Viewer.AddCommand += (o, e) =>
{
var treeGridView = (ScriptCommandSectionTreeGridView)o;
var entry = (ScriptCommandSectionEntry)treeGridView.SelectedItem;
ScriptSection section = entry.Command.Section ?? e.Command.Section;

if (string.IsNullOrEmpty(e.SectionTitle))
{
e.Command.Script.ScriptSections[e.Command.Script.ScriptSections.IndexOf(e.Command.Section)].Objects.Insert(e.Command.Index, e.Command.Invocation);
_commands[e.Command.Section].Insert(e.Command.Index, e.Command);
for (int i = e.Command.Section.Objects.IndexOf(e.Command.Invocation) + 1; i < e.Command.Section.Objects.Count; i++)
e.Command.Script.ScriptSections[e.Command.Script.ScriptSections.IndexOf(section)].Objects.Insert(e.Command.Index, e.Command.Invocation);
_commands[section].Insert(e.Command.Index, e.Command);
for (int i = section.Objects.IndexOf(e.Command.Invocation) + 1; i < section.Objects.Count; i++)
{
_commands[e.Command.Section][i].Index++;
_commands[section][i].Index++;
}
}
else
Expand All @@ -149,6 +152,7 @@ void InitializeComponent()
_commands.Add(scriptFile.ScriptSections.Last(), new());
}

((ScriptEditor)_editor).PopulateScriptCommands(true);
_editor.UpdateTabTitle(false);
};
}
Expand Down
20 changes: 8 additions & 12 deletions src/SerialLoops/Editors/ScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public override Container GetEditorPanel()
return GetCommandsContainer();
}

private void PopulateScriptCommands()
public void PopulateScriptCommands(bool refresh = false)
{
if (refresh)
{
_script.Refresh(_project);
}
_commands = _script.GetScriptCommandTree(_project);
}

Expand Down Expand Up @@ -267,9 +271,6 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
);

treeGridView.AddItem(new(new(command), scriptSection, command, false));
// Regenerate the command tree
_script.Refresh(_project);
PopulateScriptCommands();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -328,8 +329,7 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
dialog.Close();
ScriptCommandSectionEntry section = new($"NONE{labelBox.Text}", new List<ScriptCommandSectionEntry>(), _script.Event);
treeGridView.AddSection(new(section, null, null, true));
_script.Refresh(_project); // Have to recreate the command graph
PopulateScriptCommands();

_updateOptionDropDowns();
};

Expand All @@ -348,8 +348,6 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
if (treeGridView.SelectedCommandTreeItem is not null)
{
treeGridView.DeleteItem(treeGridView.SelectedCommandTreeItem);
_script.Refresh(_project); // Have to recreate the command graph
PopulateScriptCommands();
_updateOptionDropDowns();
}
};
Expand Down Expand Up @@ -2152,8 +2150,7 @@ private void OptionDropDown_SelectedKeyChanged(object sender, EventArgs e)
_script.Event.ScriptSections[_script.Event.ScriptSections.IndexOf(dropDown.Command.Section)]
.Objects[dropDown.Command.Index].Parameters[dropDown.ParameterIndex] = (short)_script.Event.ChoicesSection.Objects.IndexOf(choice);
UpdateTabTitle(false, dropDown);
_script.Refresh(_project);
PopulateScriptCommands();
PopulateScriptCommands(true);
}
private void PaletteEffectDropDown_SelectedKeyChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -2209,8 +2206,7 @@ private void ScriptSectionDropDown_SelectedKeyChanged(object sender, EventArgs e
_script.Event.ScriptSections[_script.Event.ScriptSections.IndexOf(dropDown.Command.Section)]
.Objects[dropDown.Command.Index].Parameters[dropDown.CurrentShort] =
_script.Event.LabelsSection.Objects.First(l => l.Name.Replace("/", "") == dropDown.SelectedKey).Id;
_script.Refresh(_project); // Update command graph
PopulateScriptCommands();
PopulateScriptCommands(true);
UpdateTabTitle(false, dropDown);
}
private void SfxNumericStepper_ValueChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 85930b4

Please sign in to comment.