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
00176
00177
00178
00179 delete m_renderer;
00180 m_renderer = 0;
00181
00182 delete m_config;
00183 m_config = 0;
00184 KateFactory::self()->deregisterView (this);
00185 }
00186
00187 void KateView::setupConnections()
00188 {
00189 connect( m_doc, SIGNAL(undoChanged()),
00190 this, SLOT(slotNewUndo()) );
00191 connect( m_doc, SIGNAL(hlChanged()),
00192 this, SLOT(slotHlChanged()) );
00193 connect( m_doc, SIGNAL(canceled(const QString&)),
00194 this, SLOT(slotSaveCanceled(const QString&)) );
00195 connect( m_viewInternal, SIGNAL(dropEventPass(QDropEvent*)),
00196 this, SIGNAL(dropEventPass(QDropEvent*)) );
00197 connect(this,SIGNAL(cursorPositionChanged()),this,SLOT(slotStatusMsg()));
00198 connect(this,SIGNAL(newStatus()),this,SLOT(slotStatusMsg()));
00199 connect(m_doc, SIGNAL(undoChanged()), this, SLOT(slotStatusMsg()));
00200
00201 if ( m_doc->browserView() )
00202 {
00203 connect( this, SIGNAL(dropEventPass(QDropEvent*)),
00204 this, SLOT(slotDropEventPass(QDropEvent*)) );
00205 }
00206 }
00207
00208 void KateView::setupActions()
00209 {
00210 KActionCollection *ac = this->actionCollection ();
00211 KAction *a;
00212
00213 m_toggleWriteLock = 0;
00214
00215 m_cut = a=KStdAction::cut(this, SLOT(cut()), ac);
00216 a->setWhatsThis(i18n("Cut the selected text and move it to the clipboard"));
00217
00218 m_paste = a=KStdAction::pasteText(this, SLOT(paste()), ac);
00219 a->setWhatsThis(i18n("Paste previously copied or cut clipboard contents"));
00220
00221 m_copy = a=KStdAction::copy(this, SLOT(copy()), ac);
00222 a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard."));
00223
00224 m_copyHTML = a = new KAction(i18n("Copy as &HTML"), "editcopy", 0, this, SLOT(copyHTML()), ac, "edit_copy_html");
00225 a->setWhatsThis(i18n( "Use this command to copy the currently selected text as HTML to the system clipboard."));
00226
00227 if (!m_doc->readOnly())
00228 {
00229 a=KStdAction::save(this, SLOT(save()), ac);
00230 a->setWhatsThis(i18n("Save the current document"));
00231
00232 a=m_editUndo = KStdAction::undo(m_doc, SLOT(undo()), ac);
00233 a->setWhatsThis(i18n("Revert the most recent editing actions"));
00234
00235 a=m_editRedo = KStdAction::redo(m_doc, SLOT(redo()), ac);
00236 a->setWhatsThis(i18n("Revert the most recent undo operation"));
00237
00238 (new KAction(i18n("&Word Wrap Document"), "", 0, this, SLOT(applyWordWrap()), ac, "tools_apply_wordwrap"))->setWhatsThis(
00239 i18n("Use this command to wrap all lines of the current document which are longer than the width of the"
00240 " current view, to fit into this view.<br><br> This is a static word wrap, meaning it is not updated"
00241 " when the view is resized."));
00242
00243
00244 a=new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()), ac, "tools_indent");
00245 a->setWhatsThis(i18n("Use this to indent a selected block of text.<br><br>"
00246 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00247 a=new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::SHIFT+Qt::Key_I, this, SLOT(unIndent()), ac, "tools_unindent");
00248 a->setWhatsThis(i18n("Use this to unindent a selected block of text."));
00249
00250 a=new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()), ac, "tools_cleanIndent");
00251 a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces)<br><br>"
00252 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00253
00254 a=new KAction(i18n("&Align"), 0, this, SLOT(align()), ac, "tools_align");
00255 a->setWhatsThis(i18n("Use this to align the current line or block of text to its proper indent level."));
00256
00257 a=new KAction(i18n("C&omment"), CTRL+Qt::Key_D, this, SLOT(comment()),
00258 ac, "tools_comment");
00259 a->setWhatsThis(i18n("This command comments out the current line or a selected block of text.<BR><BR>"
00260 "The characters for single/multiple line comments are defined within the language's highlighting."));
00261
00262 a=new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_D, this, SLOT(uncomment()),
00263 ac, "tools_uncomment");
00264 a->setWhatsThis(i18n("This command removes comments from the current line or a selected block of text.<BR><BR>"
00265 "The characters for single/multiple line comments are defined within the language's highlighting."));
00266 a = m_toggleWriteLock = new KToggleAction(
00267 i18n("&Read Only Mode"), 0, 0,
00268 this, SLOT( toggleWriteLock() ),
00269 ac, "tools_toggle_write_lock" );
00270 a->setWhatsThis( i18n("Lock/unlock the document for writing") );
00271
00272 a = new KAction( i18n("Uppercase"), CTRL + Qt::Key_U, this,
00273 SLOT(uppercase()), ac, "tools_uppercase" );
00274 a->setWhatsThis( i18n("Convert the selection to uppercase, or the character to the "
00275 "right of the cursor if no text is selected.") );
00276
00277 a = new KAction( i18n("Lowercase"), CTRL + SHIFT + Qt::Key_U, this,
00278 SLOT(lowercase()), ac, "tools_lowercase" );
00279 a->setWhatsThis( i18n("Convert the selection to lowercase, or the character to the "
00280 "right of the cursor if no text is selected.") );
00281
00282 a = new KAction( i18n("Capitalize"), CTRL + ALT + Qt::Key_U, this,
00283 SLOT(capitalize()), ac, "tools_capitalize" );
00284 a->setWhatsThis( i18n("Capitalize the selection, or the word under the "
00285 "cursor if no text is selected.") );
00286
00287 a = new KAction( i18n("Join Lines"), CTRL + Qt::Key_J, this,
00288 SLOT( joinLines() ), ac, "tools_join_lines" );
00289 }
00290 else
00291 {
00292 m_cut->setEnabled (false);
00293 m_paste->setEnabled (false);
00294 m_editUndo = 0;
00295 m_editRedo = 0;
00296 }
00297
00298 a=KStdAction::print( m_doc, SLOT(print()), ac );
00299 a->setWhatsThis(i18n("Print the current document."));
00300
00301 a=new KAction(i18n("Reloa&d"), "reload", KStdAccel::reload(), this, SLOT(reloadFile()), ac, "file_reload");
00302 a->setWhatsThis(i18n("Reload the current document from disk."));
00303
00304 a=KStdAction::saveAs(this, SLOT(saveAs()), ac);
00305 a->setWhatsThis(i18n("Save the current document to disk, with a name of your choice."));
00306
00307 a=KStdAction::gotoLine(this, SLOT(gotoLine()), ac);
00308 a->setWhatsThis(i18n("This command opens a dialog and lets you choose a line that you want the cursor to move to."));
00309
00310 a=new KAction(i18n("&Configure Editor..."), 0, m_doc, SLOT(configDialog()),ac, "set_confdlg");
00311 a->setWhatsThis(i18n("Configure various aspects of this editor."));
00312
00313 KateViewHighlightAction *menu = new KateViewHighlightAction (i18n("&Highlighting"), ac, "set_highlight");
00314 menu->setWhatsThis(i18n("Here you can choose how the current document should be highlighted."));
00315 menu->updateMenu (m_doc);
00316
00317 KateViewFileTypeAction *ftm = new KateViewFileTypeAction (i18n("&Filetype"),ac,"set_filetype");
00318 ftm->updateMenu (m_doc);
00319
00320 KateViewSchemaAction *schemaMenu = new KateViewSchemaAction (i18n("&Schema"),ac,"view_schemas");
00321 schemaMenu->updateMenu (this);
00322
00323
00324 new KateViewIndentationAction (m_doc, i18n("&Indentation"),ac,"tools_indentation");
00325
00326
00327 a = new KAction(i18n("E&xport as HTML..."), 0, 0, this, SLOT(exportAsHTML()), ac, "file_export_html");
00328 a->setWhatsThis(i18n("This command allows you to export the current document"
00329 " with all highlighting information into a HTML document."));
00330
00331 m_selectAll = a=KStdAction::selectAll(this, SLOT(selectAll()), ac);
00332 a->setWhatsThis(i18n("Select the entire text of the current document."));
00333
00334 m_deSelect = a=KStdAction::deselect(this, SLOT(clearSelection()), ac);
00335 a->setWhatsThis(i18n("If you have selected something within the current document, this will no longer be selected."));
00336
00337 a=new KAction(i18n("Enlarge Font"), "viewmag+", 0, m_viewInternal, SLOT(slotIncFontSizes()), ac, "incFontSizes");
00338 a->setWhatsThis(i18n("This increases the display font size."));
00339
00340 a=new KAction(i18n("Shrink Font"), "viewmag-", 0, m_viewInternal, SLOT(slotDecFontSizes()), ac, "decFontSizes");
00341 a->setWhatsThis(i18n("This decreases the display font size."));
00342
00343 a= m_toggleBlockSelection = new KToggleAction(
00344 i18n("Bl&ock Selection Mode"), CTRL + SHIFT + Key_B,
00345 this, SLOT(toggleBlockSelectionMode()),
00346 ac, "set_verticalSelect");
00347 a->setWhatsThis(i18n("This command allows switching between the normal (line based) selection mode and the block selection mode."));
00348
00349 a= m_toggleInsert = new KToggleAction(
00350 i18n("Overwr&ite Mode"), Key_Insert,
00351 this, SLOT(toggleInsert()),
00352 ac, "set_insert" );
00353 a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text."));
00354
00355 KToggleAction *toggleAction;
00356 a= m_toggleDynWrap = toggleAction = new KToggleAction(
00357 i18n("&Dynamic Word Wrap"), Key_F10,
00358 this, SLOT(toggleDynWordWrap()),
00359 ac, "view_dynamic_word_wrap" );
00360 a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen."));
00361
00362 a= m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), 0, ac, "dynamic_word_wrap_indicators");
00363 a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"));
00364
00365 connect(m_setDynWrapIndicators, SIGNAL(activated(int)), this, SLOT(setDynWrapIndicators(int)));
00366 QStringList list2;
00367 list2.append(i18n("&Off"));
00368 list2.append(i18n("Follow &Line Numbers"));
00369 list2.append(i18n("&Always On"));
00370 m_setDynWrapIndicators->setItems(list2);
00371
00372 a= toggleAction=m_toggleFoldingMarkers = new KToggleAction(
00373 i18n("Show Folding &Markers"), Key_F9,
00374 this, SLOT(toggleFoldingMarkers()),
00375 ac, "view_folding_markers" );
00376 a->setWhatsThis(i18n("You can choose if the codefolding marks should be shown, if codefolding is possible."));
00377 toggleAction->setCheckedState(i18n("Hide Folding &Markers"));
00378
00379 a= m_toggleIconBar = toggleAction = new KToggleAction(
00380 i18n("Show &Icon Border"), Key_F6,
00381 this, SLOT(toggleIconBorder()),
00382 ac, "view_border");
00383 a=toggleAction;
00384 a->setWhatsThis(i18n("Show/hide the icon border.<BR><BR> The icon border shows bookmark symbols, for instance."));
00385 toggleAction->setCheckedState(i18n("Hide &Icon Border"));
00386
00387 a= toggleAction=m_toggleLineNumbers = new KToggleAction(
00388 i18n("Show &Line Numbers"), Key_F11,
00389 this, SLOT(toggleLineNumbersOn()),
00390 ac, "view_line_numbers" );
00391 a->setWhatsThis(i18n("Show/hide the line numbers on the left hand side of the view."));
00392 toggleAction->setCheckedState(i18n("Hide &Line Numbers"));
00393
00394 a= m_toggleScrollBarMarks = toggleAction = new KToggleAction(
00395 i18n("Show Scroll&bar Marks"), 0,
00396 this, SLOT(toggleScrollBarMarks()),
00397 ac, "view_scrollbar_marks");
00398 a->setWhatsThis(i18n("Show/hide the marks on the vertical scrollbar.<BR><BR>The marks, for instance, show bookmarks."));
00399 toggleAction->setCheckedState(i18n("Hide Scroll&bar Marks"));
00400
00401 a = toggleAction = m_toggleWWMarker = new KToggleAction(
00402 i18n("Show Static &Word Wrap Marker"), 0,
00403 this, SLOT( toggleWWMarker() ),
00404 ac, "view_word_wrap_marker" );
00405 a->setWhatsThis( i18n(
00406 "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
00407 "wrap column as defined in the editing properties" ));
00408 toggleAction->setCheckedState(i18n("Hide Static &Word Wrap Marker"));
00409
00410 a= m_switchCmdLine = new KAction(
00411 i18n("Switch to Command Line"), Key_F7,
00412 this, SLOT(switchToCmdLine()),
00413 ac, "switch_to_cmd_line" );
00414 a->setWhatsThis(i18n("Show/hide the command line on the bottom of the view."));
00415
00416 a=m_setEndOfLine = new KSelectAction(i18n("&End of Line"), 0, ac, "set_eol");
00417 a->setWhatsThis(i18n("Choose which line endings should be used, when you save the document"));
00418 QStringList list;
00419 list.append("&UNIX");
00420 list.append("&Windows/DOS");
00421 list.append("&Macintosh");
00422 m_setEndOfLine->setItems(list);
00423 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
00424 connect(m_setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int)));
00425
00426
00427 new KateViewEncodingAction (m_doc, this, i18n("E&ncoding"), ac, "set_encoding");
00428
00429 m_search->createActions( ac );
00430 m_spell->createActions( ac );
00431 m_bookmarks->createActions( ac );
00432
00433 slotSelectionChanged ();
00434
00435 connect (this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
00436 }
00437
00438 void KateView::setupEditActions()
00439 {
00440 m_editActions = new KActionCollection( m_viewInternal, this, "edit_actions" );
00441 KActionCollection* ac = m_editActions;
00442
00443 new KAction(
00444 i18n("Move Word Left"), CTRL + Key_Left,
00445 this,SLOT(wordLeft()),
00446 ac, "word_left" );
00447 new KAction(
00448 i18n("Select Character Left"), SHIFT + Key_Left,
00449 this,SLOT(shiftCursorLeft()),
00450 ac, "select_char_left" );
00451 new KAction(
00452 i18n("Select Word Left"), SHIFT + CTRL + Key_Left,
00453 this, SLOT(shiftWordLeft()),
00454 ac, "select_word_left" );
00455
00456 new KAction(
00457 i18n("Move Word Right"), CTRL + Key_Right,
00458 this, SLOT(wordRight()),
00459 ac, "word_right" );
00460 new KAction(
00461 i18n("Select Character Right"), SHIFT + Key_Right,
00462 this, SLOT(shiftCursorRight()),
00463 ac, "select_char_right" );
00464 new KAction(
00465 i18n("Select Word Right"), SHIFT + CTRL + Key_Right,
00466 this,SLOT(shiftWordRight()),
00467 ac, "select_word_right" );
00468
00469 new KAction(
00470 i18n("Move to Beginning of Line"), Key_Home,
00471 this, SLOT(home()),
00472 ac, "beginning_of_line" );
00473 new KAction(
00474 i18n("Move to Beginning of Document"), KStdAccel::home(),
00475 this, SLOT(top()),
00476 ac, "beginning_of_document" );
00477 new KAction(
00478 i18n("Select to Beginning of Line"), SHIFT + Key_Home,
00479 this, SLOT(shiftHome()),
00480 ac, "select_beginning_of_line" );
00481 new KAction(
00482 i18n("Select to Beginning of Document"), SHIFT + CTRL + Key_Home,
00483 this, SLOT(shiftTop()),
00484 ac, "select_beginning_of_document" );
00485
00486 new KAction(
00487 i18n("Move to End of Line"), Key_End,
00488 this, SLOT(end()),
00489 ac, "end_of_line" );
00490 new KAction(
00491 i18n("Move to End of Document"), KStdAccel::end(),
00492 this, SLOT(bottom()),
00493 ac, "end_of_document" );
00494 new KAction(
00495 i18n("Select to End of Line"), SHIFT + Key_End,
00496 this, SLOT(shiftEnd()),
00497 ac, "select_end_of_line" );
00498 new KAction(
00499 i18n("Select to End of Document"), SHIFT + CTRL + Key_End,
00500 this, SLOT(shiftBottom()),
00501 ac, "select_end_of_document" );
00502
00503 new KAction(
00504 i18n("Select to Previous Line"), SHIFT + Key_Up,
00505 this, SLOT(shiftUp()),
00506 ac, "select_line_up" );
00507 new KAction(
00508 i18n("Scroll Line Up"),"", CTRL + Key_Up,
00509 this, SLOT(scrollUp()),
00510 ac, "scroll_line_up" );
00511
00512 new KAction(i18n("Move to Next Line"), Key_Down, this, SLOT(down()),
00513 ac, "move_line_down");
00514
00515 new KAction(i18n("Move to Previous Line"), Key_Up, this, SLOT(up()),
00516 ac, "move_line_up");
00517
00518 new KAction(i18n("Move Character Right"), Key_Right, this,
00519 SLOT(cursorRight()), ac, "move_cursor_right");
00520
00521 new KAction(i18n("Move Character Left"), Key_Left, this, SLOT(cursorLeft()),
00522 ac, "move_cusor_left");
00523
00524 new KAction(
00525 i18n("Select to Next Line"), SHIFT + Key_Down,
00526 this, SLOT(shiftDown()),
00527 ac, "select_line_down" );
00528 new KAction(
00529 i18n("Scroll Line Down"), CTRL + Key_Down,
00530 this, SLOT(scrollDown()),
00531 ac, "scroll_line_down" );
00532
00533 new KAction(
00534 i18n("Scroll Page Up"), KStdAccel::prior(),
00535 this, SLOT(pageUp()),
00536 ac, "scroll_page_up" );
00537 new KAction(
00538 i18n("Select Page Up"), SHIFT + Key_PageUp,
00539 this, SLOT(shiftPageUp()),
00540 ac, "select_page_up" );
00541 new KAction(
00542 i18n("Move to Top of View"), CTRL + Key_PageUp,
00543 this, SLOT(topOfView()),
00544 ac, "move_top_of_view" );
00545 new KAction(
00546 i18n("Select to Top of View"), CTRL + SHIFT + Key_PageUp,
00547 this, SLOT(shiftTopOfView()),
00548 ac, "select_top_of_view" );
00549
00550 new KAction(
00551 i18n("Scroll Page Down"), KStdAccel::next(),
00552 this, SLOT(pageDown()),
00553 ac, "scroll_page_down" );
00554 new KAction(
00555 i18n("Select Page Down"), SHIFT + Key_PageDown,
00556 this, SLOT(shiftPageDown()),
00557 ac, "select_page_down" );
00558 new KAction(
00559 i18n("Move to Bottom of View"), CTRL + Key_PageDown,
00560 this, SLOT(bottomOfView()),
00561 ac, "move_bottom_of_view" );
00562 new KAction(
00563 i18n("Select to Bottom of View"), CTRL + SHIFT + Key_PageDown,
00564 this, SLOT(shiftBottomOfView()),
00565 ac, "select_bottom_of_view" );
00566 new KAction(
00567 i18n("Move to Matching Bracket"), CTRL + Key_6,
00568 this, SLOT(toMatchingBracket()),
00569 ac, "to_matching_bracket" );
00570 new KAction(
00571 i18n("Select to Matching Bracket"), SHIFT + CTRL + Key_6,
00572 this, SLOT(shiftToMatchingBracket()),
00573 ac, "select_matching_bracket" );
00574
00575
00576 if ( !m_doc->readOnly() )
00577 {
00578 new KAction(
00579 i18n("Transpose Characters"), CTRL + Key_T,
00580 this, SLOT(transpose()),
00581 ac, "transpose_char" );
00582
00583 new KAction(
00584 i18n("Delete Line"), CTRL + Key_K,
00585 this, SLOT(killLine()),
00586 ac, "delete_line" );
00587
00588 new KAction(
00589 i18n("Delete Word Left"), KStdAccel::deleteWordBack(),
00590 this, SLOT(deleteWordLeft()),
00591 ac, "delete_word_left" );
00592
00593 new KAction(
00594 i18n("Delete Word Right"), KStdAccel::deleteWordForward(),
00595 this, SLOT(deleteWordRight()),
00596 ac, "delete_word_right" );
00597
00598 new KAction(i18n("Delete Next Character"), Key_Delete,
00599 this, SLOT(keyDelete()),
00600 ac, "delete_next_character");
00601
00602 KAction *a = new KAction(i18n("Backspace"), Key_Backspace,
00603 this, SLOT(backspace()),
00604 ac, "backspace");
00605 KShortcut cut = a->shortcut();
00606 cut.append( KKey( SHIFT + Key_Backspace ) );
00607 a->setShortcut( cut );
00608 }
00609
00610 connect( this, SIGNAL(gotFocus(Kate::View*)),
00611 this, SLOT(slotGotFocus()) );
00612 connect( this, SIGNAL(lostFocus(Kate::View*)),
00613 this, SLOT(slotLostFocus()) );
00614
00615 m_editActions->readShortcutSettings( "Katepart Shortcuts" );
00616
00617 if( hasFocus() )
00618 slotGotFocus();
00619 else
00620 slotLostFocus();
00621
00622
00623 }
00624
00625 void KateView::setupCodeFolding()
00626 {
00627 KActionCollection *ac=this->actionCollection();
00628 new KAction( i18n("Collapse Toplevel"), CTRL+SHIFT+Key_Minus,
00629 m_doc->foldingTree(),SLOT(collapseToplevelNodes()),ac,"folding_toplevel");
00630 new KAction( i18n("Expand Toplevel"), CTRL+SHIFT+Key_Plus,
00631 this,SLOT(slotExpandToplevel()),ac,"folding_expandtoplevel");
00632 new KAction( i18n("Collapse One Local Level"), CTRL+Key_Minus,
00633 this,SLOT(slotCollapseLocal()),ac,"folding_collapselocal");
00634 new KAction( i18n("Expand One Local Level"), CTRL+Key_Plus,
00635 this,SLOT(slotExpandLocal()),ac,"folding_expandlocal");
00636
00637 #ifdef DEBUGACCELS
00638 KAccel* debugAccels = new KAccel(this,this);
00639 debugAccels->insert("KATE_DUMP_REGION_TREE",i18n("Show the code folding region tree"),"","Ctrl+Shift+Alt+D",m_doc,SLOT(dumpRegionTree()));
00640 debugAccels->insert("KATE_TEMPLATE_TEST",i18n("Basic template code test"),"","Ctrl+Shift+Alt+T",m_doc,SLOT(testTemplateCode()));
00641 debugAccels->setEnabled(true);
00642 #endif
00643 }
00644
00645 void KateView::slotExpandToplevel()
00646 {
00647 m_doc->foldingTree()->expandToplevelNodes(m_doc->numLines());
00648 }
00649
00650 void KateView::slotCollapseLocal()
00651 {
00652 int realLine = m_doc->foldingTree()->collapseOne(cursorLine());
00653 if (realLine != -1)
00654
00655
00656 setCursorPositionInternal(realLine, cursorColumn(), tabWidth(), false);
00657 }
00658
00659 void KateView::slotExpandLocal()
00660 {
00661 m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
00662 }
00663
00664 void KateView::setupCodeCompletion()
00665 {
00666 m_codeCompletion = new KateCodeCompletion(this);
00667 connect( m_codeCompletion, SIGNAL(completionAborted()),
00668 this, SIGNAL(completionAborted()));
00669 connect( m_codeCompletion, SIGNAL(completionDone()),
00670 this, SIGNAL(completionDone()));
00671 connect( m_codeCompletion, SIGNAL(argHintHidden()),
00672 this, SIGNAL(argHintHidden()));
00673 connect( m_codeCompletion, SIGNAL(completionDone(KTextEditor::CompletionEntry)),
00674 this, SIGNAL(completionDone(KTextEditor::CompletionEntry)));
00675 connect( m_codeCompletion, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)),
00676 this, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)));
00677 }
00678
00679 void KateView::slotGotFocus()
00680 {
00681 m_editActions->accel()->setEnabled( true );
00682
00683 slotStatusMsg ();
00684 }
00685
00686 void KateView::slotLostFocus()
00687 {
00688 m_editActions->accel()->setEnabled( false );
00689 }
00690
00691 void KateView::setDynWrapIndicators(int mode)
00692 {
00693 config()->setDynWordWrapIndicators (mode);
00694 }
00695
00696 void KateView::slotStatusMsg ()
00697 {
00698 QString ovrstr;
00699 if (m_doc->isReadWrite())
00700 {
00701 if (m_doc->config()->configFlags() & KateDocument::cfOvr)
00702 ovrstr = i18n(" OVR ");
00703 else
00704 ovrstr = i18n(" INS ");
00705 }
00706 else
00707 ovrstr = i18n(" R/O ");
00708
00709 uint r = cursorLine() + 1;
00710 uint c = cursorColumn() + 1;
00711
00712 QString s1 = i18n(" Line: %1").arg(KGlobal::locale()->formatNumber(r, 0));
00713 QString s2 = i18n(" Col: %1").arg(KGlobal::locale()->formatNumber(c, 0));
00714
00715 QString modstr = m_doc->isModified() ? QString (" * ") : QString (" ");
00716 QString blockstr = blockSelectionMode() ? i18n(" BLK ") : i18n(" NORM ");
00717
00718 emit viewStatusMsg (s1 + s2 + " " + ovrstr + blockstr + modstr);
00719 }
00720
00721 void KateView::slotSelectionTypeChanged()
00722 {
00723 m_toggleBlockSelection->setChecked( blockSelectionMode() );
00724
00725 emit newStatus();
00726 }
00727
00728 bool KateView::isOverwriteMode() const
00729 {
00730 return m_doc->config()->configFlags() & KateDocument::cfOvr;
00731 }
00732
00733 void KateView::reloadFile()
00734 {
00735 m_doc->reloadFile();
00736 emit newStatus();
00737 }
00738
00739 void KateView::slotUpdate()
00740 {
00741 emit newStatus();
00742
00743 slotNewUndo();
00744 }
00745
00746 void KateView::slotReadWriteChanged ()
00747 {
00748 if ( m_toggleWriteLock )
00749 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
00750
00751 m_cut->setEnabled (m_doc->isReadWrite());
00752 m_paste->setEnabled (m_doc->isReadWrite());
00753
00754 QStringList l;
00755
00756 l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
00757 << "tools_unindent" << "tools_cleanIndent" << "tools_align" << "tools_comment"
00758 << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
00759 << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
00760 << "edit_undo" << "edit_redo" << "tools_spelling_from_cursor"
00761 << "tools_spelling_selection";
00762
00763 KAction *a = 0;
00764 for (uint z = 0; z < l.size(); z++)
00765 if ((a = actionCollection()->action( l[z].ascii() )))
00766 a->setEnabled (m_doc->isReadWrite());
00767 }
00768
00769 void KateView::slotNewUndo()
00770 {
00771 if (m_doc->readOnly())
00772 return;
00773
00774 if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
00775 m_editUndo->setEnabled(m_doc->undoCount() > 0);
00776
00777 if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
00778 m_editRedo->setEnabled(m_doc->redoCount() > 0);
00779 }
00780
00781 void KateView::slotDropEventPass( QDropEvent * ev )
00782 {
00783 KURL::List lstDragURLs;
00784 bool ok = KURLDrag::decode( ev, lstDragURLs );
00785
00786 KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
00787 if ( ok && ext )
00788 emit ext->openURLRequest( lstDragURLs.first() );
00789 }
00790
00791 void KateView::contextMenuEvent( QContextMenuEvent *ev )
00792 {
00793 if ( !m_doc || !m_doc->browserExtension() )
00794 return;
00795 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(),
00796 QString::fromLatin1( "text/plain" ) );
00797 ev->accept();
00798 }
00799
00800 bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth, bool calledExternally )
00801 {
00802 KateTextLine::Ptr l = m_doc->kateTextLine( line );
00803
00804 if (!l)
00805 return false;
00806
00807 QString line_str = m_doc->textLine( line );
00808
00809 uint z;
00810 uint x = 0;
00811 for (z = 0; z < line_str.length() && z < col; z++) {
00812 if (line_str[z] == QChar('\t')) x += tabwidth - (x % tabwidth); else x++;
00813 }
00814
00815 m_viewInternal->updateCursor( KateTextCursor( line, x ), false, true, calledExternally );
00816
00817 return true;
00818 }
00819
00820 void KateView::setOverwriteMode( bool b )
00821 {
00822 if ( isOverwriteMode() && !b )
00823 m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
00824 else
00825 m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
00826
00827 m_toggleInsert->setChecked (isOverwriteMode ());
00828 }
00829
00830 void KateView::toggleInsert()
00831 {
00832 m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
00833 m_toggleInsert->setChecked (isOverwriteMode ());
00834
00835 emit newStatus();
00836 }
00837
00838 bool KateView::canDiscard()
00839 {
00840 return m_doc->closeURL();
00841 }
00842
00843 void KateView::flush()
00844 {
00845 m_doc->closeURL();
00846 }
00847
00848 KateView::saveResult KateView::save()
00849 {
00850 if( !m_doc->url().isValid() || !doc()->isReadWrite() )
00851 return saveAs();
00852
00853 if( m_doc->save() )
00854 return SAVE_OK;
00855
00856 return SAVE_ERROR;
00857 }
00858
00859 KateView::saveResult KateView::saveAs()
00860 {
00861
00862 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
00863 m_doc->url().url(),QString::null,this,i18n("Save File"));
00864
00865
00866
00867 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
00868 return SAVE_CANCEL;
00869
00870 m_doc->config()->setEncoding( res.encoding );
00871
00872 if( m_doc->saveAs( res.URLs.first() ) )
00873 return SAVE_OK;
00874
00875 return SAVE_ERROR;
00876 }
00877
00878 bool KateView::checkOverwrite( KURL u )
00879 {
00880 if( !u.isLocalFile() )
00881 return true;
00882
00883 QFileInfo info( u.path() );
00884 if( !info.exists() )
00885 return true;
00886
00887 return KMessageBox::Continue
00888 == KMessageBox::warningContinueCancel
00889 ( this,
00890 i18n( "A file named \"%1\" already exists. Are you sure you want to overwrite it?" ).arg( info.fileName() ),
00891 i18n( "Overwrite File?" ),
00892 KGuiItem( i18n( "&Overwrite" ), "filesave", i18n( "Overwrite the file" ) )
00893 );
00894 }
00895
00896 void KateView::slotSaveCanceled( const QString& error )
00897 {
00898 if ( !error.isEmpty() )
00899 KMessageBox::error( this, error );
00900 }
00901
00902 void KateView::gotoLine()
00903 {
00904 KateGotoLineDialog *dlg = new KateGotoLineDialog (this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
00905
00906 if (dlg->exec() == QDialog::Accepted)
00907 gotoLineNumber( dlg->getLine() - 1 );
00908
00909 delete dlg;
00910 }
00911
00912 void KateView::gotoLineNumber( int line )
00913 {
00914
00915 if ( !config()->persistentSelection() )
00916 clearSelection();
00917 setCursorPositionInternal ( line, 0, 1 );
00918 }
00919
00920 void KateView::joinLines()
00921 {
00922 int first = selStartLine();
00923 int last = selEndLine();
00924
00925 if ( first == last )
00926 {
00927 first = cursorLine();
00928 last = first + 1;
00929 }
00930 m_doc->