Kate
kateview.h
Go to the documentation of this file.
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-2010 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., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef kate_view_h 00023 #define kate_view_h 00024 00025 #include <ktexteditor/view.h> 00026 #include <ktexteditor/texthintinterface.h> 00027 #include <ktexteditor/markinterface.h> 00028 #include <ktexteditor/codecompletioninterface.h> 00029 #include <ktexteditor/sessionconfiginterface.h> 00030 #include <ktexteditor/templateinterface.h> 00031 #include <ktexteditor/templateinterface2.h> 00032 #include <ktexteditor/configinterface.h> 00033 #include <ktexteditor/annotationinterface.h> 00034 00035 #include <QtCore/QPointer> 00036 #include <QModelIndex> 00037 #include <QtGui/QMenu> 00038 #include <QtCore/QLinkedList> 00039 #include <QtCore/QHash> 00040 00041 #include <kdebug.h> 00042 00043 #include "kateviinputmodemanager.h" 00044 #include "katetextrange.h" 00045 00046 namespace KTextEditor 00047 { 00048 class AnnotationModel; 00049 } 00050 00051 class KateDocument; 00052 class KateBookmarks; 00053 class KateCommandLineBar; 00054 class KateViewConfig; 00055 class KateRenderer; 00056 class KateSpellCheckDialog; 00057 class KateCompletionWidget; 00058 class KateViewInternal; 00059 class KateSearchBar; 00060 class KateViModeBar; 00061 class KateViewBar; 00062 class KateGotoBar; 00063 class KateDictionaryBar; 00064 class KateSpellingMenu; 00065 class KateRecoverBar; 00066 class KateBrokenSwapFileBar; 00067 00068 class KToggleAction; 00069 class KAction; 00070 class KRecentFilesAction; 00071 class KSelectAction; 00072 00073 class QVBoxLayout; 00074 00075 // 00076 // Kate KTextEditor::View class ;) 00077 // 00078 class KATEPART_TESTS_EXPORT KateView : public KTextEditor::View, 00079 public KTextEditor::TextHintInterface, 00080 public KTextEditor::SessionConfigInterface, 00081 public KTextEditor::TemplateInterface2, 00082 public KTextEditor::CodeCompletionInterface, 00083 public KTextEditor::ConfigInterface, 00084 public KTextEditor::AnnotationViewInterface, 00085 public KTextEditor::CoordinatesToCursorInterface 00086 { 00087 Q_OBJECT 00088 Q_INTERFACES(KTextEditor::TextHintInterface) 00089 Q_INTERFACES(KTextEditor::SessionConfigInterface) 00090 Q_INTERFACES(KTextEditor::TemplateInterface) 00091 Q_INTERFACES(KTextEditor::TemplateInterface2) 00092 Q_INTERFACES(KTextEditor::ConfigInterface) 00093 Q_INTERFACES(KTextEditor::CodeCompletionInterface) 00094 Q_INTERFACES(KTextEditor::AnnotationViewInterface) 00095 Q_INTERFACES(KTextEditor::CoordinatesToCursorInterface) 00096 00097 friend class KateViewInternal; 00098 friend class KateIconBorder; 00099 friend class KateViModeBase; 00100 00101 public: 00102 KateView( KateDocument* doc, QWidget* parent ); 00103 ~KateView (); 00104 00105 KTextEditor::Document *document () const; 00106 00107 QString viewMode () const; 00108 00109 // 00110 // KTextEditor::ClipboardInterface 00111 // 00112 public Q_SLOTS: 00113 // TODO: Factor out of m_viewInternal 00114 void paste(); 00115 void cut(); 00116 void copy() const; 00117 00118 private Q_SLOTS: 00122 void applyWordWrap (); 00123 00124 // 00125 // KTextEditor::PopupMenuInterface 00126 // 00127 public: 00128 void setContextMenu( QMenu* menu ); 00129 QMenu* contextMenu() const; 00130 QMenu* defaultContextMenu(QMenu* menu = 0L) const; 00131 00132 private Q_SLOTS: 00133 void aboutToShowContextMenu(); 00134 void aboutToHideContextMenu(); 00135 00136 private: 00137 QPointer<QMenu> m_contextMenu; 00138 00139 // 00140 // KTextEditor::ViewCursorInterface 00141 // 00142 public: 00143 bool setCursorPosition (KTextEditor::Cursor position); 00144 00145 KTextEditor::Cursor cursorPosition () const; 00146 00147 KTextEditor::Cursor cursorPositionVirtual () const; 00148 00149 QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor) const; 00150 00151 KTextEditor::Cursor coordinatesToCursor(const QPoint& coord) const; 00152 00153 QPoint cursorPositionCoordinates() const; 00154 00155 bool setCursorPositionVisual( const KTextEditor::Cursor& position ); 00156 00162 int virtualCursorColumn() const; 00163 00164 virtual bool mouseTrackingEnabled() const; 00165 virtual bool setMouseTrackingEnabled(bool enable); 00166 00167 private: 00168 void notifyMousePositionChanged(const KTextEditor::Cursor& newPosition); 00169 00170 // Internal 00171 public: 00172 bool setCursorPositionInternal( const KTextEditor::Cursor& position, uint tabwidth = 1, bool calledExternally = false ); 00173 00174 // 00175 // KTextEditor::ConfigInterface 00176 // 00177 public: 00178 QStringList configKeys() const; 00179 QVariant configValue(const QString &key); 00180 void setConfigValue(const QString &key, const QVariant &value); 00181 00182 Q_SIGNALS: 00183 void configChanged(); 00184 00185 // 00186 // KTextEditor::CodeCompletionInterface2 00187 // 00188 public: 00189 virtual bool isCompletionActive() const; 00190 virtual void startCompletion(const KTextEditor::Range& word, KTextEditor::CodeCompletionModel* model); 00191 virtual void abortCompletion(); 00192 virtual void forceCompletion(); 00193 virtual void registerCompletionModel(KTextEditor::CodeCompletionModel* model); 00194 virtual void unregisterCompletionModel(KTextEditor::CodeCompletionModel* model); 00195 virtual bool isAutomaticInvocationEnabled() const; 00196 virtual void setAutomaticInvocationEnabled(bool enabled = true); 00197 00198 Q_SIGNALS: 00199 void completionExecuted(KTextEditor::View* view, const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, const QModelIndex&); 00200 void completionAborted(KTextEditor::View* view); 00201 00202 public Q_SLOTS: 00203 void userInvokedCompletion(); 00204 00205 public: 00206 KateCompletionWidget* completionWidget() const; 00207 mutable KateCompletionWidget* m_completionWidget; 00208 void sendCompletionExecuted(const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, const QModelIndex& index); 00209 void sendCompletionAborted(); 00210 00211 // 00212 // KTextEditor::TextHintInterface 00213 // 00214 public: 00215 void enableTextHints(int timeout); 00216 void disableTextHints(); 00217 00218 Q_SIGNALS: 00219 void needTextHint(const KTextEditor::Cursor& position, QString &text); 00220 00221 public: 00222 bool dynWordWrap() const { return m_hasWrap; } 00223 00224 // 00225 // KTextEditor::SelectionInterface stuff 00226 // 00227 public Q_SLOTS: 00228 virtual bool setSelection ( const KTextEditor::Range &selection ); 00229 00230 // unhide method... 00231 bool setSelection (const KTextEditor::Cursor &c, int i, bool b) 00232 { return KTextEditor::View::setSelection (c, i, b); } 00233 00234 virtual bool removeSelection () { return clearSelection(); } 00235 00236 virtual bool removeSelectionText () { return removeSelectedText(); } 00237 00238 virtual bool setBlockSelection (bool on) { return setBlockSelectionMode (on); } 00239 00240 bool clearSelection (); 00241 bool clearSelection (bool redraw, bool finishedChangingSelection = true); 00242 00243 bool removeSelectedText (); 00244 00245 bool selectAll(); 00246 00247 public: 00248 virtual bool selection() const; 00249 virtual QString selectionText() const; 00250 virtual bool blockSelection() const { return blockSelectionMode(); } 00251 virtual const KTextEditor::Range &selectionRange() const; 00252 00253 static void blockFix(KTextEditor::Range& range); 00254 00255 private: 00256 mutable KTextEditor::Range m_holdSelectionRangeForAPI; 00257 00258 // 00259 // Arbitrary Syntax HL + Action extensions 00260 // 00261 public: 00262 // Action association extension 00263 void deactivateEditActions(); 00264 void activateEditActions(); 00265 00266 // 00267 // internal helper stuff, for katerenderer and so on 00268 // 00269 public: 00270 // should cursor be wrapped ? take config + blockselection state in account 00271 bool wrapCursor () const; 00272 00273 // some internal functions to get selection state of a line/col 00274 bool cursorSelected(const KTextEditor::Cursor& cursor); 00275 bool lineSelected (int line); 00276 bool lineEndSelected (const KTextEditor::Cursor& lineEndPos); 00277 bool lineHasSelected (int line); 00278 bool lineIsSelection (int line); 00279 00280 void ensureCursorColumnValid(); 00281 00282 void tagSelection (const KTextEditor::Range &oldSelection); 00283 00284 void selectWord( const KTextEditor::Cursor& cursor ); 00285 void selectLine( const KTextEditor::Cursor& cursor ); 00286 00287 // 00288 // KTextEditor::BlockSelectionInterface stuff 00289 // 00290 public Q_SLOTS: 00291 bool setBlockSelectionMode (bool on); 00292 bool toggleBlockSelectionMode (); 00293 00294 public: 00295 bool blockSelectionMode() const; 00296 00297 00298 //BEGIN EDIT STUFF 00299 public: 00300 void editStart (); 00301 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom); 00302 00303 void editSetCursor (const KTextEditor::Cursor &cursor); 00304 //END 00305 00306 //BEGIN TAG & CLEAR 00307 public: 00308 bool tagLine (const KTextEditor::Cursor& virtualCursor); 00309 00310 bool tagRange (const KTextEditor::Range& range, bool realLines = false); 00311 bool tagLines (int start, int end, bool realLines = false ); 00312 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false); 00313 bool tagLines (KTextEditor::Range range, bool realRange = false); 00314 00315 void tagAll (); 00316 00317 void clear (); 00318 00319 void repaintText (bool paintOnlyDirty = false); 00320 00321 void updateView (bool changed = false); 00322 //END 00323 00324 // 00325 // KTextEditor::AnnotationView 00326 // 00327 public: 00328 void setAnnotationModel( KTextEditor::AnnotationModel* model ); 00329 KTextEditor::AnnotationModel* annotationModel() const; 00330 void setAnnotationBorderVisible( bool visible); 00331 bool isAnnotationBorderVisible() const; 00332 00333 Q_SIGNALS: 00334 void annotationContextMenuAboutToShow( KTextEditor::View* view, QMenu* menu, int line ); 00335 void annotationActivated( KTextEditor::View* view, int line ); 00336 void annotationBorderVisibilityChanged( View* view, bool visible ); 00337 00338 void navigateLeft(); 00339 void navigateRight(); 00340 void navigateUp(); 00341 void navigateDown(); 00342 void navigateAccept(); 00343 void navigateBack(); 00344 00345 private: 00346 KTextEditor::AnnotationModel* m_annotationModel; 00347 00348 // 00349 // KTextEditor::View 00350 // 00351 public: 00352 void emitNavigateLeft() { 00353 emit navigateLeft(); 00354 } 00355 void emitNavigateRight() { 00356 emit navigateRight(); 00357 } 00358 void emitNavigateUp() { 00359 emit navigateUp(); 00360 } 00361 void emitNavigateDown() { 00362 emit navigateDown(); 00363 } 00364 void emitNavigateAccept() { 00365 emit navigateAccept(); 00366 } 00367 void emitNavigateBack() { 00368 emit navigateBack(); 00369 } 00373 bool isOverwriteMode() const; 00374 enum KTextEditor::View::EditMode viewEditMode() const {return isOverwriteMode() ? KTextEditor::View::EditOverwrite : KTextEditor::View::EditInsert;} 00375 QString currentTextLine(); 00376 00377 public Q_SLOTS: 00378 void indent(); 00379 void unIndent(); 00380 void cleanIndent(); 00381 void align(); 00382 void comment(); 00383 void uncomment(); 00384 void toggleComment(); 00385 void killLine(); 00386 00390 void uppercase(); 00394 void lowercase(); 00399 void capitalize(); 00403 void joinLines(); 00404 00405 // Note - the following functions simply forward to KateViewInternal 00406 void keyReturn(); 00407 void smartNewline(); 00408 void backspace(); 00409 void deleteWordLeft(); 00410 void keyDelete(); 00411 void deleteWordRight(); 00412 void transpose(); 00413 void cursorLeft(); 00414 void shiftCursorLeft(); 00415 void cursorRight(); 00416 void shiftCursorRight(); 00417 void wordLeft(); 00418 void shiftWordLeft(); 00419 void wordRight(); 00420 void shiftWordRight(); 00421 void home(); 00422 void shiftHome(); 00423 void end(); 00424 void shiftEnd(); 00425 void up(); 00426 void shiftUp(); 00427 void down(); 00428 void shiftDown(); 00429 void scrollUp(); 00430 void scrollDown(); 00431 void topOfView(); 00432 void shiftTopOfView(); 00433 void bottomOfView(); 00434 void shiftBottomOfView(); 00435 void pageUp(); 00436 void shiftPageUp(); 00437 void pageDown(); 00438 void shiftPageDown(); 00439 void top(); 00440 void shiftTop(); 00441 void bottom(); 00442 void shiftBottom(); 00443 void toMatchingBracket(); 00444 void shiftToMatchingBracket(); 00445 void insertTab(); 00446 00447 void gotoLine(); 00448 00449 // config file / session management functions 00450 public: 00451 void readSessionConfig(const KConfigGroup&); 00452 void writeSessionConfig(KConfigGroup&); 00453 00454 public Q_SLOTS: 00455 void setEol( int eol ); 00456 void setAddBom( bool enabled); 00457 void find(); 00458 void findSelectedForwards(); 00459 void findSelectedBackwards(); 00460 void replace(); 00461 void findNext(); 00462 void findPrevious(); 00463 00464 void setFoldingMarkersOn( bool enable ); // Not in KTextEditor::View, but should be 00465 void setIconBorder( bool enable ); 00466 void setLineNumbersOn( bool enable ); 00467 void setScrollBarMarks( bool enable ); 00468 void toggleFoldingMarkers(); 00469 void toggleIconBorder(); 00470 void toggleLineNumbersOn(); 00471 void toggleScrollBarMarks(); 00472 void toggleDynWordWrap (); 00473 void toggleViInputMode (); 00474 void showViModeBar (); 00475 void hideViModeBar (); 00476 void setDynWrapIndicators(int mode); 00477 00478 public: 00479 int getEol() const; 00480 00481 public: 00482 KateRenderer *renderer (); 00483 00484 bool iconBorder(); 00485 bool lineNumbersOn(); 00486 bool scrollBarMarks(); 00487 int dynWrapIndicators(); 00488 bool foldingMarkersOn(); 00489 00490 private Q_SLOTS: 00494 void slotSelectionChanged (); 00495 00496 public: 00501 KateDocument* doc() { return m_doc; } 00502 const KateDocument* doc() const { return m_doc; } 00503 00504 public Q_SLOTS: 00505 void slotUpdateUndo(); 00506 void toggleInsert(); 00507 void reloadFile(); 00508 void toggleWWMarker(); 00509 void toggleWriteLock(); 00510 void switchToCmdLine (); 00511 void slotReadWriteChanged (); 00512 00513 Q_SIGNALS: 00514 void dropEventPass(QDropEvent*); 00515 00516 public: 00517 void slotTextInserted ( KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text); 00518 00519 protected: 00520 void contextMenuEvent( QContextMenuEvent* ); 00521 00522 private Q_SLOTS: 00523 void slotGotFocus(); 00524 void slotLostFocus(); 00525 void slotDropEventPass( QDropEvent* ev ); 00526 void slotSaveCanceled( const QString& error ); 00527 void slotExpandToplevel(); 00528 void slotCollapseLocal(); 00529 void slotExpandLocal(); 00530 void slotConfigDialog (); 00531 00532 private: 00533 void setupConnections(); 00534 void setupActions(); 00535 void setupEditActions(); 00536 void setupCodeFolding(); 00537 00538 QList<QAction*> m_editActions; 00539 KAction* m_editUndo; 00540 KAction* m_editRedo; 00541 KRecentFilesAction* m_fileRecent; 00542 KToggleAction* m_toggleFoldingMarkers; 00543 KToggleAction* m_toggleIconBar; 00544 KToggleAction* m_toggleLineNumbers; 00545 KToggleAction* m_toggleScrollBarMarks; 00546 KToggleAction* m_toggleDynWrap; 00547 KSelectAction* m_setDynWrapIndicators; 00548 KToggleAction* m_toggleWWMarker; 00549 KAction* m_switchCmdLine; 00550 KToggleAction* m_viInputModeAction; 00551 00552 KSelectAction* m_setEndOfLine; 00553 KToggleAction* m_addBom; 00554 00555 QAction *m_cut; 00556 QAction *m_copy; 00557 QAction *m_paste; 00558 QAction *m_selectAll; 00559 QAction *m_deSelect; 00560 00561 KToggleAction *m_toggleBlockSelection; 00562 KToggleAction *m_toggleInsert; 00563 KToggleAction *m_toggleWriteLock; 00564 00565 bool m_hasWrap; 00566 00567 KateDocument *const m_doc; 00568 KateViewConfig *const m_config; 00569 KateRenderer *const m_renderer; 00570 KateViewInternal *const m_viewInternal; 00571 KateSpellCheckDialog *m_spell; 00572 KateBookmarks *const m_bookmarks; 00573 00574 QVBoxLayout *m_vBox; 00575 00576 private Q_SLOTS: 00577 void slotHlChanged(); 00578 00582 public: 00583 inline KateViewConfig *config () { return m_config; } 00584 00585 void updateConfig (); 00586 00587 void updateDocumentConfig(); 00588 00589 void updateRendererConfig(); 00590 00591 private Q_SLOTS: 00592 void updateFoldingConfig (); 00593 00594 private: 00595 bool m_startingUp; 00596 bool m_updatingDocumentConfig; 00597 00598 // stores the current selection 00599 Kate::TextRange m_selection; 00600 00601 // do we select normal or blockwise ? 00602 bool blockSelect; 00603 00604 // 00605 // TemplateInterface + TemplateInterface2 00606 // 00607 public: 00608 virtual bool insertTemplateTextImplementation ( const KTextEditor::Cursor&, const QString &templateString, const QMap<QString,QString> &initialValues); 00609 virtual bool insertTemplateTextImplementation ( const KTextEditor::Cursor&, const QString &templateString, const QMap<QString,QString> &initialValues, KTextEditor::TemplateScript* templateScript); 00613 public: 00614 KateViewBar *topViewBar() const; 00615 KateViewBar *bottomViewBar() const; 00616 KateCommandLineBar *cmdLineBar (); 00617 KateDictionaryBar *dictionaryBar(); 00618 00619 private: 00620 KateSearchBar *searchBar (bool initHintAsPower = false); 00621 bool hasSearchBar () const { return m_searchBar != 0; } 00622 KateViModeBar *viModeBar(); 00623 KateGotoBar *gotoBar (); 00624 KateRecoverBar *recoverBar(); 00625 KateBrokenSwapFileBar *brokenSwapFileBar(); 00626 00631 private: 00632 // created in constructor of the view 00633 KateViewBar *m_bottomViewBar; 00634 KateViewBar *m_topViewBar; 00635 KateRecoverBar *m_recoverBar; 00636 KateBrokenSwapFileBar *m_brokenSwapFileBar; 00637 // created on demand..., only access them through the above accessors.... 00638 KateCommandLineBar *m_cmdLine; 00639 KateSearchBar *m_searchBar; 00640 KateViModeBar *m_viModeBar; 00641 KateGotoBar *m_gotoBar; 00642 KateDictionaryBar *m_dictionaryBar; 00643 00644 // vi Mode 00645 public: 00649 bool viInputMode() const; 00650 00654 ViMode getCurrentViMode() const; 00655 00659 KateViInputModeManager* getViInputModeManager(); 00660 00664 bool viInputModeStealKeys() const; 00665 00669 void updateViModeBarMode(); 00670 00674 void updateViModeBarCmd(); 00675 00676 public: 00677 KTextEditor::Range visibleRange(); 00678 00679 Q_SIGNALS: 00680 void displayRangeChanged(KateView *view); 00681 00682 protected: 00683 KToggleAction* m_toggleOnTheFlySpellCheck; 00684 KateSpellingMenu *m_spellingMenu; 00685 00686 protected Q_SLOTS: 00687 void toggleOnTheFlySpellCheck(bool b); 00688 void showRecoverBar(); 00689 void showBrokenSwapFileBar(); 00690 00691 public Q_SLOTS: 00692 void changeDictionary(); 00693 void reflectOnTheFlySpellCheckStatus(bool enabled); 00694 void hideRecoverBar(); 00695 void hideBrokenSwapFileBar(); 00696 00697 public: 00698 KateSpellingMenu* spellingMenu(); 00699 private: 00700 bool m_userContextMenuSet; 00701 00702 public: 00709 void notifyAboutRangeChange (int startLine, int endLine, bool rangeWithAttribute); 00710 00711 private Q_SLOTS: 00715 void slotDelayedUpdateOfView (); 00716 00717 Q_SIGNALS: 00721 void delayedUpdateOfView (); 00722 00723 public: 00728 const QSet<Kate::TextRange *> *rangesMouseIn () const { return &m_rangesMouseIn; } 00729 00734 const QSet<Kate::TextRange *> *rangesCaretIn () const { return &m_rangesCaretIn; } 00735 00740 void updateRangesIn (KTextEditor::Attribute::ActivationType activationType); 00741 00742 // 00743 // helpers for delayed view update after ranges changes 00744 // 00745 private: 00749 bool m_delayedUpdateTriggered; 00750 00754 int m_lineToUpdateMin; 00755 00759 int m_lineToUpdateMax; 00760 00764 QSet<Kate::TextRange *> m_rangesMouseIn; 00765 00769 QSet<Kate::TextRange *> m_rangesCaretIn; 00770 }; 00771 00775 Q_DECLARE_METATYPE(KTextEditor::Cursor) 00776 Q_DECLARE_METATYPE(KTextEditor::Range) 00777 00778 #endif 00779 00780 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference