00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "kateview.h"
00025 #include "kateview.moc"
00026
00027 #include "kateviewinternal.h"
00028 #include "kateviewhelpers.h"
00029 #include "katerenderer.h"
00030 #include "katedocument.h"
00031 #include "katedocumenthelpers.h"
00032 #include "katefactory.h"
00033 #include "katehighlight.h"
00034 #include "katedialogs.h"
00035 #include "katetextline.h"
00036 #include "katecodefoldinghelpers.h"
00037 #include "katecodecompletion.h"
00038 #include "katesearch.h"
00039 #include "kateschema.h"
00040 #include "katebookmarks.h"
00041 #include "katesearch.h"
00042 #include "kateconfig.h"
00043 #include "katefiletype.h"
00044
00045 #include <ktexteditor/plugin.h>
00046
00047 #include <kparts/event.h>
00048
00049 #include <kconfig.h>
00050 #include <kurldrag.h>
00051 #include <kdebug.h>
00052 #include <kapplication.h>
00053 #include <kcursor.h>
00054 #include <klocale.h>
00055 #include <kglobal.h>
00056 #include <kcharsets.h>
00057 #include <kmessagebox.h>
00058 #include <kaction.h>
00059 #include <kstdaction.h>
00060 #include <kxmlguifactory.h>
00061 #include <kaccel.h>
00062 #include <klibloader.h>
00063 #include <kencodingfiledialog.h>
00064
00065 #include <qfont.h>
00066 #include <qfileinfo.h>
00067 #include <qstyle.h>
00068 #include <qevent.h>
00069 #include <qpopupmenu.h>
00070 #include <qlayout.h>
00071 #include <qclipboard.h>
00072
00073
00074 KateView::KateView( KateDocument *doc, QWidget *parent, const char * name )
00075 : Kate::View( doc, parent, name )
00076 , m_doc( doc )
00077 , m_search( new KateSearch( this ) )
00078 , m_bookmarks( new KateBookmarks( this ) )
00079 , m_cmdLine (0)
00080 , m_cmdLineOn (false)
00081 , m_active( false )
00082 , m_hasWrap( false )
00083 , m_startingUp (true)
00084 , m_updatingDocumentConfig (false)
00085 {
00086 KateFactory::self()->registerView( this );
00087 m_config = new KateViewConfig (this);
00088
00089 m_renderer = new KateRenderer(doc, this);
00090
00091 m_grid = new QGridLayout (this, 3, 3);
00092
00093 m_grid->setRowStretch ( 0, 10 );
00094 m_grid->setRowStretch ( 1, 0 );
00095 m_grid->setColStretch ( 0, 0 );
00096 m_grid->setColStretch ( 1, 10 );
00097 m_grid->setColStretch ( 2, 0 );
00098
00099 m_viewInternal = new KateViewInternal( this, doc );
00100 m_grid->addWidget (m_viewInternal, 0, 1);
00101
00102 setClipboardInterfaceDCOPSuffix (viewDCOPSuffix());
00103 setCodeCompletionInterfaceDCOPSuffix (viewDCOPSuffix());
00104 setDynWordWrapInterfaceDCOPSuffix (viewDCOPSuffix());
00105 setPopupMenuInterfaceDCOPSuffix (viewDCOPSuffix());
00106 setSessionConfigInterfaceDCOPSuffix (viewDCOPSuffix());
00107 setViewCursorInterfaceDCOPSuffix (viewDCOPSuffix());
00108 setViewStatusMsgInterfaceDCOPSuffix (viewDCOPSuffix());
00109
00110 setInstance( KateFactory::self()->instance() );
00111 doc->addView( this );
00112
00113 setFocusProxy( m_viewInternal );
00114 setFocusPolicy( StrongFocus );
00115
00116 if (!doc->singleViewMode()) {
00117 setXMLFile( "katepartui.rc" );
00118 } else {
00119 if( doc->readOnly() )
00120 setXMLFile( "katepartreadonlyui.rc" );
00121 else
00122 setXMLFile( "katepartui.rc" );
00123 }
00124
00125 setupConnections();
00126 setupActions();
00127 setupEditActions();
00128 setupCodeFolding();
00129 setupCodeCompletion();
00130
00131
00132 m_doc->enableAllPluginsGUI (this);
00133
00134
00135 slotNewUndo();
00136
00137 m_startingUp = false;
00138 updateConfig ();
00139
00140 m_viewInternal->show ();
00141 slotHlChanged();
00142
00143
00144
00145
00146
00147
00148 }
00149
00150 KateView::~KateView()
00151 {
00152 if (!m_doc->singleViewMode())
00153 m_doc->disableAllPluginsGUI (this);
00154
00155 m_doc->removeView( this );
00156
00157 delete m_viewInternal;
00158 delete m_codeCompletion;
00159
00160 delete m_renderer;
00161
00162 delete m_config;
00163 KateFactory::self()->deregisterView (this);
00164 }
00165
00166 void KateView::setupConnections()
00167 {
00168 connect( m_doc, SIGNAL(undoChanged()),
00169 this, SLOT(slotNewUndo()) );
00170 connect( m_doc, SIGNAL(hlChanged()),
00171 this, SLOT(slotHlChanged()) );
00172 connect( m_doc, SIGNAL(canceled(const QString&)),
00173 this, SLOT(slotSaveCanceled(const QString&)) );
00174 connect( m_viewInternal, SIGNAL(dropEventPass(QDropEvent*)),
00175 this, SIGNAL(dropEventPass(QDropEvent*)) );
00176 connect(this,SIGNAL(cursorPositionChanged()),this,SLOT(slotStatusMsg()));
00177 connect(this,SIGNAL(newStatus()),this,SLOT(slotStatusMsg()));
00178 connect(m_doc, SIGNAL(undoChanged()), this, SLOT(slotStatusMsg()));
00179
00180 if ( m_doc->browserView() )
00181 {
00182 connect( this, SIGNAL(dropEventPass(QDropEvent*)),
00183 this, SLOT(slotDropEventPass(QDropEvent*)) );
00184 }
00185 }
00186
00187 void KateView::setupActions()
00188 {
00189 KActionCollection *ac = this->actionCollection ();
00190 KAction *a;
00191
00192 m_toggleWriteLock = 0;
00193
00194 m_cut = a=KStdAction::cut(this, SLOT(cut()), ac);
00195 a->setWhatsThis(i18n("Cut the selected text and move it to the clipboard"));
00196
00197 m_paste = a=KStdAction::pasteText(this, SLOT(paste()), ac);
00198 a->setWhatsThis(i18n("Paste previously copied or cut clipboard contents"));
00199
00200 m_copy = a=KStdAction::copy(this, SLOT(copy()), ac);
00201 a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard."));
00202
00203
00204 if (!m_doc->readOnly())
00205 {
00206 KStdAction::spelling( m_doc, SLOT(spellcheck()), ac );
00207
00208 a=KStdAction::save(this, SLOT(save()), ac);
00209 a->setWhatsThis(i18n("Save the current document"));
00210
00211 a=m_editUndo = KStdAction::undo(m_doc, SLOT(undo()), ac);
00212 a->setWhatsThis(i18n("Revert the most recent editing actions"));
00213
00214 a=m_editRedo = KStdAction::redo(m_doc, SLOT(redo()), ac);
00215 a->setWhatsThis(i18n("Revert the most recent undo operation"));
00216
00217 (new KAction(i18n("&Word Wrap Document"), "", 0, m_doc, SLOT(applyWordWrap()), ac, "tools_apply_wordwrap"))->setWhatsThis(
00218 i18n("Use this command to wrap all lines of the current document which are longer than the width of the"
00219 " current view, to fit into this view.<br><br> This is a static word wrap, meaning it is not updated"
00220 " when the view is resized."));
00221
00222
00223 a=new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()),
00224 ac, "tools_indent");
00225 a->setWhatsThis(i18n("Use this to indent a selected block of text.<br><br>"
00226 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00227 a=new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::SHIFT+Qt::Key_I, this, SLOT(unIndent()),
00228 ac, "tools_unindent");
00229 a->setWhatsThis(i18n("Use this to unindent a selected block of text."));
00230 a=new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()),
00231 ac, "tools_cleanIndent");
00232 a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces)<br><br>"
00233 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00234
00235 a=new KAction(i18n("C&omment"), CTRL+Qt::Key_D, this, SLOT(comment()),
00236 ac, "tools_comment");
00237 a->setWhatsThis(i18n("This command comments out the current line or a selected block of text.<BR><BR>"
00238 "The characters for single/multiple line comments are defined within the language's highlighting."));
00239
00240 a=new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_D, this, SLOT(uncomment()),
00241 ac, "tools_uncomment");
00242 a->setWhatsThis(i18n("This command removes comments from the current line or a selected block of text.<BR><BR>"
00243 "The characters for single/multiple line comments are defined within the language's highlighting."));
00244 a = m_toggleWriteLock = new KToggleAction(
00245 i18n("&Read Only Mode"), 0, 0,
00246 this, SLOT( toggleWriteLock() ),
00247 ac, "tools_toggle_write_lock" );
00248 a->setWhatsThis( i18n("Lock/unlock the document for writing") );
00249
00250 a = new KAction( i18n("Uppercase"), CTRL + Qt::Key_U, this,
00251 SLOT(uppercase()), ac, "tools_uppercase" );
00252 a->setWhatsThis( i18n("Convert the selection to uppercase, or the character to the "
00253 "right of the cursor if no text is selected.") );
00254
00255 a = new KAction( i18n("Lowercase"), CTRL + SHIFT + Qt::Key_U, this,
00256 SLOT(lowercase()), ac, "tools_lowercase" );
00257 a->setWhatsThis( i18n("Convert the selection to lowercase, or the character to the "
00258 "right of the cursor if no text is selected.") );
00259
00260 a = new KAction( i18n("Capitalize"), CTRL + ALT + Qt::Key_U, this,
00261 SLOT(capitalize()), ac, "tools_capitalize" );
00262 a->setWhatsThis( i18n("Capitalize the selection, or the word under the "
00263 "cursor if no text is selected.") );
00264
00265 a = new KAction( i18n("Join Lines"), CTRL + Qt::Key_J, this,
00266 SLOT( joinLines() ), ac, "tools_join_lines" );
00267 }
00268 else
00269 {
00270 m_cut->setEnabled (false);
00271 m_paste->setEnabled (false);
00272 m_editUndo = 0;
00273 m_editRedo = 0;
00274 }
00275
00276 a=KStdAction::print( m_doc, SLOT(print()), ac );
00277 a->setWhatsThis(i18n("Print the current document."));
00278
00279 a=new KAction(i18n("Reloa&d"), "reload", KStdAccel::reload(), this, SLOT(reloadFile()), ac, "file_reload");
00280 a->setWhatsThis(i18n("Reload the current document from disk."));
00281
00282 a=KStdAction::saveAs(this, SLOT(saveAs()), ac);
00283 a->setWhatsThis(i18n("Save the current document to disk, with a name of your choice."));
00284
00285 a=KStdAction::gotoLine(this, SLOT(gotoLine()), ac);
00286 a->setWhatsThis(i18n("This command opens a dialog and lets you choose a line that you want the cursor to move to."));
00287
00288 a=new KAction(i18n("&Configure Editor..."), 0, m_doc, SLOT(configDialog()),ac, "set_confdlg");
00289 a->setWhatsThis(i18n("Configure various aspects of this editor."));
00290
00291 m_setHighlight = m_doc->hlActionMenu (i18n("&Highlight Mode"),ac,"set_highlight");
00292
00293 m_setFileType = new KateViewFileTypeAction (i18n("&Filetype Mode"),ac,"set_filetype");
00294 m_setFileType->updateMenu (m_doc);
00295
00296 m_schemaMenu = new KateViewSchemaAction (i18n("&Schema"),ac,"view_schemas");
00297 m_schemaMenu->updateMenu (this);
00298
00299 m_doc->exportActionMenu (i18n("E&xport"),ac,"file_export");
00300
00301 m_selectAll = a=KStdAction::selectAll(m_doc, SLOT(selectAll()), ac);
00302 a->setWhatsThis(i18n("Select the entire text of the current document."));
00303
00304 m_deSelect = a=KStdAction::deselect(m_doc, SLOT(clearSelection()), ac);
00305 a->setWhatsThis(i18n("If you have selected something within the current document, this will no longer be selected."));
00306
00307 a=new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, m_viewInternal, SLOT(slotIncFontSizes()), ac, "incFontSizes");
00308 a->setWhatsThis(i18n("This increases the display font size."));
00309
00310 a=new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, m_viewInternal, SLOT(slotDecFontSizes()), ac, "decFontSizes");
00311 a->setWhatsThis(i18n("This decreases the display font size."));
00312
00313 a= m_toggleBlockSelection = new KToggleAction(
00314 i18n("Bl&ock Selection Mode"), CTRL + SHIFT + Key_B,
00315 this, SLOT(toggleBlockSelectionMode()),
00316 ac, "set_verticalSelect");
00317 a->setWhatsThis(i18n("This command allows switching between the normal (line based) selection mode and the block selection mode."));
00318
00319 a= m_toggleInsert = new KToggleAction(
00320 i18n("Overwr&ite Mode"), Key_Insert,
00321 this, SLOT(toggleInsert()),
00322 ac, "set_insert" );
00323 a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text."));
00324
00325 KToggleAction *toggleAction;
00326 a= m_toggleDynWrap = toggleAction = new KToggleAction(
00327 i18n("&Dynamic Word Wrap"), Key_F10,
00328 this, SLOT(toggleDynWordWrap()),
00329 ac, "view_dynamic_word_wrap" );
00330 a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen."));
00331
00332 a= m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), 0, ac, "dynamic_word_wrap_indicators");
00333 a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"));
00334
00335 connect(m_setDynWrapIndicators, SIGNAL(activated(int)), this, SLOT(setDynWrapIndicators(int)));
00336 QStringList list2;
00337 list2.append("&Off");
00338 list2.append("Follow &Line Numbers");
00339 list2.append("&Always On");
00340 m_setDynWrapIndicators->setItems(list2);
00341
00342 a= toggleAction=m_toggleFoldingMarkers = new KToggleAction(
00343 i18n("Show Folding &Markers"), Key_F9,
00344 this, SLOT(toggleFoldingMarkers()),
00345 ac, "view_folding_markers" );
00346 a->setWhatsThis(i18n("You can choose if the codefolding marks should be shown, if codefolding is possible."));
00347
00348 a= m_toggleIconBar = toggleAction = new KToggleAction(
00349 i18n("Show &Icon Border"), Key_F6,
00350 this, SLOT(toggleIconBorder()),
00351 ac, "view_border");
00352 a=toggleAction;
00353 a->setWhatsThis(i18n("Show/hide the icon border.<BR><BR> The icon border shows bookmark symbols, for instance."));
00354
00355 a= m_toggleLineNumbers = toggleAction = new KToggleAction(
00356 i18n("Show &Line Numbers"), Key_F11,
00357 this, SLOT(toggleLineNumbersOn()),
00358 ac, "view_line_numbers" );
00359 a->setWhatsThis(i18n("Show/hide the line numbers on the left hand side of the view."));
00360
00361 a = m_toggleWWMarker = new KToggleAction(
00362 i18n("Show Static &Word Wrap Marker"), 0,
00363 this, SLOT( toggleWWMarker() ),
00364 ac, "view_word_wrap_marker" );
00365 a->setWhatsThis( i18n(
00366 "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
00367 "wrap column as defined in the editing properties" ));
00368
00369 a= m_toggleCmdLine = toggleAction = new KToggleAction(
00370 i18n("Show C&ommand Line"), 0,
00371 this, SLOT(toggleCmdLine()),
00372 ac, "view_cmd_line" );
00373 a->setWhatsThis(i18n("Show/hide the command line on the bottom of the view."));
00374
00375 a=m_setEndOfLine = new KSelectAction(i18n("&End of Line"), 0, ac, "set_eol");
00376 a->setWhatsThis(i18n("Choose which line endings should be used, when you save the document"));
00377 QStringList list;
00378 list.append("&UNIX");
00379 list.append("&Windows/DOS");
00380 list.append("&Macintosh");
00381 m_setEndOfLine->setItems(list);
00382 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
00383 connect(m_setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int)));
00384
00385
00386 m_setEncoding = new KSelectAction(i18n("Set &Encoding"), 0, ac, "set_encoding");
00387 list = KGlobal::charsets()->descriptiveEncodingNames();
00388 list.prepend( i18n( "Auto" ) );
00389 m_setEncoding->setItems(list);
00390 m_setEncoding->setCurrentItem (0);
00391 connect(m_setEncoding, SIGNAL(activated(const QString&)), this, SLOT(slotSetEncoding(const QString&)));
00392
00393 m_search->createActions( ac );
00394 m_bookmarks->createActions( ac );
00395
00396 selectionChanged ();
00397
00398 connect (m_doc, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
00399
00400
00401
00402 connect( QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged()) );
00403
00404 slotClipboardDataChanged();
00405 }
00406
00407 void KateView::setupEditActions()
00408 {
00409 m_editActions = new KActionCollection( m_viewInternal );
00410 KActionCollection* ac = m_editActions;
00411
00412 new KAction(
00413 i18n("Move Word Left"), CTRL + Key_Left,
00414 this,SLOT(wordLeft()),
00415 ac, "word_left" );
00416 new KAction(
00417 i18n("Select Character Left"), SHIFT + Key_Left,
00418 this,SLOT(shiftCursorLeft()),
00419 ac, "select_char_left" );
00420 new KAction(
00421 i18n("Select Word Left"), SHIFT + CTRL + Key_Left,
00422 this, SLOT(shiftWordLeft()),
00423 ac, "select_word_left" );
00424
00425 new KAction(
00426 i18n("Move Word Right"), CTRL + Key_Right,
00427 this, SLOT(wordRight()),
00428 ac, "word_right" );
00429 new KAction(
00430 i18n("Select Character Right"), SHIFT + Key_Right,
00431 this, SLOT(shiftCursorRight()),
00432 ac, "select_char_right" );
00433 new KAction(
00434 i18n("Select Word Right"), SHIFT + CTRL + Key_Right,
00435 this,SLOT(shiftWordRight()),
00436 ac, "select_word_right" );
00437
00438 new KAction(
00439 i18n("Move to Beginning of Line"), Key_Home,
00440 this, SLOT(home()),
00441 ac, "beginning_of_line" );
00442 new KAction(
00443 i18n("Move to Beginning of Document"), CTRL + Key_Home,
00444 this, SLOT(top()),
00445 ac, "beginning_of_document" );
00446 new KAction(
00447 i18n("Select to Beginning of Line"), SHIFT + Key_Home,
00448 this, SLOT(shiftHome()),
00449 ac, "select_beginning_of_line" );
00450 new KAction(
00451 i18n("Select to Beginning of Document"), SHIFT + CTRL + Key_Home,
00452 this, SLOT(shiftTop()),
00453 ac, "select_beginning_of_document" );
00454
00455 new KAction(
00456 i18n("Move to End of Line"), Key_End,
00457 this, SLOT(end()),
00458 ac, "end_of_line" );
00459 new KAction(
00460 i18n("Move to End of Document"), CTRL + Key_End,
00461 this, SLOT(bottom()),
00462 ac, "end_of_document" );
00463 new KAction(
00464 i18n("Select to End of Line"), SHIFT + Key_End,
00465 this, SLOT(shiftEnd()),
00466 ac, "select_end_of_line" );
00467 new KAction(
00468 i18n("Select to End of Document"), SHIFT + CTRL + Key_End,
00469 this, SLOT(shiftBottom()),
00470 ac, "select_end_of_document" );
00471
00472 new KAction(
00473 i18n("Select to Previous Line"), SHIFT + Key_Up,
00474 this, SLOT(shiftUp()),
00475 ac, "select_line_up" );
00476 new KAction(
00477 i18n("Scroll Line Up"),"", CTRL + Key_Up,
00478 this, SLOT(scrollUp()),
00479 ac, "scroll_line_up" );
00480
00481 new KAction(
00482 i18n("Select to Next Line"), SHIFT + Key_Down,
00483 this, SLOT(shiftDown()),
00484 ac, "select_line_down" );
00485 new KAction(
00486 i18n("Scroll Line Down"), CTRL + Key_Down,
00487 this, SLOT(scrollDown()),
00488 ac, "scroll_line_down" );
00489
00490 new KAction(
00491 i18n("Scroll Page Up"), Key_PageUp,
00492 this, SLOT(pageUp()),
00493 ac, "scroll_page_up" );
00494 new KAction(
00495 i18n("Select Page Up"), SHIFT + Key_PageUp,
00496 this, SLOT(shiftPageUp()),
00497 ac, "select_page_up" );
00498 new KAction(
00499 i18n("Move to Top of View"), CTRL + Key_PageUp,
00500 this, SLOT(topOfView()),
00501 ac, "move_top_of_view" );
00502 new KAction(
00503 i18n("Select to Top of View"), CTRL + SHIFT + Key_PageUp,
00504 this, SLOT(shiftTopOfView()),
00505 ac, "select_top_of_view" );
00506
00507 new KAction(
00508 i18n("Scroll Page Down"), Key_PageDown,
00509 this, SLOT(pageDown()),
00510 ac, "scroll_page_down" );
00511 new KAction(
00512 i18n("Select Page Down"), SHIFT + Key_PageDown,
00513 this, SLOT(shiftPageDown()),
00514 ac, "select_page_down" );
00515 new KAction(
00516 i18n("Move to Bottom of View"), CTRL + Key_PageDown,
00517 this, SLOT(bottomOfView()),
00518 ac, "move_bottom_of_view" );
00519 new KAction(
00520 i18n("Select to Bottom of View"), CTRL + SHIFT + Key_PageDown,
00521 this, SLOT(shiftBottomOfView()),
00522 ac, "select_bottom_of_view" );
00523 new KAction(
00524 i18n("Move to Matching Bracket"), CTRL + Key_6,
00525 this, SLOT(toMatchingBracket()),
00526 ac, "to_matching_bracket" );
00527 new KAction(
00528 i18n("Select to Matching Bracket"), SHIFT + CTRL + Key_6,
00529 this, SLOT(shiftToMatchingBracket()),
00530 ac, "select_matching_bracket" );
00531
00532 new KAction(
00533 i18n("Switch to Command Line"), Qt::Key_F7,
00534 this, SLOT(switchToCmdLine()),
00535 ac, "switch_to_cmd_line" );
00536
00537
00538 if ( !m_doc->readOnly() )
00539 {
00540 new KAction(
00541 i18n("Transpose Characters"), CTRL + Key_T,
00542 this, SLOT(transpose()),
00543 ac, "transpose_char" );
00544
00545 new KAction(
00546 i18n("Delete Line"), CTRL + Key_K,
00547 this, SLOT(killLine()),
00548 ac, "delete_line" );
00549
00550 new KAction(
00551 i18n("Delete Word Left"), CTRL + Key_Backspace,
00552 this, SLOT(deleteWordLeft()),
00553 ac, "delete_word_left" );
00554
00555 new KAction(
00556 i18n("Delete Word Right"), CTRL + Key_Delete,
00557 this, SLOT(deleteWordRight()),
00558 ac, "delete_word_right" );
00559 }
00560
00561 connect( this, SIGNAL(gotFocus(Kate::View*)),
00562 this, SLOT(slotGotFocus()) );
00563 connect( this, SIGNAL(lostFocus(Kate::View*)),
00564 this, SLOT(slotLostFocus()) );
00565
00566 if( hasFocus() )
00567 slotGotFocus();
00568 else
00569 slotLostFocus();
00570
00571 m_editActions->readShortcutSettings();
00572 }
00573
00574 void KateView::setupCodeFolding()
00575 {
00576 KActionCollection *ac=this->actionCollection();
00577 new KAction( i18n("Collapse Toplevel"), CTRL+SHIFT+Key_Minus,
00578 m_doc->foldingTree(),SLOT(collapseToplevelNodes()),ac,"folding_toplevel");
00579 new KAction( i18n("Expand Toplevel"), CTRL+SHIFT+Key_Plus,
00580 this,SLOT(slotExpandToplevel()),ac,"folding_expandtoplevel");
00581 new KAction( i18n("Collapse One Local Level"), CTRL+Key_Minus,
00582 this,SLOT(slotCollapseLocal()),ac,"folding_collapselocal");
00583 new KAction( i18n("Expand One Local Level"), CTRL+Key_Plus,
00584 this,SLOT(slotExpandLocal()),ac,"folding_expandlocal");
00585
00586 KAccel* debugAccels = new KAccel(this,this);
00587 debugAccels->insert("KATE_DUMP_REGION_TREE",i18n("Show the code folding region tree"),"","Ctrl+Shift+Alt+D",m_doc,SLOT(dumpRegionTree()));
00588 debugAccels->setEnabled(true);
00589 }
00590
00591 void KateView::slotExpandToplevel()
00592 {
00593 m_doc->foldingTree()->expandToplevelNodes(m_doc->numLines());
00594 }
00595
00596 void KateView::slotCollapseLocal()
00597 {
00598 int realLine = m_doc->foldingTree()->collapseOne(cursorLine());
00599 if (realLine != -1)
00600
00601 setCursorPosition(realLine, cursorColumn());
00602 }
00603
00604 void KateView::slotExpandLocal()
00605 {
00606 m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
00607 }
00608
00609 void KateView::setupCodeCompletion()
00610 {
00611 m_codeCompletion = new KateCodeCompletion(this);
00612 connect( m_codeCompletion, SIGNAL(completionAborted()),
00613 this, SIGNAL(completionAborted()));
00614 connect( m_codeCompletion, SIGNAL(completionDone()),
00615 this, SIGNAL(completionDone()));
00616 connect( m_codeCompletion, SIGNAL(argHintHidden()),
00617 this, SIGNAL(argHintHidden()));
00618 connect( m_codeCompletion, SIGNAL(completionDone(KTextEditor::CompletionEntry)),
00619 this, SIGNAL(completionDone(KTextEditor::CompletionEntry)));
00620 connect( m_codeCompletion, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)),
00621 this, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)));
00622 }
00623
00624 void KateView::slotGotFocus()
00625 {
00626 m_editActions->accel()->setEnabled( true );
00627
00628 slotStatusMsg ();
00629 }
00630
00631 void KateView::slotLostFocus()
00632 {
00633 m_editActions->accel()->setEnabled( false );
00634 }
00635
00636 void KateView::setDynWrapIndicators(int mode)
00637 {
00638 config()->setDynWordWrapIndicators (mode);
00639 }
00640
00641 void KateView::slotStatusMsg ()
00642 {
00643 QString ovrstr;
00644 if (m_doc->isReadWrite())
00645 {
00646 if (m_doc->config()->configFlags() & KateDocument::cfOvr)
00647 ovrstr = i18n(" OVR ");
00648 else
00649 ovrstr = i18n(" INS ");
00650 }
00651 else
00652 ovrstr = i18n(" R/O ");
00653
00654 uint r = cursorLine() + 1;
00655 uint c = cursorColumn();
00656
00657 QString s1 = i18n(" Line: %1").arg(KGlobal::locale()->formatNumber(r, 0));
00658 QString s2 = i18n(" Col: %1").arg(KGlobal::locale()->formatNumber(c, 0));
00659
00660 QString modstr = m_doc->isModified() ? QString (" * ") : QString (" ");
00661 QString blockstr = m_doc->blockSelectionMode() ? i18n(" BLK ") : i18n(" NORM ");
00662
00663 emit viewStatusMsg (s1 + s2 + " " + ovrstr + blockstr + modstr);
00664 }
00665
00666 void KateView::slotSelectionTypeChanged()
00667 {
00668 m_toggleBlockSelection->setChecked( m_doc->blockSelectionMode() );
00669
00670 emit newStatus();
00671 }
00672
00673 bool KateView::isOverwriteMode() const
00674 {
00675 return m_doc->config()->configFlags() & KateDocument::cfOvr;
00676 }
00677
00678 void KateView::reloadFile()
00679 {
00680
00681 uint cl = cursorLine();
00682 uint cc = cursorColumn();
00683
00684
00685 m_doc->reloadFile();
00686
00687 if (m_doc->numLines() >= cl)
00688 setCursorPosition( cl, cc );
00689 }
00690
00691 void KateView::slotUpdate()
00692 {
00693 emit newStatus();
00694
00695 slotNewUndo();
00696 }
00697
00698 void KateView::slotReadWriteChanged ()
00699 {
00700 if ( m_toggleWriteLock )
00701 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
00702
00703 m_cut->setEnabled (m_doc->isReadWrite());
00704 slotClipboardDataChanged();
00705
00706
00707 QStringList l;
00708
00709 l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
00710 << "tools_unindent" << "tools_cleanIndent" << "tools_comment"
00711 << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
00712 << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
00713 << "edit_undo" << "edit_redo";
00714
00715 KAction *a = 0;
00716 for (uint z = 0; z < l.size(); z++)
00717 if ((a = actionCollection()->action( l[z].ascii() )))
00718 a->setEnabled (m_doc->isReadWrite());
00719 }
00720
00721 void KateView::slotNewUndo()
00722 {
00723 if (m_doc->readOnly())
00724 return;
00725
00726 if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
00727 m_editUndo->setEnabled(m_doc->undoCount() > 0);
00728
00729 if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
00730 m_editRedo->setEnabled(m_doc->redoCount() > 0);
00731 }
00732
00733 void KateView::slotDropEventPass( QDropEvent * ev )
00734 {
00735 KURL::List lstDragURLs;
00736 bool ok = KURLDrag::decode( ev, lstDragURLs );
00737
00738 KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
00739 if ( ok && ext )
00740 emit ext->openURLRequest( lstDragURLs.first() );
00741 }
00742
00743 void KateView::contextMenuEvent( QContextMenuEvent *ev )
00744 {
00745 if ( !m_doc || !m_doc->browserExtension() )
00746 return;
00747
00748 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(),
00749 QString::fromLatin1( "text/plain" ) );
00750 ev->accept();
00751 }
00752
00753 bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth )
00754 {
00755 TextLine::Ptr l = m_doc->kateTextLine( line );
00756
00757 if (!l)
00758 return false;
00759
00760 QString line_str = m_doc->textLine( line );
00761
00762 uint z;
00763 uint x = 0;
00764 for (z = 0; z < line_str.length() && z < col; z++) {
00765 if (line_str[z] == QChar('\t')) x += tabwidth - (x % tabwidth); else x++;
00766 }
00767
00768 m_viewInternal->updateCursor( KateTextCursor( line, x ), false, true );
00769
00770 return true;
00771 }
00772
00773 void KateView::toggleBlockSelectionMode()
00774 {
00775 m_doc->toggleBlockSelectionMode();
00776 m_toggleBlockSelection->setChecked (m_doc->blockSelectionMode());
00777 }
00778
00779 void KateView::setOverwriteMode( bool b )
00780 {
00781 if ( isOverwriteMode() && !b )
00782 m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
00783 else
00784 m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
00785
00786 m_toggleInsert->setChecked (isOverwriteMode ());
00787 }
00788
00789 void KateView::toggleInsert()
00790 {
00791 m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
00792 m_toggleInsert->setChecked (isOverwriteMode ());
00793
00794 emit newStatus();
00795 }
00796
00797 bool KateView::canDiscard()
00798 {
00799 return m_doc->closeURL();
00800 }
00801
00802 void KateView::flush()
00803 {
00804 m_doc->closeURL();
00805 }
00806
00807 KateView::saveResult KateView::save()
00808 {
00809 if( !m_doc->url().isValid() || !doc()->isReadWrite() )
00810 return saveAs();
00811
00812 if( m_doc->save() )
00813 return SAVE_OK;
00814
00815 return SAVE_ERROR;
00816 }
00817
00818 KateView::saveResult KateView::saveAs()
00819 {
00820
00821 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
00822 m_doc->url().url(),QString::null,this,i18n("Save File"));
00823
00824 kdDebug()<<"urllist is emtpy?"<<res.URLs.isEmpty()<<endl;
00825 kdDebug()<<"url is:"<<res.URLs.first()<<endl;
00826 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
00827 return SAVE_CANCEL;
00828
00829 m_doc->setEncoding( res.encoding );
00830
00831 if( m_doc->saveAs( res.URLs.first() ) )
00832 return SAVE_OK;
00833
00834 return SAVE_ERROR;
00835 }
00836
00837 bool KateView::checkOverwrite( KURL u )
00838 {
00839 if( !u.isLocalFile() )
00840 return true;
00841
00842 QFileInfo info( u.path() );
00843 if( !info.exists() )
00844 return true;
00845
00846 return KMessageBox::Cancel != KMessageBox::warningContinueCancel( this,
00847 i18n( "A file named \"%1\" already exists. "
00848 "Are you sure you want to overwrite it?" ).arg( info.fileName() ),
00849 i18n( "Overwrite File?" ),
00850 i18n( "&Overwrite" ) );
00851 }
00852
00853 void KateView::slotSaveCanceled( const QString& error )
00854 {
00855 if ( !error.isEmpty() )
00856 KMessageBox::error( this, error );
00857 }
00858
00859 void KateView::gotoLine()
00860 {
00861 GotoLineDialog *dlg;
00862
00863 dlg = new GotoLineDialog(this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
00864
00865 if (dlg->exec() == QDialog::Accepted)
00866 gotoLineNumber( dlg->getLine() - 1 );
00867
00868 delete dlg;
00869 }
00870
00871 void KateView::gotoLineNumber( int line )
00872 {
00873 setCursorPositionInternal ( line, 0, 1 );
00874 }
00875
00876 void KateView::joinLines()
00877 {
00878 int first = m_doc->selStartLine();
00879 int last = m_doc->selEndLine();
00880
00881 if ( first == last )
00882 {
00883 first = cursorLine();
00884 last = first + 1;
00885 }
00886 m_doc->joinLines( first, last );
00887 }
00888
00889 void KateView::readSessionConfig(KConfig *config)
00890 {
00891 setCursorPositionInternal (config->readNumEntry("CursorLine"), config->readNumEntry("CursorColumn"), 1);
00892 }
00893
00894 void KateView::writeSessionConfig(KConfig *config)
00895 {
00896 config->writeEntry("CursorLine",m_viewInternal->cursor.line());
00897 config->writeEntry("CursorColumn",m_viewInternal->cursor.col());
00898 }
00899
00900 int KateView::getEol()
00901 {
00902 return m_doc->config()->eol();
00903 }
00904
00905 void KateView::setEol(int eol)
00906 {
00907 if (!doc()->isReadWrite())
00908 return;
00909
00910 if (m_updatingDocumentConfig)
00911 return;
00912
00913 m_doc->config()->setEol (eol);
00914 }
00915
00916 void KateView::slotSetEncoding( const QString& descriptiveName )
00917 {
00918 setEncoding( KGlobal::charsets()->encodingForName( descriptiveName ) );
00919 reloadFile();
00920 }
00921
00922 void KateView::setIconBorder( bool enable )
00923 {
00924 config()->setIconBar (enable);
00925 }
00926
00927 void KateView::toggleIconBorder()
00928 {
00929 config()->setIconBar (!config()->iconBar());
00930 }
00931
00932 void KateView::setLineNumbersOn( bool enable )
00933 {
00934 config()->setLineNumbers (enable);
00935 }
00936
00937 void KateView::toggleLineNumbersOn()
00938 {
00939 config()->setLineNumbers (!config()->lineNumbers());
00940 }
00941
00942 void KateView::toggleDynWordWrap()
00943 {
00944 config()->setDynWordWrap( !config()->dynWordWrap() );
00945 }
00946
00947 void KateView::setDynWordWrap( bool b )
00948 {
00949 config()->setDynWordWrap( b );
00950 }
00951
00952 void KateView::toggleWWMarker()
00953 {
00954 m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
00955 }
00956
00957 void KateView::setFoldingMarkersOn( bool enable )
00958 {
00959 config()->setFoldingBar ( enable );
00960 }
00961
00962 void KateView::toggleFoldingMarkers()
00963 {
00964 config()->setFoldingBar ( !config()->foldingBar() );
00965 }
00966
00967 bool KateView::iconBorder() {
00968 return m_viewInternal->leftBorder->iconBorderOn();
00969 }
00970
00971 bool KateView::lineNumbersOn() {
00972 return m_viewInternal->leftBorder->lineNumbersOn();
00973 }
00974
00975 int KateView::dynWrapIndicators() {
00976 return m_viewInternal->leftBorder->dynWrapIndicators();
00977 }
00978
00979 bool KateView::foldingMarkersOn() {
00980 return m_viewInternal->leftBorder->foldingMarkersOn();
00981 }
00982
00983 void KateView::showCmdLine ( bool enabled )
00984 {
00985 if (enabled == m_cmdLineOn)
00986 return;
00987
00988 if (enabled)
00989 {
00990 if (!m_cmdLine)
00991 {
00992 m_cmdLine = new KateCmdLine (this);
00993 m_grid->addMultiCellWidget (m_cmdLine, 2, 2, 0, 2);
00994 }
00995
00996 m_cmdLine->show ();
00997 }
00998 else
00999 m_cmdLine->hide ();
01000
01001 m_cmdLineOn = enabled;
01002 }
01003
01004 void KateView::toggleCmdLine ()
01005 {
01006 m_config->setCmdLine (!m_config->cmdLine ());
01007 }
01008
01009 void KateView::toggleWriteLock()
01010 {
01011 m_doc->setReadWrite( ! m_doc->isReadWrite() );
01012 }
01013
01014 void KateView::enableTextHints(int timeout)
01015 {
01016 m_viewInternal->enableTextHints(timeout);
01017 }
01018
01019 void KateView::disableTextHints()
01020 {
01021 m_viewInternal->disableTextHints();
01022 }
01023
01024 void KateView::slotNeedTextHint(int line, int col, QString &text)
01025 {
01026 text=QString("test %1 %2").arg(line).arg(col);
01027 }
01028
01029 void KateView::find()
01030 {
01031 m_search->find();
01032 }
01033
01034 void KateView::replace()
01035 {
01036 m_search->replace();
01037 }
01038
01039 void KateView::findAgain( bool back )
01040 {
01041 m_search->findAgain( back );
01042 }
01043
01044 void KateView::selectionChanged ()
01045 {
01046 if (m_doc->hasSelection())
01047 {
01048 m_copy->setEnabled (true);
01049 m_deSelect->setEnabled (true);
01050 }
01051 else
01052 {
01053 m_copy->setEnabled (false);
01054 m_deSelect->setEnabled (false);
01055 }
01056
01057 if (m_doc->readOnly())
01058 return;
01059
01060 if (m_doc->hasSelection())
01061 m_cut->setEnabled (true);
01062 else
01063 m_cut->setEnabled (false);
01064 }
01065
01066 void KateView::switchToCmdLine ()
01067 {
01068 if (!m_cmdLineOn)
01069 m_config->setCmdLine (true);
01070
01071 m_cmdLine->setFocus ();
01072 }
01073
01074 void KateView::showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 )
01075 {
01076 m_codeCompletion->showArgHint( arg1, arg2, arg3 );
01077 }
01078
01079 void KateView::showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset, bool cs )
01080 {
01081 emit aboutToShowCompletionBox();
01082 m_codeCompletion->showCompletionBox( arg1, offset, cs );
01083 }
01084
01085 KateRenderer *KateView::renderer ()
01086 {
01087 return m_renderer;
01088 }
01089
01090 void KateView::updateConfig ()
01091 {
01092 if (m_startingUp)
01093 return;
01094
01095 m_editActions->readShortcutSettings();
01096
01097
01098 if (m_hasWrap != config()->dynWordWrap()) {
01099 m_viewInternal->prepareForDynWrapChange();
01100
01101 m_hasWrap = config()->dynWordWrap();
01102
01103 m_viewInternal->dynWrapChanged();
01104
01105 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
01106 m_toggleDynWrap->setChecked( config()->dynWordWrap() );
01107 }
01108
01109 m_viewInternal->leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
01110 m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
01111
01112
01113 m_viewInternal->leftBorder->setLineNumbersOn( config()->lineNumbers() );
01114 m_toggleLineNumbers->setChecked( config()->lineNumbers() );
01115
01116
01117 m_viewInternal->leftBorder->setIconBorderOn( config()->iconBar() );
01118 m_toggleIconBar->setChecked( config()->iconBar() );
01119
01120
01121 showCmdLine (config()->cmdLine());
01122 m_toggleCmdLine->setChecked( config()->cmdLine() );
01123
01124
01125 m_toggleBlockSelection->setChecked( m_doc->blockSelectionMode() );
01126 m_toggleInsert->setChecked( isOverwriteMode() );
01127
01128 updateFoldingConfig ();
01129
01130
01131 m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
01132
01133 m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
01134 }
01135
01136 void KateView::updateDocumentConfig()
01137 {
01138 if (m_startingUp)
01139 return;
01140
01141 m_updatingDocumentConfig = true;
01142
01143 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
01144
01145 m_updatingDocumentConfig = false;
01146
01147 m_viewInternal->updateView (true);
01148
01149 m_renderer->setTabWidth (m_doc->config()->tabWidth());
01150 }
01151
01152 void KateView::updateRendererConfig()
01153 {
01154 if (m_startingUp)
01155 return;
01156
01157 m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
01158
01159
01160 m_viewInternal->updateView (true);
01161 m_viewInternal->repaint ();
01162
01163
01164 m_viewInternal->leftBorder->updateFont();
01165 m_viewInternal->leftBorder->repaint ();
01166 }
01167
01168 void KateView::updateFoldingConfig ()
01169 {
01170
01171 bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
01172 m_viewInternal->leftBorder->setFoldingMarkersOn(doit);
01173 m_toggleFoldingMarkers->setChecked( doit );
01174 m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
01175
01176 QStringList l;
01177
01178 l << "folding_toplevel" << "folding_expandtoplevel"
01179 << "folding_collapselocal" << "folding_expandlocal";
01180
01181 KAction *a = 0;
01182 for (uint z = 0; z < l.size(); z++)
01183 if ((a = actionCollection()->action( l[z].ascii() )))
01184 a->setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
01185 }
01186
01187
01188 void KateView::editStart ()
01189 {
01190 m_viewInternal->editStart ();
01191 }
01192
01193 void KateView::editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom)
01194 {
01195 m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
01196 }
01197
01198 void KateView::editSetCursor (const KateTextCursor &cursor)
01199 {
01200 m_viewInternal->editSetCursor (cursor);
01201 }
01202
01203
01204
01205 bool KateView::tagLine (const KateTextCursor& virtualCursor)
01206 {
01207 return m_viewInternal->tagLine (virtualCursor);
01208 }
01209
01210 bool KateView::tagLines (int start, int end, bool realLines)
01211 {
01212 return m_viewInternal->tagLines (start, end, realLines);
01213 }
01214
01215 bool KateView::tagLines (KateTextCursor start, KateTextCursor end, bool realCursors)
01216 {
01217 return m_viewInternal->tagLines (start, end, realCursors);
01218 }
01219
01220 void KateView::tagAll ()
01221 {
01222 m_viewInternal->tagAll ();
01223 }
01224
01225 void KateView::clear ()
01226 {
01227 m_viewInternal->clear ();
01228 }
01229
01230 void KateView::repaintText (bool paintOnlyDirty)
01231 {
01232 m_viewInternal->paintText(0,0,m_viewInternal->width(),m_viewInternal->height(), paintOnlyDirty);
01233 }
01234
01235 void KateView::updateView (bool changed)
01236 {
01237 m_viewInternal->updateView (changed);
01238 m_viewInternal->leftBorder->update();
01239 }
01240
01241
01242
01243 void KateView::slotClipboardDataChanged()
01244 {
01245 QMimeSource *data = QApplication::clipboard()->data(QClipboard::Clipboard);
01246 m_paste->setEnabled(m_doc->isReadWrite() && data->provides( "text/plain" ) );
01247 }
01248
01249 void KateView::slotHlChanged()
01250 {
01251 Highlight *hl = m_doc->highlight();
01252 bool ok ( ! ( hl->getCommentStart().isEmpty() && hl->getCommentSingleLineStart().isEmpty() ) );
01253
01254 if (actionCollection()->action("tools_comment"))
01255 actionCollection()->action("tools_comment")->setEnabled( ok );
01256
01257 if (actionCollection()->action("tools_uncomment"))
01258 actionCollection()->action("tools_uncomment")->setEnabled( ok );
01259
01260
01261 updateFoldingConfig ();
01262 }
01263