VirtualBox

Changeset 43324 in vbox


Ignore:
Timestamp:
Sep 13, 2012 9:33:37 PM (12 years ago)
Author:
vboxsync
Message:

bug #6322: Debugger: Redo the command history

Maintain invariant that the empty line is the last one. That
simplifies the logic and make history actually work as expected.

Location:
trunk/src/VBox/Debugger
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/VBoxDbgConsole.cpp

    r38814 r43324  
    146146
    147147VBoxDbgConsoleInput::VBoxDbgConsoleInput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/)
    148     : QComboBox(pParent), m_iBlankItem(0), m_hGUIThread(RTThreadNativeSelf())
    149 {
    150     insertItem(m_iBlankItem, "");
     148    : QComboBox(pParent), m_hGUIThread(RTThreadNativeSelf())
     149{
     150    addItem(""); /* invariant: empty command line is the last item */
     151
    151152    setEditable(true);
    152153    setInsertPolicy(NoInsert);
     
    181182{
    182183    Assert(m_hGUIThread == RTThreadNativeSelf());
     184
     185    QString command = currentText();
     186    /* TODO: trim whitespace? */
     187    if (command.isEmpty()) {
     188        return;
     189    }
     190
    183191    /* deal with the current command. */
    184     QString Str = currentText();
    185     emit commandSubmitted(Str);
    186 
    187     /* update the history and clear the entry field */
    188     QString PrevStr = m_iBlankItem > 0 ? itemText(m_iBlankItem - 1) : "";
    189     if (PrevStr != Str)
    190     {
    191         setItemText(m_iBlankItem, Str);
    192         if (    m_iBlankItem > 0
    193             &&  m_iBlankItem >= maxCount() - 1)
    194             removeItem(m_iBlankItem - maxCount() - 1);
    195         insertItem(++m_iBlankItem, "");
    196     }
    197 
    198     clearEditText();
    199     setCurrentIndex(m_iBlankItem);
     192    emit commandSubmitted(command);
     193
     194
     195    /*
     196     * Add current command to history.
     197     */
     198    bool needsAppending = true;
     199
     200    /* invariant: empty line at the end */
     201    int lastItem = count() - 1;
     202    Assert(itemText(lastItem).isEmpty());
     203
     204    /* have previous command? check duplicate. */
     205    if (lastItem > 0) {
     206        const QString prevCommand(itemText(lastItem - 1));
     207        if (command == prevCommand) {
     208            needsAppending = false;
     209        }
     210    }
     211
     212    if (needsAppending) {
     213        /* history full? drop the oldest command. */
     214        if (count() == maxCount()) {
     215            removeItem(0);
     216            --lastItem;
     217        }
     218
     219        /* insert before the empty line. */
     220        insertItem(lastItem, command);
     221    }
     222
     223    /* invariant: empty line at the end */
     224    int newLastItem = count() - 1;
     225    Assert(itemText(newLastItem).isEmpty());
     226
     227    /* select empty line to present "new" command line to the user */
     228    setCurrentIndex(newLastItem);
    200229}
    201230
  • trunk/src/VBox/Debugger/VBoxDbgConsole.h

    r38813 r43324  
    118118
    119119protected:
    120     /** The current blank entry. */
    121     int m_iBlankItem;
    122120    /** The handle to the GUI thread. */
    123121    RTNATIVETHREAD m_hGUIThread;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette