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 private Q_SLOTS:
00270 bool selectAllByAction();
00271 public:
00272 virtual bool selection() const;
00273 virtual QString selectionText() const;
00274 virtual bool blockSelection() const { return blockSelectionMode(); }
00275 virtual const KTextEditor::Range &selectionRange() const;
00276
00277 private:
00278
00279 mutable KTextEditor::Range m_holdSelectionRangeForAPI;
00280
00281
00282
00283
00284 public:
00285
00286 void addExternalHighlight(KTextEditor::SmartRange* topRange, bool supportDynamic);
00287 const QList<KTextEditor::SmartRange*>& externalHighlights() const;
00288 void clearExternalHighlights();
00289
00290 void addInternalHighlight(KTextEditor::SmartRange* topRange);
00291 void removeInternalHighlight(KTextEditor::SmartRange* topRange);
00292 const QList<KTextEditor::SmartRange*>& internalHighlights() const;
00293
00294
00295 void addActions(KTextEditor::SmartRange* topRange);
00296 const QList<KTextEditor::SmartRange*>& actions() const;
00297 void clearActions();
00298 void deactivateEditActions();
00299 void activateEditActions();
00300
00301 Q_SIGNALS:
00302 void dynamicHighlightAdded(KateSmartRange* range);
00303 void dynamicHighlightRemoved(KateSmartRange* range);
00304
00305 public Q_SLOTS:
00306 void removeExternalHighlight(KTextEditor::SmartRange* topRange);
00307 void removeActions(KTextEditor::SmartRange* topRange);
00308
00309 private:
00310
00311 virtual void rangeDeleted(KTextEditor::SmartRange* range);
00312
00313 QList<KTextEditor::SmartRange*> m_externalHighlights;
00314 QList<KTextEditor::SmartRange*> m_externalHighlightsDynamic;
00315 QList<KTextEditor::SmartRange*> m_internalHighlights;
00316 QList<KTextEditor::SmartRange*> m_actions;
00317
00318 bool m_bottomBarExternal;
00319 bool m_topBarExternal;
00320
00321
00322
00323
00324 public:
00325
00326 bool wrapCursor ();
00327
00328
00329 bool cursorSelected(const KTextEditor::Cursor& cursor);
00330 bool lineSelected (int line);
00331 bool lineEndSelected (const KTextEditor::Cursor& lineEndPos);
00332 bool lineHasSelected (int line);
00333 bool lineIsSelection (int line);
00334
00335 void ensureCursorColumnValid();
00336
00337 void tagSelection (const KTextEditor::Range &oldSelection);
00338
00339 void selectWord( const KTextEditor::Cursor& cursor );
00340 void selectLine( const KTextEditor::Cursor& cursor );
00341
00342
00343
00344
00345 public Q_SLOTS:
00346 bool setBlockSelectionMode (bool on);
00347 bool toggleBlockSelectionMode ();
00348
00349 public:
00350 bool blockSelectionMode() const;
00351
00352
00353
00354 public:
00355 void editStart ();
00356 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00357
00358 void editSetCursor (const KTextEditor::Cursor &cursor);
00359
00360
00361
00362 public:
00363 bool tagLine (const KTextEditor::Cursor& virtualCursor);
00364
00365 bool tagRange (const KTextEditor::Range& range, bool realLines = false);
00366 bool tagLines (int start, int end, bool realLines = false );
00367 bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00368 bool tagLines (KTextEditor::Range range, bool realRange = false);
00369
00370 void tagAll ();
00371
00372 void relayoutRange(const KTextEditor::Range& range, bool realLines = false);
00373
00374 void clear ();
00375
00376 void repaintText (bool paintOnlyDirty = false);
00377
00378 void updateView (bool changed = false);
00379
00380
00381
00382
00383
00384 public:
00385 void setAnnotationModel( KTextEditor::AnnotationModel* model );
00386 KTextEditor::AnnotationModel* annotationModel() const;
00387 void setAnnotationBorderVisible( bool visible);
00388 bool isAnnotationBorderVisible() const;
00389
00390 Q_SIGNALS:
00391 void annotationContextMenuAboutToShow( KTextEditor::View* view, QMenu* menu, int line );
00392 void annotationActivated( KTextEditor::View* view, int line );
00393 void annotationBorderVisibilityChanged( View* view, bool visible );
00394
00395 void navigateLeft();
00396 void navigateRight();
00397 void navigateUp();
00398 void navigateDown();
00399 void navigateAccept();
00400 void navigateBack();
00401
00402 private:
00403 KTextEditor::AnnotationModel* m_annotationModel;
00404
00405
00406
00407
00408 public:
00409 void emitNavigateLeft() {
00410 emit navigateLeft();
00411 }
00412 void emitNavigateRight() {
00413 emit navigateRight();
00414 }
00415 void emitNavigateUp() {
00416 emit navigateUp();
00417 }
00418 void emitNavigateDown() {
00419 emit navigateDown();
00420 }
00421 void emitNavigateAccept() {
00422 emit navigateAccept();
00423 }
00424 void emitNavigateBack() {
00425 emit navigateBack();
00426 }
00430 bool isOverwriteMode() const;
00431 enum KTextEditor::View::EditMode viewEditMode() const {return isOverwriteMode() ? KTextEditor::View::EditOverwrite : KTextEditor::View::EditInsert;}
00432 QString currentTextLine();
00433 QString currentWord();
00434
00435 public Q_SLOTS:
00436 void indent();
00437 void unIndent();
00438 void cleanIndent();
00439 void align();
00440 void comment();
00441 void uncomment();
00442 void killLine();
00443
00447 void uppercase();
00451 void lowercase();
00456 void capitalize();
00460 void joinLines();
00461
00462
00463 void keyReturn();
00464 void smartNewline();
00465 void backspace();
00466 void deleteWordLeft();
00467 void keyDelete();
00468 void deleteWordRight();
00469 void transpose();
00470 void cursorLeft();
00471 void shiftCursorLeft();
00472 void cursorRight();
00473 void shiftCursorRight();
00474 void wordLeft();
00475 void shiftWordLeft();
00476 void wordRight();
00477 void shiftWordRight();
00478 void home();
00479 void shiftHome();
00480 void end();
00481 void shiftEnd();
00482 void up();
00483 void shiftUp();
00484 void down();
00485 void shiftDown();
00486 void scrollUp();
00487 void scrollDown();
00488 void topOfView();
00489 void shiftTopOfView();
00490 void bottomOfView();
00491 void shiftBottomOfView();
00492 void pageUp();
00493 void shiftPageUp();
00494 void pageDown();
00495 void shiftPageDown();
00496 void top();
00497 void shiftTop();
00498 void bottom();
00499 void shiftBottom();
00500 void toMatchingBracket();
00501 void shiftToMatchingBracket();
00502
00503 void gotoLine();
00504
00505
00506 public:
00507 void readSessionConfig(const KConfigGroup&);
00508 void writeSessionConfig(KConfigGroup&);
00509
00510 public Q_SLOTS:
00511 void setEol( int eol );
00512 void find();
00513 void findSelectedForwards();
00514 void findSelectedBackwards();
00515 void replace();
00516 void findNext();
00517 void findPrevious();
00518
00519 void setFoldingMarkersOn( bool enable );
00520 void setIconBorder( bool enable );
00521 void setLineNumbersOn( bool enable );
00522 void setScrollBarMarks( bool enable );
00523 void toggleFoldingMarkers();
00524 void toggleIconBorder();
00525 void toggleLineNumbersOn();
00526 void toggleScrollBarMarks();
00527 void toggleDynWordWrap ();
00528 void toggleViInputMode ();
00529 void showViModeBar ();
00530 void hideViModeBar ();
00531 void setDynWrapIndicators(int mode);
00532
00533 public:
00534 int getEol() const;
00535
00536 public:
00537 KateRenderer *renderer ();
00538
00539 bool iconBorder();
00540 bool lineNumbersOn();
00541 bool scrollBarMarks();
00542 int dynWrapIndicators();
00543 bool foldingMarkersOn();
00544
00545 private Q_SLOTS:
00549 void slotSelectionChanged ();
00550
00551 public:
00556 inline KateDocument* doc() { return m_doc; }
00557
00558 public Q_SLOTS:
00559 void slotNewUndo();
00560 void slotUpdate();
00561 void toggleInsert();
00562 void reloadFile();
00563 void toggleWWMarker();
00564 void toggleWriteLock();
00565 void switchToCmdLine ();
00566 void slotReadWriteChanged ();
00567
00568 Q_SIGNALS:
00569 void dropEventPass(QDropEvent*);
00570
00571 public:
00572 void slotTextInserted ( KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
00573
00574 protected:
00575 void contextMenuEvent( QContextMenuEvent* );
00576
00577 private Q_SLOTS:
00578 void slotGotFocus();
00579 void slotLostFocus();
00580 void slotDropEventPass( QDropEvent* ev );
00581 void slotSaveCanceled( const QString& error );
00582 void slotExpandToplevel();
00583 void slotCollapseLocal();
00584 void slotExpandLocal();
00585 void slotConfigDialog ();
00586
00587 private:
00588 void setupConnections();
00589 void setupActions();
00590 void setupEditActions();
00591 void setupCodeFolding();
00592
00593 QList<QAction*> m_editActions;
00594 KAction* m_editUndo;
00595 KAction* m_editRedo;
00596 KRecentFilesAction* m_fileRecent;
00597 KToggleAction* m_toggleFoldingMarkers;
00598 KToggleAction* m_toggleIconBar;
00599 KToggleAction* m_toggleLineNumbers;
00600 KToggleAction* m_toggleScrollBarMarks;
00601 KToggleAction* m_toggleDynWrap;
00602 KSelectAction* m_setDynWrapIndicators;
00603 KToggleAction* m_toggleWWMarker;
00604 KAction* m_switchCmdLine;
00605 KToggleAction* m_viInputModeAction;
00606
00607 KSelectAction* m_setEndOfLine;
00608
00609 QAction *m_cut;
00610 QAction *m_copy;
00611 QAction *m_copyHTML;
00612 QAction *m_paste;
00613 QAction *m_selectAll;
00614 QAction *m_deSelect;
00615
00616 KToggleAction *m_toggleBlockSelection;
00617 KToggleAction *m_toggleInsert;
00618 KToggleAction *m_toggleWriteLock;
00619
00620 KateDocument* m_doc;
00621 KateViewInternal* m_viewInternal;
00622 KateRenderer* m_renderer;
00623 KateSpell *m_spell;
00624 KateBookmarks* m_bookmarks;
00625
00626 QVBoxLayout *m_vBox;
00627
00628 bool m_hasWrap;
00629
00630 private Q_SLOTS:
00631 void slotNeedTextHint(int line, int col, QString &text);
00632 void slotHlChanged();
00633
00637 public:
00638 inline KateViewConfig *config () { return m_config; }
00639
00640 void updateConfig ();
00641
00642 void updateDocumentConfig();
00643
00644 void updateRendererConfig();
00645
00646 private Q_SLOTS:
00647 void updateFoldingConfig ();
00648
00649 private:
00650 KateViewConfig *m_config;
00651 bool m_startingUp;
00652 bool m_updatingDocumentConfig;
00653
00654
00655 KateSmartRange* m_selection;
00656
00657
00658 bool blockSelect;
00659
00663 public:
00664 void setImComposeEvent( bool imComposeEvent ) { m_imComposeEvent = imComposeEvent; }
00665 bool imComposeEvent () const { return m_imComposeEvent; }
00666
00667 private:
00668 bool m_imComposeEvent;
00669
00671 public:
00672 virtual bool insertTemplateTextImplementation ( const KTextEditor::Cursor&, const QString &templateString, const QMap<QString,QString> &initialValues);
00673
00674
00678 public:
00679 KateViewBar *viewBar() const;
00680 KateCmdLine *cmdLine ();
00681 KateSearchBar *searchBar (bool initHintAsPower = false);
00682 KateViModeBar *viModeBar();
00683 KateGotoBar *gotoBar ();
00688 private:
00689
00690 KateViewBar *m_bottomViewBar;
00691 KateViewBar *m_topViewBar;
00692
00693 KateCmdLine *m_cmdLine;
00694 KateSearchBar *m_searchBar;
00695 KateViModeBar *m_viModeBar;
00696 KateGotoBar *m_gotoBar;
00697
00698
00699 public:
00703 bool viInputMode() const;
00704
00708 ViMode getCurrentViMode() const;
00709
00713 bool viInputModeStealKeys() const;
00714
00718 void updateViModeBarMode();
00719
00723 void updateViModeBarCmd();
00724 };
00725
00726 #endif
00727
00728