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();    }
00082     void copy() const    { m_doc->copy();   }
00083     // TODO: Factor out of m_viewInternal
00084     void paste()         { m_viewInternal->doPaste();  }
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 comment()            { m_doc->comment( this, cursorLine(), 1 );      }
00200     void uncomment()          { m_doc->comment( this, cursorLine(), -1 );    }
00201     void killLine()           { m_doc->removeLine( cursorLine() );     }
00202 
00206     void uppercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Uppercase ); }
00210     void lowercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Lowercase ); }
00215     void capitalize() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Capitalize ); }
00219     void joinLines();
00220 
00221 
00222     void keyReturn()          { m_viewInternal->doReturn();          }
00223     void backspace()          { m_viewInternal->doBackspace();       }
00224     void deleteWordLeft()     { m_viewInternal->doDeleteWordLeft();  }
00225     void keyDelete()          { m_viewInternal->doDelete();          }
00226     void deleteWordRight()    { m_viewInternal->doDeleteWordRight(); }
00227     void transpose()          { m_viewInternal->doTranspose();       }
00228     void cursorLeft()         { m_viewInternal->cursorLeft();        }
00229     void shiftCursorLeft()    { m_viewInternal->cursorLeft(true);    }
00230     void cursorRight()        { m_viewInternal->cursorRight();       }
00231     void shiftCursorRight()   { m_viewInternal->cursorRight(true);   }
00232     void wordLeft()           { m_viewInternal->wordLeft();          }
00233     void shiftWordLeft()      { m_viewInternal->wordLeft(true);      }
00234     void wordRight()          { m_viewInternal->wordRight();         }
00235     void shiftWordRight()     { m_viewInternal->wordRight(true);     }
00236     void home()               { m_viewInternal->home();              }
00237     void shiftHome()          { m_viewInternal->home(true);          }
00238     void end()                { m_viewInternal->end();               }
00239     void shiftEnd()           { m_viewInternal->end(true);           }
00240     void up()                 { m_viewInternal->cursorUp();          }
00241     void shiftUp()            { m_viewInternal->cursorUp(true);      }
00242     void down()               { m_viewInternal->cursorDown();        }
00243     void shiftDown()          { m_viewInternal->cursorDown(true);    }
00244     void scrollUp()           { m_viewInternal->scrollUp();          }
00245     void scrollDown()         { m_viewInternal->scrollDown();        }
00246     void topOfView()          { m_viewInternal->topOfView();         }
00247     void shiftTopOfView()     { m_viewInternal->topOfView(true);     }
00248     void bottomOfView()       { m_viewInternal->bottomOfView();      }
00249     void shiftBottomOfView()  { m_viewInternal->bottomOfView(true);  }
00250     void pageUp()             { m_viewInternal->pageUp();            }
00251     void shiftPageUp()        { m_viewInternal->pageUp(true);        }
00252     void pageDown()           { m_viewInternal->pageDown();          }
00253     void shiftPageDown()      { m_viewInternal->pageDown(true);      }
00254     void top()                { m_viewInternal->top_home();          }
00255     void shiftTop()           { m_viewInternal->top_home(true);      }
00256     void bottom()             { m_viewInternal->bottom_end();        }
00257     void shiftBottom()        { m_viewInternal->bottom_end(true);    }
00258     void toMatchingBracket()  { m_viewInternal->cursorToMatchingBracket();}
00259     void shiftToMatchingBracket()  { m_viewInternal->cursorToMatchingBracket(true);}
00260 
00261     void gotoLine();
00262     void gotoLineNumber( int linenumber );
00263 
00264   // config file / session management functions
00265   public:
00266     void readSessionConfig(KConfig *);
00267     void writeSessionConfig(KConfig *);
00268 
00269   public slots:
00270     int getEol();
00271     void setEol( int eol );
00272     void find();
00273     void replace();
00274     void findAgain( bool back );
00275     void findAgain()              { findAgain( false );          }
00276     void findPrev()               { findAgain( true );           }
00277 
00278     void setFoldingMarkersOn( bool enable ); // Not in Kate::View, but should be
00279     void setIconBorder( bool enable );
00280     void setLineNumbersOn( bool enable );
00281     void showCmdLine ( bool enable );
00282     void toggleFoldingMarkers();
00283     void toggleIconBorder();
00284     void toggleLineNumbersOn();
00285     void toggleDynWordWrap ();
00286     void toggleCmdLine ();
00287     void setDynWrapIndicators(int mode);
00288 
00289   public:
00290     KateRenderer *renderer ();
00291 
00292     bool iconBorder();
00293     bool lineNumbersOn();
00294     int dynWrapIndicators();
00295     bool foldingMarkersOn();
00296     Kate::Document* getDoc()    { return m_doc; }
00297 
00298     void setActive( bool b )    { m_active = b; }
00299     bool isActive()             { return m_active; }
00300 
00301   public slots:
00302     void gotoMark( KTextEditor::Mark* mark ) { setCursorPositionInternal ( mark->line, 0, 1 ); }
00303     void selectionChanged ();
00304 
00305   signals:
00306     void gotFocus( Kate::View* );
00307     void lostFocus( Kate::View* );
00308     void newStatus(); // Not in Kate::View, but should be (Kate app connects to it)
00309 
00310   //
00311   // Extras
00312   //
00313   public:
00314     // Is it really necessary to have 3 methods for this?! :)
00315     KateDocument*  doc() const       { return m_doc; }
00316 
00317     KActionCollection* editActionCollection() const { return m_editActions; }
00318 
00319   public slots:
00320     void slotNewUndo();
00321     void slotUpdate();
00322     void toggleInsert();
00323     void reloadFile();
00324     void toggleWWMarker();
00325     void toggleWriteLock();
00326     void switchToCmdLine ();
00327     void slotReadWriteChanged ();
00328 
00329   signals:
00330     void dropEventPass(QDropEvent*);
00331     void viewStatusMsg (const QString &msg);
00332 
00333   public:
00334     bool setCursorPositionInternal( uint line, uint col, uint tabwidth = 1, bool calledExternally = false );
00335 
00336   protected:
00337     void contextMenuEvent( QContextMenuEvent* );
00338     bool checkOverwrite( KURL );
00339 
00340   public slots:
00341     void slotSelectionTypeChanged();
00342 
00343   private slots:
00344     void slotGotFocus();
00345     void slotLostFocus();
00346     void slotDropEventPass( QDropEvent* ev );
00347     void slotSetEncoding( const QString& descriptiveName );
00348     void slotStatusMsg();
00349     void slotSaveCanceled( const QString& error );
00350     void slotExpandToplevel();
00351     void slotCollapseLocal();
00352     void slotExpandLocal();
00353 
00354   private:
00355     void setupConnections();
00356     void setupActions();
00357     void setupEditActions();
00358     void setupCodeFolding();
00359     void setupCodeCompletion();
00360 
00361     KActionCollection*     m_editActions;
00362     KAction*               m_editUndo;
00363     KAction*               m_editRedo;
00364     KRecentFilesAction*    m_fileRecent;
00365     KToggleAction*         m_toggleFoldingMarkers;
00366     KToggleAction*         m_toggleIconBar;
00367     KToggleAction*         m_toggleLineNumbers;
00368     KToggleAction*         m_toggleDynWrap;
00369     KSelectAction*         m_setDynWrapIndicators;
00370     KToggleAction*         m_toggleWWMarker;
00371     KToggleAction*         m_toggleCmdLine;
00372 
00373     KSelectAction*         m_setEndOfLine;
00374 
00375     KSelectAction*         m_setEncoding;
00376     Kate::ActionMenu*      m_setHighlight;
00377     Kate::ActionMenu*      m_setFileType;
00378     KToggleAction*         m_toggleWriteLock;
00379     KateViewSchemaAction*  m_schemaMenu;
00380 
00381     KAction *m_cut;
00382     KAction *m_copy;
00383     KAction *m_paste;
00384     KAction *m_selectAll;
00385     KAction *m_deSelect;
00386 
00387     KToggleAction *m_toggleBlockSelection;
00388     KToggleAction *m_toggleInsert;
00389 
00390     KateDocument*          m_doc;
00391     KateViewInternal*      m_viewInternal;
00392     KateRenderer*          m_renderer;
00393     KateSearch*            m_search;
00394     KateBookmarks*         m_bookmarks;
00395     QGuardedPtr<QPopupMenu>  m_rmbMenu;
00396     KateCodeCompletion*    m_codeCompletion;
00397 
00398     KateCmdLine *m_cmdLine;
00399     bool m_cmdLineOn;
00400 
00401     QGridLayout *m_grid;
00402 
00403     bool       m_active;
00404     bool       m_hasWrap;
00405 
00406     private slots:
00407         void slotNeedTextHint(int line, int col, QString &text);
00408 
00409         void slotClipboardDataChanged();
00410 
00411         void slotHlChanged();
00415   public:
00416     inline KateViewConfig *config () { return m_config; };
00417 
00418     void updateConfig ();
00419 
00420     void updateDocumentConfig();
00421 
00422     void updateRendererConfig();
00423 
00424   private slots:
00425     void updateFoldingConfig ();
00426     void toggleBlockSelectionMode ();
00427 
00428   private:
00429     KateViewConfig *m_config;
00430     bool m_startingUp;
00431     bool m_updatingDocumentConfig;
00432 };
00433 
00434 #endif
KDE Logo
This file is part of the documentation for kate Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Aug 4 05:29:50 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003