27 #define CMD_HIST_LENGTH 256
31 m_cmdCompletion.
addItem(
"help");
42 for (
int z=0; z<l.count(); z++)
43 if (m_dict.contains(l[z])) {
44 kDebug(13050)<<
"Command already registered: "<<l[z]<<
". Aborting.";
48 for (
int z=0; z<l.count(); z++) {
49 m_dict.insert (l[z], cmd);
64 while (i != m_dict.constEnd()) {
65 if (i.value()==cmd) l << i.key();
69 for ( QStringList::Iterator it1 = l.begin(); it1 != l.end(); ++it1 ) {
88 if ( cmd.length() >= 2 && cmd.at(0) ==
's' && ( cmd.at(1) ==
'-' || cmd.at(1) ==
'_') ) {
89 return m_dict.value(
QString(
"s"));
92 for ( ; f < cmd.length(); f++ )
94 if ( cmd[f].isLetter() )
96 if ( b && ( ! cmd[f].isLetterOrNumber() && cmd[f] !=
'-' && cmd[f] !=
'_' ) )
99 return m_dict.value(cmd.left(f));
104 return m_dict.values();
119 if (!m_history.isEmpty())
120 if ( m_history.last() == cmd )
124 m_history.removeFirst();
126 m_history.append( cmd );
131 if ( index < 0 || index > m_history.count() - 1 )
133 return m_history[ index ];
138 return &m_cmdCompletion;
152 m_word_break_char =
' ';
153 m_quote_char1 =
'\"';
154 m_quote_char2 =
'\'';
155 m_escape_char =
'\\';
162 splitText(text, m_text_start, m_text_compl);
171 if ( match->isNull() )
174 match->prepend( m_text_start );
179 for ( QStringList::Iterator it = matches->begin();
180 it != matches->end(); it++ )
181 if ( !(*it).isNull() )
182 (*it).prepend( m_text_start );
187 for ( KCompletionMatches::Iterator it = matches->begin();
188 it != matches->end(); it++ )
189 if ( !(*it).value().isNull() )
190 (*it).value().prepend( m_text_start );
193 void KateCmdShellCompletion::splitText(
const QString &text,
QString &text_start,
196 bool in_quote =
false;
197 bool escaped =
false;
198 QChar p_last_quote_char;
199 int last_unquoted_space = -1;
200 int end_space_len = 0;
202 for (
int pos = 0; pos < text.length(); pos++) {
209 else if ( in_quote && text[pos] == p_last_quote_char ) {
212 else if ( !in_quote && text[pos] == m_quote_char1 ) {
213 p_last_quote_char = m_quote_char1;
216 else if ( !in_quote && text[pos] == m_quote_char2 ) {
217 p_last_quote_char = m_quote_char2;
220 else if ( text[pos] == m_escape_char ) {
223 else if ( !in_quote && text[pos] == m_word_break_char ) {
227 while ( pos+1 < text.length() && text[pos+1] == m_word_break_char ) {
232 if ( pos+1 == text.length() )
235 last_unquoted_space = pos;
239 text_start = text.left( last_unquoted_space + 1 );
242 text_compl = text.mid( last_unquoted_space + 1 );
void postProcessMatches(QStringList *matches) const
bool unregisterCommand(KTextEditor::Command *cmd)
QString makeCompletion(const QString &text)
Finds completions to the given text.
static KateGlobal * self()
Kate Part Internal stuff ;)
void appendHistory(const QString &cmd)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void postProcessMatch(QString *match) const
const QString fromHistory(int i) const
void insertItems(const QStringList &items)
QList< KTextEditor::Command * > commands() const
KTextEditor::Command * queryCommand(const QString &cmd) const
KCompletion * commandCompletionObject()
virtual QString makeCompletion(const QString &string)
QStringList commandList() const
bool registerCommand(KTextEditor::Command *cmd)
void removeItem(const QString &item)
void addItem(const QString &item)
KateCmd * cmdManager()
command manager
virtual const QStringList & cmds()=0