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

tdecore

  • tdecore
kcompletion.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999,2000,2001 Carsten Pfeiffer <pfeiffer@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 as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 
21 #include <tdeapplication.h>
22 #include <kdebug.h>
23 #include <tdelocale.h>
24 #include <knotifyclient.h>
25 #include <tdeglobal.h>
26 
27 #include <tqptrvector.h>
28 
29 #include "kcompletion.h"
30 #include "kcompletion_private.h"
31 
32 
33 class TDECompletionPrivate
34 {
35 public:
36  // not a member to avoid #including kcompletion_private.h from kcompletion.h
37  // list used for nextMatch() and previousMatch()
38  TDECompletionMatchesWrapper matches;
39 };
40 
41 TDECompletion::TDECompletion()
42 {
43  d = new TDECompletionPrivate;
44 
45  myCompletionMode = TDEGlobalSettings::completionMode();
46  myTreeRoot = new TDECompTreeNode;
47  myBeep = true;
48  myIgnoreCase = false;
49  myHasMultipleMatches = false;
50  myRotationIndex = 0;
51  setOrder( Insertion );
52 }
53 
54 TDECompletion::~TDECompletion()
55 {
56  delete d;
57  delete myTreeRoot;
58 }
59 
60 void TDECompletion::setOrder( CompOrder order )
61 {
62  myOrder = order;
63  d->matches.setSorting( order == Weighted );
64 }
65 
66 void TDECompletion::setIgnoreCase( bool ignoreCase )
67 {
68  myIgnoreCase = ignoreCase;
69 }
70 
71 void TDECompletion::setItems( const TQStringList& items )
72 {
73  clear();
74  insertItems( items );
75 }
76 
77 
78 void TDECompletion::insertItems( const TQStringList& items )
79 {
80  bool weighted = (myOrder == Weighted);
81  TQStringList::ConstIterator it;
82  if ( weighted ) { // determine weight
83  for ( it = items.begin(); it != items.end(); ++it )
84  addWeightedItem( *it );
85  }
86  else {
87  for ( it = items.begin(); it != items.end(); ++it )
88  addItem( *it, 0 );
89  }
90 }
91 
92 TQStringList TDECompletion::items() const
93 {
94  TDECompletionMatchesWrapper list; // unsorted
95  bool addWeight = (myOrder == Weighted);
96  extractStringsFromNode( myTreeRoot, TQString::null, &list, addWeight );
97 
98  return list.list();
99 }
100 
101 bool TDECompletion::isEmpty() const
102 {
103  return (myTreeRoot->childrenCount() == 0);
104 }
105 
106 void TDECompletion::addItem( const TQString& item )
107 {
108  d->matches.clear();
109  myRotationIndex = 0;
110  myLastString = TQString::null;
111 
112  addItem( item, 0 );
113 }
114 
115 void TDECompletion::addItem( const TQString& item, uint weight )
116 {
117  if ( item.isEmpty() )
118  return;
119 
120  TDECompTreeNode *node = myTreeRoot;
121  uint len = item.length();
122 
123  bool sorted = (myOrder == Sorted);
124  bool weighted = ((myOrder == Weighted) && weight > 1);
125 
126  // knowing the weight of an item, we simply add this weight to all of its
127  // nodes.
128 
129  for ( uint i = 0; i < len; i++ ) {
130  node = node->insert( item.at(i), sorted );
131  if ( weighted )
132  node->confirm( weight -1 ); // node->insert() sets weighting to 1
133  }
134 
135  // add 0x0-item as delimiter with evtl. weight
136  node = node->insert( 0x0, true );
137  if ( weighted )
138  node->confirm( weight -1 );
139 // tqDebug("*** added: %s (%i)", item.latin1(), node->weight());
140 }
141 
142 void TDECompletion::addWeightedItem( const TQString& item )
143 {
144  if ( myOrder != Weighted ) {
145  addItem( item, 0 );
146  return;
147  }
148 
149  uint len = item.length();
150  uint weight = 0;
151 
152  // find out the weighting of this item (appended to the string as ":num")
153  int index = item.findRev(':');
154  if ( index > 0 ) {
155  bool ok;
156  weight = item.mid( index + 1 ).toUInt( &ok );
157  if ( !ok )
158  weight = 0;
159 
160  len = index; // only insert until the ':'
161  }
162 
163  addItem( item.left( len ), weight );
164  return;
165 }
166 
167 
168 void TDECompletion::removeItem( const TQString& item )
169 {
170  d->matches.clear();
171  myRotationIndex = 0;
172  myLastString = TQString::null;
173 
174  myTreeRoot->remove( item );
175 }
176 
177 
178 void TDECompletion::clear()
179 {
180  d->matches.clear();
181  myRotationIndex = 0;
182  myLastString = TQString::null;
183 
184  delete myTreeRoot;
185  myTreeRoot = new TDECompTreeNode;
186 }
187 
188 
189 TQString TDECompletion::makeCompletion( const TQString& string )
190 {
191  if ( myCompletionMode == TDEGlobalSettings::CompletionNone )
192  return TQString::null;
193 
194  //kdDebug(0) << "TDECompletion: completing: " << string << endl;
195 
196  d->matches.clear();
197  myRotationIndex = 0;
198  myHasMultipleMatches = false;
199  myLastMatch = myCurrentMatch;
200 
201  // in Shell-completion-mode, emit all matches when we get the same
202  // complete-string twice
203  if ( myCompletionMode == TDEGlobalSettings::CompletionShell &&
204  string == myLastString ) {
205  // Don't use d->matches since calling postProcessMatches()
206  // on d->matches here would interfere with call to
207  // postProcessMatch() during rotation
208 
209  findAllCompletions( string, &d->matches, myHasMultipleMatches );
210  TQStringList l = d->matches.list();
211  postProcessMatches( &l );
212  emit matches( l );
213 
214  if ( l.isEmpty() )
215  doBeep( NoMatch );
216 
217  return TQString::null;
218  }
219 
220  TQString completion;
221  // in case-insensitive popup mode, we search all completions at once
222  if ( myCompletionMode == TDEGlobalSettings::CompletionPopup ||
223  myCompletionMode == TDEGlobalSettings::CompletionPopupAuto ) {
224  findAllCompletions( string, &d->matches, myHasMultipleMatches );
225  if ( !d->matches.isEmpty() )
226  completion = d->matches.first();
227  }
228  else
229  completion = findCompletion( string );
230 
231  if ( myHasMultipleMatches )
232  emit multipleMatches();
233 
234  myLastString = string;
235  myCurrentMatch = completion;
236 
237  postProcessMatch( &completion );
238 
239  if ( !string.isEmpty() ) { // only emit match when string is not empty
240  //kdDebug(0) << "TDECompletion: Match: " << completion << endl;
241  emit match( completion );
242  }
243 
244  if ( completion.isNull() )
245  doBeep( NoMatch );
246 
247  return completion;
248 }
249 
250 
251 TQStringList TDECompletion::substringCompletion( const TQString& string ) const
252 {
253  // get all items in the tree, possibly in sorted order
254  bool sorted = (myOrder == Weighted);
255  TDECompletionMatchesWrapper allItems( sorted );
256  extractStringsFromNode( myTreeRoot, TQString::null, &allItems, false );
257 
258  TQStringList list = allItems.list();
259 
260  // subStringMatches is invoked manually, via a shortcut, so we should
261  // beep here, if necessary.
262  if ( list.isEmpty() ) {
263  doBeep( NoMatch );
264  return list;
265  }
266 
267  if ( string.isEmpty() ) { // shortcut
268  postProcessMatches( &list );
269  return list;
270  }
271 
272  TQStringList matches;
273  TQStringList::ConstIterator it = list.begin();
274 
275  for( ; it != list.end(); ++it ) {
276  TQString item = *it;
277  if ( item.find( string, 0, false ) != -1 ) { // always case insensitive
278  matches.append( item );
279  }
280  }
281 
282  postProcessMatches( &matches );
283 
284  if ( matches.isEmpty() )
285  doBeep( NoMatch );
286 
287  return matches;
288 }
289 
290 
291 void TDECompletion::setCompletionMode( TDEGlobalSettings::Completion mode )
292 {
293  myCompletionMode = mode;
294 }
295 
296 TQStringList TDECompletion::allMatches()
297 {
298  // Don't use d->matches since calling postProcessMatches()
299  // on d->matches here would interfere with call to
300  // postProcessMatch() during rotation
301  TDECompletionMatchesWrapper matches( myOrder == Weighted );
302  bool dummy;
303  findAllCompletions( myLastString, &matches, dummy );
304  TQStringList l = matches.list();
305  postProcessMatches( &l );
306  return l;
307 }
308 
309 TDECompletionMatches TDECompletion::allWeightedMatches()
310 {
311  // Don't use d->matches since calling postProcessMatches()
312  // on d->matches here would interfere with call to
313  // postProcessMatch() during rotation
314  TDECompletionMatchesWrapper matches( myOrder == Weighted );
315  bool dummy;
316  findAllCompletions( myLastString, &matches, dummy );
317  TDECompletionMatches ret( matches );
318  postProcessMatches( &ret );
319  return ret;
320 }
321 
322 TQStringList TDECompletion::allMatches( const TQString &string )
323 {
324  TDECompletionMatchesWrapper matches( myOrder == Weighted );
325  bool dummy;
326  findAllCompletions( string, &matches, dummy );
327  TQStringList l = matches.list();
328  postProcessMatches( &l );
329  return l;
330 }
331 
332 TDECompletionMatches TDECompletion::allWeightedMatches( const TQString &string )
333 {
334  TDECompletionMatchesWrapper matches( myOrder == Weighted );
335  bool dummy;
336  findAllCompletions( string, &matches, dummy );
337  TDECompletionMatches ret( matches );
338  postProcessMatches( &ret );
339  return ret;
340 }
341 
344 
345 
346 TQString TDECompletion::nextMatch()
347 {
348  TQString completion;
349  myLastMatch = myCurrentMatch;
350 
351  if ( d->matches.isEmpty() ) {
352  findAllCompletions( myLastString, &d->matches, myHasMultipleMatches );
353  completion = d->matches.first();
354  myCurrentMatch = completion;
355  myRotationIndex = 0;
356  postProcessMatch( &completion );
357  emit match( completion );
358  return completion;
359  }
360 
361  TQStringList matches = d->matches.list();
362  myLastMatch = matches[ myRotationIndex++ ];
363 
364  if ( myRotationIndex == matches.count() -1 )
365  doBeep( Rotation ); // indicate last matching item -> rotating
366 
367  else if ( myRotationIndex == matches.count() )
368  myRotationIndex = 0;
369 
370  completion = matches[ myRotationIndex ];
371  myCurrentMatch = completion;
372  postProcessMatch( &completion );
373  emit match( completion );
374  return completion;
375 }
376 
377 
378 
379 TQString TDECompletion::previousMatch()
380 {
381  TQString completion;
382  myLastMatch = myCurrentMatch;
383 
384  if ( d->matches.isEmpty() ) {
385  findAllCompletions( myLastString, &d->matches, myHasMultipleMatches );
386  completion = d->matches.last();
387  myCurrentMatch = completion;
388  myRotationIndex = 0;
389  postProcessMatch( &completion );
390  emit match( completion );
391  return completion;
392  }
393 
394  TQStringList matches = d->matches.list();
395  myLastMatch = matches[ myRotationIndex ];
396  if ( myRotationIndex == 1 )
397  doBeep( Rotation ); // indicate first item -> rotating
398 
399  else if ( myRotationIndex == 0 )
400  myRotationIndex = matches.count();
401 
402  myRotationIndex--;
403 
404  completion = matches[ myRotationIndex ];
405  myCurrentMatch = completion;
406  postProcessMatch( &completion );
407  emit match( completion );
408  return completion;
409 }
410 
411 
412 
413 // tries to complete "string" from the tree-root
414 TQString TDECompletion::findCompletion( const TQString& string )
415 {
416  TQChar ch;
417  TQString completion;
418  const TDECompTreeNode *node = myTreeRoot;
419 
420  // start at the tree-root and try to find the search-string
421  for( uint i = 0; i < string.length(); i++ ) {
422  ch = string.at( i );
423  node = node->find( ch );
424 
425  if ( node )
426  completion += ch;
427  else
428  return TQString::null; // no completion
429  }
430 
431  // Now we have the last node of the to be completed string.
432  // Follow it as long as it has exactly one child (= longest possible
433  // completion)
434 
435  while ( node->childrenCount() == 1 ) {
436  node = node->firstChild();
437  if ( !node->isNull() )
438  completion += *node;
439  }
440  // if multiple matches and auto-completion mode
441  // -> find the first complete match
442  if ( node && node->childrenCount() > 1 ) {
443  myHasMultipleMatches = true;
444 
445  if ( myCompletionMode == TDEGlobalSettings::CompletionAuto ) {
446  myRotationIndex = 1;
447  if (myOrder != Weighted) {
448  while ( (node = node->firstChild()) ) {
449  if ( !node->isNull() )
450  completion += *node;
451  else
452  break;
453  }
454  }
455  else {
456  // don't just find the "first" match, but the one with the
457  // highest priority
458 
459  const TDECompTreeNode* temp_node = 0L;
460  while(1) {
461  int count = node->childrenCount();
462  temp_node = node->firstChild();
463  uint weight = temp_node->weight();
464  const TDECompTreeNode* hit = temp_node;
465  for( int i = 1; i < count; i++ ) {
466  temp_node = node->childAt(i);
467  if( temp_node->weight() > weight ) {
468  hit = temp_node;
469  weight = hit->weight();
470  }
471  }
472  // 0x0 has the highest priority -> we have the best match
473  if ( hit->isNull() )
474  break;
475 
476  node = hit;
477  completion += *node;
478  }
479  }
480  }
481 
482  else
483  doBeep( PartialMatch ); // partial match -> beep
484  }
485 
486  return completion;
487 }
488 
489 
490 void TDECompletion::findAllCompletions(const TQString& string,
491  TDECompletionMatchesWrapper *matches,
492  bool& hasMultipleMatches) const
493 {
494  //kdDebug(0) << "*** finding all completions for " << string << endl;
495 
496  if ( string.isEmpty() )
497  return;
498 
499  if ( myIgnoreCase ) { // case insensitive completion
500  extractStringsFromNodeCI( myTreeRoot, TQString::null, string, matches );
501  hasMultipleMatches = (matches->count() > 1);
502  return;
503  }
504 
505  TQChar ch;
506  TQString completion;
507  const TDECompTreeNode *node = myTreeRoot;
508 
509  // start at the tree-root and try to find the search-string
510  for( uint i = 0; i < string.length(); i++ ) {
511  ch = string.at( i );
512  node = node->find( ch );
513 
514  if ( node )
515  completion += ch;
516  else
517  return; // no completion -> return empty list
518  }
519 
520  // Now we have the last node of the to be completed string.
521  // Follow it as long as it has exactly one child (= longest possible
522  // completion)
523 
524  while ( node->childrenCount() == 1 ) {
525  node = node->firstChild();
526  if ( !node->isNull() )
527  completion += *node;
528  // kdDebug() << completion << node->latin1();
529  }
530 
531 
532  // there is just one single match)
533  if ( node->childrenCount() == 0 )
534  matches->append( node->weight(), completion );
535 
536  else {
537  // node has more than one child
538  // -> recursively find all remaining completions
539  hasMultipleMatches = true;
540  extractStringsFromNode( node, completion, matches );
541  }
542 }
543 
544 
545 void TDECompletion::extractStringsFromNode( const TDECompTreeNode *node,
546  const TQString& beginning,
547  TDECompletionMatchesWrapper *matches,
548  bool addWeight ) const
549 {
550  if ( !node || !matches )
551  return;
552 
553  // kDebug() << "Beginning: " << beginning << endl;
554  const TDECompTreeChildren *list = node->children();
555  TQString string;
556  TQString w;
557 
558  // loop thru all children
559  for ( TDECompTreeNode *cur = list->begin(); cur ; cur = cur->next) {
560  string = beginning;
561  node = cur;
562  if ( !node->isNull() )
563  string += *node;
564 
565  while ( node && node->childrenCount() == 1 ) {
566  node = node->firstChild();
567  if ( node->isNull() )
568  break;
569  string += *node;
570  }
571 
572  if ( node && node->isNull() ) { // we found a leaf
573  if ( addWeight ) {
574  // add ":num" to the string to store the weighting
575  string += ':';
576  w.setNum( node->weight() );
577  string.append( w );
578  }
579  matches->append( node->weight(), string );
580  }
581 
582  // recursively find all other strings.
583  if ( node && node->childrenCount() > 1 )
584  extractStringsFromNode( node, string, matches, addWeight );
585  }
586 }
587 
588 void TDECompletion::extractStringsFromNodeCI( const TDECompTreeNode *node,
589  const TQString& beginning,
590  const TQString& restString,
591  TDECompletionMatchesWrapper *matches ) const
592 {
593  if ( restString.isEmpty() ) {
594  extractStringsFromNode( node, beginning, matches, false /*noweight*/ );
595  return;
596  }
597 
598  TQChar ch1 = restString.at(0);
599  TQString newRest = restString.mid(1);
600  TDECompTreeNode *child1, *child2;
601 
602  child1 = node->find( ch1 ); // the correct match
603  if ( child1 )
604  extractStringsFromNodeCI( child1, beginning + *child1, newRest,
605  matches );
606 
607  // append the case insensitive matches, if available
608  if ( ch1.isLetter() ) {
609  // find out if we have to lower or upper it. Is there a better way?
610  TQChar ch2 = ch1.lower();
611  if ( ch1 == ch2 )
612  ch2 = ch1.upper();
613  if ( ch1 != ch2 ) {
614  child2 = node->find( ch2 );
615  if ( child2 )
616  extractStringsFromNodeCI( child2, beginning + *child2, newRest,
617  matches );
618  }
619  }
620 }
621 
622 void TDECompletion::doBeep( BeepMode mode ) const
623 {
624  if ( !myBeep )
625  return;
626 
627  TQString text, event;
628 
629  switch ( mode ) {
630  case Rotation:
631  event = TQString::fromLatin1("Textcompletion: rotation");
632  text = i18n("You reached the end of the list\nof matching items.\n");
633  break;
634  case PartialMatch:
635  if ( myCompletionMode == TDEGlobalSettings::CompletionShell ||
636  myCompletionMode == TDEGlobalSettings::CompletionMan ) {
637  event = TQString::fromLatin1("Textcompletion: partial match");
638  text = i18n("The completion is ambiguous, more than one\nmatch is available.\n");
639  }
640  break;
641  case NoMatch:
642  if ( myCompletionMode == TDEGlobalSettings::CompletionShell ) {
643  event = TQString::fromLatin1("Textcompletion: no match");
644  text = i18n("There is no matching item available.\n");
645  }
646  break;
647  }
648 
649  if ( !text.isEmpty() )
650  KNotifyClient::event( event, text );
651 }
652 
653 
656 
657 
658 // Implements the tree. Every node is a TQChar and has a list of children, which
659 // are Nodes as well.
660 // TQChar( 0x0 ) is used as the delimiter of a string; the last child of each
661 // inserted string is 0x0.
662 
663 TDECompTreeNode::~TDECompTreeNode()
664 {
665  // delete all children
666  TDECompTreeNode *cur = myChildren.begin();
667  while (cur) {
668  TDECompTreeNode * next = cur->next;
669  delete myChildren.remove(cur);
670  cur = next;
671  }
672 }
673 
674 
675 // Adds a child-node "ch" to this node. If such a node is already existant,
676 // it will not be created. Returns the new/existing node.
677 TDECompTreeNode * TDECompTreeNode::insert( const TQChar& ch, bool sorted )
678 {
679  TDECompTreeNode *child = find( ch );
680  if ( !child ) {
681  child = new TDECompTreeNode( ch );
682 
683  // FIXME, first (slow) sorted insertion implementation
684  if ( sorted ) {
685  TDECompTreeNode * prev = 0;
686  TDECompTreeNode * cur = myChildren.begin();
687  while ( cur ) {
688  if ( ch > *cur ) {
689  prev = cur;
690  cur = cur->next;
691  } else
692  break;
693  }
694  if (prev)
695  myChildren.insert( prev, child );
696  else
697  myChildren.prepend(child);
698  }
699 
700  else
701  myChildren.append( child );
702  }
703 
704  // implicit weighting: the more often an item is inserted, the higher
705  // priority it gets.
706  child->confirm();
707 
708  return child;
709 }
710 
711 
712 // Iteratively removes a string from the tree. The nicer recursive
713 // version apparently was a little memory hungry (see #56757)
714 void TDECompTreeNode::remove( const TQString& str )
715 {
716  TQString string = str;
717  string += TQChar(0x0);
718 
719  TQPtrVector<TDECompTreeNode> deletables( string.length() + 1 );
720 
721  TDECompTreeNode *child = 0L;
722  TDECompTreeNode *parent = this;
723  deletables.insert( 0, parent );
724 
725  uint i = 0;
726  for ( ; i < string.length(); i++ )
727  {
728  child = parent->find( string.at( i ) );
729  if ( child )
730  deletables.insert( i + 1, child );
731  else
732  break;
733 
734  parent = child;
735  }
736 
737  for ( ; i >= 1; i-- )
738  {
739  parent = deletables.at( i - 1 );
740  child = deletables.at( i );
741  if ( child->myChildren.count() == 0 )
742  delete parent->myChildren.remove( child );
743  }
744 }
745 
746 TQStringList TDECompletionMatchesWrapper::list() const
747 {
748  if ( sortedList && dirty ) {
749  sortedList->sort();
750  dirty = false;
751 
752  stringList.clear();
753 
754  // high weight == sorted last -> reverse the sorting here
755  TQValueListConstIterator<KSortableItem<TQString> > it;
756  for ( it = sortedList->begin(); it != sortedList->end(); ++it )
757  stringList.prepend( (*it).value() );
758  }
759 
760  return stringList;
761 }
762 
763 TDECompletionMatches::TDECompletionMatches( bool sort_P )
764  : _sorting( sort_P )
765 {
766 }
767 
768 TDECompletionMatches::TDECompletionMatches( const TDECompletionMatchesWrapper& matches )
769  : _sorting( matches.sorting())
770 {
771  if( matches.sortedList != 0L )
772  TDECompletionMatchesList::operator=( *matches.sortedList );
773  else {
774  TQStringList l = matches.list();
775  for( TQStringList::ConstIterator it = l.begin();
776  it != l.end();
777  ++it )
778  prepend( KSortableItem<TQString, int>( 1, *it ) );
779  }
780 }
781 
782 TDECompletionMatches::~TDECompletionMatches()
783 {
784 }
785 
786 TQStringList TDECompletionMatches::list( bool sort_P ) const
787 {
788  if( _sorting && sort_P )
789  const_cast< TDECompletionMatches* >( this )->sort();
790  TQStringList stringList;
791  // high weight == sorted last -> reverse the sorting here
792  for ( ConstIterator it = begin(); it != end(); ++it )
793  stringList.prepend( (*it).value() );
794  return stringList;
795 }
796 
797 void TDECompletionMatches::removeDuplicates()
798 {
799  Iterator it1, it2;
800  for ( it1 = begin(); it1 != end(); ++it1 ) {
801  for ( (it2 = it1), ++it2; it2 != end();) {
802  if( (*it1).value() == (*it2).value()) {
803  // use the max height
804  (*it1).first = kMax( (*it1).index(), (*it2).index());
805  it2 = remove( it2 );
806  continue;
807  }
808  ++it2;
809  }
810  }
811 }
812 
813 void TDECompTreeNodeList::append(TDECompTreeNode *item)
814 {
815  m_count++;
816  if (!last) {
817  last = item;
818  last->next = 0;
819  first = item;
820  return;
821  }
822  last->next = item;
823  item->next = 0;
824  last = item;
825 }
826 
827 void TDECompTreeNodeList::prepend(TDECompTreeNode *item)
828 {
829  m_count++;
830  if (!last) {
831  last = item;
832  last->next = 0;
833  first = item;
834  return;
835  }
836  item->next = first;
837  first = item;
838 }
839 
840 void TDECompTreeNodeList::insert(TDECompTreeNode *after, TDECompTreeNode *item)
841 {
842  if (!after) {
843  append(item);
844  return;
845  }
846 
847  m_count++;
848 
849  item->next = after->next;
850  after->next = item;
851 
852  if (after == last)
853  last = item;
854 }
855 
856 TDECompTreeNode *TDECompTreeNodeList::remove(TDECompTreeNode *item)
857 {
858  if (!first || !item)
859  return 0;
860  TDECompTreeNode *cur = 0;
861 
862  if (item == first)
863  first = first->next;
864  else {
865  cur = first;
866  while (cur && cur->next != item) cur = cur->next;
867  if (!cur)
868  return 0;
869  cur->next = item->next;
870  }
871  if (item == last)
872  last = cur;
873  m_count--;
874  return item;
875 }
876 
877 TDECompTreeNode *TDECompTreeNodeList::at(uint index) const
878 {
879  TDECompTreeNode *cur = first;
880  while (index-- && cur) cur = cur->next;
881  return cur;
882 }
883 
884 TDEZoneAllocator TDECompTreeNode::alloc(8192);
885 
886 void TDECompletion::virtual_hook( int, void* )
887 { /*BASE::virtual_hook( id, data );*/ }
888 
889 void TDECompletionBase::virtual_hook( int, void* )
890 { /*BASE::virtual_hook( id, data );*/ }
891 
892 #include "kcompletion.moc"
KSortableItem
KSortableItem is a TQPair that provides several operators for sorting.
Definition: ksortablevaluelist.h:33
KSortableValueList::sort
void sort()
Sorts the KSortableItems.
Definition: ksortablevaluelist.h:162
TDECompTreeNode
A helper class for TDECompletion.
Definition: kcompletion_private.h:85
TDECompletionMatches
This structure is returned by TDECompletion::allWeightedMatches .
Definition: kcompletion.h:616
TDECompletionMatches::list
TQStringList list(bool sort=true) const
Returns the matches as a TQStringList.
Definition: kcompletion.cpp:786
TDECompletionMatches::removeDuplicates
void removeDuplicates()
Removes duplicate matches.
Definition: kcompletion.cpp:797
TDECompletion::substringCompletion
TQStringList substringCompletion(const TQString &string) const
Returns a list of all completion items that contain the given string.
Definition: kcompletion.cpp:251
TDECompletion::hasMultipleMatches
bool hasMultipleMatches() const
Returns true when more than one match is found.
Definition: kcompletion.h:384
TDECompletion::previousMatch
TQString previousMatch()
Returns the next item from the matching-items-list.
Definition: kcompletion.cpp:379
TDECompletion::setOrder
virtual void setOrder(CompOrder order)
TDECompletion offers three different ways in which it offers its items:
Definition: kcompletion.cpp:60
TDECompletion::isEmpty
bool isEmpty() const
Returns true when the completion object contains no entries.
Definition: kcompletion.cpp:101
TDECompletion::removeItem
void removeItem(const TQString &item)
Removes an item from the list of available completions.
Definition: kcompletion.cpp:168
TDECompletion::items
TQStringList items() const
Returns a list of all items inserted into TDECompletion.
Definition: kcompletion.cpp:92
TDECompletion::allMatches
TQStringList allMatches()
Returns a list of all items matching the last completed string.
Definition: kcompletion.cpp:296
TDECompletion::setCompletionMode
virtual void setCompletionMode(TDEGlobalSettings::Completion mode)
Sets the completion mode to Auto/Manual, Shell or None.
Definition: kcompletion.cpp:291
TDECompletion::match
void match(const TQString &item)
The matching item.
TDECompletion::setItems
virtual void setItems(const TQStringList &list)
Sets the list of items available for completion.
Definition: kcompletion.cpp:71
TDECompletion::~TDECompletion
virtual ~TDECompletion()
Destructor, nothing special here, either.
Definition: kcompletion.cpp:54
TDECompletion::multipleMatches
void multipleMatches()
This signal is emitted, when calling makeCompletion() and more than one matching item is found.
TDECompletion::postProcessMatch
virtual void postProcessMatch(TQString *match) const
This method is called after a completion is found and before the matching string is emitted.
Definition: kcompletion.h:528
TDECompletion::postProcessMatches
virtual void postProcessMatches(TQStringList *matches) const
This method is called before a list of all available completions is emitted via matches.
Definition: kcompletion.h:540
TDECompletion::makeCompletion
virtual TQString makeCompletion(const TQString &string)
Attempts to find an item in the list of available completions, that begins with string.
Definition: kcompletion.cpp:189
TDECompletion::CompOrder
CompOrder
Constants that represent the order in which TDECompletion performs completion-lookups.
Definition: kcompletion.h:145
TDECompletion::Insertion
@ Insertion
Use order of insertion.
Definition: kcompletion.h:146
TDECompletion::Weighted
@ Weighted
Use weighted order.
Definition: kcompletion.h:147
TDECompletion::Sorted
@ Sorted
Use alphabetically sorted order.
Definition: kcompletion.h:145
TDECompletion::nextMatch
TQString nextMatch()
Returns the next item from the matching-items-list.
Definition: kcompletion.cpp:346
TDECompletion::order
CompOrder order() const
Returns the completion order.
Definition: kcompletion.h:300
TDECompletion::setIgnoreCase
virtual void setIgnoreCase(bool ignoreCase)
Setting this to true makes TDECompletion behave case insensitively.
Definition: kcompletion.cpp:66
TDECompletion::clear
virtual void clear()
Removes all inserted items.
Definition: kcompletion.cpp:178
TDECompletion::insertItems
void insertItems(const TQStringList &items)
Inserts items into the list of possible completions.
Definition: kcompletion.cpp:78
TDECompletion::TDECompletion
TDECompletion()
Constructor, nothing special here :)
Definition: kcompletion.cpp:41
TDECompletion::allWeightedMatches
TDECompletionMatches allWeightedMatches()
Returns a list of all items matching the last completed string.
Definition: kcompletion.cpp:309
TDECompletion::addItem
void addItem(const TQString &item)
Adds an item to the list of available completions.
Definition: kcompletion.cpp:106
TDECompletion::matches
void matches(const TQStringList &matchlist)
All matching items.
TDECompletion::ignoreCase
bool ignoreCase() const
Return whether TDECompletion acts case insensitively or not.
Definition: kcompletion.h:317
TDEGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the TDECompletion class.
Definition: tdeglobalsettings.h:178
TDEGlobalSettings::CompletionNone
@ CompletionNone
No completion is used.
Definition: tdeglobalsettings.h:182
TDEGlobalSettings::CompletionShell
@ CompletionShell
Complete text much in the same way as a typical *nix shell would.
Definition: tdeglobalsettings.h:194
TDEGlobalSettings::CompletionAuto
@ CompletionAuto
Text is automatically filled in whenever possible.
Definition: tdeglobalsettings.h:186
TDEGlobalSettings::CompletionPopup
@ CompletionPopup
Lists all possible matches in a popup list-box to choose from.
Definition: tdeglobalsettings.h:198
TDEGlobalSettings::CompletionMan
@ CompletionMan
Same as automatic except shortest match is used for completion.
Definition: tdeglobalsettings.h:190
TDEGlobalSettings::CompletionPopupAuto
@ CompletionPopupAuto
Lists all possible matches in a popup list-box to choose from, and automatically fill the result when...
Definition: tdeglobalsettings.h:203
TDEGlobalSettings::completionMode
static Completion completionMode()
Returns the preferred completion mode setting.
Definition: tdeglobalsettings.cpp:283
TDEShortcut::isNull
bool isNull() const
Returns true if the shortcut is null (after clear() or empty constructor).
Definition: tdeshortcut.cpp:517
TDEZoneAllocator
Memory allocator for large groups of small objects.
Definition: kallocator.h:47
KNotifyClient::event
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
Definition: knotifyclient.cpp:125
KStdAction::next
TDEAction * next(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEStdAccel::completion
const TDEShortcut & completion()
Complete text in input widgets.
Definition: tdestdaccel.cpp:304
tdelocale.h

tdecore

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

tdecore

Skip menu "tdecore"
  • 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 tdecore by doxygen 1.9.1
This website is maintained by Timothy Pearson.