QTfrontend/ui/widget/SmartLineEdit.cpp
changeset 6205 7764cbe4ddd7
parent 6197 4ce7c29799b9
child 6217 ef53ba841791
equal deleted inserted replaced
6204:80cd75daf80f 6205:7764cbe4ddd7
    51 }
    51 }
    52 
    52 
    53 
    53 
    54 void SmartLineEdit::addCommands(const QStringList & commands)
    54 void SmartLineEdit::addCommands(const QStringList & commands)
    55 {
    55 {
    56     m_keywordMutex.lock();
       
    57 
       
    58     m_cmds->append(commands);
    56     m_cmds->append(commands);
    59 
       
    60     m_keywordMutex.unlock();
       
    61 }
    57 }
    62 
    58 
    63 
    59 
    64 void SmartLineEdit::removeCommands(const QStringList & commands)
    60 void SmartLineEdit::removeCommands(const QStringList & commands)
    65 {
    61 {
    66     m_keywordMutex.lock();
       
    67 
       
    68     foreach (const QString & cmd, commands)
    62     foreach (const QString & cmd, commands)
    69     {
    63     {
    70         m_cmds->removeAll(cmd);
    64         m_cmds->removeAll(cmd);
    71     }
    65     }
    72 
       
    73     m_keywordMutex.unlock();
       
    74 }
    66 }
    75 
    67 
    76 
    68 
    77 void SmartLineEdit::addNickname(const QString & name)
    69 void SmartLineEdit::addNickname(const QString & name)
    78 {
    70 {
    79     m_keywordMutex.lock();
       
    80 
       
    81     m_sorted_nicks->insert(name.toLower(), name);
    71     m_sorted_nicks->insert(name.toLower(), name);
    82     m_nicks->append(name);
    72     m_nicks->append(name);
    83 
       
    84     m_keywordMutex.unlock();
       
    85 }
    73 }
    86 
    74 
    87 
    75 
    88 void SmartLineEdit::removeNickname(const QString & name)
    76 void SmartLineEdit::removeNickname(const QString & name)
    89 {
    77 {
    90     m_keywordMutex.lock();
       
    91 
       
    92     m_sorted_nicks->remove(name.toLower());
    78     m_sorted_nicks->remove(name.toLower());
    93     m_nicks->removeAll(name);
    79     m_nicks->removeAll(name);
    94 
       
    95     m_keywordMutex.unlock();
       
    96 }
    80 }
    97 
    81 
    98 
    82 
    99 void SmartLineEdit::reset()
    83 void SmartLineEdit::reset()
   100 {
    84 {
   101     // forget keywords
    85     // forget keywords
   102     m_keywordMutex.lock();
       
   103 
       
   104     m_cmds->clear();
    86     m_cmds->clear();
   105     m_sorted_nicks->clear();
    87     m_sorted_nicks->clear();
   106     m_nicks->clear();
    88     m_nicks->clear();
   107     resetAutoCompletionStatus();
    89     resetAutoCompletionStatus();
   108 
       
   109     m_keywordMutex.unlock();
       
   110 
    90 
   111     // forget history
    91     // forget history
   112     HistoryLineEdit::reset();
    92     HistoryLineEdit::reset();
   113 }
    93 }
   114 
    94 
   171         postfix = m_postfix;
   151         postfix = m_postfix;
   172         isFirstWord = prefix.isEmpty();
   152         isFirstWord = prefix.isEmpty();
   173     }
   153     }
   174     else
   154     else
   175     {
   155     {
   176         m_keywordMutex.lock();
       
   177         m_cmds->sort();
   156         m_cmds->sort();
   178         m_nicks = new QStringList(m_sorted_nicks->values());
   157         m_nicks = new QStringList(m_sorted_nicks->values());
   179         m_keywordMutex.unlock();
       
   180 
   158 
   181         int cp = cursorPosition();
   159         int cp = cursorPosition();
   182 
   160 
   183         // cursor is not in or at end/beginning of word
   161         // cursor is not in or at end/beginning of word
   184         if ((cp = matchMe.length()) || (QString(matchMe.at(cp)).contains(m_whitespace)))
   162         if ((cp = matchMe.length()) || (QString(matchMe.at(cp)).contains(m_whitespace)))
   209 
   187 
   210         isFirstWord = prefix.isEmpty(); // true if first word
   188         isFirstWord = prefix.isEmpty(); // true if first word
   211     }
   189     }
   212 
   190 
   213 
   191 
   214     m_keywordMutex.lock();
       
   215 
       
   216     if (isFirstWord)
   192     if (isFirstWord)
   217     {
   193     {
   218         // find matching commands
   194         // find matching commands
   219         foreach (const QString & cmd, *m_cmds)
   195         foreach (const QString & cmd, *m_cmds)
   220         {
   196         {
   248                 break;
   224                 break;
   249             }
   225             }
   250         }
   226         }
   251     }
   227     }
   252 
   228 
   253     m_keywordMutex.unlock();
       
   254 
       
   255     // we found a single match?
   229     // we found a single match?
   256     if (!match.isEmpty())
   230     if (!match.isEmpty())
   257     {
   231     {
   258         // replace last word with match
   232         // replace last word with match
   259         // and append ':' if a name at the beginning of the matchMe got completed
   233         // and append ':' if a name at the beginning of the matchMe got completed