kate Library API Documentation

kateview.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
00003    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00004    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00005    Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef kate_view_h
00023 #define kate_view_h
00024 
00025 #include "katedocument.h"
00026 #include "kateviewinternal.h"
00027 #include "kateconfig.h"
00028 
00029 #include "../interfaces/view.h"
00030 
00031 #include <ktexteditor/sessionconfiginterface.h>
00032 #include <ktexteditor/viewstatusmsginterface.h>
00033 #include <ktexteditor/texthintinterface.h>
00034 
00035 #include <qguardedptr.h>
00036 
00037 class KateDocument;
00038 class KateBookmarks;
00039 class KateSearch;
00040 class KateCmdLine;
00041 class KateCodeCompletion;
00042 class KateViewConfig;
00043 class KateViewSchemaAction;
00044 class KateRenderer;
00045 
00046 class KToggleAction;
00047 class KAction;
00048 class KRecentFilesAction;
00049 class KSelectAction;
00050 
00051 class QGridLayout;
00052 
00053 //
00054 // Kate KTextEditor::View class ;)
00055 //
00056 class KateView : public Kate::View,
00057                  public KTextEditor::SessionConfigInterface,
00058                  public KTextEditor::ViewStatusMsgInterface,
00059                  public KTextEditor::TextHintInterface
00060 {
00061     Q_OBJECT
00062 
00063     friend class KateViewInternal;
00064     friend class KateIconBorder;
00065     friend class KateCodeCompletion;
00066 
00067   public:
00068     KateView( KateDocument* doc, QWidget* parent = 0L, const char* name = 0 );
00069     ~KateView ();
00070 
00071   //
00072   // KTextEditor::View
00073   //
00074   public:
00075     KTextEditor::Document* document() const       { return m_doc; }
00076 
00077   //
00078   // KTextEditor::ClipboardInterface
00079   //
00080   public slots:
00081     void cut()           { m_doc->cut(); m_viewInternal->repaint(); }
00082     void copy() const    { m_doc->copy();   }
00083     // TODO: Factor out of m_viewInternal
00084     void paste()         { m_viewInternal->doPaste(); m_viewInternal->repaint(); }
00085 
00086   //
00087   // KTextEditor::PopupMenuInterface
00088   //
00089   public:
00090     void installPopup( QPopupMenu* menu ) { m_rmbMenu = menu; }
00091     QPopupMenu* popup() const             { return m_rmbMenu; }
00092 
00093   //
00094   // KTextEditor::ViewCursorInterface
00095   //
00096   public slots:
00097     QPoint cursorCoordinates()
00098         { return m_viewInternal->cursorCoordinates();                 }
00099     void cursorPosition( uint* l, uint* c )
00100         { if( l ) *l = cursorLine(); if( c ) *c = cursorColumn();     }
00101     void cursorPositionReal( uint* l, uint* c )
00102         { if( l ) *l = cursorLine(); if( c ) *c = cursorColumnReal(); }
00103     bool setCursorPosition( uint line, uint col )
00104         { return setCursorPositionInternal( line, col, tabWidth(), true );  }
00105     bool setCursorPositionReal( uint line, uint col)
00106         { return setCursorPositionInternal( line, col, 1, true );           }
00107     uint cursorLine()
00108         { return m_viewInternal->getCursor().line();                    }
00109     uint cursorColumn();
00110     uint cursorColumnReal()
00111         { return m_viewInternal->getCursor().col();                     }
00112 
00113   signals:
00114     void cursorPositionChanged();
00115 
00116   //
00117   // KTextEditor::CodeCompletionInterface
00118   //
00119   public slots:
00120     void showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 );
00121     void showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset = 0, bool cs = true );
00122 
00123   signals:
00124     void completionAborted();
00125     void completionDone();
00126     void argHintHidden();
00127     void completionDone(KTextEditor::CompletionEntry);
00128     void filterInsertString(KTextEditor::CompletionEntry*,QString *);
00129     void aboutToShowCompletionBox();
00130 
00131   //
00132   // KTextEditor::TextHintInterface
00133   //
00134   public:
00135     void enableTextHints(int timeout);
00136     void disableTextHints();
00137 
00138   signals:
00139     void needTextHint(int line, int col, QString &text);
00140 
00141   //
00142   // KTextEditor::DynWordWrapInterface
00143   //
00144   public:
00145     void setDynWordWrap( bool b );
00146     bool dynWordWrap() const      { return m_hasWrap; }
00147 
00148   // BEGIN EDIT STUFF
00149   public:
00150     void editStart ();
00151     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00152 
00153     void editSetCursor (const KateTextCursor &cursor);
00154   // END
00155 
00156   // BEGIN TAG & CLEAR
00157   public:
00158     bool tagLine (const KateTextCursor& virtualCursor);
00159 
00160     bool tagLines (int start, int end, bool realLines = false );
00161     bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00162 
00163     void tagAll ();
00164 
00165     void clear ();
00166 
00167     void repaintText (bool paintOnlyDirty = false);
00168 
00169     void updateView (bool changed = false);
00170   // END
00171 
00172   //
00173   // Kate::View
00174   //
00175   public:
00176     bool isOverwriteMode() const;
00177     void setOverwriteMode( bool b );
00178 
00179     QString currentTextLine()
00180         { return getDoc()->textLine( cursorLine() ); }
00181     QString currentWord()
00182         { return m_doc->getWord( m_viewInternal->getCursor() ); }
00183     void insertText( const QString& text )
00184         { getDoc()->insertText( cursorLine(), cursorColumnReal(), text ); }
00185     bool canDiscard();
00186     int tabWidth()                { return m_doc->config()->tabWidth(); }
00187     void setTabWidth( int w )     { m_doc->config()->setTabWidth(w);  }
00188     void setEncoding( QString e ) { m_doc->setEncoding(e);       }
00189     bool isLastView()             { return m_doc->isLastView(1); }
00190 
00191   public slots:
00192     void flush();
00193     saveResult save();
00194     saveResult saveAs();
00195 
00196     void indent()             { m_doc->indent( this, cursorLine(), 1 );  }
00197     void unIndent()           { m_doc->indent( this, cursorLine(), -1 ); }
00198     void cleanIndent()        { m_doc->indent( this, cursorLine(), 0 );  }
00199     void align()              { m_doc->align( cursorLine() ); }
00200     void comment()            { m_doc->comment( this, cursorLine(), 1 );  }
00201     void uncomment()          { m_doc->comment( this, cursorLine(), -1 ); }
00202     void killLine()           { m_doc->removeLine( cursorLine() ); }
00203 
00207     void uppercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Uppercase ); }
00211     void lowercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Lowercase ); }
00216     void capitalize() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Capitalize ); }
00220     void joinLines();
00221 
00222 
00223     void keyReturn()          { m_viewInternal->doReturn();          }
00224     void backspace()          { m_viewInternal->doBackspace();       }
00225     void deleteWordLeft()     { m_viewInternal->doDeleteWordLeft();  }
00226     void keyDelete()          { m_viewInternal->doDelete();          }
00227     void deleteWordRight()    { m_viewInternal->doDeleteWordRight(); }
00228     void transpose()          { m_viewInternal->doTranspose();       }
00229     void cursorLeft()         { m_viewInternal->cursorLeft();        }
00230     void shiftCursorLeft()    { m_viewInternal->cursorLeft(true);    }
00231     void cursorRight()        { m_viewInternal->cursorRight();       }
00232     void shiftCursorRight()   { m_viewInternal->cursorRight(true);   }
00233     void wordLeft()           { m_viewInternal->wordLeft();          }
00234     void shiftWordLeft()      { m_viewInternal->wordLeft(true);      }
00235     void wordRight()          { m_viewInternal->wordRight();         }
00236     void shiftWordRight()     { m_viewInternal->wordRight(true);     }
00237     void home()               { m_viewInternal->home();              }
00238     void shiftHome()          { m_viewInternal->home(true);          }
00239     void end()                { m_viewInternal->end();               }
00240     void shiftEnd()           { m_viewInternal->end(true);           }
00241     void up()                 { m_viewInternal->cursorUp();          }
00242     void shiftUp()            { m_viewInternal->cursorUp(true);      }
00243     void down()               { m_viewInternal->cursorDown();        }
00244     void shiftDown()          { m_viewInternal->cursorDown(true);    }
00245     void scrollUp()           { m_viewInternal->scrollUp();          }
00246     void scrollDown()         { m_viewInternal->scrollDown();        }
00247     void topOfView()          { m_viewInternal->topOfView();         }
00248     void shiftTopOfView()     { m_viewInternal->topOfView(true);     }
00249     void bottomOfView()       { m_viewInternal->bottomOfView();      }
00250     void shiftBottomOfView()  { m_viewInternal->bottomOfView(true);  }
00251     void pageUp()             { m_viewInternal->pageUp();            }
00252     void shiftPageUp()        { m_viewInternal->pageUp(true);        }
00253     void pageDown()           { m_viewInternal->pageDown();          }
00254     void shiftPageDown()      { m_viewInternal->pageDown(true);      }
00255     void top()                { m_viewInternal->top_home();          }
00256     void shiftTop()           { m_viewInternal->top_home(true);      }
00257     void bottom()             { m_viewInternal->bottom_end();        }
00258     void shiftBottom()        { m_viewInternal->bottom_end(true);    }
00259     void toMatchingBracket()  { m_viewInternal->cursorToMatchingBracket();}
00260     void shiftToMatchingBracket()  { m_viewInternal->cursorToMatchingBracket(true);}
00261 
00262     void gotoLine();
00263     void gotoLineNumber( int linenumber );
00264 
00265   // config file / session management functions
00266   public:
00267     void readSessionConfig(KConfig *);
00268     void writeSessionConfig(KConfig *);
00269 
00270   public slots:
00271     int getEol();
00272     void setEol( int eol );
00273     void find();
00274     void replace();
00275     void findAgain( bool back );
00276     void findAgain()              { findAgain( false );          }
00277     void findPrev()               { findAgain( true );           }
00278 
00279     void setFoldingMarkersOn( bool enable ); // Not in Kate::View, but should be
00280     void setIconBorder( bool enable );
00281     void setLineNumbersOn( bool enable );
00282     void setScrollBarMarks( bool enable );
00283     void showCmdLine ( bool enable );
00284     void toggleFoldingMarkers();
00285     void toggleIconBorder();
00286     void toggleLineNumbersOn();
00287     void toggleScrollBarMarks();
00288     void toggleDynWordWrap ();
00289     void toggleCmdLine ();
00290     void setDynWrapIndicators(int mode);
00291 
00292   public:
00293     KateRenderer *renderer ();
00294 
00295     bool iconBorder();
00296     bool lineNumbersOn();
00297     bool scrollBarMarks();
00298     int dynWrapIndicators();
00299     bool foldingMarkersOn();
00300     Kate::Document* getDoc()    { return m_doc; }
00301 
00302     void setActive( bool b )    { m_active = b; }
00303     bool isActive()             { return m_active; }
00304 
00305   public slots:
00306     void gotoMark( KTextEditor::Mark* mark ) { setCursorPositionInternal ( mark->line, 0, 1 ); }
00307     void selectionChanged ();
00308 
00309   signals:
00310     void gotFocus( Kate::View* );
00311     void lostFocus( Kate::View* );
00312     void newStatus(); // Not in Kate::View, but should be (Kate app connects to it)
00313 
00314   //
00315   // Extras
00316   //
00317   public:
00318     // Is it really necessary to have 3 methods for this?! :)
00319     KateDocument*  doc() const       { return m_doc; }
00320 
00321     KActionCollection* editActionCollection() const { return m_editActions; }
00322 
00323   public slots:
00324     void slotNewUndo();
00325     void slotUpdate();
00326     void toggleInsert();
00327     void reloadFile();
00328     void toggleWWMarker();
00329     void toggleWriteLock();
00330     void switchToCmdLine ();
00331     void slotReadWriteChanged ();
00332 
00333   signals:
00334     void dropEventPass(QDropEvent*);
00335     void viewStatusMsg (const QString &msg);
00336 
00337   public:
00338     bool setCursorPositionInternal( uint line, uint col, uint tabwidth = 1, bool calledExternally = false );
00339 
00340   protected:
00341     void contextMenuEvent( QContextMenuEvent* );
00342     bool checkOverwrite( KURL );
00343 
00344   public slots:
00345     void slotSelectionTypeChanged();
00346 
00347   private slots:
00348     void slotGotFocus();
00349     void slotLostFocus();
00350     void slotDropEventPass( QDropEvent* ev );
00351     void slotSetEncoding( const QString& descriptiveName );
00352     void slotStatusMsg();
00353     void slotSaveCanceled( const QString& error );
00354     void slotExpandToplevel();
00355     void slotCollapseLocal();
00356     void slotExpandLocal();
00357 
00358   private:
00359     void setupConnections();
00360     void setupActions();
00361     void setupEditActions();
00362     void setupCodeFolding();
00363     void setupCodeCompletion();
00364 
00365     KActionCollection*     m_editActions;
00366     KAction*               m_editUndo;
00367     KAction*               m_editRedo;
00368     KRecentFilesAction*    m_fileRecent;
00369     KToggleAction*         m_toggleFoldingMarkers;
00370     KToggleAction*         m_toggleIconBar;
00371     KToggleAction*         m_toggleLineNumbers;
00372     KToggleAction*         m_toggleScrollBarMarks;
00373     KToggleAction*         m_toggleDynWrap;
00374     KSelectAction*         m_setDynWrapIndicators;
00375     KToggleAction*         m_toggleWWMarker;
00376     KAction*         m_switchCmdLine;
00377 
00378     KSelectAction*         m_setEndOfLine;
00379 
00380     KSelectAction*         m_setEncoding;
00381     Kate::ActionMenu*      m_setHighlight;
00382     Kate::ActionMenu*      m_setFileType;
00383     KToggleAction*         m_toggleWriteLock;
00384     KateViewSchemaAction*  m_schemaMenu;
00385 
00386     KAction *m_cut;
00387     KAction *m_copy;
00388     KAction *m_paste;
00389     KAction *m_selectAll;
00390     KAction *m_deSelect;
00391 
00392     KToggleAction *m_toggleBlockSelection;
00393     KToggleAction *m_toggleInsert;
00394 
00395     KateDocument*          m_doc;
00396     KateViewInternal*      m_viewInternal;
00397     KateRenderer*          m_renderer;
00398     KateSearch*            m_search;
00399     KateBookmarks*         m_bookmarks;
00400     QGuardedPtr<QPopupMenu>  m_rmbMenu;
00401     KateCodeCompletion*    m_codeCompletion;
00402 
00403     KateCmdLine *m_cmdLine;
00404     bool m_cmdLineOn;
00405 
00406     QGridLayout *m_grid;
00407 
00408     bool       m_active;
00409     bool       m_hasWrap;
00410 
00411   private slots:
00412     void slotNeedTextHint(int line, int col, QString &text);
00413     void slotHlChanged();
00414   
00418   public:
00419     inline KateViewConfig *config () { return m_config; };
00420 
00421     void updateConfig ();
00422 
00423     void updateDocumentConfig();
00424 
00425     void updateRendererConfig();
00426 
00427   private slots:
00428     void updateFoldingConfig ();
00429     void toggleBlockSelectionMode ();
00430 
00431   private:
00432     KateViewConfig *m_config;
00433     bool m_startingUp;
00434     bool m_updatingDocumentConfig;
00435 };
00436 
00437 #endif
KDE Logo
This file is part of the documentation for kate Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Feb 18 15:11:57 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003