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