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(i18n("&Off"));
00338 list2.append(i18n("Follow &Line Numbers"));
00339 list2.append(i18n("&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
00602 setCursorPositionInternal(realLine, cursorColumn(), tabWidth(), false);
00603 }
00604
00605 void KateView::slotExpandLocal()
00606 {
00607 m_doc->foldingTree()->expandOne(cursorLine(), m_doc->numLines());
00608 }
00609
00610 void KateView::setupCodeCompletion()
00611 {
00612 m_codeCompletion = new KateCodeCompletion(this);
00613 connect( m_codeCompletion, SIGNAL(completionAborted()),
00614 this, SIGNAL(completionAborted()));
00615 connect( m_codeCompletion, SIGNAL(completionDone()),
00616 this, SIGNAL(completionDone()));
00617 connect( m_codeCompletion, SIGNAL(argHintHidden()),
00618 this, SIGNAL(argHintHidden()));
00619 connect( m_codeCompletion, SIGNAL(completionDone(KTextEditor::CompletionEntry)),
00620 this, SIGNAL(completionDone(KTextEditor::CompletionEntry)));
00621 connect( m_codeCompletion, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)),
00622 this, SIGNAL(filterInsertString(KTextEditor::CompletionEntry*,QString*)));
00623 }
00624
00625 void KateView::slotGotFocus()
00626 {
00627 m_editActions->accel()->setEnabled( true );
00628
00629 slotStatusMsg ();
00630 }
00631
00632 void KateView::slotLostFocus()
00633 {
00634 m_editActions->accel()->setEnabled( false );
00635 }
00636
00637 void KateView::setDynWrapIndicators(int mode)
00638 {
00639 config()->setDynWordWrapIndicators (mode);
00640 }
00641
00642 void KateView::slotStatusMsg ()
00643 {
00644 QString ovrstr;
00645 if (m_doc->isReadWrite())
00646 {
00647 if (m_doc->config()->configFlags() & KateDocument::cfOvr)
00648 ovrstr = i18n(" OVR ");
00649 else
00650 ovrstr = i18n(" INS ");
00651 }
00652 else
00653 ovrstr = i18n(" R/O ");
00654
00655 uint r = cursorLine() + 1;
00656 uint c = cursorColumn();
00657
00658 QString s1 = i18n(" Line: %1").arg(KGlobal::locale()->formatNumber(r, 0));
00659 QString s2 = i18n(" Col: %1").arg(KGlobal::locale()->formatNumber(c, 0));
00660
00661 QString modstr = m_doc->isModified() ? QString (" * ") : QString (" ");
00662 QString blockstr = m_doc->blockSelectionMode() ? i18n(" BLK ") : i18n(" NORM ");
00663
00664 emit viewStatusMsg (s1 + s2 + " " + ovrstr + blockstr + modstr);
00665 }
00666
00667 void KateView::slotSelectionTypeChanged()
00668 {
00669 m_toggleBlockSelection->setChecked( m_doc->blockSelectionMode() );
00670
00671 emit newStatus();
00672 }
00673
00674 bool KateView::isOverwriteMode() const
00675 {
00676 return m_doc->config()->configFlags() & KateDocument::cfOvr;
00677 }
00678
00679 void KateView::reloadFile()
00680 {
00681
00682 uint cl = cursorLine();
00683 uint cc = cursorColumn();
00684
00685
00686 m_doc->reloadFile();
00687
00688 if (m_doc->numLines() >= cl)
00689
00690 setCursorPositionInternal( cl, cc, tabWidth(), false );
00691 }
00692
00693 void KateView::slotUpdate()
00694 {
00695 emit newStatus();
00696
00697 slotNewUndo();
00698 }
00699
00700 void KateView::slotReadWriteChanged ()
00701 {
00702 if ( m_toggleWriteLock )
00703 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
00704
00705 m_cut->setEnabled (m_doc->isReadWrite());
00706 slotClipboardDataChanged();
00707
00708
00709 QStringList l;
00710
00711 l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
00712 << "tools_unindent" << "tools_cleanIndent" << "tools_comment"
00713 << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
00714 << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
00715 << "edit_undo" << "edit_redo";
00716
00717 KAction *a = 0;
00718 for (uint z = 0; z < l.size(); z++)
00719 if ((a = actionCollection()->action( l[z].ascii() )))
00720 a->setEnabled (m_doc->isReadWrite());
00721 }
00722
00723 void KateView::slotNewUndo()
00724 {
00725 if (m_doc->readOnly())
00726 return;
00727
00728 if ((m_doc->undoCount() > 0) != m_editUndo->isEnabled())
00729 m_editUndo->setEnabled(m_doc->undoCount() > 0);
00730
00731 if ((m_doc->redoCount() > 0) != m_editRedo->isEnabled())
00732 m_editRedo->setEnabled(m_doc->redoCount() > 0);
00733 }
00734
00735 void KateView::slotDropEventPass( QDropEvent * ev )
00736 {
00737 KURL::List lstDragURLs;
00738 bool ok = KURLDrag::decode( ev, lstDragURLs );
00739
00740 KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
00741 if ( ok && ext )
00742 emit ext->openURLRequest( lstDragURLs.first() );
00743 }
00744
00745 void KateView::contextMenuEvent( QContextMenuEvent *ev )
00746 {
00747 if ( !m_doc || !m_doc->browserExtension() )
00748 return;
00749
00750 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(),
00751 QString::fromLatin1( "text/plain" ) );
00752 ev->accept();
00753 }
00754
00755 bool KateView::setCursorPositionInternal( uint line, uint col, uint tabwidth, bool calledExternally )
00756 {
00757 TextLine::Ptr l = m_doc->kateTextLine( line );
00758
00759 if (!l)
00760 return false;
00761
00762 QString line_str = m_doc->textLine( line );
00763
00764 uint z;
00765 uint x = 0;
00766 for (z = 0; z < line_str.length() && z < col; z++) {
00767 if (line_str[z] == QChar('\t')) x += tabwidth - (x % tabwidth); else x++;
00768 }
00769
00770 m_viewInternal->updateCursor( KateTextCursor( line, x ), false, true, calledExternally );
00771
00772 return true;
00773 }
00774
00775 void KateView::toggleBlockSelectionMode()
00776 {
00777 m_doc->toggleBlockSelectionMode();
00778 m_toggleBlockSelection->setChecked (m_doc->blockSelectionMode());
00779 }
00780
00781 void KateView::setOverwriteMode( bool b )
00782 {
00783 if ( isOverwriteMode() && !b )
00784 m_doc->setConfigFlags( m_doc->config()->configFlags() ^ KateDocument::cfOvr );
00785 else
00786 m_doc->setConfigFlags( m_doc->config()->configFlags() | KateDocument::cfOvr );
00787
00788 m_toggleInsert->setChecked (isOverwriteMode ());
00789 }
00790
00791 void KateView::toggleInsert()
00792 {
00793 m_doc->setConfigFlags(m_doc->config()->configFlags() ^ KateDocument::cfOvr);
00794 m_toggleInsert->setChecked (isOverwriteMode ());
00795
00796 emit newStatus();
00797 }
00798
00799 bool KateView::canDiscard()
00800 {
00801 return m_doc->closeURL();
00802 }
00803
00804 void KateView::flush()
00805 {
00806 m_doc->closeURL();
00807 }
00808
00809 KateView::saveResult KateView::save()
00810 {
00811 if( !m_doc->url().isValid() || !doc()->isReadWrite() )
00812 return saveAs();
00813
00814 if( m_doc->save() )
00815 return SAVE_OK;
00816
00817 return SAVE_ERROR;
00818 }
00819
00820 KateView::saveResult KateView::saveAs()
00821 {
00822
00823 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(doc()->config()->encoding(),
00824 m_doc->url().url(),QString::null,this,i18n("Save File"));
00825
00826 kdDebug()<<"urllist is emtpy?"<<res.URLs.isEmpty()<<endl;
00827 kdDebug()<<"url is:"<<res.URLs.first()<<endl;
00828 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) )
00829 return SAVE_CANCEL;
00830
00831 m_doc->setEncoding( res.encoding );
00832
00833 if( m_doc->saveAs( res.URLs.first() ) )
00834 return SAVE_OK;
00835
00836 return SAVE_ERROR;
00837 }
00838
00839 bool KateView::checkOverwrite( KURL u )
00840 {
00841 if( !u.isLocalFile() )
00842 return true;
00843
00844 QFileInfo info( u.path() );
00845 if( !info.exists() )
00846 return true;
00847
00848 return KMessageBox::Cancel != KMessageBox::warningContinueCancel( this,
00849 i18n( "A file named \"%1\" already exists. "
00850 "Are you sure you want to overwrite it?" ).arg( info.fileName() ),
00851 i18n( "Overwrite File?" ),
00852 i18n( "&Overwrite" ) );
00853 }
00854
00855 void KateView::slotSaveCanceled( const QString& error )
00856 {
00857 if ( !error.isEmpty() )
00858 KMessageBox::error( this, error );
00859 }
00860
00861 void KateView::gotoLine()
00862 {
00863 GotoLineDialog *dlg;
00864
00865 dlg = new GotoLineDialog(this, m_viewInternal->getCursor().line() + 1, m_doc->numLines());
00866
00867 if (dlg->exec() == QDialog::Accepted)
00868 gotoLineNumber( dlg->getLine() - 1 );
00869
00870 delete dlg;
00871 }
00872
00873 void KateView::gotoLineNumber( int line )
00874 {
00875 setCursorPositionInternal ( line, 0, 1 );
00876 }
00877
00878 void KateView::joinLines()
00879 {
00880 int first = m_doc->selStartLine();
00881 int last = m_doc->selEndLine();
00882
00883 if ( first == last )
00884 {
00885 first = cursorLine();
00886 last = first + 1;
00887 }
00888 m_doc->joinLines( first, last );
00889 }
00890
00891 void KateView::readSessionConfig(KConfig *config)
00892 {
00893 setCursorPositionInternal (config->readNumEntry("CursorLine"), config->readNumEntry("CursorColumn"), 1);
00894 }
00895
00896 void KateView::writeSessionConfig(KConfig *config)
00897 {
00898 config->writeEntry("CursorLine",m_viewInternal->cursor.line());
00899 config->writeEntry("CursorColumn",m_viewInternal->cursor.col());
00900 }
00901
00902 int KateView::getEol()
00903 {
00904 return m_doc->config()->eol();
00905 }
00906
00907 void KateView::setEol(int eol)
00908 {
00909 if (!doc()->isReadWrite())
00910 return;
00911
00912 if (m_updatingDocumentConfig)
00913 return;
00914
00915 m_doc->config()->setEol (eol);
00916 }
00917
00918 void KateView::slotSetEncoding( const QString& descriptiveName )
00919 {
00920 setEncoding( KGlobal::charsets()->encodingForName( descriptiveName ) );
00921 reloadFile();
00922 }
00923
00924 void KateView::setIconBorder( bool enable )
00925 {
00926 config()->setIconBar (enable);
00927 }
00928
00929 void KateView::toggleIconBorder()
00930 {
00931 config()->setIconBar (!config()->iconBar());
00932 }
00933
00934 void KateView::setLineNumbersOn( bool enable )
00935 {
00936 config()->setLineNumbers (enable);
00937 }
00938
00939 void KateView::toggleLineNumbersOn()
00940 {
00941 config()->setLineNumbers (!config()->lineNumbers());
00942 }
00943
00944 void KateView::toggleDynWordWrap()
00945 {
00946 config()->setDynWordWrap( !config()->dynWordWrap() );
00947 }
00948
00949 void KateView::setDynWordWrap( bool b )
00950 {
00951 config()->setDynWordWrap( b );
00952 }
00953
00954 void KateView::toggleWWMarker()
00955 {
00956 m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
00957 }
00958
00959 void KateView::setFoldingMarkersOn( bool enable )
00960 {
00961 config()->setFoldingBar ( enable );
00962 }
00963
00964 void KateView::toggleFoldingMarkers()
00965 {
00966 config()->setFoldingBar ( !config()->foldingBar() );
00967 }
00968
00969 bool KateView::iconBorder() {
00970 return m_viewInternal->leftBorder->iconBorderOn();
00971 }
00972
00973 bool KateView::lineNumbersOn() {
00974 return m_viewInternal->leftBorder->lineNumbersOn();
00975 }
00976
00977 int KateView::dynWrapIndicators() {
00978 return m_viewInternal->leftBorder->dynWrapIndicators();
00979 }
00980
00981 bool KateView::foldingMarkersOn() {
00982 return m_viewInternal->leftBorder->foldingMarkersOn();
00983 }
00984
00985 void KateView::showCmdLine ( bool enabled )
00986 {
00987 if (enabled == m_cmdLineOn)
00988 return;
00989
00990 if (enabled)
00991 {
00992 if (!m_cmdLine)
00993 {
00994 m_cmdLine = new KateCmdLine (this);
00995 m_grid->addMultiCellWidget (m_cmdLine, 2, 2, 0, 2);
00996 }
00997
00998 m_cmdLine->show ();
00999 }
01000 else
01001 m_cmdLine->hide ();
01002
01003 m_cmdLineOn = enabled;
01004 }
01005
01006 void KateView::toggleCmdLine ()
01007 {
01008 m_config->setCmdLine (!m_config->cmdLine ());
01009 }
01010
01011 void KateView::toggleWriteLock()
01012 {
01013 m_doc->setReadWrite( ! m_doc->isReadWrite() );
01014 }
01015
01016 void KateView::enableTextHints(int timeout)
01017 {
01018 m_viewInternal->enableTextHints(timeout);
01019 }
01020
01021 void KateView::disableTextHints()
01022 {
01023 m_viewInternal->disableTextHints();
01024 }
01025
01026 void KateView::slotNeedTextHint(int line, int col, QString &text)
01027 {
01028 text=QString("test %1 %2").arg(line).arg(col);
01029 }
01030
01031 void KateView::find()
01032 {
01033 m_search->find();
01034 }
01035
01036 void KateView::replace()
01037 {
01038 m_search->replace();
01039 }
01040
01041 void KateView::findAgain( bool back )
01042 {
01043 m_search->findAgain( back );
01044 }
01045
01046 void KateView::selectionChanged ()
01047 {
01048 if (m_doc->hasSelection())
01049 {
01050 m_copy->setEnabled (true);
01051 m_deSelect->setEnabled (true);
01052 }
01053 else
01054 {
01055 m_copy->setEnabled (false);
01056 m_deSelect->setEnabled (false);
01057 }
01058
01059 if (m_doc->readOnly())
01060 return;
01061
01062 if (m_doc->hasSelection())
01063 m_cut->setEnabled (true);
01064 else
01065 m_cut->setEnabled (false);
01066 }
01067
01068 void KateView::switchToCmdLine ()
01069 {
01070 if (!m_cmdLineOn)
01071 m_config->setCmdLine (true);
01072
01073 m_cmdLine->setFocus ();
01074 }
01075
01076 void KateView::showArgHint( QStringList arg1, const QString& arg2, const QString& arg3 )
01077 {
01078 m_codeCompletion->showArgHint( arg1, arg2, arg3 );
01079 }
01080
01081 void KateView::showCompletionBox( QValueList<KTextEditor::CompletionEntry> arg1, int offset, bool cs )
01082 {
01083 emit aboutToShowCompletionBox();
01084 m_codeCompletion->showCompletionBox( arg1, offset, cs );
01085 }
01086
01087 KateRenderer *KateView::renderer ()
01088 {
01089 return m_renderer;
01090 }
01091
01092 void KateView::updateConfig ()
01093 {
01094 if (m_startingUp)
01095 return;
01096
01097 m_editActions->readShortcutSettings();
01098
01099
01100 if (m_hasWrap != config()->dynWordWrap()) {
01101 m_viewInternal->prepareForDynWrapChange();
01102
01103 m_hasWrap = config()->dynWordWrap();
01104
01105 m_viewInternal->dynWrapChanged();
01106
01107 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
01108 m_toggleDynWrap->setChecked( config()->dynWordWrap() );
01109 }
01110
01111 m_viewInternal->leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
01112 m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
01113
01114
01115 m_viewInternal->leftBorder->setLineNumbersOn( config()->lineNumbers() );
01116 m_toggleLineNumbers->setChecked( config()->lineNumbers() );
01117
01118
01119 m_viewInternal->leftBorder->setIconBorderOn( config()->iconBar() );
01120 m_toggleIconBar->setChecked( config()->iconBar() );
01121
01122
01123 showCmdLine (config()->cmdLine());
01124 m_toggleCmdLine->setChecked( config()->cmdLine() );
01125
01126
01127 m_toggleBlockSelection->setChecked( m_doc->blockSelectionMode() );
01128 m_toggleInsert->setChecked( isOverwriteMode() );
01129
01130 updateFoldingConfig ();
01131
01132
01133 m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
01134
01135 m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
01136 }
01137
01138 void KateView::updateDocumentConfig()
01139 {
01140 if (m_startingUp)
01141 return;
01142
01143 m_updatingDocumentConfig = true;
01144
01145 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
01146
01147 m_updatingDocumentConfig = false;
01148
01149 m_viewInternal->updateView (true);
01150
01151 m_renderer->setTabWidth (m_doc->config()->tabWidth());
01152 }
01153
01154 void KateView::updateRendererConfig()
01155 {
01156 if (m_startingUp)
01157 return;
01158
01159 m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
01160
01161
01162 m_viewInternal->updateView (true);
01163 m_viewInternal->repaint ();
01164
01165
01166 m_viewInternal->leftBorder->updateFont();
01167 m_viewInternal->leftBorder->repaint ();
01168 }
01169
01170 void KateView::updateFoldingConfig ()
01171 {
01172
01173 bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
01174 m_viewInternal->leftBorder->setFoldingMarkersOn(doit);
01175 m_toggleFoldingMarkers->setChecked( doit );
01176 m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
01177
01178 QStringList l;
01179
01180 l << "folding_toplevel" << "folding_expandtoplevel"
01181 << "folding_collapselocal" << "folding_expandlocal";
01182
01183 KAction *a = 0;
01184 for (uint z = 0; z < l.size(); z++)
01185 if ((a = actionCollection()->action( l[z].ascii() )))
01186 a->setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
01187 }
01188
01189
01190 void KateView::editStart ()
01191 {
01192 m_viewInternal->editStart ();
01193 }
01194
01195 void KateView::editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom)
01196 {
01197 m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
01198 }
01199
01200 void KateView::editSetCursor (const KateTextCursor &cursor)
01201 {
01202 m_viewInternal->editSetCursor (cursor);
01203 }
01204
01205
01206
01207 bool KateView::tagLine (const KateTextCursor& virtualCursor)
01208 {
01209 return m_viewInternal->tagLine (virtualCursor);
01210 }
01211
01212 bool KateView::tagLines (int start, int end, bool realLines)
01213 {
01214 return m_viewInternal->tagLines (start, end, realLines);
01215 }
01216
01217 bool KateView::tagLines (KateTextCursor start, KateTextCursor end, bool realCursors)
01218 {
01219 return m_viewInternal->tagLines (start, end, realCursors);
01220 }
01221
01222 void KateView::tagAll ()
01223 {
01224 m_viewInternal->tagAll ();
01225 }
01226
01227 void KateView::clear ()
01228 {
01229 m_viewInternal->clear ();
01230 }
01231
01232 void KateView::repaintText (bool paintOnlyDirty)
01233 {
01234 m_viewInternal->paintText(0,0,m_viewInternal->width(),m_viewInternal->height(), paintOnlyDirty);
01235 }
01236
01237 void KateView::updateView (bool changed)
01238 {
01239 m_viewInternal->updateView (changed);
01240 m_viewInternal->leftBorder->update();
01241 }
01242
01243
01244
01245 void KateView::slotClipboardDataChanged()
01246 {
01247 QMimeSource *data = QApplication::clipboard()->data(QClipboard::Clipboard);
01248 m_paste->setEnabled(m_doc->isReadWrite() && data->provides( "text/plain" ) );
01249 }
01250
01251 void KateView::slotHlChanged()
01252 {
01253 Highlight *hl = m_doc->highlight();
01254 bool ok ( ! ( hl->getCommentStart().isEmpty() && hl->getCommentSingleLineStart().isEmpty() ) );
01255
01256 if (actionCollection()->action("tools_comment"))
01257 actionCollection()->action("tools_comment")->setEnabled( ok );
01258
01259 if (actionCollection()->action("tools_uncomment"))
01260 actionCollection()->action("tools_uncomment")->setEnabled( ok );
01261
01262
01263 updateFoldingConfig ();
01264 }
01265