KDevelop API Documentation

qeditor_view.cpp

Go to the documentation of this file.
00001 /* $Id: qeditor_view.cpp,v 1.51 2004/03/04 05:20:42 cunz Exp $
00002  *
00003  *  Copyright (C) 2001 Roberto Raggi (roberto@kdevelop.org)
00004  *
00005  *  This program is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  *  Boston, MA 02111-1307, USA.
00019  *
00020  */
00021 
00029 #include "qeditor_view.h"
00030 #include "qeditor_part.h"
00031 #include "qeditor_settings.h"
00032 #include "qeditor_factory.h"
00033 #include "qeditor.h"
00034 #include "paragdata.h"
00035 #include "qeditorcodecompletion.h"
00036 #include "linenumberwidget.h"
00037 #include "markerwidget.h"
00038 #include "levelwidget.h"
00039 #include "gotolinedialog.h"
00040 #include "koFind.h"
00041 #include "koReplace.h"
00042 #include "qeditor_texthint.h"
00043 
00044 #include <qregexp.h>
00045 #include <qlayout.h>
00046 #include <qpopupmenu.h>
00047 #include <private/qrichtext_p.h>
00048 
00049 #include <kdebug.h>
00050 #include <kaction.h>
00051 #include <klocale.h>
00052 #include <kapplication.h>
00053 #include <kcombobox.h>
00054 #include <kdeversion.h>
00055 
00056 #include "kdevkstdaction.h"
00057 
00058 QEditorView::QEditorView( QEditorPart* document, QWidget* parent, const char* name )
00059     : KTextEditor::View( document, parent, name ),
00060       m_document( document ), m_textHintToolTip( 0 )
00061 {
00062     setInstance( QEditorPartFactory::instance() );
00063 
00064     QEditorPartFactory::registerView( this );
00065     m_findDialog = new KoFindDialog( this, "FindDialog_0", long(KoFindDialog::FromCursor) );
00066     m_replaceDialog = new KoReplaceDialog( this, "ReplaceDialog_0",
00067                                            long(KoReplaceDialog::PromptOnReplace |
00068                                            KoReplaceDialog::FromCursor) );
00069     m_currentParag = 0;
00070     m_find = 0;
00071     m_replace = 0;
00072     m_options = 0;
00073     m_offset = 0;
00074 
00075     QHBoxLayout* lay = new QHBoxLayout( this );
00076 
00077     m_editor = new QEditor( this );
00078     m_lineNumberWidget = new LineNumberWidget( m_editor, this );
00079 
00080     m_markerWidget = new MarkerWidget( m_editor, this );
00081     connect( document, SIGNAL(marksChanged()),
00082              m_markerWidget, SLOT(doRepaint()) );
00083     connect( m_markerWidget, SIGNAL(markChanged(KTextEditor::Mark,KTextEditor::MarkInterfaceExtension::MarkChangeAction)),
00084              document, SIGNAL(markChanged(KTextEditor::Mark,KTextEditor::MarkInterfaceExtension::MarkChangeAction)) );
00085     connect( m_markerWidget, SIGNAL(marksChanged()), document, SIGNAL(marksChanged()) );
00086 
00087     m_levelWidget = new LevelWidget( m_editor, this );
00088     connect( m_levelWidget, SIGNAL(expandBlock(QTextParagraph*)),
00089          this, SLOT(expandBlock(QTextParagraph*)) );
00090     connect( m_levelWidget, SIGNAL(collapseBlock(QTextParagraph*)),
00091          this, SLOT(collapseBlock(QTextParagraph*)) );
00092 
00093     lay->addWidget( m_markerWidget );
00094     lay->addWidget( m_lineNumberWidget );
00095     lay->addWidget( m_levelWidget );
00096     lay->addWidget( m_editor );
00097 
00098     setFocusProxy( m_editor );
00099     connect( m_editor, SIGNAL(cursorPositionChanged(int, int)),
00100          this, SIGNAL(cursorPositionChanged()) );
00101 
00102     // connections
00103     connect( m_editor, SIGNAL(textChanged()),
00104              doc(), SIGNAL(textChanged()) );
00105     connect( doc(), SIGNAL(newStatus()),
00106              this, SIGNAL(newStatus()) );
00107     connect( m_editor, SIGNAL(selectionChanged()),
00108              doc(), SIGNAL(selectionChanged()) );
00109 
00110     connect( m_editor, SIGNAL(ensureTextIsVisible(QTextParagraph*)),
00111              this, SLOT(ensureTextIsVisible(QTextParagraph*)) );
00112 
00113     m_pCodeCompletion = new QEditorCodeCompletion( this );
00114     connect(m_pCodeCompletion,SIGNAL(completionAborted()),
00115         this,SIGNAL(completionAborted()));
00116     connect(m_pCodeCompletion,SIGNAL(completionDone()),
00117         this,SIGNAL(completionDone()));
00118     connect(m_pCodeCompletion,SIGNAL(argHintHidden()),
00119         this,SIGNAL(argHintHidden()));
00120     connect(m_pCodeCompletion,SIGNAL(completionDone(KTextEditor::CompletionEntry)),
00121         this,SIGNAL(completionDone(KTextEditor::CompletionEntry)));
00122     connect(m_pCodeCompletion,SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString *)),
00123         this,SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString *)) );
00124 
00125     // set our XML-UI resource file
00126     setXMLFile( "qeditor_part.rc" );
00127 
00128     setupActions();
00129 
00130     configChanged();
00131 
00132     //enableTextHints( 500 );
00133 }
00134 
00135 QEditorView::~QEditorView()
00136 {
00137     delete( m_pCodeCompletion );
00138     m_pCodeCompletion = 0;
00139     QEditorPartFactory::deregisterView( this );
00140 }
00141 
00142 void QEditorView::configChanged()
00143 {
00144     m_editor->configChanged();
00145 
00146     setMarkerWidgetVisible( QEditorSettings::self()->showMarkers() );
00147     setLineNumberWidgetVisible( QEditorSettings::self()->showLineNumber() );
00148     setLevelWidgetVisible( QEditorSettings::self()->showCodeFoldingMarkers() );
00149 }
00150 
00151 bool QEditorView::isMarkerWidgetVisible() const
00152 {
00153     return m_markerWidget->isVisible();
00154 }
00155 
00156 void QEditorView::setMarkerWidgetVisible( bool b )
00157 {
00158     if( b ){
00159     m_markerWidget->show();
00160     m_markerWidget->doRepaint();
00161     } else {
00162     m_markerWidget->hide();
00163     }
00164 }
00165 
00166 bool QEditorView::isLineNumberWidgetVisible() const
00167 {
00168     return m_lineNumberWidget->isVisible();
00169 }
00170 
00171 void QEditorView::setLineNumberWidgetVisible( bool b )
00172 {
00173     if( b ){
00174     m_lineNumberWidget->show();
00175     m_lineNumberWidget->doRepaint();
00176     } else {
00177     m_lineNumberWidget->hide();
00178     }
00179 }
00180 
00181 bool QEditorView::isLevelWidgetVisible() const
00182 {
00183     return m_levelWidget->isVisible();
00184 }
00185 
00186 void QEditorView::setLevelWidgetVisible( bool b )
00187 {
00188     if( b ){
00189     m_levelWidget->show();
00190     m_levelWidget->doRepaint();
00191     } else {
00192     m_levelWidget->hide();
00193     }
00194 }
00195 
00196 int QEditorView::tabStop() const
00197 {
00198     return m_editor->tabStop();
00199 }
00200 
00201 void QEditorView::setTabStop( int tabStop )
00202 {
00203     m_editor->setTabStop( tabStop );
00204 }
00205 
00206 KTextEditor::Document* QEditorView::document() const
00207 {
00208     return m_document;
00209 }
00210 
00211 QPoint QEditorView::cursorCoordinates()
00212 {
00213     QTextCursor *cursor = m_editor->textCursor();
00214     QTextStringChar *chr = cursor->paragraph()->at( cursor->index() );
00215     int h = cursor->paragraph()->lineHeightOfChar( cursor->index() );
00216     int x = cursor->paragraph()->rect().x() + chr->x;
00217     int y, dummy;
00218     cursor->paragraph()->lineHeightOfChar( cursor->index(), &dummy, &y );
00219     y += cursor->paragraph()->rect().y();
00220     return m_editor->contentsToViewport( QPoint( x, y+h ) );
00221 }
00222 
00223 void QEditorView::cursorPosition(unsigned int *line, unsigned int *col)
00224 {
00225     *line = cursorLine();
00226     *col = cursorColumn();
00227 }
00228 
00229 void QEditorView::cursorPositionReal(unsigned int *line, unsigned int *col)
00230 {
00231     *line = cursorLine();
00232     *col = cursorColumnReal();
00233 }
00234 
00235 bool QEditorView::setCursorPosition(unsigned int line, unsigned int col)
00236 {
00237 #warning "TODO: implement QEditorView::setCursorPosition"
00238     kdDebug(9032) << "TODO: implement QEditorView::setCursorPosition" << endl;
00239 
00240     QTextParagraph* p = m_editor->document()->paragAt( line );
00241     if (p)
00242         ensureTextIsVisible( p );
00243 
00244     m_editor->setCursorPosition( line, col );
00245     m_editor->ensureCursorVisible();
00246 
00247     return true;
00248 }
00249 
00250 bool QEditorView::setCursorPositionReal(unsigned int line, unsigned int col)
00251 {
00252     QTextParagraph* p = m_editor->document()->paragAt( line );
00253     if( p )
00254         ensureTextIsVisible( p );
00255 
00256     m_editor->setCursorPosition( line, col );
00257     m_editor->ensureCursorVisible();
00258     return true;
00259 }
00260 
00261 unsigned int QEditorView::cursorLine()
00262 {
00263     int line, col;
00264     m_editor->getCursorPosition( &line, &col );
00265     return line;
00266 }
00267 
00268 unsigned int QEditorView::cursorColumn()
00269 {
00270     const int tabwidth = 4;
00271     int line, col;
00272 
00273     m_editor->getCursorPosition( &line, &col );
00274     QString text = m_editor->text( line ).left( col );
00275     col = 0;
00276 
00277     for( uint i=0; i<text.length(); ++i ){
00278         if( text[ i ] == QChar('\t') ){
00279             col += tabwidth - (col % tabwidth);
00280         } else {
00281             ++col;
00282         }
00283     }
00284     return col;
00285 }
00286 
00287 unsigned int QEditorView::cursorColumnReal()
00288 {
00289     int line, col;
00290     m_editor->getCursorPosition( &line, &col );
00291     return col;
00292 }
00293 
00294 void QEditorView::copy( ) const
00295 {
00296     m_editor->copy();
00297 }
00298 
00299 void QEditorView::cut( )
00300 {
00301     m_editor->cut();
00302 }
00303 
00304 void QEditorView::paste( )
00305 {
00306     m_editor->paste();
00307 }
00308 
00309 void QEditorView::installPopup( QPopupMenu *rmb_Menu )
00310 {
00311     m_editor->setApplicationMenu( rmb_Menu );
00312 }
00313 
00314 void QEditorView::showArgHint(QStringList functionList,
00315                               const QString& strWrapping,
00316                               const QString& strDelimiter)
00317 {
00318     m_pCodeCompletion->showArgHint( functionList, strWrapping, strDelimiter );
00319 }
00320 
00321 void QEditorView::showCompletionBox(QValueList<KTextEditor::CompletionEntry> complList,
00322                                     int offset,
00323                                     bool casesensitive )
00324 {
00325     emit aboutToShowCompletionBox();
00326     m_pCodeCompletion->showCompletionBox( complList, offset, casesensitive );
00327 }
00328 
00329 QString QEditorView::currentTextLine() const
00330 {
00331     int line, col;
00332     m_editor->getCursorPosition( &line, &col );
00333     return m_editor->text( line );
00334 }
00335 
00336 void QEditorView::insertText( const QString& text )
00337 {
00338     m_editor->insert( text );
00339 }
00340 
00341 void QEditorView::setLanguage( const QString& language )
00342 {
00343     m_editor->setLanguage( language );
00344 }
00345 
00346 QString QEditorView::language() const
00347 {
00348     return m_editor->language();
00349 }
00350 
00351 void QEditorView::indent()
00352 {
00353     m_editor->indent();
00354 }
00355 
00356 void QEditorView::gotoLine()
00357 {
00358     GotoLineDialog dlg;
00359     dlg.setEditor( m_editor );
00360     dlg.exec();
00361 }
00362 
00363 void QEditorView::proceed()
00364 {
00365     // Start point
00366     QTextParagraph * firstParagraph = m_editor->document()->firstParagraph();
00367     int firstIndex = 0;
00368     QTextParagraph * startParagraph = firstParagraph;
00369     int startIndex = 0;
00370     QTextParagraph * lastParagraph;
00371     int lastIndex;
00372 
00373     // 'From Cursor' option
00374     QEditor* edit = m_editor;
00375     if ( edit && ( m_options & KoFindDialog::FromCursor ) )
00376     {
00377         startParagraph = edit->textCursor()->paragraph();
00378         startIndex = edit->textCursor()->index();
00379     } // no else here !
00380 
00381     bool forw = ! (m_options & KoFindDialog::FindBackwards);
00382 
00383     // 'Selected Text' option
00384     if ( edit && ( m_options & KoFindDialog::SelectedText ) )
00385     {
00386         QTextCursor c1 = edit->document()->selectionStartCursor( QTextDocument::Standard );
00387         firstParagraph = c1.paragraph();
00388         firstIndex = c1.index();
00389         QTextCursor c2 = edit->document()->selectionEndCursor( QTextDocument::Standard );
00390         lastParagraph = c2.paragraph();
00391         lastIndex = c2.index();
00392     }
00393     else // Not 'find in selection', need to iterate over the framesets
00394     {
00395         lastParagraph = edit->document()->lastParagraph();
00396         lastIndex = lastParagraph->length()-1;
00397     }
00398 
00399     bool bProceed = true;
00400     if (forw) {
00401         while (bProceed) { // loop until cancelled
00402             bProceed = find_real( startParagraph, startIndex, lastParagraph, lastIndex );
00403             if (bProceed) {
00404                 bProceed = find_real( firstParagraph, firstIndex, startParagraph, startIndex );
00405             }
00406             if (!m_editor->selectedText()) {
00407                 bProceed = false; // nothing found in the whole selection or file
00408             }
00409         }
00410     }
00411     else { // backwards
00412         while (bProceed) { // loop until cancelled
00413             bProceed = find_real( firstParagraph, firstIndex, startParagraph, startIndex );
00414             if (bProceed) {
00415                 bProceed = find_real( startParagraph, startIndex, lastParagraph, lastIndex );
00416             }
00417             if (!m_editor->selectedText()) {
00418                 bProceed = false; // nothing found in the whole selection or file
00419             }
00420         }
00421     }
00422 }
00423 
00424 bool QEditorView::find_real( QTextParagraph* firstParagraph, int firstIndex,
00425                              QTextParagraph* lastParagraph, int lastIndex )
00426 {
00427     Q_ASSERT( firstParagraph );
00428     Q_ASSERT( lastParagraph );
00429 
00430     m_currentParag = firstParagraph;
00431     m_offset = 0;
00432 
00433     if( firstParagraph == lastParagraph ){
00434         m_offset = firstIndex;
00435         return process( firstParagraph->string()->toString().mid( firstIndex, lastIndex-firstIndex ) );
00436     } else {
00437         bool forw = ! (m_options & KoFindDialog::FindBackwards);
00438         bool ret = true;
00439         if( forw ){
00440             m_offset = firstIndex;
00441             QString str = m_currentParag->string()->toString();
00442             ret = process( str.mid( firstIndex ) );
00443             if (!ret) return false;
00444         } else {
00445             m_currentParag = lastParagraph;
00446             ret = process( lastParagraph->string()->toString().left( lastIndex + 1 ) );
00447             if (!ret) return false;
00448         }
00449 
00450         m_currentParag = forw ? firstParagraph->next() : lastParagraph->prev();
00451         m_offset = 0;
00452         QTextParagraph* endParag = forw ? lastParagraph : firstParagraph;
00453         while( m_currentParag && m_currentParag != endParag ){
00454             QString str = m_currentParag->string()->toString();
00455             str = str.left( str.length() - 1 );
00456             ret = process( str );
00457 
00458             if (!ret) return false;
00459             m_currentParag = forw ? m_currentParag->next() : m_currentParag->prev();
00460         }
00461         Q_ASSERT( endParag == m_currentParag );
00462         if ( forw )
00463         {
00464             QString s = lastParagraph->string()->toString().left( lastIndex + 1 );
00465             ret = process( s );
00466         } else {
00467             m_offset = firstIndex;
00468             QString str = m_currentParag->string()->toString();
00469             str = str.mid( firstIndex );
00470             ret = process( str );
00471         }
00472         return ret;
00473     }
00474 }
00475 
00476 void QEditorView::doFind()
00477 {
00478     m_findDialog->m_find->setEditURL(KURL( m_editor->selectedText() ));
00479 
00480     if( m_findDialog->exec() ){
00481         m_options = m_findDialog->options();
00482         if ( m_find )
00483         {
00484             m_find->abort();
00485             delete m_find;
00486         }
00487         m_find = new KoFind( m_findDialog->pattern(), m_findDialog->options() );
00488         connect( m_find, SIGNAL(highlight(const QString&,int,int,const QRect&)),
00489                  this, SLOT(highlight(const QString&,int,int,const QRect&)) );
00490         proceed();
00491         delete m_find;
00492         m_find = 0;
00493     }
00494 }
00495 
00496 void QEditorView::doReplace()
00497 {
00498     m_replaceDialog->m_find->setEditURL(KURL( m_editor->selectedText() ));
00499 
00500     if( m_replaceDialog->exec() ){
00501         m_options = m_replaceDialog->options();
00502         if ( m_replace )
00503         {
00504             m_replace->abort();
00505             delete m_replace;
00506         }
00507         m_replace = new KoReplace( m_replaceDialog->pattern(), m_replaceDialog->replacement(),
00508                                    m_replaceDialog->options() );
00509         connect( m_replace, SIGNAL(highlight(const QString&,int,int,const QRect&)),
00510                  this, SLOT(highlight(const QString&,int,int,const QRect&)) );
00511         connect( m_replace, SIGNAL(replace(const QString&,int,int,int,const QRect&)),
00512                  this, SLOT(replace(const QString&,int,int,int,const QRect&)) );
00513         proceed();
00514         delete m_replace;
00515         m_replace = 0;
00516     }
00517 }
00518 
00519 bool QEditorView::process( const QString& _text )
00520 {
00521     if( m_find ){
00522         return m_find->find( _text, QRect() );
00523     } else if( m_replace ) {
00524         QString text( _text );
00525         return m_replace->replace( text, QRect() );
00526     }
00527     return false;
00528 }
00529 
00530 void QEditorView::highlight( const QString& /*text*/, int matchingIndex, int matchedLength, const QRect& )
00531 {
00532     m_editor->setSelection( m_currentParag->paragId(), matchingIndex,
00533                             m_currentParag->paragId(), matchingIndex + matchedLength );
00534 }
00535 
00536 void QEditorView::replace( const QString&, int matchingIndex,
00537                            int /*matchingLength*/, int matchedLength,
00538                            const QRect &/*expose*/ )
00539 {
00540     m_editor->setSelection( m_currentParag->paragId(), matchingIndex,
00541                             m_currentParag->paragId(), matchingIndex + matchedLength );
00542     m_editor->removeSelectedText();
00543     m_editor->insertAt( m_replaceDialog->replacement(),
00544                         m_currentParag->paragId(),
00545                         matchingIndex );
00546 }
00547 
00548 void QEditorView::ensureTextIsVisible( QTextParagraph* p)
00549 {
00550     internalEnsureVisibleBlock( p );
00551 
00552     m_editor->refresh();
00553     doRepaint();
00554 
00555     // some math
00556     QRect r = m_editor->paragraphRect(p->paragId());
00557     int y = r.y();
00558     int h = r.height();
00559     y = y + h/2;
00560     int cY = m_editor->contentsY();
00561     h = m_editor->viewport()->size().height();
00562 
00563     // if the paragraph is in the lower quarter of the viewport, center it
00564     if (y > (cY + (3*h)/4)) {
00565     m_editor->center(0, y);
00566     }
00567 }
00568 
00569 void QEditorView::internalEnsureVisibleBlock( QTextParagraph* p )
00570 {
00571     ParagData* data = (ParagData*) p->extraData();
00572 
00573     if( !data ){
00574         return;
00575     }
00576     int lev = data->level(), parentLevel;
00577 
00578     while( lev > 0 ){
00579         QTextParagraph* parent = p->prev();
00580 
00581         parentLevel = parent ? ((ParagData*) parent->extraData())->level() : 0;
00582 
00583         while( parentLevel > lev ){
00584             parent = parent->prev();
00585             parentLevel = ((ParagData*) parent->extraData())->level();
00586         }
00587         if( parentLevel < lev ){
00588             internalExpandBlock(p);
00589             lev = parentLevel;
00590         }
00591 
00592         p = parent;
00593     }
00594 }
00595 
00596 void QEditorView::internalExpandBlock( QTextParagraph* p )
00597 {
00598     ParagData* data = (ParagData*) p->extraData();
00599     if( !data ){
00600         return;
00601     }
00602     int lev = QMAX( data->level() - 1, 0 );
00603 
00604     data->setOpen( true );
00605 
00606     p = p->next();
00607     while( p ){
00608         ParagData* data = (ParagData*) p->extraData();
00609         if( data ){
00610             p->show();
00611             data->setOpen( true );
00612 
00613             if( data->level() == lev ){
00614                 break;
00615             }
00616             p = p->next();
00617         }
00618     }
00619 }
00620 
00621 void QEditorView::internalCollapseBlock( QTextParagraph* p )
00622 {
00623     ParagData* data = (ParagData*) p->extraData();
00624     if( !data ){
00625         return;
00626     }
00627 
00628     int lev = QMAX( data->level() - 1, 0 );
00629     data->setOpen( false );
00630 
00631     p = p->next();
00632     while( p ){
00633         ParagData* data = (ParagData*) p->extraData();
00634         if( data ){
00635 
00636             if( data->level() == lev ){
00637                 break;
00638             }
00639 
00640         // kdDebug(9032) << "hide parag " << p->paragId() << " level = " << data->level() << endl;
00641             p->hide();
00642 
00643             p = p->next();
00644         }
00645     }
00646 }
00647 
00648 void QEditorView::expandBlock( QTextParagraph* p )
00649 {
00650     internalExpandBlock( p );
00651 
00652     m_editor->setCursorPosition( p->paragId(), 0 );
00653     m_editor->refresh();
00654     doRepaint();
00655 }
00656 
00657 void QEditorView::collapseBlock( QTextParagraph* p )
00658 {
00659     internalCollapseBlock( p );
00660 
00661     m_editor->setCursorPosition( p->paragId(), 0 );
00662     m_editor->refresh();
00663     doRepaint();
00664 }
00665 
00666 void QEditorView::doRepaint()
00667 {
00668     m_markerWidget->doRepaint();
00669     m_lineNumberWidget->doRepaint();
00670     m_levelWidget->doRepaint();
00671 }
00672 
00673 void QEditorView::selectAll( )
00674 {
00675     m_editor->selectAll();
00676 }
00677 
00678 void QEditorView::setupActions()
00679 {
00680     // create our actions
00681     KStdAction::open( doc(), SLOT(fileOpen()), actionCollection() );
00682     KStdAction::saveAs( doc(), SLOT(fileSaveAs()), actionCollection() );
00683     KStdAction::save( doc(), SLOT(save()), actionCollection() );
00684 
00685     KAction *action = new KAction( i18n("Reloa&d"), "reload", Key_F5,
00686                  doc(), SLOT(fileReload()), actionCollection(), "file_reload" );
00687     action->setToolTip(i18n("Reload"));
00688     action->setWhatsThis(i18n("<b>Reload</b><p>Reloads the current document from disk."));
00689 
00690     action = KStdAction::undo( doc(), SLOT(undo()), actionCollection() );
00691     action->setWhatsThis(i18n("Reverts the most recent editing actions."));
00692     action = KStdAction::redo( doc(), SLOT(redo()), actionCollection() );
00693     action->setWhatsThis(i18n("Reverts the most recent undo operation."));
00694 
00695     action = KStdAction::cut( this, SLOT(cut()), actionCollection() );
00696     action->setWhatsThis(i18n("Cuts the selected text and moves it to the clipboard."));
00697     action = KStdAction::copy( this, SLOT(copy()), actionCollection() );
00698     action->setWhatsThis(i18n("Copies the selected text to the clipboard."));
00699 
00700     action = KStdAction::pasteText( this, SLOT(paste()), actionCollection() );
00701     action->setWhatsThis(i18n("Pastes previously copied or cut clipboard contents."));
00702     action = KStdAction::selectAll( this, SLOT(selectAll()), actionCollection() );
00703     action->setWhatsThis(i18n("Selects the entire text of the current document."));
00704 
00705     action = KStdAction::gotoLine( this, SLOT(gotoLine()), actionCollection() );
00706     action->setWhatsThis(i18n("Opens a dialog and lets you choose a line that you want the cursor to move to."));
00707     action = KStdAction::find( this, SLOT(doFind()), actionCollection() );
00708     action->setWhatsThis(i18n("Looks up the first occurrence of a piece of text or regular expression."));
00709     action = KStdAction::replace( this, SLOT(doReplace()), actionCollection() );
00710     action->setWhatsThis(i18n("Looks up a piece of text or regular expression and replace the result with some given text."));
00711 
00712     action = new KAction( i18n("&Indent"), "indent", CTRL + Key_I,
00713          editor(), SLOT(indent()),
00714                  actionCollection(), "edit_indent" );
00715     action->setToolTip(i18n("Indent"));
00716     action->setWhatsThis(i18n("<b>Indent</b><p>Indents a selected block of text."));
00717 
00718     action = new KAction( i18n("Collapse All Blocks"), "collapse all blocks", 0,
00719          this, SLOT(collapseAllBlocks()),
00720                  actionCollection(), "edit_collapse_all_blocks" );
00721     action->setToolTip(i18n("Collapse all blocks"));
00722     action->setWhatsThis(i18n("<b>Collapse all blocks</b><p>Collapses all blocks in the current document."));
00723 
00724     action = new KAction( i18n("Expand All Blocks"), "collapse all blocks", 0,
00725          this, SLOT(expandAllBlocks()),
00726                  actionCollection(), "edit_expand_all_blocks" );
00727     action->setToolTip(i18n("Expand all blocks"));
00728     action->setWhatsThis(i18n("<b>Expand all blocks</b><p>Expands all blocks in the current document."));
00729 
00730     action = new KAction( i18n("Start Macro"), "start macro", CTRL + Key_ParenLeft,
00731          editor(), SLOT(startMacro()),
00732                  actionCollection(), "tools_start_macro" );
00733     action->setToolTip(i18n("Start macro"));
00734     action->setWhatsThis(i18n("<b>Start macro</b><p>Starts recording a macro based on the editor input."));
00735 
00736     action = new KAction( i18n("Stop Macro"), "stop macro", CTRL + Key_ParenRight,
00737          editor(), SLOT(stopMacro()),
00738                  actionCollection(), "tools_stop_macro" );
00739     action->setToolTip(i18n("Stop macro"));
00740     action->setWhatsThis(i18n("<b>Stop macro</b><p>Stops recording a macro."));
00741 
00742     action = new KAction( i18n("Execute Macro"), "execute macro", CTRL + Key_E,
00743          editor(), SLOT(executeMacro()),
00744                  actionCollection(), "tools_execute_macro" );
00745     action->setToolTip(i18n("Execute macro"));
00746     action->setWhatsThis(i18n("<b>Execute macro</b><p>Executes previously recorded macro."));
00747 
00748     action = new KAction( i18n("&Configure Editor..."), "configure editor", 0,
00749          doc(), SLOT(configDialog()),
00750                  actionCollection(), "set_confdlg" );
00751     action->setToolTip(i18n("Configure editor"));
00752     action->setWhatsThis(i18n("<b>Configure editor</b><p>Opens an editor configuration dialog."));
00753 //                 actionCollection(), "settings_configure_editor" );
00754 }
00755 
00756 void QEditorView::expandAllBlocks()
00757 {
00758     QTextParagraph* p = m_editor->document()->firstParagraph();
00759     while( p ){
00760     ParagData* data = (ParagData*) p->extraData();
00761     if( data && data->isBlockStart() ){
00762         internalExpandBlock( p );
00763     }
00764     p = p->next();
00765     }
00766 
00767     m_editor->refresh();
00768     doRepaint();
00769 }
00770 
00771 void QEditorView::collapseAllBlocks()
00772 {
00773     QTextParagraph* p = m_editor->document()->firstParagraph();
00774     while( p ){
00775     ParagData* data = (ParagData*) p->extraData();
00776     if( data && data->isBlockStart() ){
00777         internalCollapseBlock( p );
00778     }
00779     p = p->next();
00780     }
00781 
00782     m_editor->refresh();
00783     doRepaint();
00784 }
00785 
00786 QString QEditorView::computeTextHint( int line, int column )
00787 {
00788     QString s;
00789     emit needTextHint( line, column, s );
00790     return s;
00791 }
00792 
00793 void QEditorView::enableTextHints( int timeout )
00794 {
00795     if( !m_textHintToolTip )
00796         m_textHintToolTip = new QEditorTextHint( this );
00797 
00798 #if KDE_VERSION > 305
00799     m_textHintToolTip->setWakeUpDelay( timeout );
00800 #else
00801 
00802 #endif
00803 }
00804 
00805 void QEditorView::disableTextHints()
00806 {
00807     if( m_textHintToolTip ){
00808         delete m_textHintToolTip;
00809     m_textHintToolTip = 0;
00810     }
00811 }
00812 
00813 
00814 #include "qeditor_view.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:42 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003