public void Clear() { _buffer.Clear(); _selectionStart = 0; _selectionDirection = 0; _autoComplete = null; }
public void AutoComplete() { if (_buffer.Length == 0) { return; } string argCompletionStr = string.Empty; if (_autoComplete == null) { _autoComplete = new UI.AutoComplete(); idCmdArgs args = new idCmdArgs(_buffer.ToString(), true); argCompletionStr = args.ToString(); _autoComplete.CompletionString = args.Get(0); _autoComplete.MatchCount = 0; _autoComplete.MatchIndex = 0; string[] matches = idE.CmdSystem.CommandCompletion(new Predicate <string>(FindMatch)); if (matches.Length > 1) { foreach (string s in matches) { idConsole.WriteLine(" {0}", s); } } matches = idE.CvarSystem.CommandCompletion(new Predicate <string>(FindMatch)); if (matches.Length > 1) { foreach (string s in matches) { idConsole.WriteLine(" {0} {1}= \"{2}\"", s, idColorString.White, idE.CvarSystem.GetString(s)); } } else if (matches.Length == 1) { this.Buffer = string.Format("{0} ", matches[0]); string[] argMatches = idE.CvarSystem.ArgCompletion(matches[0], argCompletionStr); foreach (string s in argMatches) { idConsole.WriteLine(" {0}", s); } } } }
public void AutoComplete() { if(_buffer.Length == 0) { return; } string argCompletionStr = string.Empty; if(_autoComplete == null) { _autoComplete = new UI.AutoComplete(); idCmdArgs args = new idCmdArgs(_buffer.ToString(), true); argCompletionStr = args.ToString(); _autoComplete.CompletionString = args.Get(0); _autoComplete.MatchCount = 0; _autoComplete.MatchIndex = 0; string[] matches = idE.CmdSystem.CommandCompletion(new Predicate<string>(FindMatch)); if(matches.Length > 1) { foreach(string s in matches) { idConsole.WriteLine(" {0}", s); } } matches = idE.CvarSystem.CommandCompletion(new Predicate<string>(FindMatch)); if(matches.Length > 1) { foreach(string s in matches) { idConsole.WriteLine(" {0} {1}= \"{2}\"", s, idColorString.White, idE.CvarSystem.GetString(s)); } } else if(matches.Length == 1) { this.Buffer = string.Format("{0} ", matches[0]); string[] argMatches = idE.CvarSystem.ArgCompletion(matches[0], argCompletionStr); foreach(string s in argMatches) { idConsole.WriteLine(" {0}", s); } } } }
public void ProcessKeyDown(KeyEventArgs e) { if((e.Alt == true) || (e.Control == true)) { if((e.Control == true) && (e.KeyCode == Keys.A)) { this.SelectionStart = 0; this.SelectionDirection = _buffer.Length; } } else if((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Enter)) { if(_buffer.Length > 0) { if(InputAvailable != null) { InputAvailable(this, new EventArgs()); } _historyLines.Add(_buffer.ToString()); _historyLine = _historyLines.Count; _buffer.Clear(); _selectionStart = 0; _selectionDirection = 0; } } else if(e.KeyCode == Keys.Tab) { AutoComplete(); return; } else if((e.KeyCode == Keys.Home) || (e.KeyCode == Keys.End)) { if(e.Shift == true) { // we're shift selecting while pressing home or end, figure out where to select from. int start = this.SelectionStart; this.SelectionStart = (e.KeyCode == Keys.Home) ? 0 : (this.SelectionDirection != 0) ? -this.SelectionDirection : start; if(e.KeyCode == Keys.End) { this.SelectionDirection = _buffer.Length - start; } else { this.SelectionDirection = -(start + 1); } } else { this.SelectionDirection = 0; this.SelectionStart = (e.KeyCode == Keys.Home) ? 0 : _buffer.Length; } } else if((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right)) { if(e.Shift == true) { this.SelectionDirection += (e.KeyCode == Keys.Left) ? -1 : 1; } else { if(this.SelectionDirection != 0) { if((this.SelectionDirection != 0) && (e.KeyCode == Keys.Right)) { this.SelectionStart = this.SelectionStart + this.SelectionLength; } else { this.SelectionStart = this.SelectionStart; } this.SelectionDirection = 0; } else { this.SelectionStart += (e.KeyCode == Keys.Left) ? -1 : 1; } } } else if((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down)) { // command history _historyLine += (e.KeyCode == Keys.Up) ? -1 : 1; if(_historyLine < 0) { _historyLine = 0; } else if(_historyLine >= _historyLines.Count) { _historyLine = _historyLines.Count; } _buffer.Clear(); if(_historyLine < _historyLines.Count) { _buffer.Append(_historyLines[_historyLine]); } this.SelectionStart = this.Length; this.SelectionDirection = 0; } else if((e.KeyCode == Keys.Back) || (e.KeyCode == Keys.Delete)) { if((e.KeyCode == Keys.Delete) && (this.SelectionStart == _buffer.Length)) { // don't want to delete past the end of the buffer. return; } else if((e.KeyCode == Keys.Back) && (this.SelectionStart == 0)) { // don't want backspace deleting paste the start of the buffer. return; } else if(this.SelectionLength > 0) { _buffer.Remove(this.SelectionStart, this.SelectionLength); this.SelectionStart = this.SelectionStart; } else { int dir = (e.KeyCode == Keys.Back) ? -1 : 0; _buffer.Remove(this.SelectionStart + dir, 1); this.SelectionStart += dir; } if(this.SelectionStart > _buffer.Length) { this.SelectionStart = _buffer.Length; } this.SelectionDirection = 0; } else { char c = idHelper.CharacterFromKeyCode(e.KeyCode, e.Modifiers); if(c != '\0') { _buffer.Insert(_selectionStart, c); this.SelectionStart++; this.SelectionDirection = 0; } } // pressing tab exits the method above, so if we got here // the user pressed another key and broke out of autocomplete. _autoComplete = null; }
public void ProcessKeyDown(KeyEventArgs e) { if ((e.Alt == true) || (e.Control == true)) { if ((e.Control == true) && (e.KeyCode == Keys.A)) { this.SelectionStart = 0; this.SelectionDirection = _buffer.Length; } } else if ((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Enter)) { if (_buffer.Length > 0) { if (InputAvailable != null) { InputAvailable(this, new EventArgs()); } _historyLines.Add(_buffer.ToString()); _historyLine = _historyLines.Count; _buffer.Clear(); _selectionStart = 0; _selectionDirection = 0; } } else if (e.KeyCode == Keys.Tab) { AutoComplete(); return; } else if ((e.KeyCode == Keys.Home) || (e.KeyCode == Keys.End)) { if (e.Shift == true) { // we're shift selecting while pressing home or end, figure out where to select from. int start = this.SelectionStart; this.SelectionStart = (e.KeyCode == Keys.Home) ? 0 : (this.SelectionDirection != 0) ? -this.SelectionDirection : start; if (e.KeyCode == Keys.End) { this.SelectionDirection = _buffer.Length - start; } else { this.SelectionDirection = -(start + 1); } } else { this.SelectionDirection = 0; this.SelectionStart = (e.KeyCode == Keys.Home) ? 0 : _buffer.Length; } } else if ((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right)) { if (e.Shift == true) { this.SelectionDirection += (e.KeyCode == Keys.Left) ? -1 : 1; } else { if (this.SelectionDirection != 0) { if ((this.SelectionDirection != 0) && (e.KeyCode == Keys.Right)) { this.SelectionStart = this.SelectionStart + this.SelectionLength; } else { this.SelectionStart = this.SelectionStart; } this.SelectionDirection = 0; } else { this.SelectionStart += (e.KeyCode == Keys.Left) ? -1 : 1; } } } else if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down)) { // command history _historyLine += (e.KeyCode == Keys.Up) ? -1 : 1; if (_historyLine < 0) { _historyLine = 0; } else if (_historyLine >= _historyLines.Count) { _historyLine = _historyLines.Count; } _buffer.Clear(); if (_historyLine < _historyLines.Count) { _buffer.Append(_historyLines[_historyLine]); } this.SelectionStart = this.Length; this.SelectionDirection = 0; } else if ((e.KeyCode == Keys.Back) || (e.KeyCode == Keys.Delete)) { if ((e.KeyCode == Keys.Delete) && (this.SelectionStart == _buffer.Length)) { // don't want to delete past the end of the buffer. return; } else if ((e.KeyCode == Keys.Back) && (this.SelectionStart == 0)) { // don't want backspace deleting paste the start of the buffer. return; } else if (this.SelectionLength > 0) { _buffer.Remove(this.SelectionStart, this.SelectionLength); this.SelectionStart = this.SelectionStart; } else { int dir = (e.KeyCode == Keys.Back) ? -1 : 0; _buffer.Remove(this.SelectionStart + dir, 1); this.SelectionStart += dir; } if (this.SelectionStart > _buffer.Length) { this.SelectionStart = _buffer.Length; } this.SelectionDirection = 0; } else { char c = idHelper.CharacterFromKeyCode(e.KeyCode, e.Modifiers); if (c != '\0') { _buffer.Insert(_selectionStart, c); this.SelectionStart++; this.SelectionDirection = 0; } } // pressing tab exits the method above, so if we got here // the user pressed another key and broke out of autocomplete. _autoComplete = null; }