• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • interfaces
katecmd.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2001, 2003 Christoph Cullmann <cullmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "katecmd.h"
20
21#include <kstaticdeleter.h>
22#include <kdebug.h>
23
24//BEGIN KateCmd
25#define CMD_HIST_LENGTH 256
26
27KateCmd *KateCmd::s_self = 0;
28
29KateCmd::KateCmd ()
30{
31}
32
33KateCmd::~KateCmd ()
34{
35}
36
37bool KateCmd::registerCommand (Kate::Command *cmd)
38{
39 TQStringList l = cmd->cmds ();
40
41 for (uint z=0; z<l.count(); z++)
42 if (m_dict[l[z]])
43 return false;
44
45 for (uint z=0; z<l.count(); z++) {
46 m_dict.insert (l[z], cmd);
47 kdDebug()<<"Inserted command:"<<l[z]<<endl;
48 }
49
50 m_cmds += l;
51
52 return true;
53}
54
55bool KateCmd::unregisterCommand (Kate::Command *cmd)
56{
57 TQStringList l;
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 ) {
62 m_dict.remove(*it1);
63 kdDebug()<<"Removed command:"<<*it1<<endl;
64 }
65 return true;
66}
67
68Kate::Command *KateCmd::queryCommand (const TQString &cmd)
69{
70 // a command can be named ".*[\w\-]+" with the constrain that it must
71 // contain at least one letter.
72 uint f = 0;
73 bool b = false;
74 for ( ; f < cmd.length(); f++ )
75 {
76 if ( cmd[f].isLetter() )
77 b = true;
78 if ( b && ( ! cmd[f].isLetterOrNumber() && cmd[f] != '-' && cmd[f] != '_' ) )
79 break;
80 }
81 return m_dict[cmd.left(f)];
82}
83
84TQStringList KateCmd::cmds ()
85{
86 return m_cmds;
87}
88
89static KStaticDeleter<KateCmd> sdCmd;
90
91KateCmd *KateCmd::self ()
92{
93 if (!s_self)
94 sdCmd.setObject(s_self, new KateCmd ());
95
96 return s_self;
97}
98
99void KateCmd::appendHistory( const TQString &cmd )
100{
101 if ( !m_history.isEmpty() && m_history.last() == cmd )
102 return;
103
104 if ( m_history.count() == CMD_HIST_LENGTH )
105 m_history.remove( m_history.first() );
106
107 m_history.append( cmd );
108}
109
110const TQString KateCmd::fromHistory( uint index ) const
111{
112 if ( index > m_history.count() - 1 )
113 return TQString();
114 return m_history[ index ];
115}
116//END KateCmd
117
118//BEGIN KateCmdShellCompletion
119/*
120 A lot of the code in the below class is copied from
121 tdelibs/tdeio/tdeio/kshellcompletion.cpp
122 Copyright (C) 2000 David Smith <dsmith@algonet.se>
123 Copyright (C) 2004 Anders Lund <anders@alweb.dk>
124*/
125KateCmdShellCompletion::KateCmdShellCompletion()
126 : TDECompletion()
127{
128 m_word_break_char = ' ';
129 m_quote_char1 = '\"';
130 m_quote_char2 = '\'';
131 m_escape_char = '\\';
132}
133
134TQString KateCmdShellCompletion::makeCompletion( const TQString &text )
135{
136 // Split text at the last unquoted space
137 //
138 splitText(text, m_text_start, m_text_compl);
139
140 // Make completion on the last part of text
141 //
142 return TDECompletion::makeCompletion( m_text_compl );
143}
144
145void KateCmdShellCompletion::postProcessMatch( TQString *match ) const
146{
147 if ( match->isNull() )
148 return;
149
150 match->prepend( m_text_start );
151}
152
153void KateCmdShellCompletion::postProcessMatches( TQStringList *matches ) const
154{
155 for ( TQStringList::Iterator it = matches->begin();
156 it != matches->end(); it++ )
157 if ( !(*it).isNull() )
158 (*it).prepend( m_text_start );
159}
160
161void KateCmdShellCompletion::postProcessMatches( TDECompletionMatches *matches ) const
162{
163 for ( TDECompletionMatches::Iterator it = matches->begin();
164 it != matches->end(); it++ )
165 if ( !(*it).value().isNull() )
166 (*it).value().prepend( m_text_start );
167}
168
169void KateCmdShellCompletion::splitText(const TQString &text, TQString &text_start,
170 TQString &text_compl) const
171{
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;
177
178 for (uint pos = 0; pos < text.length(); pos++) {
179
180 end_space_len = 0;
181
182 if ( escaped ) {
183 escaped = false;
184 }
185 else if ( in_quote && text[pos] == p_last_quote_char ) {
186 in_quote = false;
187 }
188 else if ( !in_quote && text[pos] == m_quote_char1 ) {
189 p_last_quote_char = m_quote_char1;
190 in_quote = true;
191 }
192 else if ( !in_quote && text[pos] == m_quote_char2 ) {
193 p_last_quote_char = m_quote_char2;
194 in_quote = true;
195 }
196 else if ( text[pos] == m_escape_char ) {
197 escaped = true;
198 }
199 else if ( !in_quote && text[pos] == m_word_break_char ) {
200
201 end_space_len = 1;
202
203 while ( pos+1 < text.length() && text[pos+1] == m_word_break_char ) {
204 end_space_len++;
205 pos++;
206 }
207
208 if ( pos+1 == text.length() )
209 break;
210
211 last_unquoted_space = pos;
212 }
213 }
214
215 text_start = text.left( last_unquoted_space + 1 );
216
217 // the last part without trailing blanks
218 text_compl = text.mid( last_unquoted_space + 1 );
219}
220
221//END KateCmdShellCompletion
222
223
KStaticDeleter
KateCmdShellCompletion::makeCompletion
TQString makeCompletion(const TQString &text)
Finds completions to the given text.
Definition: katecmd.cpp:134
Kate::Command
Kate Commands.
Definition: document.h:97
Kate::Command::cmds
virtual TQStringList cmds()=0
Pure text start part of the commands which can be handled by this object which means i....
TDECompletionMatches
TDECompletion
TDECompletion::match
void match(const TQString &item)
TDECompletion::makeCompletion
virtual TQString makeCompletion(const TQString &string)
TDECompletion::matches
void matches(const TQStringList &matchlist)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.