2015-07-03 00:12:02 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Controls
|
|
|
|
|
{
|
|
|
|
|
class MyListView : ListView
|
|
|
|
|
{
|
2016-01-10 13:23:19 -05:00
|
|
|
|
private bool _preventCheck = false;
|
|
|
|
|
|
2016-11-26 14:15:50 -05:00
|
|
|
|
public MyListView()
|
|
|
|
|
{
|
|
|
|
|
this.DoubleBuffered = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 19:27:02 -04:00
|
|
|
|
protected override void OnItemCheck(ItemCheckEventArgs e)
|
2015-07-03 00:12:02 -04:00
|
|
|
|
{
|
2016-01-10 13:23:19 -05:00
|
|
|
|
if(this._preventCheck) {
|
2015-08-02 19:27:02 -04:00
|
|
|
|
e.NewValue = e.CurrentValue;
|
2016-01-10 13:23:19 -05:00
|
|
|
|
this._preventCheck = false;
|
2015-08-02 19:27:02 -04:00
|
|
|
|
} else
|
|
|
|
|
base.OnItemCheck(e);
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 19:27:02 -04:00
|
|
|
|
protected override void OnMouseDown(MouseEventArgs e)
|
2015-07-03 00:12:02 -04:00
|
|
|
|
{
|
2015-08-02 19:27:02 -04:00
|
|
|
|
if(e.Button == MouseButtons.Left && e.Clicks > 1) {
|
2016-01-10 13:23:19 -05:00
|
|
|
|
this._preventCheck = true;
|
2015-08-02 19:27:02 -04:00
|
|
|
|
} else {
|
2016-01-10 13:23:19 -05:00
|
|
|
|
this._preventCheck = false;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
2015-08-02 19:27:02 -04:00
|
|
|
|
base.OnMouseDown(e);
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 20:33:25 -05:00
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this._preventCheck = false;
|
|
|
|
|
base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class WatchList : MyListView
|
|
|
|
|
{
|
|
|
|
|
private int _editItemIndex = -1;
|
|
|
|
|
private string _originalText = null;
|
|
|
|
|
private bool _pressedEsc = false;
|
|
|
|
|
|
|
|
|
|
public event LabelEditEventHandler AfterEdit;
|
|
|
|
|
|
|
|
|
|
public WatchList()
|
|
|
|
|
{
|
|
|
|
|
this.DoubleBuffered = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEditing
|
|
|
|
|
{
|
|
|
|
|
get { return _editItemIndex >= 0; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-10 13:23:19 -05:00
|
|
|
|
protected override void OnBeforeLabelEdit(LabelEditEventArgs e)
|
|
|
|
|
{
|
2016-02-13 23:13:44 -05:00
|
|
|
|
if(_originalText == null) {
|
|
|
|
|
_originalText = this.Items[e.Item].Text;
|
|
|
|
|
}
|
2017-03-02 20:33:25 -05:00
|
|
|
|
_editItemIndex = e.Item;
|
2016-01-10 13:23:19 -05:00
|
|
|
|
base.OnBeforeLabelEdit(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAfterLabelEdit(LabelEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnAfterLabelEdit(e);
|
2017-03-02 20:33:25 -05:00
|
|
|
|
string text = e.Label;
|
|
|
|
|
var item = this.Items[e.Item];
|
|
|
|
|
if(_pressedEsc) {
|
|
|
|
|
text = _originalText;
|
|
|
|
|
item = new ListViewItem(_originalText);
|
|
|
|
|
this.Items.Insert(e.Item, item);
|
|
|
|
|
_pressedEsc = false;
|
|
|
|
|
}
|
2016-02-13 23:13:44 -05:00
|
|
|
|
_originalText = null;
|
2016-01-10 13:23:19 -05:00
|
|
|
|
_editItemIndex = -1;
|
2017-03-02 20:33:25 -05:00
|
|
|
|
AfterEdit?.Invoke(this, new LabelEditEventArgs(item.Index, text));
|
2016-01-10 13:23:19 -05:00
|
|
|
|
}
|
2017-03-02 20:33:25 -05:00
|
|
|
|
|
2016-01-10 13:23:19 -05:00
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
2017-03-02 20:33:25 -05:00
|
|
|
|
if(_editItemIndex >= 0 && keyData == Keys.Escape) {
|
|
|
|
|
_pressedEsc = true;
|
2016-01-10 13:23:19 -05:00
|
|
|
|
}
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnKeyPress(KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(this.LabelEdit && _editItemIndex < 0 && this.SelectedItems.Count > 0) {
|
|
|
|
|
if(e.KeyChar >= 32 && e.KeyChar <= 127) {
|
|
|
|
|
_originalText = this.SelectedItems[0].Text;
|
|
|
|
|
this.SelectedItems[0].Text = e.KeyChar.ToString();
|
|
|
|
|
this.SelectedItems[0].BeginEdit();
|
|
|
|
|
SendKeys.Send("{RIGHT}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnKeyPress(e);
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
2016-11-26 14:15:50 -05:00
|
|
|
|
|
|
|
|
|
public class DoubleBufferedListView : ListView
|
|
|
|
|
{
|
|
|
|
|
public DoubleBufferedListView()
|
|
|
|
|
{
|
|
|
|
|
this.DoubleBuffered = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|