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