21 #include <kstaticdeleter.h>
25 #define CMD_HIST_LENGTH 256
27 KateCmd *KateCmd::s_self = 0;
39 TQStringList l = cmd->
cmds ();
41 for (uint z=0; z<l.count(); z++)
45 for (uint z=0; z<l.count(); z++) {
46 m_dict.insert (l[z], cmd);
58 TQDictIterator<Kate::Command> it(m_dict);
59 for( ; it.current(); ++it )
60 if (it.current()==cmd) l<<it.currentKey();
61 for ( TQStringList::Iterator it1 = l.begin(); it1 != l.end(); ++it1 ) {
74 for ( ; f < cmd.length(); f++ )
76 if ( cmd[f].isLetter() )
78 if ( b && ( ! cmd[f].isLetterOrNumber() && cmd[f] !=
'-' && cmd[f] !=
'_' ) )
81 return m_dict[cmd.left(f)];
84 TQStringList KateCmd::cmds ()
91 KateCmd *KateCmd::self ()
94 sdCmd.setObject(s_self,
new KateCmd ());
99 void KateCmd::appendHistory(
const TQString &cmd )
101 if ( !m_history.isEmpty() && m_history.last() == cmd )
104 if ( m_history.count() == CMD_HIST_LENGTH )
105 m_history.remove( m_history.first() );
107 m_history.append( cmd );
110 const TQString KateCmd::fromHistory( uint index )
const
112 if ( index > m_history.count() - 1 )
114 return m_history[ index ];
125 KateCmdShellCompletion::KateCmdShellCompletion()
128 m_word_break_char =
' ';
129 m_quote_char1 =
'\"';
130 m_quote_char2 =
'\'';
131 m_escape_char =
'\\';
138 splitText(text, m_text_start, m_text_compl);
145 void KateCmdShellCompletion::postProcessMatch( TQString *match )
const
147 if (
match->isNull() )
150 match->prepend( m_text_start );
153 void KateCmdShellCompletion::postProcessMatches( TQStringList *matches )
const
155 for ( TQStringList::Iterator it =
matches->begin();
157 if ( !(*it).isNull() )
158 (*it).prepend( m_text_start );
163 for ( TDECompletionMatches::Iterator it =
matches->begin();
165 if ( !(*it).value().isNull() )
166 (*it).value().prepend( m_text_start );
169 void KateCmdShellCompletion::splitText(
const TQString &text, TQString &text_start,
170 TQString &text_compl)
const
172 bool in_quote =
false;
173 bool escaped =
false;
174 TQChar p_last_quote_char;
175 int last_unquoted_space = -1;
176 int end_space_len = 0;
178 for (uint pos = 0; pos < text.length(); pos++) {
185 else if ( in_quote && text[pos] == p_last_quote_char ) {
188 else if ( !in_quote && text[pos] == m_quote_char1 ) {
189 p_last_quote_char = m_quote_char1;
192 else if ( !in_quote && text[pos] == m_quote_char2 ) {
193 p_last_quote_char = m_quote_char2;
196 else if ( text[pos] == m_escape_char ) {
199 else if ( !in_quote && text[pos] == m_word_break_char ) {
203 while ( pos+1 < text.length() && text[pos+1] == m_word_break_char ) {
208 if ( pos+1 == text.length() )
211 last_unquoted_space = pos;
215 text_start = text.left( last_unquoted_space + 1 );
218 text_compl = text.mid( last_unquoted_space + 1 );
TQString makeCompletion(const TQString &text)
Finds completions to the given text.
virtual TQStringList cmds()=0
Pure text start part of the commands which can be handled by this object which means i....
void match(const TQString &item)
virtual TQString makeCompletion(const TQString &string)
void matches(const TQStringList &matchlist)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)