00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef kate_view_h
00023 #define kate_view_h
00024
00025 #include "katetextline.h"
00026 #include "kateviinputmodemanager.h"
00027
00028 #include <ktexteditor/view.h>
00029 #include <ktexteditor/texthintinterface.h>
00030 #include <ktexteditor/markinterface.h>
00031 #include <ktexteditor/codecompletioninterface.h>
00032 #include <ktexteditor/sessionconfiginterface.h>
00033 #include <ktexteditor/templateinterface.h>
00034 #include <ktexteditor/rangefeedback.h>
00035 #include <ktexteditor/configinterface.h>
00036 #include <ktexteditor/annotationinterface.h>
00037
00038 #include <QtCore/QPointer>
00039 #include <QModelIndex>
00040 #include <QtGui/QMenu>
00041 #include <QtCore/QLinkedList>
00042 #include <QtCore/QHash>
00043
00044 #include <kdebug.h>
00045
00046 namespace KTextEditor
00047 {
00048 class AnnotationModel;
00049 }
00050
00051 class KateDocument;
00052 class KateBookmarks;
00053 class KateCmdLine;
00054 class KateViewConfig;
00055 class KateRenderer;
00056 class KateSpell;
00057 class KateCompletionWidget;
00058 class KateSmartRange;
00059 class KateViewInternal;
00060 class KateSearchBar;
00061 class KateViModeBar;
00062 class KateViewBar;
00063 class KateGotoBar;
00064
00065 class KToggleAction;
00066 class KAction;
00067 class KRecentFilesAction;
00068 class KSelectAction;
00069
00070 class QVBoxLayout;
00071
00072
00073
00074
00075 class KateView : public KTextEditor::View,
00076 public KTextEditor::TextHintInterface,
00077 public KTextEditor::SessionConfigInterface,
00078 public KTextEditor::TemplateInterface,
00079 public KTextEditor::CodeCompletionInterface,
00080 public KTextEditor::ConfigInterface,
00081 private KTextEditor::SmartRangeWatcher,
00082 public KTextEditor::AnnotationViewInterface,
00083 public KTextEditor::CoordinatesToCursorInterface
00084 {
00085 Q_OBJECT
00086 Q_INTERFACES(KTextEditor::TextHintInterface)
00087 Q_INTERFACES(KTextEditor::SessionConfigInterface)
00088 Q_INTERFACES(KTextEditor::TemplateInterface)
00089 Q_INTERFACES(KTextEditor::ConfigInterface)
00090 Q_INTERFACES(KTextEditor::CodeCompletionInterface)
00091 Q_INTERFACES(KTextEditor::AnnotationViewInterface)
00092 Q_INTERFACES(KTextEditor::CoordinatesToCursorInterface)
00093
00094 friend class KateViewInternal;
00095 friend class KateIconBorder;
00096 friend class KateSearchBar;
00097 friend class KateViModeBase;
00098
00099 public:
00100 KateView( KateDocument* doc, QWidget* parent );
00101 ~KateView ();
00102
00103 KTextEditor::Document *document () const;
00104
00105 QString viewMode () const;
00106
00107
00108
00109
00110 public Q_SLOTS:
00111
00112 void paste();
00113 void cut();
00114 void copy() const;
00115
00116 private Q_SLOTS:
00120 void copyHTML();
00121
00125 void applyWordWrap ();
00126
00127
00128 private:
00129 QString selectionAsHtml ();
00130 QString textAsHtml ( KTextEditor::Range range, bool blockwise);
00131 void textAsHtmlStream ( const KTextEditor::Range& range, bool blockwise, QTextStream *ts);
00132
00145 void lineAsHTML (KateTextLine::Ptr line, int startCol, int length, QTextStream *outputStream);
00146
00147 public Q_SLOTS:
00148 void exportAsHTML ();
00149
00150
00151
00152
00153 public:
00154 void setContextMenu( QMenu* menu );
00155 QMenu* contextMenu() const;
00156 QMenu* defaultContextMenu(QMenu* menu = 0L) const;
00157
00158 private Q_SLOTS:
00159 void aboutToShowContextMenu();
00160
00161 private:
00162 QPointer<QMenu> m_contextMenu;
00163
00164
00165
00166
00167 public:
00168 bool setCursorPosition (KTextEditor::Cursor position);
00169
00170 KTextEditor::Cursor cursorPosition () const;
00171
00172 KTextEditor::Cursor cursorPositionVirtual () const;
00173
00174 QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor) const;
00175
00176 KTextEditor::Cursor coordinatesToCursor(const QPoint& coord) const;
00177
00178 QPoint cursorPositionCoordinates() const;
00179
00180 bool setCursorPositionVisual( const KTextEditor::Cursor& position );
00181
00187 int virtualCursorColumn() const;
00188
00189 virtual bool mouseTrackingEnabled() const;
00190 virtual bool setMouseTrackingEnabled(bool enable);
00191
00192 private:
00193 void notifyMousePositionChanged(const KTextEditor::Cursor& newPosition);
00194
00195
00196 public:
00197 bool setCursorPositionInternal( const KTextEditor::Cursor& position, uint tabwidth = 1, bool calledExternally = false );
00198
00199
00200
00201
00202 public:
00203 QStringList configKeys() const;
00204 QVariant configValue(const QString &key);
00205 void setConfigValue(const QString &key, const QVariant &value);
00206
00207
00208
00209
00210 public:
00211 virtual bool isCompletionActive() const;
00212 virtual void startCompletion(const KTextEditor::Range& word, KTextEditor::CodeCompletionModel* model);
00213 virtual void abortCompletion();
00214 virtual void forceCompletion();
00215 virtual void registerCompletionModel(KTextEditor::CodeCompletionModel* model);
00216 virtual void unregisterCompletionModel(KTextEditor::CodeCompletionModel* model);
00217 virtual bool isAutomaticInvocationEnabled() const;
00218 virtual void setAutomaticInvocationEnabled(bool enabled = true);
00219
00220 Q_SIGNALS:
00221 void completionExecuted(KTextEditor::View* view, const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, const QModelIndex&);
00222 void completionAborted(KTextEditor::View* view);
00223
00224 public Q_SLOTS:
00225 void userInvokedCompletion();
00226
00227 public:
00228 KateCompletionWidget* completionWidget() const;
00229 mutable KateCompletionWidget* m_completionWidget;
00230 void sendCompletionExecuted(const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, const QModelIndex& index);
00231 void sendCompletionAborted();
00232
00233
00234
00235
00236 public:
00237 void enableTextHints(int timeout);
00238 void disableTextHints();
00239
00240 Q_SIGNALS:
00241 void needTextHint(const KTextEditor::Cursor& position, QString &text);
00242
00243 public:
00244 bool dynWordWrap() const { return m_hasWrap; }
00245
00246
00247
00248
00249 public Q_SLOTS:
00250 virtual bool setSelection ( const KTextEditor::Range &selection );
00251
00252
00253 bool setSelection (const KTextEditor::Cursor &c, int i, bool b)
00254 { return KTextEditor::View::setSelection (c, i, b); }
00255
00256 virtual bool removeSelection () { return clearSelection(); }
00257
00258 virtual bool removeSelectionText () { return removeSelectedText(); }
00259
00260 virtual bool setBlockSelection (bool on) { return setBlockSelectionMode (on); }
00261
00262 bool clearSelection ();
00263 bool clearSelection (bool redraw, bool finishedChangingSelection = true);
00264
00265 bool removeSelectedText ();
00266
00267 bool selectAll();
00268
00269 public:
00270 virtual bool selection() const;
00271 virtual QString selectionText() const;
00272 virtual bool blockSelection() const { return blockSelectionMode(); }
00273 virtual const KTextEditor::Range &selectionRange() const;
00274
00275 private:
00276
00277 mutable KTextEditor::Range m_holdSelectionRangeForAPI;
00278
00279
00280
00281
00282 public:
00283
00284 void addExternalHighlight(KTextEditor::SmartRange* topRange, bool supportDynamic);
00285 const QList<KTextEditor::SmartRange*>& externalHighlights() const;
00286 void clearExternalHighlights();
00287
00288 void addInternalHighlight(KTextEditor::SmartRange* topRange);
00289 void removeInternalHighlight(KTextEditor::SmartRange* topRange);
00290 const QList<KTextEditor::SmartRange*>& internalHighlights() const;
00291
00292
00293 void addActions(KTextEditor::SmartRange* topRange);
00294 const QList<KTextEditor::SmartRange*>& actions() const;
00295 void clearActions();
00296 void deactivateEditActions();
00297 void activateEditActions();
00298
00299 Q_SIGNALS:
00300 void dynamicHighlightAdded(KateSmartRange* range);
00301 void dynamicHighlightRemoved(KateSmartRange* range);
00302
00303 public Q_SLOTS:
00304 void removeExternalHighlight(KTextEditor::SmartRange* topRange);
00305 void removeActions(KTextEditor::SmartRange* topRange);
00306
00307 private:
00308
00309 virtual void rangeDeleted(KTextEditor::SmartRange* range);
00310
00311 QList<KTextEditor::SmartRange*> m_externalHighlights;
00312 QList<KTextEditor::SmartRange*> m_externalHighlightsDynamic;
00313 QList<KTextEditor::SmartRange*> m_internalHighlights;
00314 QList<KTextEditor::SmartRange*> m_actions;
00315
00316 bool m_bottomBarExternal;
00317 bool m_topBarExternal;
00318
00319
00320
00321
00322 public:
00323
00324 bool wrapCursor ();
00325
00326
00327 bool cursorSelected(const KTextEditor::Cursor& cursor);
00328 bool lineSelected (int line);
00329 bool lineEndSelected (const KTextEditor::Cursor& lineEndPos);
00330 bool lineHasSelected (int line);
00331 bool lineIsSelection (int line);
00332
00333 void ensureCursorColumnValid();
00334
00335 void tagSelection (const KTextEditor::Range &oldSelection);
00336
00337 void selectWord( const KTextEditor::Cursor& cursor );
00338 void selectLine( const KTextEditor::Cursor& cursor );
00339
00340
00341
00342
00343 public Q_SLOTS:
00344 bool setBlockSelectionMode (bool on);
00345 bool toggleBlockSelectionMode ();
00346
00347 public:
00348 bool blockSelectionMode() const;
00349
00350
00351
00352 public:
00353 void editStart ();
00354 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00355
00356 void editSetCursor (const KTextEditor::Cursor &cursor);
00357
00358
00359
00360 public:
00361 bool tagLine (const KTextEditor::Cursor& virtualCursor);
00362
00363 bool tagRange (const KTextEditor::Range& range, bool realLines = false);
00364 bool tagLines (int start, int end, bool realLines = false );
00365 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00366 bool tagLines (KTextEditor::Range range, bool realRange = false);
00367
00368 void tagAll ();
00369
00370 void relayoutRange(const KTextEditor::Range& range, bool realLines = false);
00371
00372 void clear ();
00373
00374 void repaintText (bool paintOnlyDirty = false);
00375
00376 void updateView (bool changed = false);
00377
00378
00379
00380
00381
00382 public:
00383 void setAnnotationModel( KTextEditor::AnnotationModel* model );
00384 KTextEditor::AnnotationModel* annotationModel() const;
00385 void setAnnotationBorderVisible( bool visible);
00386 bool isAnnotationBorderVisible() const;
00387
00388 Q_SIGNALS:
00389 void annotationContextMenuAboutToShow( KTextEditor::View* view, QMenu* menu, int line );
00390 void annotationActivated( KTextEditor::View* view, int line );
00391 void annotationBorderVisibilityChanged( View* view, bool visible );
00392
00393 void navigateLeft();
00394 void navigateRight();
00395 void navigateUp();
00396 void navigateDown();
00397 void navigateAccept();
00398 void navigateBack();
00399
00400 private:
00401 KTextEditor::AnnotationModel* m_annotationModel;
00402
00403
00404
00405
00406 public:
00407 void emitNavigateLeft() {
00408 emit navigateLeft();
00409 }
00410 void emitNavigateRight() {
00411 emit navigateRight();
00412 }
00413 void emitNavigateUp() {
00414 emit navigateUp();
00415 }
00416 void emitNavigateDown() {
00417 emit navigateDown();
00418 }
00419 void emitNavigateAccept() {
00420 emit navigateAccept();
00421 }
00422 void emitNavigateBack() {
00423 emit navigateBack();
00424 }
00428 bool isOverwriteMode() const;
00429 enum KTextEditor::View::EditMode viewEditMode() const {return isOverwriteMode() ? KTextEditor::View::EditOverwrite : KTextEditor::View::EditInsert;}
00430 QString currentTextLine();
00431 QString currentWord();
00432
00433 public Q_SLOTS:
00434 void indent();
00435 void unIndent();
00436 void cleanIndent();
00437 void align();
00438 void comment();
00439 void uncomment();
00440 void killLine();
00441
00445 void uppercase();
00449 void lowercase();
00454 void capitalize();
00458 void joinLines();
00459
00460
00461 void keyReturn();
00462 void smartNewline();
00463 void backspace();
00464 void deleteWordLeft();
00465 void keyDelete();
00466 void deleteWordRight();
00467 void transpose();
00468 void cursorLeft();
00469 void shiftCursorLeft();
00470 void cursorRight();
00471 void shiftCursorRight();
00472 void wordLeft();
00473 void shiftWordLeft();
00474 void wordRight();
00475 void shiftWordRight();
00476 void home();
00477 void shiftHome();
00478 void end();
00479 void shiftEnd();
00480 void up();
00481 void shiftUp();
00482 void down();
00483 void shiftDown();
00484 void scrollUp();
00485 void scrollDown();
00486 void topOfView();
00487 void shiftTopOfView();
00488 void bottomOfView();
00489 void shiftBottomOfView();
00490 void pageUp();
00491 void shiftPageUp();
00492 void pageDown();
00493 void shiftPageDown();
00494 void top();
00495 void shiftTop();
00496 void bottom();
00497 void shiftBottom();
00498 void toMatchingBracket();
00499 void shiftToMatchingBracket();
00500
00501 void gotoLine();
00502
00503
00504 public:
00505 void readSessionConfig(const KConfigGroup&);
00506 void writeSessionConfig(KConfigGroup&);
00507
00508 public Q_SLOTS:
00509 void setEol( int eol );
00510 void find();
00511 void findSelectedForwards();
00512 void findSelectedBackwards();
00513 void replace();
00514 void findNext();
00515 void findPrevious();
00516
00517 void setFoldingMarkersOn( bool enable );
00518 void setIconBorder( bool enable );
00519 void setLineNumbersOn( bool enable );
00520 void setScrollBarMarks( bool enable );
00521 void toggleFoldingMarkers();
00522 void toggleIconBorder();
00523 void toggleLineNumbersOn();
00524 void toggleScrollBarMarks();
00525 void toggleDynWordWrap ();
00526 void toggleViInputMode ();
00527 void showViModeBar ();
00528 void hideViModeBar ();
00529 void setDynWrapIndicators(int mode);
00530
00531 public:
00532 int getEol() const;
00533
00534 public:
00535 KateRenderer *renderer ();
00536
00537 bool iconBorder();
00538 bool lineNumbersOn();
00539 bool scrollBarMarks();
00540 int dynWrapIndicators();
00541 bool foldingMarkersOn();
00542
00543 private Q_SLOTS:
00547 void slotSelectionChanged ();
00548
00549 public:
00554 inline KateDocument* doc() { return m_doc; }
00555
00556 public Q_SLOTS:
00557 void slotUpdateUndo();
00558 void toggleInsert();
00559 void reloadFile();
00560 void toggleWWMarker();
00561 void toggleWriteLock();
00562 void switchToCmdLine ();
00563 void slotReadWriteChanged ();
00564
00565 Q_SIGNALS:
00566 void dropEventPass(QDropEvent*);
00567
00568 public:
00569 void slotTextInserted ( KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
00570
00571 protected:
00572 void contextMenuEvent( QContextMenuEvent* );
00573
00574 private Q_SLOTS:
00575 void slotGotFocus();
00576 void slotLostFocus();
00577 void slotDropEventPass( QDropEvent* ev );
00578 void slotSaveCanceled( const QString& error );
00579 void slotExpandToplevel();
00580 void slotCollapseLocal();
00581 void slotExpandLocal();
00582 void slotConfigDialog ();
00583
00584 private:
00585 void setupConnections();
00586 void setupActions();
00587 void setupEditActions();
00588 void setupCodeFolding();
00589
00590 QList<QAction*> m_editActions;
00591 KAction* m_editUndo;
00592 KAction* m_editRedo;
00593 KRecentFilesAction* m_fileRecent;
00594 KToggleAction* m_toggleFoldingMarkers;
00595 KToggleAction* m_toggleIconBar;
00596 KToggleAction* m_toggleLineNumbers;
00597 KToggleAction* m_toggleScrollBarMarks;
00598 KToggleAction* m_toggleDynWrap;
00599 KSelectAction* m_setDynWrapIndicators;
00600 KToggleAction* m_toggleWWMarker;
00601 KAction* m_switchCmdLine;
00602 KToggleAction* m_viInputModeAction;
00603
00604 KSelectAction* m_setEndOfLine;
00605
00606 QAction *m_cut;
00607 QAction *m_copy;
00608 QAction *m_copyHTML;
00609 QAction *m_paste;
00610 QAction *m_selectAll;
00611 QAction *m_deSelect;
00612
00613 KToggleAction *m_toggleBlockSelection;
00614 KToggleAction *m_toggleInsert;
00615 KToggleAction *m_toggleWriteLock;
00616
00617 KateDocument* m_doc;
00618 KateViewInternal* m_viewInternal;
00619 KateRenderer* m_renderer;
00620 KateSpell *m_spell;
00621 KateBookmarks* m_bookmarks;
00622
00623 QVBoxLayout *m_vBox;
00624
00625 bool m_hasWrap;
00626
00627 private Q_SLOTS:
00628 void slotNeedTextHint(int line, int col, QString &text);
00629 void slotHlChanged();
00630
00634 public:
00635 inline KateViewConfig *config () { return m_config; }
00636
00637 void updateConfig ();
00638
00639 void updateDocumentConfig();
00640
00641 void updateRendererConfig();
00642
00643 private Q_SLOTS:
00644 void updateFoldingConfig ();
00645
00646 private:
00647 KateViewConfig *m_config;
00648 bool m_startingUp;
00649 bool m_updatingDocumentConfig;
00650
00651
00652 KateSmartRange* m_selection;
00653
00654
00655 bool blockSelect;
00656
00658 public:
00659 virtual bool insertTemplateTextImplementation ( const KTextEditor::Cursor&, const QString &templateString, const QMap<QString,QString> &initialValues);
00660
00661
00665 public:
00666 KateViewBar *viewBar() const;
00667 KateCmdLine *cmdLine ();
00668 KateSearchBar *searchBar (bool initHintAsPower = false);
00669 KateViModeBar *viModeBar();
00670 KateGotoBar *gotoBar ();
00675 private:
00676
00677 KateViewBar *m_bottomViewBar;
00678 KateViewBar *m_topViewBar;
00679
00680 KateCmdLine *m_cmdLine;
00681 KateSearchBar *m_searchBar;
00682 KateViModeBar *m_viModeBar;
00683 KateGotoBar *m_gotoBar;
00684
00685
00686 public:
00690 bool viInputMode() const;
00691
00695 ViMode getCurrentViMode() const;
00696
00700 KateViInputModeManager* getViInputModeManager();
00701
00705 bool viInputModeStealKeys() const;
00706
00710 void updateViModeBarMode();
00711
00715 void updateViModeBarCmd();
00716 };
00717
00721 Q_DECLARE_METATYPE(KTextEditor::Cursor)
00722
00723 #endif
00724
00725