Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
twostarsmco committed Apr 9, 2020
2 parents 5e4a119 + 2930a24 commit ea743c4
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 66 deletions.
87 changes: 49 additions & 38 deletions NSAutomationWin/MacroDesigner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 89 additions & 17 deletions NSAutomationWin/MacroDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,59 +66,129 @@ private void AddButton_Click(object sender, EventArgs e)

private void InsertButton_Click(object sender, EventArgs e)
{
var c = CommandEditDialog.CreateNewCommandFromDialog();
if (c != null) this.Commands.Insert(CommandsDataGridView.CurrentCell.RowIndex, new CommandWrapper(c));
if (this.Commands.Count<1)
{
this.AddButton_Click(sender, e);
}
else
{
var c = CommandEditDialog.CreateNewCommandFromDialog();
if (c != null) this.Commands.Insert(CommandsDataGridView.CurrentCell.RowIndex, new CommandWrapper(c));
}
}

private void EditButton_Click(object sender, EventArgs e)
{
var current = this.Commands[CommandsDataGridView.CurrentCell.RowIndex].Command;
var cNew = CommandEditDialog.CreateNewCommandFromDialog(current);
if (cNew != null) this.Commands[CommandsDataGridView.CurrentCell.RowIndex] = new CommandWrapper(cNew);
if (this.Commands.Count > 0)
{
var current = this.Commands[CommandsDataGridView.CurrentCell.RowIndex].Command;
var cNew = CommandEditDialog.CreateNewCommandFromDialog(current);
if (cNew != null) this.Commands[CommandsDataGridView.CurrentCell.RowIndex] = new CommandWrapper(cNew);
}
}

private void CutButton_Click(object sender, EventArgs e)
{
this.Copy();
this.DeleteSelectedRows();
}

private void CopyButton_Click(object sender, EventArgs e)
{
this.Copy();
}

private void PasteButton_Click(object sender, EventArgs e)
{
this.Paste(Clipboard.GetText());
}

private void DeleteButton_Click(object sender, EventArgs e)
{
SortedSet<int> targetRows = new SortedSet<int>();
foreach (DataGridViewCell item in CommandsDataGridView.SelectedCells) targetRows.Add(item.RowIndex);
this.DeleteSelectedRows();
}

foreach (int i in targetRows.Reverse())
private void DeleteAllButton_Click(object sender, EventArgs e)
{
this.CommandsDataGridView.SelectAll();
this.DeleteSelectedRows();
}

private void CommandsDataGridView_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.X)
{
if (i < Commands.Count)
Commands.RemoveAt(i);
this.CutButton_Click(sender, e);
} //Copy is handled naturally by DataGridView
else if (e.Control && e.KeyCode == Keys.V)
{
this.Paste(Clipboard.GetText());
}
else if (e.Control && e.KeyCode == Keys.A)
{
this.CommandsDataGridView.SelectAll();
}
else if (e.Control && e.KeyCode == Keys.I)
{
this.InsertButton_Click(sender, e);
}
else if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
{
this.DeleteSelectedRows();
}
}

private SortedSet<int> GetSelectedRows()
{
SortedSet<int> selectedRows = new SortedSet<int>();
foreach (DataGridViewCell item in CommandsDataGridView.SelectedCells) selectedRows.Add(item.RowIndex);
return selectedRows;
}


private void CommandsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
var current = this.Commands[e.RowIndex].Command;
var cNew = CommandEditDialog.CreateNewCommandFromDialog(current);
if (cNew != null) this.Commands[e.RowIndex] = new CommandWrapper(cNew);
}

private void PasteButton_Click(object sender, EventArgs e)
private void DeleteSelectedRows()
{
this.Paste(Clipboard.GetText());
var targetRows = this.GetSelectedRows();

foreach (int i in targetRows.Reverse())
{
if (i < Commands.Count)
Commands.RemoveAt(i);
}
}

private void CommandsDataGridView_KeyDown(object sender, KeyEventArgs e)
private void Copy()
{
if (e.Control && e.KeyCode == Keys.V)
var targetRows = this.GetSelectedRows();
var commandsString = string.Join("\r\n", targetRows.Select(i => this.Commands[i].ToString()));
if (!string.IsNullOrEmpty(commandsString))
{
this.Paste(Clipboard.GetText());
Clipboard.SetText(commandsString);
}
}

private void Paste(string s)
{
if (string.IsNullOrEmpty(s)) return;
int currentRow = CommandsDataGridView.CurrentCell.RowIndex;

int currentRow =
CommandsDataGridView.CurrentCell is null ? 0 :
CommandsDataGridView.CurrentCell.RowIndex;
string[] s_rows = s.Replace("\r\n", "\n").Split(new[] { '\n', '\r' });

foreach (var commandString in s_rows)
{
try
{
var cw = new CommandWrapper(commandString);
this.Commands.Insert(CommandsDataGridView.CurrentCell.RowIndex, cw);
this.Commands.Insert(currentRow, cw);
this.CommandsDataGridView.OffsetSelectedRange(1, 0);
}
catch (ArgumentException)
Expand All @@ -128,6 +198,8 @@ private void Paste(string s)
}
}
#endregion


}

}
1 change: 1 addition & 0 deletions NSAutomationWin/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea743c4

Please sign in to comment.