00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kateview.h"
00026 #include "kateview.moc"
00027
00028 #include "kateviewinternal.h"
00029 #include "kateviewhelpers.h"
00030 #include "katerenderer.h"
00031 #include "katedocument.h"
00032 #include "katedocumenthelpers.h"
00033 #include "kateglobal.h"
00034 #include "katehighlight.h"
00035 #include "katehighlightmenu.h"
00036 #include "katedialogs.h"
00037 #include "katetextline.h"
00038 #include "katecodefolding.h"
00039 #include "kateschema.h"
00040 #include "katebookmarks.h"
00041 #include "kateconfig.h"
00042 #include "katemodemenu.h"
00043 #include "kateautoindent.h"
00044 #include "katespell.h"
00045 #include "katecompletionwidget.h"
00046 #include "katesmartmanager.h"
00047 #include "katesmartrange.h"
00048 #include "katesearchbar.h"
00049 #include "katevimodebar.h"
00050 #include "katepartpluginmanager.h"
00051 #include "katewordcompletion.h"
00052 #include "katelayoutcache.h"
00053
00054 #include <ktexteditor/cursorfeedback.h>
00055
00056 #include <kparts/event.h>
00057
00058 #include <kio/netaccess.h>
00059
00060 #include <kconfig.h>
00061 #include <kdebug.h>
00062 #include <kapplication.h>
00063 #include <kcursor.h>
00064 #include <kicon.h>
00065 #include <klocale.h>
00066 #include <kglobal.h>
00067 #include <kcharsets.h>
00068 #include <kmessagebox.h>
00069 #include <kaction.h>
00070 #include <kstandardaction.h>
00071 #include <kxmlguifactory.h>
00072 #include <kxmlguiclient.h>
00073 #include <klibloader.h>
00074 #include <kencodingfiledialog.h>
00075 #include <ktemporaryfile.h>
00076 #include <ksavefile.h>
00077 #include <kstandardshortcut.h>
00078 #include <kmenu.h>
00079 #include <ktoggleaction.h>
00080 #include <kselectaction.h>
00081 #include <kactioncollection.h>
00082 #include <kdeversion.h>
00083
00084 #include <QtGui/QFont>
00085 #include <QtCore/QFileInfo>
00086 #include <QtGui/QStyle>
00087 #include <QtGui/QKeyEvent>
00088 #include <QtGui/QLayout>
00089 #include <QtGui/QClipboard>
00090 #include <QtGui/QTextDocument>
00091 #include <QtCore/QTextStream>
00092 #include <QtCore/QMimeData>
00093 #include <QtCore/QTextCodec>
00094 #include <QtCore/QMutexLocker>
00095
00096
00097
00098 static void blockFix(KTextEditor::Range& range)
00099 {
00100 if (range.start().column() > range.end().column())
00101 {
00102 int tmp = range.start().column();
00103 range.start().setColumn(range.end().column());
00104 range.end().setColumn(tmp);
00105 }
00106 }
00107
00108 KateView::KateView( KateDocument *doc, QWidget *parent )
00109 : KTextEditor::View( parent )
00110 , m_completionWidget(0)
00111 , m_annotationModel(0)
00112 , m_doc( doc )
00113 , m_spell( new KateSpell( this ) )
00114 , m_bookmarks( new KateBookmarks( this ) )
00115 , m_hasWrap( false )
00116 , m_startingUp (true)
00117 , m_updatingDocumentConfig (false)
00118 , m_selection(m_doc->smartManager()->newSmartRange(KTextEditor::Range::invalid(), 0L, KTextEditor::SmartRange::ExpandRight))
00119 , blockSelect (false)
00120 , m_bottomViewBar (0)
00121 , m_topViewBar (0)
00122 , m_cmdLine (0)
00123 , m_searchBar (0)
00124 , m_viModeBar (0)
00125 , m_gotoBar (0)
00126 {
00127
00128 setComponentData ( KateGlobal::self()->componentData () );
00129
00130 KateGlobal::self()->registerView( this );
00131
00132 KTextEditor::ViewBarContainer *viewBarContainer=qobject_cast<KTextEditor::ViewBarContainer*>( KateGlobal::self()->container() );
00133 QWidget *bottomBarParent=viewBarContainer?viewBarContainer->getViewBarParent(this,KTextEditor::ViewBarContainer::BottomBar):0;
00134 QWidget *topBarParent=viewBarContainer?viewBarContainer->getViewBarParent(this,KTextEditor::ViewBarContainer::TopBar):0;
00135
00136 m_bottomBarExternal=bottomBarParent;
00137 m_topBarExternal=topBarParent;
00138
00139 m_bottomViewBar=new KateViewBar (m_bottomBarExternal,KTextEditor::ViewBarContainer::BottomBar,bottomBarParent?bottomBarParent:this,this);
00140 m_topViewBar=new KateViewBar (m_topBarExternal,KTextEditor::ViewBarContainer::TopBar,topBarParent?topBarParent:this,this);
00141
00142
00143
00144 m_config = new KateViewConfig (this);
00145
00146 m_renderer = new KateRenderer(doc, this);
00147
00148 m_viewInternal = new KateViewInternal( this, doc );
00149
00150
00151
00152
00153
00154 setLayoutDirection ( Qt::LeftToRight );
00155
00156
00157 m_vBox = new QVBoxLayout (this);
00158 m_vBox->setMargin (0);
00159 m_vBox->setSpacing (0);
00160
00161 QHBoxLayout *hbox = new QHBoxLayout ();
00162 m_vBox->addLayout (hbox, 100);
00163 hbox->setMargin (0);
00164 hbox->setSpacing (0);
00165
00166
00167 if (topBarParent)
00168 viewBarContainer->addViewBarToLayout(this,m_topViewBar,KTextEditor::ViewBarContainer::TopBar);
00169 else
00170 m_vBox->addWidget(m_topViewBar);
00171
00172 QStyleOption option;
00173 option.initFrom(this);
00174
00175 if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &option, this)) {
00176 QHBoxLayout *extrahbox = new QHBoxLayout ();
00177 QFrame * frame = new QFrame(this);
00178 extrahbox->setMargin (0);
00179 extrahbox->setSpacing (0);
00180 extrahbox->addWidget (m_viewInternal->m_leftBorder);
00181 extrahbox->addWidget (m_viewInternal);
00182 frame->setLayout (extrahbox);
00183 hbox->addWidget (frame);
00184 hbox->addSpacing (style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this) * 2);
00185 frame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
00186 }
00187 else {
00188 hbox->addWidget (m_viewInternal->m_leftBorder);
00189 hbox->addWidget (m_viewInternal);
00190 }
00191 hbox->addWidget (m_viewInternal->m_lineScroll);
00192
00193 if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &option, this)) {
00194 m_vBox->addSpacing (style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this) * 2);
00195 }
00196
00197 hbox = new QHBoxLayout ();
00198 m_vBox->addLayout (hbox);
00199 hbox->setMargin (0);
00200 hbox->setSpacing (0);
00201
00202 hbox->addWidget (m_viewInternal->m_columnScroll);
00203 hbox->addWidget (m_viewInternal->m_dummy);
00204
00205
00206 if (bottomBarParent)
00207 viewBarContainer->addViewBarToLayout(this,m_bottomViewBar,KTextEditor::ViewBarContainer::BottomBar);
00208 else
00209 m_vBox->addWidget(m_bottomViewBar);
00210
00211
00212 m_viewInternal->updateView ();
00213
00214 doc->addView( this );
00215
00216 setFocusProxy( m_viewInternal );
00217 setFocusPolicy( Qt::StrongFocus );
00218
00219
00220 QString uifile = "katepartui.rc";
00221
00222
00223 if (doc->simpleMode ())
00224 uifile = "katepartsimpleui.rc";
00225
00226 setXMLFile( uifile );
00227
00228 setupConnections();
00229 setupActions();
00230
00231
00232 new KateWordCompletionView (this, actionCollection ());
00233
00234
00235 KatePartPluginManager::self()->addView(this);
00236
00237
00238 slotUpdateUndo();
00239
00240 m_startingUp = false;
00241 updateConfig ();
00242
00243 slotHlChanged();
00244 KCursor::setAutoHideCursor( m_viewInternal, true );
00245
00246
00247
00248
00249
00250
00251
00252 if ( viInputMode() && !config()->viInputModeHideStatusBar() ) {
00253 deactivateEditActions();
00254 showViModeBar();
00255 }
00256 }
00257
00258 KateView::~KateView()
00259 {
00260 KTextEditor::ViewBarContainer *viewBarContainer=qobject_cast<KTextEditor::ViewBarContainer*>( KateGlobal::self()->container() );
00261 if (viewBarContainer) {
00262 viewBarContainer->deleteViewBarForView(this,KTextEditor::ViewBarContainer::BottomBar);
00263 m_bottomViewBar=0;
00264 viewBarContainer->deleteViewBarForView(this,KTextEditor::ViewBarContainer::TopBar);
00265 m_topViewBar=0;
00266 }
00267
00268 if (!m_doc->singleViewMode())
00269 KatePartPluginManager::self()->removeView(this);
00270
00271 m_doc->removeView( this );
00272
00273 foreach (KTextEditor::SmartRange* range, m_externalHighlights)
00274 removeExternalHighlight(range);
00275
00276 foreach (KTextEditor::SmartRange* range, m_internalHighlights)
00277 removeInternalHighlight(range);
00278
00279 delete m_viewInternal;
00280
00281
00282 delete m_selection;
00283 m_selection = 0L;
00284
00285 delete m_renderer;
00286
00287 delete m_config;
00288
00289 KateGlobal::self()->deregisterView (this);
00290 }
00291
00292 void KateView::setupConnections()
00293 {
00294 connect( m_doc, SIGNAL(undoChanged()),
00295 this, SLOT(slotUpdateUndo()) );
00296 connect( m_doc, SIGNAL(highlightingModeChanged(KTextEditor::Document *)),
00297 this, SLOT(slotHlChanged()) );
00298 connect( m_doc, SIGNAL(canceled(const QString&)),
00299 this, SLOT(slotSaveCanceled(const QString&)) );
00300 connect( m_viewInternal, SIGNAL(dropEventPass(QDropEvent*)),
00301 this, SIGNAL(dropEventPass(QDropEvent*)) );
00302
00303 connect( m_doc, SIGNAL(annotationModelChanged( KTextEditor::AnnotationModel*, KTextEditor::AnnotationModel* )),
00304 m_viewInternal->m_leftBorder, SLOT(annotationModelChanged( KTextEditor::AnnotationModel*, KTextEditor::AnnotationModel* )) );
00305
00306 if ( m_doc->browserView() )
00307 {
00308 connect( this, SIGNAL(dropEventPass(QDropEvent*)),
00309 this, SLOT(slotDropEventPass(QDropEvent*)) );
00310 }
00311 }
00312
00313 void KateView::setupActions()
00314 {
00315 KActionCollection *ac = actionCollection ();
00316 KAction *a;
00317
00318 m_toggleWriteLock = 0;
00319
00320 m_cut = a = ac->addAction(KStandardAction::Cut, this, SLOT(cut()));
00321 a->setWhatsThis(i18n("Cut the selected text and move it to the clipboard"));
00322
00323 m_paste = a = ac->addAction(KStandardAction::PasteText, this, SLOT(paste()));
00324 a->setWhatsThis(i18n("Paste previously copied or cut clipboard contents"));
00325
00326 m_copy = a = ac->addAction(KStandardAction::Copy, this, SLOT(copy()));
00327 a->setWhatsThis(i18n( "Use this command to copy the currently selected text to the system clipboard."));
00328
00329 m_copyHTML = a = ac->addAction("edit_copy_html");
00330 m_copyHTML->setIcon(KIcon("edit-copy"));
00331 m_copyHTML->setText(i18n("Copy as &HTML"));
00332 connect(a, SIGNAL(triggered(bool)), SLOT(copyHTML()));
00333 a->setWhatsThis(i18n( "Use this command to copy the currently selected text as HTML to the system clipboard."));
00334
00335 if (!m_doc->readOnly())
00336 {
00337 a = ac->addAction(KStandardAction::Save, m_doc, SLOT(documentSave()));
00338 a->setWhatsThis(i18n("Save the current document"));
00339
00340 a = m_editUndo = ac->addAction(KStandardAction::Undo, m_doc, SLOT(undo()));
00341 a->setWhatsThis(i18n("Revert the most recent editing actions"));
00342
00343 a = m_editRedo = ac->addAction(KStandardAction::Redo, m_doc, SLOT(redo()));
00344 a->setWhatsThis(i18n("Revert the most recent undo operation"));
00345
00346 a = ac->addAction("tools_apply_wordwrap");
00347 a->setText(i18n("&Word Wrap Document"));
00348 a->setWhatsThis(i18n("Use this command to wrap all lines of the current document which are longer than the width of the"
00349 " current view, to fit into this view.<br /><br /> This is a static word wrap, meaning it is not updated"
00350 " when the view is resized."));
00351 connect(a, SIGNAL(triggered(bool)), SLOT(applyWordWrap()));
00352
00353
00354 a = ac->addAction("tools_indent");
00355 a->setIcon(KIcon("format-indent-more"));
00356 a->setText(i18n("&Indent"));
00357 a->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_I));
00358 a->setWhatsThis(i18n("Use this to indent a selected block of text.<br /><br />"
00359 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00360 connect(a, SIGNAL(triggered(bool)), SLOT(indent()));
00361
00362 a = ac->addAction("tools_unindent");
00363 a->setIcon(KIcon("format-indent-less"));
00364 a->setText(i18n("&Unindent"));
00365 a->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_I));
00366 a->setWhatsThis(i18n("Use this to unindent a selected block of text."));
00367 connect(a, SIGNAL(triggered(bool)), SLOT(unIndent()));
00368
00369 a = ac->addAction("tools_cleanIndent");
00370 a->setText(i18n("&Clean Indentation"));
00371 a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces).<br /><br />"
00372 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
00373 connect(a, SIGNAL(triggered(bool)), SLOT(cleanIndent()));
00374
00375
00376 a = ac->addAction("tools_align");
00377 a->setText(i18n("&Align"));
00378 a->setWhatsThis(i18n("Use this to align the current line or block of text to its proper indent level."));
00379 connect(a, SIGNAL(triggered(bool)), SLOT(align()));
00380
00381 a = ac->addAction("tools_comment");
00382 a->setText(i18n("C&omment"));
00383 a->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_D));
00384 a->setWhatsThis(i18n("This command comments out the current line or a selected block of text.<br /><br />"
00385 "The characters for single/multiple line comments are defined within the language's highlighting."));
00386 connect(a, SIGNAL(triggered(bool)), SLOT(comment()));
00387
00388 a = ac->addAction("tools_uncomment");
00389 a->setText(i18n("Unco&mment"));
00390 a->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_D));
00391 a->setWhatsThis(i18n("This command removes comments from the current line or a selected block of text.<br /><br />"
00392 "The characters for single/multiple line comments are defined within the language's highlighting."));
00393 connect(a, SIGNAL(triggered(bool)), SLOT(uncomment()));
00394
00395 a = m_toggleWriteLock = new KToggleAction(i18n("&Read Only Mode"), this);
00396 a->setWhatsThis( i18n("Lock/unlock the document for writing") );
00397 a->setChecked( !m_doc->isReadWrite() );
00398 connect(a, SIGNAL(triggered(bool)), SLOT( toggleWriteLock() ));
00399 ac->addAction("tools_toggle_write_lock", a);
00400
00401 a = ac->addAction("tools_uppercase");
00402 a->setText(i18n("Uppercase"));
00403 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
00404 a->setWhatsThis( i18n("Convert the selection to uppercase, or the character to the "
00405 "right of the cursor if no text is selected.") );
00406 connect(a, SIGNAL(triggered(bool)), SLOT(uppercase()));
00407
00408 a = ac->addAction( "tools_lowercase" );
00409 a->setText( i18n("Lowercase") );
00410 a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_U));
00411 a->setWhatsThis( i18n("Convert the selection to lowercase, or the character to the "
00412 "right of the cursor if no text is selected.") );
00413 connect(a, SIGNAL(triggered(bool)), SLOT(lowercase()));
00414
00415 a = ac->addAction( "tools_capitalize" );
00416 a->setText( i18n("Capitalize") );
00417 a->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_U));
00418 a->setWhatsThis( i18n("Capitalize the selection, or the word under the "
00419 "cursor if no text is selected.") );
00420 connect(a, SIGNAL(triggered(bool)), SLOT(capitalize()));
00421
00422 a = ac->addAction( "tools_join_lines" );
00423 a->setText( i18n("Join Lines") );
00424 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
00425 connect(a, SIGNAL(triggered(bool)), SLOT( joinLines() ));
00426
00427 a = ac->addAction( "tools_invoke_code_completion" );
00428 a->setText( i18n("Invoke Code Completion") );
00429 a->setWhatsThis(i18n("Manually invoke command completion, usually by using a shortcut bound to this action."));
00430 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Space));
00431 connect(a, SIGNAL(triggered(bool)), SLOT(userInvokedCompletion()));
00432 }
00433 else
00434 {
00435 m_cut->setEnabled (false);
00436 m_paste->setEnabled (false);
00437 m_editUndo = 0;
00438 m_editRedo = 0;
00439 }
00440
00441 a = ac->addAction( KStandardAction::Print, m_doc, SLOT(print()) );
00442 a->setWhatsThis(i18n("Print the current document."));
00443
00444 a = ac->addAction( "file_reload" );
00445 a->setIcon(KIcon("view-refresh"));
00446 a->setText(i18n("Reloa&d"));
00447 a->setShortcuts(KStandardShortcut::reload());
00448 a->setWhatsThis(i18n("Reload the current document from disk."));
00449 connect(a, SIGNAL(triggered(bool)), SLOT(reloadFile()));
00450
00451 a = ac->addAction( KStandardAction::SaveAs, m_doc, SLOT(documentSaveAs()) );
00452 a->setWhatsThis(i18n("Save the current document to disk, with a name of your choice."));
00453
00454 a = ac->addAction( KStandardAction::GotoLine, this, SLOT(gotoLine()) );
00455 a->setWhatsThis(i18n("This command opens a dialog and lets you choose a line that you want the cursor to move to."));
00456
00457 a = ac->addAction("set_confdlg");
00458 a->setText(i18n("&Configure Editor..."));
00459 a->setWhatsThis(i18n("Configure various aspects of this editor."));
00460 connect(a, SIGNAL(triggered(bool)), SLOT(slotConfigDialog()));
00461
00462 KateModeMenu *ftm = new KateModeMenu (i18n("&Mode"), this);
00463 ac->addAction("tools_mode", ftm);
00464 ftm->setWhatsThis(i18n("Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
00465 ftm->updateMenu (m_doc);
00466
00467 KateHighlightingMenu *menu = new KateHighlightingMenu (i18n("&Highlighting"), this);
00468 ac->addAction("tools_highlighting", menu);
00469 menu->setWhatsThis(i18n("Here you can choose how the current document should be highlighted."));
00470 menu->updateMenu (m_doc);
00471
00472 KateViewSchemaAction *schemaMenu = new KateViewSchemaAction (i18n("&Schema"), this);
00473 ac->addAction("view_schemas", schemaMenu);
00474 schemaMenu->updateMenu (this);
00475
00476
00477 KateViewIndentationAction *indentMenu = new KateViewIndentationAction(m_doc, i18n("&Indentation"), this);
00478 ac->addAction("tools_indentation", indentMenu);
00479
00480
00481 a = ac->addAction("file_export_html");
00482 a->setText(i18n("E&xport as HTML..."));
00483 a->setWhatsThis(i18n("This command allows you to export the current document"
00484 " with all highlighting information into a HTML document."));
00485 connect(a, SIGNAL(triggered(bool)), SLOT(exportAsHTML()));
00486
00487 m_selectAll = a= ac->addAction( KStandardAction::SelectAll, this, SLOT(selectAll()) );
00488 a->setWhatsThis(i18n("Select the entire text of the current document."));
00489
00490 m_deSelect = a= ac->addAction( KStandardAction::Deselect, this, SLOT(clearSelection()) );
00491 a->setWhatsThis(i18n("If you have selected something within the current document, this will no longer be selected."));
00492
00493 a = ac->addAction("view_inc_font_sizes");
00494 a->setIcon(KIcon("zoom-in"));
00495 a->setText(i18n("Enlarge Font"));
00496 a->setWhatsThis(i18n("This increases the display font size."));
00497 connect(a, SIGNAL(triggered(bool)), m_viewInternal, SLOT(slotIncFontSizes()));
00498
00499 a = ac->addAction("view_dec_font_sizes");
00500 a->setIcon(KIcon("zoom-out"));
00501 a->setText(i18n("Shrink Font"));
00502 a->setWhatsThis(i18n("This decreases the display font size."));
00503 connect(a, SIGNAL(triggered(bool)), m_viewInternal, SLOT(slotDecFontSizes()));
00504
00505 a = m_toggleBlockSelection = new KToggleAction(i18n("Bl&ock Selection Mode"), this);
00506 ac->addAction("set_verticalSelect", a);
00507 a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
00508 a->setWhatsThis(i18n("This command allows switching between the normal (line based) selection mode and the block selection mode."));
00509 connect(a, SIGNAL(triggered(bool)), SLOT(toggleBlockSelectionMode()));
00510
00511 a = m_toggleInsert = new KToggleAction(i18n("Overwr&ite Mode"), this);
00512 ac->addAction("set_insert", a);
00513 a->setShortcut(QKeySequence(Qt::Key_Insert));
00514 a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text."));
00515 connect(a, SIGNAL(triggered(bool)), SLOT(toggleInsert()));
00516
00517 KToggleAction *toggleAction;
00518 a = m_toggleDynWrap = toggleAction = new KToggleAction(i18n("&Dynamic Word Wrap"), this);
00519 ac->addAction("view_dynamic_word_wrap", a);
00520 a->setShortcut(QKeySequence(Qt::Key_F10));
00521 a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen."));
00522 connect(a, SIGNAL(triggered(bool)), SLOT(toggleDynWordWrap()));
00523
00524 a = m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), this);
00525 ac->addAction("dynamic_word_wrap_indicators", a);
00526 a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed"));
00527
00528 connect(m_setDynWrapIndicators, SIGNAL(triggered(int)), this, SLOT(setDynWrapIndicators(int)));
00529 QStringList list2;
00530 list2.append(i18n("&Off"));
00531 list2.append(i18n("Follow &Line Numbers"));
00532 list2.append(i18n("&Always On"));
00533 m_setDynWrapIndicators->setItems(list2);
00534 m_setDynWrapIndicators->setEnabled(m_toggleDynWrap->isChecked());
00535
00536 a = toggleAction = m_toggleFoldingMarkers = new KToggleAction(i18n("Show Folding &Markers"), this);
00537 ac->addAction("view_folding_markers", a);
00538 a->setShortcut(QKeySequence(Qt::Key_F9));
00539 a->setWhatsThis(i18n("You can choose if the codefolding marks should be shown, if codefolding is possible."));
00540 connect(a, SIGNAL(triggered(bool)), SLOT(toggleFoldingMarkers()));
00541
00542 a = m_toggleIconBar = toggleAction = new KToggleAction(i18n("Show &Icon Border"), this);
00543 ac->addAction("view_border", a);
00544 a->setShortcut(QKeySequence(Qt::Key_F6));
00545 a->setWhatsThis(i18n("Show/hide the icon border.<br /><br />The icon border shows bookmark symbols, for instance."));
00546 connect(a, SIGNAL(triggered(bool)), SLOT(toggleIconBorder()));
00547
00548 a = toggleAction = m_toggleLineNumbers = new KToggleAction(i18n("Show &Line Numbers"), this);
00549 ac->addAction("view_line_numbers", a);
00550 a->setShortcut(QKeySequence(Qt::Key_F11));
00551 a->setWhatsThis(i18n("Show/hide the line numbers on the left hand side of the view."));
00552 connect(a, SIGNAL(triggered(bool)), SLOT(toggleLineNumbersOn()));
00553
00554 a = m_toggleScrollBarMarks = toggleAction = new KToggleAction(i18n("Show Scroll&bar Marks"), this);
00555 ac->addAction("view_scrollbar_marks", a);
00556 a->setWhatsThis(i18n("Show/hide the marks on the vertical scrollbar.<br /><br />The marks show bookmarks, for instance."));
00557 connect(a, SIGNAL(triggered(bool)), SLOT(toggleScrollBarMarks()));
00558
00559 a = toggleAction = m_toggleWWMarker = new KToggleAction(i18n("Show Static &Word Wrap Marker"), this);
00560 ac->addAction("view_word_wrap_marker", a);
00561 a->setWhatsThis( i18n(
00562 "Show/hide the Word Wrap Marker, a vertical line drawn at the word "
00563 "wrap column as defined in the editing properties" ));
00564 connect(a, SIGNAL(triggered(bool)), SLOT( toggleWWMarker() ));
00565
00566 a = m_switchCmdLine = ac->addAction("switch_to_cmd_line");
00567 a->setText(i18n("Switch to Command Line"));
00568 a->setShortcut(QKeySequence(Qt::Key_F7));
00569 a->setWhatsThis(i18n("Show/hide the command line on the bottom of the view."));
00570 connect(a, SIGNAL(triggered(bool)), SLOT(switchToCmdLine()));
00571
00572 a = m_viInputModeAction = new KToggleAction(i18n("&VI Input Mode"), this);
00573 ac->addAction("view_vi_input_mode", a);
00574 a->setShortcut(QKeySequence(Qt::CTRL + Qt::META + Qt::Key_V));
00575 a->setWhatsThis( i18n("Activate/deactivate VI input mode" ));
00576 connect(a, SIGNAL(triggered(bool)), SLOT( toggleViInputMode() ));
00577
00578 a = m_setEndOfLine = new KSelectAction(i18n("&End of Line"), this);
00579 ac->addAction("set_eol", a);
00580 a->setWhatsThis(i18n("Choose which line endings should be used, when you save the document"));
00581 QStringList list;
00582 list.append("&UNIX");
00583 list.append("&Windows/DOS");
00584 list.append("&Macintosh");
00585 m_setEndOfLine->setItems(list);
00586 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
00587 connect(m_setEndOfLine, SIGNAL(triggered(int)), this, SLOT(setEol(int)));
00588
00589
00590 KateViewEncodingAction *encodingAction = new KateViewEncodingAction(m_doc, this, i18n("E&ncoding"), this);
00591 ac->addAction("set_encoding", encodingAction);
00592 encodingAction->setCurrentCodec(m_doc->config()->encoding());
00593
00594 a = ac->addAction( KStandardAction::Find, this, SLOT(find()) );
00595 a->setWhatsThis(i18n("Look up the first occurrence of a piece of text or regular expression."));
00596 addAction(a);
00597
00598 a = ac->addAction("edit_find_selected");
00599 a->setText(i18n("Find Selected"));
00600 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H));
00601 a->setWhatsThis(i18n("Finds next occurrence of selected text."));
00602 connect(a, SIGNAL(triggered(bool)), SLOT(findSelectedForwards()));
00603
00604 a = ac->addAction("edit_find_selected_backwards");
00605 a->setText(i18n("Find Selected Backwards"));
00606 a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_H));
00607 a->setWhatsThis(i18n("Finds previous occurrence of selected text."));
00608 connect(a, SIGNAL(triggered(bool)), SLOT(findSelectedBackwards()));
00609
00610 a = ac->addAction( KStandardAction::FindNext, this, SLOT(findNext()) );
00611 a->setWhatsThis(i18n("Look up the next occurrence of the search phrase."));
00612 addAction(a);
00613
00614 a = ac->addAction( KStandardAction::FindPrev, "edit_find_prev", this, SLOT(findPrevious()) );
00615 a->setWhatsThis(i18n("Look up the previous occurrence of the search phrase."));
00616 addAction(a);
00617
00618 a = ac->addAction( KStandardAction::Replace, this, SLOT(replace()) );
00619 a->setWhatsThis(i18n("Look up a piece of text or regular expression and replace the result with some given text."));
00620
00621 m_spell->createActions( ac );
00622
00623 if (!m_doc->simpleMode ())
00624 m_bookmarks->createActions( ac );
00625
00626 slotSelectionChanged ();
00627
00628
00629
00630 setupEditActions();
00631 setupCodeFolding();
00632
00633 ac->addAssociatedWidget(m_viewInternal);
00634
00635 foreach (QAction* action, ac->actions())
00636 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
00637
00638 connect (this, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(slotSelectionChanged()));
00639 }
00640
00641 void KateView::slotConfigDialog ()
00642 {
00643 KateGlobal::self ()->configDialog (this);
00644 }
00645
00646 void KateView::setupEditActions()
00647 {
00648
00649
00650
00651 KActionCollection* ac = actionCollection();
00652
00653 KAction* a = ac->addAction("word_left");
00654 a->setText(i18n("Move Word Left"));
00655 a->setShortcuts(KStandardShortcut::backwardWord());
00656 connect(a, SIGNAL(triggered(bool)), SLOT(wordLeft()));
00657 m_editActions << a;
00658
00659 a = ac->addAction("select_char_left");
00660 a->setText(i18n("Select Character Left"));
00661 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Left));
00662 connect(a, SIGNAL(triggered(bool)), SLOT(shiftCursorLeft()));
00663 m_editActions << a;
00664
00665 a = ac->addAction("select_word_left");
00666 a->setText(i18n("Select Word Left"));
00667 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_Left));
00668 connect(a, SIGNAL(triggered(bool)), SLOT(shiftWordLeft()));
00669 m_editActions << a;
00670
00671
00672 a = ac->addAction("word_right");
00673 a->setText(i18n("Move Word Right"));
00674 a->setShortcuts(KStandardShortcut::forwardWord());
00675 connect(a, SIGNAL(triggered(bool)), SLOT(wordRight()));
00676 m_editActions << a;
00677
00678 a = ac->addAction("select_char_right");
00679 a->setText(i18n("Select Character Right"));
00680 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Right));
00681 connect(a, SIGNAL(triggered(bool)), SLOT(shiftCursorRight()));
00682 m_editActions << a;
00683
00684 a = ac->addAction("select_word_right");
00685 a->setText(i18n("Select Word Right"));
00686 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_Right));
00687 connect(a, SIGNAL(triggered(bool)), SLOT(shiftWordRight()));
00688 m_editActions << a;
00689
00690
00691 a = ac->addAction("beginning_of_line");
00692 a->setText(i18n("Move to Beginning of Line"));
00693 a->setShortcuts(KStandardShortcut::beginningOfLine());
00694 connect(a, SIGNAL(triggered(bool)), SLOT(home()));
00695 m_editActions << a;
00696
00697 a = ac->addAction("beginning_of_document");
00698 a->setText(i18n("Move to Beginning of Document"));
00699 a->setShortcuts(KStandardShortcut::begin());
00700 connect(a, SIGNAL(triggered(bool)), SLOT(top()));
00701 m_editActions << a;
00702
00703 a = ac->addAction("select_beginning_of_line");
00704 a->setText(i18n("Select to Beginning of Line"));
00705 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Home));
00706 connect(a, SIGNAL(triggered(bool)), SLOT(shiftHome()));
00707 m_editActions << a;
00708
00709 a = ac->addAction("select_beginning_of_document");
00710 a->setText(i18n("Select to Beginning of Document"));
00711 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_Home));
00712 connect(a, SIGNAL(triggered(bool)), SLOT(shiftTop()));
00713 m_editActions << a;
00714
00715
00716 a = ac->addAction("end_of_line");
00717 a->setText(i18n("Move to End of Line"));
00718 a->setShortcuts(KStandardShortcut::endOfLine());
00719 connect(a, SIGNAL(triggered(bool)), SLOT(end()));
00720 m_editActions << a;
00721
00722 a = ac->addAction("end_of_document");
00723 a->setText(i18n("Move to End of Document"));
00724 a->setShortcuts(KStandardShortcut::end());
00725 connect(a, SIGNAL(triggered(bool)), SLOT(bottom()));
00726 m_editActions << a;
00727
00728 a = ac->addAction("select_end_of_line");
00729 a->setText(i18n("Select to End of Line"));
00730 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_End));
00731 connect(a, SIGNAL(triggered(bool)), SLOT(shiftEnd()));
00732 m_editActions << a;
00733
00734 a = ac->addAction("select_end_of_document");
00735 a->setText(i18n("Select to End of Document"));
00736 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_End));
00737 connect(a, SIGNAL(triggered(bool)), SLOT(shiftBottom()));
00738 m_editActions << a;
00739
00740
00741 a = ac->addAction("select_line_up");
00742 a->setText(i18n("Select to Previous Line"));
00743 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Up));
00744 connect(a, SIGNAL(triggered(bool)), SLOT(shiftUp()));
00745 m_editActions << a;
00746
00747 a = ac->addAction("scroll_line_up");
00748 a->setText(i18n("Scroll Line Up"));
00749 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
00750 connect(a, SIGNAL(triggered(bool)), SLOT(scrollUp()));
00751 m_editActions << a;
00752
00753
00754 a = ac->addAction("move_line_down");
00755 a->setText(i18n("Move to Next Line"));
00756 a->setShortcut(QKeySequence(Qt::Key_Down));
00757 connect(a, SIGNAL(triggered(bool)), SLOT(down()));
00758 m_editActions << a;
00759
00760
00761 a = ac->addAction("move_line_up");
00762 a->setText(i18n("Move to Previous Line"));
00763 a->setShortcut(QKeySequence(Qt::Key_Up));
00764 connect(a, SIGNAL(triggered(bool)), SLOT(up()));
00765 m_editActions << a;
00766
00767
00768 a = ac->addAction("move_cursor_right");
00769 a->setText(i18n("Move Character Right"));
00770 a->setShortcut(QKeySequence(Qt::Key_Right));
00771 connect(a, SIGNAL(triggered(bool)), SLOT(cursorRight()));
00772 m_editActions << a;
00773
00774
00775 a = ac->addAction("move_cusor_left");
00776 a->setText(i18n("Move Character Left"));
00777 a->setShortcut(QKeySequence(Qt::Key_Left));
00778 connect(a, SIGNAL(triggered(bool)), SLOT(cursorLeft()));
00779 m_editActions << a;
00780
00781
00782 a = ac->addAction("select_line_down");
00783 a->setText(i18n("Select to Next Line"));
00784 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Down));
00785 connect(a, SIGNAL(triggered(bool)), SLOT(shiftDown()));
00786 m_editActions << a;
00787
00788 a = ac->addAction("scroll_line_down");
00789 a->setText(i18n("Scroll Line Down"));
00790 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
00791 connect(a, SIGNAL(triggered(bool)), SLOT(scrollDown()));
00792 m_editActions << a;
00793
00794
00795 a = ac->addAction("scroll_page_up");
00796 a->setText(i18n("Scroll Page Up"));
00797 a->setShortcuts(KStandardShortcut::prior());
00798 connect(a, SIGNAL(triggered(bool)), SLOT(pageUp()));
00799 m_editActions << a;
00800
00801 a = ac->addAction("select_page_up");
00802 a->setText(i18n("Select Page Up"));
00803 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_PageUp));
00804 connect(a, SIGNAL(triggered(bool)), SLOT(shiftPageUp()));
00805 m_editActions << a;
00806
00807 a = ac->addAction("move_top_of_view");
00808 a->setText(i18n("Move to Top of View"));
00809 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp));
00810 connect(a, SIGNAL(triggered(bool)), SLOT(topOfView()));
00811 m_editActions << a;
00812
00813 a = ac->addAction("select_top_of_view");
00814 a->setText(i18n("Select to Top of View"));
00815 a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_PageUp));
00816 connect(a, SIGNAL(triggered(bool)), SLOT(shiftTopOfView()));
00817 m_editActions << a;
00818
00819
00820 a = ac->addAction("scroll_page_down");
00821 a->setText(i18n("Scroll Page Down"));
00822 a->setShortcuts(KStandardShortcut::next());
00823 connect(a, SIGNAL(triggered(bool)), SLOT(pageDown()));
00824 m_editActions << a;
00825
00826 a = ac->addAction("select_page_down");
00827 a->setText(i18n("Select Page Down"));
00828 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_PageDown));
00829 connect(a, SIGNAL(triggered(bool)), SLOT(shiftPageDown()));
00830 m_editActions << a;
00831
00832 a = ac->addAction("move_bottom_of_view");
00833 a->setText(i18n("Move to Bottom of View"));
00834 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown));
00835 connect(a, SIGNAL(triggered(bool)), SLOT(bottomOfView()));
00836 m_editActions << a;
00837
00838 a = ac->addAction("select_bottom_of_view");
00839 a->setText(i18n("Select to Bottom of View"));
00840 a->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_PageDown));
00841 connect(a, SIGNAL(triggered(bool)), SLOT(shiftBottomOfView()));
00842 m_editActions << a;
00843
00844 a = ac->addAction("to_matching_bracket");
00845 a->setText(i18n("Move to Matching Bracket"));
00846 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6));
00847 connect(a, SIGNAL(triggered(bool)), SLOT(toMatchingBracket()));
00848 m_editActions << a;
00849
00850 a = ac->addAction("select_matching_bracket");
00851 a->setText(i18n("Select to Matching Bracket"));
00852 a->setShortcut(QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_6));
00853 connect(a, SIGNAL(triggered(bool)), SLOT(shiftToMatchingBracket()));
00854 m_editActions << a;
00855
00856
00857
00858 if ( !m_doc->readOnly() )
00859 {
00860 a = ac->addAction("transpose_char");
00861 a->setText(i18n("Transpose Characters"));
00862 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_T));
00863 connect(a, SIGNAL(triggered(bool)), SLOT(transpose()));
00864 m_editActions << a;
00865
00866 a = ac->addAction("delete_line");
00867 a->setText(i18n("Delete Line"));
00868 a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
00869 connect(a, SIGNAL(triggered(bool)), SLOT(killLine()));
00870 m_editActions << a;
00871
00872 a = ac->addAction("delete_word_left");
00873 a->setText(i18n("Delete Word Left"));
00874 a->setShortcuts(KStandardShortcut::deleteWordBack());
00875 connect(a, SIGNAL(triggered(bool)), SLOT(deleteWordLeft()));
00876 m_editActions << a;
00877
00878 a = ac->addAction("delete_word_right");
00879 a->setText(i18n("Delete Word Right"));
00880 a->setShortcuts(KStandardShortcut::deleteWordForward());
00881 connect(a, SIGNAL(triggered(bool)), SLOT(deleteWordRight()));
00882 m_editActions << a;
00883
00884 a = ac->addAction("delete_next_character");
00885 a->setText(i18n("Delete Next Character"));
00886 a->setShortcut(QKeySequence(Qt::Key_Delete));
00887 connect(a, SIGNAL(triggered(bool)), SLOT(keyDelete()));
00888 m_editActions << a;
00889
00890 a = ac->addAction("backspace");
00891 a->setText(i18n("Backspace"));
00892 QList<QKeySequence> scuts;
00893 scuts << QKeySequence(Qt::Key_Backspace)
00894 << QKeySequence(Qt::SHIFT + Qt::Key_Backspace);
00895 a->setShortcuts(scuts);
00896 connect(a, SIGNAL(triggered(bool)), SLOT(backspace()));
00897 m_editActions << a;
00898
00899 a = ac->addAction("smart_newline");
00900 a->setText(i18n("Insert Smart Newline"));
00901 a->setWhatsThis(i18n("Insert newline including leading characters of the current line which are not letters or numbers."));
00902 scuts.clear();
00903 scuts << QKeySequence(Qt::SHIFT + Qt::Key_Return)
00904 << QKeySequence(Qt::SHIFT + Qt::Key_Enter);
00905 a->setShortcuts(scuts);
00906 connect(a, SIGNAL(triggered(bool)), SLOT(smartNewline()));
00907 m_editActions << a;
00908
00909
00910 #if 0
00911 #ifdef __GNUC__
00912 #warning REMOVE THIS IN THE RELEASE
00913 #endif
00914
00915
00916
00917
00918
00919 #endif
00920 }
00921
00922 if( hasFocus() )
00923 slotGotFocus();
00924 else
00925 slotLostFocus();
00926 }
00927
00928 void KateView::setupCodeFolding()
00929 {
00930 KActionCollection *ac=this->actionCollection();
00931
00932 KAction* a = ac->addAction("folding_toplevel");
00933 a->setText(i18n("Collapse Toplevel"));
00934 a->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Minus));
00935 connect(a, SIGNAL(triggered(bool)), m_doc->foldingTree(), SLOT(collapseToplevelNodes()));
00936
00937 a = ac->addAction("folding_expandtoplevel");
00938 a->setText(i18n("Expand Toplevel"));
00939 a->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Plus));
00940 connect(a, SIGNAL(triggered(bool)), SLOT(slotExpandToplevel()));
00941
00942 a = ac->addAction("folding_collapselocal");
00943 a->setText(i18n("Collapse One Local Level"));
00944 a->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Minus));
00945 connect(a, SIGNAL(triggered(bool)), SLOT(slotCollapseLocal()));
00946
00947 a = ac->addAction("folding_expandlocal");
00948 a->setText(i18n("Expand One Local Level"));
00949 a->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Plus));
00950 connect(a, SIGNAL(triggered(bool)), SLOT(slotExpandLocal()));
00951 }
00952
00953 void KateView::slotExpandToplevel()
00954 {
00955 m_doc->foldingTree()->expandToplevelNodes(m_doc->lines());
00956 }
00957
00958 void KateView::slotCollapseLocal()
00959 {
00960 int realLine = m_doc->foldingTree()->collapseOne(cursorPosition().line());
00961 if (realLine != -1) {
00962
00963
00964
00965
00966
00967 KateTextLine::Ptr textLine = m_doc->plainKateTextLine(realLine);
00968 if (!textLine) return;
00969 KTextEditor::Cursor cc = KTextEditor::Cursor(realLine, textLine->fromVirtualColumn(virtualCursorColumn(), m_doc->config()->tabWidth()));
00970 setCursorPositionInternal(cc, 1);
00971 }
00972 }
00973
00974 void KateView::slotExpandLocal()
00975 {
00976 m_doc->foldingTree()->expandOne(cursorPosition().line(), m_doc->lines());
00977 }
00978
00979 QString KateView::viewMode () const
00980 {
00981 if (!m_doc->isReadWrite())
00982 return i18n ("R/O");
00983
00984 if (viInputMode()) {
00985
00986
00987 return QString();
00988 }
00989
00990 return isOverwriteMode() ? i18n("OVR") : i18n ("INS");
00991 }
00992
00993 void KateView::slotGotFocus()
00994 {
00995 kDebug(13020) << "KateView::slotGotFocus";
00996
00997 if ( !viInputMode() ) {
00998 activateEditActions();
00999 }
01000 emit focusIn ( this );
01001 }
01002
01003 void KateView::slotLostFocus()
01004 {
01005 kDebug(13020) << "KateView::slotLostFocus";
01006 if ( !viInputMode() ) {
01007 deactivateEditActions();
01008 }
01009
01010
01011
01012
01013
01014 emit focusOut ( this );
01015 }
01016
01017 void KateView::setDynWrapIndicators(int mode)
01018 {
01019 config()->setDynWordWrapIndicators (mode);
01020 }
01021
01022 bool KateView::isOverwriteMode() const
01023 {
01024 return m_doc->config()->configFlags() & KateDocumentConfig::cfOvr;
01025 }
01026
01027 void KateView::reloadFile()
01028 {
01029
01030 m_doc->documentReload();
01031 }
01032
01033 void KateView::slotReadWriteChanged ()
01034 {
01035 if ( m_toggleWriteLock )
01036 m_toggleWriteLock->setChecked( ! m_doc->isReadWrite() );
01037
01038 m_cut->setEnabled (m_doc->isReadWrite());
01039 m_paste->setEnabled (m_doc->isReadWrite());
01040
01041 QStringList l;
01042
01043 l << "edit_replace" << "set_insert" << "tools_spelling" << "tools_indent"
01044 << "tools_unindent" << "tools_cleanIndent" << "tools_align" << "tools_comment"
01045 << "tools_uncomment" << "tools_uppercase" << "tools_lowercase"
01046 << "tools_capitalize" << "tools_join_lines" << "tools_apply_wordwrap"
01047 << "tools_spelling_from_cursor"
01048 << "tools_spelling_selection";
01049
01050 QAction *a = 0;
01051 for (int z = 0; z < l.size(); z++)
01052 if ((a = actionCollection()->action( l[z].toAscii().constData() )))
01053 a->setEnabled (m_doc->isReadWrite());
01054 slotUpdateUndo();
01055 }
01056
01057 void KateView::slotUpdateUndo()
01058 {
01059 if (m_doc->readOnly())
01060 return;
01061
01062 m_editUndo->setEnabled(m_doc->isReadWrite() && m_doc->undoCount() > 0);
01063 m_editRedo->setEnabled(m_doc->isReadWrite() && m_doc->redoCount() > 0);
01064 }
01065
01066 void KateView::slotDropEventPass( QDropEvent * ev )
01067 {
01068 const KUrl::List lstDragURLs=KUrl::List::fromMimeData(ev->mimeData());
01069 bool ok = !lstDragURLs.isEmpty();
01070
01071 KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( doc() );
01072 if ( ok && ext )
01073 emit ext->openUrlRequest( lstDragURLs.first() );
01074 }
01075
01076 void KateView::contextMenuEvent( QContextMenuEvent *ev )
01077 {
01078 if ( !m_doc || !m_doc->browserExtension() )
01079 return;
01080 KParts::OpenUrlArguments args;
01081 args.setMimeType( QLatin1String("text/plain") );
01082 emit m_doc->browserExtension()->popupMenu( ev->globalPos(), m_doc->url(), S_IFREG, args );
01083 ev->accept();
01084 }
01085
01086 bool KateView::setCursorPositionInternal( const KTextEditor::Cursor& position, uint tabwidth, bool calledExternally )
01087 {
01088 QMutexLocker lock(m_doc->smartMutex());
01089
01090 KateTextLine::Ptr l = m_doc->kateTextLine( position.line() );
01091
01092 if (!l)
01093 return false;
01094
01095 QString line_str = m_doc->line( position.line() );
01096
01097 int x = 0;
01098 int z = 0;
01099 for (; z < line_str.length() && z < position.column(); z++) {
01100 if (line_str[z] == QChar('\t')) x += tabwidth - (x % tabwidth); else x++;
01101 }
01102
01103 if (blockSelectionMode())
01104 if (z < position.column())
01105 x += position.column() - z;
01106
01107 m_viewInternal->updateCursor( KTextEditor::Cursor(position.line(), x), false, true, calledExternally );
01108
01109 return true;
01110 }
01111
01112 void KateView::toggleInsert()
01113 {
01114 m_doc->config()->setConfigFlags(m_doc->config()->configFlags() ^ KateDocumentConfig::cfOvr);
01115 m_toggleInsert->setChecked (isOverwriteMode ());
01116
01117 emit viewModeChanged(this);
01118 emit viewEditModeChanged(this,viewEditMode());
01119 }
01120
01121 void KateView::slotSaveCanceled( const QString& error )
01122 {
01123 if ( !error.isEmpty() )
01124 KMessageBox::error( this, error );
01125 }
01126
01127 void KateView::gotoLine()
01128 {
01129 gotoBar()->updateData();
01130 m_bottomViewBar->showBarWidget(gotoBar());
01131 }
01132
01133 void KateView::joinLines()
01134 {
01135 int first = selectionRange().start().line();
01136 int last = selectionRange().end().line();
01137
01138 if ( first == last )
01139 {
01140 first = cursorPosition().line();
01141 last = first + 1;
01142 }
01143 m_doc->joinLines( first, last );
01144 }
01145
01146 void KateView::readSessionConfig(const KConfigGroup& config)
01147 {
01148 setCursorPositionInternal(KTextEditor::Cursor(config.readEntry("CursorLine",0), config.readEntry("CursorColumn",0)));
01149 }
01150
01151 void KateView::writeSessionConfig(KConfigGroup& config)
01152 {
01153 config.writeEntry("CursorLine",m_viewInternal->m_cursor.line());
01154 config.writeEntry("CursorColumn",m_viewInternal->m_cursor.column());
01155 }
01156
01157 int KateView::getEol() const
01158 {
01159 return m_doc->config()->eol();
01160 }
01161
01162 void KateView::setEol(int eol)
01163 {
01164 if (!doc()->isReadWrite())
01165 return;
01166
01167 if (m_updatingDocumentConfig)
01168 return;
01169
01170 m_doc->config()->setEol (eol);
01171 }
01172
01173 void KateView::setIconBorder( bool enable )
01174 {
01175 config()->setIconBar (enable);
01176 }
01177
01178 void KateView::toggleIconBorder()
01179 {
01180 config()->setIconBar (!config()->iconBar());
01181 }
01182
01183 void KateView::setLineNumbersOn( bool enable )
01184 {
01185 config()->setLineNumbers (enable);
01186 }
01187
01188 void KateView::toggleLineNumbersOn()
01189 {
01190 config()->setLineNumbers (!config()->lineNumbers());
01191 }
01192
01193 void KateView::setScrollBarMarks( bool enable )
01194 {
01195 config()->setScrollBarMarks (enable);
01196 }
01197
01198 void KateView::toggleScrollBarMarks()
01199 {
01200 config()->setScrollBarMarks (!config()->scrollBarMarks());
01201 }
01202
01203 void KateView::toggleDynWordWrap()
01204 {
01205 config()->setDynWordWrap( !config()->dynWordWrap() );
01206 }
01207
01208 void KateView::toggleWWMarker()
01209 {
01210 m_renderer->config()->setWordWrapMarker (!m_renderer->config()->wordWrapMarker());
01211 }
01212
01213 void KateView::setFoldingMarkersOn( bool enable )
01214 {
01215 config()->setFoldingBar ( enable );
01216 }
01217
01218 void KateView::toggleFoldingMarkers()
01219 {
01220 config()->setFoldingBar ( !config()->foldingBar() );
01221 }
01222
01223 bool KateView::iconBorder() {
01224 return m_viewInternal->m_leftBorder->iconBorderOn();
01225 }
01226
01227 bool KateView::lineNumbersOn() {
01228 return m_viewInternal->m_leftBorder->lineNumbersOn();
01229 }
01230
01231 bool KateView::scrollBarMarks() {
01232 return m_viewInternal->m_lineScroll->showMarks();
01233 }
01234
01235 int KateView::dynWrapIndicators() {
01236 return m_viewInternal->m_leftBorder->dynWrapIndicators();
01237 }
01238
01239 bool KateView::foldingMarkersOn() {
01240 return m_viewInternal->m_leftBorder->foldingMarkersOn();
01241 }
01242
01243 void KateView::toggleWriteLock()
01244 {
01245 m_doc->setReadWrite( ! m_doc->isReadWrite() );
01246 }
01247
01248 void KateView::enableTextHints(int timeout)
01249 {
01250 m_viewInternal->enableTextHints(timeout);
01251 }
01252
01253 void KateView::disableTextHints()
01254 {
01255 m_viewInternal->disableTextHints();
01256 }
01257
01258 bool KateView::viInputMode() const
01259 {
01260 return m_viewInternal->m_viInputMode;
01261 }
01262
01263 bool KateView::viInputModeStealKeys() const
01264 {
01265 return m_viewInternal->m_viInputModeStealKeys;
01266 }
01267
01268 void KateView::toggleViInputMode()
01269 {
01270 config()->setViInputMode (!config()->viInputMode());
01271
01272 if ( viInputMode() ) {
01273 m_viewInternal->getViInputModeManager()->viEnterNormalMode();
01274
01275 if ( !config()->viInputModeHideStatusBar() ) {
01276 showViModeBar();
01277 }
01278
01279 deactivateEditActions();
01280 } else {
01281 hideViModeBar();
01282 activateEditActions();
01283 }
01284
01285 emit viewModeChanged(this);
01286 emit viewEditModeChanged(this,viewEditMode());
01287 }
01288
01289 void KateView::showViModeBar()
01290 {
01291 if (viInputMode() && !config()->viInputModeHideStatusBar()) {
01292 m_bottomViewBar->addPermanentBarWidget(viModeBar());
01293 updateViModeBarMode();
01294 }
01295 }
01296
01297 void KateView::hideViModeBar()
01298 {
01299 if (m_bottomViewBar) {
01300 m_bottomViewBar->removePermanentBarWidget(viModeBar());
01301 }
01302 }
01303
01304 void KateView::updateViModeBarMode()
01305 {
01306 if (config()->viInputModeHideStatusBar())
01307 return;
01308
01309 viModeBar()->updateViMode(getCurrentViMode());
01310 }
01311
01312 void KateView::updateViModeBarCmd()
01313 {
01314 if (config()->viInputModeHideStatusBar())
01315 return;
01316
01317 QString cmd = m_viewInternal->getViInputModeManager()->getVerbatimKeys();
01318 viModeBar()->updatePartialCommand(cmd);
01319 }
01320
01321 ViMode KateView::getCurrentViMode() const
01322 {
01323 return m_viewInternal->getCurrentViMode();
01324 }
01325
01326 KateViInputModeManager* KateView::getViInputModeManager()
01327 {
01328 return m_viewInternal->getViInputModeManager();
01329 }
01330
01331 void KateView::slotNeedTextHint(int line, int col, QString &text)
01332 {
01333 text=QString("test %1 %2").arg(line).arg(col);
01334 }
01335
01336 void KateView::find()
01337 {
01338 const bool INIT_HINT_AS_INCREMENTAL = false;
01339 KateSearchBar * const bar = searchBar(INIT_HINT_AS_INCREMENTAL);
01340 if (bar->hasFocus())
01341 return m_viewInternal->setFocus();
01342 bar->onMutateIncremental();
01343 m_bottomViewBar->showBarWidget(bar);
01344 bar->setFocus();
01345 }
01346
01347 void KateView::findSelectedForwards()
01348 {
01349 const bool FORWARDS = true;
01350 KateSearchBar::nextMatchForSelection(this, FORWARDS);
01351 }
01352
01353 void KateView::findSelectedBackwards()
01354 {
01355 const bool BACKWARDS = false;
01356 KateSearchBar::nextMatchForSelection(this, BACKWARDS);
01357 }
01358
01359 void KateView::replace()
01360 {
01361 const bool INIT_HINT_AS_POWER = true;
01362 KateSearchBar * const bar = searchBar(INIT_HINT_AS_POWER);
01363 if (bar->hasFocus())
01364 return m_viewInternal->setFocus();
01365 bar->onMutatePower();
01366 m_bottomViewBar->showBarWidget(bar);
01367 bar->setFocus();
01368 }
01369
01370 void KateView::findNext()
01371 {
01372 searchBar()->findNext();
01373 }
01374
01375 void KateView::findPrevious()
01376 {
01377 searchBar()->findPrevious();
01378 }
01379
01380 void KateView::slotSelectionChanged ()
01381 {
01382 m_copy->setEnabled (selection());
01383 m_copyHTML->setEnabled (selection());
01384 m_deSelect->setEnabled (selection());
01385
01386 if (m_doc->readOnly())
01387 return;
01388
01389 m_cut->setEnabled (selection());
01390
01391 m_spell->updateActions ();
01392 }
01393
01394 void KateView::switchToCmdLine ()
01395 {
01396
01397
01398 if (selectionRange().start().line() != -1 && selectionRange().end().line() != -1) {
01399 cmdLine()->setText(QString::number(selectionRange().start().line()+1)+','
01400 +QString::number(selectionRange().end().line()+1));
01401 }
01402 m_bottomViewBar->showBarWidget(cmdLine());
01403 cmdLine()->setFocus ();
01404 hideViModeBar();
01405 }
01406
01407 KateRenderer *KateView::renderer ()
01408 {
01409 return m_renderer;
01410 }
01411
01412 void KateView::updateConfig ()
01413 {
01414 if (m_startingUp)
01415 return;
01416
01417
01418 if (m_hasWrap != config()->dynWordWrap()) {
01419 m_viewInternal->prepareForDynWrapChange();
01420
01421 m_hasWrap = config()->dynWordWrap();
01422
01423 m_viewInternal->dynWrapChanged();
01424
01425 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
01426 m_toggleDynWrap->setChecked( config()->dynWordWrap() );
01427 }
01428
01429 m_viewInternal->m_leftBorder->setDynWrapIndicators( config()->dynWordWrapIndicators() );
01430 m_setDynWrapIndicators->setCurrentItem( config()->dynWordWrapIndicators() );
01431
01432
01433 m_viewInternal->m_leftBorder->setLineNumbersOn( config()->lineNumbers() );
01434 m_toggleLineNumbers->setChecked( config()->lineNumbers() );
01435
01436
01437 m_viewInternal->m_leftBorder->setIconBorderOn( config()->iconBar() );
01438 m_toggleIconBar->setChecked( config()->iconBar() );
01439
01440
01441 m_viewInternal->m_lineScroll->setShowMarks( config()->scrollBarMarks() );
01442 m_toggleScrollBarMarks->setChecked( config()->scrollBarMarks() );
01443
01444
01445 m_toggleBlockSelection->setChecked( blockSelectionMode() );
01446 m_toggleInsert->setChecked( isOverwriteMode() );
01447
01448
01449 m_viInputModeAction->setChecked( config()->viInputMode() );
01450
01451 updateFoldingConfig ();
01452
01453
01454 m_bookmarks->setSorting( (KateBookmarks::Sorting) config()->bookmarkSort() );
01455
01456 m_viewInternal->setAutoCenterLines(config()->autoCenterLines ());
01457
01458
01459 m_viewInternal->m_viInputMode = config()->viInputMode();
01460
01461
01462 m_viewInternal->m_viInputModeStealKeys = config()->viInputModeStealKeys();
01463
01464
01465 unregisterCompletionModel (KateGlobal::self()->wordCompletionModel());
01466 if (config()->wordCompletion ())
01467 registerCompletionModel (KateGlobal::self()->wordCompletionModel());
01468
01469
01470 {
01471 QMutexLocker lock(m_viewInternal->m_doc->smartMutex());
01472 m_viewInternal->cache()->clear();
01473 }
01474 tagAll ();
01475 updateView (true);
01476 }
01477
01478 void KateView::updateDocumentConfig()
01479 {
01480 if (m_startingUp)
01481 return;
01482
01483 m_updatingDocumentConfig = true;
01484
01485 m_setEndOfLine->setCurrentItem (m_doc->config()->eol());
01486
01487 m_updatingDocumentConfig = false;
01488
01489
01490 ensureCursorColumnValid();
01491
01492
01493 m_renderer->setTabWidth (m_doc->config()->tabWidth());
01494 m_renderer->setIndentWidth (m_doc->config()->indentationWidth());
01495
01496
01497 {
01498 QMutexLocker lock(m_viewInternal->m_doc->smartMutex());
01499 m_viewInternal->cache()->clear();
01500 }
01501 tagAll ();
01502 updateView (true);
01503 }
01504
01505 void KateView::updateRendererConfig()
01506 {
01507 if (m_startingUp)
01508 return;
01509
01510 m_toggleWWMarker->setChecked( m_renderer->config()->wordWrapMarker() );
01511
01512 m_viewInternal->updateBracketMarkAttributes();
01513 m_viewInternal->updateBracketMarks();
01514
01515
01516 {
01517 QMutexLocker lock(m_viewInternal->m_doc->smartMutex());
01518 m_viewInternal->cache()->clear();
01519 }
01520 tagAll ();
01521 m_viewInternal->updateView (true);
01522
01523
01524 m_viewInternal->m_leftBorder->updateFont();
01525 m_viewInternal->m_leftBorder->repaint ();
01526
01527
01528
01529 }
01530
01531 void KateView::updateFoldingConfig ()
01532 {
01533
01534 bool doit = config()->foldingBar() && m_doc->highlight() && m_doc->highlight()->allowsFolding();
01535 m_viewInternal->m_leftBorder->setFoldingMarkersOn(doit);
01536 m_toggleFoldingMarkers->setChecked( doit );
01537 m_toggleFoldingMarkers->setEnabled( m_doc->highlight() && m_doc->highlight()->allowsFolding() );
01538
01539 QStringList l;
01540
01541 l << "folding_toplevel" << "folding_expandtoplevel"
01542 << "folding_collapselocal" << "folding_expandlocal";
01543
01544 QAction *a = 0;
01545 for (int z = 0; z < l.size(); z++)
01546 if ((a = actionCollection()->action( l[z].toAscii().constData() )))
01547 a->setEnabled (m_doc->highlight() && m_doc->highlight()->allowsFolding());
01548 }
01549
01550 void KateView::ensureCursorColumnValid()
01551 {
01552 KTextEditor::Cursor c = m_viewInternal->getCursor();
01553
01554
01555
01556
01557 if (!blockSelectionMode() && wrapCursor()
01558 && (!c.isValid() || c.column() > m_doc->lineLength(c.line())))
01559 {
01560 c.setColumn(m_doc->kateTextLine(cursorPosition().line())->length());
01561 setCursorPosition(c);
01562 }
01563 }
01564
01565
01566 void KateView::editStart ()
01567 {
01568 m_viewInternal->editStart ();
01569 }
01570
01571 void KateView::editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom)
01572 {
01573 m_viewInternal->editEnd (editTagLineStart, editTagLineEnd, tagFrom);
01574 }
01575
01576 void KateView::editSetCursor (const KTextEditor::Cursor &cursor)
01577 {
01578 m_viewInternal->editSetCursor (cursor);
01579 }
01580
01581
01582
01583 bool KateView::tagLine (const KTextEditor::Cursor& virtualCursor)
01584 {
01585 return m_viewInternal->tagLine (virtualCursor);
01586 }
01587
01588 bool KateView::tagRange(const KTextEditor::Range& range, bool realLines)
01589 {
01590 return m_viewInternal->tagRange(range, realLines);
01591 }
01592
01593 bool KateView::tagLines (int start, int end, bool realLines)
01594 {
01595 return m_viewInternal->tagLines (start, end, realLines);
01596 }
01597
01598 bool KateView::tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors)
01599 {
01600 return m_viewInternal->tagLines (start, end, realCursors);
01601 }
01602
01603 void KateView::tagAll ()
01604 {
01605 m_viewInternal->tagAll ();
01606 }
01607
01608 void KateView::relayoutRange( const KTextEditor::Range & range, bool realLines )
01609 {
01610 return m_viewInternal->relayoutRange(range, realLines);
01611 }
01612
01613 void KateView::clear ()
01614 {
01615 m_viewInternal->clear ();
01616 }
01617
01618 void KateView::repaintText (bool paintOnlyDirty)
01619 {
01620 if (paintOnlyDirty)
01621 m_viewInternal->updateDirty();
01622 else
01623 m_viewInternal->update();
01624 }
01625
01626 void KateView::updateView (bool changed)
01627 {
01628 m_viewInternal->updateView (changed);
01629 kDebug(13020) << "KateView::updateView";
01630 m_viewInternal->m_leftBorder->update();
01631 }
01632
01633
01634
01635 void KateView::slotHlChanged()
01636 {
01637 KateHighlighting *hl = m_doc->highlight();
01638 bool ok ( !hl->getCommentStart(0).isEmpty() || !hl->getCommentSingleLineStart(0).isEmpty() );
01639
01640 if (actionCollection()->action("tools_comment"))
01641 actionCollection()->action("tools_comment")->setEnabled( ok );
01642
01643 if (actionCollection()->action("tools_uncomment"))
01644 actionCollection()->action("tools_uncomment")->setEnabled( ok );
01645
01646
01647 updateFoldingConfig ();
01648 }
01649
01650 int KateView::virtualCursorColumn() const
01651 {
01652 int r = m_doc->toVirtualColumn(m_viewInternal->getCursor());
01653 if ( !( m_doc->config()->configFlags() & KateDocumentConfig::cfWrapCursor ) &&
01654 m_viewInternal->getCursor().column() > m_doc->line( m_viewInternal->getCursor().line() ).length() )
01655 r += m_viewInternal->getCursor().column() - m_doc->line( m_viewInternal->getCursor().line() ).length();
01656
01657 return r;
01658 }
01659
01660 void KateView::notifyMousePositionChanged(const KTextEditor::Cursor& newPosition)
01661 {
01662 emit mousePositionChanged(this, newPosition);
01663 }
01664
01665
01666
01667 bool KateView::setSelection( const KTextEditor::Range &selection )
01668 {
01669 QMutexLocker l(m_doc->smartMutex());
01670
01671 KTextEditor::Range oldSelection = *m_selection;
01672 *m_selection = selection.isEmpty() ? KTextEditor::Range::invalid() : selection;
01673
01674 tagSelection(oldSelection);
01675
01676 repaintText(true);
01677
01678 emit selectionChanged (this);
01679
01680 return true;
01681 }
01682
01683 bool KateView::clearSelection()
01684 {
01685 return clearSelection(true);
01686 }
01687
01688 bool KateView::clearSelection(bool redraw, bool finishedChangingSelection)
01689 {
01690 QMutexLocker l(m_doc->smartMutex());
01691
01692 if( !selection() )
01693 return false;
01694
01695 KTextEditor::Range oldSelection = *m_selection;
01696
01697 *m_selection = KTextEditor::Range::invalid();
01698
01699 tagSelection(oldSelection);
01700
01701 oldSelection = *m_selection;
01702
01703 if (redraw)
01704 repaintText(true);
01705
01706 if (finishedChangingSelection)
01707 emit selectionChanged(this);
01708
01709 return true;
01710 }
01711
01712 bool KateView::selection() const
01713 {
01714 if(blockSelection())
01715 return *m_selection != KateSmartRange::invalid();
01716 else
01717 return m_selection->isValid();
01718 }
01719
01720 QString KateView::selectionText() const
01721 {
01722 QMutexLocker l(m_doc->smartMutex());
01723
01724 KTextEditor::Range range = *m_selection;
01725
01726 if ( blockSelect )
01727 blockFix(range);
01728
01729 return m_doc->text(range, blockSelect);
01730 }
01731
01732 bool KateView::removeSelectedText()
01733 {
01734 QMutexLocker l(m_doc->smartMutex());
01735
01736 if (!selection())
01737 return false;
01738
01739 m_doc->editStart (true, Kate::CutCopyPasteEdit);
01740
01741 KTextEditor::Range range = *m_selection;
01742
01743 if ( blockSelect )
01744 blockFix(range);
01745
01746 m_doc->removeText(range, blockSelect);
01747
01748
01749 clearSelection(false);
01750
01751 m_doc->editEnd ();
01752
01753 return true;
01754 }
01755
01756 bool KateView::selectAll()
01757 {
01758 setBlockSelectionMode (false);
01759
01760 return setSelection(KTextEditor::Range(KTextEditor::Cursor(), m_doc->documentEnd()));
01761 }
01762
01763 bool KateView::cursorSelected(const KTextEditor::Cursor& cursor)
01764 {
01765 KTextEditor::Cursor ret = cursor;
01766 if ( (!blockSelect) && (ret.column() < 0) )
01767 ret.setColumn(0);
01768
01769 if (blockSelect)
01770 return cursor.line() >= m_selection->start().line() && ret.line() <= m_selection->end().line() && ret.column() >= m_selection->start().column() && ret.column() < m_selection->end().column();
01771 else
01772 return m_selection->contains(cursor) || m_selection->end() == cursor;
01773 }
01774
01775 bool KateView::lineSelected (int line)
01776 {
01777 return !blockSelect && m_selection->containsLine(line);
01778 }
01779
01780 bool KateView::lineEndSelected (const KTextEditor::Cursor& lineEndPos)
01781 {
01782 return (!blockSelect)
01783 && (lineEndPos.line() > m_selection->start().line() || (lineEndPos.line() == m_selection->start().line() && (m_selection->start().column() < lineEndPos.column() || lineEndPos.column() == -1)))
01784 && (lineEndPos.line() < m_selection->end().line() || (lineEndPos.line() == m_selection->end().line() && (lineEndPos.column() <= m_selection->end().column() && lineEndPos.column() != -1)));
01785 }
01786
01787 bool KateView::lineHasSelected (int line)
01788 {
01789 return selection() && m_selection->containsLine(line);
01790 }
01791
01792 bool KateView::lineIsSelection (int line)
01793 {
01794 return (line == m_selection->start().line() && line == m_selection->end().line());
01795 }
01796
01797 void KateView::tagSelection(const KTextEditor::Range &oldSelection)
01798 {
01799 if (selection()) {
01800 if (oldSelection.start().line() == -1) {
01801
01802
01803
01804 tagLines(*m_selection, true);
01805
01806 } else if (blockSelectionMode() && (oldSelection.start().column() != m_selection->start().column() || oldSelection.end().column() != m_selection->end().column())) {
01807
01808 tagLines(*m_selection, true);
01809 tagLines(oldSelection, true);
01810
01811 } else {
01812 if (oldSelection.start() != m_selection->start()) {
01813 if (oldSelection.start() < m_selection->start())
01814 tagLines(oldSelection.start(), m_selection->start(), true);
01815 else
01816 tagLines(m_selection->start(), oldSelection.start(), true);
01817 }
01818
01819 if (oldSelection.end() != m_selection->end()) {
01820 if (oldSelection.end() < m_selection->end())
01821 tagLines(oldSelection.end(), m_selection->end(), true);
01822 else
01823 tagLines(m_selection->end(), oldSelection.end(), true);
01824 }
01825 }
01826
01827 } else {
01828
01829 tagLines(oldSelection, true);
01830 }
01831 }
01832
01833 void KateView::selectWord( const KTextEditor::Cursor& cursor )
01834 {
01835 int start, end, len;
01836
01837 KateTextLine::Ptr textLine = m_doc->plainKateTextLine(cursor.line());
01838
01839 if (!textLine)
01840 return;
01841
01842 len = textLine->length();
01843 start = end = cursor.column();
01844 while (start > 0 && m_doc->highlight()->isInWord(textLine->at(start - 1), textLine->attribute(start - 1))) start--;
01845 while (end < len && m_doc->highlight()->isInWord(textLine->at(end), textLine->attribute(start - 1))) end++;
01846 if (end <= start) return;
01847
01848 setSelection (KTextEditor::Range(cursor.line(), start, cursor.line(), end));
01849 }
01850
01851 void KateView::selectLine( const KTextEditor::Cursor& cursor )
01852 {
01853 int line = cursor.line();
01854 if ( line+1 >= m_doc->lines() )
01855 setSelection (KTextEditor::Range(line, 0, line, m_doc->lineLength(line)));
01856 else
01857 setSelection (KTextEditor::Range(line, 0, line+1, 0));
01858 }
01859
01860 void KateView::cut()
01861 {
01862 if (!selection())
01863 return;
01864
01865 copy();
01866 removeSelectedText();
01867 }
01868
01869 void KateView::copy() const
01870 {
01871 if (!selection())
01872 return;
01873
01874 QApplication::clipboard()->setText(selectionText ());
01875 }
01876
01877 void KateView::applyWordWrap ()
01878 {
01879 if (selection())
01880 m_doc->wrapText (selectionRange().start().line(), selectionRange().end().line());
01881 else
01882 m_doc->wrapText (0, m_doc->lastLine());
01883 }
01884
01885 void KateView::copyHTML()
01886 {
01887 if (!selection())
01888 return;
01889
01890 QMimeData *data = new QMimeData();
01891 data->setText(selectionText());
01892 data->setHtml(selectionAsHtml());
01893 QApplication::clipboard()->setMimeData(data);
01894 }
01895
01896 QString KateView::selectionAsHtml()
01897 {
01898 return textAsHtml(*m_selection, blockSelect);
01899 }
01900
01901 QString KateView::textAsHtml ( KTextEditor::Range range, bool blockwise)
01902 {
01903 kDebug(13020) << "textAsHtml";
01904 if (blockwise)
01905 blockFix(range);
01906
01907 QString s;
01908 QTextStream ts( &s, QIODevice::WriteOnly );
01909
01910 ts.setCodec(QTextCodec::codecForName("UTF-8"));
01911 ts << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
01912 ts << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
01913 ts << "<head>" << endl;
01914 ts << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
01915 ts << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
01916 ts << "</head>" << endl;
01917
01918 ts << "<body>" << endl;
01919 textAsHtmlStream(range, blockwise, &ts);
01920
01921 ts << "</body>" << endl;
01922 ts << "</html>" << endl;
01923 kDebug(13020) << "html is: " << s;
01924 return s;
01925 }
01926
01927 void KateView::textAsHtmlStream ( const KTextEditor::Range& range, bool blockwise, QTextStream *ts)
01928 {
01929 if ( (blockwise || range.onSingleLine()) && (range.start().column() > range.end().column() ) )
01930 return;
01931
01932 if (range.onSingleLine())
01933 {
01934 KateTextLine::Ptr textLine = m_doc->kateTextLine(range.start().line());
01935 if ( !textLine )
01936 return;
01937
01938 (*ts) << "<pre>" << endl;
01939
01940 lineAsHTML(textLine, range.start().column(), range.columnWidth(), ts);
01941 }
01942 else
01943 {
01944 (*ts) << "<pre>" << endl;
01945
01946 for (int i = range.start().line(); (i <= range.end().line()) && (i < m_doc->lines()); ++i)
01947 {
01948 KateTextLine::Ptr textLine = m_doc->kateTextLine(i);
01949
01950 if ( !blockwise )
01951 {
01952 if (i == range.start().line())
01953 lineAsHTML(textLine, range.start().column(), textLine->length() - range.start().column(), ts);
01954 else if (i == range.end().line())
01955 lineAsHTML(textLine, 0, range.end().column(), ts);
01956 else
01957 lineAsHTML(textLine, 0, textLine->length(), ts);
01958 }
01959 else
01960 {
01961 lineAsHTML( textLine, range.start().column(), range.columnWidth(), ts);
01962 }
01963
01964 if ( i < range.end().line() )
01965 (*ts) << "\n";
01966 }
01967 }
01968 (*ts) << "</pre>";
01969 }
01970
01971 void KateView::lineAsHTML (KateTextLine::Ptr line, int startCol, int length, QTextStream *outputStream)
01972 {
01973 if(length == 0) return;
01974
01975 bool previousCharacterWasBold = false;
01976 bool previousCharacterWasItalic = false;
01977
01978
01979
01980 bool needToReinitializeTags = false;
01981 QColor previousCharacterColor(0,0,0);
01982 QColor blackColor(0,0,0);
01983
01984
01985
01986
01987 for (int curPos=startCol;curPos<(length+startCol);curPos++)
01988 {
01989 KTextEditor::Attribute::Ptr charAttributes = m_renderer->attribute(line->attribute(curPos));
01990
01991
01992
01993 if ( (charAttributes->foreground() != previousCharacterColor))
01994 {
01995
01996 if (previousCharacterWasBold)
01997 (*outputStream) << "</b>";
01998 if (previousCharacterWasItalic)
01999 (*outputStream) << "</i>";
02000
02001
02002 if(previousCharacterColor != blackColor)
02003 (*outputStream) << "</span>";
02004
02005 int red, green, blue;
02006
02007 charAttributes->foreground().color().getRgb(&red, &green, &blue);
02008 if(!(red == 0 && green == 0 && blue == 0)) {
02009 (*outputStream) << "<span style='color: #"
02010 << ( (red < 0x10)?"0":"")
02011 << QString::number(red, 16)
02012 << ( (green < 0x10)?"0":"")
02013 << QString::number(green, 16)
02014 << ( (blue < 0x10)?"0":"")
02015 << QString::number(blue, 16)
02016 << "'>";
02017 }
02018
02019 needToReinitializeTags = true;
02020 }
02021
02022 if ( (needToReinitializeTags && charAttributes->fontBold()) ||
02023 (!previousCharacterWasBold && charAttributes->fontBold()) )
02024
02025 (*outputStream) << "<b>";
02026 if ( !needToReinitializeTags && (previousCharacterWasBold && !charAttributes->fontBold()) )
02027
02028 (*outputStream) << "</b>";
02029
02030
02031 if ( (needToReinitializeTags && charAttributes->fontItalic()) ||
02032 (!previousCharacterWasItalic && charAttributes->fontItalic()) )
02033
02034 (*outputStream) << "<i>";
02035 if ( !needToReinitializeTags && (previousCharacterWasItalic && !charAttributes->fontItalic()) )
02036
02037 (*outputStream) << "</i>";
02038
02039
02040 (*outputStream) << Qt::escape(QString(line->at(curPos)));
02041
02042
02043 previousCharacterWasItalic = charAttributes->fontItalic();
02044 previousCharacterWasBold = charAttributes->fontBold();
02045 previousCharacterColor = charAttributes->foreground().color();
02046 needToReinitializeTags = false;
02047 }
02048
02049 if (previousCharacterWasBold)
02050 (*outputStream) << "</b>";
02051 if (previousCharacterWasItalic)
02052 (*outputStream) << "</i>";
02053
02054 if(previousCharacterColor != blackColor)
02055 (*outputStream) << "</span>";
02056 }
02057
02058 void KateView::exportAsHTML ()
02059 {
02060 KUrl url = KFileDialog::getSaveUrl(m_doc->documentName(), "text/html",
02061 this, i18n("Export File as HTML"));
02062
02063 if ( url.isEmpty() )
02064 return;
02065
02066 QString filename;
02067
02068 if ( url.isLocalFile() )
02069 filename = url.toLocalFile();
02070 else {
02071 KTemporaryFile tmp;
02072 tmp.setAutoRemove(false);
02073 tmp.open();
02074 filename = tmp.fileName();
02075 }
02076
02077 KSaveFile savefile(filename);
02078 if (savefile.open())
02079 {
02080 QTextStream outputStream ( &savefile );
02081
02082
02083 outputStream.setCodec(QTextCodec::codecForName("UTF-8"));
02084
02085 outputStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
02086 outputStream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl;
02087 outputStream << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl;
02088 outputStream << "<head>" << endl;
02089 outputStream << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl;
02090 outputStream << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl;
02091
02092 outputStream << "<title>" << m_doc->documentName () << "</title>" << endl;
02093 outputStream << "</head>" << endl;
02094 outputStream << "<body>" << endl;
02095
02096 textAsHtmlStream(m_doc->documentRange(), false, &outputStream);
02097
02098 outputStream << "</body>" << endl;
02099 outputStream << "</html>" << endl;
02100 outputStream.flush();
02101
02102 savefile.finalize();
02103 }
02104
02105
02106
02107 if ( url.isLocalFile() )
02108 return;
02109
02110 KIO::NetAccess::upload( filename, url, 0 );
02111 }
02112
02113
02114
02115
02116 bool KateView::blockSelectionMode () const
02117 {
02118 return blockSelect;
02119 }
02120
02121 bool KateView::setBlockSelectionMode (bool on)
02122 {
02123 QMutexLocker l(m_doc->smartMutex());
02124
02125 if (on != blockSelect)
02126 {
02127 blockSelect = on;
02128
02129 KTextEditor::Range oldSelection = *m_selection;
02130
02131 clearSelection(false, false);
02132
02133 setSelection(oldSelection);
02134
02135 m_toggleBlockSelection->setChecked( blockSelectionMode() );
02136
02137
02138
02139 ensureCursorColumnValid();
02140 }
02141
02142 return true;
02143 }
02144
02145 bool KateView::toggleBlockSelectionMode ()
02146 {
02147 m_toggleBlockSelection->setChecked (!blockSelect);
02148 return setBlockSelectionMode (!blockSelect);
02149 }
02150
02151 bool KateView::wrapCursor ()
02152 {
02153 return !blockSelectionMode() && (m_doc->config()->configFlags() & KateDocumentConfig::cfWrapCursor);
02154 }
02155
02156
02157
02158
02159 void KateView::slotTextInserted ( KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
02160 {
02161 emit textInserted ( view, position, text);
02162 }
02163
02164 bool KateView::insertTemplateTextImplementation ( const KTextEditor::Cursor& c, const QString &templateString, const QMap<QString,QString> &initialValues) {
02165 return m_doc->insertTemplateTextImplementation(c,templateString,initialValues,this);
02166 }
02167
02168 bool KateView::tagLines( KTextEditor::Range range, bool realRange )
02169 {
02170 return tagLines(range.start(), range.end(), realRange);
02171 }
02172
02173 void KateView::addInternalHighlight( KTextEditor::SmartRange * topRange )
02174 {
02175 m_internalHighlights.append(topRange);
02176
02177 m_viewInternal->addHighlightRange(topRange);
02178 }
02179
02180 void KateView::removeInternalHighlight( KTextEditor::SmartRange * topRange )
02181 {
02182 m_internalHighlights.removeAll(topRange);
02183
02184 m_viewInternal->removeHighlightRange(topRange);
02185 }
02186
02187 const QList< KTextEditor::SmartRange * > & KateView::internalHighlights( ) const
02188 {
02189 return m_internalHighlights;
02190 }
02191
02192 void KateView::rangeDeleted( KTextEditor::SmartRange * range )
02193 {
02194 removeExternalHighlight(range);
02195 removeActions(range);
02196 }
02197
02198 void KateView::addExternalHighlight( KTextEditor::SmartRange * topRange, bool supportDynamic )
02199 {
02200 if (m_externalHighlights.contains(topRange))
02201 return;
02202
02203 m_externalHighlights.append(topRange);
02204
02205
02206 topRange->addWatcher(this);
02207
02208 if (supportDynamic) {
02209 m_externalHighlightsDynamic.append(topRange);
02210 emit dynamicHighlightAdded(static_cast<KateSmartRange*>(topRange));
02211 }
02212
02213 m_viewInternal->addHighlightRange(topRange);
02214 }
02215
02216 void KateView::removeExternalHighlight( KTextEditor::SmartRange * topRange )
02217 {
02218 if (!m_externalHighlights.contains(topRange))
02219 return;
02220
02221 m_externalHighlights.removeAll(topRange);
02222
02223 if (!m_actions.contains(topRange))
02224 topRange->removeWatcher(this);
02225
02226 if (m_externalHighlightsDynamic.contains(topRange)) {
02227 m_externalHighlightsDynamic.removeAll(topRange);
02228 emit dynamicHighlightRemoved(static_cast<KateSmartRange*>(topRange));
02229 }
02230
02231 m_viewInternal->removeHighlightRange(topRange);
02232 }
02233
02234 const QList< KTextEditor::SmartRange * > & KateView::externalHighlights( ) const
02235 {
02236 return m_externalHighlights;
02237 }
02238
02239 void KateView::addActions( KTextEditor::SmartRange * topRange )
02240 {
02241 if (m_actions.contains(topRange))
02242 return;
02243
02244 m_actions.append(topRange);
02245
02246
02247 topRange->addWatcher(this);
02248 }
02249
02250 void KateView::removeActions( KTextEditor::SmartRange * topRange )
02251 {
02252 if (!m_actions.contains(topRange))
02253 return;
02254
02255 m_actions.removeAll(topRange);
02256
02257 if (!m_externalHighlights.contains(topRange))
02258 topRange->removeWatcher(this);
02259 }
02260
02261 const QList< KTextEditor::SmartRange * > & KateView::actions( ) const
02262 {
02263 return m_actions;
02264 }
02265
02266 void KateView::clearExternalHighlights( )
02267 {
02268 m_externalHighlights.clear();
02269 }
02270
02271 void KateView::clearActions( )
02272 {
02273 m_actions.clear();
02274 }
02275
02276 void KateView::deactivateEditActions()
02277 {
02278 foreach(QAction *action, m_editActions)
02279 action->setEnabled(false);
02280 }
02281
02282 void KateView::activateEditActions()
02283 {
02284 foreach(QAction *action, m_editActions)
02285 action->setEnabled(true);
02286 }
02287
02288 bool KateView::mouseTrackingEnabled( ) const
02289 {
02290
02291 return true;
02292 }
02293
02294 bool KateView::setMouseTrackingEnabled( bool )
02295 {
02296
02297 return true;
02298 }
02299
02300 bool KateView::isCompletionActive( ) const
02301 {
02302 return completionWidget()->isCompletionActive();
02303 }
02304
02305 KateCompletionWidget* KateView::completionWidget() const
02306 {
02307 if (!m_completionWidget)
02308 m_completionWidget = new KateCompletionWidget(const_cast<KateView*>(this));
02309
02310 return m_completionWidget;
02311 }
02312
02313 void KateView::startCompletion( const KTextEditor::Range & word, KTextEditor::CodeCompletionModel * model )
02314 {
02315 completionWidget()->startCompletion(word, model);
02316 }
02317
02318 void KateView::abortCompletion( )
02319 {
02320 completionWidget()->abortCompletion();
02321 }
02322
02323 void KateView::forceCompletion( )
02324 {
02325 completionWidget()->execute();
02326 }
02327
02328 void KateView::registerCompletionModel(KTextEditor::CodeCompletionModel* model)
02329 {
02330 completionWidget()->registerCompletionModel(model);
02331 }
02332
02333 void KateView::unregisterCompletionModel(KTextEditor::CodeCompletionModel* model)
02334 {
02335 completionWidget()->unregisterCompletionModel(model);
02336 }
02337
02338 bool KateView::isAutomaticInvocationEnabled() const
02339 {
02340 return m_config->automaticCompletionInvocation();
02341 }
02342
02343 void KateView::setAutomaticInvocationEnabled(bool enabled)
02344 {
02345 config()->setAutomaticCompletionInvocation(enabled);
02346 }
02347
02348 void KateView::sendCompletionExecuted(const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, const QModelIndex& index)
02349 {
02350 emit completionExecuted(this, position, model, index);
02351 }
02352
02353 void KateView::sendCompletionAborted()
02354 {
02355 emit completionAborted(this);
02356 }
02357
02358 void KateView::paste( )
02359 {
02360 m_doc->paste( this );
02361 emit selectionChanged (this);
02362 m_viewInternal->repaint();
02363 }
02364
02365 bool KateView::setCursorPosition( KTextEditor::Cursor position )
02366 {
02367 return setCursorPositionInternal( position, 1, true );
02368 }
02369
02370 KTextEditor::Cursor KateView::cursorPosition( ) const
02371 {
02372 return m_viewInternal->getCursor();
02373 }
02374
02375 KTextEditor::Cursor KateView::cursorPositionVirtual( ) const
02376 {
02377 return KTextEditor::Cursor (m_viewInternal->getCursor().line(), virtualCursorColumn());
02378 }
02379
02380 QPoint KateView::cursorToCoordinate( const KTextEditor::Cursor & cursor ) const
02381 {
02382 return m_viewInternal->cursorToCoordinate(cursor);
02383 }
02384
02385 KTextEditor::Cursor KateView::coordinatesToCursor(const QPoint& coords) const
02386 {
02387 return m_viewInternal->coordinatesToCursor(coords);
02388 }
02389
02390 QPoint KateView::cursorPositionCoordinates( ) const
02391 {
02392 return m_viewInternal->cursorCoordinates();
02393 }
02394
02395 bool KateView::setCursorPositionVisual( const KTextEditor::Cursor & position )
02396 {
02397 return setCursorPositionInternal( position, m_doc->config()->tabWidth(), true );
02398 }
02399
02400 QString KateView::currentTextLine( )
02401 {
02402 return m_doc->line( cursorPosition().line() );
02403 }
02404
02405 QString KateView::currentWord( )
02406 {
02407 return m_doc->getWord( cursorPosition() );
02408 }
02409
02410 void KateView::indent( )
02411 {
02412 m_doc->indent( this, cursorPosition().line(), 1 );
02413 }
02414
02415 void KateView::unIndent( )
02416 {
02417 m_doc->indent( this, cursorPosition().line(), -1 );
02418 }
02419
02420 void KateView::cleanIndent( )
02421 {
02422 m_doc->indent( this, cursorPosition().line(), 0 );
02423 }
02424
02425 void KateView::align( )
02426 {
02427
02428 const int line = cursorPosition().line();
02429 KTextEditor::Range alignRange(KTextEditor::Cursor (line,0), KTextEditor::Cursor (line,0));
02430 if (selection()) {
02431 alignRange = selectionRange();
02432 }
02433
02434 m_doc->align( this, alignRange );
02435 }
02436
02437 void KateView::comment( )
02438 {
02439 m_doc->comment( this, cursorPosition().line(), cursorPosition().column(), 1 );
02440 }
02441
02442 void KateView::uncomment( )
02443 {
02444 m_doc->comment( this, cursorPosition().line(), cursorPosition().column(),-1 );
02445 }
02446
02447 void KateView::uppercase( )
02448 {
02449 m_doc->transform( this, m_viewInternal->m_cursor, KateDocument::Uppercase );
02450 }
02451
02452 void KateView::killLine( )
02453 {
02454 m_doc->removeLine( cursorPosition().line() );
02455 }
02456
02457 void KateView::lowercase( )
02458 {
02459 m_doc->transform( this, m_viewInternal->m_cursor, KateDocument::Lowercase );
02460 }
02461
02462 void KateView::capitalize( )
02463 {
02464 m_doc->editStart();
02465 m_doc->transform( this, m_viewInternal->m_cursor, KateDocument::Lowercase );
02466 m_doc->transform( this, m_viewInternal->m_cursor, KateDocument::Capitalize );
02467 m_doc->editEnd();
02468 }
02469
02470 void KateView::keyReturn( )
02471 {
02472 QMutexLocker l(m_doc->smartMutex());
02473 m_viewInternal->doReturn();
02474 }
02475
02476 void KateView::smartNewline( )
02477 {
02478 QMutexLocker l(m_doc->smartMutex());
02479 m_viewInternal->doSmartNewline();
02480 }
02481
02482 void KateView::backspace( )
02483 {
02484 QMutexLocker l(m_doc->smartMutex());
02485 m_viewInternal->doBackspace();
02486 }
02487
02488 void KateView::deleteWordLeft( )
02489 {
02490 QMutexLocker l(m_doc->smartMutex());
02491 m_viewInternal->doDeleteWordLeft();
02492 }
02493
02494 void KateView::keyDelete( )
02495 {
02496 QMutexLocker l(m_doc->smartMutex());
02497 m_viewInternal->doDelete();
02498 }
02499
02500 void KateView::deleteWordRight( )
02501 {
02502 QMutexLocker l(m_doc->smartMutex());
02503 m_viewInternal->doDeleteWordRight();
02504 }
02505
02506 void KateView::transpose( )
02507 {
02508 QMutexLocker l(m_doc->smartMutex());
02509 m_viewInternal->doTranspose();
02510 }
02511
02512 void KateView::cursorLeft( )
02513 {
02514 m_viewInternal->cursorLeft();
02515 }
02516
02517 void KateView::shiftCursorLeft( )
02518 {
02519 m_viewInternal->cursorLeft(true);
02520 }
02521
02522 void KateView::cursorRight( )
02523 {
02524 m_viewInternal->cursorRight();
02525 }
02526
02527 void KateView::shiftCursorRight( )
02528 {
02529 m_viewInternal->cursorRight(true);
02530 }
02531
02532 void KateView::wordLeft( )
02533 {
02534 QMutexLocker l(m_doc->smartMutex());
02535 m_viewInternal->wordLeft();
02536 }
02537
02538 void KateView::shiftWordLeft( )
02539 {
02540 QMutexLocker l(m_doc->smartMutex());
02541 m_viewInternal->wordLeft(true);
02542 }
02543
02544 void KateView::wordRight( )
02545 {
02546 QMutexLocker l(m_doc->smartMutex());
02547 m_viewInternal->wordRight();
02548 }
02549
02550 void KateView::shiftWordRight( )
02551 {
02552 QMutexLocker l(m_doc->smartMutex());
02553 m_viewInternal->wordRight(true);
02554 }
02555
02556 void KateView::home( )
02557 {
02558 QMutexLocker l(m_doc->smartMutex());
02559 m_viewInternal->home();
02560 }
02561
02562 void KateView::shiftHome( )
02563 {
02564 QMutexLocker l(m_doc->smartMutex());
02565 m_viewInternal->home(true);
02566 }
02567
02568 void KateView::end( )
02569 {
02570 m_viewInternal->end();
02571 }
02572
02573 void KateView::shiftEnd( )
02574 {
02575 m_viewInternal->end(true);
02576 }
02577
02578 void KateView::up( )
02579 {
02580 m_viewInternal->cursorUp();
02581 }
02582
02583 void KateView::shiftUp( )
02584 {
02585 m_viewInternal->cursorUp(true);
02586 }
02587
02588 void KateView::down( )
02589 {
02590 m_viewInternal->cursorDown();
02591 }
02592
02593 void KateView::shiftDown( )
02594 {
02595 m_viewInternal->cursorDown(true);
02596 }
02597
02598 void KateView::scrollUp( )
02599 {
02600 QMutexLocker l(m_doc->smartMutex());
02601 m_viewInternal->scrollUp();
02602 }
02603
02604 void KateView::scrollDown( )
02605 {
02606 QMutexLocker l(m_doc->smartMutex());
02607 m_viewInternal->scrollDown();
02608 }
02609
02610 void KateView::topOfView( )
02611 {
02612 QMutexLocker l(m_doc->smartMutex());
02613 m_viewInternal->topOfView();
02614 }
02615
02616 void KateView::shiftTopOfView( )
02617 {
02618 QMutexLocker l(m_doc->smartMutex());
02619 m_viewInternal->topOfView(true);
02620 }
02621
02622 void KateView::bottomOfView( )
02623 {
02624 QMutexLocker l(m_doc->smartMutex());
02625 m_viewInternal->bottomOfView();
02626 }
02627
02628 void KateView::shiftBottomOfView( )
02629 {
02630 QMutexLocker l(m_doc->smartMutex());
02631 m_viewInternal->bottomOfView(true);
02632 }
02633
02634 void KateView::pageUp( )
02635 {
02636 m_viewInternal->pageUp();
02637 }
02638
02639 void KateView::shiftPageUp( )
02640 {
02641 m_viewInternal->pageUp(true);
02642 }
02643
02644 void KateView::pageDown( )
02645 {
02646 m_viewInternal->pageDown();
02647 }
02648
02649 void KateView::shiftPageDown( )
02650 {
02651 m_viewInternal->pageDown(true);
02652 }
02653
02654 void KateView::top( )
02655 {
02656 m_viewInternal->top_home();
02657 }
02658
02659 void KateView::shiftTop( )
02660 {
02661 m_viewInternal->top_home(true);
02662 }
02663
02664 void KateView::bottom( )
02665 {
02666 m_viewInternal->bottom_end();
02667 }
02668
02669 void KateView::shiftBottom( )
02670 {
02671 m_viewInternal->bottom_end(true);
02672 }
02673
02674 void KateView::toMatchingBracket( )
02675 {
02676 QMutexLocker l(m_doc->smartMutex());
02677 m_viewInternal->cursorToMatchingBracket();
02678 }
02679
02680 void KateView::shiftToMatchingBracket( )
02681 {
02682 QMutexLocker l(m_doc->smartMutex());
02683 m_viewInternal->cursorToMatchingBracket(true);
02684 }
02685
02686 const KTextEditor::Range & KateView::selectionRange( ) const
02687 {
02688 QMutexLocker l(m_doc->smartMutex());
02689
02690 m_holdSelectionRangeForAPI = *m_selection;
02691
02692 return m_holdSelectionRangeForAPI;
02693 }
02694
02695 KTextEditor::Document * KateView::document( ) const
02696 {
02697 return m_doc;
02698 }
02699
02700 void KateView::setContextMenu( QMenu * menu )
02701 {
02702 if (m_contextMenu)
02703 disconnect(m_contextMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowContextMenu()));
02704
02705 m_contextMenu = menu;
02706
02707 if (m_contextMenu)
02708 connect(m_contextMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowContextMenu()));
02709 }
02710
02711 QMenu * KateView::contextMenu( ) const
02712 {
02713 return m_contextMenu;
02714 }
02715
02716 QMenu * KateView::defaultContextMenu(QMenu* menu) const
02717 {
02718 if (!menu)
02719 menu = new KMenu(const_cast<KateView*>(this));
02720
02721
02722 KXMLGUIClient* client = const_cast<KateView*>(this);
02723 while (client->parentClient())
02724 client = client->parentClient();
02725
02726 QWidget* popupwidget = 0;
02727 if (client->factory() && (popupwidget = client->factory()->container("ktexteditor_popup", client))) {
02728 menu->addActions(popupwidget->actions());
02729
02730 } else {
02731 kDebug( 13030 ) << "no ktexteditor_popup container found; populating manually";
02732 menu->addAction(m_editUndo);
02733 menu->addAction(m_editRedo);
02734 menu->addSeparator();
02735 menu->addAction(m_cut);
02736 menu->addAction(m_copy);
02737 menu->addAction(m_paste);
02738 menu->addSeparator();
02739 menu->addAction(m_selectAll);
02740 menu->addAction(m_deSelect);
02741 if (QAction* bookmark = actionCollection()->action("bookmarks")) {
02742 menu->addSeparator();
02743 menu->addAction(bookmark);
02744 }
02745 }
02746
02747 return menu;
02748 }
02749
02750 void KateView::aboutToShowContextMenu( )
02751 {
02752 QMenu* menu = qobject_cast<QMenu*>(sender());
02753 if (menu)
02754 emit contextMenuAboutToShow(this, menu);
02755 }
02756
02757
02758 QStringList KateView::configKeys() const
02759 {
02760 return QStringList() << "icon-bar" << "line-numbers" << "dynamic-word-wrap";
02761 }
02762
02763 QVariant KateView::configValue(const QString &key)
02764 {
02765 if (key == "icon-bar")
02766 return config()->iconBar();
02767 else if (key == "line-numbers")
02768 return config()->lineNumbers();
02769 else if (key == "dynamic-word-wrap")
02770 return config()->dynWordWrap();
02771
02772
02773 return QVariant();
02774 }
02775
02776 void KateView::setConfigValue(const QString &key, const QVariant &value)
02777 {
02778
02779
02780
02781 bool toggle = value.toBool();
02782
02783 if (key == "icon-bar")
02784 config()->setIconBar(toggle);
02785 else if (key == "line-numbers")
02786 config()->setLineNumbers(toggle);
02787 else if (key == "dynamic-word-wrap")
02788 config()->setDynWordWrap(toggle);
02789 }
02790
02791
02792
02793 void KateView::userInvokedCompletion()
02794 {
02795 completionWidget()->userInvokedCompletion();
02796 }
02797
02798 KateViewBar *KateView::viewBar() const
02799 {
02800 return m_bottomViewBar;
02801 }
02802
02803 KateCmdLine *KateView::cmdLine ()
02804 {
02805 if (!m_cmdLine) {
02806 m_cmdLine = new KateCmdLine (this, m_bottomViewBar);
02807 m_bottomViewBar->addBarWidget(m_cmdLine);
02808 }
02809
02810 return m_cmdLine;
02811 }
02812
02813 KateSearchBar *KateView::searchBar (bool initHintAsPower)
02814 {
02815 if (!m_searchBar) {
02816 m_searchBar = new KateSearchBar(initHintAsPower, this);
02817 m_bottomViewBar->addBarWidget(m_searchBar);
02818 }
02819 return m_searchBar;
02820 }
02821
02822 KateViModeBar *KateView::viModeBar()
02823 {
02824 if (!m_viModeBar) {
02825 m_viModeBar = new KateViModeBar(this);
02826 }
02827
02828 return m_viModeBar;
02829 }
02830
02831 KateGotoBar *KateView::gotoBar ()
02832 {
02833 if (!m_gotoBar) {
02834 m_gotoBar = new KateGotoBar (this);
02835 m_bottomViewBar->addBarWidget(m_gotoBar);
02836 }
02837
02838 return m_gotoBar;
02839 }
02840
02841 void KateView::setAnnotationModel( KTextEditor::AnnotationModel* model )
02842 {
02843 KTextEditor::AnnotationModel* oldmodel = m_annotationModel;
02844 m_annotationModel = model;
02845 m_viewInternal->m_leftBorder->annotationModelChanged(oldmodel, m_annotationModel);
02846 }
02847
02848 KTextEditor::AnnotationModel* KateView::annotationModel() const
02849 {
02850 return m_annotationModel;
02851 }
02852
02853 void KateView::setAnnotationBorderVisible( bool visible )
02854 {
02855 m_viewInternal->m_leftBorder->setAnnotationBorderOn( visible );
02856 }
02857
02858 bool KateView::isAnnotationBorderVisible() const
02859 {
02860 return m_viewInternal->m_leftBorder->annotationBorderOn();
02861 }
02862
02863
02864
02865