• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateview.cpp

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

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal