diff options
author | Max Horn | 2003-05-03 21:49:19 +0000 |
---|---|---|
committer | Max Horn | 2003-05-03 21:49:19 +0000 |
commit | 975d325a924a5a55d87d1ed4c3fd1cfb1de9e876 (patch) | |
tree | 3132bc563701cbcc636718bca65d9da9e6e1fc46 /gui | |
parent | fc9100c8415e03e98e8111ecc54713fb94691f6b (diff) | |
download | scummvm-rg350-975d325a924a5a55d87d1ed4c3fd1cfb1de9e876.tar.gz scummvm-rg350-975d325a924a5a55d87d1ed4c3fd1cfb1de9e876.tar.bz2 scummvm-rg350-975d325a924a5a55d87d1ed4c3fd1cfb1de9e876.zip |
Patch #731613: debugger tab-completion (thanks, Willem!)
svn-id: r7293
Diffstat (limited to 'gui')
-rw-r--r-- | gui/console.cpp | 41 | ||||
-rw-r--r-- | gui/console.h | 10 |
2 files changed, 50 insertions, 1 deletions
diff --git a/gui/console.cpp b/gui/console.cpp index f531629d7d..c52c54a823 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -159,7 +159,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { // comply to the C++ standard, so we can't use a dynamic sized stack array. char *str = new char[len + 1]; - // Copy the user intput to str + // Copy the user input to str for (i = 0; i < len; i++) str[i] = _buffer[(_promptStartPos + i) % kBufferSize]; str[len] = '\0'; @@ -197,6 +197,33 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { scrollToCurrent(); draw(); // FIXME - not nice to redraw the full console just for one char! break; + case 9: // tab + { + if (_completionCallbackProc) { + int len = _currentPos - _promptStartPos; + assert(len >= 0); + char *str = new char[len + 1]; + + // Copy the user input to str + for (i = 0; i < len; i++) + str[i] = _buffer[(_promptStartPos + i) % kBufferSize]; + str[len] = '\0'; + + char *completion = 0; + if ((*_completionCallbackProc)(this, str, completion, + _callbackRefCon)) + { + if (_caretVisible) + drawCaret(true); + insertIntoPrompt(completion); + scrollToCurrent(); + draw(); + delete[] completion; + } + delete[] str; + } + break; + } case 127: killChar(); draw(); @@ -255,6 +282,18 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { } } +void ConsoleDialog::insertIntoPrompt(const char* str) +{ + unsigned int l = strlen(str); + for (int i = _promptEndPos-1; i >= _currentPos; i--) + _buffer[(i + l) % kBufferSize] = + _buffer[i % kBufferSize]; + for (unsigned int j = 0; j < l; ++j) { + _promptEndPos++; + putcharIntern(str[j]); + } +} + void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kSetPositionCmd: diff --git a/gui/console.h b/gui/console.h index c0c806a9b1..4af9eafd2e 100644 --- a/gui/console.h +++ b/gui/console.h @@ -39,6 +39,7 @@ class ScrollBarWidget; class ConsoleDialog : public Dialog { public: typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon); + typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon); protected: char _buffer[kBufferSize]; @@ -63,6 +64,10 @@ protected: InputCallbackProc _callbackProc; void *_callbackRefCon; + // _completionCallbackProc is called when tab is pressed + CompletionCallbackProc _completionCallbackProc; + void *_completionCallbackRefCon; + char _history[kHistorySize][kLineBufferSize]; int _historySize; int _historyIndex; @@ -88,10 +93,15 @@ public: _callbackProc = proc; _callbackRefCon = refCon; } + void setCompletionCallback(CompletionCallbackProc proc, void *refCon) { + _completionCallbackProc = proc; + _completionCallbackRefCon = refCon; + } protected: void drawCaret(bool erase); void putcharIntern(int c); + void insertIntoPrompt(const char *str); void print(const char *str); void nextLine(); void updateScrollBar(); |