Allow using up/down in main gui window input box for quickly repeating commands.

This commit is contained in:
UnknownShadow200 2016-08-25 10:27:27 +10:00
parent 5877dc63d6
commit f42ea4e6ee

View File

@ -183,33 +183,33 @@ namespace MCGalaxy.Gui {
if (InvokeRequired) { if (InvokeRequired) {
Invoke(new PlayerListCallback(UpdateClientList), playerList); return; Invoke(new PlayerListCallback(UpdateClientList), playerList); return;
} }
if (main_Players.DataSource == null) if (main_Players.DataSource == null)
main_Players.DataSource = pc; main_Players.DataSource = pc;
// Try to keep the same selection on update // Try to keep the same selection on update
string selected = null; string selected = null;
var selectedRows = main_Players.SelectedRows; var selectedRows = main_Players.SelectedRows;
if (pc.Count > 0 && selectedRows.Count > 0) if (pc.Count > 0 && selectedRows.Count > 0)
selected = pc[selectedRows[0].Index].name; selected = pc[selectedRows[0].Index].name;
// Update the data source and control // Update the data source and control
pc = new PlayerCollection(); pc = new PlayerCollection();
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) foreach (Player pl in players)
pc.Add(pl); pc.Add(pl);
main_Players.DataSource = pc; main_Players.DataSource = pc;
// Reselect player // Reselect player
if (selected != null) { if (selected != null) {
for (int i = 0; i < main_Players.Rows.Count; i++) { for (int i = 0; i < main_Players.Rows.Count; i++) {
if (Equals(main_Players.Rows[i].Cells[0].Value, selected)) if (Equals(main_Players.Rows[i].Cells[0].Value, selected))
main_Players.Rows[i].Selected = true; main_Players.Rows[i].Selected = true;
} }
} }
main_Players.Refresh(); main_Players.Refresh();
} }
public void PopupNotify(string message, ToolTipIcon icon = ToolTipIcon.Info) { public void PopupNotify(string message, ToolTipIcon icon = ToolTipIcon.Info) {
@ -407,17 +407,42 @@ namespace MCGalaxy.Gui {
void demoteToolStripMenuItem_Click(object sender, EventArgs e) { void demoteToolStripMenuItem_Click(object sender, EventArgs e) {
PlayerCmd("rank", "-down ", ""); PlayerCmd("rank", "-down ", "");
} }
PlayerProperties playerProps;
#region Main tab #region Main tab
List<string> inputLog = new List<string>(21);
int inputIndex = -1;
void txtInput_KeyDown(object sender, KeyEventArgs e) { void txtInput_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode != Keys.Enter) return; if (e.KeyCode == Keys.Up) {
inputIndex = Math.Min(inputIndex + 1, inputLog.Count - 1);
if (inputIndex > -1) SetInputText();
} else if (e.KeyCode == Keys.Down) {
inputIndex = Math.Max(inputIndex - 1, -1);
if (inputIndex > -1) SetInputText();
} else if (e.KeyCode == Keys.Enter) {
InputText();
} else {
inputIndex = -1; return;
}
e.Handled = true; e.Handled = true;
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
}
void SetInputText() {
if (inputIndex == -1) return;
main_txtInput.Text = inputLog[inputIndex];
main_txtInput.SelectionLength = 0;
main_txtInput.SelectionStart = main_txtInput.Text.Length;
}
void InputText() {
string text = main_txtInput.Text; string text = main_txtInput.Text;
if (text.Length == 0) return; if (text.Length == 0) return;
inputLog.Insert(0, text);
if (inputLog.Count > 20)
inputLog.RemoveAt(20);
if (text[0] == '/' && text.Length > 1 && text[1] == '/') { if (text[0] == '/' && text.Length > 1 && text[1] == '/') {
Handlers.HandleChat(text.Substring(1), WriteLine); Handlers.HandleChat(text.Substring(1), WriteLine);
} else if (text[0] == '/') { } else if (text[0] == '/') {
@ -622,7 +647,8 @@ namespace MCGalaxy.Gui {
#region Players tab #region Players tab
PlayerProperties playerProps;
public void UpdatePlyersListBox() { public void UpdatePlyersListBox() {
RunOnUiThread( RunOnUiThread(
delegate { delegate {