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