00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define DEBUGACCELS
00024
00025
00026 #include "kateview.h"
00027 #include "kateview.moc"
00028
00029 #include "kateviewinternal.h"
00030 #include "kateviewhelpers.h"
00031 #include "katerenderer.h"
00032 #include "katedocument.h"
00033 #include "katedocumenthelpers.h"
00034 #include "katefactory.h"
00035 #include "katehighlight.h"
00036 #include "katedialogs.h"
00037 #include "katetextline.h"
00038 #include "katecodefoldinghelpers.h"
00039 #include "katecodecompletion.h"
00040 #include "katesearch.h"
00041 #include "kateschema.h"
00042 #include "katebookmarks.h"
00043 #include "katesearch.h"
00044 #include "kateconfig.h"
00045 #include "katefiletype.h"
00046 #include "kateautoindent.h"
00047 #include "katespell.h"
00048
00049 #include <ktexteditor/plugin.h>
00050
00051 #include <kparts/event.h>
00052
00053 #include <kio/netaccess.h>
00054
00055 #include <kconfig.h>
00056 #include <kurldrag.h>
00057 #include <kdebug.h>
00058 #include <kapplication.h>
00059 #include <kcursor.h>
00060 #include <klocale.h>
00061 #include <kglobal.h>
00062 #include <kcharsets.h>
00063 #include <kmessagebox.h>
00064 #include <kaction.h>
00065 #include <kstdaction.h>
00066 #include <kxmlguifactory.h>
00067 #include <kaccel.h>
00068 #include <klibloader.h>
00069 #include <kencodingfiledialog.h>
00070 #include <kmultipledrag.h>
00071 #include <ktempfile.h>
00072 #include <ksavefile.h>
00073
00074 #include <qfont.h>
00075 #include <qfileinfo.h>
00076 #include <qstyle.h>
00077 #include <qevent.h>
00078 #include <qpopupmenu.h>
00079 #include <qlayout.h>
00080 #include <qclipboard.h>
00081 #include <qstylesheet.h>
00082
00083
00084 KateView::KateView( KateDocument *doc, QWidget *parent, const char * name )
00085 : Kate::View( doc, parent, name )
00086 , m_doc( doc )
00087 , m_search( new KateSearch( this ) )
00088 , m_spell( new KateSpell( this ) )
00089 , m_bookmarks( new KateBookmarks( this ) )
00090 , m_cmdLine (0)
00091 , m_cmdLineOn (false)
00092 , m_active( false )
00093 , m_hasWrap( false )
00094 , m_startingUp (true)
00095 , m_updatingDocumentConfig (false)
00096 , selectStart (m_doc, true)
00097 , selectEnd (m_doc, true)
00098 , blockSelect (false)
00099 , m_imStartLine( 0 )
00100 , m_imStart( 0 )
00101 , m_imEnd( 0 )
00102 , m_imSelStart( 0 )
00103 , m_imSelEnd( 0 )
00104 , m_imComposeEvent( false )
00105 {
00106 KateFactory::self()->registerView( this );
00107 m_config = new KateViewConfig (this);
00108
00109 m_renderer = new KateRenderer(doc, this);
00110
00111 m_grid = new QGridLayout (this, 3, 3);
00112
00113 m_grid->setRowStretch ( 0, 10 );
00114 m_grid->setRowStretch ( 1, 0 );
00115 m_grid->setColStretch ( 0, 0 );
00116 m_grid->setColStretch ( 1, 10 );
00117 m_grid->setColStretch ( 2, 0 );
00118
00119 m_viewInternal = new KateViewInternal( this, doc );
00120 m_grid->addWidget (m_viewInternal, 0, 1);
00121
00122 setClipboardInterfaceDCOPSuffix (viewDCOPSuffix());
00123 setCodeCompletionInterfaceDCOPSuffix (viewDCOPSuffix());
00124 setDynWordWrapInterfaceDCOPSuffix (viewDCOPSuffix());
00125 setPopupMenuInterfaceDCOPSuffix (viewDCOPSuffix());
00126 setSessionConfigInterfaceDCOPSuffix (viewDCOPSuffix());
00127 setViewCursorInterfaceDCOPSuffix (viewDCOPSuffix());
00128 setViewStatusMsgInterfaceDCOPSuffix (viewDCOPSuffix());
00129
00130 setInstance( KateFactory::self()->instance() );
00131 doc->addView( this );
00132
00133 setFocusProxy( m_viewInternal );
00134 setFocusPolicy( StrongFocus );
00135
00136 if (!doc->singleViewMode()) {
00137 setXMLFile( "katepartui.rc" );
00138 } else {
00139 if( doc->readOnly() )
00140 setXMLFile( "katepartreadonlyui.rc" );
00141 else
00142 setXMLFile( "katepartui.rc" );
00143 }
00144
00145 setupConnections();
00146 setupActions();
00147 setupEditActions();
00148 setupCodeFolding();
00149 setupCodeCompletion();
00150
00151
00152 m_doc->enableAllPluginsGUI (this);
00153
00154
00155 slotNewUndo();
00156
00157 m_startingUp = false;
00158 updateConfig ();
00159
00160 slotHlChanged();
00161
00162
00163
00164
00165
00166 }
00167
00168 KateView::~KateView()
00169 {
00170 if (!m_doc->singleViewMode())
00171 m_doc->disableAllPluginsGUI (this);
00172
00173 m_doc->removeView( this );
00174
00175 delete m_viewInternal;
00176 delete m_codeCompletion;
00177
00178 delete m_renderer;
00179
00180 delete m_config;
00181 KateFactory::self()->deregisterView (this);
00182 }
00183
00184 void KateView::setupConnections()
00185 {
00186 connect( m_doc, SIGNAL(undoChanged()),
00187 this, SLOT(slotNewUndo()) );
00188 connect( m_doc, SIGNAL(hlChanged()),
00189 this, SLOT(slotHlChanged()) );
00190 connect( m_doc, SIGNAL(canceled(const QString&)),
00191 this, SLOT(slotSaveCanceled(const QString&)) );
00192 connect( m_viewInternal, SIGNAL(dropEventPass(QDropEvent*)),
00193 this, SIGNAL(dropEventPass(QDropEvent*)) );
00194 connect(this,SIGNAL(cursorPositionChanged()),this,SLOT(slotStatusMsg()));
00195 connect(this,SIGNAL(newStatus()),this,SLOT(slotStatusMsg()));
00196 connect(m_doc, SIGNAL(undoChanged()), this, SLOT(slotStatusMsg()));
00197
00198 if ( m_doc->browserView() )
00199 {
00200 connect( this, SIGNAL(dropEventPass(QDropEvent*)),
00201 this, SLOT(slotDropEventPass(QDropEvent*)) );
00202 }
00203 }
00204
00205 void KateView::setupActions()
00206 {
00207 KActionCollection *ac = this->actionCollection ();
00208 KAction *a;
00209
00210 m_toggleWriteLock = 0;
00211
00212 m_cut = a=KStdAction::cut(this, SLOT(cut()), ac);
00213 a->setWhatsThis(i18n("Cut the selected text and move it to the clipboard"));
00214
00215 m_paste = a=KStdAction::pasteText(this, SLOT(paste()), ac);
00216 a->setWhatsThis(i18n("Paste previously copied or cut clipboard contents"));
00217
00218 m_copy = a=KStdAction::copy(this, SLOT(copy()), ac);
00219 a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard."));
00220
00221 m_copyHTML = a = new KAction(i18n("Copy as &HTML"), "editcopy", 0, this, SLOT(copyHTML()), ac, "edit_copy_html");
00222 a->setWhatsThis(i18n( "Use this command to copy the currently selected text as HTML to the system clipboard."));
00223
00224 if (!m_doc->readOnly())
00225 {
00226 a=KStdAction::save(this, SLOT(save()), ac);
00227 a->setWhatsThis(i18n("Save the current document"));
00228
00229 a=m_editUndo = KStdAction::undo(m_doc, SLOT(undo()), ac);
00230 a->setWhatsThis(i18n("Revert the most recent editing actions"));
00231
00232 a=m_editRedo = KStdAction::redo(m_doc, SLOT(redo()), ac);
00233 a->setWhatsThis(i18n("Revert the most recent undo operation"));
00234
00235 (new KAction(i18n("&Word Wrap Document"), "", 0, this, SLOT(applyWordWrap()), ac, "tools_apply_wordwrap"))->setWhatsThis(
00236 i18n("Use this command to wrap all lines of the current document which are longer than the width of the"
00237 " current view, to fit into this view.<br><br> This is a static word wrap, meaning it is not updated"
00238 " when the view is resized."));
00239
00240
00241 a=new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()), ac, "tools_indent");
00242 a->setWhatsThis(i18n("Use this to indent a selected block of text.<br><br>"
00243 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00244 a=new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::SHIFT+Qt::Key_I, this, SLOT(unIndent()), ac, "tools_unindent");
00245 a->setWhatsThis(i18n("Use this to unindent a selected block of text."));
00246
00247 a=new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()), ac, "tools_cleanIndent");
00248 a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces)<br><br>"
00249 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00250
00251 a=new KAction(i18n("&Align"), 0, this, SLOT(align()), ac, "tools_align");
00252 a->setWhatsThis(i18n("Use this to align the current line or block of text to its proper indent level."));
00253
00254 a=new KAction(i18n("C&omment"), CTRL+Qt::Key_D, this, SLOT(comment()),
00255 ac, "tools_comment");
00256 a->setWhatsThis(i18n("This command comments out the current line or a selected block of text.<BR><BR>"
00257 "The characters for single/multiple line comments are defined within the language's highlighting."));
00258
00259 a=new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_D, this, SLOT(uncomment()),
00260 ac, "tools_uncomment");
00261 a->setWhatsThis(i18n("This command removes comments from the current line or a selected block of text.<BR><BR>"
00262 "The characters for single/multiple line comments are defined within the language's highlighting."));
00263 a = m_toggleWriteLock = new KToggleAction(
00264 i18n("&Read Only Mode"), 0, 0,
00265 this, SLOT( toggleWriteLock() ),
00266 ac, "tools_toggle_write_lock" );
00267 a->setWhatsThis( i18n("Lock/unlock the document for writing") );
00268
00269 a = new KAction( i18n("Uppercase"), CTRL + Qt::Key_U, this,
00270 SLOT(uppercase()), ac, "tools_uppercase" );
00271 a->setWhatsThis( i18n("Convert the selection to uppercase, or the character to the "
00272 "right of the cursor if no text is selected.") );
00273
00274 a = new KAction( i18n("Lowercase"), CTRL + SHIFT + Qt::Key_U, this,
00275 SLOT(lowercase()), ac, "tools_lowercase" );
00276 a->setWhatsThis( i18n("Convert the selection to lowercase, or the character to the "
00277 "right of the cursor if no text is selected.") );
00278
00279 a = new KAction( i18n("Capitalize"), CTRL + ALT + Qt::Key_U, this,
00280 SLOT(capitalize()), ac, "tools_capitalize" );
00281 a->setWhatsThis( i18n("Capitalize the selection, or the word under the "
00282 "cursor if no text is selected.") );
00283
00284 a = new KAction( i18n("Join Lines"), CTRL + Qt::Key_J, this,
00285 SLOT( joinLines() ), ac, "tools_join_lines" );
00286 }
00287 else
00288 {
00289 m_cut->setEnabled (false);
00290 m_paste->setEnabled (false);
00291 m_editUndo = 0;
00292 m_editRedo = 0;
00293 }
00294
00295 a=KStdAction::print( m_doc, SLOT(print()), ac );
00296 a->setWhatsThis(i18n("Print the current document."));
00297
00298 a=new KAction(i18n("Reloa&d"), "reload", KStdAccel::reload(), this, SLOT(reloadFile()), ac, "file_reload");
00299 a->setWhatsThis(i18n("Reload the current document from disk."));
00300
00301 a=KStdAction::saveAs(this, SLOT(saveAs()), ac);
00302 a->setWhatsThis(i18n("Save the current document to disk, with a name of your choice."));
00303
00304 a=KStdAction::gotoLine(this, SLOT(gotoLine()), ac);
00305 a->setWhatsThis(i18n("This command opens a dialog and lets you choose a line that you want the cursor to move to."));
00306
00307 a=new KAction(i18n("&Configure Editor..."), 0, m_doc, SLOT(configDialog()),ac, "set_confdlg");
00308 a->setWhatsThis(i18n("Configure various aspects of this editor."));
00309
00310 KateViewHighlightAction *menu = new KateViewHighlightAction (i18n("&Highlighting"), ac, "set_highlight");
00311 menu->setWhatsThis(i18n("Here you can choose how the current document should be highlighted."));
00312 menu->updateMenu (m_doc);
00313
00314 KateViewFileTypeAction *ftm = new KateViewFileTypeAction (i18n("&Filetype"),ac,"set_filetype");
00315 ftm->updateMenu (m_doc);
00316
00317 KateViewSchemaAction *schemaMenu = new KateViewSchemaAction (i18n("&Schema"),ac,"view_schemas");
00318 schemaMenu->updateMenu (this);
00319
00320
00321 new KateViewIndentationAction (m_doc, i18n("&Indentation"),ac,"tools_indentation");
00322
00323
00324 a = new KAction(i18n("E&xport as HTML..."), 0, 0, this, SLOT(exportAsHTML()), ac, "file_export_html");
00325 a->setWhatsThis(i18n("This command allows you to export the current document"
00326 " with all highlighting information into a HTML document."));
00327
00328 m_selectAll = a=KStdAction::selectAll(this, SLOT(selectAll()), ac);
00329 a->setWhatsThis(i18n("Select the entire text of the current document."));
00330
00331 m_deSelect = a=KStdAction::deselect(this, SLOT(clearSelection()), ac);
00332 a->setWhatsThis(i18n("If you have selected something within the current document, this will no longer be selected."));
00333
00334 a=new KAction(i18n("Enlarge Font"), "viewmag+", 0, m_viewInternal, SLOT(slotIncFontSizes()), ac, "incFontSizes");
00335 a->setWhatsThis(i18n("This increases the display font size."));
00336
00337 a=new KAction(i18n("Shrink Font"), "viewmag-", 0, m_viewInternal, SLOT(slotDecFontSizes()), ac, "decFontSizes");
00338 a->setWhatsThis(i18n("This decreases the display font size."));
00339
00340 a= m_toggleBlockSelection = new KToggleAction(
00341 i18n("Bl&ock Selection Mode"), CTRL + SHIFT + Key_B,
00342 this, SLOT(toggleBlockSelectionMode()),
00343 ac, "set_verticalSelect");
00344 a->setWhatsThis(i18n("This command allows switching between the normal (line based) selection mode and the block selection mode."));
00345
00346 a= m_toggleInsert = new KToggleAction(
00347 i18n("Overwr&ite Mode"), Key_Insert,
00348 this, SLOT(toggleInsert()),
00349 ac, "set_insert" );
00350 a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text."));
00351
00352 KToggleAction *toggleAction;
00353 a= m_toggleDynWrap = toggleAction = new KToggleAction(
00354 i18n("&Dynamic Word Wrap"), Key_F10,
00355 this, SLOT(toggleDynWordWrap()),
00356 ac, "view_dynamic_word_wrap" );
00357 a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen."));
00358
00359 a= m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), 0, ac, "dynamic_word_wrap_indicators");
00360 a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"));
00361
00362 connect(m_setDynWrapIndicators, SIGNAL(activated(int)), this, SLOT(setDynWrapIndicators(int)));
00363 QStringList list2;
00364 list2.append(i18n("&Off"));
00365 list2.append(i18n("Follow &Line Numbers"));
00366 list2.append(i18n("&Always On"));
00367 m_setDynWrapIndicators->setItems(list2);
00368
00369 a= toggleAction=m_toggleFoldingMarkers = new KToggleAction(
00370 i18n("Show Folding &Markers"), Key_F9,
00371 this, SLOT(toggleFoldingMarkers()),
00372 ac, "view_folding_markers" );
00373 a->setWhatsThis(i18n("You can choose if the codefolding marks should be shown, if codefolding is possible."));
00374 toggleAction->setCheckedState(i18n("Hide Folding &Markers"));
00375
00376 a= m_toggleIconBar = toggleAction = new KToggleAction(
00377 i18n("Show &Icon Border"), Key_F6,
00378 this, SLOT(toggleIconBorder()),
00379 ac, "view_border");
00380 a=toggleAction;
00381 a->setWhatsThis(i18n("Show/hide the icon border.<BR><BR> The icon border shows bookmark symbols, for instance."));
00382 toggleAction->setCheckedState(i18n("Hide &Icon Border"));
00383
00384 a= toggleAction=m_toggleLineNumbers = new KToggleAction(
00385 i18n("Show &Line Numbers"), Key_F11,
00386 this, SLOT(toggleLineNumbersOn()),
00387 ac, "view_line_numbers" );
00388 a->setWhatsThis(i18n("Show/hide the line numbers on the left hand side of the view."));
00389 toggleAction->setCheckedState(i18n("Hide &Line Numbers"));
00390
00391 a= m_toggleScrollBarMarks = toggleAction = new KToggleAction(
00392 i18n("Show Scroll&bar Marks"), 0,
00393 this, SLOT(toggleScrollBarMarks()),
00394 ac, "view_scrollbar_marks");
00395 a->setWhatsThis(i18n("Show/hide the marks on the vertical scrollbar.<BR><BR>The marks, for instance, show bookmarks."));
00396 toggleAction->setCheckedState(i18n("Hide Scroll&bar Marks"));
00397
00398 a = toggleAction = m_toggleWWMarker = new KToggleAction(
00399 i18n("Show Static &Word Wrap Marker"), 0,
00400 this, SLOT( toggleWWMarker() ),
00401 ac, "view_word_wrap_marker" );
00402 a->setWhatsThis( i18n(
00403 "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
00404 "wrap column as defined in the editing properties" ));
00405 toggleAction->setCheckedState(i18n("Hide Static &Word Wrap Marker"));
00406
00407 a= m_switchCmdLine = new KAction(
00408 i18n("Switch to Command Line"), Key_F7,
00409 this, SLOT(switchToCmdLine()),
00410 ac, "switch_to_cmd_line" );
00411 a->setWhatsThis(i18n("Show/hide the command line on the bottom of the view."));
00412
00413 a=m_setEndOfLine = new KSelectAction(i18n("&End of Line"), 0, ac, "set_eol");
00414 a->setWhatsThis(i18n("Choose which line endings should be used, when you save the document"));
00415 QStringList list;
00416 list.append("&UNIX");
00417 list.append("&Windows/DOS");
00418 list.append("&Macintosh");
00419 m_setEndOfLine->setItems(list);
00420 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
00421 connect(m_setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int)));
00422
00423
00424 new KateViewEncodingAction (m_doc, this, i18n("E&ncoding"), ac, "set_encoding");
00425
00426 m_search->createActions( ac );
00427 m_spell->createActions( ac );
00428 m_bookmarks->createActions( ac );
00429
00430 slotSelectionChanged ();
00431
00432 connect (this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
00433 }
00434
00435 void KateView::setupEditActions()
00436 {
00437 m_editActions = new KActionCollection( m_viewInternal, this, "edit_actions" );
00438 KActionCollection* ac = m_editActions;
00439
00440 new KAction(
00441 i18n("Move Word Left"), CTRL + Key_Left,
00442 this,SLOT(wordLeft()),
00443 ac, "word_left" );
00444 new KAction(
00445 i18n("Select Character Left"), SHIFT + Key_Left,
00446 this,SLOT(shiftCursorLeft()),
00447 ac, "select_char_left" );
00448 new KAction(
00449 i18n("Select Word Left"), SHIFT + CTRL + Key_Left,
00450 this, SLOT(shiftWordLeft()),
00451 ac, "select_word_left" );
00452
00453 new KAction(
00454 i18n("Move Word Right"), CTRL + Key_Right,
00455 this, SLOT(wordRight()),
00456 ac, "word_right" );
00457 new KAction(
00458 i18n("Select Character Right"), SHIFT + Key_Right,
00459 this, SLOT(shiftCursorRight()),
00460 ac, "select_char_right" );
00461 new KAction(
00462 i18n("Select Word Right"), SHIFT + CTRL + Key_Right,
00463 this,SLOT(shiftWordRight()),
00464 ac, "select_word_right" );
00465
00466 new KAction(
00467 i18n("Move to Beginning of Line"), Key_Home,
00468 this, SLOT(home()),
00469 ac, "beginning_of_line" );
00470 new KAction(
00471 i18n("Move to Beginning of Document"), KStdAccel::home(),
00472 this, SLOT(top()),
00473 ac, "beginning_of_document" );
00474 new KAction(
00475 i18n("Select to Beginning of Line"), SHIFT + Key_Home,
00476 this, SLOT(shiftHome()),
00477 ac, "select_beginning_of_line" );
00478 new KAction(
00479 i18n("Select to Beginning of Document"), SHIFT + CTRL + Key_Home,
00480 this, SLOT(shiftTop()),
00481 ac, "select_beginning_of_document" );
00482
00483 new KAction(
00484 i18n("Move to End of Line"), Key_End,
00485 this, SLOT(end()),
00486 ac, "end_of_line" );
00487 new KAction(
00488 i18n("Move to End of Document"), KStdAccel::end(),
00489 this, SLOT(bottom()),
00490 ac, "end_of_document" );
00491 new KAction(
00492 i18n("Select to End of Line"), SHIFT + Key_End,
00493 this, SLOT(shiftEnd()),
00494 ac, "select_end_of_line" );
00495 new KAction(
00496 i18n("Select to End of Document"), SHIFT + CTRL + Key_End,
00497 this, SLOT(shiftBottom()),
00498 ac, "select_end_of_document" );
00499
00500 new KAction(
00501 i18n("Select to Previous Line"), SHIFT + Key_Up,
00502 this, SLOT(shiftUp()),
00503 ac, "select_line_up" );
00504 new KAction(
00505 i18n("Scroll Line Up"),"", CTRL + Key_Up,
00506 this, SLOT(scrollUp()),
00507 ac, "scroll_line_up" );
00508
00509 new KAction(i18n("Move to Next Line"), Key_Down, this, SLOT(down()),
00510 ac, "move_line_down");
00511
00512 new KAction(i18n("Move to Previous Line"), Key_Up, this, SLOT(up()),
00513 ac, "move_line_up");
00514
00515 new KAction(i18n("Move Character Right"), Key_Right, this,
00516 SLOT(cursorRight()), ac, "move_cursor_right");
00517
00518 new KAction(i18n("Move Character Left"), Key_Left, this, SLOT(cursorLeft()),
00519 ac, "move_cusor_left");
00520
00521 new KAction(
00522 i18n("Select to Next Line"), SHIFT + Key_Down,
00523 this, SLOT(shiftDown()),
00524 ac, "select_line_down" );
00525 new KAction(
00526 i18n("Scroll Line Down"), CTRL + Key_Down,
00527 this, SLOT(scrollDown()),
00528 ac, "scroll_line_down" );
00529
00530 new KAction(
00531 i18n("Scroll Page Up"), KStdAccel::prior(),
00532 this, SLOT(pageUp()),
00533 ac, "scroll_page_up" );
00534 new KAction(
00535 i18n("Select Page Up"), SHIFT + Key_PageUp,
00536 this, SLOT(shiftPageUp()),
00537 ac, "select_page_up" );
00538 new KAction(
00539 i18n("Move to Top of View"), CTRL + Key_PageUp,
00540 this, SLOT(topOfView()),
00541 ac, "move_top_of_view" );
00542 new KAction(
00543 i18n("Select to Top of View"), CTRL + SHIFT + Key_PageUp,
00544 this, SLOT(shiftTopOfView()),
00545 ac, "select_top_of_view" );
00546
00547 new KAction(
00548 i18n("Scroll Page Down"), KStdAccel::next(),
00549 this, SLOT(pageDown()),
00550 ac, "scroll_page_down" );
00551 new KAction(
00552 i18n("Select Page Down"), SHIFT + Key_PageDown,
00553 this, SLOT(shiftPageDown()),
00554 ac, "select_page_down" );
00555 new KAction(
00556 i18n("Move to Bottom of View"), CTRL + Key_PageDown,
00557 this, SLOT(bottomOfView()),
00558 ac, "move_bottom_of_view" );
00559 new KAction(
00560 i18n("Select to Bottom of View"), CTRL + SHIFT + Key_PageDown,
00561 this, SLOT(shiftBottomOfView()),
00562 ac, "select_bottom_of_view" );
00563 new KAction(
00564 i18n("Move to Matching Bracket"), CTRL + Key_6,
00565 this, SLOT(toMatchingBracket()),
00566 ac, "to_matching_bracket" );
00567 new KAction(
00568 i18n("Select to Matching Bracket"), SHIFT + CTRL + Key_6,
00569 this, SLOT(shiftToMatchingBracket()),
00570 ac, "select_matching_bracket" );
00571
00572
00573 if ( !m_doc->readOnly() )
00574 {
00575 new KAction(
00576 i18n("Transpose Characters"), CTRL + Key_T,
00577 this, SLOT(transpose()),
00578 ac, "transpose_char" );
00579
00580 new KAction(
00581 i18n("Delete Line"), CTRL + Key_K,
00582 this, SLOT(killLine()),
00583 ac, "delete_line" );
00584
00585 new KAction(
00586 i18n("Delete Word Left"), KStdAccel::deleteWordBack(),
00587 this, SLOT(deleteWordLeft()),
00588 ac, "delete_word_left" );
00589
00590 new KAction(
00591 i18n("Delete Word Right"), KStdAccel::deleteWordForward(),
00592 this, SLOT(deleteWordRight()),
00593 ac, "delete_word_right" );
00594
00595 new KAction(i18n("Delete Next Character"), Key_Delete,
00596 this, SLOT(keyDelete()),
00597 ac, "delete_next_character");
00598
00599 KAction *a = new KAction(i18n("Backspace"), Key_Backspace,
00600 this, SLOT(backspace()),
00601 ac, "backspace");
00602 KShortcut cut = a->shortcut();
00603 cut.append( KKey( SHIFT + Key_Backspace ) );
00604 a->setShortcut( cut );
00605 }
00606
00607 connect( this, SIGNAL(gotFocus(Kate::View*)),
00608 this, SLOT(slotGotFocus()) );
00609 connect( this, SIGNAL(lostFocus(Kate::View*)),
00610 this, SLOT(slotLostFocus()) );
00611
00612 m_editActions->readShortcutSettings( "Katepart Shortcuts" );
00613
00614 if( hasFocus() )
00615 slotGotFocus();
00616 else
00617 slotLostFocus();
00618
00619
00620 }
00621
00622 void KateView::setupCodeFolding()
00623 {
00624 KActionCollection *ac=this->actionCollection();
00625 new KAction( i18n("Collapse Toplevel"), CTRL+SHIFT+Key_Minus,
00626 m_doc->foldingTree(),SLOT(collapseToplevelNodes()),ac,"folding_toplevel");
00627 new KAction( i18n("Expand Toplevel"), CTRL+SHIFT+Key_Plus,
00628 this,SLOT(slotExpandToplevel()),ac,"folding_expandtoplevel");
00629 new KAction( i18n("Collapse One Local Level"), CTRL+Key_Minus,
00630 this,SLOT(slotCollapseLocal()),ac,"folding_collapselocal");
00631 new KAction( i18n("Expand One Local Level"), CTRL+Key_Plus,
00632 this,SLOT(slotExpandLocal()),ac,"folding_expandlocal");
00633
00634 #ifdef DEBUGACCELS
00635 KAccel* debugAccels = new KAccel(this,this);
00636 debugAccels->insert("KATE_DUMP_REGION_TREE",i18n("Show the code folding region tree"),"","Ctrl+Shift+Alt+D",m_doc,SLOT(dumpRegionTree()));
00637 debugAccels->insert("KATE_TEMPLATE_TEST",i18n("Basic template code test"),"","Ctrl+Shift+Alt+T",m_doc,SLOT(testTemplateCode()));
00638 debugAccels->setEnabled(true);
00639 #endif
00640 }
00641
00642 void KateView::slotExpandToplevel()
00643 {
00644 m_doc->foldingTree()->expandToplevelNodes(m_doc->numLines());
00645 }
00646
00647 void KateView::slotCollapseLocal()
00648 {
00649 int realLine = m_doc->foldingTree()->collapseOne(cursorLine());
00650 if (realLine != -1)
00651
00652
00653 setCursorPositionInternal(realLine, cursorColumn(), tabWidth(), false);
00654 }
00655
00656 void KateView::slotExpandLocal()
00657 {
00658 m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
00659 }
00660
00661 void KateView::setupCodeCompletion()
00662 {
00663 m_codeCompletion = new KateCodeCompletion(this);
00664 connect( m_codeCompletion, SIGNAL(completionAborted()),
00665 this, SIGNAL(completionAborted()));
00666 connect( m_codeCompletion, SIGNAL(completionDone()),
00667 this, SIGNAL(completionDone()));
00668 connect( m_codeCompletion, SIGNAL(argHintHidden()),
00669 this, SIGNAL(argHintHidden()));
00670 connect( m_codeCompletion, SIGNAL(completionDone(KTextEditor::CompletionEntry)),
00671 this, SIGNAL(completionDone(KTextEditor::CompletionEntry)));
00672 connect( m_codeCompletion, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)),
00673 this, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)));
00674 }
00675
00676 void KateView::slotGotFocus()
00677 {
00678 m_editActions->accel()->setEnabled( true );
00679
00680 slotStatusMsg ();
00681 }
00682
00683 void KateView::slotLostFocus()
00684 {
00685 m_editActions->accel()->setEnabled( false );
00686 }
00687
00688 void KateView::setDynWrapIndicators(int mode)
00689 {
00690 config()->setDynWordWrapIndicators (mode);
00691 }
00692
00693 void KateView::slotStatusMsg ()
00694 {
00695 QString ovrstr;
00696 if (m_doc->isReadWrite())
00697 {
00698 if (m_doc->config()->configFlags() & KateDocument::cfOvr)
00699 ovrstr = i18n(" OVR ");
00700 else
00701 ovrstr = i18n(" INS ");
00702 }
00703 else
00704 ovrstr = i18n(" R/O ");
00705
00706 uint r = cursorLine() + 1;
00707 uint c = cursorColumn() + 1;
00708
00709 QString s1 = i18n(" Line: %1").arg(KGlobal::locale()->formatNumber(r, 0));
00710 QString s2 = i18n(" Col: %1").arg(KGlobal::locale()->formatNumber(c, 0));
00711
00712 QString modstr = m_doc->isModified() ? QString (" * ") : QString (" ");
00713 QString blockstr = blockSelectionMode() ? i18n(" BLK ") : i18n(" NORM ");
00714
00715 emit viewStatusMsg (s1 + s2 + " " + ovrstr + blockstr + modstr);
00716 }
00717
00718 void KateView::slotSelectionTypeChanged()
00719 {
00720 m_toggleBlockSelection->setChecked( blockSelectionMode() );
00721
00722 emit newStatus();
00723 }
00724
00725 bool KateView::isOverwriteMode() const
00726 {
00727 return m_doc->config()->configFlags() & KateDocument::cfOvr;
00728 }
00729
00730 void KateView::reloadFile()
00731 {
00732 m_doc->reloadFile();
00733 emit newStatus();
00734 }
00735
00736 void KateView::slotUpdate()
00737 {
00738 emit newStatus();
00739
00740 slotNewUndo();
00741 }
00742
00743 void KateView::slotReadWriteChanged ()
00744 {
00745 if ( m_toggleWriteLock )
00746 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
00747
00748 m_cut->setEnabled (m_doc->isReadWrite());
00749 m_paste->setEnabled (m_doc->isReadWrite());
00750
00751 QStringList l;
00752
00753 l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
00754 << "tools_unindent" << "tools_cleanIndent" << "tools_align" << "tools_comment"
00755 << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
00756 << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
00757 << "edit_undo" << "edit_redo" << "tools_spelling_from_cursor"
00758 << "tools_spelling_selection";
00759
00760 KAction *a = 0;
00761 for (uint z = 0; z < l.size(); z++)
00762 if ((a = actionCollection()->action( l[z].ascii() )))
00763 a->setEnabled (m_doc->isReadWrite());
00764 }
00765
00766 void KateView::slotNewUndo()
00767 {
00768 if (m_doc->readOnly())
00769 return;
00770
00771 if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
00772 m_editUndo->setEnabled(m_doc->undoCount() > 0);
00773
00774 if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
00775 m_editRedo->setEnabled(m_doc->redoCount() > 0);
00776 }
00777
00778 void KateView::slotDropEventPass( QDropEvent * ev )
00779 {
00780 KURL::List lstDragURLs;
00781 bool ok = KURLDrag::decode( ev, lstDragURLs );
00782
00783 KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
00784 if ( ok && ext )
00785 emit ext->openURLRequest( lstDragURLs.first() );
00786 }
00787
00788 void KateView::contextMenuEvent( QContextMenuEvent *ev )
00789 {
00790 if ( !m_doc || !m_doc->browserExtension() )
00791 return;
00792 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(),
00793 QString::fromLatin1( "text/plain" ) );
00794 ev->accept();
00795 }
00796
00797 bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth, bool calledExternally )
00798 {
00799 KateTextLine::Ptr l = m_doc->kateTextLine( line );
00800
00801 if (!l)
00802 return false;
00803
00804 QString line_str = m_doc->textLine( line );
00805
00806 uint z;
00807 uint x = 0;
00808 for (z = 0; z < line_str.length() && z < col; z++) {
00809 if (line_str[z] == QChar('\t')) x += tabwidth - (x % tabwidth); else x++;
00810 }
00811
00812 m_viewInternal->updateCursor( KateTextCursor( line, x ), false, true, calledExternally );
00813
00814 return true;
00815 }
00816
00817 void KateView::setOverwriteMode( bool b )
00818 {
00819 if ( isOverwriteMode() && !b )
00820 m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
00821 else
00822 m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
00823
00824 m_toggleInsert->setChecked (isOverwriteMode ());
00825 }
00826
00827 void KateView::toggleInsert()
00828 {
00829 m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
00830 m_toggleInsert->setChecked (isOverwriteMode ());
00831
00832 emit newStatus();
00833 }
00834
00835 bool KateView::canDiscard()
00836 {
00837 return m_doc->closeURL();
00838 }
00839
00840 void KateView::flush()
00841 {
00842 m_doc->closeURL();
00843 }
00844
00845 KateView::saveResult KateView::save()
00846 {
00847 if( !m_doc->url().isValid() || !doc()->isReadWrite() )
00848 return saveAs();
00849
00850 if( m_doc->save() )
00851 return SAVE_OK;
00852
00853 return SAVE_ERROR;
00854 }
00855
00856 KateView::saveResult KateView::saveAs()
00857 {
00858
00859 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
00860 m_doc->url().url(),QString::null,this,i18n("Save File"));
00861
00862
00863
00864 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
00865 return SAVE_CANCEL;
00866
00867 m_doc->config()->setEncoding( res.encoding );
00868
00869 if( m_doc->saveAs( res.URLs.first() ) )
00870 return SAVE_OK;
00871
00872 return SAVE_ERROR;
00873 }
00874
00875 bool KateView::checkOverwrite( KURL u )
00876 {
00877 if( !u.isLocalFile() )
00878 return true;
00879
00880 QFileInfo info( u.path() );
00881 if( !info.exists() )
00882 return true;
00883
00884 return KMessageBox::Continue
00885 == KMessageBox::warningContinueCancel
00886 ( this,
00887 i18n( "A file named \"%1\" already exists. Are you sure you want to overwrite it?" ).arg( info.fileName() ),
00888 i18n( "Overwrite File?" ),
00889 KGuiItem( i18n( "&Overwrite" ), "filesave", i18n( "Overwrite the file" ) )
00890 );
00891 }
00892
00893 void KateView::slotSaveCanceled( const QString& error )
00894 {
00895 if ( !error.isEmpty() )
00896 KMessageBox::error( this, error );
00897 }
00898
00899 void KateView::gotoLine()
00900 {
00901 KateGotoLineDialog *dlg = new KateGotoLineDialog (this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
00902
00903 if (dlg->exec() == QDialog::Accepted)
00904 gotoLineNumber( dlg->getLine() - 1 );
00905
00906 delete dlg;
00907 }
00908
00909 void KateView::gotoLineNumber( int line )
00910 {
00911
00912 if ( !config()->persistentSelection() )
00913 clearSelection();
00914 setCursorPositionInternal ( line, 0, 1 );
00915 }
00916
00917 void KateView::joinLines()
00918 {
00919 int first = selStartLine();
00920 int last = selEndLine();
00921
00922 if ( first == last )
00923 {
00924 first = cursorLine();
00925 last = first + 1;
00926 }
00927 m_doc->joinLines( first, last );
00928 }
00929
00930 void KateView::readSessionConfig(KConfig *config)
00931 {
00932 setCursorPositionInternal (config->readNumEntry("CursorLine"), config->readNumEntry("CursorColumn"), 1);
00933 }
00934
00935 void KateView::writeSessionConfig(KConfig *config)
00936 {
00937 config->writeEntry("CursorLine",m_viewInternal->cursor.line());
00938 config->writeEntry("CursorColumn",m_viewInternal->cursor.col());
00939 }
00940
00941 int KateView::getEol()
00942 {
00943 return m_doc->config()->eol();
00944 }
00945
00946 void KateView::setEol(int eol)
00947 {
00948 if (!doc()->isReadWrite())
00949 return;
00950
00951 if (m_updatingDocumentConfig)
00952 return;
00953
00954 m_doc->config()->setEol (eol);
00955 }
00956
00957 void KateView::setIconBorder( bool enable )
00958 {
00959 config()->setIconBar (enable);
00960 }
00961
00962 void KateView::toggleIconBorder()
00963 {
00964 config()->setIconBar (!config()->iconBar());
00965 }
00966
00967 void KateView::setLineNumbersOn( bool enable )
00968 {
00969 config()->setLineNumbers (enable);
00970 }
00971
00972 void KateView::toggleLineNumbersOn()
00973 {
00974 config()->setLineNumbers (!config()->lineNumbers());
00975 }
00976
00977 void KateView::setScrollBarMarks( bool enable )
00978 {
00979 config()->setScrollBarMarks (enable);
00980 }
00981
00982 void KateView::toggleScrollBarMarks()
00983 {
00984 config()->setScrollBarMarks (!config()->scrollBarMarks());
00985 }
00986
00987 void KateView::toggleDynWordWrap()
00988 {
00989 config()->setDynWordWrap( !config()->dynWordWrap() );
00990 }
00991
00992 void KateView::setDynWordWrap( bool b )
00993 {
00994 config()->setDynWordWrap( b );
00995 }
00996
00997 void KateView::toggleWWMarker()
00998 {
00999 m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
01000 }
01001
01002 void KateView::setFoldingMarkersOn( bool enable )
01003 {
01004 config()->setFoldingBar ( enable );
01005 }
01006
01007 void KateView::toggleFoldingMarkers()
01008 {
01009 config()->setFoldingBar ( !config()->foldingBar() );
01010 }
01011
01012 bool KateView::iconBorder() {
01013 return m_viewInternal->leftBorder->iconBorderOn();
01014 }
01015
01016 bool KateView::lineNumbersOn() {
01017 return m_viewInternal->leftBorder->lineNumbersOn();
01018 }
01019
01020 bool KateView::scrollBarMarks() {
01021 return m_viewInternal->m_lineScroll->showMarks();
01022 }
01023
01024 int KateView::dynWrapIndicators() {
01025 return m_viewInternal->leftBorder->dynWrapIndicators();
01026 }
01027
01028 bool KateView::foldingMarkersOn() {
01029 return m_viewInternal->leftBorder->foldingMarkersOn();
01030 }
01031
01032 void KateView::showCmdLine ( bool enabled )
01033 {
01034 if (enabled == m_cmdLineOn)
01035 return;
01036
01037 if (enabled)
01038 {
01039 if (!m_cmdLine)
01040 {
01041 m_cmdLine = new KateCmdLine (this);
01042 m_grid->addMultiCellWidget (m_cmdLine, 2, 2, 0, 2);
01043 }
01044
01045 m_cmdLine->show ();
01046 m_cmdLine->setFocus();
01047 }
01048 else {
01049 m_cmdLine->hide ();
01050
01051 }
01052
01053 m_cmdLineOn = enabled;
01054 }
01055
01056 void KateView::toggleCmdLine ()
01057 {
01058 m_config->setCmdLine (!m_config->cmdLine ());
01059 }
01060
01061 void KateView::toggleWriteLock()
01062 {
01063 m_doc->setReadWrite( ! m_doc->isReadWrite() );
01064 }
01065
01066 void KateView::enableTextHints(int timeout)
01067 {
01068 m_viewInternal->enableTextHints(timeout);
01069 }
01070
01071 void KateView::disableTextHints()
01072 {
01073 m_viewInternal->disableTextHints();
01074 }
01075
01076 void KateView::applyWordWrap ()
01077 {
01078 if (hasSelection())
01079 m_doc->wrapText (selectStart.line(), selectEnd.line());
01080 else
01081 m_doc->wrapText (0, m_doc->lastLine());
01082 }
01083
01084 void KateView::slotNeedTextHint(int line, int col, QString &text)
01085 {
01086 text=QString("test %1 %2").arg(line).arg(col);
01087 }
01088
01089 void KateView::find()
01090 {
01091 m_search->find();
01092 }
01093
01094 void KateView::find( const QString& pattern, long flags, bool add )
01095 {
01096 m_search->find( pattern, flags, add );
01097 }
01098
01099 void KateView::replace()
01100 {
01101 m_search->replace();
01102 }
01103
01104 void KateView::replace( const QString &pattern, const QString &replacement, long flags )
01105 {
01106 m_search->replace( pattern, replacement, flags );
01107 }
01108
01109 void KateView::findAgain( bool back )
01110 {
01111 m_search->findAgain( back );
01112 }
01113
01114 void KateView::slotSelectionChanged ()
01115 {
01116 m_copy->setEnabled (hasSelection());
01117 m_copyHTML->setEnabled (hasSelection());
01118 m_deSelect->setEnabled (hasSelection());
01119
01120 if (m_doc->readOnly())
01121 return;
01122
01123 m_cut->setEnabled (hasSelection());
01124
01125 m_spell->updateActions ();
01126 }
01127
01128 void KateView::switchToCmdLine ()
01129 {
01130 if (!m_cmdLineOn)
01131 m_config->setCmdLine (true);
01132 else {
01133 if (m_cmdLine->hasFocus()) {
01134 this->setFocus();
01135 return;
01136 }
01137 }
01138 m_cmdLine->setFocus ();
01139 }
01140
01141 void KateView::showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 )
01142 {
01143 m_codeCompletion->showArgHint( arg1, arg2, arg3 );
01144 }
01145
01146 void KateView::showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset, bool cs )
01147 {
01148 emit aboutToShowCompletionBox();
01149 m_codeCompletion->showCompletionBox( arg1, offset, cs );
01150 }
01151
01152 KateRenderer *KateView::renderer ()
01153 {
01154 return m_renderer;
01155 }
01156
01157 void KateView::updateConfig ()
01158 {
01159 if (m_startingUp)
01160 return;
01161
01162 m_editActions->readShortcutSettings( "Katepart Shortcuts" );
01163
01164
01165 if (m_hasWrap != config()->dynWordWrap()) {
01166 m_viewInternal->prepareForDynWrapChange();
01167
01168 m_hasWrap = config()->dynWordWrap();
01169
01170 m_viewInternal->dynWrapChanged();
01171
01172 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
01173 m_toggleDynWrap->setChecked( config()->dynWordWrap() );
01174 }
01175
01176 m_viewInternal->leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
01177 m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
01178
01179
01180 m_viewInternal->leftBorder->setLineNumbersOn( config()->lineNumbers() );
01181 m_toggleLineNumbers->setChecked( config()->lineNumbers() );
01182
01183
01184 m_viewInternal->leftBorder->setIconBorderOn( config()->iconBar() );
01185 m_toggleIconBar->setChecked( config()->iconBar() );
01186
01187
01188 m_viewInternal->m_lineScroll->setShowMarks( config()->scrollBarMarks() );
01189 m_toggleScrollBarMarks->setChecked( config()->scrollBarMarks() );
01190
01191
01192 showCmdLine (config()->cmdLine());
01193
01194
01195
01196 m_toggleBlockSelection->setChecked( blockSelectionMode() );
01197 m_toggleInsert->setChecked( isOverwriteMode() );
01198
01199 updateFoldingConfig ();
01200
01201
01202 m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
01203
01204 m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
01205 }
01206
01207 void KateView::updateDocumentConfig()
01208 {
01209 if (m_startingUp)
01210 return;
01211
01212 m_updatingDocumentConfig = true;
01213
01214 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
01215
01216 m_updatingDocumentConfig = false;
01217
01218 m_viewInternal->updateView (true);
01219
01220 m_renderer->setTabWidth (m_doc->config()->tabWidth());
01221 m_renderer->setIndentWidth (m_doc->config()->indentationWidth());
01222 }
01223
01224 void KateView::updateRendererConfig()
01225 {
01226 if (m_startingUp)
01227 return;
01228
01229 m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
01230
01231
01232 m_viewInternal->updateView (true);
01233 m_viewInternal->repaint ();
01234
01235
01236 m_viewInternal->leftBorder->updateFont();
01237 m_viewInternal->leftBorder->repaint ();
01238
01239
01240
01241 }
01242
01243 void KateView::updateFoldingConfig ()
01244 {
01245
01246 bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
01247 m_viewInternal->leftBorder->setFoldingMarkersOn(doit);
01248 m_toggleFoldingMarkers->setChecked( doit );
01249 m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
01250
01251 QStringList l;
01252
01253 l << "folding_toplevel" << "folding_expandtoplevel"
01254 << "folding_collapselocal" << "folding_expandlocal";
01255
01256 KAction *a = 0;
01257 for (uint z = 0; z < l.size(); z++)
01258 if ((a = actionCollection()->action( l[z].ascii() )))
01259 a->setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
01260 }
01261
01262
01263 void KateView::editStart ()
01264 {
01265 m_viewInternal->editStart ();
01266 }
01267
01268 void KateView::editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom)
01269 {
01270 m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
01271 }
01272
01273 void KateView::editSetCursor (const KateTextCursor &cursor)
01274 {
01275 m_viewInternal->editSetCursor (cursor);
01276 }
01277
01278
01279
01280 bool KateView::tagLine (const KateTextCursor& virtualCursor)
01281 {
01282 return m_viewInternal->tagLine (virtualCursor);
01283 }
01284
01285 bool KateView::tagLines (int start, int end, bool realLines)
01286 {
01287 return m_viewInternal->tagLines (start, end, realLines);
01288 }
01289
01290 bool KateView::tagLines (KateTextCursor start, KateTextCursor end, bool realCursors)
01291 {
01292 return m_viewInternal->tagLines (start, end, realCursors);
01293 }
01294
01295 void KateView::tagAll ()
01296 {
01297 m_viewInternal->tagAll ();
01298 }
01299
01300 void KateView::clear ()
01301 {
01302 m_viewInternal->clear ();
01303 }
01304
01305 void KateView::repaintText (bool paintOnlyDirty)
01306 {
01307 m_viewInternal->paintText(0,0,m_viewInternal->width(),m_viewInternal->height(), paintOnlyDirty);
01308 }
01309
01310 void KateView::updateView (bool changed)
01311 {
01312 m_viewInternal->updateView (changed);
01313 m_viewInternal->leftBorder->update();
01314 }
01315
01316
01317
01318 void KateView::slotHlChanged()
01319 {
01320 KateHighlighting *hl = m_doc->highlight();
01321 bool ok ( !hl->getCommentStart(0).isEmpty() || !hl->getCommentSingleLineStart(0).isEmpty() );
01322
01323 if (actionCollection()->action("tools_comment"))
01324 actionCollection()->action("tools_comment")->setEnabled( ok );
01325
01326 if (actionCollection()->action("tools_uncomment"))
01327 actionCollection()->action("tools_uncomment")->setEnabled( ok );
01328
01329
01330 updateFoldingConfig ();
01331 }
01332
01333 uint KateView::cursorColumn()
01334 {
01335 uint r = m_doc->currentColumn(m_viewInternal->getCursor());
01336 if ( !( m_doc->config()->configFlags() & KateDocumentConfig::cfWrapCursor ) &&
01337 (uint)m_viewInternal->getCursor().col() > m_doc->textLine( m_viewInternal->getCursor().line() ).length() )
01338 r += m_viewInternal->getCursor().col() - m_doc->textLine( m_viewInternal->getCursor().line() ).length();
01339
01340 return r;
01341 }
01342
01343
01344
01345 bool KateView::setSelection( const KateTextCursor& start, const KateTextCursor& end )
01346 {
01347 KateTextCursor oldSelectStart = selectStart;
01348 KateTextCursor oldSelectEnd = selectEnd;
01349
01350 if (start <= end) {
01351 selectStart.setPos(start);
01352 selectEnd.setPos(end);
01353 } else {
01354 selectStart.setPos(end);
01355 selectEnd.setPos(start);
01356 }
01357
01358 tagSelection(oldSelectStart, oldSelectEnd);
01359
01360 repaintText(true);
01361
01362 emit selectionChanged ();
01363 emit m_doc->selectionChanged ();
01364
01365 return true;
01366 }
01367
01368 bool KateView::setSelection( uint startLine, uint startCol, uint endLine, uint endCol )
01369 {
01370 if (hasSelection())
01371 clearSelection(false, false);
01372
01373 return setSelection( KateTextCursor(startLine, startCol), KateTextCursor(endLine, endCol) );
01374 }
01375
01376 void KateView::syncSelectionCache()
01377 {
01378 m_viewInternal->selStartCached = selectStart;
01379 m_viewInternal->selEndCached = selectEnd;
01380 m_viewInternal->selectAnchor = selectEnd;
01381 }
01382
01383 bool KateView::clearSelection()
01384 {
01385 return clearSelection(true);
01386 }
01387
01388 bool KateView::clearSelection(bool redraw, bool finishedChangingSelection)
01389 {
01390 if( !hasSelection() )
01391 return false;
01392
01393 KateTextCursor oldSelectStart = selectStart;
01394 KateTextCursor oldSelectEnd = selectEnd;
01395
01396 selectStart.setPos(-1, -1);
01397 selectEnd.setPos(-1, -1);
01398
01399 tagSelection(oldSelectStart, oldSelectEnd);
01400
01401 oldSelectStart = selectStart;
01402 oldSelectEnd = selectEnd;
01403
01404 if (redraw)
01405 repaintText(true);
01406
01407 if (finishedChangingSelection)
01408 {
01409 emit selectionChanged();
01410 emit m_doc->selectionChanged ();
01411 }
01412
01413 return true;
01414 }
01415
01416 bool KateView::hasSelection() const
01417 {
01418 return selectStart != selectEnd;
01419 }
01420
01421 QString KateView::selection() const
01422 {
01423 int sc = selectStart.col();
01424 int ec = selectEnd.col();
01425
01426 if ( blockSelect )
01427 {
01428 if (sc > ec)
01429 {
01430 uint tmp = sc;
01431 sc = ec;
01432 ec = tmp;
01433 }
01434 }
01435 return m_doc->text (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
01436 }
01437
01438 bool KateView::removeSelectedText ()
01439 {
01440 if (!hasSelection())
01441 return false;
01442
01443 m_doc->editStart ();
01444
01445 int sc = selectStart.col();
01446 int ec = selectEnd.col();
01447
01448 if ( blockSelect )
01449 {
01450 if (sc > ec)
01451 {
01452 uint tmp = sc;
01453 sc = ec;
01454 ec = tmp;
01455 }
01456 }
01457
01458 m_doc->removeText (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
01459
01460
01461 clearSelection(false);
01462
01463 m_doc->editEnd ();
01464
01465 return true;
01466 }
01467
01468 bool KateView::selectAll()
01469 {
01470 setBlockSelectionMode (false);
01471
01472 return setSelection (0, 0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()));
01473 }
01474
01475 bool KateView::lineColSelected (int line, int col)
01476 {
01477 if ( (!blockSelect) && (col < 0) )
01478 col = 0;
01479
01480 KateTextCursor cursor(line, col);
01481
01482 if (blockSelect)
01483 return cursor.line() >= selectStart.line() && cursor.line() <= selectEnd.line() && cursor.col() >= selectStart.col() && cursor.col() < selectEnd.col();
01484 else
01485 return (cursor >= selectStart) && (cursor < selectEnd);
01486 }
01487
01488 bool KateView::lineSelected (int line)
01489 {
01490 return (!blockSelect)
01491 && (selectStart <= KateTextCursor(line, 0))
01492 && (line < selectEnd.line());
01493 }
01494
01495 bool KateView::lineEndSelected (int line, int endCol)
01496 {
01497 return (!blockSelect)
01498 && (line > selectStart.line() || (line == selectStart.line() && (selectStart.col() < endCol || endCol == -1)))
01499 && (line < selectEnd.line() || (line == selectEnd.line() && (endCol <= selectEnd.col() && endCol != -1)));
01500 }
01501
01502 bool KateView::lineHasSelected (int line)
01503 {
01504 return (selectStart < selectEnd)
01505 && (line >= selectStart.line())
01506 && (line <= selectEnd.line());
01507 }
01508
01509 bool KateView::lineIsSelection (int line)
01510 {
01511 return (line == selectStart.line() && line == selectEnd.line());
01512 }
01513
01514 void KateView::tagSelection(const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd)
01515 {
01516 if (hasSelection()) {
01517 if (oldSelectStart.line() == -1) {
01518
01519
01520
01521 tagLines(selectStart, selectEnd);
01522
01523 } else if (blockSelectionMode() && (oldSelectStart.col() != selectStart.col() || oldSelectEnd.col() != selectEnd.col())) {
01524
01525 tagLines(selectStart, selectEnd);
01526 tagLines(oldSelectStart, oldSelectEnd);
01527
01528 } else {
01529 if (oldSelectStart != selectStart) {
01530 if (oldSelectStart < selectStart)
01531 tagLines(oldSelectStart, selectStart);
01532 else
01533 tagLines(selectStart, oldSelectStart);
01534 }
01535
01536 if (oldSelectEnd != selectEnd) {
01537 if (oldSelectEnd < selectEnd)
01538 tagLines(oldSelectEnd, selectEnd);
01539 else
01540 tagLines(selectEnd, oldSelectEnd);
01541 }
01542 }
01543
01544 } else {
01545
01546 tagLines(oldSelectStart, oldSelectEnd);
01547 }
01548 }
01549
01550 void KateView::selectWord( const KateTextCursor& cursor )
01551 {
01552 int start, end, len;
01553
01554 KateTextLine::Ptr textLine = m_doc->plainKateTextLine(cursor.line());
01555
01556 if (!textLine)
01557 return;
01558
01559 len = textLine->length();
01560 start = end = cursor.col();
01561 while (start > 0 && m_doc->highlight()->isInWord(textLine->getChar(start - 1), textLine->attribute(start - 1))) start--;
01562 while (end < len && m_doc->highlight()->isInWord(textLine->getChar(end), textLine->attribute(start - 1))) end++;
01563 if (end <= start) return;
01564
01565 setSelection (cursor.line(), start, cursor.line(), end);
01566 }
01567
01568 void KateView::selectLine( const KateTextCursor& cursor )
01569 {
01570 setSelection (cursor.line(), 0, cursor.line()+1, 0);
01571 }
01572
01573 void KateView::selectLength( const KateTextCursor& cursor, int length )
01574 {
01575 int start, end;
01576
01577 KateTextLine::Ptr textLine = m_doc->plainKateTextLine(cursor.line());
01578
01579 if (!textLine)
01580 return;
01581
01582 start = cursor.col();
01583 end = start + length;
01584 if (end <= start) return;
01585
01586 setSelection (cursor.line(), start, cursor.line(), end);
01587 }
01588
01589 void KateView::cut()
01590 {
01591 if (!hasSelection())
01592 return;
01593
01594 copy();
01595 removeSelectedText();
01596 }
01597
01598 void KateView::copy() const
01599 {
01600 if (!hasSelection())
01601 return;
01602
01603 QApplication::clipboard()->setText(selection ());
01604 }
01605
01606 void KateView::copyHTML()
01607 {
01608 if (!hasSelection())
01609 return;
01610
01611 KMultipleDrag *drag = new KMultipleDrag();
01612
01613 QTextDrag *htmltextdrag = new QTextDrag(selectionAsHtml()) ;
01614 htmltextdrag->setSubtype("html");
01615
01616 drag->addDragObject( htmltextdrag);
01617 drag->addDragObject( new QTextDrag( selection()));
01618
01619 QApplication::clipboard()->setData(drag);
01620 }
01621
01622 QString KateView::selectionAsHtml()
01623 {
01624 int sc = selectStart.col();
01625 int ec = selectEnd.col();
01626
01627 if ( blockSelect )
01628 {
01629 if (sc > ec)
01630 {
01631 uint tmp = sc;
01632 sc = ec;
01633 ec = tmp;
01634 }
01635 }
01636
01637 return textAsHtml (selectStart.line(), sc, selectEnd.line(), ec, blockSelect);
01638 }
01639
01640 QString KateView::textAsHtml ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise)
01641 {
01642 kdDebug(13020) << "textAsHtml" << endl;
01643 if ( blockwise && (startCol > endCol) )
01644 return QString ();
01645
01646 QString s;
01647 QTextStream ts( &s, IO_WriteOnly );
01648 ts.setEncoding(QTextStream::UnicodeUTF8);
01649 ts << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
01650 ts << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
01651 ts << "<head>" << endl;
01652 ts << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
01653 ts << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
01654 ts << "</head>" << endl;
01655
01656 ts << "<body>" << endl;
01657 textAsHtmlStream(startLine, startCol, endLine, endCol, blockwise, &ts);
01658
01659 ts << "</body>" << endl;
01660 ts << "</html>" << endl;
01661 kdDebug(13020) << "html is: " << s << endl;
01662 return s;
01663 }
01664
01665 void KateView::textAsHtmlStream ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise, QTextStream *ts)
01666 {
01667 if ( (blockwise || startLine == endLine) && (startCol > endCol) )
01668 return;
01669
01670 if (startLine == endLine)
01671 {
01672 KateTextLine::Ptr textLine = m_doc->kateTextLine(startLine);
01673 if ( !textLine )
01674 return;
01675
01676 (*ts) << "<pre>" << endl;
01677
01678 lineAsHTML(textLine, startCol, endCol-startCol, ts);
01679 }
01680 else
01681 {
01682 (*ts) << "<pre>" << endl;
01683
01684 for (uint i = startLine; (i <= endLine) && (i < m_doc->numLines()); i++)
01685 {
01686 KateTextLine::Ptr textLine = m_doc->kateTextLine(i);
01687
01688 if ( !blockwise )
01689 {
01690 if (i == startLine)
01691 lineAsHTML(textLine, startCol, textLine->length()-startCol, ts);
01692 else if (i == endLine)
01693 lineAsHTML(textLine, 0, endCol, ts);
01694 else
01695 lineAsHTML(textLine, 0, textLine->length(), ts);
01696 }
01697 else
01698 {
01699 lineAsHTML( textLine, startCol, endCol-startCol, ts);
01700 }
01701
01702 if ( i < endLine )
01703 (*ts) << "\n";
01704 }
01705 }
01706 (*ts) << "</pre>";
01707 }
01708
01709
01710
01711 void KateView::lineAsHTML (KateTextLine::Ptr line, uint startCol, uint length, QTextStream *outputStream)
01712 {
01713 if(length == 0)
01714 return;
01715
01716
01717 QMap<uchar,QString> stylecache;
01718
01719 QString textcache;
01720
01721 KateAttribute *charAttributes = 0;
01722
01723 for (uint curPos=startCol;curPos<(length+startCol);curPos++)
01724 {
01725 if ( curPos == 0 || line->attribute( curPos ) != line->attribute( curPos - 1 ) &&
01726
01727
01728 KateAttribute(*charAttributes) != KateAttribute(*m_renderer->attribute(line->attribute(curPos))) )
01729 {
01730 (*outputStream) << textcache;
01731 textcache.truncate(0);
01732
01733 if ( curPos > startCol )
01734 (*outputStream) << "</span>";
01735
01736 charAttributes = m_renderer->attribute(line->attribute(curPos));
01737
01738 if ( ! stylecache.contains( line->attribute(curPos) ) )
01739 {
01740 QString textdecoration;
01741 QString style;
01742
01743 if ( charAttributes->bold() )
01744 style.append("font-weight: bold;");
01745 if ( charAttributes->italic() )
01746 style.append("font-style: italic;");
01747 if ( charAttributes->underline() )
01748 textdecoration = "underline";
01749 if ( charAttributes->overline() )
01750 textdecoration.append(" overline" );
01751 if ( charAttributes->strikeOut() )
01752 textdecoration.append(" line-trough" );
01753 if ( !textdecoration.isEmpty() )
01754 style.append("text-decoration: %1;").arg(textdecoration);
01755
01756
01757 if ( charAttributes->itemSet(KateAttribute::BGColor) )
01758 style.append(QString("background-color: %1;").arg(charAttributes->bgColor().name()));
01759 if ( charAttributes->itemSet(KateAttribute::TextColor) )
01760 style.append(QString("color: %1;").arg(charAttributes->textColor().name()));
01761
01762 stylecache[line->attribute(curPos)] = style;
01763 }
01764 (*outputStream)<<"<span style=\""
01765 << stylecache[line->attribute(curPos)]
01766 << "\">";
01767 }
01768
01769 QString s( line->getChar(curPos) );
01770 if ( s == "&" ) s = "&";
01771 else if ( s == "<" ) s = "<";
01772 else if ( s == ">" ) s = ">";
01773 textcache.append( s );
01774 }
01775
01776 (*outputStream) << textcache << "</span>";
01777 }
01778
01779 void KateView::exportAsHTML ()
01780 {
01781 KURL url = KFileDialog::getSaveURL(m_doc->docName(),"text/html",0,i18n("Export File as HTML"));
01782
01783 if ( url.isEmpty() )
01784 return;
01785
01786 QString filename;
01787 KTempFile tmp;
01788
01789 if ( url.isLocalFile() )
01790 filename = url.path();
01791 else
01792 filename = tmp.name();
01793
01794 KSaveFile *savefile=new KSaveFile(filename);
01795 if (!savefile->status())
01796 {
01797 QTextStream *outputStream = savefile->textStream();
01798
01799 outputStream->setEncoding(QTextStream::UnicodeUTF8);
01800
01801
01802 (*outputStream) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
01803 (*outputStream) << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
01804 (*outputStream) << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
01805 (*outputStream) << "<head>" << endl;
01806 (*outputStream) << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
01807 (*outputStream) << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
01808
01809 (*outputStream) << "<title>" << m_doc->docName () << "</title>" << endl;
01810 (*outputStream) << "</head>" << endl;
01811 (*outputStream) << "<body>" << endl;
01812
01813 textAsHtmlStream(0,0, m_doc->lastLine(), m_doc->lineLength(m_doc->lastLine()), false, outputStream);
01814
01815 (*outputStream) << "</body>" << endl;
01816 (*outputStream) << "</html>" << endl;
01817
01818
01819 savefile->close();
01820
01821 }
01822
01823
01824 delete savefile;
01825
01826 if ( url.isLocalFile() )
01827 return;
01828
01829 KIO::NetAccess::upload( filename, url, 0 );
01830 }
01831
01832
01833
01834
01835 bool KateView::blockSelectionMode ()
01836 {
01837 return blockSelect;
01838 }
01839
01840 bool KateView::setBlockSelectionMode (bool on)
01841 {
01842 if (on != blockSelect)
01843 {
01844 blockSelect = on;
01845
01846 KateTextCursor oldSelectStart = selectStart;
01847 KateTextCursor oldSelectEnd = selectEnd;
01848
01849 clearSelection(false, false);
01850
01851 setSelection(oldSelectStart, oldSelectEnd);
01852
01853 slotSelectionTypeChanged();
01854 }
01855
01856 return true;
01857 }
01858
01859 bool KateView::toggleBlockSelectionMode ()
01860 {
01861 m_toggleBlockSelection->setChecked (!blockSelect);
01862 return setBlockSelectionMode (!blockSelect);
01863 }
01864
01865 bool KateView::wrapCursor ()
01866 {
01867 return !blockSelectionMode() && (m_doc->configFlags() & KateDocument::cfWrapCursor);
01868 }
01869
01870
01871
01872
01873 void KateView::setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
01874 uint imSelStart, uint imSelEnd, bool imComposeEvent )
01875 {
01876 m_imStartLine = imStartLine;
01877 m_imStart = imStart;
01878 m_imEnd = imEnd;
01879 m_imSelStart = imSelStart;
01880 m_imSelEnd = imSelEnd;
01881 m_imComposeEvent = imComposeEvent;
01882 }
01883
01884 bool KateView::isIMSelection( int _line, int _column )
01885 {
01886 return ( ( int( m_imStartLine ) == _line ) && ( m_imSelStart < m_imSelEnd ) && ( _column >= int( m_imSelStart ) ) &&
01887 ( _column < int( m_imSelEnd ) ) );
01888 }
01889
01890 bool KateView::isIMEdit( int _line, int _column )
01891 {
01892 return ( ( int( m_imStartLine ) == _line ) && ( m_imStart < m_imEnd ) && ( _column >= int( m_imStart ) ) &&
01893 ( _column < int( m_imEnd ) ) );
01894 }
01895
01896 void KateView::getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
01897 uint *imSelStart, uint *imSelEnd )
01898 {
01899 *imStartLine = m_imStartLine;
01900 *imStart = m_imStart;
01901 *imEnd = m_imEnd;
01902 *imSelStart = m_imSelStart;
01903 *imSelEnd = m_imSelEnd;
01904 }
01905
01906
01907