public FastSharpForm() { InitializeComponent(); AutoComplete = new AutoComplete(); AutoComplete.ReadAssembly(Assembly.GetExecutingAssembly()); AutoComplete.ReadAssembly(Assembly.GetAssembly(typeof(int))); AutoComplete.ReadAssembly(Assembly.GetAssembly(typeof(File))); AutoComplete.ReadAssembly(Assembly.GetAssembly(typeof(AutoComplete))); foreach (var pair in languageToDisplayMap) { displayToLanguageMap.Add(pair.Value, pair.Key); } foreach (var language in fastSharp.SupportedLanguages) { codeLanguageCombo.Items.Add(languageToDisplayMap[language]); } }
/// <summary> /// Set an auto-completion engine for TAB autocompletion. /// </summary> /// <param name="engine">Engine implementing the IAutoComplete interface</param> public static void SetAutoCompleteEngine(IAutoComplete engine) { autocomplete_engine = engine; }
public static void SetAutoCompleteEngine(IAutoComplete engine) { autocomplete_engine = engine; }
public void Setup() { Root = Node.CreateRoot(); AutoComplete = new AutoComplete(Root); }
// TODO: this method is monstrosity, but it rather not be wise to just cut it into pieces... It's slow enough... // TODO: make this configurable, especially behavior of UP/DOWND arrows might not be intuitive in some environments public string GetUserEntry(IAutoComplete acProvider) { acProvider.Requires(nameof(acProvider)).IsNotNull(); var startPosition = this._console.GetCursorPosition(); var consoleLineWidth = this._console.WindowWidth; var longestLineContentSoFar = 0; int currentCommandEndIndex = 0; char[] commandBuffer = new char[MAX_COMMAND_LENGTH]; string[] autocompleteList = null; int autocompleteIndex = 0; while (true) { ConsoleKeyInfo key = this._console.ReadKey(); if (key.Key == ConsoleKey.Enter) { if (currentCommandEndIndex >= 0) { this._console.WriteLine(); string cmdContent = new string(commandBuffer, 0, currentCommandEndIndex); if (!string.IsNullOrWhiteSpace(cmdContent)) { // remember only new entries (on last position) if (!this._commandHistory.Any() || !this._commandHistory.Last().Equals(cmdContent)) { this._commandHistory.Add(cmdContent); this._historyIndex = this._commandHistory.Count - 1; } } return(cmdContent); } else { return(string.Empty); } } if (key.Key == ConsoleKey.Tab) { // TODO: hide/ show cursor her? probably not required if (autocompleteList == null) { autocompleteList = acProvider.MatchAutoComplete(new string(commandBuffer, 0, currentCommandEndIndex)).ToArray(); autocompleteIndex = -1; } if (autocompleteList.Any()) { // reverse? if ((key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift) { autocompleteIndex--; if (autocompleteIndex < 0) { autocompleteIndex = autocompleteList.Length - 1; } } else { autocompleteIndex++; if (autocompleteIndex >= autocompleteList.Length) { autocompleteIndex = 0; } } string acText = autocompleteList[autocompleteIndex]; this.ApplyText(acText, this._console, commandBuffer, startPosition, ref longestLineContentSoFar, ref currentCommandEndIndex); } } else if (key.Key == ConsoleKey.Backspace) { if (currentCommandEndIndex > 0) { try { this._console.HideCursor(); var currentPosition = this._console.GetCursorPosition(); int lineIndex = this.CalculatePositionInLine(startPosition, currentPosition, consoleLineWidth); if (lineIndex > 0) { this.RemoveCharsAt(commandBuffer, lineIndex - 1, 1, ref currentCommandEndIndex); this._console.SetCursorPosition(startPosition.X, startPosition.Y); this._console.WriteText(this._cmdColor, new string(' ', currentCommandEndIndex + 1)); if (currentCommandEndIndex >= 0) { this._console.SetCursorPosition(startPosition.X, startPosition.Y); this._console.WriteText(this._cmdColor, new string(commandBuffer, 0, currentCommandEndIndex)); this._console.SetCursorPosition(currentPosition.X - 1, currentPosition.Y); } } } finally { this._console.ShowCursor(); } } } else if (key.Key == ConsoleKey.Delete) { if (currentCommandEndIndex >= 0) { try { this._console.HideCursor(); var currentPosition = this._console.GetCursorPosition(); int lineIndex = this.CalculatePositionInLine(startPosition, currentPosition, consoleLineWidth); if (lineIndex >= 0 && lineIndex < currentCommandEndIndex) { this.RemoveCharsAt(commandBuffer, lineIndex, 1, ref currentCommandEndIndex); this._console.SetCursorPosition(startPosition.X, startPosition.Y); this._console.WriteText(this._cmdColor, new string(' ', currentCommandEndIndex + 1)); if (currentCommandEndIndex >= 0) { this._console.SetCursorPosition(startPosition.X, startPosition.Y); this._console.WriteText(this._cmdColor, new string(commandBuffer, 0, currentCommandEndIndex)); this._console.SetCursorPosition(currentPosition.X, currentPosition.Y); } } } finally { this._console.ShowCursor(); } } } else if (key.Key == ConsoleKey.LeftArrow) { // TODO: multiline fix var currentPosition = this._console.GetCursorPosition(); var deltaX = currentPosition.X - startPosition.X; if (deltaX > 0) { this._console.SetCursorPosition(currentPosition.X - 1, startPosition.Y); } } else if (key.Key == ConsoleKey.RightArrow) { // TODO: multiline fix var currentPosition = this._console.GetCursorPosition(); var deltaX = currentPosition.X - startPosition.X; if (deltaX < currentCommandEndIndex) { this._console.SetCursorPosition(currentPosition.X + 1, startPosition.Y); } } else if (key.Key == ConsoleKey.UpArrow) { // TODO: multiline fix // TODO: move cursor between lines // TODO: is it possible to do text selection with SHIFT? } else if (key.Key == ConsoleKey.DownArrow) { // TODO: multiline fix // TODO: move cursor between lines // TODO: is it possible to do text selection with SHIFT? } else if (key.Key == ConsoleKey.Insert) { if ((key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift) { var currentPosition = this._console.GetCursorPosition(); int lineIndex = this.CalculatePositionInLine(startPosition, currentPosition, consoleLineWidth); currentCommandEndIndex = this.PasteFromClipboard(commandBuffer, lineIndex, currentCommandEndIndex); } else { // switch insert mode this._overWriting = !this._overWriting; } } else if (key.Key == ConsoleKey.End) { var endOfline = this.CalculateCursorPositionForLineIndex(startPosition, consoleLineWidth, currentCommandEndIndex); this._console.SetCursorPosition(endOfline.X, endOfline.Y); } else if (key.Key == ConsoleKey.Home) { this._console.SetCursorPosition(startPosition.X, startPosition.Y); } else if (key.Key == ConsoleKey.PageUp) { if (this._historyIndex < this._commandHistory.Count && this._historyIndex >= 0) { string historyEntry = this._commandHistory[this._historyIndex--]; // looping? //if (historyIndex < 0) //{ // historyIndex = this._commandHistory.Count - 1; //} this.ApplyText(historyEntry, this._console, commandBuffer, startPosition, ref longestLineContentSoFar, ref currentCommandEndIndex); } } else if (key.Key == ConsoleKey.PageDown) { if (this._historyIndex < this._commandHistory.Count - 1 && this._historyIndex >= -1) { string historyEntry = this._commandHistory[++this._historyIndex]; // looping? //if (historyIndex >= this._commandHistory.Count) //{ // historyIndex = 0; //} this.ApplyText(historyEntry, this._console, commandBuffer, startPosition, ref longestLineContentSoFar, ref currentCommandEndIndex); } } else if (key.Key == ConsoleKey.Escape) { // do nothing // TODO: or reset command-line? } else if (key.KeyChar != 0) { var currentPosition = this._console.GetCursorPosition(); int lineIndex = this.CalculatePositionInLine(startPosition, currentPosition, consoleLineWidth); if ((key.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control && key.Key == ConsoleKey.V) { currentCommandEndIndex = this.PasteFromClipboard(commandBuffer, lineIndex, currentCommandEndIndex); } else { if (currentCommandEndIndex < MAX_COMMAND_LENGTH) { if (lineIndex == currentCommandEndIndex) { // append at the end - in both INSERT modes the same commandBuffer[currentCommandEndIndex] = key.KeyChar; currentCommandEndIndex += 1; } else if (this._overWriting) { // overwrite in the middle commandBuffer[lineIndex] = key.KeyChar; } else { // insert in the middle var usedBufferLength = currentCommandEndIndex + 1; this.InsertCharsAt(commandBuffer, lineIndex, new[] { key.KeyChar }, ref usedBufferLength); currentCommandEndIndex++; } try { this._console.HideCursor(); this._console.SetCursorPosition(startPosition.X, startPosition.Y); this._console.SetColors(this._cmdColor); this._console.WriteText(new string(commandBuffer, 0, currentCommandEndIndex)); if (currentPosition.X < consoleLineWidth) { this._console.SetCursorPosition(currentPosition.X + 1, currentPosition.Y); } else { this._console.SetCursorPosition(0, currentPosition.Y + 1); } autocompleteList = null; } finally { this._console.ShowCursor(); } } } } else { // delete, esc } } }
public void onOpened(TextController controller) { m_boss = controller.Boss; m_autoComplete = m_boss.Get<IAutoComplete>(); setTypingAttributes(CurrentStyles.DefaultAttributes); setAutomaticTextReplacementEnabled(false); if (m_boss.Has<ITooltip>()) { m_tooltip = m_boss.Get<ITooltip>(); m_timer = new System.Threading.Timer((object state) => { NSApplication.sharedApplication().BeginInvoke(this.DoShowTooltip); }); } }
public void onClosing(TextController controller) { if (m_tooltipWindow != null) { m_tooltipWindow.Close(); m_tooltipWindow = null; } if (m_timer != null) m_timer.Dispose(); m_autoComplete = null; // note that these won't be GCed if we don't null them out m_boss = null; }