Skip to content

Commit

Permalink
Add command history
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Oct 16, 2018
1 parent 10f0e63 commit fa01e4c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions FiveMRcon/CmdHistoryNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace FiveMRcon
{
public class CmdHistoryNode
{
public string Command;
public CmdHistoryNode PreviousCmdNode { get; }
public CmdHistoryNode NextCmdNode;

public CmdHistoryNode(CmdHistoryNode prevNode)
{
PreviousCmdNode = prevNode;
}
}
}
1 change: 1 addition & 0 deletions FiveMRcon/FiveMRcon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CmdHistoryNode.cs" />
<Compile Include="InfoHolder.cs" />
<Compile Include="RconForm.cs">
<SubType>Form</SubType>
Expand Down
1 change: 1 addition & 0 deletions FiveMRcon/RconForm.Designer.cs

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

43 changes: 43 additions & 0 deletions FiveMRcon/RconForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Media;
using System.Net;
using System.Net.Sockets;
using System.Text;
Expand All @@ -8,8 +9,12 @@ namespace FiveMRcon
{
public partial class RconForm : Form
{
private CmdHistoryNode _CurrentCmdHistoryNode;

public RconForm()
{
_CurrentCmdHistoryNode = new CmdHistoryNode(null);

InitializeComponent();
ActiveControl = InputText;
}
Expand All @@ -25,6 +30,37 @@ private void InputText_TextChanged(object sender, EventArgs e)
InputSend.Enabled = InputText.Text.Trim().Length > 0;
}

private void InputText_KeyUp(object sender, KeyEventArgs e)
{
bool relevantKeyUp = false;
if (e.KeyCode == Keys.Up)
{
if (_CurrentCmdHistoryNode.PreviousCmdNode != null)
{
_CurrentCmdHistoryNode = _CurrentCmdHistoryNode.PreviousCmdNode;
relevantKeyUp = true;
}
else
SystemSounds.Beep.Play();
}
else if (e.KeyCode == Keys.Down)
{
if (_CurrentCmdHistoryNode.NextCmdNode != null)
{
_CurrentCmdHistoryNode = _CurrentCmdHistoryNode.NextCmdNode;
relevantKeyUp = true;
}
else
SystemSounds.Beep.Play();
}

if (relevantKeyUp)
{
InputText.Text = _CurrentCmdHistoryNode.Command;
InputText.SelectionStart = InputText.TextLength;
}
}

private void InputSend_Click(object sender, EventArgs e)
{
InputSend.Enabled = false;
Expand Down Expand Up @@ -69,6 +105,13 @@ private void InputSend_Click(object sender, EventArgs e)
}
}

CmdHistoryNode newCmdHistoryNode = new CmdHistoryNode(_CurrentCmdHistoryNode);
// Set command and next node of current node
_CurrentCmdHistoryNode.Command = InputText.Text;
_CurrentCmdHistoryNode.NextCmdNode = newCmdHistoryNode;
// Set current node to new one
_CurrentCmdHistoryNode = newCmdHistoryNode;

InputText.ResetText();
ActiveControl = InputText;
}
Expand Down

0 comments on commit fa01e4c

Please sign in to comment.