Skip to content

Commit

Permalink
* gui/busdog/MainForm.cs:
Browse files Browse the repository at this point in the history
 * gui/busdog/MainForm.Designer.cs:
 * gui/busdog/MainForm.resx: Added "Copy Traces", "Copy Selected Traces"
	and "Save to File" functions
  • Loading branch information
djpnewton committed Jun 5, 2010
1 parent 10d8073 commit 144eda0
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 45 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2010-06-05 Daniel Newton <djpnewton@gmail.com>

* gui/busdog/MainForm.cs:
* gui/busdog/MainForm.Designer.cs:
* gui/busdog/MainForm.resx: Added "Copy Traces", "Copy Selected Traces"
and "Save to File" functions


2009-11-26 Daniel Newton <djpnewton@gmail.com>

* gui/busdog/MainForm.cs: Shutdown redrawing on trace list when updating
Expand Down
149 changes: 104 additions & 45 deletions gui/busdog/MainForm.Designer.cs

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

52 changes: 52 additions & 0 deletions gui/busdog/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,24 @@ private void cbMaxTraces_SelectedIndexChanged(object sender, EventArgs e)
maxTraces = Convert.ToUInt32(s);
}
}

private void btnCopyToClipboard_Click(object sender, EventArgs e)
{
lvTraces.CopyToClipboard(false);
}

private void btnCopySelectedToClipboard_Click(object sender, EventArgs e)
{
lvTraces.CopyToClipboard(true);
}

private void btnSaveToFile_Click(object sender, EventArgs e)
{
SaveFileDialog fd = new SaveFileDialog();
fd.Filter = "Text Files|.txt";
if (fd.ShowDialog() == DialogResult.OK)
System.IO.File.WriteAllText(fd.FileName, lvTraces.CopyContents(false));
}
}

public class BufferedListView : ListView
Expand All @@ -473,5 +491,39 @@ public void ResumeDrawing()
SendMessage(Handle, WM_SETREDRAW, true, 0);
Refresh();
}

public string CopyContents(bool onlySelectedRows)
{
StringBuilder buffer = new StringBuilder();

// header
for (int i = 0; i < Columns.Count; i++)
{
buffer.Append(Columns[i].Text);
buffer.Append("\t");
}
buffer.Append("\r\n");

// rows
for (int i = 0; i < Items.Count; i++)
{
if (!onlySelectedRows || Items[i].Selected)
{
for (int j = 0; j < Columns.Count; j++)
{
buffer.Append(Items[i].SubItems[j].Text);
buffer.Append("\t");
}
buffer.Append("\r\n");
}
}

return buffer.ToString();
}

public void CopyToClipboard(bool onlySelectedRows)
{
Clipboard.SetText(CopyContents(onlySelectedRows).ToString());
}
}
}
Loading

0 comments on commit 144eda0

Please sign in to comment.