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 "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 class KateSpell;
00046
00047 class KToggleAction;
00048 class KAction;
00049 class KRecentFilesAction;
00050 class KSelectAction;
00051
00052 class QGridLayout;
00053
00054
00055
00056
00057 class KateView : public Kate::View,
00058 public KTextEditor::SessionConfigInterface,
00059 public KTextEditor::ViewStatusMsgInterface,
00060 public KTextEditor::TextHintInterface,
00061 public KTextEditor::SelectionInterface,
00062 public KTextEditor::SelectionInterfaceExt,
00063 public KTextEditor::BlockSelectionInterface
00064 {
00065 Q_OBJECT
00066
00067 friend class KateViewInternal;
00068 friend class KateIconBorder;
00069 friend class KateCodeCompletion;
00070
00071 public:
00072 KateView( KateDocument* doc, QWidget* parent = 0L, const char* name = 0 );
00073 ~KateView ();
00074
00075
00076
00077
00078 public:
00079 KTextEditor::Document* document() const { return m_doc; }
00080
00081
00082
00083
00084 public slots:
00085
00086 void paste() { m_doc->paste( this ); m_viewInternal->repaint(); }
00087 void cut();
00088 void copy() const;
00089
00093 void copyHTML();
00094
00095
00096 private:
00097 QString selectionAsHtml ();
00098 QString textAsHtml ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise);
00099 void textAsHtmlStream ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise, QTextStream *ts);
00100
00113 void lineAsHTML (KateTextLine::Ptr line, uint startCol, uint length, QTextStream *outputStream);
00114
00115 public slots:
00116 void exportAsHTML ();
00117
00118
00119
00120
00121 public:
00122 void installPopup( QPopupMenu* menu ) { m_rmbMenu = menu; }
00123 QPopupMenu* popup() const { return m_rmbMenu; }
00124
00125
00126
00127
00128 public slots:
00129 QPoint cursorCoordinates()
00130 { return m_viewInternal->cursorCoordinates(); }
00131 void cursorPosition( uint* l, uint* c )
00132 { if( l ) *l = cursorLine(); if( c ) *c = cursorColumn(); }
00133 void cursorPositionReal( uint* l, uint* c )
00134 { if( l ) *l = cursorLine(); if( c ) *c = cursorColumnReal(); }
00135 bool setCursorPosition( uint line, uint col )
00136 { return setCursorPositionInternal( line, col, tabWidth(), true ); }
00137 bool setCursorPositionReal( uint line, uint col)
00138 { return setCursorPositionInternal( line, col, 1, true ); }
00139 uint cursorLine()
00140 { return m_viewInternal->getCursor().line(); }
00141 uint cursorColumn();
00142 uint cursorColumnReal()
00143 { return m_viewInternal->getCursor().col(); }
00144
00145 signals:
00146 void cursorPositionChanged();
00147
00148
00149
00150
00151 public slots:
00152 void showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 );
00153 void showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset = 0, bool cs = true );
00154
00155 signals:
00156 void completionAborted();
00157 void completionDone();
00158 void argHintHidden();
00159 void completionDone(KTextEditor::CompletionEntry);
00160 void filterInsertString(KTextEditor::CompletionEntry*,QString *);
00161 void aboutToShowCompletionBox();
00162
00163
00164
00165
00166 public:
00167 void enableTextHints(int timeout);
00168 void disableTextHints();
00169
00170 signals:
00171 void needTextHint(int line, int col, QString &text);
00172
00173
00174
00175
00176 public:
00177 void setDynWordWrap( bool b );
00178 bool dynWordWrap() const { return m_hasWrap; }
00179
00180
00181
00182
00183 public slots:
00184 bool setSelection ( const KateTextCursor & start,
00185 const KateTextCursor & end );
00186 bool setSelection ( uint startLine, uint startCol,
00187 uint endLine, uint endCol );
00188 bool clearSelection ();
00189 bool clearSelection (bool redraw, bool finishedChangingSelection = true);
00190
00191 bool hasSelection () const;
00192 QString selection () const ;
00193
00194 bool removeSelectedText ();
00195
00196 bool selectAll();
00197
00198
00199
00200
00201 int selStartLine() { return selectStart.line(); };
00202 int selStartCol() { return selectStart.col(); };
00203 int selEndLine() { return selectEnd.line(); };
00204 int selEndCol() { return selectEnd.col(); };
00205
00206 signals:
00207 void selectionChanged ();
00208
00209
00210
00211
00212 public:
00217 inline const KateSuperCursor &selStart () const { return selectStart; }
00218
00223 inline const KateSuperCursor &selEnd () const { return selectEnd; }
00224
00225
00226 bool wrapCursor ();
00227
00228
00229 bool lineColSelected (int line, int col);
00230 bool lineSelected (int line);
00231 bool lineEndSelected (int line, int endCol);
00232 bool lineHasSelected (int line);
00233 bool lineIsSelection (int line);
00234
00235 void tagSelection (const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd);
00236
00237 void selectWord( const KateTextCursor& cursor );
00238 void selectLine( const KateTextCursor& cursor );
00239 void selectLength( const KateTextCursor& cursor, int length );
00240
00241
00242
00243 void syncSelectionCache();
00244
00245
00246
00247
00248 public slots:
00249 bool blockSelectionMode ();
00250 bool setBlockSelectionMode (bool on);
00251 bool toggleBlockSelectionMode ();
00252
00253
00254
00255 public:
00256 void editStart ();
00257 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00258
00259 void editSetCursor (const KateTextCursor &cursor);
00260
00261
00262
00263 public:
00264 bool tagLine (const KateTextCursor& virtualCursor);
00265
00266 bool tagLines (int start, int end, bool realLines = false );
00267 bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00268
00269 void tagAll ();
00270
00271 void clear ();
00272
00273 void repaintText (bool paintOnlyDirty = false);
00274
00275 void updateView (bool changed = false);
00276
00277
00278
00279
00280
00281 public:
00282 bool isOverwriteMode() const;
00283 void setOverwriteMode( bool b );
00284
00285 QString currentTextLine()
00286 { return getDoc()->textLine( cursorLine() ); }
00287 QString currentWord()
00288 { return m_doc->getWord( m_viewInternal->getCursor() ); }
00289 void insertText( const QString& text )
00290 { getDoc()->insertText( cursorLine(), cursorColumnReal(), text ); }
00291 bool canDiscard();
00292 int tabWidth() { return m_doc->config()->tabWidth(); }
00293 void setTabWidth( int w ) { m_doc->config()->setTabWidth(w); }
00294 void setEncoding( QString e ) { m_doc->setEncoding(e); }
00295 bool isLastView() { return m_doc->isLastView(1); }
00296
00297 public slots:
00298 void flush();
00299 saveResult save();
00300 saveResult saveAs();
00301
00302 void indent() { m_doc->indent( this, cursorLine(), 1 ); }
00303 void unIndent() { m_doc->indent( this, cursorLine(), -1 ); }
00304 void cleanIndent() { m_doc->indent( this, cursorLine(), 0 ); }
00305 void align() { m_doc->align( this, cursorLine() ); }
00306 void comment() { m_doc->comment( this, cursorLine(), cursorColumnReal(), 1 ); }
00307 void uncomment() { m_doc->comment( this, cursorLine(), cursorColumnReal(),-1 ); }
00308 void killLine() { m_doc->removeLine( cursorLine() ); }
00309
00313 void uppercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Uppercase ); }
00317 void lowercase() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Lowercase ); }
00322 void capitalize() { m_doc->transform( this, m_viewInternal->cursor, KateDocument::Capitalize ); }
00326 void joinLines();
00327
00328
00329 void keyReturn() { m_viewInternal->doReturn(); }
00330 void backspace() { m_viewInternal->doBackspace(); }
00331 void deleteWordLeft() { m_viewInternal->doDeleteWordLeft(); }
00332 void keyDelete() { m_viewInternal->doDelete(); }
00333 void deleteWordRight() { m_viewInternal->doDeleteWordRight(); }
00334 void transpose() { m_viewInternal->doTranspose(); }
00335 void cursorLeft() { m_viewInternal->cursorLeft(); }
00336 void shiftCursorLeft() { m_viewInternal->cursorLeft(true); }
00337 void cursorRight() { m_viewInternal->cursorRight(); }
00338 void shiftCursorRight() { m_viewInternal->cursorRight(true); }
00339 void wordLeft() { m_viewInternal->wordLeft(); }
00340 void shiftWordLeft() { m_viewInternal->wordLeft(true); }
00341 void wordRight() { m_viewInternal->wordRight(); }
00342 void shiftWordRight() { m_viewInternal->wordRight(true); }
00343 void home() { m_viewInternal->home(); }
00344 void shiftHome() { m_viewInternal->home(true); }
00345 void end() { m_viewInternal->end(); }
00346 void shiftEnd() { m_viewInternal->end(true); }
00347 void up() { m_viewInternal->cursorUp(); }
00348 void shiftUp() { m_viewInternal->cursorUp(true); }
00349 void down() { m_viewInternal->cursorDown(); }
00350 void shiftDown() { m_viewInternal->cursorDown(true); }
00351 void scrollUp() { m_viewInternal->scrollUp(); }
00352 void scrollDown() { m_viewInternal->scrollDown(); }
00353 void topOfView() { m_viewInternal->topOfView(); }
00354 void shiftTopOfView() { m_viewInternal->topOfView(true); }
00355 void bottomOfView() { m_viewInternal->bottomOfView(); }
00356 void shiftBottomOfView() { m_viewInternal->bottomOfView(true); }
00357 void pageUp() { m_viewInternal->pageUp(); }
00358 void shiftPageUp() { m_viewInternal->pageUp(true); }
00359 void pageDown() { m_viewInternal->pageDown(); }
00360 void shiftPageDown() { m_viewInternal->pageDown(true); }
00361 void top() { m_viewInternal->top_home(); }
00362 void shiftTop() { m_viewInternal->top_home(true); }
00363 void bottom() { m_viewInternal->bottom_end(); }
00364 void shiftBottom() { m_viewInternal->bottom_end(true); }
00365 void toMatchingBracket() { m_viewInternal->cursorToMatchingBracket();}
00366 void shiftToMatchingBracket() { m_viewInternal->cursorToMatchingBracket(true);}
00367
00368 void gotoLine();
00369 void gotoLineNumber( int linenumber );
00370
00371
00372 public:
00373 void readSessionConfig(KConfig *);
00374 void writeSessionConfig(KConfig *);
00375
00376 public slots:
00377 int getEol();
00378 void setEol( int eol );
00379 void find();
00380 void find( const QString&, long, bool add=true );
00381 void replace();
00382 void replace( const QString&, const QString &, long );
00383 void findAgain( bool back );
00384 void findAgain() { findAgain( false ); }
00385 void findPrev() { findAgain( true ); }
00386
00387 void setFoldingMarkersOn( bool enable );
00388 void setIconBorder( bool enable );
00389 void setLineNumbersOn( bool enable );
00390 void setScrollBarMarks( bool enable );
00391 void showCmdLine ( bool enable );
00392 void toggleFoldingMarkers();
00393 void toggleIconBorder();
00394 void toggleLineNumbersOn();
00395 void toggleScrollBarMarks();
00396 void toggleDynWordWrap ();
00397 void toggleCmdLine ();
00398 void setDynWrapIndicators(int mode);
00399
00400 void applyWordWrap ();
00401
00402 public:
00403 KateRenderer *renderer ();
00404
00405 bool iconBorder();
00406 bool lineNumbersOn();
00407 bool scrollBarMarks();
00408 int dynWrapIndicators();
00409 bool foldingMarkersOn();
00410 Kate::Document* getDoc() { return m_doc; }
00411
00412 void setActive( bool b ) { m_active = b; }
00413 bool isActive() { return m_active; }
00414
00415 public slots:
00416 void gotoMark( KTextEditor::Mark* mark ) { setCursorPositionInternal ( mark->line, 0, 1 ); }
00417 void slotSelectionChanged ();
00418
00419 signals:
00420 void gotFocus( Kate::View* );
00421 void lostFocus( Kate::View* );
00422 void newStatus();
00423
00424
00425
00426
00427 public:
00428
00429 KateDocument* doc() const { return m_doc; }
00430
00431 KActionCollection* editActionCollection() const { return m_editActions; }
00432
00433 public slots:
00434 void slotNewUndo();
00435 void slotUpdate();
00436 void toggleInsert();
00437 void reloadFile();
00438 void toggleWWMarker();
00439 void toggleWriteLock();
00440 void switchToCmdLine ();
00441 void slotReadWriteChanged ();
00442
00443 signals:
00444 void dropEventPass(QDropEvent*);
00445 void viewStatusMsg (const QString &msg);
00446
00447 public:
00448 bool setCursorPositionInternal( uint line, uint col, uint tabwidth = 1, bool calledExternally = false );
00449
00450 protected:
00451 void contextMenuEvent( QContextMenuEvent* );
00452 bool checkOverwrite( KURL );
00453
00454 public slots:
00455 void slotSelectionTypeChanged();
00456
00457 private slots:
00458 void slotGotFocus();
00459 void slotLostFocus();
00460 void slotDropEventPass( QDropEvent* ev );
00461 void slotStatusMsg();
00462 void slotSaveCanceled( const QString& error );
00463 void slotExpandToplevel();
00464 void slotCollapseLocal();
00465 void slotExpandLocal();
00466
00467 private:
00468 void setupConnections();
00469 void setupActions();
00470 void setupEditActions();
00471 void setupCodeFolding();
00472 void setupCodeCompletion();
00473
00474 KActionCollection* m_editActions;
00475 KAction* m_editUndo;
00476 KAction* m_editRedo;
00477 KRecentFilesAction* m_fileRecent;
00478 KToggleAction* m_toggleFoldingMarkers;
00479 KToggleAction* m_toggleIconBar;
00480 KToggleAction* m_toggleLineNumbers;
00481 KToggleAction* m_toggleScrollBarMarks;
00482 KToggleAction* m_toggleDynWrap;
00483 KSelectAction* m_setDynWrapIndicators;
00484 KToggleAction* m_toggleWWMarker;
00485 KAction* m_switchCmdLine;
00486
00487 KSelectAction* m_setEndOfLine;
00488
00489 KAction *m_cut;
00490 KAction *m_copy;
00491 KAction *m_copyHTML;
00492 KAction *m_paste;
00493 KAction *m_selectAll;
00494 KAction *m_deSelect;
00495
00496 KToggleAction *m_toggleBlockSelection;
00497 KToggleAction *m_toggleInsert;
00498 KToggleAction *m_toggleWriteLock;
00499
00500 KateDocument* m_doc;
00501 KateViewInternal* m_viewInternal;
00502 KateRenderer* m_renderer;
00503 KateSearch* m_search;
00504 KateSpell *m_spell;
00505 KateBookmarks* m_bookmarks;
00506 QGuardedPtr<QPopupMenu> m_rmbMenu;
00507 KateCodeCompletion* m_codeCompletion;
00508
00509 KateCmdLine *m_cmdLine;
00510 bool m_cmdLineOn;
00511
00512 QGridLayout *m_grid;
00513
00514 bool m_active;
00515 bool m_hasWrap;
00516
00517 private slots:
00518 void slotNeedTextHint(int line, int col, QString &text);
00519 void slotHlChanged();
00520
00524 public:
00525 inline KateViewConfig *config () { return m_config; };
00526
00527 void updateConfig ();
00528
00529 void updateDocumentConfig();
00530
00531 void updateRendererConfig();
00532
00533 private slots:
00534 void updateFoldingConfig ();
00535
00536 private:
00537 KateViewConfig *m_config;
00538 bool m_startingUp;
00539 bool m_updatingDocumentConfig;
00540
00541 private:
00542
00543 KateSuperCursor selectStart;
00544 KateSuperCursor selectEnd;
00545
00546
00547 bool blockSelect;
00548
00552 public:
00553 void setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
00554 uint imSelStart, uint imSelEnd, bool m_imComposeEvent );
00555 void getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
00556 uint *imSelStart, uint *imSelEnd );
00557 bool isIMSelection( int _line, int _column );
00558 bool isIMEdit( int _line, int _column );
00559 bool imComposeEvent () const { return m_imComposeEvent; }
00560
00561 private:
00562 uint m_imStartLine;
00563 uint m_imStart;
00564 uint m_imEnd;
00565 uint m_imSelStart;
00566 uint m_imSelEnd;
00567 bool m_imComposeEvent;
00568 };
00569
00570 #endif