LogWindow: replace textbox with a virtuallistview. while it may leave some things to be desired, it's not slow as balls. a superior implementation would be creating a VirtualTextBox of some sort

This commit is contained in:
goyuken 2012-12-03 21:19:39 +00:00
parent 7fa80cdcaf
commit 2e4ca0fae6
3 changed files with 105 additions and 41 deletions

View File

@ -31,14 +31,17 @@
this.btnClose = new System.Windows.Forms.Button(); this.btnClose = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button(); this.btnClear = new System.Windows.Forms.Button();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.textBox1 = new System.Windows.Forms.TextBox(); this.buttonCopy = new System.Windows.Forms.Button();
this.virtualListView1 = new BizHawk.VirtualListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.buttonCopyAll = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnClose // btnClose
// //
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(453, 3); this.btnClose.Location = new System.Drawing.Point(597, 3);
this.btnClose.Name = "btnClose"; this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23); this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 2; this.btnClose.TabIndex = 2;
@ -60,40 +63,70 @@
// //
this.tableLayoutPanel1.AutoSize = true; this.tableLayoutPanel1.AutoSize = true;
this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnCount = 5;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.btnClear, 0, 0); this.tableLayoutPanel1.Controls.Add(this.btnClear, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.btnClose, 2, 0); this.tableLayoutPanel1.Controls.Add(this.btnClose, 4, 0);
this.tableLayoutPanel1.Controls.Add(this.buttonCopy, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.buttonCopyAll, 2, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 273); this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 368);
this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(531, 29); this.tableLayoutPanel1.Size = new System.Drawing.Size(675, 29);
this.tableLayoutPanel1.TabIndex = 5; this.tableLayoutPanel1.TabIndex = 5;
// //
// textBox1 // buttonCopy
// //
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.buttonCopy.Location = new System.Drawing.Point(84, 3);
this.textBox1.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.buttonCopy.Name = "buttonCopy";
this.textBox1.Location = new System.Drawing.Point(0, 0); this.buttonCopy.Size = new System.Drawing.Size(75, 23);
this.textBox1.Multiline = true; this.buttonCopy.TabIndex = 3;
this.textBox1.Name = "textBox1"; this.buttonCopy.Text = "Copy Sel.";
this.textBox1.ReadOnly = true; this.buttonCopy.UseVisualStyleBackColor = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.buttonCopy.Click += new System.EventHandler(this.buttonCopy_Click);
this.textBox1.Size = new System.Drawing.Size(531, 273); //
this.textBox1.TabIndex = 6; // virtualListView1
this.textBox1.TabStop = false; //
this.virtualListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1});
this.virtualListView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.virtualListView1.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.virtualListView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.virtualListView1.ItemCount = 0;
this.virtualListView1.Location = new System.Drawing.Point(0, 0);
this.virtualListView1.Name = "virtualListView1";
this.virtualListView1.selectedItem = -1;
this.virtualListView1.Size = new System.Drawing.Size(675, 368);
this.virtualListView1.TabIndex = 8;
this.virtualListView1.UseCompatibleStateImageBehavior = false;
this.virtualListView1.View = System.Windows.Forms.View.Details;
this.virtualListView1.VirtualMode = true;
this.virtualListView1.QueryItemText += new BizHawk.QueryItemTextHandler(this.virtualListView1_QueryItemText);
this.virtualListView1.ClientSizeChanged += new System.EventHandler(this.virtualListView1_ClientSizeChanged);
//
// buttonCopyAll
//
this.buttonCopyAll.Location = new System.Drawing.Point(165, 3);
this.buttonCopyAll.Name = "buttonCopyAll";
this.buttonCopyAll.Size = new System.Drawing.Size(75, 23);
this.buttonCopyAll.TabIndex = 4;
this.buttonCopyAll.Text = "Copy All";
this.buttonCopyAll.UseVisualStyleBackColor = true;
this.buttonCopyAll.Click += new System.EventHandler(this.buttonCopyAll_Click);
// //
// LogWindow // LogWindow
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnClose; this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(531, 302); this.ClientSize = new System.Drawing.Size(675, 397);
this.Controls.Add(this.textBox1); this.Controls.Add(this.virtualListView1);
this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.tableLayoutPanel1);
this.MinimumSize = new System.Drawing.Size(171, 97); this.MinimumSize = new System.Drawing.Size(171, 97);
this.Name = "LogWindow"; this.Name = "LogWindow";
@ -111,6 +144,9 @@
private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnClear; private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TextBox textBox1; private VirtualListView virtualListView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.Button buttonCopy;
private System.Windows.Forms.Button buttonCopyAll;
} }
} }

View File

@ -16,6 +16,8 @@ namespace BizHawk.MultiClient
int defaultWidth; int defaultWidth;
int defaultHeight; int defaultHeight;
List<string> Lines = new List<string>();
public LogWindow() public LogWindow()
{ {
InitializeComponent(); InitializeComponent();
@ -26,36 +28,35 @@ namespace BizHawk.MultiClient
LogConsole.notifyLogWindowClosing(); LogConsole.notifyLogWindowClosing();
SaveConfigSettings(); SaveConfigSettings();
}; };
virtualListView1_ClientSizeChanged(null, null);
} }
public void ShowReport(string title, string report) public static void ShowReport(string title, string report, IWin32Window parent)
{ {
Text = title; using (var dlg = new LogWindow())
textBox1.Text = report; {
btnClear.Visible = false; var ss = report.Split('\n');
ShowDialog(); foreach (var s in ss)
} dlg.Lines.Add(s);
dlg.virtualListView1.ItemCount = ss.Length;
public void SetLogText(string str) dlg.Text = title;
{ dlg.btnClear.Visible = false;
textBox1.Text = str; dlg.ShowDialog(parent);
textBox1.SelectionStart = str.Length; }
textBox1.ScrollToCaret();
Refresh();
} }
StringBuilder sbLog = new StringBuilder(); StringBuilder sbLog = new StringBuilder();
public void Append(string str) public void Append(string str)
{ {
sbLog.Append(str); Lines.Add(str);
SetLogText(sbLog.ToString()); virtualListView1.ItemCount++;
} }
private void btnClear_Click(object sender, EventArgs e) private void btnClear_Click(object sender, EventArgs e)
{ {
sbLog.Length = 0; Lines.Clear();
SetLogText(""); virtualListView1.ItemCount = 0;
Refresh(); virtualListView1.SelectedIndices.Clear();
} }
private void btnClose_Click(object sender, EventArgs e) private void btnClose_Click(object sender, EventArgs e)
@ -90,5 +91,33 @@ namespace BizHawk.MultiClient
Global.Config.LogWindowHeight = this.Bottom - this.Top; Global.Config.LogWindowHeight = this.Bottom - this.Top;
} }
} }
private void virtualListView1_QueryItemText(int item, int subItem, out string text)
{
text = Lines[item];
}
private void virtualListView1_ClientSizeChanged(object sender, EventArgs e)
{
virtualListView1.Columns[0].Width = virtualListView1.ClientSize.Width;
}
private void buttonCopy_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
foreach (int i in virtualListView1.SelectedIndices)
sb.AppendLine(Lines[i]);
if (sb.Length > 0)
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
}
private void buttonCopyAll_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
foreach (var s in Lines)
sb.Append(s);
if (sb.Length > 0)
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
}
} }
} }

View File

@ -24,10 +24,9 @@ namespace BizHawk.MultiClient
private void DumpStatus_Click(object sender, EventArgs e) private void DumpStatus_Click(object sender, EventArgs e)
{ {
string details = Global.Emulator.CoreOutputComm.RomStatusDetails; string details = Global.Emulator.CoreOutputComm.RomStatusDetails;
if(string.IsNullOrEmpty(details)) return; if (string.IsNullOrEmpty(details)) return;
var lw = new LogWindow();
Global.Sound.StopSound(); Global.Sound.StopSound();
lw.ShowReport("Dump Status Report",details); LogWindow.ShowReport("Dump Status Report", details, this);
Global.Sound.StartSound(); Global.Sound.StartSound();
} }