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         { return m_doc->currentColumn(m_viewInternal->getCursor());   }
00111     uint cursorColumnReal()
00112         { return m_viewInternal->getCursor().col();                     }
00113 
00114   signals:
00115     void cursorPositionChanged();
00116 
00117   //
00118   // KTextEditor::CodeCompletionInterface
00119   //
00120   public slots:
00121     void showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 );
00122     void showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset = 0, bool cs = true );
00123 
00124   signals:
00125     void completionAborted();
00126     void completionDone();
00127     void argHintHidden();
00128     void completionDone(KTextEditor::CompletionEntry);
00129     void filterInsertString(KTextEditor::CompletionEntry*,QString *);
00130     void aboutToShowCompletionBox();
00131 
00132   //
00133   // KTextEditor::TextHintInterface
00134   //
00135   public:
00136     void enableTextHints(int timeout);
00137     void disableTextHints();
00138 
00139   signals:
00140     void needTextHint(int line, int col, QString &text);
00141 
00142   //
00143   // KTextEditor::DynWordWrapInterface
00144   //
00145   public:
00146     void setDynWordWrap( bool b );
00147     bool dynWordWrap() const      { return m_hasWrap; }
00148 
00149   // BEGIN EDIT STUFF
00150   public:
00151     void editStart ();
00152     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00153 
00154     void editSetCursor (const KateTextCursor &cursor);
00155   // END
00156 
00157   // BEGIN TAG & CLEAR
00158   public:
00159     bool tagLine (const KateTextCursor& virtualCursor);
00160 
00161     bool tagLines (int start, int end, bool realLines = false );
00162     bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00163 
00164     void tagAll ();
00165 
00166     void clear ();
00167 
00168     void repaintText (bool paintOnlyDirty = false);
00169 
00170     void updateView (bool changed = false);
00171   // END
00172 
00173   //
00174   // Kate::View
00175   //
00176   public:
00177     bool isOverwriteMode() const;
00178     void setOverwriteMode( bool b );
00179 
00180     QString currentTextLine()
00181         { return getDoc()->textLine( cursorLine() ); }
00182     QString currentWord()
00183         { return m_doc->getWord( m_viewInternal->getCursor() ); }
00184     void insertText( const QString& text )
00185         { getDoc()->insertText( cursorLine(), cursorColumnReal(), text ); }
00186     bool canDiscard();
00187     int tabWidth()                { return m_doc->config()->tabWidth(); }
00188     void setTabWidth( int w )     { m_doc->config()->setTabWidth(w);  }
00189     void setEncoding( QString e ) { m_doc->setEncoding(e);       }
00190     bool isLastView()             { return m_doc->isLastView(1); }
00191 
00192   public slots:
00193     void flush();
00194     saveResult save();
00195     saveResult saveAs();
00196 
00197     void indent()             { m_doc->indent( this, cursorLine(), 1 );       }
00198     void unIndent()           { m_doc->indent( this, cursorLine(), -1 );     }
00199     void cleanIndent()        { m_doc->indent( this, cursorLine(), 0 );  }
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 showCmdLine ( bool enable );
00283     void toggleFoldingMarkers();
00284     void toggleIconBorder();
00285     void toggleLineNumbersOn();
00286     void toggleDynWordWrap ();
00287     void toggleCmdLine ();
00288     void setDynWrapIndicators(int mode);
00289 
00290   public:
00291     KateRenderer *renderer ();
00292 
00293     bool iconBorder();
00294     bool lineNumbersOn();
00295     int dynWrapIndicators();
00296     bool foldingMarkersOn();
00297     Kate::Document* getDoc()    { return m_doc; }
00298 
00299     void setActive( bool b )    { m_active = b; }
00300     bool isActive()             { return m_active; }
00301 
00302   public slots:
00303     void gotoMark( KTextEditor::Mark* mark ) { setCursorPositionInternal ( mark->line, 0, 1 ); }
00304     void selectionChanged ();
00305 
00306   signals:
00307     void gotFocus( Kate::View* );
00308     void lostFocus( Kate::View* );
00309     void newStatus(); // Not in Kate::View, but should be (Kate app connects to it)
00310 
00311   //
00312   // Extras
00313   //
00314   public:
00315     // Is it really necessary to have 3 methods for this?! :)
00316     KateDocument*  doc() const       { return m_doc; }
00317 
00318     KActionCollection* editActionCollection() const { return m_editActions; }
00319 
00320   public slots:
00321     void slotNewUndo();
00322     void slotUpdate();
00323     void toggleInsert();
00324     void reloadFile();
00325     void toggleWWMarker();
00326     void toggleWriteLock();
00327     void switchToCmdLine ();
00328     void slotReadWriteChanged ();
00329 
00330   signals:
00331     void dropEventPass(QDropEvent*);
00332     void viewStatusMsg (const QString &msg);
00333 
00334   public:
00335     bool setCursorPositionInternal( uint line, uint col, uint tabwidth = 1, bool calledExternally = false );
00336 
00337   protected:
00338     void contextMenuEvent( QContextMenuEvent* );
00339     bool checkOverwrite( KURL );
00340 
00341   public slots:
00342     void slotSelectionTypeChanged();
00343 
00344   private slots:
00345     void slotGotFocus();
00346     void slotLostFocus();
00347     void slotDropEventPass( QDropEvent* ev );
00348     void slotSetEncoding( const QString& descriptiveName );
00349     void slotStatusMsg();
00350     void slotSaveCanceled( const QString& error );
00351     void slotExpandToplevel();
00352     void slotCollapseLocal();
00353     void slotExpandLocal();
00354 
00355   private:
00356     void setupConnections();
00357     void setupActions();
00358     void setupEditActions();
00359     void setupCodeFolding();
00360     void setupCodeCompletion();
00361 
00362     KActionCollection*     m_editActions;
00363     KAction*               m_editUndo;
00364     KAction*               m_editRedo;
00365     KRecentFilesAction*    m_fileRecent;
00366     KToggleAction*         m_toggleFoldingMarkers;
00367     KToggleAction*         m_toggleIconBar;
00368     KToggleAction*         m_toggleLineNumbers;
00369     KToggleAction*         m_toggleDynWrap;
00370     KSelectAction*         m_setDynWrapIndicators;
00371     KToggleAction*         m_toggleWWMarker;
00372     KToggleAction*         m_toggleCmdLine;
00373 
00374     KSelectAction*         m_setEndOfLine;
00375 
00376     KSelectAction*         m_setEncoding;
00377     Kate::ActionMenu*      m_setHighlight;
00378     Kate::ActionMenu*      m_setFileType;
00379     KToggleAction*         m_toggleWriteLock;
00380     KateViewSchemaAction*  m_schemaMenu;
00381 
00382     KAction *m_cut;
00383     KAction *m_copy;
00384     KAction *m_paste;
00385     KAction *m_selectAll;
00386     KAction *m_deSelect;
00387 
00388     KToggleAction *m_toggleBlockSelection;
00389     KToggleAction *m_toggleInsert;
00390 
00391     KateDocument*          m_doc;
00392     KateViewInternal*      m_viewInternal;
00393     KateRenderer*          m_renderer;
00394     KateSearch*            m_search;
00395     KateBookmarks*         m_bookmarks;
00396     QGuardedPtr<QPopupMenu>  m_rmbMenu;
00397     KateCodeCompletion*    m_codeCompletion;
00398 
00399     KateCmdLine *m_cmdLine;
00400     bool m_cmdLineOn;
00401 
00402     QGridLayout *m_grid;
00403 
00404     bool       m_active;
00405     bool       m_hasWrap;
00406 
00407     private slots:
00408         void slotNeedTextHint(int line, int col, QString &text);
00409 
00410         void slotClipboardDataChanged();
00411 
00412         void slotHlChanged();
00416   public:
00417     inline KateViewConfig *config () { return m_config; };
00418 
00419     void updateConfig ();
00420 
00421     void updateDocumentConfig();
00422 
00423     void updateRendererConfig();
00424 
00425   private slots:
00426     void updateFoldingConfig ();
00427     void toggleBlockSelectionMode ();
00428 
00429   private:
00430     KateViewConfig *m_config;
00431     bool m_startingUp;
00432     bool m_updatingDocumentConfig;
00433 };
00434 
00435 #endif
KDE Logo
This file is part of the documentation for kate Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 22 14:26:28 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003