KDevelop API Documentation

qeditor_part.cpp

Go to the documentation of this file.
00001 /* $Id: qeditor_part.cpp,v 1.60 2004/02/22 23:53:43 mueller 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 
00022 #include <qvbox.h>
00023 #include <qfile.h>
00024 #include <qtextstream.h>
00025 #include <qregexp.h>
00026 #include <qlayout.h>
00027 #include <private/qrichtext_p.h>
00028 
00029 #include <kinstance.h>
00030 #include <kaction.h>
00031 #include <kstdaction.h>
00032 #include <kfiledialog.h>
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035 #include <kdialogbase.h>
00036 #include <klocale.h>
00037 #include <kxmlguifactory.h>
00038 
00039 #include "qeditor_part.h"
00040 #include "qeditor_view.h"
00041 #include "qeditor_settings.h"
00042 #include "qeditor_browserextension.h"
00043 #include "qeditor.h"
00044 #include "paragdata.h"
00045 #include "qsourcecolorizer.h"
00046 #include "qeditor_indenter.h"
00047 #include "highlightingconfigpage.h"
00048 #include "generalconfigpage.h"
00049 #include "markerwidget.h"
00050 
00051 #include "qeditor_part.moc"
00052 
00053 
00054 struct HLMode{
00055     QString name;
00056     QString section;
00057     QStringList extensions;
00058 };
00059 
00060 
00061 class CursorImpl: public KTextEditor::Cursor
00062 {
00063 public:
00064     CursorImpl( QTextDocument* doc ): m_doc( doc ) {
00065         m_cursor = new QTextCursor( doc );
00066     }
00067 
00068     virtual ~CursorImpl(){
00069         delete( m_cursor );
00070     }
00071 
00072     virtual void position ( unsigned int *line, unsigned int *col ) const{
00073         *line = m_cursor->paragraph()->paragId();
00074         *col = m_cursor->index();
00075     }
00076 
00077     virtual bool setPosition ( unsigned int line, unsigned int col ){
00078         m_cursor->setParagraph( m_cursor->document()->paragAt( line ) );
00079         m_cursor->setIndex( col );
00080         return TRUE;
00081     }
00082 
00083     virtual bool insertText ( const QString& text ){
00084         m_cursor->paragraph()->insert( m_cursor->index(), text );
00085         return TRUE;
00086     }
00087 
00088     virtual bool removeText ( unsigned int numberOfCharacters ){
00089         m_cursor->paragraph()->remove( m_cursor->index(), numberOfCharacters );
00090         return TRUE;
00091     }
00092 
00093     virtual QChar currentChar () const{
00094         return m_cursor->paragraph()->at( m_cursor->index() )->c;
00095     }
00096 
00097 private:
00098     QTextDocument* m_doc;
00099     QTextCursor* m_cursor;
00100 };
00101 
00102 using namespace std;
00103 
00104 QEditorPart::QEditorPart( QWidget *parentWidget, const char *widgetName,
00105                           QObject *parent, const char *name,
00106                           const QStringList & /*args*/ )
00107     : KTextEditor::Document( parent, name == 0 ? "QEditorPart" : name ), m_currentView( 0 )
00108 {
00109     kdDebug(9032) << "QEditorPart::QEditorPart()" << endl;
00110     // we need an instance
00111     setInstance( QEditorPartFactory::instance() );
00112 
00113     QEditorPartFactory::registerDocument( this );
00114 
00115     m_views.setAutoDelete( FALSE );
00116     m_cursors.setAutoDelete( TRUE );
00117     m_marks.setAutoDelete( TRUE );
00118 
00119     (void) createView( parentWidget, widgetName );
00120     m_extension = new QEditorBrowserExtension( this );
00121 
00122     setupHighlighting();
00123 
00124     // we are read-write by default
00125     setReadWrite(true);
00126 
00127     // we are not modified since we haven't done anything yet
00128     setModified(false);
00129 
00130 }
00131 
00132 QEditorPart::~QEditorPart()
00133 {
00134     QEditorPartFactory::deregisterDocument( this );
00135 }
00136 
00137 void QEditorPart::setReadWrite(bool rw)
00138 {
00139     // notify your internal widget of the read-write state
00140     m_currentView->editor()->setReadOnly(!rw);
00141     if (rw){
00142         connect(m_currentView->editor(), SIGNAL(textChanged()),
00143                 this, SLOT(setModified()));
00144     } else {
00145         disconnect(m_currentView->editor(), SIGNAL(textChanged()),
00146                    this, SLOT(setModified()));
00147     }
00148 
00149     ReadWritePart::setReadWrite(rw);
00150 }
00151 
00152 void QEditorPart::setModified(bool modified)
00153 {
00154     if ( modified == ReadWritePart::isModified() )
00155         return; //nothing to do
00156 
00157     m_currentView->editor()->setModified( modified );
00158 
00159     // in any event, we want our parent to do it's thing
00160     ReadWritePart::setModified(modified);
00161 
00162     // get a handle on our Save action and make sure it is valid
00163     KAction *save = m_currentView->actionCollection()->action(KStdAction::stdName(KStdAction::Save));
00164     if (save)
00165         // if so, we either enable or disable it based on the current
00166         // state
00167         save->setEnabled(modified);
00168 
00169     // same for the reload action
00170     KAction *reload = m_currentView->actionCollection()->action("Reload");
00171     if ( reload )
00172         reload->setEnabled(modified);
00173 
00174     emit newStatus();
00175 }
00176 
00177 bool QEditorPart::openFile()
00178 {
00179     // m_file is always local so we can use QFile on it
00180     QFile file(m_file);
00181     if (file.open(IO_ReadOnly) == false)
00182         return false;
00183 
00184     // our example widget is text-based, so we use QTextStream instead
00185     // of a raw QDataStream
00186     QTextStream stream(&file);
00187     QString str;
00188     while (!stream.eof())
00189         str += stream.readLine() + "\n";
00190 
00191     file.close();
00192 
00193     m_currentView->editor()->setText( str );
00194     int hl = findMode( m_file );
00195     setHlMode( hl>=0 ? hl : 0 );
00196 
00197     setModified( false );
00198     emit fileNameChanged();
00199 
00200     return true;
00201 }
00202 
00203 bool QEditorPart::saveFile()
00204 {
00205     // if we aren't read-write, return immediately
00206     if (isReadWrite() == false)
00207         return false;
00208 
00209     if( m_file.isEmpty() ){
00210     fileSaveAs();
00211     return true;
00212     }
00213 
00214     // m_file is always local, so we use QFile
00215     QFile file(m_file);
00216     if (file.open(IO_WriteOnly) == false)
00217         return false;
00218 
00219     // use QTextStream to dump the text to the file
00220     QTextStream stream(&file);
00221     stream << m_currentView->editor()->text();
00222 
00223     file.close();
00224 
00225     int hl = findMode( m_file );
00226     setHlMode( hl>=0 ? hl : 0 );
00227 
00228     setModified( false );
00229     emit fileNameChanged();
00230 
00231     return true;
00232 }
00233 
00234 void QEditorPart::fileReload()
00235 {
00236     if (openURL(url())) {
00237         setModified( false );
00238     emit newStatus();
00239     }
00240 }
00241 
00242 void QEditorPart::fileOpen()
00243 {
00244     // this slot is called whenever the File->Open menu is selected,
00245     // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
00246     // button is clicked
00247     QString file_name = KFileDialog::getOpenFileName();
00248 
00249     if (file_name.isEmpty() == false)
00250         openURL(KURL::fromPathOrURL( file_name ));
00251 }
00252 
00253 void QEditorPart::fileSaveAs()
00254 {
00255     // this slot is called whenever the File->Save As menu is selected,
00256     QString file_name = KFileDialog::getSaveFileName();
00257     if (file_name.isEmpty() == false)
00258         saveAs(KURL::fromPathOrURL( file_name ));
00259 }
00260 
00261 // -- EditInterface Implementation -- START -------------------------------------------------------------
00262 QString QEditorPart::text() const
00263 {
00264     return m_currentView->editor()->text();
00265 }
00266 
00267 QString QEditorPart::text( unsigned int startLine, unsigned int startCol,
00268                            unsigned int endLine, unsigned int endCol ) const
00269 {
00270     int selNum = 1000;
00271     QTextDocument* textDoc = m_currentView->editor()->document();
00272 
00273     m_currentView->editor()->setSelection( startLine, startCol, endLine, endCol, selNum );
00274     QString txt = textDoc->selectedText( selNum );
00275     textDoc->removeSelection( selNum );
00276 
00277     return textDoc->selectedText( selNum );
00278 }
00279 
00280 QString QEditorPart::textLine( unsigned int line ) const
00281 {
00282     return m_currentView->editor()->textLine( line );
00283 }
00284 
00285 unsigned int QEditorPart::numLines() const
00286 {
00287     return m_currentView->editor()->lines();
00288 }
00289 
00290 unsigned int QEditorPart::length() const
00291 {
00292     return m_currentView->editor()->length();
00293 }
00294 
00295 int QEditorPart::lineLength( unsigned int line ) const
00296 {
00297     if( int(line) < m_currentView->editor()->lines() ){
00298         return m_currentView->editor()->paragraphLength( line );
00299     }
00300     return -1;
00301 }
00302 
00303 bool QEditorPart::setText( const QString &text )
00304 {
00305     m_currentView->editor()->setText( text );
00306     return TRUE;
00307 }
00308 
00309 bool QEditorPart::clear()
00310 {
00311     m_currentView->editor()->clear();
00312     return TRUE;
00313 }
00314 
00315 bool QEditorPart::insertText( unsigned int line, unsigned int col, const QString &text )
00316 {
00317     m_currentView->editor()->insertAt( text, line, col );
00318     return TRUE;
00319 }
00320 
00321 bool QEditorPart::removeText( unsigned int startLine, unsigned int startCol,
00322                               unsigned int endLine, unsigned int endCol )
00323 {
00324     int selNum = 10;
00325     m_currentView->editor()->setSelection( startLine, startCol, endLine, endCol, selNum );
00326     m_currentView->editor()->removeSelectedText( selNum );
00327     return TRUE;
00328 }
00329 
00330 bool QEditorPart::insertLine( unsigned int line, const QString &text )
00331 {
00332     m_currentView->editor()->insertParagraph( text, line );
00333     return TRUE;
00334 }
00335 
00336 bool QEditorPart::removeLine( unsigned int line )
00337 {
00338     m_currentView->editor()->removeParagraph( line );
00339     return TRUE;
00340 }
00341 
00342 KTextEditor::View* QEditorPart::createView( QWidget* parentWidget, const char* widgetName )
00343 {
00344     kdDebug(9032) << "QEditorPart::createView()" << endl;
00345 
00346     if( !m_currentView ){
00347     m_currentView = new QEditorView( this, parentWidget, widgetName );
00348     m_views.append( m_currentView );
00349     insertChildClient( m_currentView );
00350     setWidget( m_currentView );
00351     }
00352     else
00353     m_currentView->reparent( parentWidget, QPoint(0,0) );
00354 
00355     return m_currentView;
00356 }
00357 
00358 QPtrList<KTextEditor::View> QEditorPart::views() const
00359 {
00360     return m_views;
00361 }
00362 
00363 // UndoInterface -------------------------------------------------------------------------
00364 void QEditorPart::clearUndo()
00365 {
00366 #warning "TODO: void QEditorPart::clearUndo()"
00367     kdDebug(9032) << "QEditorPart::clearUndo() -- not implemented yet!!" << endl;
00368 }
00369 
00370 void QEditorPart::clearRedo()
00371 {
00372 #warning "TODO: void QEditorPart::clearRedo()"
00373     kdDebug(9032) << "QEditorPart::clearRedo() -- not implemented yet!!" << endl;
00374 }
00375 
00376 unsigned int QEditorPart::undoCount() const
00377 {
00378 #warning "TODO: unsigned int QEditorPart::undoCount() const"
00379     kdDebug(9032) << "QEditorPart::undoCount() -- not implemented yet!!" << endl;
00380     return 0;
00381 }
00382 
00383 unsigned int QEditorPart::redoCount() const
00384 {
00385 #warning "TODO: unsigned int QEditorPart::redoCount() const"
00386     kdDebug(9032) << "QEditorPart::redoCount() -- not implemented yet!!" << endl;
00387     return 0;
00388 }
00389 
00390 unsigned int QEditorPart::undoSteps() const
00391 {
00392     QTextDocument* textDoc = m_currentView->editor()->document();
00393     return textDoc->commands()->undoDepth();
00394 }
00395 
00396 void QEditorPart::setUndoSteps( unsigned int steps )
00397 {
00398     QTextDocument* textDoc = m_currentView->editor()->document();
00399     textDoc->commands()->setUndoDepth( steps );
00400 }
00401 
00402 void QEditorPart::undo()
00403 {
00404     m_currentView->editor()->undo();
00405 }
00406 
00407 void QEditorPart::redo()
00408 {
00409     m_currentView->editor()->redo();
00410 }
00411 
00412 KTextEditor::Cursor* QEditorPart::createCursor( )
00413 {
00414     KTextEditor::Cursor* c = new CursorImpl( m_currentView->editor()->document() );
00415     m_cursors.append( c );
00416     return c;
00417 }
00418 
00419 QPtrList<KTextEditor::Cursor> QEditorPart::cursors() const
00420 {
00421     return m_cursors;
00422 }
00423 
00424 bool QEditorPart::setSelection( unsigned int startLine, unsigned int startCol,
00425                                 unsigned int endLine, unsigned int endCol )
00426 {
00427     m_currentView->editor()->setSelection( startLine, startCol, endLine, endCol );
00428     return TRUE;
00429 }
00430 
00431 bool QEditorPart::clearSelection()
00432 {
00433     m_currentView->editor()->removeSelection();
00434     return TRUE;
00435 }
00436 
00437 bool QEditorPart::hasSelection() const
00438 {
00439     return m_currentView->editor()->hasSelectedText();
00440 }
00441 
00442 QString QEditorPart::selection() const
00443 {
00444     return m_currentView->editor()->selectedText();
00445 }
00446 
00447 bool QEditorPart::removeSelectedText()
00448 {
00449     m_currentView->editor()->removeSelectedText();
00450     return TRUE;
00451 }
00452 
00453 bool QEditorPart::selectAll()
00454 {
00455     m_currentView->editor()->selectAll();
00456     return TRUE;
00457 }
00458 
00459 void QEditorPart::setupHighlighting()
00460 {
00461     m_currentMode = 0;
00462 
00463     HLMode* mode = 0;
00464     m_modes.setAutoDelete( TRUE );
00465 
00466     mode = new HLMode;
00467     mode->name = "normal";
00468     mode->section = "Normal";
00469     mode->extensions = QStringList() << "*.txt" << "*.doc";
00470     m_modes.append( mode );
00471 
00472     mode = new HLMode;
00473     mode->name = "c++";
00474     mode->section = "Programming";
00475     mode->extensions = QStringList() << "*.cpp" << "*.cxx" << "*.cc" << "*.C" << "*.c++" << "*.c" << "*.tcc" <<
00476                        "*.m" << "*.mm" << "*.M" << "*.inl" << "*.tlh" << "*.diff" << "*.patch" << "*.moc" << "*.xpm" <<
00477                        "*.h" << "*.hpp" << "*.hh" << "*.hxx" << "*.h++" << "*.H";
00478     m_modes.append( mode );
00479 
00480     mode = new HLMode;
00481     mode->name = "java";
00482     mode->section = "Programming";
00483     mode->extensions = QStringList() << "*.java";
00484     m_modes.append( mode );
00485 
00486     mode = new HLMode;
00487     mode->name = "javascript";
00488     mode->section = "Programming";
00489     mode->extensions = QStringList() << "*.js" << "*.qs";
00490     m_modes.append( mode );
00491 
00492     mode = new HLMode;
00493     mode->name = "csharp";
00494     mode->section = "Programming";
00495     mode->extensions = QStringList() << "*.cs";
00496     m_modes.append( mode );
00497 
00498 #if defined(HAVE_PERL_MODE)
00499     mode = new HLMode;
00500     mode->name = "perl";
00501     mode->section = "Programming";
00502     mode->extensions = QStringList() << "*.pl";
00503     m_modes.append( mode );
00504 #endif
00505 
00506     mode = new HLMode;
00507     mode->name = "python";
00508     mode->section = "Programming";
00509     mode->extensions = QStringList() << "*.py" << "*.pyw";
00510     m_modes.append( mode );
00511 
00512     mode = new HLMode;
00513     mode->name = "xml";
00514     mode->section = "Markup";
00515     mode->extensions = QStringList() << "*.xml" << "*.xslt" << "*.rc" << "*rc" << "*.ui" <<
00516                                         "*.html" << "*.htm" << "*.kdevelop" << "*.kdevses" ;
00517     m_modes.append( mode );
00518 
00519     mode = new HLMode;
00520     mode->name = "qmake";
00521     mode->section = "Programming";
00522     mode->extensions = QStringList() << "*.pro" << "*.sh" << "*Makefile" << "*Makefile.am" << "*Makefile.in";
00523     m_modes.append( mode );
00524 
00525     mode = new HLMode;
00526     mode->name = "jsp";
00527     mode->section = "Programming";
00528     mode->extensions = QStringList() << "*.jsp";
00529     m_modes.append( mode );
00530 
00531     mode = new HLMode;
00532     mode->name = "ocaml";
00533     mode->section = "Programming";
00534     mode->extensions = QStringList() << "*.ml" << "*.mli";
00535     m_modes.append( mode );
00536 
00537     mode = new HLMode;
00538     mode->name = "pascal";
00539     mode->section = "Programming";
00540     mode->extensions = QStringList() << "*.pp" << "*.p" << "*.pas" << "*.dpr";
00541     m_modes.append( mode );
00542 
00543     mode = new HLMode;
00544     mode->name = "ada";
00545     mode->section = "Programming";
00546     mode->extensions = QStringList() << "*.adb" << "*.ads";
00547     m_modes.append( mode );
00548 
00549     mode = new HLMode;
00550     mode->name = "sql";
00551     mode->section = "Programming";
00552     mode->extensions = QStringList() << "*.sql" << "*.SQL";
00553     m_modes.append( mode );
00554 }
00555 
00556 unsigned int QEditorPart::hlMode()
00557 {
00558     return m_currentMode;
00559 }
00560 
00561 bool QEditorPart::setHlMode(unsigned int mode)
00562 {
00563     if( m_currentMode != mode ){
00564         m_currentMode = mode;
00565         HLMode* m = m_modes.at( m_currentMode );
00566         if( m ){
00567             m_currentView->setLanguage( m->name );
00568         }
00569         emit hlChanged();
00570     }
00571     return TRUE;
00572 }
00573 
00574 unsigned int QEditorPart::hlModeCount()
00575 {
00576     return m_modes.count();
00577 }
00578 
00579 QString QEditorPart::hlModeName(unsigned int mode)
00580 {
00581     HLMode* m = m_modes.at( mode );
00582     return m ? m->name : QString::null;
00583 }
00584 
00585 QString QEditorPart::hlModeSectionName(unsigned int mode)
00586 {
00587     HLMode* m = m_modes.at( mode );
00588     return m ? m->section : QString::null;
00589 }
00590 
00591 int QEditorPart::findMode( const QString& filename )
00592 {
00593     for( unsigned int modeNum=0; modeNum<m_modes.count(); ++modeNum ){
00594         HLMode* mode = m_modes.at( modeNum );
00595         QStringList::Iterator itExt = mode->extensions.begin();
00596         while( itExt != mode->extensions.end() ){
00597             if( QRegExp(*itExt, TRUE, TRUE).exactMatch(filename) ){
00598                 return modeNum;
00599             }
00600             ++itExt;
00601         }
00602     }
00603     return -1;
00604 }
00605 
00606 bool QEditorPart::searchText (unsigned int startLine, unsigned int startCol,
00607                               const QString &text, unsigned int *foundAtLine, unsigned int *foundAtCol,
00608                               unsigned int *matchLen, bool casesensitive, bool backwards )
00609 {
00610     /*
00611     Q_UNUSED( startLine );
00612     Q_UNUSED( startCol );
00613     Q_UNUSED( text );
00614     Q_UNUSED( foundAtLine );
00615     Q_UNUSED( foundAtCol );
00616     Q_UNUSED( matchLen );
00617     Q_UNUSED( casesensitive );
00618     Q_UNUSED( backwards );
00619     */
00620     if( text.isEmpty() ){
00621         return false;
00622     }
00623 
00624     unsigned int tmpline = startLine;
00625     int foundCol;
00626     QString oneline;
00627     bool firstTestedLine=true;
00628 
00629     if( !backwards ){
00630         while( tmpline <= numLines() ){
00631             //int oneLineLen = lineLength( tmpline-1 );
00632             oneline = textLine( tmpline );
00633             kdDebug()<<oneline<<endl;
00634 
00635             // test one line by one line
00636             if( firstTestedLine ){
00637                 int index = (int)startCol;
00638                 foundCol = oneline.find( text, index, casesensitive );
00639                 firstTestedLine = false;
00640             }else{
00641                 foundCol = oneline.find( text, 0, casesensitive );
00642             }
00643             //case of found..
00644             if( foundCol != -1 ){
00645                 (*foundAtLine) = tmpline;
00646                 (*foundAtCol) = foundCol;
00647                 (*matchLen) = text.length();
00648                 return true;
00649             }
00650             //case of not found..
00651             tmpline++;
00652         }
00653 
00654         return false;
00655 
00656     }else{
00657         while( tmpline != 0 ){
00658             oneline = textLine( tmpline );
00659             kdDebug()<<oneline<<endl;
00660             if( firstTestedLine ){
00661                 int index = (int)startCol;
00662                 foundCol = oneline.findRev( text, index, casesensitive );
00663                 firstTestedLine = false;
00664             }else{
00665                 foundCol = oneline.findRev( text, -1, casesensitive );
00666             }
00667 
00668             // case of found..
00669             if( foundCol != -1 ){
00670                 (*foundAtLine) = tmpline;
00671                 (*foundAtCol) = foundCol;
00672                 (*matchLen) = text.length();
00673                 return true;
00674             }
00675             tmpline--;
00676         }
00677         return false;
00678     }
00679 }
00680 
00681 bool QEditorPart::searchText (unsigned int startLine, unsigned int startCol,
00682             const QRegExp &regexp, unsigned int *foundAtLine,
00683             unsigned int *foundAtCol, unsigned int *matchLen, bool backwards )
00684 {
00685     unsigned int line = startLine;
00686     while( line<=numLines() ){
00687         QString str = textLine( line );
00688         int pos = -1;
00689         if( backwards ){
00690             pos = regexp.searchRev( str, line == startLine ? startCol : str.length() );
00691         } else {
00692             pos = regexp.search( str, line == startLine ? startCol : 0 );
00693         }
00694 
00695         if( pos != -1 ){
00696         *foundAtLine = line;
00697             *foundAtCol = pos;
00698             *matchLen = regexp.matchedLength();
00699             return true;
00700         }
00701 
00702         if( backwards ){
00703         --line;
00704         } else {
00705         ++line;
00706         }
00707     }
00708     return false;
00709 }
00710 
00711 uint QEditorPart::mark (uint line)
00712 {
00713     QTextDocument* textDoc = m_currentView->editor()->document();
00714     QTextParagraph* parag = textDoc->paragAt( line );
00715     if( parag ){
00716         ParagData* data = (ParagData*) parag->extraData();
00717         if( data ){
00718             return data->mark();
00719         }
00720     }
00721     return 0;
00722 }
00723 
00724 void QEditorPart::setMark (uint line, uint markType)
00725 {
00726     QTextDocument* textDoc = m_currentView->editor()->document();
00727     QTextParagraph* parag = textDoc->paragAt( line );
00728     if( parag ){
00729         ParagData* data = (ParagData*) parag->extraData();
00730         if( data ){
00731             data->setMark( markType );
00732             emit marksChanged();
00733         }
00734     }
00735 }
00736 
00737 void QEditorPart::clearMark (uint line)
00738 {
00739     setMark( line, 0 );
00740 }
00741 
00742 void QEditorPart::addMark (uint line, uint markType)
00743 {
00744     QTextDocument* textDoc = m_currentView->editor()->document();
00745     QTextParagraph* parag = textDoc->paragAt( line );
00746     if( parag ){
00747         ParagData* data = (ParagData*) parag->extraData();
00748         if( data ){
00749             data->setMark( data->mark() | markType );
00750             emit marksChanged();
00751         }
00752     }
00753 }
00754 
00755 void QEditorPart::removeMark (uint line, uint markType)
00756 {
00757     QTextDocument* textDoc = m_currentView->editor()->document();
00758     QTextParagraph* parag = textDoc->paragAt( line );
00759     if( parag ){
00760         ParagData* data = (ParagData*) parag->extraData();
00761         if( data ){
00762             data->setMark( data->mark() & ~markType );
00763             emit marksChanged();
00764         }
00765     }
00766 }
00767 
00768 QPtrList<KTextEditor::Mark> QEditorPart::marks ()
00769 {
00770     //m_marks.clear();
00771 
00772     QPtrList<KTextEditor::Mark> marks;
00773     marks.setAutoDelete( true );
00774 
00775     QTextDocument* textDoc = m_currentView->editor()->document();
00776     QTextParagraph* p = textDoc->firstParagraph();
00777     while( p ){
00778         ParagData* data = (ParagData*) p->extraData();
00779         if( data && data->mark() ){
00780             KTextEditor::Mark* mark = new KTextEditor::Mark;
00781             mark->type = data->mark();
00782             mark->line = p->paragId();
00783 
00784             marks.append( mark );
00785         }
00786         p = p->next();
00787     }
00788     return marks;
00789 }
00790 
00791 void QEditorPart::clearMarks ()
00792 {
00793     QTextDocument* textDoc = m_currentView->editor()->document();
00794     QTextParagraph* p = textDoc->firstParagraph();
00795     while( p ){
00796         ParagData* data = (ParagData*) p->extraData();
00797         if( data ){
00798             data->setMark( 0 );
00799         }
00800         p = p->next();
00801     }
00802 }
00803 
00804 void QEditorPart::setPixmap(KTextEditor::MarkInterface::MarkTypes mt, const QPixmap & pm)
00805 {
00806     m_currentView->markerWidget()->setPixmap(mt, pm);
00807 }
00808 
00809 void QEditorPart::setDescription(KTextEditor::MarkInterface::MarkTypes mt, const QString & s)
00810 {
00811     m_currentView->markerWidget()->setDescription(mt, s);
00812 }
00813 
00814 void QEditorPart::setMarksUserChangable(uint markMask)
00815 {
00816     m_currentView->markerWidget()->setMarksUserChangable(markMask);
00817 }
00818 
00819 // -- ConfigInterface ---------------------------------------------------------------------
00820 
00821 void QEditorPart::readConfig()
00822 {
00823     QEditorSettings::self()->readConfig();
00824     m_currentView->configChanged();
00825 }
00826 
00827 void QEditorPart::writeConfig()
00828 {
00829     kdDebug(9032) << "QEditorPart::writeConfig() - not implemented yet!" << endl;
00830 }
00831 
00832 void QEditorPart::readConfig(KConfig *)
00833 {
00834     kdDebug(9032) << "QEditorPart::readConfig(KConfig *) - not implemented yet!" << endl;
00835 }
00836 
00837 void QEditorPart::writeConfig(KConfig *)
00838 {
00839     kdDebug(9032) << "QEditorPart::writeConfig(KConfig *) - not implemented yet!" << endl;
00840 }
00841 
00842 void QEditorPart::readSessionConfig(KConfig *)
00843 {
00844     kdDebug(9032) << "QEditorPart::readSessionConfig(KConfig *) - not implemented yet!" << endl;
00845 }
00846 
00847 void QEditorPart::writeSessionConfig(KConfig *)
00848 {
00849     kdDebug(9032) << "QEditorPart::writeSessionConfig(KConfig *) - not implemented yet!" << endl;
00850 }
00851 
00852 void QEditorPart::configDialog()
00853 {
00854     KDialogBase dlg(KDialogBase::Tabbed, i18n("QEditor Options"),
00855                     KDialogBase::Ok|KDialogBase::Cancel,
00856                     KDialogBase::Ok, 0,
00857                     "qeditor options dialog");
00858 
00859     GeneralConfigPage* generalPage = new GeneralConfigPage( dlg.addVBoxPage(i18n("General")) );
00860     generalPage->setPart( this );
00861     connect( &dlg, SIGNAL(okClicked()), generalPage, SLOT(accept()) );
00862 
00863 
00864     if( colorizer() ){
00865         HighlightingConfigPage* hlPage = new HighlightingConfigPage( dlg.addVBoxPage(i18n("Highlighting")) );
00866         hlPage->setEditor( this );
00867         connect( &dlg, SIGNAL(okClicked()), hlPage, SLOT(accept()) );
00868     }
00869 
00870     if( indenter() ){
00871         (void) indenter()->createConfigPage( this, &dlg );
00872     }
00873 
00874     emit configWidget( &dlg );
00875 
00876     if ( dlg.exec() )
00877     {
00878         QEditorSettings::self()->config()->sync();
00879         m_currentView->configChanged();
00880 /*
00881         QPtrList<QEditorView> views = QEditorPartFactory::views();
00882         QPtrListIterator<QEditorView> it( views );
00883         while( it.current() )
00884         {
00885             it.current()->configChanged();
00886             ++it;
00887         }
00888 */
00889     }
00890 }
00891 
00892 // ----------------------------------------------------------------------------------
00893 
00894 QSourceColorizer* QEditorPart::colorizer() const
00895 {
00896     return m_currentView->editor()->colorizer();
00897 }
00898 
00899 QEditorIndenter* QEditorPart::indenter() const
00900 {
00901     return m_currentView->editor()->indenter();
00902 }
00903 
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