• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • document
katedocument.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4  Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
5  Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
6  Copyright (C) 2007 Mirko Stocker <me@misto.ch>
7  Copyright (C) 2009-2010 Michel Ludwig <michel.ludwig@kdemail.net>
8  Copyright (C) 2013 Gerald Senarclens de Grancy <oss@senarclens.eu>
9  Copyright (C) 2013 Andrey Matveyakin <a.matveyakin@gmail.com>
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License version 2 as published by the Free Software Foundation.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02111-13020, USA.
24 */
25 
26 //BEGIN includes
27 #include "katedocument.h"
28 #include "katedocument.moc"
29 #include "kateglobal.h"
30 #include "katedialogs.h"
31 #include "katehighlight.h"
32 #include "kateview.h"
33 #include "kateautoindent.h"
34 #include "katetextline.h"
35 #include "katedocumenthelpers.h"
36 #include "katehighlighthelpers.h"
37 #include "kateprinter.h"
38 #include "katerenderer.h"
39 #include "kateregexp.h"
40 #include "kateplaintextsearch.h"
41 #include "kateregexpsearch.h"
42 #include "kateconfig.h"
43 #include "katemodemanager.h"
44 #include "kateschema.h"
45 #include "katebuffer.h"
46 #include "kateundomanager.h"
47 #include "katepartpluginmanager.h"
48 #include "katevireplacemode.h"
49 #include "spellcheck/prefixstore.h"
50 #include "spellcheck/ontheflycheck.h"
51 #include "spellcheck/spellcheck.h"
52 #include "katescriptmanager.h"
53 #include "kateswapfile.h"
54 
55 #include "documentcursor.h"
56 
57 #include <ktexteditor/attribute.h>
58 #include <ktexteditor/plugin.h>
59 #include <ktexteditor/loadsavefiltercheckplugin.h>
60 
61 #include <kio/job.h>
62 #include <kio/jobuidelegate.h>
63 #include <kio/netaccess.h>
64 #include <kfileitem.h>
65 
66 #include <klocale.h>
67 #include <kglobal.h>
68 #include <kmenu.h>
69 #include <kconfig.h>
70 #include <kfiledialog.h>
71 #include <kmessagebox.h>
72 #include <kstandardaction.h>
73 #include <kxmlguifactory.h>
74 #include <kdebug.h>
75 #include <kglobalsettings.h>
76 #include <kdirwatch.h>
77 #include <kencodingfiledialog.h>
78 #include <kcodecs.h>
79 #include <kstandarddirs.h>
80 #include <kstringhandler.h>
81 
82 #include <kservicetypetrader.h>
83 
84 #include <QtDBus/QtDBus>
85 #include <QtGui/QApplication>
86 #include <QtCore/QTimer>
87 #include <QtCore/QFile>
88 #include <QtGui/QClipboard>
89 #include <QtCore/QTextStream>
90 #include <QtCore/QTextCodec>
91 #include <QtCore/QCryptographicHash>
92 #include <QtCore/QMap>
93 //END includes
94 
95 #if 0
96 #define EDIT_DEBUG kDebug()
97 #else
98 #define EDIT_DEBUG if (0) kDebug()
99 #endif
100 
101 static int dummy = 0;
102 
103 inline bool isStartBracket( const QChar& c ) { return c == '{' || c == '[' || c == '('; }
104 inline bool isEndBracket ( const QChar& c ) { return c == '}' || c == ']' || c == ')'; }
105 inline bool isBracket ( const QChar& c ) { return isStartBracket( c ) || isEndBracket( c ); }
106 
107 //BEGIN d'tor, c'tor
108 //
109 // KateDocument Constructor
110 //
111 KateDocument::KateDocument ( bool bSingleViewMode, bool bBrowserView,
112  bool bReadOnly, QWidget *parentWidget,
113  QObject *parent)
114 : KTextEditor::Document (parent),
115  m_bSingleViewMode(bSingleViewMode),
116  m_bBrowserView(bBrowserView),
117  m_bReadOnly(bReadOnly),
118  m_activeView(0),
119  editSessionNumber(0),
120  editIsRunning(false),
121  m_undoMergeAllEdits(false),
122  m_undoManager(new KateUndoManager(this)),
123  m_editableMarks(markType01),
124  m_annotationModel(0),
125  m_isasking(0),
126  m_buffer(new KateBuffer(this)),
127  m_indenter(new KateAutoIndent(this)),
128  m_hlSetByUser(false),
129  m_bomSetByUser(false),
130  m_indenterSetByUser(false),
131  m_userSetEncodingForNextReload(false),
132  m_modOnHd(false),
133  m_modOnHdReason(OnDiskUnmodified),
134  m_docName("need init"),
135  m_docNameNumber(0),
136  m_fileTypeSetByUser(false),
137  m_reloading(false),
138  m_config(new KateDocumentConfig(this)),
139  m_fileChangedDialogsActivated(false),
140  m_onTheFlyChecker(0),
141  m_documentState (DocumentIdle),
142  m_readWriteStateBeforeLoading (false),
143  m_isUntitled(true)
144 {
145  setComponentData ( KateGlobal::self()->componentData () );
146 
151  setProgressInfoEnabled (false);
152 
153  QString pathName ("/Kate/Document/%1");
154  pathName = pathName.arg (++dummy);
155 
156  // my dbus object
157  QDBusConnection::sessionBus().registerObject (pathName, this, QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableSlots);
158 
159  // register doc at factory
160  KateGlobal::self()->registerDocument(this);
161 
162  // normal hl
163  m_buffer->setHighlight (0);
164 
165  // swap file
166  m_swapfile = new Kate::SwapFile(this);
167 
168  new KateBrowserExtension( this ); // deleted by QObject memory management
169 
170  // important, fill in the config into the indenter we use...
171  m_indenter->updateConfig ();
172 
173  // some nice signals from the buffer
174  connect(m_buffer, SIGNAL(tagLines(int,int)), this, SLOT(tagLines(int,int)));
175 
176  // if the user changes the highlight with the dialog, notify the doc
177  connect(KateHlManager::self(),SIGNAL(changed()),SLOT(internalHlChanged()));
178 
179  // signals for mod on hd
180  connect( KateGlobal::self()->dirWatch(), SIGNAL(dirty(QString)),
181  this, SLOT(slotModOnHdDirty(QString)) );
182 
183  connect( KateGlobal::self()->dirWatch(), SIGNAL(created(QString)),
184  this, SLOT(slotModOnHdCreated(QString)) );
185 
186  connect( KateGlobal::self()->dirWatch(), SIGNAL(deleted(QString)),
187  this, SLOT(slotModOnHdDeleted(QString)) );
188 
194  connect (this, SIGNAL(started(KIO::Job*)), this, SLOT(slotStarted(KIO::Job*)));
195  connect (this, SIGNAL(completed()), this, SLOT(slotCompleted()));
196  connect (this, SIGNAL(canceled(QString)), this, SLOT(slotCanceled()));
197 
198  // update doc name
199  updateDocName ();
200 
201  // if single view mode, like in the konqui embedding, create a default view ;)
202  // be lazy, only create it now, if any parentWidget is given, otherwise widget()
203  // will create it on demand...
204  if ( m_bSingleViewMode && parentWidget )
205  {
206  KTextEditor::View *view = (KTextEditor::View*)createView( parentWidget );
207  insertChildClient( view );
208  view->show();
209  setWidget( view );
210  }
211 
212  connect(m_undoManager, SIGNAL(undoChanged()), this, SIGNAL(undoChanged()));
213  connect(m_undoManager, SIGNAL(undoStart(KTextEditor::Document*)), this, SIGNAL(exclusiveEditStart(KTextEditor::Document*)));
214  connect(m_undoManager, SIGNAL(undoEnd(KTextEditor::Document*)), this, SIGNAL(exclusiveEditEnd(KTextEditor::Document*)));
215  connect(m_undoManager, SIGNAL(redoStart(KTextEditor::Document*)), this, SIGNAL(exclusiveEditStart(KTextEditor::Document*)));
216  connect(m_undoManager, SIGNAL(redoEnd(KTextEditor::Document*)), this, SIGNAL(exclusiveEditEnd(KTextEditor::Document*)));
217 
218  connect(this,SIGNAL(sigQueryClose(bool*,bool*)),this,SLOT(slotQueryClose_save(bool*,bool*)));
219 
220  onTheFlySpellCheckingEnabled(config()->onTheFlySpellCheck());
221 
222  // register document in plugins
223  KatePartPluginManager::self()->addDocument(this);
224 }
225 
226 //
227 // KateDocument Destructor
228 //
229 KateDocument::~KateDocument()
230 {
234  emit aboutToDeleteMovingInterfaceContent (this);
235 
236  // kill it early, it has ranges!
237  delete m_onTheFlyChecker;
238  m_onTheFlyChecker = NULL;
239 
240  clearDictionaryRanges();
241 
242  // Tell the world that we're about to close (== destruct)
243  // Apps must receive this in a direct signal-slot connection, and prevent
244  // any further use of interfaces once they return.
245  emit aboutToClose(this);
246 
247  // remove file from dirwatch
248  deactivateDirWatch ();
249 
250  // thanks for offering, KPart, but we're already self-destructing
251  setAutoDeleteWidget(false);
252  setAutoDeletePart(false);
253 
254  // clean up remaining views
255  while (!m_views.isEmpty()) {
256  delete m_views.takeFirst();
257  }
258 
259  // de-register from plugin
260  KatePartPluginManager::self()->removeDocument(this);
261 
262  // cu marks
263  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
264  delete i.value();
265  m_marks.clear();
266 
267  delete m_config;
268  KateGlobal::self()->deregisterDocument (this);
269 }
270 //END
271 
272 // on-demand view creation
273 QWidget *KateDocument::widget()
274 {
275  // no singleViewMode -> no widget()...
276  if (!singleViewMode())
277  return 0;
278 
279  // does a widget exist already? use it!
280  if (KTextEditor::Document::widget())
281  return KTextEditor::Document::widget();
282 
283  // create and return one...
284  KTextEditor::View *view = (KTextEditor::View*)createView(0);
285  insertChildClient( view );
286  setWidget( view );
287  return view;
288 }
289 
290 //BEGIN KTextEditor::Document stuff
291 
292 KTextEditor::View *KateDocument::createView( QWidget *parent )
293 {
294  KateView* newView = new KateView( this, parent);
295  if ( m_fileChangedDialogsActivated )
296  connect( newView, SIGNAL(focusIn(KTextEditor::View*)), this, SLOT(slotModifiedOnDisk()) );
297 
298  emit viewCreated (this, newView);
299 
300  // post existing messages to the new view, if no specific view is given
301  foreach (KTextEditor::Message *message, m_messageHash.keys()) {
302  if (!message->view())
303  newView->postMessage(message, m_messageHash[message]);
304  }
305 
306  return newView;
307 }
308 
309 const QList<KTextEditor::View*> &KateDocument::views () const
310 {
311  return m_textEditViews;
312 }
313 
314 KTextEditor::Editor *KateDocument::editor ()
315 {
316  return KateGlobal::self();
317 }
318 
319 KTextEditor::Range KateDocument::rangeOnLine(KTextEditor::Range range, int line) const
320 {
321  int col1 = toVirtualColumn(range.start());
322  int col2 = toVirtualColumn(range.end());
323 
324  col1 = fromVirtualColumn(line, col1);
325  col2 = fromVirtualColumn(line, col2);
326 
327  return KTextEditor::Range(line, col1, line, col2);
328 }
329 
330 //BEGIN KTextEditor::EditInterface stuff
331 
332 QString KateDocument::text() const
333 {
334  return m_buffer->text ();
335 }
336 
337 QString KateDocument::text( const KTextEditor::Range& range, bool blockwise ) const
338 {
339  if (!range.isValid()) {
340  kWarning() << k_funcinfo << "Text requested for invalid range" << range;
341  return QString();
342  }
343 
344  QString s;
345 
346  if (range.start().line() == range.end().line())
347  {
348  if (range.start().column() > range.end().column())
349  return QString ();
350 
351  Kate::TextLine textLine = m_buffer->plainLine(range.start().line());
352 
353  if ( !textLine )
354  return QString ();
355 
356  return textLine->string(range.start().column(), range.end().column()-range.start().column());
357  }
358  else
359  {
360 
361  for (int i = range.start().line(); (i <= range.end().line()) && (i < m_buffer->count()); ++i)
362  {
363  Kate::TextLine textLine = m_buffer->plainLine(i);
364 
365  if ( !blockwise )
366  {
367  if (i == range.start().line())
368  s.append (textLine->string(range.start().column(), textLine->length()-range.start().column()));
369  else if (i == range.end().line())
370  s.append (textLine->string(0, range.end().column()));
371  else
372  s.append (textLine->string());
373  }
374  else
375  {
376  KTextEditor::Range subRange = rangeOnLine(range, i);
377  s.append(textLine->string(subRange.start().column(), subRange.columnWidth()));
378  }
379 
380  if ( i < range.end().line() )
381  s.append(QChar::fromAscii('\n'));
382  }
383  }
384 
385  return s;
386 }
387 
388 QChar KateDocument::character( const KTextEditor::Cursor & position ) const
389 {
390  Kate::TextLine textLine = m_buffer->plainLine(position.line());
391 
392  if ( !textLine )
393  return QChar();
394 
395  return textLine->at(position.column());
396 }
397 
398 QStringList KateDocument::textLines( const KTextEditor::Range & range, bool blockwise ) const
399 {
400  QStringList ret;
401 
402  if (!range.isValid()) {
403  kWarning() << k_funcinfo << "Text requested for invalid range" << range;
404  return ret;
405  }
406 
407  if ( blockwise && (range.start().column() > range.end().column()) )
408  return ret;
409 
410  if (range.start().line() == range.end().line())
411  {
412  Q_ASSERT(range.start() <= range.end());
413 
414  Kate::TextLine textLine = m_buffer->plainLine(range.start().line());
415 
416  if ( !textLine )
417  return ret;
418 
419  ret << textLine->string(range.start().column(), range.end().column() - range.start().column());
420  }
421  else
422  {
423  for (int i = range.start().line(); (i <= range.end().line()) && (i < m_buffer->count()); ++i)
424  {
425  Kate::TextLine textLine = m_buffer->plainLine(i);
426 
427  if ( !blockwise )
428  {
429  if (i == range.start().line())
430  ret << textLine->string(range.start().column(), textLine->length() - range.start().column());
431  else if (i == range.end().line())
432  ret << textLine->string(0, range.end().column());
433  else
434  ret << textLine->string();
435  }
436  else
437  {
438  KTextEditor::Range subRange = rangeOnLine(range, i);
439  ret << textLine->string(subRange.start().column(), subRange.columnWidth());
440  }
441  }
442  }
443 
444  return ret;
445 }
446 
447 QString KateDocument::line( int line ) const
448 {
449  Kate::TextLine l = m_buffer->plainLine(line);
450 
451  if (!l)
452  return QString();
453 
454  return l->string();
455 }
456 
457 bool KateDocument::setText(const QString &s)
458 {
459  if (!isReadWrite())
460  return false;
461 
462  QList<KTextEditor::Mark> msave;
463 
464  foreach (KTextEditor::Mark* mark, m_marks)
465  msave.append(*mark);
466 
467  editStart ();
468 
469  // delete the text
470  clear();
471 
472  // insert the new text
473  insertText (KTextEditor::Cursor(), s);
474 
475  editEnd ();
476 
477  foreach (const KTextEditor::Mark& mark, msave)
478  setMark (mark.line, mark.type);
479 
480  return true;
481 }
482 
483 bool KateDocument::setText( const QStringList & text )
484 {
485  if (!isReadWrite())
486  return false;
487 
488  QList<KTextEditor::Mark> msave;
489 
490  foreach (KTextEditor::Mark* mark, m_marks)
491  msave.append(*mark);
492 
493  editStart ();
494 
495  // delete the text
496  clear();
497 
498  // insert the new text
499  insertText (KTextEditor::Cursor::start(), text);
500 
501  editEnd ();
502 
503  foreach (const KTextEditor::Mark& mark, msave)
504  setMark (mark.line, mark.type);
505 
506  return true;
507 }
508 
509 bool KateDocument::clear()
510 {
511  if (!isReadWrite())
512  return false;
513 
514  foreach (KateView *view, m_views) {
515  view->clear();
516  view->tagAll();
517  view->update();
518  }
519 
520  clearMarks ();
521 
522  emit aboutToInvalidateMovingInterfaceContent(this);
523  m_buffer->invalidateRanges();
524 
525  emit aboutToRemoveText(documentRange());
526 
527  return editRemoveLines(0, lastLine());
528 }
529 
530 bool KateDocument::insertText( const KTextEditor::Cursor& position, const QString& text, bool block )
531 {
532  if (!isReadWrite())
533  return false;
534 
535  if (text.isEmpty())
536  return true;
537 
538  editStart();
539 
540  int currentLine = position.line();
541  int currentLineStart = 0;
542  int totalLength = text.length();
543  int insertColumn = position.column();
544 
545  if (position.line() > lines())
546  {
547  int line = lines();
548  while (line != position.line() + totalLength + 1)
549  {
550  editInsertLine(line,QString());
551  line++;
552  }
553  }
554 
555  bool replacetabs = ( config()->replaceTabsDyn() );
556  int tabWidth = config()->tabWidth();
557 
558  static const QChar newLineChar('\n');
559  static const QChar tabChar('\t');
560  static const QChar spaceChar(' ');
561 
562  int insertColumnExpanded = insertColumn;
563  Kate::TextLine l = plainKateTextLine( currentLine );
564  if (l)
565  insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
566  int positionColumnExpanded = insertColumnExpanded;
567 
568  int pos = 0;
569  for (; pos < totalLength; pos++)
570  {
571  const QChar& ch = text.at(pos);
572 
573  if (ch == newLineChar)
574  {
575  // Only perform the text insert if there is text to insert
576  if (currentLineStart < pos)
577  editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart));
578 
579  if ( !block )
580  {
581  editWrapLine(currentLine, insertColumn + pos - currentLineStart);
582  insertColumn = 0;
583  }
584 
585  currentLine++;
586  l = plainKateTextLine( currentLine );
587 
588  if ( block )
589  {
590  if ( currentLine == lastLine() + 1 )
591  editInsertLine(currentLine, QString());
592  insertColumn = positionColumnExpanded;
593  if (l)
594  insertColumn = l->fromVirtualColumn( insertColumn, tabWidth );
595  }
596 
597  currentLineStart = pos + 1;
598  if (l)
599  insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
600  }
601  else
602  {
603  if ( replacetabs && ch == tabChar )
604  {
605  int spacesRequired = tabWidth - ( (insertColumnExpanded + pos - currentLineStart) % tabWidth );
606  editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart) + QString(spacesRequired, spaceChar));
607 
608  insertColumn += pos - currentLineStart + spacesRequired;
609  currentLineStart = pos + 1;
610  if (l)
611  insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
612  }
613  }
614  }
615 
616  // Only perform the text insert if there is text to insert
617  if (currentLineStart < pos)
618  editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart));
619 
620  editEnd();
621  return true;
622 }
623 
624 bool KateDocument::insertText( const KTextEditor::Cursor & position, const QStringList & textLines, bool block )
625 {
626  if (!isReadWrite())
627  return false;
628 
629  // just reuse normal function
630  return insertText (position, textLines.join ("\n"), block);
631 }
632 
633 bool KateDocument::removeText ( const KTextEditor::Range &_range, bool block )
634 {
635  KTextEditor::Range range = _range;
636 
637  if (!isReadWrite())
638  return false;
639 
640  // Should now be impossible to trigger with the new Range class
641  Q_ASSERT( range.start().line() <= range.end().line() );
642 
643  if ( range.start().line() > lastLine() )
644  return false;
645 
646  if (!block)
647  emit aboutToRemoveText(range);
648 
649  editStart();
650 
651  if ( !block )
652  {
653  if ( range.end().line() > lastLine() )
654  {
655  range.end().setPosition(lastLine()+1, 0);
656  }
657 
658  if (range.onSingleLine())
659  {
660  editRemoveText(range.start().line(), range.start().column(), range.columnWidth());
661  }
662  else
663  {
664  int from = range.start().line();
665  int to = range.end().line();
666 
667  // remove last line
668  if (to <= lastLine())
669  editRemoveText(to, 0, range.end().column());
670 
671  // editRemoveLines() will be called on first line (to remove bookmark)
672  if (range.start().column() == 0 && from > 0)
673  --from;
674 
675  // remove middle lines
676  editRemoveLines(from+1, to-1);
677 
678  // remove first line if not already removed by editRemoveLines()
679  if (range.start().column() > 0 || range.start().line() == 0) {
680  editRemoveText(from, range.start().column(), m_buffer->plainLine(from)->length() - range.start().column());
681  editUnWrapLine(from);
682  }
683  }
684  } // if ( ! block )
685  else
686  {
687  int startLine = qMax(0, range.start().line());
688  int vc1 = toVirtualColumn(range.start());
689  int vc2 = toVirtualColumn(range.end());
690  for (int line = qMin(range.end().line(), lastLine()); line >= startLine; --line) {
691  int col1 = fromVirtualColumn(line, vc1);
692  int col2 = fromVirtualColumn(line, vc2);
693  editRemoveText(line, qMin(col1, col2), qAbs(col2 - col1));
694  }
695  }
696 
697  editEnd ();
698  return true;
699 }
700 
701 bool KateDocument::insertLine( int l, const QString &str )
702 {
703  if (!isReadWrite())
704  return false;
705 
706  if (l < 0 || l > lines())
707  return false;
708 
709  return editInsertLine (l, str);
710 }
711 
712 bool KateDocument::insertLines( int line, const QStringList & text )
713 {
714  if (!isReadWrite())
715  return false;
716 
717  if (line < 0 || line > lines())
718  return false;
719 
720  bool success = true;
721  foreach (const QString &string, text)
722  success &= editInsertLine (line++, string);
723 
724  return success;
725 }
726 
727 bool KateDocument::removeLine( int line )
728 {
729  if (!isReadWrite())
730  return false;
731 
732  if (line < 0 || line > lastLine())
733  return false;
734 
735  return editRemoveLine (line);
736 }
737 
738 int KateDocument::totalCharacters() const
739 {
740  int l = 0;
741 
742  for (int i = 0; i < m_buffer->count(); ++i)
743  {
744  Kate::TextLine line = m_buffer->plainLine(i);
745 
746  if (line)
747  l += line->length();
748  }
749 
750  return l;
751 }
752 
753 int KateDocument::lines() const
754 {
755  return m_buffer->count();
756 }
757 
758 int KateDocument::lineLength ( int line ) const
759 {
760  if (line < 0 || line > lastLine())
761  return -1;
762 
763  Kate::TextLine l = m_buffer->plainLine(line);
764 
765  if (!l)
766  return -1;
767 
768  return l->length();
769 }
770 //END
771 
772 //BEGIN KTextEditor::EditInterface internal stuff
773 //
774 // Starts an edit session with (or without) undo, update of view disabled during session
775 //
776 void KateDocument::editStart ()
777 {
778  editSessionNumber++;
779 
780  if (editSessionNumber > 1)
781  return;
782 
783  editIsRunning = true;
784 
785  m_undoManager->editStart();
786 
787  foreach(KateView *view,m_views)
788  view->editStart ();
789 
790  m_buffer->editStart ();
791 }
792 
793 //
794 // End edit session and update Views
795 //
796 void KateDocument::editEnd ()
797 {
798  if (editSessionNumber == 0) {
799  Q_ASSERT(0);
800  return;
801  }
802 
803  // wrap the new/changed text, if something really changed!
804  if (m_buffer->editChanged() && (editSessionNumber == 1))
805  if (m_undoManager->isActive() && config()->wordWrap())
806  wrapText (m_buffer->editTagStart(), m_buffer->editTagEnd());
807 
808  editSessionNumber--;
809 
810  if (editSessionNumber > 0)
811  return;
812 
813  // end buffer edit, will trigger hl update
814  // this will cause some possible adjustment of tagline start/end
815  m_buffer->editEnd ();
816 
817  m_undoManager->editEnd();
818 
819  // edit end for all views !!!!!!!!!
820  foreach(KateView *view, m_views)
821  view->editEnd (m_buffer->editTagStart(), m_buffer->editTagEnd(), m_buffer->editTagFrom());
822 
823  if (m_buffer->editChanged()) {
824  setModified(true);
825  emit textChanged (this);
826  }
827 
828  editIsRunning = false;
829 }
830 
831 void KateDocument::pushEditState ()
832 {
833  editStateStack.push(editSessionNumber);
834 }
835 
836 void KateDocument::popEditState ()
837 {
838  if (editStateStack.isEmpty()) return;
839 
840  int count = editStateStack.pop() - editSessionNumber;
841  while (count < 0) { ++count; editEnd(); }
842  while (count > 0) { --count; editStart(); }
843 }
844 
845 void KateDocument::inputMethodStart()
846 {
847  m_undoManager->inputMethodStart();
848 }
849 
850 void KateDocument::inputMethodEnd()
851 {
852  m_undoManager->inputMethodEnd();
853 }
854 
855 bool KateDocument::wrapText(int startLine, int endLine)
856 {
857  if (startLine < 0 || endLine < 0)
858  return false;
859 
860  if (!isReadWrite())
861  return false;
862 
863  int col = config()->wordWrapAt();
864 
865  if (col == 0)
866  return false;
867 
868  editStart ();
869 
870  for (int line = startLine; (line <= endLine) && (line < lines()); line++)
871  {
872  Kate::TextLine l = kateTextLine(line);
873 
874  if (!l)
875  break;
876 
877  //kDebug (13020) << "try wrap line: " << line;
878 
879  if (l->virtualLength(m_buffer->tabWidth()) > col)
880  {
881  Kate::TextLine nextl = kateTextLine(line+1);
882 
883  //kDebug (13020) << "do wrap line: " << line;
884 
885  int eolPosition = l->length()-1;
886 
887  // take tabs into account here, too
888  int x = 0;
889  const QString & t = l->string();
890  int z2 = 0;
891  for ( ; z2 < l->length(); z2++)
892  {
893  static const QChar tabChar('\t');
894  if (t.at(z2) == tabChar)
895  x += m_buffer->tabWidth() - (x % m_buffer->tabWidth());
896  else
897  x++;
898 
899  if (x > col)
900  break;
901  }
902 
903  const int colInChars = qMin (z2, l->length()-1);
904  int searchStart = colInChars;
905 
906  // If where we are wrapping is an end of line and is a space we don't
907  // want to wrap there
908  if (searchStart == eolPosition && t.at(searchStart).isSpace())
909  searchStart--;
910 
911  // Scan backwards looking for a place to break the line
912  // We are not interested in breaking at the first char
913  // of the line (if it is a space), but we are at the second
914  // anders: if we can't find a space, try breaking on a word
915  // boundary, using KateHighlight::canBreakAt().
916  // This could be a priority (setting) in the hl/filetype/document
917  int z = -1;
918  int nw = -1; // alternative position, a non word character
919  for (z=searchStart; z >= 0; z--)
920  {
921  if (t.at(z).isSpace()) break;
922  if ( (nw < 0) && highlight()->canBreakAt( t.at(z) , l->attribute(z) ) )
923  nw = z;
924  }
925 
926  if (z >= 0)
927  {
928  // So why don't we just remove the trailing space right away?
929  // Well, the (view's) cursor may be directly in front of that space
930  // (user typing text before the last word on the line), and if that
931  // happens, the cursor would be moved to the next line, which is not
932  // what we want (bug #106261)
933  z++;
934  }
935  else
936  {
937  // There was no space to break at so break at a nonword character if
938  // found, or at the wrapcolumn ( that needs be configurable )
939  // Don't try and add any white space for the break
940  if ( (nw >= 0) && nw < colInChars ) nw++; // break on the right side of the character
941  z = (nw >= 0) ? nw : colInChars;
942  }
943 
944  if (nextl && !nextl->isAutoWrapped())
945  {
946  editWrapLine (line, z, true);
947  editMarkLineAutoWrapped (line+1, true);
948 
949  endLine++;
950  }
951  else
952  {
953  if (nextl && (nextl->length() > 0) && !nextl->at(0).isSpace() && ((l->length() < 1) || !l->at(l->length()-1).isSpace()))
954  editInsertText (line+1, 0, QString (" "));
955 
956  bool newLineAdded = false;
957  editWrapLine (line, z, false, &newLineAdded);
958 
959  editMarkLineAutoWrapped (line+1, true);
960 
961  endLine++;
962  }
963  }
964  }
965 
966  editEnd ();
967 
968  return true;
969 }
970 
971 bool KateDocument::editInsertText ( int line, int col, const QString &s )
972 {
973  // verbose debug
974  EDIT_DEBUG << "editInsertText" << line << col << s;
975 
976  if (line < 0 || col < 0)
977  return false;
978 
979  if (!isReadWrite())
980  return false;
981 
982  Kate::TextLine l = kateTextLine(line);
983 
984  if (!l)
985  return false;
986 
987  // nothing to do, do nothing!
988  if (s.isEmpty())
989  return true;
990 
991  editStart ();
992 
993  QString s2 = s;
994  int col2 = col;
995  if (col2 > l->length()) {
996  s2 = QString(col2 - l->length(), QLatin1Char(' ')) + s;
997  col2 = l->length();
998  }
999 
1000  m_undoManager->slotTextInserted(line, col2, s2);
1001 
1002  // insert text into line
1003  m_buffer->insertText (KTextEditor::Cursor (line, col2), s2);
1004 
1005  emit KTextEditor::Document::textInserted(this, KTextEditor::Range(line, col2, line, col2 + s2.length()));
1006 
1007  editEnd();
1008 
1009  return true;
1010 }
1011 
1012 bool KateDocument::editRemoveText ( int line, int col, int len )
1013 {
1014  // verbose debug
1015  EDIT_DEBUG << "editRemoveText" << line << col << len;
1016 
1017  if (line < 0 || col < 0 || len < 0)
1018  return false;
1019 
1020  if (!isReadWrite())
1021  return false;
1022 
1023  Kate::TextLine l = kateTextLine(line);
1024 
1025  if (!l)
1026  return false;
1027 
1028  // nothing to do, do nothing!
1029  if (len == 0)
1030  return true;
1031 
1032  // wrong column
1033  if (col >= l->text().size())
1034  return false;
1035 
1036  // don't try to remove what's not there
1037  len = qMin(len, l->text().size() - col);
1038 
1039  editStart ();
1040 
1041  QString oldText = l->string().mid(col, len);
1042 
1043  m_undoManager->slotTextRemoved(line, col, oldText);
1044 
1045  // remove text from line
1046  m_buffer->removeText (KTextEditor::Range (KTextEditor::Cursor (line, col), KTextEditor::Cursor (line, col+len)));
1047 
1048  emit KTextEditor::Document::textRemoved(this, KTextEditor::Range(line, col, line, col + len));
1049  emit KTextEditor::Document::textRemoved(this, KTextEditor::Range(line, col, line, col + len), oldText);
1050 
1051  editEnd ();
1052 
1053  return true;
1054 }
1055 
1056 bool KateDocument::editMarkLineAutoWrapped ( int line, bool autowrapped )
1057 {
1058  // verbose debug
1059  EDIT_DEBUG << "editMarkLineAutoWrapped" << line << autowrapped;
1060 
1061  if (line < 0)
1062  return false;
1063 
1064  if (!isReadWrite())
1065  return false;
1066 
1067  Kate::TextLine l = kateTextLine(line);
1068 
1069  if (!l)
1070  return false;
1071 
1072  editStart ();
1073 
1074  m_undoManager->slotMarkLineAutoWrapped(line, autowrapped);
1075 
1076  l->setAutoWrapped (autowrapped);
1077 
1078  editEnd ();
1079 
1080  return true;
1081 }
1082 
1083 bool KateDocument::editWrapLine ( int line, int col, bool newLine, bool *newLineAdded)
1084 {
1085  // verbose debug
1086  EDIT_DEBUG << "editWrapLine" << line << col << newLine;
1087 
1088  if (line < 0 || col < 0)
1089  return false;
1090 
1091  if (!isReadWrite())
1092  return false;
1093 
1094  Kate::TextLine l = kateTextLine(line);
1095 
1096  if (!l)
1097  return false;
1098 
1099  editStart ();
1100 
1101  Kate::TextLine nextLine = kateTextLine(line+1);
1102 
1103  const int length = l->length();
1104  m_undoManager->slotLineWrapped(line, col, length - col, (!nextLine || newLine));
1105 
1106  if (!nextLine || newLine)
1107  {
1108  m_buffer->wrapLine (KTextEditor::Cursor (line, col));
1109 
1110  QList<KTextEditor::Mark*> list;
1111  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
1112  {
1113  if( i.value()->line >= line )
1114  {
1115  if ((col == 0) || (i.value()->line > line))
1116  list.append( i.value() );
1117  }
1118  }
1119 
1120  for( int i=0; i < list.size(); ++i )
1121  m_marks.take( list.at(i)->line );
1122 
1123  for( int i=0; i < list.size(); ++i )
1124  {
1125  list.at(i)->line++;
1126  m_marks.insert( list.at(i)->line, list.at(i) );
1127  }
1128 
1129  if( !list.isEmpty() )
1130  emit marksChanged( this );
1131 
1132  // yes, we added a new line !
1133  if (newLineAdded)
1134  (*newLineAdded) = true;
1135  }
1136  else
1137  {
1138  m_buffer->wrapLine (KTextEditor::Cursor (line, col));
1139  m_buffer->unwrapLine (line + 2);
1140 
1141  // no, no new line added !
1142  if (newLineAdded)
1143  (*newLineAdded) = false;
1144  }
1145 
1146  emit KTextEditor::Document::textInserted(this, KTextEditor::Range(line, col, line+1, 0));
1147 
1148  editEnd ();
1149 
1150  return true;
1151 }
1152 
1153 bool KateDocument::editUnWrapLine ( int line, bool removeLine, int length )
1154 {
1155  // verbose debug
1156  EDIT_DEBUG << "editUnWrapLine" << line << removeLine << length;
1157 
1158  if (line < 0 || length < 0)
1159  return false;
1160 
1161  if (!isReadWrite())
1162  return false;
1163 
1164  Kate::TextLine l = kateTextLine(line);
1165  Kate::TextLine nextLine = kateTextLine(line+1);
1166 
1167  if (!l || !nextLine)
1168  return false;
1169 
1170  editStart ();
1171 
1172  int col = l->length ();
1173 
1174  m_undoManager->slotLineUnWrapped(line, col, length, removeLine);
1175 
1176  if (removeLine)
1177  {
1178  m_buffer->unwrapLine (line+1);
1179  }
1180  else
1181  {
1182  m_buffer->wrapLine (KTextEditor::Cursor (line + 1, length));
1183  m_buffer->unwrapLine (line + 1);
1184  }
1185 
1186  QList<KTextEditor::Mark*> list;
1187  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
1188  {
1189  if( i.value()->line >= line+1 )
1190  list.append( i.value() );
1191 
1192  if ( i.value()->line == line+1 )
1193  {
1194  KTextEditor::Mark* mark = m_marks.take( line );
1195 
1196  if (mark)
1197  {
1198  i.value()->type |= mark->type;
1199  }
1200  }
1201  }
1202 
1203  for( int i=0; i < list.size(); ++i )
1204  m_marks.take( list.at(i)->line );
1205 
1206  for( int i=0; i < list.size(); ++i )
1207  {
1208  list.at(i)->line--;
1209  m_marks.insert( list.at(i)->line, list.at(i) );
1210  }
1211 
1212  if( !list.isEmpty() )
1213  emit marksChanged( this );
1214 
1215  emit KTextEditor::Document::textRemoved(this, KTextEditor::Range(line, col, line+1, 0));
1216  emit KTextEditor::Document::textRemoved(this, KTextEditor::Range(line, col, line+1, 0), "\n");
1217 
1218  editEnd ();
1219 
1220  return true;
1221 }
1222 
1223 bool KateDocument::editInsertLine ( int line, const QString &s )
1224 {
1225  // verbose debug
1226  EDIT_DEBUG << "editInsertLine" << line << s;
1227 
1228  if (line < 0)
1229  return false;
1230 
1231  if (!isReadWrite())
1232  return false;
1233 
1234  if ( line > lines() )
1235  return false;
1236 
1237  editStart ();
1238 
1239  m_undoManager->slotLineInserted(line, s);
1240 
1241  // wrap line
1242  if (line > 0) {
1243  Kate::TextLine previousLine = m_buffer->line (line-1);
1244  m_buffer->wrapLine (KTextEditor::Cursor (line-1, previousLine->text().size()));
1245  } else {
1246  m_buffer->wrapLine (KTextEditor::Cursor (0, 0));
1247  }
1248 
1249  // insert text
1250  m_buffer->insertText (KTextEditor::Cursor (line, 0), s);
1251 
1252  Kate::TextLine tl = m_buffer->line (line);
1253 
1254  QList<KTextEditor::Mark*> list;
1255  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
1256  {
1257  if( i.value()->line >= line )
1258  list.append( i.value() );
1259  }
1260 
1261  for( int i=0; i < list.size(); ++i )
1262  m_marks.take( list.at(i)->line );
1263 
1264  for( int i=0; i < list.size(); ++i )
1265  {
1266  list.at(i)->line++;
1267  m_marks.insert( list.at(i)->line, list.at(i) );
1268  }
1269 
1270  if( !list.isEmpty() )
1271  emit marksChanged( this );
1272 
1273  KTextEditor::Range rangeInserted(line, 0, line, tl->length());
1274 
1275  if (line) {
1276  Kate::TextLine prevLine = plainKateTextLine(line - 1);
1277  rangeInserted.start().setPosition(line - 1, prevLine->length());
1278  } else {
1279  rangeInserted.end().setPosition(line + 1, 0);
1280  }
1281 
1282  emit KTextEditor::Document::textInserted(this, rangeInserted);
1283 
1284  editEnd ();
1285 
1286  return true;
1287 }
1288 
1289 bool KateDocument::editRemoveLine ( int line )
1290 {
1291  return editRemoveLines(line, line);
1292 }
1293 
1294 bool KateDocument::editRemoveLines ( int from, int to )
1295 {
1296  // verbose debug
1297  EDIT_DEBUG << "editRemoveLines" << from << to;
1298 
1299  if (to < from || from < 0 || to > lastLine())
1300  return false;
1301 
1302  if (!isReadWrite())
1303  return false;
1304 
1305  if (lines() == 1)
1306  return editRemoveText(0, 0, kateTextLine(0)->length());
1307 
1308  editStart();
1309  QStringList oldText;
1310 
1311  for (int line = to; line >= from; line--) {
1312  Kate::TextLine tl = m_buffer->line (line);
1313  oldText.prepend(this->line(line));
1314  m_undoManager->slotLineRemoved(line, this->line(line));
1315 
1316  m_buffer->removeText (KTextEditor::Range (KTextEditor::Cursor (line, 0), KTextEditor::Cursor (line, tl->text().size())));
1317  }
1318 
1319  m_buffer->unwrapLines(from, to);
1320 
1321  QList<int> rmark;
1322  QList<int> list;
1323 
1324  foreach (KTextEditor::Mark* mark, m_marks) {
1325  int line = mark->line;
1326  if (line > to)
1327  list << line;
1328  else if (line >= from)
1329  rmark << line;
1330  }
1331 
1332  foreach (int line, rmark)
1333  delete m_marks.take(line);
1334 
1335  foreach (int line, list)
1336  {
1337  KTextEditor::Mark* mark = m_marks.take(line);
1338  mark->line -= to - from + 1;
1339  m_marks.insert(mark->line, mark);
1340  }
1341 
1342  if (!list.isEmpty())
1343  emit marksChanged(this);
1344 
1345  KTextEditor::Range rangeRemoved(from, 0, to + 1, 0);
1346 
1347  if (to == lastLine() + to - from + 1) {
1348  rangeRemoved.end().setPosition(to, oldText.last().length());
1349  if (from > 0) {
1350  Kate::TextLine prevLine = plainKateTextLine(from - 1);
1351  rangeRemoved.start().setPosition(from - 1, prevLine->length());
1352  }
1353  }
1354 
1355  emit KTextEditor::Document::textRemoved(this, rangeRemoved);
1356  emit KTextEditor::Document::textRemoved(this, rangeRemoved, oldText.join("\n") + '\n');
1357 
1358  editEnd();
1359 
1360  return true;
1361 }
1362 //END
1363 
1364 //BEGIN KTextEditor::UndoInterface stuff
1365 uint KateDocument::undoCount () const
1366 {
1367  return m_undoManager->undoCount ();
1368 }
1369 
1370 uint KateDocument::redoCount () const
1371 {
1372  return m_undoManager->redoCount ();
1373 }
1374 
1375 void KateDocument::undo()
1376 {
1377  m_undoManager->undo();
1378 }
1379 
1380 void KateDocument::redo()
1381 {
1382  m_undoManager->redo();
1383 }
1384 //END
1385 
1386 //BEGIN KTextEditor::SearchInterface stuff
1387 QVector<KTextEditor::Range> KateDocument::searchText(
1388  const KTextEditor::Range & range,
1389  const QString & pattern,
1390  const KTextEditor::Search::SearchOptions options)
1391 {
1392  // TODO
1393  // * support BlockInputRange
1394  // * support DotMatchesNewline
1395 
1396  const bool escapeSequences = options.testFlag(KTextEditor::Search::EscapeSequences);
1397  const bool regexMode = options.testFlag(KTextEditor::Search::Regex);
1398  const bool backwards = options.testFlag(KTextEditor::Search::Backwards);
1399  const bool wholeWords = options.testFlag(KTextEditor::Search::WholeWords);
1400  const Qt::CaseSensitivity caseSensitivity = options.testFlag(KTextEditor::Search::CaseInsensitive) ? Qt::CaseInsensitive : Qt::CaseSensitive;
1401 
1402  if (regexMode)
1403  {
1404  // regexp search
1405  // escape sequences are supported by definition
1406  KateRegExpSearch searcher(this, caseSensitivity);
1407  return searcher.search(pattern, range, backwards);
1408  }
1409 
1410  if (escapeSequences)
1411  {
1412  // escaped search
1413  KatePlainTextSearch searcher(this, caseSensitivity, wholeWords);
1414  KTextEditor::Range match = searcher.search(KateRegExpSearch::escapePlaintext(pattern), range, backwards);
1415 
1416  QVector<KTextEditor::Range> result;
1417  result.append(match);
1418  return result;
1419  }
1420 
1421  // plaintext search
1422  KatePlainTextSearch searcher(this, caseSensitivity, wholeWords);
1423  KTextEditor::Range match = searcher.search(pattern, range, backwards);
1424 
1425  QVector<KTextEditor::Range> result;
1426  result.append(match);
1427  return result;
1428 }
1429 
1430 
1431 
1432 KTextEditor::Search::SearchOptions KateDocument::supportedSearchOptions() const
1433 {
1434  KTextEditor::Search::SearchOptions supported(KTextEditor::Search::Default);
1435  supported |= KTextEditor::Search::Regex;
1436  supported |= KTextEditor::Search::CaseInsensitive;
1437  supported |= KTextEditor::Search::Backwards;
1438 // supported |= KTextEditor::Search::BlockInputRange;
1439  supported |= KTextEditor::Search::EscapeSequences;
1440  supported |= KTextEditor::Search::WholeWords;
1441 // supported |= KTextEditor::Search::DotMatchesNewline;
1442  return supported;
1443 }
1444 //END
1445 
1446 QWidget * KateDocument::dialogParent()
1447 {
1448  QWidget *w=widget();
1449 
1450  if(!w)
1451  {
1452  w=activeView();
1453 
1454  if(!w)
1455  w=QApplication::activeWindow();
1456  }
1457 
1458  return w;
1459 }
1460 
1461 //BEGIN KTextEditor::HighlightingInterface stuff
1462 bool KateDocument::setMode (const QString &name)
1463 {
1464  updateFileType (name);
1465  return true;
1466 }
1467 
1468 QString KateDocument::mode () const
1469 {
1470  return m_fileType;
1471 }
1472 
1473 QStringList KateDocument::modes () const
1474 {
1475  QStringList m;
1476 
1477  const QList<KateFileType *> &modeList = KateGlobal::self()->modeManager()->list();
1478  foreach(KateFileType* type, modeList)
1479  m << type->name;
1480 
1481  return m;
1482 }
1483 
1484 bool KateDocument::setHighlightingMode (const QString &name)
1485 {
1486  int mode = KateHlManager::self()->nameFind(name);
1487  if (mode == -1) {
1488  return false;
1489  }
1490  m_buffer->setHighlight(mode);
1491  return true;
1492 }
1493 
1494 QString KateDocument::highlightingMode () const
1495 {
1496  return highlight()->name ();
1497 }
1498 
1499 QStringList KateDocument::highlightingModes () const
1500 {
1501  QStringList hls;
1502 
1503  for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
1504  hls << KateHlManager::self()->hlName (i);
1505 
1506  return hls;
1507 }
1508 
1509 QString KateDocument::highlightingModeSection( int index ) const
1510 {
1511  return KateHlManager::self()->hlSection( index );
1512 }
1513 
1514 QString KateDocument::modeSection( int index ) const
1515 {
1516  return KateGlobal::self()->modeManager()->list().at( index )->section;
1517 }
1518 
1519 void KateDocument::bufferHlChanged ()
1520 {
1521  // update all views
1522  makeAttribs(false);
1523 
1524  // deactivate indenter if necessary
1525  m_indenter->checkRequiredStyle();
1526 
1527  emit highlightingModeChanged(this);
1528 }
1529 
1530 
1531 void KateDocument::setDontChangeHlOnSave()
1532 {
1533  m_hlSetByUser = true;
1534 }
1535 
1536 void KateDocument::bomSetByUser()
1537 {
1538  m_bomSetByUser=true;
1539 }
1540 //END
1541 
1542 //BEGIN KTextEditor::SessionConfigInterface and KTextEditor::ParameterizedSessionConfigInterface stuff
1543 void KateDocument::readSessionConfig(const KConfigGroup &kconfig)
1544 {
1545  readParameterizedSessionConfig(kconfig, SkipNone);
1546 }
1547 
1548 void KateDocument::readParameterizedSessionConfig(const KConfigGroup &kconfig,
1549  unsigned long configParameters)
1550 {
1551  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipEncoding)) {
1552  // get the encoding
1553  QString tmpenc=kconfig.readEntry("Encoding");
1554  if (!tmpenc.isEmpty() && (tmpenc != encoding()))
1555  setEncoding(tmpenc);
1556  }
1557 
1558  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipUrl)) {
1559  // restore the url
1560  KUrl url (kconfig.readEntry("URL"));
1561 
1562  // open the file if url valid
1563  if (!url.isEmpty() && url.isValid())
1564  openUrl (url);
1565  else completed(); //perhaps this should be emitted at the end of this function
1566  }
1567  else {
1568  completed(); //perhaps this should be emitted at the end of this function
1569  }
1570 
1571  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipMode)) {
1572  // restore the filetype
1573  if (kconfig.hasKey("Mode")) {
1574  updateFileType (kconfig.readEntry("Mode", fileType()));
1575  }
1576  }
1577 
1578  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipHighlighting)) {
1579  // restore the hl stuff
1580  if (kconfig.hasKey("Highlighting")) {
1581  int mode = KateHlManager::self()->nameFind(kconfig.readEntry("Highlighting"));
1582  if (mode >= 0) {
1583  m_buffer->setHighlight(mode);
1584  }
1585  }
1586  }
1587 
1588  // indent mode
1589  config()->setIndentationMode( kconfig.readEntry("Indentation Mode", config()->indentationMode() ) );
1590 
1591  // Restore Bookmarks
1592  const QList<int> marks = kconfig.readEntry("Bookmarks", QList<int>());
1593  for( int i = 0; i < marks.count(); i++ )
1594  addMark( marks.at(i), KateDocument::markType01 );
1595 }
1596 
1597 void KateDocument::writeSessionConfig(KConfigGroup &kconfig)
1598 {
1599  writeParameterizedSessionConfig(kconfig, SkipNone);
1600 }
1601 
1602 void KateDocument::writeParameterizedSessionConfig(KConfigGroup &kconfig,
1603  unsigned long configParameters)
1604 {
1605  if ( this->url().isLocalFile() ) {
1606  const QString path = this->url().toLocalFile();
1607  if ( KGlobal::dirs()->relativeLocation( "tmp", path ) != path ) {
1608  return; // inside tmp resource, do not save
1609  }
1610  }
1611 
1612  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipUrl)) {
1613  // save url
1614  kconfig.writeEntry("URL", this->url().prettyUrl() );
1615  }
1616 
1617  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipEncoding)) {
1618  // save encoding
1619  kconfig.writeEntry("Encoding",encoding());
1620  }
1621 
1622  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipMode)) {
1623  // save file type
1624  kconfig.writeEntry("Mode", m_fileType);
1625  }
1626 
1627  if(!(configParameters & KTextEditor::ParameterizedSessionConfigInterface::SkipHighlighting)) {
1628  // save hl
1629  kconfig.writeEntry("Highlighting", highlight()->name());
1630  }
1631 
1632  // indent mode
1633  kconfig.writeEntry("Indentation Mode", config()->indentationMode() );
1634 
1635  // Save Bookmarks
1636  QList<int> marks;
1637  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
1638  if (i.value()->type & KTextEditor::MarkInterface::markType01)
1639  marks << i.value()->line;
1640 
1641  kconfig.writeEntry( "Bookmarks", marks );
1642 }
1643 
1644 //END KTextEditor::SessionConfigInterface and KTextEditor::ParameterizedSessionConfigInterface stuff
1645 
1646 uint KateDocument::mark( int line )
1647 {
1648  KTextEditor::Mark* m = m_marks.value(line);
1649  if( !m )
1650  return 0;
1651 
1652  return m->type;
1653 }
1654 
1655 void KateDocument::setMark( int line, uint markType )
1656 {
1657  clearMark( line );
1658  addMark( line, markType );
1659 }
1660 
1661 void KateDocument::clearMark( int line )
1662 {
1663  if( line < 0 || line > lastLine() )
1664  return;
1665 
1666  if( !m_marks.value(line) )
1667  return;
1668 
1669  KTextEditor::Mark* mark = m_marks.take( line );
1670  emit markChanged( this, *mark, MarkRemoved );
1671  emit marksChanged( this );
1672  delete mark;
1673  tagLines( line, line );
1674  repaintViews(true);
1675 }
1676 
1677 void KateDocument::addMark( int line, uint markType )
1678 {
1679  KTextEditor::Mark *mark;
1680 
1681  if( line < 0 || line > lastLine())
1682  return;
1683 
1684  if( markType == 0 )
1685  return;
1686 
1687  if( (mark = m_marks.value(line)) ) {
1688  // Remove bits already set
1689  markType &= ~mark->type;
1690 
1691  if( markType == 0 )
1692  return;
1693 
1694  // Add bits
1695  mark->type |= markType;
1696  } else {
1697  mark = new KTextEditor::Mark;
1698  mark->line = line;
1699  mark->type = markType;
1700  m_marks.insert( line, mark );
1701  }
1702 
1703  // Emit with a mark having only the types added.
1704  KTextEditor::Mark temp;
1705  temp.line = line;
1706  temp.type = markType;
1707  emit markChanged( this, temp, MarkAdded );
1708 
1709  emit marksChanged( this );
1710  tagLines( line, line );
1711  repaintViews(true);
1712 }
1713 
1714 void KateDocument::removeMark( int line, uint markType )
1715 {
1716  if( line < 0 || line > lastLine() )
1717  return;
1718 
1719  KTextEditor::Mark* mark = m_marks.value(line);
1720 
1721  if( !mark )
1722  return;
1723 
1724  // Remove bits not set
1725  markType &= mark->type;
1726 
1727  if( markType == 0 )
1728  return;
1729 
1730  // Subtract bits
1731  mark->type &= ~markType;
1732 
1733  // Emit with a mark having only the types removed.
1734  KTextEditor::Mark temp;
1735  temp.line = line;
1736  temp.type = markType;
1737  emit markChanged( this, temp, MarkRemoved );
1738 
1739  if( mark->type == 0 )
1740  m_marks.remove( line );
1741 
1742  emit marksChanged( this );
1743  tagLines( line, line );
1744  repaintViews(true);
1745 }
1746 
1747 const QHash<int, KTextEditor::Mark*> &KateDocument::marks()
1748 {
1749  return m_marks;
1750 }
1751 
1752 void KateDocument::requestMarkTooltip( int line, QPoint position )
1753 {
1754  KTextEditor::Mark* mark = m_marks.value(line);
1755  if(!mark)
1756  return;
1757 
1758  bool handled = false;
1759  emit markToolTipRequested( this, *mark, position, handled );
1760 }
1761 
1762 bool KateDocument::handleMarkClick( int line )
1763 {
1764  KTextEditor::Mark* mark = m_marks.value(line);
1765  if(!mark)
1766  return false;
1767 
1768  bool handled = false;
1769  emit markClicked( this, *mark, handled );
1770 
1771  return handled;
1772 }
1773 
1774 bool KateDocument::handleMarkContextMenu( int line, QPoint position )
1775 {
1776  KTextEditor::Mark* mark = m_marks.value(line);
1777  if(!mark)
1778  return false;
1779 
1780  bool handled = false;
1781 
1782  emit markContextMenuRequested( this, *mark, position, handled );
1783 
1784  return handled;
1785 }
1786 
1787 void KateDocument::clearMarks()
1788 {
1789  while (!m_marks.isEmpty())
1790  {
1791  QHash<int, KTextEditor::Mark*>::iterator it = m_marks.begin();
1792  KTextEditor::Mark mark = *it.value();
1793  delete it.value();
1794  m_marks.erase (it);
1795 
1796  emit markChanged( this, mark, MarkRemoved );
1797  tagLines( mark.line, mark.line );
1798  }
1799 
1800  m_marks.clear();
1801 
1802  emit marksChanged( this );
1803  repaintViews(true);
1804 }
1805 
1806 void KateDocument::setMarkPixmap( MarkInterface::MarkTypes type, const QPixmap& pixmap )
1807 {
1808  m_markPixmaps.insert( type, pixmap );
1809 }
1810 
1811 void KateDocument::setMarkDescription( MarkInterface::MarkTypes type, const QString& description )
1812 {
1813  m_markDescriptions.insert( type, description );
1814 }
1815 
1816 QPixmap KateDocument::markPixmap( MarkInterface::MarkTypes type ) const
1817 {
1818  return m_markPixmaps.value(type, QPixmap());
1819 }
1820 
1821 QColor KateDocument::markColor( MarkInterface::MarkTypes type ) const
1822 {
1823  uint reserved = (0x1 << KTextEditor::MarkInterface::reservedMarkersCount()) - 1;
1824  if ((uint)type >= (uint)markType01 && (uint)type <= reserved) {
1825  return KateRendererConfig::global()->lineMarkerColor(type);
1826  } else {
1827  return QColor();
1828  }
1829 }
1830 
1831 QString KateDocument::markDescription( MarkInterface::MarkTypes type ) const
1832 {
1833  return m_markDescriptions.value(type, QString());
1834 }
1835 
1836 void KateDocument::setEditableMarks( uint markMask )
1837 {
1838  m_editableMarks = markMask;
1839 }
1840 
1841 uint KateDocument::editableMarks() const
1842 {
1843  return m_editableMarks;
1844 }
1845 //END
1846 
1847 //BEGIN KTextEditor::PrintInterface stuff
1848 bool KateDocument::printDialog ()
1849 {
1850  return KatePrinter::print (this);
1851 }
1852 
1853 bool KateDocument::print ()
1854 {
1855  return KatePrinter::print (this);
1856 }
1857 //END
1858 
1859 //BEGIN KTextEditor::DocumentInfoInterface (### unfinished)
1860 QString KateDocument::mimeType()
1861 {
1862  KMimeType::Ptr result = KMimeType::defaultMimeTypePtr();
1863 
1864  // if the document has a URL, try KMimeType::findByURL
1865  if ( ! this->url().isEmpty() )
1866  result = KMimeType::findByUrl( this->url() );
1867 
1868  else if ( this->url().isEmpty() || ! this->url().isLocalFile() )
1869  result = mimeTypeForContent();
1870 
1871  return result->name();
1872 }
1873 
1874 KMimeType::Ptr KateDocument::mimeTypeForContent()
1875 {
1876  QByteArray buf (1024,'\0');
1877  uint bufpos = 0;
1878 
1879  for (int i=0; i < lines(); ++i)
1880  {
1881  QString line = this->line( i );
1882  uint len = line.length() + 1;
1883 
1884  if (bufpos + len > 1024)
1885  len = 1024 - bufpos;
1886 
1887  QString ld (line + QChar::fromAscii('\n'));
1888  buf.replace(bufpos,len,ld.toLatin1()); //memcpy(buf.data() + bufpos, ld.toLatin1().constData(), len);
1889 
1890  bufpos += len;
1891 
1892  if (bufpos >= 1024)
1893  break;
1894  }
1895  buf.resize( bufpos );
1896 
1897  int accuracy = 0;
1898  KMimeType::Ptr mt = KMimeType::findByContent(buf, &accuracy);
1899  return mt ? mt : KMimeType::defaultMimeTypePtr();
1900 }
1901 //END KTextEditor::DocumentInfoInterface
1902 
1903 //BEGIN: error
1904 void KateDocument::showAndSetOpeningErrorAccess() {
1905  QPointer<KTextEditor::Message> message
1906  = new KTextEditor::Message(i18n ("The file %1 could not be loaded, as it was not possible to read from it.<br />Check if you have read access to this file.", this->url().pathOrUrl()),
1907  KTextEditor::Message::Error);
1908  message->setWordWrap(true);
1909  QAction* tryAgainAction = new QAction(KIcon("view-refresh"), i18nc("translators: you can also translate 'Try Again' with 'Reload'", "Try Again"), 0);
1910  connect(tryAgainAction, SIGNAL(triggered()), SLOT(documentReload()), Qt::QueuedConnection);
1911 
1912  QAction* closeAction = new QAction(KIcon("window-close"), i18n("&Close"), 0);
1913  closeAction->setToolTip(i18n("Close message"));
1914 
1915  // add try again and close actions
1916  message->addAction(tryAgainAction);
1917  message->addAction(closeAction);
1918 
1919  // finally post message
1920  postMessage(message);
1921 
1922  // remember error
1923  setOpeningError(true);
1924  setOpeningErrorMessage(i18n ("The file %1 could not be loaded, as it was not possible to read from it.\n\nCheck if you have read access to this file.",this->url().pathOrUrl()));
1925 
1926 }
1927 //END: error
1928 
1929 
1930 //BEGIN KParts::ReadWrite stuff
1931 bool KateDocument::openFile()
1932 {
1936  emit aboutToInvalidateMovingInterfaceContent (this);
1937 
1938  // no open errors until now...
1939  setOpeningError(false);
1940 
1941  // add new m_file to dirwatch
1942  activateDirWatch ();
1943 
1944  // remember current encoding
1945  QString currentEncoding = encoding();
1946 
1947  //
1948  // mime type magic to get encoding right
1949  //
1950  QString mimeType = arguments().mimeType();
1951  int pos = mimeType.indexOf(';');
1952  if (pos != -1 && !(m_reloading && m_userSetEncodingForNextReload))
1953  setEncoding (mimeType.mid(pos+1));
1954 
1955  // do we have success ?
1956  emit KTextEditor::Document::textRemoved(this, documentRange());
1957  emit KTextEditor::Document::textRemoved(this, documentRange(), m_buffer->text());
1958 
1959  // update file type, we do this here PRE-LOAD, therefore pass file name for reading from
1960  updateFileType (KateGlobal::self()->modeManager()->fileType (this, localFilePath()));
1961 
1962  // read dir config (if possible and wanted)
1963  // do this PRE-LOAD to get encoding info!
1964  readDirConfig ();
1965 
1966  // perhaps we need to re-set again the user encoding
1967  if (m_reloading && m_userSetEncodingForNextReload && (currentEncoding != encoding()))
1968  setEncoding (currentEncoding);
1969 
1970  bool success = m_buffer->openFile (localFilePath(), (m_reloading && m_userSetEncodingForNextReload));
1971 
1972  // disable view updates
1973  foreach (KateView * view, m_views)
1974  view->setUpdatesEnabled (false);
1975 
1976  //
1977  // yeah, success
1978  // read variables
1979  //
1980  if (success)
1981  readVariables ();
1982 
1983  //
1984  // update views
1985  //
1986  foreach (KateView * view, m_views)
1987  {
1988  // This is needed here because inserting the text moves the view's start position (it is a MovingCursor)
1989  view->setCursorPosition (KTextEditor::Cursor());
1990  view->setUpdatesEnabled (true);
1991  view->updateView (true);
1992  }
1993 
1994  // emit all signals about new text after view updates
1995  emit KTextEditor::Document::textInserted(this, documentRange());
1996 
1997  // Inform that the text has changed (required as we're not inside the usual editStart/End stuff)
1998  emit textChanged (this);
1999 
2000  if (!m_reloading)
2001  {
2002  //
2003  // emit the signal we need for example for kate app
2004  //
2005  emit documentUrlChanged (this);
2006 
2007  //
2008  // set doc name, dummy value as arg, don't need it
2009  //
2010  updateDocName ();
2011  }
2012 
2013  //
2014  // to houston, we are not modified
2015  //
2016  if (m_modOnHd)
2017  {
2018  m_modOnHd = false;
2019  m_modOnHdReason = OnDiskUnmodified;
2020  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
2021  }
2022 
2023  //
2024  // display errors
2025  //
2026  if (!success) {
2027  showAndSetOpeningErrorAccess();
2028  }
2029 
2030  // warn: broken encoding
2031  if (m_buffer->brokenEncoding()) {
2032  // this file can't be saved again without killing it
2033  setReadWrite( false );
2034 
2035  QPointer<KTextEditor::Message> message
2036  = new KTextEditor::Message(i18n ("The file %1 was opened with %2 encoding but contained invalid characters.<br />"
2037  "It is set to read-only mode, as saving might destroy its content.<br />"
2038  "Either reopen the file with the correct encoding chosen or enable the read-write mode again in the menu to be able to edit it.", this->url().pathOrUrl(),
2039  QString (m_buffer->textCodec()->name ())),
2040  KTextEditor::Message::Warning);
2041  message->setWordWrap(true);
2042  postMessage(message);
2043 
2044  // remember error
2045  setOpeningError(true);
2046  setOpeningErrorMessage(i18n ("The file %1 was opened with %2 encoding but contained invalid characters."
2047  " It is set to read-only mode, as saving might destroy its content."
2048  " Either reopen the file with the correct encoding chosen or enable the read-write mode again in the menu to be able to edit it.", this->url().pathOrUrl(), QString (m_buffer->textCodec()->name ())));
2049  }
2050 
2051  // warn: too long lines
2052  if (m_buffer->tooLongLinesWrapped()) {
2053  // this file can't be saved again without modifications
2054  setReadWrite( false );
2055 
2056  m_readWriteStateBeforeLoading = false;
2057  QPointer<KTextEditor::Message> message
2058  = new KTextEditor::Message(i18n ("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters).<br />"
2059  "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.",
2060  this->url().pathOrUrl(),config()->lineLengthLimit()),
2061  KTextEditor::Message::Warning);
2062  message->setWordWrap(true);
2063  postMessage(message);
2064 
2065  // remember error
2066  setOpeningError(true);
2067  setOpeningErrorMessage(i18n ("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters)."
2068  " Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", this->url().pathOrUrl(),config()->lineLengthLimit()));
2069  }
2070 
2071  //
2072  // return the success
2073  //
2074  return success;
2075 }
2076 
2077 bool KateDocument::saveFile()
2078 {
2079  QWidget *parentWidget(dialogParent());
2080 
2081  // some warnings, if file was changed by the outside!
2082  if ( !url().isEmpty() )
2083  {
2084  if (m_fileChangedDialogsActivated && m_modOnHd)
2085  {
2086  QString str = reasonedMOHString() + "\n\n";
2087 
2088  if (!isModified())
2089  {
2090  if (KMessageBox::warningContinueCancel(parentWidget,
2091  str + i18n("Do you really want to save this unmodified file? You could overwrite changed data in the file on disk."),i18n("Trying to Save Unmodified File"),KGuiItem(i18n("Save Nevertheless"))) != KMessageBox::Continue)
2092  return false;
2093  }
2094  else
2095  {
2096  if (KMessageBox::warningContinueCancel(parentWidget,
2097  str + i18n("Do you really want to save this file? Both your open file and the file on disk were changed. There could be some data lost."),i18n("Possible Data Loss"),KGuiItem(i18n("Save Nevertheless"))) != KMessageBox::Continue)
2098  return false;
2099  }
2100  }
2101  }
2102 
2103  //
2104  // can we encode it if we want to save it ?
2105  //
2106  if (!m_buffer->canEncode ()
2107  && (KMessageBox::warningContinueCancel(parentWidget,
2108  i18n("The selected encoding cannot encode every unicode character in this document. Do you really want to save it? There could be some data lost."),i18n("Possible Data Loss"),KGuiItem(i18n("Save Nevertheless"))) != KMessageBox::Continue))
2109  {
2110  return false;
2111  }
2112 
2113  //
2114  // try to create backup file..
2115  //
2116 
2117  // local file or not is here the question
2118  bool l ( url().isLocalFile() );
2119 
2120  // does the user want any backup, if not, not our problem?
2121  if ( ( l && config()->backupFlags() & KateDocumentConfig::LocalFiles )
2122  || ( ! l && config()->backupFlags() & KateDocumentConfig::RemoteFiles ) )
2123  {
2124  KUrl u( url() );
2125  if (config()->backupPrefix().contains(QDir::separator())) {
2126  u.setPath( config()->backupPrefix() + url().fileName() + config()->backupSuffix() );
2127  } else {
2128  u.setFileName( config()->backupPrefix() + url().fileName() + config()->backupSuffix() );
2129  }
2130 
2131  kDebug( 13020 ) << "backup src file name: " << url();
2132  kDebug( 13020 ) << "backup dst file name: " << u;
2133 
2134  // handle the backup...
2135  bool backupSuccess = false;
2136 
2137  // local file mode, no kio
2138  if (u.isLocalFile ())
2139  {
2140  if (QFile::exists (url().toLocalFile ()))
2141  {
2142  // first: check if backupFile is already there, if true, unlink it
2143  QFile backupFile (u.toLocalFile ());
2144  if (backupFile.exists()) backupFile.remove ();
2145 
2146  backupSuccess = QFile::copy (url().toLocalFile (), u.toLocalFile ());
2147  }
2148  else
2149  backupSuccess = true;
2150  }
2151  else // remote file mode, kio
2152  {
2153  // get the right permissions, start with safe default
2154  KIO::UDSEntry fentry;
2155  if (KIO::NetAccess::stat (url(), fentry, QApplication::activeWindow())) {
2156  // do a evil copy which will overwrite target if possible
2157  KFileItem item (fentry, url());
2158  KIO::FileCopyJob *job = KIO::file_copy ( url(), u, item.permissions(), KIO::Overwrite );
2159  backupSuccess = KIO::NetAccess::synchronousRun(job, QApplication::activeWindow());
2160  }
2161  else
2162  backupSuccess = true;
2163  }
2164 
2165  // backup has failed, ask user how to proceed
2166  if (!backupSuccess && (KMessageBox::warningContinueCancel (parentWidget
2167  , i18n ("For file %1 no backup copy could be created before saving."
2168  " If an error occurs while saving, you might lose the data of this file."
2169  " A reason could be that the media you write to is full or the directory of the file is read-only for you.", url().pathOrUrl())
2170  , i18n ("Failed to create backup copy.")
2171  , KGuiItem(i18n("Try to Save Nevertheless"))
2172  , KStandardGuiItem::cancel(), "Backup Failed Warning") != KMessageBox::Continue))
2173  {
2174  return false;
2175  }
2176  }
2177 
2178  // update file type, pass no file path, read file type content from this document
2179  updateFileType (KateGlobal::self()->modeManager()->fileType (this, QString ()));
2180 
2181  // remember the oldpath...
2182  QString oldPath = m_dirWatchFile;
2183 
2184  // read dir config (if possible and wanted)
2185  if ( url().isLocalFile())
2186  {
2187  QFileInfo fo (oldPath), fn (localFilePath());
2188 
2189  if (fo.path() != fn.path())
2190  readDirConfig();
2191  }
2192 
2193  // read our vars
2194  readVariables();
2195 
2196  // remove file from dirwatch
2197  deactivateDirWatch ();
2198 
2199  // remove all trailing spaces in the document (as edit actions)
2200  // NOTE: we need this as edit actions, since otherwise the edit actions
2201  // in the swap file recovery may happen at invalid cursor positions
2202  removeTrailingSpaces ();
2203 
2204  //
2205  // try to save
2206  //
2207  if (!m_buffer->saveFile (localFilePath()))
2208  {
2209  // add m_file again to dirwatch
2210  activateDirWatch (oldPath);
2211 
2212  KMessageBox::error (parentWidget, i18n ("The document could not be saved, as it was not possible to write to %1.\n\nCheck that you have write access to this file or that enough disk space is available.", this->url().pathOrUrl()));
2213 
2214  return false;
2215  }
2216 
2217  // update the md5 digest
2218  createDigest ();
2219 
2220  // add m_file again to dirwatch
2221  activateDirWatch ();
2222 
2223  //
2224  // we are not modified
2225  //
2226  if (m_modOnHd)
2227  {
2228  m_modOnHd = false;
2229  m_modOnHdReason = OnDiskUnmodified;
2230  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
2231  }
2232 
2233  // update document name...
2234  updateDocName ();
2235 
2236  // url may have changed...
2237  emit documentUrlChanged (this);
2238 
2239  // (dominik) mark last undo group as not mergeable, otherwise the next
2240  // edit action might be merged and undo will never stop at the saved state
2241  m_undoManager->undoSafePoint();
2242  m_undoManager->updateLineModifications();
2243 
2244  //
2245  // return success
2246  //
2247  return true;
2248 }
2249 
2250 void KateDocument::readDirConfig ()
2251 {
2252  int depth = config()->searchDirConfigDepth ();
2253 
2254  if (this->url().isLocalFile() && (depth > -1))
2255  {
2256  QString currentDir = QFileInfo (localFilePath()).absolutePath();
2257 
2258  // only search as deep as specified or not at all ;)
2259  while (depth > -1)
2260  {
2261  //kDebug (13020) << "search for config file in path: " << currentDir;
2262 
2263  // try to open config file in this dir
2264  QFile f (currentDir + "/.kateconfig");
2265 
2266  if (f.open (QIODevice::ReadOnly))
2267  {
2268  QTextStream stream (&f);
2269 
2270  uint linesRead = 0;
2271  QString line = stream.readLine();
2272  while ((linesRead < 32) && !line.isNull())
2273  {
2274  readVariableLine( line );
2275 
2276  line = stream.readLine();
2277 
2278  linesRead++;
2279  }
2280 
2281  break;
2282  }
2283 
2284  QString newDir = QFileInfo (currentDir).absolutePath();
2285 
2286  // bail out on looping (for example reached /)
2287  if (currentDir == newDir)
2288  break;
2289 
2290  currentDir = newDir;
2291  --depth;
2292  }
2293  }
2294 }
2295 
2296 void KateDocument::activateDirWatch (const QString &useFileName)
2297 {
2298  QString fileToUse = useFileName;
2299  if (fileToUse.isEmpty())
2300  fileToUse = localFilePath();
2301 
2302  QFileInfo fileInfo = QFileInfo(fileToUse);
2303  if (fileInfo.isSymLink()) {
2304  // Monitor the actual data and not the symlink
2305  fileToUse = fileInfo.canonicalFilePath();
2306  }
2307 
2308  // same file as we are monitoring, return
2309  if (fileToUse == m_dirWatchFile)
2310  return;
2311 
2312  // remove the old watched file
2313  deactivateDirWatch ();
2314 
2315  // add new file if needed
2316  if (url().isLocalFile() && !fileToUse.isEmpty())
2317  {
2318  KateGlobal::self()->dirWatch ()->addFile (fileToUse);
2319  m_dirWatchFile = fileToUse;
2320  }
2321 }
2322 
2323 void KateDocument::deactivateDirWatch ()
2324 {
2325  if (!m_dirWatchFile.isEmpty())
2326  KateGlobal::self()->dirWatch ()->removeFile (m_dirWatchFile);
2327 
2328  m_dirWatchFile.clear();
2329 }
2330 
2331 bool KateDocument::openUrl( const KUrl &url ) {
2332  bool res=KTextEditor::Document::openUrl(url);
2333  updateDocName();
2334  return res;
2335 }
2336 
2337 bool KateDocument::closeUrl()
2338 {
2339  //
2340  // file mod on hd
2341  //
2342  if ( !m_reloading && !url().isEmpty() )
2343  {
2344  if (m_fileChangedDialogsActivated && m_modOnHd)
2345  {
2346  QWidget *parentWidget(dialogParent());
2347 
2348  if (!(KMessageBox::warningContinueCancel(
2349  parentWidget,
2350  reasonedMOHString() + "\n\n" + i18n("Do you really want to continue to close this file? Data loss may occur."),
2351  i18n("Possible Data Loss"), KGuiItem(i18n("Close Nevertheless")), KStandardGuiItem::cancel(),
2352  QString("kate_close_modonhd_%1").arg( m_modOnHdReason ) ) == KMessageBox::Continue)) {
2356  m_reloading = false;
2357  return false;
2358  }
2359  }
2360  }
2361 
2362  //
2363  // first call the normal kparts implementation
2364  //
2365  if (!KParts::ReadWritePart::closeUrl ()) {
2369  m_reloading = false;
2370  return false;
2371  }
2372 
2373  // Tell the world that we're about to go ahead with the close
2374  if (!m_reloading)
2375  emit aboutToClose(this);
2376 
2380  if (m_messageHash.count()) {
2381  QList<KTextEditor::Message*> keys = m_messageHash.keys ();
2382  foreach (KTextEditor::Message* message, keys)
2383  delete message;
2384  }
2385 
2389  emit aboutToInvalidateMovingInterfaceContent (this);
2390 
2391  // remove file from dirwatch
2392  deactivateDirWatch ();
2393 
2394  //
2395  // empty url + fileName
2396  //
2397  setUrl(KUrl());
2398  setLocalFilePath(QString());
2399 
2400  // we are not modified
2401  if (m_modOnHd)
2402  {
2403  m_modOnHd = false;
2404  m_modOnHdReason = OnDiskUnmodified;
2405  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
2406  }
2407 
2408  emit KTextEditor::Document::textRemoved(this, documentRange());
2409  emit KTextEditor::Document::textRemoved(this, documentRange(), m_buffer->text());
2410 
2411  {
2412  // remove all marks
2413  clearMarks ();
2414 
2415  // clear the buffer
2416  m_buffer->clear();
2417 
2418  // clear undo/redo history
2419  m_undoManager->clearUndo();
2420  m_undoManager->clearRedo();
2421  }
2422 
2423  // no, we are no longer modified
2424  setModified(false);
2425 
2426  // we have no longer any hl
2427  m_buffer->setHighlight(0);
2428 
2429  // update all our views
2430  foreach (KateView * view, m_views )
2431  {
2432  view->clearSelection(); // fix bug #118588
2433  view->clear();
2434  }
2435 
2436  if (!m_reloading)
2437  {
2438  // uh, fileName changed
2439  emit documentUrlChanged (this);
2440 
2441  // update doc name
2442  updateDocName ();
2443  }
2444 
2445  // purge swap file
2446  m_swapfile->fileClosed ();
2447 
2448  // success
2449  return true;
2450 }
2451 
2452 bool KateDocument::isDataRecoveryAvailable() const
2453 {
2454  return m_swapfile->shouldRecover();
2455 }
2456 
2457 void KateDocument::recoverData()
2458 {
2459  if (isDataRecoveryAvailable())
2460  m_swapfile->recover();
2461 }
2462 
2463 void KateDocument::discardDataRecovery()
2464 {
2465  if (isDataRecoveryAvailable())
2466  m_swapfile->discard();
2467 }
2468 
2469 void KateDocument::setReadWrite( bool rw )
2470 {
2471  if (isReadWrite() != rw)
2472  {
2473  KParts::ReadWritePart::setReadWrite (rw);
2474 
2475  foreach( KateView* view, m_views)
2476  {
2477  view->slotUpdateUndo();
2478  view->slotReadWriteChanged ();
2479  }
2480  emit readWriteChanged(this);
2481  }
2482 }
2483 
2484 void KateDocument::setModified(bool m) {
2485 
2486  if (isModified() != m) {
2487  KParts::ReadWritePart::setModified (m);
2488 
2489  foreach( KateView* view,m_views)
2490  {
2491  view->slotUpdateUndo();
2492  }
2493 
2494  emit modifiedChanged (this);
2495  }
2496 
2497  m_undoManager->setModified (m);
2498 }
2499 //END
2500 
2501 //BEGIN Kate specific stuff ;)
2502 
2503 void KateDocument::makeAttribs(bool needInvalidate)
2504 {
2505  foreach(KateView *view,m_views)
2506  view->renderer()->updateAttributes ();
2507 
2508  if (needInvalidate)
2509  m_buffer->invalidateHighlighting();
2510 
2511  foreach(KateView *view,m_views)
2512  {
2513  view->tagAll();
2514  view->updateView (true);
2515  }
2516 }
2517 
2518 // the attributes of a hl have changed, update
2519 void KateDocument::internalHlChanged()
2520 {
2521  makeAttribs();
2522 }
2523 
2524 void KateDocument::addView(KTextEditor::View *view) {
2525  if (!view)
2526  return;
2527 
2528  m_views.append( static_cast<KateView*>(view) );
2529  m_textEditViews.append( view );
2530 
2531  // apply the view & renderer vars from the file type
2532  if (!m_fileType.isEmpty())
2533  readVariableLine(KateGlobal::self()->modeManager()->fileType(m_fileType).varLine, true);
2534 
2535  // apply the view & renderer vars from the file
2536  readVariables (true);
2537 
2538  setActiveView(view);
2539 }
2540 
2541 void KateDocument::removeView(KTextEditor::View *view) {
2542  if (!view)
2543  return;
2544 
2545  if (activeView() == view)
2546  setActiveView(0L);
2547 
2548  m_views.removeAll( static_cast<KateView *>(view) );
2549  m_textEditViews.removeAll( view );
2550 }
2551 
2552 void KateDocument::setActiveView(KTextEditor::View* view)
2553 {
2554  if ( m_activeView == view )
2555  return;
2556 
2557  m_activeView = static_cast<KateView*>(view);
2558 }
2559 
2560 bool KateDocument::ownedView(KateView *view) {
2561  // do we own the given view?
2562  return (m_views.contains(view));
2563 }
2564 
2565 int KateDocument::toVirtualColumn( int line, int column ) const
2566 {
2567  Kate::TextLine textLine = m_buffer->plainLine(line);
2568 
2569  if (textLine)
2570  return textLine->toVirtualColumn(column, config()->tabWidth());
2571  else
2572  return 0;
2573 }
2574 
2575 int KateDocument::toVirtualColumn( const KTextEditor::Cursor& cursor ) const
2576 {
2577  return toVirtualColumn(cursor.line(), cursor.column());
2578 }
2579 
2580 int KateDocument::fromVirtualColumn( int line, int column ) const
2581 {
2582  Kate::TextLine textLine = m_buffer->plainLine(line);
2583 
2584  if (textLine)
2585  return textLine->fromVirtualColumn(column, config()->tabWidth());
2586  else
2587  return 0;
2588 }
2589 
2590 int KateDocument::fromVirtualColumn( const KTextEditor::Cursor& cursor ) const
2591 {
2592  return fromVirtualColumn(cursor.line(), cursor.column());
2593 }
2594 
2595 bool KateDocument::typeChars ( KateView *view, const QString &realChars )
2596 {
2597  Kate::TextLine textLine = m_buffer->plainLine(view->cursorPosition().line ());
2598  if (!textLine)
2599  return false;
2600 
2604  QString chars;
2605  Q_FOREACH (QChar c, realChars)
2606  if (c.isPrint() || c == QChar::fromLatin1('\t'))
2607  chars.append (c);
2608 
2609  if (chars.isEmpty())
2610  return false;
2611 
2612  editStart ();
2613 
2614  if (!view->config()->persistentSelection() && view->selection() )
2615  view->removeSelectedText();
2616 
2617  KTextEditor::Cursor oldCur (view->cursorPosition());
2618 
2619  if (config()->ovr()
2620  || (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode)) {
2621 
2622  KTextEditor::Range r = KTextEditor::Range(view->cursorPosition(), qMin(chars.length(),
2623  textLine->length() - view->cursorPosition().column()));
2624 
2625  // replace mode needs to know what was removed so it can be restored with backspace
2626  if (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode
2627  && oldCur.column() < line( view->cursorPosition().line() ).length() ) {
2628  QChar removed = line( view->cursorPosition().line() ).at( r.start().column() );
2629  view->getViInputModeManager()->getViReplaceMode()->overwrittenChar( removed );
2630  }
2631 
2632  removeText(r);
2633  }
2634 
2635  if (view->blockSelection() && view->selection()) {
2636  KTextEditor::Range selectionRange = view->selectionRange();
2637  int startLine = qMax(0, selectionRange.start().line());
2638  int endLine = qMin(selectionRange.end().line(), lastLine());
2639  int column = toVirtualColumn(selectionRange.end());
2640  for (int line = endLine; line >= startLine; --line)
2641  editInsertText(line, fromVirtualColumn(line, column), chars);
2642  int newSelectionColumn = toVirtualColumn(view->cursorPosition());
2643  selectionRange.start().setColumn(fromVirtualColumn(selectionRange.start().line(), newSelectionColumn));
2644  selectionRange.end().setColumn(fromVirtualColumn(selectionRange.end().line(), newSelectionColumn));
2645  view->setSelection(selectionRange);
2646  }
2647  else
2648  insertText(view->cursorPosition(), chars);
2649 
2650  // end edit session here, to have updated HL in userTypedChar!
2651  editEnd();
2652 
2653  KTextEditor::Cursor b(view->cursorPosition());
2654  m_indenter->userTypedChar (view, b, chars.isEmpty() ? QChar() : chars.at(chars.length() - 1));
2655 
2656  view->slotTextInserted (view, oldCur, chars);
2657  return true;
2658 }
2659 
2660 void KateDocument::newLine( KateView *v )
2661 {
2662  editStart();
2663 
2664  if( !v->config()->persistentSelection() && v->selection() ) {
2665  v->removeSelectedText();
2666  v->clearSelection();
2667  }
2668 
2669  // query cursor position
2670  KTextEditor::Cursor c = v->cursorPosition();
2671 
2672  if (c.line() > (int)lastLine())
2673  c.setLine(lastLine());
2674 
2675  if (c.line() < 0)
2676  c.setLine(0);
2677 
2678  uint ln = c.line();
2679 
2680  Kate::TextLine textLine = plainKateTextLine(ln);
2681 
2682  if (c.column() > (int)textLine->length())
2683  c.setColumn(textLine->length());
2684 
2685  // first: wrap line
2686  editWrapLine (c.line(), c.column());
2687 
2688  // end edit session here, to have updated HL in userTypedChar!
2689  editEnd();
2690 
2691  // second: indent the new line, if needed...
2692  m_indenter->userTypedChar(v, v->cursorPosition(), '\n');
2693 }
2694 
2695 void KateDocument::transpose( const KTextEditor::Cursor& cursor)
2696 {
2697  Kate::TextLine textLine = m_buffer->plainLine(cursor.line());
2698 
2699  if (!textLine || (textLine->length() < 2))
2700  return;
2701 
2702  uint col = cursor.column();
2703 
2704  if (col > 0)
2705  col--;
2706 
2707  if ((textLine->length() - col) < 2)
2708  return;
2709 
2710  uint line = cursor.line();
2711  QString s;
2712 
2713  //clever swap code if first character on the line swap right&left
2714  //otherwise left & right
2715  s.append (textLine->at(col+1));
2716  s.append (textLine->at(col));
2717  //do the swap
2718 
2719  // do it right, never ever manipulate a textline
2720  editStart ();
2721  editRemoveText (line, col, 2);
2722  editInsertText (line, col, s);
2723  editEnd ();
2724 }
2725 
2726 void KateDocument::backspace( KateView *view, const KTextEditor::Cursor& c )
2727 {
2728  if ( !view->config()->persistentSelection() && view->selection() ) {
2729  if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) {
2730  // Remove one character after selection line
2731  KTextEditor::Range range = view->selectionRange();
2732  range.start().setColumn(range.start().column() - 1);
2733  view->setSelection(range);
2734  }
2735  view->removeSelectedText();
2736  return;
2737  }
2738 
2739  uint col = qMax( c.column(), 0 );
2740  uint line = qMax( c.line(), 0 );
2741 
2742  if ((col == 0) && (line == 0))
2743  return;
2744 
2745  if (col > 0)
2746  {
2747  if (!(config()->backspaceIndents()))
2748  {
2749  // ordinary backspace
2750  //c.cursor.col--;
2751  removeText(KTextEditor::Range(line, col-1, line, col));
2752  // in most cases cursor is moved by removeText, but we should do it manually
2753  // for past-end-of-line cursors in block mode
2754  view->setCursorPosition(KTextEditor::Cursor(line, col-1));
2755  }
2756  else
2757  {
2758  // backspace indents: erase to next indent position
2759  Kate::TextLine textLine = m_buffer->plainLine(line);
2760 
2761  // don't forget this check!!!! really!!!!
2762  if (!textLine)
2763  return;
2764 
2765  int colX = textLine->toVirtualColumn(col, config()->tabWidth());
2766  int pos = textLine->firstChar();
2767  if (pos > 0)
2768  pos = textLine->toVirtualColumn(pos, config()->tabWidth());
2769 
2770  if (pos < 0 || pos >= (int)colX)
2771  {
2772  // only spaces on left side of cursor
2773  indent( KTextEditor::Range( line, 0, line, 0), -1);
2774  }
2775  else
2776  {
2777  removeText(KTextEditor::Range(line, col-1, line, col));
2778  // in most cases cursor is moved by removeText, but we should do it manually
2779  // for past-end-of-line cursors in block mode
2780  view->setCursorPosition(KTextEditor::Cursor(line, col-1));
2781  }
2782  }
2783  }
2784  else
2785  {
2786  // col == 0: wrap to previous line
2787  if (line >= 1)
2788  {
2789  Kate::TextLine textLine = m_buffer->plainLine(line-1);
2790 
2791  // don't forget this check!!!! really!!!!
2792  if (!textLine)
2793  return;
2794 
2795  if (config()->wordWrap() && textLine->endsWith(QLatin1String(" ")))
2796  {
2797  // gg: in hard wordwrap mode, backspace must also eat the trailing space
2798  removeText (KTextEditor::Range(line-1, textLine->length()-1, line, 0));
2799  }
2800  else
2801  removeText (KTextEditor::Range(line-1, textLine->length(), line, 0));
2802  }
2803  }
2804 }
2805 
2806 void KateDocument::del( KateView *view, const KTextEditor::Cursor& c )
2807 {
2808  if ( !view->config()->persistentSelection() && view->selection() ) {
2809  if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) {
2810  // Remove one character after selection line
2811  KTextEditor::Range range = view->selectionRange();
2812  range.end().setColumn(range.end().column() + 1);
2813  view->setSelection(range);
2814  }
2815  view->removeSelectedText();
2816  return;
2817  }
2818 
2819  if( c.column() < (int) m_buffer->plainLine(c.line())->length())
2820  {
2821  removeText(KTextEditor::Range(c, 1));
2822  }
2823  else if ( c.line() < lastLine() )
2824  {
2825  removeText(KTextEditor::Range(c.line(), c.column(), c.line()+1, 0));
2826  }
2827 }
2828 
2829 void KateDocument::paste ( KateView* view, const QString &text )
2830 {
2831  static const QChar newLineChar('\n');
2832  QString s = text;
2833 
2834  if (s.isEmpty())
2835  return;
2836 
2837  int lines = s.count (newLineChar);
2838 
2839  m_undoManager->undoSafePoint();
2840 
2841  editStart ();
2842 
2843  KTextEditor::Cursor pos = view->cursorPosition();
2844  if (!view->config()->persistentSelection() && view->selection()) {
2845  pos = view->selectionRange().start();
2846  if (view->blockSelection()) {
2847  pos = rangeOnLine(view->selectionRange(), pos.line()).start();
2848  if (lines == 0) {
2849  s += newLineChar;
2850  s = s.repeated(view->selectionRange().numberOfLines() + 1);
2851  s.chop(1);
2852  }
2853  }
2854  view->removeSelectedText();
2855  }
2856 
2857  if (config()->ovr()) {
2858  QStringList pasteLines = s.split(newLineChar);
2859 
2860  if (!view->blockSelection()) {
2861  int endColumn = (pasteLines.count() == 1 ? pos.column() : 0) + pasteLines.last().length();
2862  removeText(KTextEditor::Range(pos,
2863  pos.line()+pasteLines.count()-1, endColumn));
2864  } else {
2865  int maxi = qMin(pos.line() + pasteLines.count(), this->lines());
2866 
2867  for (int i = pos.line(); i < maxi; ++i) {
2868  int pasteLength = pasteLines.at(i-pos.line()).length();
2869  removeText(KTextEditor::Range(i, pos.column(),
2870  i, qMin(pasteLength + pos.column(), lineLength(i))));
2871  }
2872  }
2873  }
2874 
2875 
2876  insertText(pos, s, view->blockSelection());
2877  editEnd();
2878 
2879  // move cursor right for block select, as the user is moved right internal
2880  // even in that case, but user expects other behavior in block selection
2881  // mode !
2882  // just let cursor stay, that was it before I changed to moving ranges!
2883  if (view->blockSelection())
2884  view->setCursorPositionInternal(pos);
2885 
2886  if (config()->indentPastedText())
2887  {
2888  KTextEditor::Range range = KTextEditor::Range(KTextEditor::Cursor(pos.line(), 0),
2889  KTextEditor::Cursor(pos.line() + lines, 0));
2890 
2891  m_indenter->indent(view, range);
2892  }
2893 
2894  if (!view->blockSelection())
2895  emit charactersSemiInteractivelyInserted (pos, s);
2896  m_undoManager->undoSafePoint();
2897 }
2898 
2899 void KateDocument::indent (KTextEditor::Range range, int change)
2900 {
2901  if (!isReadWrite())
2902  return;
2903 
2904  editStart();
2905  m_indenter->changeIndent(range, change);
2906  editEnd();
2907 }
2908 
2909 void KateDocument::align(KateView *view, const KTextEditor::Range &range)
2910 {
2911  m_indenter->indent(view, range);
2912 }
2913 
2914 void KateDocument::insertTab( KateView *view, const KTextEditor::Cursor&)
2915 {
2916  if (!isReadWrite())
2917  return;
2918 
2919  int lineLen = line(view->cursorPosition().line()).length();
2920  KTextEditor::Cursor c = view->cursorPosition();
2921 
2922  editStart();
2923 
2924 
2925  if (!view->config()->persistentSelection() && view->selection() ) {
2926  view->removeSelectedText();
2927  }
2928  else if (config()->ovr() && c.column() < lineLen)
2929  {
2930  KTextEditor::Range r = KTextEditor::Range(view->cursorPosition(), 1);
2931 
2932  if (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode)
2933  {
2934  // vi replace mode needs to know what was removed so it can be restored with backspace
2935  QChar removed = line(view->cursorPosition().line()).at( r.start().column());
2936  view->getViInputModeManager()->getViReplaceMode()->overwrittenChar(removed);
2937  }
2938  removeText(r);
2939  }
2940 
2941  c = view->cursorPosition();
2942  editInsertText(c.line(), c.column(), QChar('\t'));
2943 
2944  editEnd();
2945 }
2946 
2947 /*
2948  Remove a given string at the beginning
2949  of the current line.
2950 */
2951 bool KateDocument::removeStringFromBeginning(int line, const QString &str)
2952 {
2953  Kate::TextLine textline = m_buffer->plainLine(line);
2954 
2955  KTextEditor::Cursor cursor (line, 0);
2956  bool there = textline->startsWith(str);
2957 
2958  if (!there)
2959  {
2960  cursor.setColumn(textline->firstChar());
2961  there = textline->matchesAt(cursor.column(), str);
2962  }
2963 
2964  if (there)
2965  {
2966  // Remove some chars
2967  removeText (KTextEditor::Range(cursor, str.length()));
2968  }
2969 
2970  return there;
2971 }
2972 
2973 /*
2974  Remove a given string at the end
2975  of the current line.
2976 */
2977 bool KateDocument::removeStringFromEnd(int line, const QString &str)
2978 {
2979  Kate::TextLine textline = m_buffer->plainLine(line);
2980 
2981  KTextEditor::Cursor cursor (line, 0);
2982  bool there = textline->endsWith(str);
2983 
2984  if (there)
2985  {
2986  cursor.setColumn(textline->length() - str.length());
2987  }
2988  else
2989  {
2990  cursor.setColumn(textline->lastChar() - str.length() + 1);
2991  there = textline->matchesAt(cursor.column(), str);
2992  }
2993 
2994  if (there)
2995  {
2996  // Remove some chars
2997  removeText (KTextEditor::Range(cursor, str.length()));
2998  }
2999 
3000  return there;
3001 }
3002 
3003 /*
3004  Add to the current line a comment line mark at the beginning.
3005 */
3006 void KateDocument::addStartLineCommentToSingleLine( int line, int attrib )
3007 {
3008  QString commentLineMark = highlight()->getCommentSingleLineStart(attrib);
3009  int pos = -1;
3010 
3011  if (highlight()->getCommentSingleLinePosition(attrib) == KateHighlighting::CSLPosColumn0)
3012  {
3013  pos = 0;
3014  commentLineMark += ' ';
3015  } else {
3016  const Kate::TextLine l = kateTextLine(line);
3017  pos = l->firstChar();
3018  }
3019 
3020  if (pos >= 0)
3021  insertText (KTextEditor::Cursor(line, pos), commentLineMark);
3022 }
3023 
3024 /*
3025  Remove from the current line a comment line mark at
3026  the beginning if there is one.
3027 */
3028 bool KateDocument::removeStartLineCommentFromSingleLine( int line, int attrib )
3029 {
3030  const QString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3031  const QString longCommentMark = shortCommentMark + ' ';
3032 
3033  editStart();
3034 
3035  // Try to remove the long comment mark first
3036  bool removed = (removeStringFromBeginning(line, longCommentMark)
3037  || removeStringFromBeginning(line, shortCommentMark));
3038 
3039  editEnd();
3040 
3041  return removed;
3042 }
3043 
3044 /*
3045  Add to the current line a start comment mark at the
3046  beginning and a stop comment mark at the end.
3047 */
3048 void KateDocument::addStartStopCommentToSingleLine( int line, int attrib )
3049 {
3050  const QString startCommentMark = highlight()->getCommentStart( attrib ) + ' ';
3051  const QString stopCommentMark = ' ' + highlight()->getCommentEnd( attrib );
3052 
3053  editStart();
3054 
3055  // Add the start comment mark
3056  insertText (KTextEditor::Cursor(line, 0), startCommentMark);
3057 
3058  // Go to the end of the line
3059  const int col = m_buffer->plainLine(line)->length();
3060 
3061  // Add the stop comment mark
3062  insertText (KTextEditor::Cursor(line, col), stopCommentMark);
3063 
3064  editEnd();
3065 }
3066 
3067 /*
3068  Remove from the current line a start comment mark at
3069  the beginning and a stop comment mark at the end.
3070 */
3071 bool KateDocument::removeStartStopCommentFromSingleLine( int line, int attrib )
3072 {
3073  QString shortStartCommentMark = highlight()->getCommentStart( attrib );
3074  QString longStartCommentMark = shortStartCommentMark + ' ';
3075  QString shortStopCommentMark = highlight()->getCommentEnd( attrib );
3076  QString longStopCommentMark = ' ' + shortStopCommentMark;
3077 
3078  editStart();
3079 
3080  // TODO "that's a bad idea, can lead to stray endings, FIXME"
3081 
3082  // Try to remove the long start comment mark first
3083  bool removedStart = (removeStringFromBeginning(line, longStartCommentMark)
3084  || removeStringFromBeginning(line, shortStartCommentMark));
3085 
3086  bool removedStop = false;
3087  if (removedStart)
3088  {
3089  // Try to remove the long stop comment mark first
3090  removedStop = (removeStringFromEnd(line, longStopCommentMark)
3091  || removeStringFromEnd(line, shortStopCommentMark));
3092  }
3093 
3094  editEnd();
3095 
3096  return (removedStart || removedStop);
3097 }
3098 
3099 /*
3100  Add to the current selection a start comment mark at the beginning
3101  and a stop comment mark at the end.
3102 */
3103 void KateDocument::addStartStopCommentToSelection( KateView *view, int attrib )
3104 {
3105  const QString startComment = highlight()->getCommentStart( attrib );
3106  const QString endComment = highlight()->getCommentEnd( attrib );
3107 
3108  KTextEditor::Range range = view->selectionRange();
3109 
3110  if ((range.end().column() == 0) && (range.end().line() > 0))
3111  range.end().setPosition(range.end().line() - 1, lineLength(range.end().line() - 1));
3112 
3113  editStart();
3114 
3115  if (!view->blockSelection()) {
3116  insertText(range.end(), endComment);
3117  insertText(range.start(), startComment);
3118  } else {
3119  for (int line = range.start().line(); line <= range.end().line(); line++ ) {
3120  KTextEditor::Range subRange = rangeOnLine(range, line);
3121  insertText(subRange.end(), endComment);
3122  insertText(subRange.start(), startComment);
3123  }
3124  }
3125 
3126  editEnd ();
3127  // selection automatically updated (MovingRange)
3128 }
3129 
3130 /*
3131  Add to the current selection a comment line mark at the beginning of each line.
3132 */
3133 void KateDocument::addStartLineCommentToSelection( KateView *view, int attrib )
3134 {
3135  const QString commentLineMark = highlight()->getCommentSingleLineStart( attrib ) + ' ';
3136 
3137  int sl = view->selectionRange().start().line();
3138  int el = view->selectionRange().end().line();
3139 
3140  // if end of selection is in column 0 in last line, omit the last line
3141  if ((view->selectionRange().end().column() == 0) && (el > 0))
3142  {
3143  el--;
3144  }
3145 
3146  editStart();
3147 
3148  // For each line of the selection
3149  for (int z = el; z >= sl; z--) {
3150  //insertText (z, 0, commentLineMark);
3151  addStartLineCommentToSingleLine(z, attrib );
3152  }
3153 
3154  editEnd ();
3155  // selection automatically updated (MovingRange)
3156 }
3157 
3158 bool KateDocument::nextNonSpaceCharPos(int &line, int &col)
3159 {
3160  for(; line < (int)m_buffer->count(); line++) {
3161  Kate::TextLine textLine = m_buffer->plainLine(line);
3162 
3163  if (!textLine)
3164  break;
3165 
3166  col = textLine->nextNonSpaceChar(col);
3167  if(col != -1)
3168  return true; // Next non-space char found
3169  col = 0;
3170  }
3171  // No non-space char found
3172  line = -1;
3173  col = -1;
3174  return false;
3175 }
3176 
3177 bool KateDocument::previousNonSpaceCharPos(int &line, int &col)
3178 {
3179  while(true)
3180  {
3181  Kate::TextLine textLine = m_buffer->plainLine(line);
3182 
3183  if (!textLine)
3184  break;
3185 
3186  col = textLine->previousNonSpaceChar(col);
3187  if(col != -1) return true;
3188  if(line == 0) return false;
3189  --line;
3190  col = textLine->length();
3191  }
3192  // No non-space char found
3193  line = -1;
3194  col = -1;
3195  return false;
3196 }
3197 
3198 /*
3199  Remove from the selection a start comment mark at
3200  the beginning and a stop comment mark at the end.
3201 */
3202 bool KateDocument::removeStartStopCommentFromSelection( KateView *view, int attrib )
3203 {
3204  const QString startComment = highlight()->getCommentStart( attrib );
3205  const QString endComment = highlight()->getCommentEnd( attrib );
3206 
3207  int sl = qMax<int> (0, view->selectionRange().start().line());
3208  int el = qMin<int> (view->selectionRange().end().line(), lastLine());
3209  int sc = view->selectionRange().start().column();
3210  int ec = view->selectionRange().end().column();
3211 
3212  // The selection ends on the char before selectEnd
3213  if (ec != 0) {
3214  --ec;
3215  } else if (el > 0) {
3216  --el;
3217  ec = m_buffer->plainLine(el)->length() - 1;
3218  }
3219 
3220  const int startCommentLen = startComment.length();
3221  const int endCommentLen = endComment.length();
3222 
3223  // had this been perl or sed: s/^\s*$startComment(.+?)$endComment\s*/$2/
3224 
3225  bool remove = nextNonSpaceCharPos(sl, sc)
3226  && m_buffer->plainLine(sl)->matchesAt(sc, startComment)
3227  && previousNonSpaceCharPos(el, ec)
3228  && ( (ec - endCommentLen + 1) >= 0 )
3229  && m_buffer->plainLine(el)->matchesAt(ec - endCommentLen + 1, endComment);
3230 
3231  if (remove) {
3232  editStart();
3233 
3234  removeText (KTextEditor::Range(el, ec - endCommentLen + 1, el, ec + 1));
3235  removeText (KTextEditor::Range(sl, sc, sl, sc + startCommentLen));
3236 
3237  editEnd ();
3238  // selection automatically updated (MovingRange)
3239  }
3240 
3241  return remove;
3242 }
3243 
3244 bool KateDocument::removeStartStopCommentFromRegion(const KTextEditor::Cursor &start,const KTextEditor::Cursor &end,int attrib)
3245 {
3246  const QString startComment = highlight()->getCommentStart( attrib );
3247  const QString endComment = highlight()->getCommentEnd( attrib );
3248  const int startCommentLen = startComment.length();
3249  const int endCommentLen = endComment.length();
3250 
3251  const bool remove = m_buffer->plainLine(start.line())->matchesAt(start.column(), startComment)
3252  && m_buffer->plainLine(end.line())->matchesAt(end.column() - endCommentLen , endComment);
3253  if (remove) {
3254  editStart();
3255  removeText(KTextEditor::Range(end.line(), end.column() - endCommentLen, end.line(), end.column()));
3256  removeText(KTextEditor::Range(start, startCommentLen));
3257  editEnd();
3258  }
3259  return remove;
3260 }
3261 
3262 /*
3263  Remove from the beginning of each line of the
3264  selection a start comment line mark.
3265 */
3266 bool KateDocument::removeStartLineCommentFromSelection( KateView *view, int attrib )
3267 {
3268  const QString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3269  const QString longCommentMark = shortCommentMark + ' ';
3270 
3271  int sl = view->selectionRange().start().line();
3272  int el = view->selectionRange().end().line();
3273 
3274  if ((view->selectionRange().end().column() == 0) && (el > 0))
3275  {
3276  el--;
3277  }
3278 
3279  bool removed = false;
3280 
3281  editStart();
3282 
3283  // For each line of the selection
3284  for (int z = el; z >= sl; z--)
3285  {
3286  // Try to remove the long comment mark first
3287  removed = (removeStringFromBeginning(z, longCommentMark)
3288  || removeStringFromBeginning(z, shortCommentMark)
3289  || removed);
3290  }
3291 
3292  editEnd();
3293  // selection automatically updated (MovingRange)
3294 
3295  return removed;
3296 }
3297 
3298 /*
3299  Comment or uncomment the selection or the current
3300  line if there is no selection.
3301 */
3302 void KateDocument::comment( KateView *v, uint line,uint column, int change)
3303 {
3304  // skip word wrap bug #105373
3305  const bool skipWordWrap = wordWrap();
3306  if (skipWordWrap) setWordWrap(false);
3307 
3308  bool hassel = v->selection();
3309  int c = 0;
3310 
3311  if ( hassel )
3312  c = v->selectionRange().start().column();
3313 
3314  int startAttrib = 0;
3315  Kate::TextLine ln = kateTextLine( line );
3316 
3317  if ( c < ln->length() )
3318  startAttrib = ln->attribute( c );
3319  else if ( !ln->contextStack().isEmpty() )
3320  startAttrib = highlight()->attribute( ln->contextStack().last() );
3321 
3322  bool hasStartLineCommentMark = !(highlight()->getCommentSingleLineStart( startAttrib ).isEmpty());
3323  bool hasStartStopCommentMark = ( !(highlight()->getCommentStart( startAttrib ).isEmpty())
3324  && !(highlight()->getCommentEnd( startAttrib ).isEmpty()) );
3325 
3326  bool removed = false;
3327 
3328  if (change > 0) // comment
3329  {
3330  if ( !hassel )
3331  {
3332  if ( hasStartLineCommentMark )
3333  addStartLineCommentToSingleLine( line, startAttrib );
3334  else if ( hasStartStopCommentMark )
3335  addStartStopCommentToSingleLine( line, startAttrib );
3336  }
3337  else
3338  {
3339  // anders: prefer single line comment to avoid nesting probs
3340  // If the selection starts after first char in the first line
3341  // or ends before the last char of the last line, we may use
3342  // multiline comment markers.
3343  // TODO We should try to detect nesting.
3344  // - if selection ends at col 0, most likely she wanted that
3345  // line ignored
3346  const KTextEditor::Range sel = v->selectionRange();
3347  if ( hasStartStopCommentMark &&
3348  ( !hasStartLineCommentMark || (
3349  ( sel.start().column() > m_buffer->plainLine( sel.start().line() )->firstChar() ) ||
3350  ( sel.end().column() > 0 &&
3351  sel.end().column() < (m_buffer->plainLine( sel.end().line() )->length()) )
3352  ) ) )
3353  addStartStopCommentToSelection( v, startAttrib );
3354  else if ( hasStartLineCommentMark )
3355  addStartLineCommentToSelection( v, startAttrib );
3356  }
3357  }
3358  else // uncomment
3359  {
3360  if ( !hassel )
3361  {
3362  removed = ( hasStartLineCommentMark
3363  && removeStartLineCommentFromSingleLine( line, startAttrib ) )
3364  || ( hasStartStopCommentMark
3365  && removeStartStopCommentFromSingleLine( line, startAttrib ) );
3366  }
3367  else
3368  {
3369  // anders: this seems like it will work with above changes :)
3370  removed = ( hasStartStopCommentMark
3371  && removeStartStopCommentFromSelection( v, startAttrib ) )
3372  || ( hasStartLineCommentMark
3373  && removeStartLineCommentFromSelection( v, startAttrib ) );
3374  }
3375 
3376  // recursive call for toggle comment
3377  if (!removed && change == 0)
3378  comment(v, line, column, 1);
3379  }
3380 
3381  if (skipWordWrap) setWordWrap(true); // see begin of function ::comment (bug #105373)
3382 }
3383 
3384 void KateDocument::transform( KateView *v, const KTextEditor::Cursor &c,
3385  KateDocument::TextTransform t )
3386 {
3387  if ( v->selection() )
3388  {
3389  editStart();
3390 
3391  // remember cursor
3392  KTextEditor::Cursor cursor = c;
3393 
3394  // cache the selection and cursor, so we can be sure to restore.
3395  KTextEditor::Range selection = v->selectionRange();
3396 
3397  KTextEditor::Range range(selection.start(), 0);
3398  while ( range.start().line() <= selection.end().line() )
3399  {
3400  int start = 0;
3401  int end = lineLength( range.start().line() );
3402 
3403  if (range.start().line() == selection.start().line() || v->blockSelection())
3404  start = selection.start().column();
3405 
3406  if (range.start().line() == selection.end().line() || v->blockSelection())
3407  end = selection.end().column();
3408 
3409  if ( start > end )
3410  {
3411  int swapCol = start;
3412  start = end;
3413  end = swapCol;
3414  }
3415  range.start().setColumn( start );
3416  range.end().setColumn( end );
3417 
3418  QString s = text( range );
3419  QString old = s;
3420 
3421  if ( t == Uppercase )
3422  s = s.toUpper();
3423  else if ( t == Lowercase )
3424  s = s.toLower();
3425  else // Capitalize
3426  {
3427  Kate::TextLine l = m_buffer->plainLine( range.start().line() );
3428  int p ( 0 );
3429  while( p < s.length() )
3430  {
3431  // If bol or the character before is not in a word, up this one:
3432  // 1. if both start and p is 0, upper char.
3433  // 2. if blockselect or first line, and p == 0 and start-1 is not in a word, upper
3434  // 3. if p-1 is not in a word, upper.
3435  if ( ( ! range.start().column() && ! p ) ||
3436  ( ( range.start().line() == selection.start().line() || v->blockSelection() ) &&
3437  ! p && ! highlight()->isInWord( l->at( range.start().column() - 1 )) ) ||
3438  ( p && ! highlight()->isInWord( s.at( p-1 ) ) )
3439  ) {
3440  s[p] = s.at(p).toUpper();
3441  }
3442  p++;
3443  }
3444  }
3445 
3446  if ( s != old )
3447  {
3448  removeText( range );
3449  insertText( range.start(), s );
3450  }
3451 
3452  range.setBothLines(range.start().line() + 1);
3453  }
3454 
3455  editEnd();
3456 
3457  // restore selection & cursor
3458  v->setSelection( selection );
3459  v->setCursorPosition( c );
3460 
3461  } else { // no selection
3462  editStart();
3463 
3464  // get cursor
3465  KTextEditor::Cursor cursor = c;
3466 
3467  QString old = text( KTextEditor::Range(cursor, 1) );
3468  QString s;
3469  switch ( t ) {
3470  case Uppercase:
3471  s = old.toUpper();
3472  break;
3473  case Lowercase:
3474  s = old.toLower();
3475  break;
3476  case Capitalize:
3477  {
3478  Kate::TextLine l = m_buffer->plainLine( cursor.line() );
3479  while ( cursor.column() > 0 && highlight()->isInWord( l->at( cursor.column() - 1 ), l->attribute( cursor.column() - 1 ) ) )
3480  cursor.setColumn(cursor.column() - 1);
3481  old = text( KTextEditor::Range(cursor, 1) );
3482  s = old.toUpper();
3483  }
3484  break;
3485  default:
3486  break;
3487  }
3488 
3489  removeText( KTextEditor::Range(cursor, 1) );
3490  insertText( cursor, s );
3491 
3492  editEnd();
3493  }
3494 
3495 }
3496 
3497 void KateDocument::joinLines( uint first, uint last )
3498 {
3499 // if ( first == last ) last += 1;
3500  editStart();
3501  int line( first );
3502  while ( first < last )
3503  {
3504  // Normalize the whitespace in the joined lines by making sure there's
3505  // always exactly one space between the joined lines
3506  // This cannot be done in editUnwrapLine, because we do NOT want this
3507  // behavior when deleting from the start of a line, just when explicitly
3508  // calling the join command
3509  Kate::TextLine l = kateTextLine( line );
3510  Kate::TextLine tl = kateTextLine( line + 1 );
3511 
3512  if ( !l || !tl )
3513  {
3514  editEnd();
3515  return;
3516  }
3517 
3518  int pos = tl->firstChar();
3519  if ( pos >= 0 )
3520  {
3521  if (pos != 0)
3522  editRemoveText( line + 1, 0, pos );
3523  if ( !( l->length() == 0 || l->at( l->length() - 1 ).isSpace() ) )
3524  editInsertText( line + 1, 0, " " );
3525  }
3526  else
3527  {
3528  // Just remove the whitespace and let Kate handle the rest
3529  editRemoveText( line + 1, 0, tl->length() );
3530  }
3531 
3532  editUnWrapLine( line );
3533  first++;
3534  }
3535  editEnd();
3536 }
3537 
3538 QString KateDocument::getWord( const KTextEditor::Cursor& cursor )
3539 {
3540  int start, end, len;
3541 
3542  Kate::TextLine textLine = m_buffer->plainLine(cursor.line());
3543  len = textLine->length();
3544  start = end = cursor.column();
3545  if (start > len) // Probably because of non-wrapping cursor mode.
3546  return QString();
3547 
3548  while (start > 0 && highlight()->isInWord(textLine->at(start - 1), textLine->attribute(start - 1))) start--;
3549  while (end < len && highlight()->isInWord(textLine->at(end), textLine->attribute(end))) end++;
3550  len = end - start;
3551  return textLine->string().mid(start, len);
3552 }
3553 
3554 void KateDocument::tagLines(int start, int end)
3555 {
3556  foreach(KateView *view,m_views)
3557  view->tagLines (start, end, true);
3558 }
3559 
3560 void KateDocument::repaintViews(bool paintOnlyDirty)
3561 {
3562  foreach(KateView *view,m_views)
3563  view->repaintText(paintOnlyDirty);
3564 }
3565 
3566 /*
3567  Bracket matching uses the following algorithm:
3568  If in overwrite mode, match the bracket currently underneath the cursor.
3569  Otherwise, if the character to the left is a bracket,
3570  match it. Otherwise if the character to the right of the cursor is a
3571  bracket, match it. Otherwise, don't match anything.
3572 */
3573 void KateDocument::newBracketMark( const KTextEditor::Cursor& cursor, KTextEditor::Range& bm, int maxLines )
3574 {
3575  // search from cursor for brackets
3576  KTextEditor::Range range (cursor, cursor);
3577 
3578  // if match found, remember the range
3579  if( findMatchingBracket( range, maxLines ) ) {
3580  bm = range;
3581  return;
3582  }
3583 
3584  // else, invalidate, if still valid
3585  if (bm.isValid())
3586  bm = KTextEditor::Range::invalid();
3587 }
3588 
3589 bool KateDocument::findMatchingBracket( KTextEditor::Range& range, int maxLines )
3590 {
3591  Kate::TextLine textLine = m_buffer->plainLine( range.start().line() );
3592  if( !textLine )
3593  return false;
3594 
3595  QChar right = textLine->at( range.start().column() );
3596  QChar left = textLine->at( range.start().column() - 1 );
3597  QChar bracket;
3598 
3599  if ( config()->ovr() ) {
3600  if( isBracket( right ) ) {
3601  bracket = right;
3602  } else {
3603  return false;
3604  }
3605  } else if ( isBracket( left ) ) {
3606  range.start().setColumn(range.start().column() - 1);
3607  bracket = left;
3608  } else if ( isBracket( right ) ) {
3609  bracket = right;
3610  } else {
3611  return false;
3612  }
3613 
3614  QChar opposite;
3615 
3616  switch( bracket.toAscii() ) {
3617  case '{': opposite = '}'; break;
3618  case '}': opposite = '{'; break;
3619  case '[': opposite = ']'; break;
3620  case ']': opposite = '['; break;
3621  case '(': opposite = ')'; break;
3622  case ')': opposite = '('; break;
3623  default: return false;
3624  }
3625 
3626  const int searchDir = isStartBracket( bracket ) ? 1 : -1;
3627  uint nesting = 0;
3628 
3629  int minLine = qMax( range.start().line() - maxLines, 0 );
3630  int maxLine = qMin( range.start().line() + maxLines, documentEnd().line() );
3631 
3632  range.end() = range.start();
3633  KTextEditor::DocumentCursor cursor(this);
3634  cursor.setPosition(range.start());
3635  int validAttr = kateTextLine(cursor.line())->attribute(cursor.column());
3636 
3637  while( cursor.line() >= minLine && cursor.line() <= maxLine ) {
3638 
3639  if (!cursor.move(searchDir))
3640  return false;
3641 
3642  Kate::TextLine textLine = kateTextLine(cursor.line());
3643  if (textLine->attribute(cursor.column()) == validAttr )
3644  {
3645  // Check for match
3646  QChar c = textLine->at(cursor.column());
3647  if( c == opposite ) {
3648  if( nesting == 0 ) {
3649  if (searchDir > 0) // forward
3650  range.end() = cursor.toCursor();
3651  else
3652  range.start() = cursor.toCursor();
3653  return true;
3654  }
3655  nesting--;
3656  } else if( c == bracket ) {
3657  nesting++;
3658  }
3659  }
3660  }
3661 
3662  return false;
3663 }
3664 
3665 // helper: remove \r and \n from visible document name (bug #170876)
3666 inline static QString removeNewLines(const QString& str)
3667 {
3668  QString tmp(str);
3669  return tmp.replace(QLatin1String("\r\n"), QLatin1String(" "))
3670  .replace(QChar('\r'), QLatin1Char(' '))
3671  .replace(QChar('\n'), QLatin1Char(' '));
3672 }
3673 
3674 void KateDocument::updateDocName ()
3675 {
3676  // if the name is set, and starts with FILENAME, it should not be changed!
3677  if ( ! url().isEmpty()
3678  && (m_docName == removeNewLines(url().fileName()) ||
3679  m_docName.startsWith (removeNewLines(url().fileName()) + " (") ) ) {
3680  return;
3681  }
3682 
3683  int count = -1;
3684 
3685 
3686  foreach(KateDocument* doc, KateGlobal::self()->kateDocuments())
3687  {
3688  if ( (doc != this) && (doc->url().fileName() == url().fileName()) )
3689  if ( doc->m_docNameNumber > count )
3690  count = doc->m_docNameNumber;
3691  }
3692 
3693  m_docNameNumber = count + 1;
3694 
3695  QString oldName = m_docName;
3696  m_docName = removeNewLines(url().fileName());
3697 
3698  m_isUntitled = m_docName.isEmpty();
3699  if (m_isUntitled) {
3700  m_docName = i18n ("Untitled");
3701  }
3702 
3703  if (m_docNameNumber > 0)
3704  m_docName = QString(m_docName + " (%1)").arg(m_docNameNumber+1);
3705 
3709  if (oldName != m_docName)
3710  emit documentNameChanged (this);
3711 }
3712 
3713 void KateDocument::slotModifiedOnDisk( KTextEditor::View * /*v*/ )
3714 {
3715  if ( m_isasking < 0 )
3716  {
3717  m_isasking = 0;
3718  return;
3719  }
3720 
3721  if ( !m_fileChangedDialogsActivated || m_isasking )
3722  return;
3723 
3724  if (m_modOnHd && !url().isEmpty())
3725  {
3726  m_isasking = 1;
3727 
3728  QWidget *parentWidget(dialogParent());
3729 
3730  KateModOnHdPrompt p( this, m_modOnHdReason, reasonedMOHString(), parentWidget );
3731  switch ( p.exec() )
3732  {
3733  case KateModOnHdPrompt::Save:
3734  {
3735  m_modOnHd = false;
3736  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
3737  url().url(),QString(),parentWidget,i18n("Save File"));
3738 
3739  kDebug(13020)<<"got "<<res.URLs.count()<<" URLs";
3740  if( ! res.URLs.isEmpty() && ! res.URLs.first().isEmpty() && checkOverwrite( res.URLs.first(), parentWidget ) )
3741  {
3742  setEncoding( res.encoding );
3743 
3744  if( ! saveAs( res.URLs.first() ) )
3745  {
3746  KMessageBox::error( parentWidget, i18n("Save failed") );
3747  m_modOnHd = true;
3748  }
3749  else
3750  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3751  }
3752  else // the save as dialog was canceled, we are still modified on disk
3753  {
3754  m_modOnHd = true;
3755  }
3756 
3757  m_isasking = 0;
3758  break;
3759  }
3760 
3761  case KateModOnHdPrompt::Reload:
3762  m_modOnHd = false;
3763  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3764  documentReload();
3765  m_isasking = 0;
3766  break;
3767 
3768  case KateModOnHdPrompt::Ignore:
3769  m_modOnHd = false;
3770  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3771  m_isasking = 0;
3772  break;
3773 
3774  case KateModOnHdPrompt::Overwrite:
3775  m_modOnHd = false;
3776  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3777  m_isasking = 0;
3778  save();
3779  break;
3780 
3781  default: // Delay/cancel: ignore next focus event
3782  m_isasking = -1;
3783  }
3784  }
3785 }
3786 
3787 void KateDocument::setModifiedOnDisk( ModifiedOnDiskReason reason )
3788 {
3789  m_modOnHdReason = reason;
3790  m_modOnHd = (reason != OnDiskUnmodified);
3791  emit modifiedOnDisk( this, (reason != OnDiskUnmodified), reason );
3792 }
3793 
3794 class KateDocumentTmpMark
3795 {
3796  public:
3797  QString line;
3798  KTextEditor::Mark mark;
3799 };
3800 
3801 void KateDocument::setModifiedOnDiskWarning (bool on)
3802 {
3803  m_fileChangedDialogsActivated = on;
3804 }
3805 
3806 bool KateDocument::documentReload()
3807 {
3808  if ( !url().isEmpty() )
3809  {
3810  if (m_modOnHd && m_fileChangedDialogsActivated)
3811  {
3812  QWidget *parentWidget(dialogParent());
3813 
3814  int i = KMessageBox::warningYesNoCancel
3815  (parentWidget, reasonedMOHString() + "\n\n" + i18n("What do you want to do?"),
3816  i18n("File Was Changed on Disk"),
3817  KGuiItem(i18n("&Reload File"), "view-refresh"),
3818  KGuiItem(i18n("&Ignore Changes"), "dialog-warning"));
3819 
3820  if ( i != KMessageBox::Yes)
3821  {
3822  if (i == KMessageBox::No)
3823  {
3824  m_modOnHd = false;
3825  m_modOnHdReason = OnDiskUnmodified;
3826  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
3827  }
3828 
3829  // reset some flags only valid for one reload!
3830  m_userSetEncodingForNextReload = false;
3831  return false;
3832  }
3833  }
3834 
3835  emit aboutToReload(this);
3836 
3837  QList<KateDocumentTmpMark> tmp;
3838 
3839  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
3840  {
3841  KateDocumentTmpMark m;
3842 
3843  m.line = line (i.value()->line);
3844  m.mark = *i.value();
3845 
3846  tmp.append (m);
3847  }
3848 
3849  const QString oldMode = mode ();
3850  const bool byUser = m_fileTypeSetByUser;
3851  const QString hl_mode = highlightingMode ();
3852  KTextEditor::View* oldActiveView = activeView();
3853 
3854  m_storedVariables.clear();
3855 
3856  // save cursor positions for all views
3857  QVector<KTextEditor::Cursor> cursorPositions;
3858  cursorPositions.reserve(m_views.size());
3859  foreach (KateView *v, m_views)
3860  cursorPositions.append( v->cursorPosition() );
3861 
3862  m_reloading = true;
3863  KateDocument::openUrl( url() );
3864 
3865  // reset some flags only valid for one reload!
3866  m_userSetEncodingForNextReload = false;
3867 
3868  // restore cursor positions for all views
3869  QLinkedList<KateView*>::iterator it = m_views.begin();
3870  for(int i = 0; i < m_views.size(); ++i, ++it) {
3871  setActiveView(*it);
3872  (*it)->setCursorPositionInternal( cursorPositions.at(i), m_config->tabWidth(), false );
3873  if ((*it)->isVisible()) {
3874  (*it)->repaintText(false);
3875  }
3876  }
3877  setActiveView(oldActiveView);
3878 
3879  for (int z=0; z < tmp.size(); z++)
3880  {
3881  if (z < (int)lines())
3882  {
3883  if (line(tmp.at(z).mark.line) == tmp.at(z).line)
3884  setMark (tmp.at(z).mark.line, tmp.at(z).mark.type);
3885  }
3886  }
3887 
3888  if (byUser)
3889  setMode (oldMode);
3890  setHighlightingMode (hl_mode);
3891 
3892  emit reloaded(this);
3893 
3894  return true;
3895  }
3896 
3897  return false;
3898 }
3899 
3900 bool KateDocument::documentSave()
3901 {
3902  if( !url().isValid() || !isReadWrite() )
3903  return documentSaveAs();
3904 
3905  return save();
3906 }
3907 
3908 bool KateDocument::documentSaveAs()
3909 {
3910  QWidget *parentWidget(dialogParent());
3911 
3912  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
3913  url().url(),QString(),parentWidget,i18n("Save File"));
3914 
3915  if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first(), parentWidget ) )
3916  return false;
3917 
3918  setEncoding( res.encoding );
3919 
3920  return saveAs( res.URLs.first() );
3921 }
3922 
3923 void KateDocument::setWordWrap (bool on)
3924 {
3925  config()->setWordWrap (on);
3926 }
3927 
3928 bool KateDocument::wordWrap () const
3929 {
3930  return config()->wordWrap ();
3931 }
3932 
3933 void KateDocument::setWordWrapAt (uint col)
3934 {
3935  config()->setWordWrapAt (col);
3936 }
3937 
3938 unsigned int KateDocument::wordWrapAt () const
3939 {
3940  return config()->wordWrapAt ();
3941 }
3942 
3943 void KateDocument::setPageUpDownMovesCursor (bool on)
3944 {
3945  config()->setPageUpDownMovesCursor (on);
3946 }
3947 
3948 bool KateDocument::pageUpDownMovesCursor () const
3949 {
3950  return config()->pageUpDownMovesCursor ();
3951 }
3952 //END
3953 
3954 bool KateDocument::setEncoding (const QString &e)
3955 {
3956  return m_config->setEncoding(e);
3957 }
3958 
3959 const QString &KateDocument::encoding() const
3960 {
3961  return m_config->encoding();
3962 }
3963 
3964 void KateDocument::updateConfig ()
3965 {
3966  m_undoManager->updateConfig ();
3967 
3968  // switch indenter if needed and update config....
3969  m_indenter->setMode (m_config->indentationMode());
3970  m_indenter->updateConfig();
3971 
3972  // set tab width there, too
3973  m_buffer->setTabWidth (config()->tabWidth());
3974 
3975  // update all views, does tagAll and updateView...
3976  foreach (KateView * view, m_views)
3977  view->updateDocumentConfig ();
3978 
3979  // update on-the-fly spell checking as spell checking defaults might have changes
3980  if(m_onTheFlyChecker) {
3981  m_onTheFlyChecker->updateConfig();
3982  }
3983 
3984  emit configChanged();
3985 }
3986 
3987 //BEGIN Variable reader
3988 // "local variable" feature by anders, 2003
3989 /* TODO
3990  add config options (how many lines to read, on/off)
3991  add interface for plugins/apps to set/get variables
3992  add view stuff
3993 */
3994 QRegExp KateDocument::kvLine = QRegExp("kate:(.*)");
3995 QRegExp KateDocument::kvLineWildcard = QRegExp("kate-wildcard\\((.*)\\):(.*)");
3996 QRegExp KateDocument::kvLineMime = QRegExp("kate-mimetype\\((.*)\\):(.*)");
3997 QRegExp KateDocument::kvVar = QRegExp("([\\w\\-]+)\\s+([^;]+)");
3998 
3999 void KateDocument::readVariables(bool onlyViewAndRenderer)
4000 {
4001  if (!onlyViewAndRenderer)
4002  m_config->configStart();
4003 
4004  // views!
4005  KateView *v;
4006  foreach (v,m_views)
4007  {
4008  v->config()->configStart();
4009  v->renderer()->config()->configStart();
4010  }
4011  // read a number of lines in the top/bottom of the document
4012  for (int i=0; i < qMin( 9, lines() ); ++i )
4013  {
4014  readVariableLine( line( i ), onlyViewAndRenderer );
4015  }
4016  if ( lines() > 10 )
4017  {
4018  for ( int i = qMax( 10, lines() - 10); i < lines(); i++ )
4019  {
4020  readVariableLine( line( i ), onlyViewAndRenderer );
4021  }
4022  }
4023 
4024  if (!onlyViewAndRenderer)
4025  m_config->configEnd();
4026 
4027  foreach (v,m_views)
4028  {
4029  v->config()->configEnd();
4030  v->renderer()->config()->configEnd();
4031  }
4032 }
4033 
4034 void KateDocument::readVariableLine( QString t, bool onlyViewAndRenderer )
4035 {
4036  // simple check first, no regex
4037  // no kate inside, no vars, simple...
4038  if (!t.contains("kate"))
4039  return;
4040 
4041  // found vars, if any
4042  QString s;
4043 
4044  // now, try first the normal ones
4045  if ( kvLine.indexIn( t ) > -1 )
4046  {
4047  s = kvLine.cap(1);
4048 
4049  kDebug (13020) << "normal variable line kate: matched: " << s;
4050  }
4051  else if (kvLineWildcard.indexIn( t ) > -1) // regex given
4052  {
4053  const QStringList wildcards (kvLineWildcard.cap(1).split (';', QString::SkipEmptyParts));
4054  const QString nameOfFile = url().fileName();
4055 
4056  bool found = false;
4057  foreach(const QString& pattern, wildcards)
4058  {
4059  QRegExp wildcard (pattern, Qt::CaseSensitive, QRegExp::Wildcard);
4060 
4061  found = wildcard.exactMatch (nameOfFile);
4062  }
4063 
4064  // nothing usable found...
4065  if (!found)
4066  return;
4067 
4068  s = kvLineWildcard.cap(2);
4069 
4070  kDebug (13020) << "guarded variable line kate-wildcard: matched: " << s;
4071  }
4072  else if (kvLineMime.indexIn( t ) > -1) // mime-type given
4073  {
4074  const QStringList types (kvLineMime.cap(1).split (';', QString::SkipEmptyParts));
4075 
4076  // no matching type found
4077  if (!types.contains (mimeType ()))
4078  return;
4079 
4080  s = kvLineMime.cap(2);
4081 
4082  kDebug (13020) << "guarded variable line kate-mimetype: matched: " << s;
4083  }
4084  else // nothing found
4085  {
4086  return;
4087  }
4088 
4089  QStringList vvl; // view variable names
4090  vvl << "dynamic-word-wrap" << "dynamic-word-wrap-indicators"
4091  << "line-numbers" << "icon-border" << "folding-markers"
4092  << "bookmark-sorting" << "auto-center-lines"
4093  << "icon-bar-color"
4094  // renderer
4095  << "background-color" << "selection-color"
4096  << "current-line-color" << "bracket-highlight-color"
4097  << "word-wrap-marker-color"
4098  << "font" << "font-size" << "scheme";
4099  int spaceIndent = -1; // for backward compatibility; see below
4100  bool replaceTabsSet = false;
4101  int p( 0 );
4102 
4103  QString var, val;
4104  while ( (p = kvVar.indexIn( s, p )) > -1 )
4105  {
4106  p += kvVar.matchedLength();
4107  var = kvVar.cap( 1 );
4108  val = kvVar.cap( 2 ).trimmed();
4109  bool state; // store booleans here
4110  int n; // store ints here
4111 
4112  // only apply view & renderer config stuff
4113  if (onlyViewAndRenderer)
4114  {
4115  if ( vvl.contains( var ) ) // FIXME define above
4116  setViewVariable( var, val );
4117  }
4118  else
4119  {
4120  // BOOL SETTINGS
4121  if ( var == "word-wrap" && checkBoolValue( val, &state ) )
4122  setWordWrap( state ); // ??? FIXME CHECK
4123  // KateConfig::configFlags
4124  // FIXME should this be optimized to only a few calls? how?
4125  else if ( var == "backspace-indents" && checkBoolValue( val, &state ) )
4126  m_config->setBackspaceIndents( state );
4127  else if ( var == "indent-pasted-text" && checkBoolValue( val, &state ) )
4128  m_config->setIndentPastedText( state );
4129  else if ( var == "replace-tabs" && checkBoolValue( val, &state ) )
4130  {
4131  m_config->setReplaceTabsDyn( state );
4132  replaceTabsSet = true; // for backward compatibility; see below
4133  }
4134  else if ( var == "remove-trailing-space" && checkBoolValue( val, &state ) ) {
4135  kWarning() << i18n("Using deprecated modeline 'remove-trailing-space'. "
4136  "Please replace with 'remove-trailing-spaces modified;', see "
4137  "http://docs.kde.org/stable/en/applications/kate/config-variables.html#variable-remove-trailing-spaces");
4138  m_config->setRemoveSpaces( state ? 1 : 0 );
4139  }
4140  else if ( var == "replace-trailing-space-save" && checkBoolValue( val, &state ) ) {
4141  kWarning() << i18n("Using deprecated modeline 'replace-trailing-space-save'. "
4142  "Please replace with 'remove-trailing-spaces all;', see "
4143  "http://docs.kde.org/stable/en/applications/kate/config-variables.html#variable-remove-trailing-spaces");
4144  m_config->setRemoveSpaces( state ? 2 : 0 );
4145  }
4146  else if ( var == "overwrite-mode" && checkBoolValue( val, &state ) )
4147  m_config->setOvr( state );
4148  else if ( var == "keep-extra-spaces" && checkBoolValue( val, &state ) )
4149  m_config->setKeepExtraSpaces( state );
4150  else if ( var == "tab-indents" && checkBoolValue( val, &state ) )
4151  m_config->setTabIndents( state );
4152  else if ( var == "show-tabs" && checkBoolValue( val, &state ) )
4153  m_config->setShowTabs( state );
4154  else if ( var == "show-trailing-spaces" && checkBoolValue( val, &state ) )
4155  m_config->setShowSpaces( state );
4156  else if ( var == "space-indent" && checkBoolValue( val, &state ) )
4157  {
4158  // this is for backward compatibility; see below
4159  spaceIndent = state;
4160  }
4161  else if ( var == "smart-home" && checkBoolValue( val, &state ) )
4162  m_config->setSmartHome( state );
4163  else if ( var == "newline-at-eof" && checkBoolValue( val, &state ) )
4164  m_config->setNewLineAtEof( state );
4165 
4166  // INTEGER SETTINGS
4167  else if ( var == "tab-width" && checkIntValue( val, &n ) )
4168  m_config->setTabWidth( n );
4169  else if ( var == "indent-width" && checkIntValue( val, &n ) )
4170  m_config->setIndentationWidth( n );
4171  else if ( var == "indent-mode" )
4172  {
4173  m_config->setIndentationMode( val );
4174  }
4175  else if ( var == "word-wrap-column" && checkIntValue( val, &n ) && n > 0 ) // uint, but hard word wrap at 0 will be no fun ;)
4176  m_config->setWordWrapAt( n );
4177 
4178  // STRING SETTINGS
4179  else if ( var == "eol" || var == "end-of-line" )
4180  {
4181  QStringList l;
4182  l << "unix" << "dos" << "mac";
4183  if ( (n = l.indexOf( val.toLower() )) != -1 )
4184  m_config->setEol( n );
4185  }
4186  else if (var == "bom" || var =="byte-order-marker")
4187  {
4188  if (checkBoolValue(val,&state)) {
4189  m_config->setBom(state);
4190  }
4191  }
4192  else if ( var == "remove-trailing-spaces" ) {
4193  val = val.toLower();
4194  if (val == "1" || val == "modified" || val == "mod" || val == "+") {
4195  m_config->setRemoveSpaces(1);
4196  } else if (val == "2" || val == "all" || val == "*") {
4197  m_config->setRemoveSpaces(2);
4198  } else {
4199  m_config->setRemoveSpaces(0);
4200  }
4201  }
4202  else if ( var == "syntax" || var == "hl" )
4203  {
4204  setHighlightingMode( val );
4205  }
4206  else if ( var == "mode" )
4207  {
4208  setMode( val );
4209  }
4210  else if ( var == "encoding" )
4211  {
4212  setEncoding( val );
4213  }
4214  else if ( var == "default-dictionary" )
4215  {
4216  setDefaultDictionary( val );
4217  }
4218  else if ( var == "automatic-spell-checking" && checkBoolValue( val, &state ) )
4219  {
4220  onTheFlySpellCheckingEnabled( state );
4221  }
4222 
4223  // VIEW SETTINGS
4224  else if ( vvl.contains( var ) )
4225  setViewVariable( var, val );
4226  else
4227  {
4228  m_storedVariables.insert( var, val );
4229  emit variableChanged( this, var, val );
4230  }
4231  }
4232  }
4233 
4234  // Backward compatibility
4235  // If space-indent was set, but replace-tabs was not set, we assume
4236  // that the user wants to replace tabulators and set that flag.
4237  // If both were set, replace-tabs has precedence.
4238  // At this point spaceIndent is -1 if it was never set,
4239  // 0 if it was set to off, and 1 if it was set to on.
4240  // Note that if onlyViewAndRenderer was requested, spaceIndent is -1.
4241  if ( !replaceTabsSet && spaceIndent >= 0 )
4242  {
4243  m_config->setReplaceTabsDyn( spaceIndent > 0 );
4244  }
4245 }
4246 
4247 void KateDocument::setViewVariable( QString var, QString val )
4248 {
4249  KateView *v;
4250  bool state;
4251  int n;
4252  QColor c;
4253  foreach (v,m_views)
4254  {
4255  if ( var == "dynamic-word-wrap" && checkBoolValue( val, &state ) )
4256  v->config()->setDynWordWrap( state );
4257  else if ( var == "persistent-selection" && checkBoolValue( val, &state ) )
4258  v->config()->setPersistentSelection( state );
4259  else if ( var == "block-selection" && checkBoolValue( val, &state ) )
4260  v->setBlockSelection( state );
4261  //else if ( var = "dynamic-word-wrap-indicators" )
4262  else if ( var == "line-numbers" && checkBoolValue( val, &state ) )
4263  v->config()->setLineNumbers( state );
4264  else if (var == "icon-border" && checkBoolValue( val, &state ) )
4265  v->config()->setIconBar( state );
4266  else if (var == "folding-markers" && checkBoolValue( val, &state ) )
4267  v->config()->setFoldingBar( state );
4268  else if ( var == "auto-center-lines" && checkIntValue( val, &n ) )
4269  v->config()->setAutoCenterLines( n );
4270  else if ( var == "icon-bar-color" && checkColorValue( val, c ) )
4271  v->renderer()->config()->setIconBarColor( c );
4272  // RENDERER
4273  else if ( var == "background-color" && checkColorValue( val, c ) )
4274  v->renderer()->config()->setBackgroundColor( c );
4275  else if ( var == "selection-color" && checkColorValue( val, c ) )
4276  v->renderer()->config()->setSelectionColor( c );
4277  else if ( var == "current-line-color" && checkColorValue( val, c ) )
4278  v->renderer()->config()->setHighlightedLineColor( c );
4279  else if ( var == "bracket-highlight-color" && checkColorValue( val, c ) )
4280  v->renderer()->config()->setHighlightedBracketColor( c );
4281  else if ( var == "word-wrap-marker-color" && checkColorValue( val, c ) )
4282  v->renderer()->config()->setWordWrapMarkerColor( c );
4283  else if ( var == "font" || ( var == "font-size" && checkIntValue( val, &n ) ) )
4284  {
4285  QFont _f( v->renderer()->config()->font() );
4286 
4287  if ( var == "font" )
4288  {
4289  _f.setFamily( val );
4290  _f.setFixedPitch( QFont( val ).fixedPitch() );
4291  }
4292  else
4293  _f.setPointSize( n );
4294 
4295  v->renderer()->config()->setFont( _f );
4296  }
4297  else if ( var == "scheme" )
4298  {
4299  v->renderer()->config()->setSchema( val );
4300  }
4301  }
4302 }
4303 
4304 bool KateDocument::checkBoolValue( QString val, bool *result )
4305 {
4306  val = val.trimmed().toLower();
4307  QStringList l;
4308  l << "1" << "on" << "true";
4309  if ( l.contains( val ) )
4310  {
4311  *result = true;
4312  return true;
4313  }
4314  l.clear();
4315  l << "0" << "off" << "false";
4316  if ( l.contains( val ) )
4317  {
4318  *result = false;
4319  return true;
4320  }
4321  return false;
4322 }
4323 
4324 bool KateDocument::checkIntValue( QString val, int *result )
4325 {
4326  bool ret( false );
4327  *result = val.toInt( &ret );
4328  return ret;
4329 }
4330 
4331 bool KateDocument::checkColorValue( QString val, QColor &c )
4332 {
4333  c.setNamedColor( val );
4334  return c.isValid();
4335 }
4336 
4337 // KTextEditor::variable
4338 QString KateDocument::variable( const QString &name ) const
4339 {
4340  return m_storedVariables.value(name, QString());
4341 }
4342 
4343 QString KateDocument::setVariable( const QString &name, const QString &value)
4344 {
4345  QString s = "kate: ";
4346  s.append(name);
4347  s.append(" ");
4348  s.append(value);
4349  readVariableLine(s);
4350  return m_storedVariables.value(name, QString());
4351 }
4352 
4353 //END
4354 
4355 void KateDocument::slotModOnHdDirty (const QString &path)
4356 {
4357  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskModified))
4358  {
4359  // compare md5 with the one we have (if we have one)
4360  if ( !digest().isEmpty() )
4361  {
4362  QByteArray oldDigest = digest();
4363  if ( createDigest () && oldDigest == digest() ) {
4364  return;
4365  }
4366  }
4367 
4368  m_modOnHd = true;
4369  m_modOnHdReason = OnDiskModified;
4370 
4371  // reenable dialog if not running atm
4372  if (m_isasking == -1)
4373  m_isasking = false;
4374 
4375  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4376  }
4377 }
4378 
4379 void KateDocument::slotModOnHdCreated (const QString &path)
4380 {
4381  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskCreated))
4382  {
4383  m_modOnHd = true;
4384  m_modOnHdReason = OnDiskCreated;
4385 
4386  // reenable dialog if not running atm
4387  if (m_isasking == -1)
4388  m_isasking = false;
4389 
4390  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4391  }
4392 }
4393 
4394 void KateDocument::slotModOnHdDeleted (const QString &path)
4395 {
4396  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskDeleted))
4397  {
4398  m_modOnHd = true;
4399  m_modOnHdReason = OnDiskDeleted;
4400 
4401  // reenable dialog if not running atm
4402  if (m_isasking == -1)
4403  m_isasking = false;
4404 
4405  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4406  }
4407 }
4408 
4409 const QByteArray &KateDocument::digest () const
4410 {
4411  return m_buffer->digest();
4412 }
4413 
4414 bool KateDocument::createDigest ()
4415 {
4416  QByteArray md5sum;
4417 
4418  if ( url().isLocalFile() )
4419  {
4420  QFile f ( url().toLocalFile() );
4421  if ( f.open( QIODevice::ReadOnly) )
4422  {
4423  QCryptographicHash crypto(QCryptographicHash::Md5);
4424  while(!f.atEnd())
4425  crypto.addData (f.read(256 * 1024));
4426  md5sum = crypto.result();
4427  }
4428  }
4429 
4430  m_buffer->setDigest( md5sum );
4431 
4432  return !md5sum.isEmpty();
4433 }
4434 
4435 QString KateDocument::reasonedMOHString() const
4436 {
4437  // squeeze path
4438  QString str = KStringHandler::csqueeze(url().pathOrUrl());
4439 
4440  switch( m_modOnHdReason )
4441  {
4442  case OnDiskModified:
4443  return i18n("The file '%1' was modified by another program.", str );
4444  break;
4445  case OnDiskCreated:
4446  return i18n("The file '%1' was created by another program.", str );
4447  break;
4448  case OnDiskDeleted:
4449  return i18n("The file '%1' was deleted by another program.", str );
4450  break;
4451  default:
4452  return QString();
4453  }
4454  return QString();
4455 }
4456 
4457 void KateDocument::removeTrailingSpaces()
4458 {
4459  const int remove = config()->removeSpaces();
4460  if (remove == 0)
4461  return;
4462 
4463  // temporarily disable static word wrap (see bug #328900)
4464  const bool wordWrapEnabled = config()->wordWrap ();
4465  if (wordWrapEnabled) setWordWrap(false);
4466 
4467  // get cursor position of active view
4468  KTextEditor::Cursor curPos = KTextEditor::Cursor::invalid();
4469  if (activeView()) {
4470  curPos = activeView()->cursorPosition();
4471  }
4472 
4473  editStart();
4474 
4475  for (int line = 0; line < lines(); ++line)
4476  {
4477  Kate::TextLine textline = plainKateTextLine(line);
4478 
4479  // remove trailing spaces in entire document, remove = 2
4480  // remove trailing spaces of touched lines, remove = 1
4481  // remove trailing spaces of lines saved on disk, remove = 1
4482  if (remove == 2 || textline->markedAsModified() || textline->markedAsSavedOnDisk()) {
4483  const int p = textline->lastChar() + 1;
4484  const int l = textline->length() - p;
4485  if (l > 0 ) {
4486  // if the cursor is in the trailing space, only delete behind cursor
4487  if (curPos.line() != line || curPos.column() <= p || curPos.column() > p + l) {
4488  editRemoveText(line, p, l);
4489  } else {
4490  editRemoveText(line, curPos.column(), l - (curPos.column() - p));
4491  }
4492  }
4493  }
4494  }
4495 
4496  editEnd();
4497 
4498  // enable word wrap again, if it was enabled (see bug #328900)
4499  if (wordWrapEnabled) setWordWrap(true); // see begin of this function
4500 }
4501 
4502 
4503 void KateDocument::updateFileType (const QString &newType, bool user)
4504 {
4505  if (user || !m_fileTypeSetByUser)
4506  {
4507  if (!newType.isEmpty())
4508  {
4509  // remember that we got set by user
4510  m_fileTypeSetByUser = user;
4511 
4512  m_fileType = newType;
4513 
4514  m_config->configStart();
4515 
4516  if (!m_hlSetByUser && !KateGlobal::self()->modeManager()->fileType(newType).hl.isEmpty())
4517  {
4518  int hl (KateHlManager::self()->nameFind (KateGlobal::self()->modeManager()->fileType(newType).hl));
4519 
4520  if (hl >= 0)
4521  m_buffer->setHighlight(hl);
4522  }
4523 
4528  if (!m_indenterSetByUser && !KateGlobal::self()->modeManager()->fileType(newType).indenter.isEmpty())
4529  config()->setIndentationMode (KateGlobal::self()->modeManager()->fileType(newType).indenter);
4530 
4531  // views!
4532  KateView *v;
4533  foreach (v,m_views)
4534  {
4535  v->config()->configStart();
4536  v->renderer()->config()->configStart();
4537  }
4538 
4539  bool bom_settings = false;
4540  if (m_bomSetByUser)
4541  bom_settings=m_config->bom();
4542  readVariableLine( KateGlobal::self()->modeManager()->fileType(newType).varLine );
4543  if (m_bomSetByUser)
4544  m_config->setBom(bom_settings);
4545  m_config->configEnd();
4546  foreach (v,m_views)
4547  {
4548  v->config()->configEnd();
4549  v->renderer()->config()->configEnd();
4550  }
4551  }
4552  }
4553 
4554  // fixme, make this better...
4555  emit modeChanged (this);
4556 }
4557 
4558 void KateDocument::slotQueryClose_save(bool *handled, bool* abortClosing) {
4559  *handled=true;
4560  *abortClosing=true;
4561  if (this->url().isEmpty())
4562  {
4563  QWidget *parentWidget(dialogParent());
4564 
4565  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
4566  QString(),QString(),parentWidget,i18n("Save File"));
4567 
4568  if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first(), parentWidget ) ) {
4569  *abortClosing=true;
4570  return;
4571  }
4572  setEncoding( res.encoding );
4573  saveAs( res.URLs.first() );
4574  *abortClosing=false;
4575  }
4576  else
4577  {
4578  save();
4579  *abortClosing=false;
4580  }
4581 
4582 }
4583 
4584 bool KateDocument::checkOverwrite( KUrl u, QWidget *parent )
4585 {
4586  if( !u.isLocalFile() )
4587  return true;
4588 
4589  QFileInfo info( u.path() );
4590  if( !info.exists() )
4591  return true;
4592 
4593  return KMessageBox::Cancel != KMessageBox::warningContinueCancel( parent,
4594  i18n( "A file named \"%1\" already exists. "
4595  "Are you sure you want to overwrite it?" , info.fileName() ),
4596  i18n( "Overwrite File?" ), KStandardGuiItem::overwrite(),
4597  KStandardGuiItem::cancel(), QString(), KMessageBox::Notify | KMessageBox::Dangerous );
4598 }
4599 
4600 //BEGIN KTextEditor::ConfigInterface
4601 
4602 // BEGIN ConfigInterface stff
4603 QStringList KateDocument::configKeys() const
4604 {
4605  return QStringList() << "tab-width" << "indent-width";
4606 }
4607 
4608 QVariant KateDocument::configValue(const QString &key)
4609 {
4610  if (key == "backup-on-save-local") {
4611  return m_config->backupFlags() & KateDocumentConfig::LocalFiles;
4612  } else if (key == "backup-on-save-remote") {
4613  return m_config->backupFlags() & KateDocumentConfig::RemoteFiles;
4614  } else if (key == "backup-on-save-suffix") {
4615  return m_config->backupSuffix();
4616  } else if (key == "backup-on-save-prefix") {
4617  return m_config->backupPrefix();
4618  } else if (key == "replace-tabs") {
4619  return m_config->replaceTabsDyn();
4620  } else if (key == "indent-pasted-text") {
4621  return m_config->indentPastedText();
4622  } else if (key == "tab-width") {
4623  return m_config->tabWidth();
4624  } else if (key == "indent-width") {
4625  return m_config->indentationWidth();
4626  }
4627 
4628  // return invalid variant
4629  return QVariant();
4630 }
4631 
4632 void KateDocument::setConfigValue(const QString &key, const QVariant &value)
4633 {
4634  if (value.type() == QVariant::String) {
4635  if (key == "backup-on-save-suffix") {
4636  m_config->setBackupSuffix(value.toString());
4637  } else if (key == "backup-on-save-prefix") {
4638  m_config->setBackupPrefix(value.toString());
4639  }
4640  } else if (value.canConvert(QVariant::Bool)) {
4641  const bool bValue = value.toBool();
4642  if (key == "backup-on-save-local" && value.type() == QVariant::String) {
4643  uint f = m_config->backupFlags();
4644  if (bValue) {
4645  f |= KateDocumentConfig::LocalFiles;
4646  } else {
4647  f ^= KateDocumentConfig::LocalFiles;
4648  }
4649 
4650  m_config->setBackupFlags(f);
4651  } else if (key == "backup-on-save-remote") {
4652  uint f = m_config->backupFlags();
4653  if (bValue) {
4654  f |= KateDocumentConfig::RemoteFiles;
4655  } else {
4656  f ^= KateDocumentConfig::RemoteFiles;
4657  }
4658 
4659  m_config->setBackupFlags(f);
4660  } else if (key == "replace-tabs") {
4661  m_config->setReplaceTabsDyn(bValue);
4662  } else if (key == "indent-pasted-text") {
4663  m_config->setIndentPastedText(bValue);
4664  }
4665  } else if (value.canConvert(QVariant::Int)) {
4666  if (key == "tab-width") {
4667  config()->setTabWidth(value.toInt());
4668  } else if (key == "indent-width") {
4669  config()->setIndentationWidth(value.toInt());
4670  }
4671  }
4672 }
4673 
4674 //END KTextEditor::ConfigInterface
4675 
4676 KateView * KateDocument::activeKateView( ) const
4677 {
4678  return static_cast<KateView*>(m_activeView);
4679 }
4680 
4681 KTextEditor::Cursor KateDocument::documentEnd( ) const
4682 {
4683  return KTextEditor::Cursor(lastLine(), lineLength(lastLine()));
4684 }
4685 
4686 bool KateDocument::replaceText( const KTextEditor::Range & range, const QString & s, bool block )
4687 {
4688  // TODO more efficient?
4689  editStart();
4690  bool changed = removeText(range, block);
4691  changed |= insertText(range.start(), s, block);
4692  editEnd();
4693  return changed;
4694 }
4695 
4696 void KateDocument::ignoreModifiedOnDiskOnce( )
4697 {
4698  m_isasking = -1;
4699 }
4700 
4701 KateHighlighting * KateDocument::highlight( ) const
4702 {
4703  return m_buffer->highlight();
4704 }
4705 
4706 Kate::TextLine KateDocument::kateTextLine( uint i )
4707 {
4708  m_buffer->ensureHighlighted (i);
4709  return m_buffer->plainLine (i);
4710 }
4711 
4712 Kate::TextLine KateDocument::plainKateTextLine( uint i )
4713 {
4714  return m_buffer->plainLine (i);
4715 }
4716 
4717 bool KateDocument::isEditRunning() const
4718 {
4719  return editIsRunning;
4720 }
4721 
4722 void KateDocument::setUndoMergeAllEdits(bool merge)
4723 {
4724  if (merge && m_undoMergeAllEdits)
4725  {
4726  // Don't add another undo safe point: it will override our current one,
4727  // meaning we'll need two undo's to get back there - which defeats the object!
4728  return;
4729  }
4730  m_undoManager->undoSafePoint();
4731  m_undoManager->setAllowComplexMerge(merge);
4732  m_undoMergeAllEdits = merge;
4733 }
4734 
4735 //BEGIN KTextEditor::MovingInterface
4736 KTextEditor::MovingCursor *KateDocument::newMovingCursor (const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior)
4737 {
4738  return new Kate::TextCursor(buffer(), position, insertBehavior);
4739 }
4740 
4741 KTextEditor::MovingRange *KateDocument::newMovingRange (const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior)
4742 {
4743  return new Kate::TextRange(buffer(), range, insertBehaviors, emptyBehavior);
4744 }
4745 
4746 qint64 KateDocument::revision () const
4747 {
4748  return m_buffer->history().revision ();
4749 }
4750 
4751 qint64 KateDocument::lastSavedRevision () const
4752 {
4753  return m_buffer->history().lastSavedRevision ();
4754 }
4755 
4756 void KateDocument::lockRevision (qint64 revision)
4757 {
4758  m_buffer->history().lockRevision (revision);
4759 }
4760 
4761 void KateDocument::unlockRevision (qint64 revision)
4762 {
4763  m_buffer->history().unlockRevision (revision);
4764 }
4765 
4766 void KateDocument::transformCursor(int& line, int& column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision)
4767 {
4768  m_buffer->history().transformCursor (line, column, insertBehavior, fromRevision, toRevision);
4769 }
4770 
4771 void KateDocument::transformCursor (KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision)
4772 {
4773  int line = cursor.line(), column = cursor.column();
4774  m_buffer->history().transformCursor (line, column, insertBehavior, fromRevision, toRevision);
4775  cursor.setLine(line);
4776  cursor.setColumn(column);
4777 }
4778 
4779 void KateDocument::transformRange (KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision)
4780 {
4781  m_buffer->history().transformRange (range, insertBehaviors, emptyBehavior, fromRevision, toRevision);
4782 }
4783 
4784 //END
4785 
4786 bool KateDocument::simpleMode ()
4787 {
4788  return KateGlobal::self()->simpleMode () && KateGlobal::self()->documentConfig()->allowSimpleMode ();
4789 }
4790 
4791 //BEGIN KTextEditor::AnnotationInterface
4792 void KateDocument::setAnnotationModel( KTextEditor::AnnotationModel* model )
4793 {
4794  KTextEditor::AnnotationModel* oldmodel = m_annotationModel;
4795  m_annotationModel = model;
4796  emit annotationModelChanged(oldmodel, m_annotationModel);
4797 }
4798 
4799 KTextEditor::AnnotationModel* KateDocument::annotationModel() const
4800 {
4801  return m_annotationModel;
4802 }
4803 //END KTextEditor::AnnotationInterface
4804 
4805 //TAKEN FROM kparts.h
4806 bool KateDocument::queryClose()
4807 {
4808  if ( !isReadWrite() || !isModified() )
4809  return true;
4810 
4811  QString docName = documentName();
4812 
4813  int res = KMessageBox::warningYesNoCancel( dialogParent(),
4814  i18n( "The document \"%1\" has been modified.\n"
4815  "Do you want to save your changes or discard them?" , docName ),
4816  i18n( "Close Document" ), KStandardGuiItem::save(), KStandardGuiItem::discard() );
4817 
4818  bool abortClose=false;
4819  bool handled=false;
4820 
4821  switch(res) {
4822  case KMessageBox::Yes :
4823  sigQueryClose(&handled,&abortClose);
4824  if (!handled)
4825  {
4826  if (url().isEmpty())
4827  {
4828  KUrl url = KFileDialog::getSaveUrl(KUrl(), QString(), dialogParent());
4829  if (url.isEmpty())
4830  return false;
4831 
4832  saveAs( url );
4833  }
4834  else
4835  {
4836  save();
4837  }
4838  } else if (abortClose) return false;
4839  return waitSaveComplete();
4840  case KMessageBox::No :
4841  return true;
4842  default : // case KMessageBox::Cancel :
4843  return false;
4844  }
4845 }
4846 
4847 void KateDocument::slotStarted (KIO::Job *job)
4848 {
4852  if (m_documentState == DocumentIdle)
4853  m_documentState = DocumentLoading;
4854 
4862  if (m_documentState == DocumentLoading) {
4866  m_readWriteStateBeforeLoading = isReadWrite ();
4867 
4871  if (job) {
4875  setReadWrite (false);
4876 
4881  m_loadingJob = job;
4882  QTimer::singleShot (1000, this, SLOT(slotTriggerLoadingMessage()));
4883  }
4884  }
4885 }
4886 
4887 void KateDocument::slotCompleted() {
4892  if (m_documentState == DocumentLoading) {
4893  setReadWrite (m_readWriteStateBeforeLoading);
4894  delete m_loadingMessage;
4895  }
4896 
4900  if (m_documentState == DocumentSaving || m_documentState == DocumentSavingAs)
4901  emit documentSavedOrUploaded (this, m_documentState == DocumentSavingAs);
4902 
4906  m_documentState = DocumentIdle;
4907  m_reloading = false;
4908 }
4909 
4910 void KateDocument::slotCanceled() {
4915  if (m_documentState == DocumentLoading) {
4916  setReadWrite (m_readWriteStateBeforeLoading);
4917  delete m_loadingMessage;
4918 
4919  showAndSetOpeningErrorAccess();
4920 
4921  updateDocName();
4922  }
4923 
4927  m_documentState = DocumentIdle;
4928  m_reloading = false;
4929 
4930 
4931 }
4932 
4933 void KateDocument::slotTriggerLoadingMessage ()
4934 {
4939  if (m_documentState != DocumentLoading)
4940  return;
4941 
4945  delete m_loadingMessage;
4946  m_loadingMessage = new KTextEditor::Message(i18n ("The file <a href=\"%1\">%2</a> is still loading.", url().pathOrUrl(), url().fileName()));
4947  m_loadingMessage->setPosition(KTextEditor::Message::TopInView);
4948 
4952  if (m_loadingJob) {
4953  QAction *cancel = new QAction ( i18n ("&Abort Loading"), 0);
4954  connect (cancel, SIGNAL(triggered()), this, SLOT(slotAbortLoading()));
4955  m_loadingMessage->addAction (cancel);
4956  }
4957 
4961  postMessage(m_loadingMessage);
4962 }
4963 
4964 void KateDocument::slotAbortLoading ()
4965 {
4969  if (!m_loadingJob)
4970  return;
4971 
4976  m_loadingJob->kill (KJob::EmitResult);
4977  m_loadingJob = 0;
4978 }
4979 
4980 bool KateDocument::save()
4981 {
4986  if ((m_documentState != DocumentIdle) && (m_documentState != DocumentPreSavingAs))
4987  return false;
4988 
4992  if (m_documentState == DocumentIdle)
4993  m_documentState = DocumentSaving;
4994  else
4995  m_documentState = DocumentSavingAs;
4996 
5000  return KTextEditor::Document::save();
5001 }
5002 
5003 bool KateDocument::saveAs( const KUrl &url )
5004 {
5011  if (!url.isValid())
5012  return false;
5013 
5017  if (m_documentState != DocumentIdle)
5018  return false;
5019 
5023  m_documentState = DocumentPreSavingAs;
5024 
5028  return KTextEditor::Document::saveAs(url);
5029 }
5030 
5031 QString KateDocument::defaultDictionary() const
5032 {
5033  return m_defaultDictionary;
5034 }
5035 
5036 QList<QPair<KTextEditor::MovingRange*, QString> > KateDocument::dictionaryRanges() const
5037 {
5038  return m_dictionaryRanges;
5039 }
5040 
5041 void KateDocument::clearDictionaryRanges()
5042 {
5043  for (QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5044  i != m_dictionaryRanges.end(); ++i)
5045  {
5046  delete (*i).first;
5047  }
5048  m_dictionaryRanges.clear();
5049  if (m_onTheFlyChecker) {
5050  m_onTheFlyChecker->refreshSpellCheck();
5051  }
5052  emit dictionaryRangesPresent(false);
5053 }
5054 
5055 void KateDocument::setDictionary(const QString& newDictionary, const KTextEditor::Range &range)
5056 {
5057  KTextEditor::Range newDictionaryRange = range;
5058  if (!newDictionaryRange.isValid() || newDictionaryRange.isEmpty()) {
5059  return;
5060  }
5061  QList<QPair<KTextEditor::MovingRange*, QString> > newRanges;
5062  // all ranges is 'm_dictionaryRanges' are assumed to be mutually disjoint
5063  for(QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5064  i != m_dictionaryRanges.end();)
5065  {
5066  kDebug(13000) << "new iteration" << newDictionaryRange;
5067  if (newDictionaryRange.isEmpty()) {
5068  break;
5069  }
5070  QPair<KTextEditor::MovingRange*, QString> pair = *i;
5071  QString dictionarySet = pair.second;
5072  KTextEditor::MovingRange *dictionaryRange = pair.first;
5073  kDebug(13000) << *dictionaryRange << dictionarySet;
5074  if(dictionaryRange->contains(newDictionaryRange) && newDictionary == dictionarySet)
5075  {
5076  kDebug(13000) << "dictionaryRange contains newDictionaryRange";
5077  return;
5078  }
5079  if(newDictionaryRange.contains(*dictionaryRange))
5080  {
5081  delete dictionaryRange;
5082  i = m_dictionaryRanges.erase(i);
5083  kDebug(13000) << "newDictionaryRange contains dictionaryRange";
5084  continue;
5085  }
5086 
5087  KTextEditor::Range intersection = dictionaryRange->toRange().intersect(newDictionaryRange);
5088  if(!intersection.isEmpty() && intersection.isValid())
5089  {
5090  if(dictionarySet == newDictionary) // we don't have to do anything for 'intersection'
5091  { // except cut off the intersection
5092  QList<KTextEditor::Range> remainingRanges = KateSpellCheckManager::rangeDifference(newDictionaryRange, intersection);
5093  Q_ASSERT(remainingRanges.size() == 1);
5094  newDictionaryRange = remainingRanges.first();
5095  ++i;
5096  kDebug(13000) << "dictionarySet == newDictionary";
5097  continue;
5098  }
5099  QList<KTextEditor::Range> remainingRanges = KateSpellCheckManager::rangeDifference(*dictionaryRange, intersection);
5100  for(QList<KTextEditor::Range>::iterator j = remainingRanges.begin(); j != remainingRanges.end(); ++j)
5101  {
5102  KTextEditor::MovingRange *remainingRange = newMovingRange(*j,
5103  KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight);
5104  remainingRange->setFeedback(this);
5105  newRanges.push_back(QPair<KTextEditor::MovingRange*, QString>(remainingRange, dictionarySet));
5106  }
5107  i = m_dictionaryRanges.erase(i);
5108  delete dictionaryRange;
5109  } else {
5110  ++i;
5111  }
5112  }
5113  m_dictionaryRanges += newRanges;
5114  if(!newDictionaryRange.isEmpty() && !newDictionary.isEmpty()) // we don't add anything for the default dictionary
5115  {
5116  KTextEditor::MovingRange *newDictionaryMovingRange = newMovingRange(newDictionaryRange,
5117  KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight);
5118  newDictionaryMovingRange->setFeedback(this);
5119  m_dictionaryRanges.push_back(QPair<KTextEditor::MovingRange*, QString>(newDictionaryMovingRange, newDictionary));
5120  }
5121  if(m_onTheFlyChecker && !newDictionaryRange.isEmpty())
5122  {
5123  m_onTheFlyChecker->refreshSpellCheck(newDictionaryRange);
5124  }
5125  emit dictionaryRangesPresent(!m_dictionaryRanges.isEmpty());
5126 }
5127 
5128 void KateDocument::revertToDefaultDictionary(const KTextEditor::Range &range)
5129 {
5130  setDictionary(QString(), range);
5131 }
5132 
5133 void KateDocument::setDefaultDictionary(const QString& dict)
5134 {
5135  if (m_defaultDictionary == dict) {
5136  return;
5137  }
5138 
5139  m_defaultDictionary = dict;
5140 
5141  if (m_onTheFlyChecker) {
5142  m_onTheFlyChecker->updateConfig();
5143  refreshOnTheFlyCheck();
5144  }
5145  emit defaultDictionaryChanged(this);
5146 }
5147 
5148 void KateDocument::onTheFlySpellCheckingEnabled(bool enable)
5149 {
5150  if (isOnTheFlySpellCheckingEnabled() == enable) {
5151  return;
5152  }
5153 
5154  if (enable) {
5155  Q_ASSERT(m_onTheFlyChecker == 0);
5156  m_onTheFlyChecker = new KateOnTheFlyChecker(this);
5157  } else {
5158  delete m_onTheFlyChecker;
5159  m_onTheFlyChecker = 0;
5160  }
5161 
5162  foreach (KateView *view, m_views) {
5163  view->reflectOnTheFlySpellCheckStatus(enable);
5164  }
5165 }
5166 
5167 bool KateDocument::isOnTheFlySpellCheckingEnabled() const
5168 {
5169  return m_onTheFlyChecker != 0;
5170 }
5171 
5172 QString KateDocument::dictionaryForMisspelledRange(const KTextEditor::Range& range) const
5173 {
5174  if (!m_onTheFlyChecker) {
5175  return QString();
5176  } else {
5177  return m_onTheFlyChecker->dictionaryForMisspelledRange(range);
5178  }
5179 }
5180 
5181 void KateDocument::clearMisspellingForWord(const QString& word)
5182 {
5183  if (m_onTheFlyChecker) {
5184  m_onTheFlyChecker->clearMisspellingForWord(word);
5185  }
5186 }
5187 
5188 void KateDocument::refreshOnTheFlyCheck(const KTextEditor::Range &range)
5189 {
5190  if (m_onTheFlyChecker) {
5191  m_onTheFlyChecker->refreshSpellCheck(range);
5192  }
5193 }
5194 
5195 void KateDocument::rangeInvalid(KTextEditor::MovingRange *movingRange)
5196 {
5197  deleteDictionaryRange(movingRange);
5198 }
5199 
5200 void KateDocument::rangeEmpty(KTextEditor::MovingRange *movingRange)
5201 {
5202  deleteDictionaryRange(movingRange);
5203 }
5204 
5205 void KateDocument::deleteDictionaryRange(KTextEditor::MovingRange *movingRange)
5206 {
5207  kDebug(13020) << "deleting" << movingRange;
5208  for(QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5209  i != m_dictionaryRanges.end();)
5210  {
5211  KTextEditor::MovingRange *dictionaryRange = (*i).first;
5212  if(dictionaryRange == movingRange)
5213  {
5214  delete movingRange;
5215  i = m_dictionaryRanges.erase(i);
5216  } else {
5217  ++i;
5218  }
5219  }
5220 }
5221 
5222 bool KateDocument::containsCharacterEncoding(const KTextEditor::Range& range)
5223 {
5224  KateHighlighting *highlighting = highlight();
5225  Kate::TextLine textLine;
5226 
5227  const int rangeStartLine = range.start().line();
5228  const int rangeStartColumn = range.start().column();
5229  const int rangeEndLine = range.end().line();
5230  const int rangeEndColumn = range.end().column();
5231 
5232  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5233  textLine = kateTextLine(line);
5234  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5235  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5236  for(int col = startColumn; col < endColumn; ++col) {
5237  int attr = textLine->attribute(col);
5238  const KatePrefixStore& prefixStore = highlighting->getCharacterEncodingsPrefixStore(attr);
5239  if(!prefixStore.findPrefix(textLine, col).isEmpty()) {
5240  return true;
5241  }
5242  }
5243  }
5244 
5245  return false;
5246 }
5247 
5248 int KateDocument::computePositionWrtOffsets(const OffsetList& offsetList, int pos)
5249 {
5250  int previousOffset = 0;
5251  for(OffsetList::const_iterator i = offsetList.begin(); i != offsetList.end(); ++i) {
5252  if((*i).first > pos) {
5253  break;
5254  }
5255  previousOffset = (*i).second;
5256  }
5257  return pos + previousOffset;
5258 }
5259 
5260 QString KateDocument::decodeCharacters(const KTextEditor::Range& range, KateDocument::OffsetList& decToEncOffsetList,
5261  KateDocument::OffsetList& encToDecOffsetList)
5262 {
5263  QString toReturn;
5264  KTextEditor::Cursor previous = range.start();
5265  int decToEncCurrentOffset = 0, encToDecCurrentOffset = 0;
5266  int i = 0;
5267  int newI = 0;
5268 
5269  KateHighlighting *highlighting = highlight();
5270  Kate::TextLine textLine;
5271 
5272  const int rangeStartLine = range.start().line();
5273  const int rangeStartColumn = range.start().column();
5274  const int rangeEndLine = range.end().line();
5275  const int rangeEndColumn = range.end().column();
5276 
5277  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5278  textLine = kateTextLine(line);
5279  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5280  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5281  for(int col = startColumn; col < endColumn;) {
5282  int attr = textLine->attribute(col);
5283  const KatePrefixStore& prefixStore = highlighting->getCharacterEncodingsPrefixStore(attr);
5284  const QHash<QString, QChar>& characterEncodingsHash = highlighting->getCharacterEncodings(attr);
5285  QString matchingPrefix = prefixStore.findPrefix(textLine, col);
5286  if(!matchingPrefix.isEmpty()) {
5287  toReturn += text(KTextEditor::Range(previous, KTextEditor::Cursor(line, col)));
5288  const QChar& c = characterEncodingsHash.value(matchingPrefix);
5289  const bool isNullChar = c.isNull();
5290  if(!c.isNull()) {
5291  toReturn += c;
5292  }
5293  i += matchingPrefix.length();
5294  col += matchingPrefix.length();
5295  previous = KTextEditor::Cursor(line, col);
5296  decToEncCurrentOffset = decToEncCurrentOffset - (isNullChar ? 0 : 1) + matchingPrefix.length();
5297  encToDecCurrentOffset = encToDecCurrentOffset - matchingPrefix.length() + (isNullChar ? 0 : 1);
5298  newI += (isNullChar ? 0 : 1);
5299  decToEncOffsetList.push_back(QPair<int, int>(newI, decToEncCurrentOffset));
5300  encToDecOffsetList.push_back(QPair<int, int>(i, encToDecCurrentOffset));
5301  continue;
5302  }
5303  ++col;
5304  ++i;
5305  ++newI;
5306  }
5307  ++i;
5308  ++newI;
5309  }
5310  if(previous < range.end()) {
5311  toReturn += text(KTextEditor::Range(previous, range.end()));
5312  }
5313  return toReturn;
5314 }
5315 
5316 void KateDocument::replaceCharactersByEncoding(const KTextEditor::Range& range)
5317 {
5318  KateHighlighting *highlighting = highlight();
5319  Kate::TextLine textLine;
5320 
5321  const int rangeStartLine = range.start().line();
5322  const int rangeStartColumn = range.start().column();
5323  const int rangeEndLine = range.end().line();
5324  const int rangeEndColumn = range.end().column();
5325 
5326  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5327  textLine = kateTextLine(line);
5328  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5329  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5330  for(int col = startColumn; col < endColumn;) {
5331  int attr = textLine->attribute(col);
5332  const QHash<QChar, QString>& reverseCharacterEncodingsHash = highlighting->getReverseCharacterEncodings(attr);
5333  QHash<QChar, QString>::const_iterator it = reverseCharacterEncodingsHash.find(textLine->at(col));
5334  if(it != reverseCharacterEncodingsHash.end()) {
5335  replaceText(KTextEditor::Range(line, col, line, col + 1), *it);
5336  col += (*it).length();
5337  continue;
5338  }
5339  ++col;
5340  }
5341  }
5342 }
5343 
5344 //
5345 // KTextEditor::HighlightInterface
5346 //
5347 
5348 KTextEditor::Attribute::Ptr KateDocument::defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
5349 {
5351  KateView* view = activeKateView();
5352  if ( !view ) {
5353  kWarning() << "ATTENTION: cannot access defaultStyle() without any View (will be fixed eventually)";
5354  return KTextEditor::Attribute::Ptr(0);
5355  }
5356 
5357  KTextEditor::Attribute::Ptr style = highlight()->attributes(view->renderer()->config()->schema()).at(ds);
5358  if (!style->hasProperty(QTextFormat::BackgroundBrush)) {
5359  // make sure the returned style has the default background color set
5360  style.attach(new KTextEditor::Attribute(*style));
5361  style->setBackground( QBrush(view->renderer()->config()->backgroundColor()) );
5362  }
5363  return style;
5364 }
5365 
5366 QList< KTextEditor::HighlightInterface::AttributeBlock > KateDocument::lineAttributes(const unsigned int line)
5367 {
5369 
5370  QList< KTextEditor::HighlightInterface::AttributeBlock > attribs;
5371 
5372  KateView* view = activeKateView();
5373  if ( !view ) {
5374  kWarning() << "ATTENTION: cannot access lineAttributes() without any View (will be fixed eventually)";
5375  return attribs;
5376  }
5377 
5378  Kate::TextLine kateLine = kateTextLine(line);
5379  if ( !kateLine )
5380  return attribs;
5381 
5382  const QVector<Kate::TextLineData::Attribute> &intAttrs = kateLine->attributesList();
5383  for ( int i = 0; i < intAttrs.size(); ++i ) {
5384  if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0)
5385  attribs << KTextEditor::HighlightInterface::AttributeBlock(
5386  intAttrs.at(i).offset,
5387  intAttrs.at(i).length,
5388  view->renderer()->attribute(intAttrs.at(i).attributeValue)
5389  );
5390  }
5391 
5392  return attribs;
5393 }
5394 
5395 KTextEditor::Attribute::Ptr KateDocument::attributeAt(const KTextEditor::Cursor & position)
5396 {
5397  KTextEditor::Attribute::Ptr attrib(new KTextEditor::Attribute());
5398 
5399  KateView* view = activeKateView();
5400  if ( !view ) {
5401  kWarning() << "ATTENTION: cannot access lineAttributes() without any View (will be fixed eventually)";
5402  return attrib;
5403  }
5404 
5405  Kate::TextLine kateLine = kateTextLine(position.line());
5406  if ( !kateLine )
5407  return attrib;
5408 
5409  *attrib = *view->renderer()->attribute(kateLine->attribute(position.column()));
5410 
5411  return attrib;
5412 }
5413 
5414 QStringList KateDocument::embeddedHighlightingModes() const
5415 {
5416  return highlight()->getEmbeddedHighlightingModes();
5417 }
5418 
5419 QString KateDocument::highlightingModeAt(const KTextEditor::Cursor& position)
5420 {
5421  Kate::TextLine kateLine = kateTextLine(position.line());
5422 
5423 // const QVector< short >& attrs = kateLine->ctxArray();
5424 // kDebug() << "----------------------------------------------------------------------";
5425 // foreach( short a, attrs ) {
5426 // kDebug() << a;
5427 // }
5428 // kDebug() << "----------------------------------------------------------------------";
5429 // kDebug() << "col: " << position.column() << " lastchar:" << kateLine->lastChar() << " length:" << kateLine->length() << "global mode:" << highlightingMode();
5430 
5431  int len = kateLine->length();
5432  int pos = position.column();
5433  if ( pos >= len ) {
5434  const Kate::TextLineData::ContextStack &ctxs = kateLine->contextStack();
5435  int ctxcnt = ctxs.count();
5436  if ( ctxcnt == 0 ) {
5437  return highlightingMode();
5438  }
5439  int ctx = ctxs.at(ctxcnt-1);
5440  if ( ctx == 0 ) {
5441  return highlightingMode();
5442  }
5443  return KateHlManager::self()->nameForIdentifier(highlight()->hlKeyForContext(ctx));
5444  }
5445 
5446  int attr = kateLine->attribute(pos);
5447  if ( attr == 0 ) {
5448  return mode();
5449  }
5450 
5451  return KateHlManager::self()->nameForIdentifier(highlight()->hlKeyForAttrib(attr));
5452 
5453 }
5454 
5455 Kate::SwapFile* KateDocument::swapFile()
5456 {
5457  return m_swapfile;
5458 }
5459 
5464 int KateDocument::defStyleNum(int line, int column)
5465 {
5466  // Validate parameters to prevent out of range access
5467  if (line < 0 || line >= lines() || column < 0)
5468  return -1;
5469 
5470  // get highlighted line
5471  Kate::TextLine tl = kateTextLine(line);
5472 
5473  // make sure the textline is a valid pointer
5474  if (!tl)
5475  return -1;
5476 
5480  int attribute = 0;
5481  if (column < tl->length())
5482  attribute = tl->attribute (column);
5483  else if (column == tl->length()) {
5484  KateHlContext *context = tl->contextStack().isEmpty() ? highlight()->contextNum(0) : highlight()->contextNum (tl->contextStack().back());
5485  attribute = context->attr;
5486  } else
5487  return -1;
5488 
5489  KateView* view = static_cast<KateView*>(activeView());
5490  if (!view) {
5491  if (!m_views.isEmpty()) {
5492  view = m_views.first();
5493  } else {
5494  //FIXME: find a way to use this function without any view, or move it to the KateView.
5495  return -1;
5496  }
5497  }
5498 
5499  QList<KTextEditor::Attribute::Ptr> attributes = highlight()->attributes(
5500  view->renderer()->config()->schema()
5501  );
5502 
5503  // sanity check for the attribute
5504  if (attribute < 0 || attribute >= attributes.size())
5505  return -1;
5506 
5507  KTextEditor::Attribute::Ptr a = attributes[attribute];
5508  return a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
5509 }
5510 
5511 bool KateDocument::isComment(int line, int column)
5512 {
5513  const int defaultStyle = defStyleNum(line, column);
5514  return defaultStyle == KTextEditor::HighlightInterface::dsComment;
5515 }
5516 
5517 int KateDocument::findModifiedLine(int startLine, bool down)
5518 {
5519  const int offset = down ? 1 : -1;
5520  const int lineCount = lines();
5521  while (startLine >= 0 && startLine < lineCount) {
5522  Kate::TextLine tl = m_buffer->plainLine(startLine);
5523  if (tl && (tl->markedAsModified() || tl->markedAsSavedOnDisk())) {
5524  return startLine;
5525  }
5526  startLine += offset;
5527  }
5528 
5529  return -1;
5530 }
5531 
5532 //BEGIN KTextEditor::MessageInterface
5533 bool KateDocument::postMessage(KTextEditor::Message* message)
5534 {
5535  // no message -> cancel
5536  if (!message)
5537  return false;
5538 
5539  // make sure the desired view belongs to this document
5540  if (message->view() && message->view()->document() != this) {
5541  kWarning(13020) << "trying to post a message to a view of another document:" << message->text();
5542  return false;
5543  }
5544 
5545  message->setParent(this);
5546  message->setDocument(this);
5547 
5548  // if there are no actions, add a close action by default if widget does not auto-hide
5549  if (message->actions().count() == 0 && message->autoHide() < 0) {
5550  QAction* closeAction = new QAction(KIcon("window-close"), i18n("&Close"), 0);
5551  closeAction->setToolTip(i18n("Close message"));
5552  message->addAction(closeAction);
5553  }
5554 
5555  // make sure the message is registered even if no actions and no views exist
5556  m_messageHash[message] = QList<QSharedPointer<QAction> >();
5557 
5558  // reparent actions, as we want full control over when they are deleted
5559  foreach (QAction *action, message->actions()) {
5560  action->setParent(0);
5561  m_messageHash[message].append(QSharedPointer<QAction>(action));
5562  }
5563 
5564  // post message to requested view, or to all views
5565  if (KateView *view = qobject_cast<KateView*>(message->view())) {
5566  view->postMessage(message, m_messageHash[message]);
5567  } else {
5568  foreach (KateView *view, m_views)
5569  view->postMessage(message, m_messageHash[message]);
5570  }
5571 
5572  // also catch if the user manually calls delete message
5573  connect(message, SIGNAL(closed(KTextEditor::Message*)), SLOT(messageDestroyed(KTextEditor::Message*)));
5574 
5575  return true;
5576 }
5577 
5578 void KateDocument::messageDestroyed(KTextEditor::Message* message)
5579 {
5580  // KTE:Message is already in destructor
5581  Q_ASSERT(m_messageHash.contains(message));
5582  m_messageHash.remove(message);
5583 }
5584 //END KTextEditor::MessageInterface
5585 
5586 // kate: space-indent on; indent-width 2; replace-tabs on;
KateDocument::documentName
virtual const QString & documentName() const
Definition: katedocument.h:828
Kate::TextBuffer::line
TextLine line(int line) const
Retrieve a text line.
Definition: katetextbuffer.cpp:150
KateModOnHdPrompt::Ignore
Definition: katedialogs.h:409
KateDocument::line
virtual QString line(int line) const
Definition: katedocument.cpp:447
KateHlManager::hlName
QString hlName(int n)
Definition: katesyntaxmanager.cpp:360
KateDocument::setConfigValue
virtual void setConfigValue(const QString &key, const QVariant &value)
Definition: katedocument.cpp:4632
KateDocument::align
void align(KateView *view, const KTextEditor::Range &range)
Definition: katedocument.cpp:2909
QVariant::canConvert
bool canConvert(Type t) const
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
KateBrowserExtension
Interface for embedding KateDocument into a browser.
Definition: katedocumenthelpers.h:36
KateDocument::insertLine
virtual bool insertLine(int line, const QString &s)
Definition: katedocument.cpp:701
KateDocument::highlightingMode
virtual QString highlightingMode() const
Return the name of the currently used mode.
Definition: katedocument.cpp:1494
QList::clear
void clear()
KateDocumentConfig::setKeepExtraSpaces
void setKeepExtraSpaces(bool on)
Definition: kateconfig.cpp:598
KatePrefixStore
This class can be used to efficiently search for occurrences of strings in a given string...
Definition: prefixstore.h:41
KateDocument::setText
virtual bool setText(const QString &)
Definition: katedocument.cpp:457
KateDocument::config
KateDocumentConfig * config()
Configuration.
Definition: katedocument.h:1009
KateUndoManager::setModified
void setModified(bool modified)
Definition: kateundomanager.cpp:365
KateView::tagLines
bool tagLines(int start, int end, bool realLines=false)
Definition: kateview.cpp:1888
KateDocument::setWordWrap
void setWordWrap(bool on)
Definition: katedocument.cpp:3923
KateDocumentConfig::LocalFiles
Definition: kateconfig.h:279
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KatePlainTextSearch
Object to help to search for plain text.
Definition: kateplaintextsearch.h:40
Kate::TextBuffer::textCodec
QTextCodec * textCodec() const
Get codec for this buffer.
Definition: katetextbuffer.h:123
isEndBracket
bool isEndBracket(const QChar &c)
Definition: katedocument.cpp:104
KateOnTheFlyChecker::dictionaryForMisspelledRange
QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const
Definition: ontheflycheck.cpp:95
QWidget
KateRendererConfig::setSchema
void setSchema(const QString &schema)
Definition: kateconfig.cpp:2183
KateDocument::mimeType
virtual QString mimeType()
Definition: katedocument.cpp:1860
katehighlight.h
katetextline.h
QRegExp::cap
QString cap(int nth) const
KateDocument::ignoreModifiedOnDiskOnce
void ignoreModifiedOnDiskOnce()
Definition: katedocument.cpp:4696
KateGlobal::registerDocument
void registerDocument(KateDocument *doc)
register document at the factory this allows us to loop over all docs for example on config changes ...
Definition: kateglobal.cpp:474
kateview.h
KateDocumentConfig::backupPrefix
const QString & backupPrefix() const
Definition: kateconfig.cpp:1000
QString::append
QString & append(QChar ch)
documentcursor.h
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
KateBuffer::plainLine
Kate::TextLine plainLine(int lineno)
Return line lineno.
Definition: katebuffer.h:138
QHash::insert
iterator insert(const Key &key, const T &value)
KateDocumentConfig::setIndentationMode
void setIndentationMode(const QString &identationMode)
Definition: kateconfig.cpp:500
KateDocument::updateFileType
void updateFileType(const QString &newType, bool user=false)
Definition: katedocument.cpp:4503
KateGlobal::modeManager
KateModeManager * modeManager()
global mode manager used to manage the modes centrally
Definition: kateglobal.h:292
QString::toUpper
QString toUpper() const
KateDocument::newMovingCursor
virtual KTextEditor::MovingCursor * newMovingCursor(const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior=KTextEditor::MovingCursor::MoveOnInsert)
Create a new moving cursor for this document.
Definition: katedocument.cpp:4736
KateDocument::computePositionWrtOffsets
int computePositionWrtOffsets(const OffsetList &offsetList, int pos)
Definition: katedocument.cpp:5248
KateDocument::printDialog
bool printDialog()
Definition: katedocument.cpp:1848
KateView::clearSelection
bool clearSelection()
Definition: kateview.cpp:1991
QFileInfo::path
QString path() const
KateAutoIndent::updateConfig
void updateConfig()
Update indenter's configuration (indention width, etc.) Is called in the updateConfig() of the docume...
Definition: kateautoindent.cpp:370
KateDocument::setModifiedOnDiskWarning
virtual void setModifiedOnDiskWarning(bool on)
Definition: katedocument.cpp:3801
KateDocument::addMark
virtual void addMark(int line, uint markType)
Definition: katedocument.cpp:1677
KateDocument::newMovingRange
virtual KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty)
Create a new moving range for this document.
Definition: katedocument.cpp:4741
dummy
static int dummy
Definition: katedocument.cpp:101
KateGlobal::kateDocuments
QList< KateDocument * > & kateDocuments()
return a list of all registered docs
Definition: kateglobal.h:267
KateRendererConfig::setHighlightedBracketColor
void setHighlightedBracketColor(const QColor &col)
Definition: kateconfig.cpp:2432
KateDocument::replaceCharactersByEncoding
void replaceCharactersByEncoding(const KTextEditor::Range &range)
Definition: katedocument.cpp:5316
QChar::toAscii
char toAscii() const
QTextCodec::name
virtual QByteArray name() const =0
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1664
KateDocument::repaintViews
void repaintViews(bool paintOnlyDirty=true)
Definition: katedocument.cpp:3560
KateDocument::clearDictionaryRanges
void clearDictionaryRanges()
Definition: katedocument.cpp:5041
KateDocument::bufferHlChanged
void bufferHlChanged()
Definition: katedocument.cpp:1519
katerenderer.h
KateUndoManager::slotTextInserted
void slotTextInserted(int line, int col, const QString &s)
Notify KateUndoManager that text was inserted.
Definition: kateundomanager.cpp:139
QStack::pop
T pop()
KateDocumentConfig::RemoteFiles
Definition: kateconfig.h:280
KateRendererConfig::lineMarkerColor
const QColor & lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type=KTextEditor::MarkInterface::markType01) const
Definition: kateconfig.cpp:2390
KateBuffer::ensureHighlighted
void ensureHighlighted(int line, int lookAhead=64)
Update highlighting of given line line, if needed.
Definition: katebuffer.cpp:284
KateUndoManager::redo
void redo()
Redo the latest undo group.
Definition: kateundomanager.cpp:251
KateDocument::clearMark
virtual void clearMark(int line)
Definition: katedocument.cpp:1661
QVector::append
void append(const T &value)
KateDocument::setReadWrite
virtual void setReadWrite(bool rw=true)
Definition: katedocument.cpp:2469
KateDocument::removeLine
virtual bool removeLine(int line)
Definition: katedocument.cpp:727
KateDocumentConfig::ovr
bool ovr() const
Definition: kateconfig.cpp:800
KateBuffer::editTagFrom
bool editTagFrom() const
line inserted/removed?
Definition: katebuffer.h:89
QList::push_back
void push_back(const T &value)
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4701
QByteArray
KateSpellCheckManager::rangeDifference
static QList< KTextEditor::Range > rangeDifference(const KTextEditor::Range &r1, const KTextEditor::Range &r2)
'r2' is a subrange of 'r1', which is extracted from 'r1' and the remaining ranges are returned ...
Definition: spellcheck.cpp:68
KateDocumentConfig::setNewLineAtEof
void setNewLineAtEof(bool on)
Definition: kateconfig.cpp:766
Kate::TextHistory::lastSavedRevision
qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
Definition: katetexthistory.h:54
KateDocument::undoChanged
void undoChanged()
kateplaintextsearch.h
Kate::Script::i18nc
QScriptValue i18nc(QScriptContext *context, QScriptEngine *engine)
i18nc("context", "text", arguments [optional])
Definition: katescripthelpers.cpp:210
KateUndoManager::inputMethodStart
void inputMethodStart()
Definition: kateundomanager.cpp:115
QFile::remove
bool remove()
KateDocument::dictionaryForMisspelledRange
QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const
Definition: katedocument.cpp:5172
KateDocumentConfig::setOvr
void setOvr(bool on)
Definition: kateconfig.cpp:787
KateBuffer::editChanged
bool editChanged() const
were there changes in the current running editing session?
Definition: katebuffer.h:71
kateswapfile.h
KateDocument::redo
void redo()
Definition: katedocument.cpp:1380
KateDocument::activeView
virtual KTextEditor::View * activeView() const
Definition: katedocument.h:156
KateGlobal::documentConfig
KateDocumentConfig * documentConfig()
fallback document config
Definition: kateglobal.h:304
KateDocument::transpose
void transpose(const KTextEditor::Cursor &)
Definition: katedocument.cpp:2695
KateDocument::handleMarkClick
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
Definition: katedocument.cpp:1762
QChar
KateDocument::clear
virtual bool clear()
Definition: katedocument.cpp:509
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KateHlManager::nameForIdentifier
QString nameForIdentifier(const QString &)
Returns the mode name for a given identifier, as e.g.
Definition: katesyntaxmanager.cpp:388
KateDocument::documentSaveAs
virtual bool documentSaveAs()
Definition: katedocument.cpp:3908
KateDocument::readWriteChanged
void readWriteChanged(KTextEditor::Document *document)
KateDocument::paste
void paste(KateView *view, const QString &text)
Definition: katedocument.cpp:2829
KateDocumentConfig::setBackupSuffix
void setBackupSuffix(const QString &suffix)
Definition: kateconfig.cpp:1029
KateDocument::lineLength
virtual int lineLength(int line) const
Definition: katedocument.cpp:758
Kate::SwapFile::recover
void recover()
Definition: kateswapfile.cpp:208
KateDocument::simpleMode
static bool simpleMode()
Definition: katedocument.cpp:4786
KateDocumentConfig::indentPastedText
bool indentPastedText() const
Definition: kateconfig.cpp:632
QLinkedList::begin
iterator begin()
KateViewConfig::setIconBar
void setIconBar(bool on)
Definition: kateconfig.cpp:1602
QFont
kateautoindent.h
KateDocument::TextTransform
TextTransform
Definition: katedocument.h:734
Kate::TextBuffer::digest
const QByteArray & digest() const
md5 digest of the document on disk, set either through file loading in openFile() or in KateDocument:...
Definition: katetextbuffer.cpp:692
KateDocument::setMode
virtual bool setMode(const QString &name)
Set the current mode of the document by giving its name.
Definition: katedocument.cpp:1462
QStack::push
void push(const T &t)
KateHighlighting::getCommentStart
QString getCommentStart(int attrib=0) const
Definition: katehighlight.cpp:1157
QLinkedList::takeFirst
T takeFirst()
KateDocumentConfig::setTabIndents
void setTabIndents(bool on)
Definition: kateconfig.cpp:808
KateAutoIndent::setMode
void setMode(const QString &name)
Switch indenter Nop if already set to given mode Otherwise switch to given indenter or to "None" if n...
Definition: kateautoindent.cpp:304
KateConfig::configEnd
void configEnd()
end a config change transaction, update the concerned documents/views/renderers
Definition: kateconfig.cpp:64
QList::at
const T & at(int i) const
KateUndoManager::editEnd
void editEnd()
Notify KateUndoManager about the end of an edit.
Definition: kateundomanager.cpp:82
KateDocument::updateConfig
void updateConfig()
Definition: katedocument.cpp:3964
KateBuffer::wrapLine
void wrapLine(const KTextEditor::Cursor &position)
Wrap line at given cursor position.
Definition: katebuffer.cpp:301
KateRenderer::attribute
KTextEditor::Attribute::Ptr attribute(uint pos) const
This takes an in index, and returns all the attributes for it.
Definition: katerenderer.cpp:79
KateDocument::onTheFlySpellCheckingEnabled
void onTheFlySpellCheckingEnabled(bool enable)
Definition: katedocument.cpp:5148
QPointer< KTextEditor::Message >
ReplaceMode
Definition: kateviinputmodemanager.h:54
KateDocument::swapFile
Kate::SwapFile * swapFile()
Definition: katedocument.cpp:5455
KTextEditor::DocumentCursor
A Cursor which is bound to a specific Document.
Definition: documentcursor.h:69
QDBusConnection::registerObject
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KateDocument::clearMisspellingForWord
void clearMisspellingForWord(const QString &word)
Definition: katedocument.cpp:5181
KateDocument::setWordWrapAt
void setWordWrapAt(uint col)
Definition: katedocument.cpp:3933
QFileInfo::isSymLink
bool isSymLink() const
QByteArray::isEmpty
bool isEmpty() const
KateDocument::editRemoveLines
bool editRemoveLines(int from, int to)
Definition: katedocument.cpp:1294
katedocument.h
KateDocument::documentReload
virtual bool documentReload()
Reloads the current document from disk if possible.
Definition: katedocument.cpp:3806
KateDocument::tagLines
void tagLines(int start, int end)
Definition: katedocument.cpp:3554
KateView::repaintText
void repaintText(bool paintOnlyDirty=false)
Definition: kateview.cpp:1908
KateDocument::addView
void addView(KTextEditor::View *)
Definition: katedocument.cpp:2524
KateDocument::highlightingModeAt
virtual QString highlightingModeAt(const KTextEditor::Cursor &position)
Definition: katedocument.cpp:5419
KateDocument::defaultStyle
virtual KTextEditor::Attribute::Ptr defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
Definition: katedocument.cpp:5348
KateDocument::fileType
QString fileType() const
Definition: katedocument.h:939
KateDocument::annotationModel
virtual KTextEditor::AnnotationModel * annotationModel() const
Definition: katedocument.cpp:4799
KateDocument::embeddedHighlightingModes
virtual QStringList embeddedHighlightingModes() const
Definition: katedocument.cpp:5414
KateDocument::~KateDocument
~KateDocument()
Definition: katedocument.cpp:229
KateViReplaceMode::overwrittenChar
void overwrittenChar(const QChar &s)
Definition: katevireplacemode.h:48
KateDocumentConfig::wordWrapAt
int wordWrapAt() const
Definition: kateconfig.cpp:553
KateRegExpSearch::escapePlaintext
static QString escapePlaintext(const QString &text)
Returns a modified version of text where escape sequences are resolved, e.g.
Definition: kateregexpsearch.cpp:531
KateBuffer::clear
void clear()
Clear the buffer.
Definition: katebuffer.cpp:148
KateExtendedAttribute::AttributeDefaultStyleIndex
Definition: kateextendedattribute.h:44
QList::erase
iterator erase(iterator pos)
KatePlainTextSearch::search
KTextEditor::Range search(const QString &text, const KTextEditor::Range &inputRange, bool backwards=false)
Search for the given text inside the range inputRange taking into account whether to search casesensi...
Definition: kateplaintextsearch.cpp:52
QBrush
KateAutoIndent::indent
void indent(KateView *view, const KTextEditor::Range &range)
The document requests the indenter to indent the given range of existing text.
Definition: kateautoindent.cpp:415
KateUndoManager::slotTextRemoved
void slotTextRemoved(int line, int col, const QString &s)
Notify KateUndoManager that text was removed.
Definition: kateundomanager.cpp:145
KateDocument::inputMethodEnd
void inputMethodEnd()
Definition: katedocument.cpp:850
KateRegExpSearch
Object to help to search for regexp.
Definition: kateregexpsearch.h:40
QDBusConnection::sessionBus
QDBusConnection sessionBus()
KateUndoManager::inputMethodEnd
void inputMethodEnd()
Definition: kateundomanager.cpp:121
KateDocument::modeSection
virtual QString modeSection(int index) const
Returns the name of the section for a mode given its index in the highlight list (as returned by mode...
Definition: katedocument.cpp:1514
KateRendererConfig::setFont
void setFont(const QFont &font)
Definition: kateconfig.cpp:2292
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
KateUndoManager
KateUndoManager implements a document's history.
Definition: kateundomanager.h:45
KateDocument::createView
virtual KTextEditor::View * createView(QWidget *parent)
Definition: katedocument.cpp:292
QPoint
QStringList::join
QString join(const QString &separator) const
KateRendererConfig::setSelectionColor
void setSelectionColor(const QColor &col)
Definition: kateconfig.cpp:2356
KateHighlighting::canBreakAt
bool canBreakAt(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1129
KateBuffer::saveFile
bool saveFile(const QString &m_file)
Save the buffer to a file, use the given filename + codec + end of line chars (internal use of qtexts...
Definition: katebuffer.cpp:256
KateDocument::setDontChangeHlOnSave
void setDontChangeHlOnSave()
allow to mark, that we changed hl on user wish and should not reset it atm used for the user visible ...
Definition: katedocument.cpp:1531
QFile::exists
bool exists() const
KateDocument::markChanged
void markChanged(KTextEditor::Document *, KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction)
KateDocument::totalCharacters
virtual int totalCharacters() const
Definition: katedocument.cpp:738
QHash::count
int count(const Key &key) const
KateDocument::writeSessionConfig
virtual void writeSessionConfig(KConfigGroup &)
Definition: katedocument.cpp:1597
KateDocument::openUrl
virtual bool openUrl(const KUrl &url)
Definition: katedocument.cpp:2331
katedialogs.h
KateView::setCursorPosition
bool setCursorPosition(KTextEditor::Cursor position)
Definition: kateview.cpp:2418
QMap::clear
void clear()
QString::chop
void chop(int n)
QColor::setNamedColor
void setNamedColor(const QString &name)
KateDocument::bomSetByUser
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
Definition: katedocument.cpp:1536
KateDocument::marksChanged
void marksChanged(KTextEditor::Document *)
KTextEditor::DocumentCursor::move
bool move(int chars, WrapBehavior wrapBehavior=Wrap)
Moves the cursor chars character forward or backwards.
Definition: documentcursor.cpp:171
KateDocument::plainKateTextLine
Kate::TextLine plainKateTextLine(uint i)
Definition: katedocument.cpp:4712
KateDocumentConfig::removeSpaces
int removeSpaces() const
Definition: kateconfig.cpp:758
QDir::separator
QChar separator()
KateDocumentConfig::backupFlags
uint backupFlags() const
Definition: kateconfig.cpp:979
KateDocument::indent
void indent(KTextEditor::Range range, int change)
Definition: katedocument.cpp:2899
KateModOnHdPrompt::Overwrite
Definition: katedialogs.h:408
KateDocument::backspace
void backspace(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2726
KateDocument::fromVirtualColumn
int fromVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2580
kateregexpsearch.h
QFile
KateDocument::dictionaryRangesPresent
void dictionaryRangesPresent(bool yesNo)
spellcheck.h
QFile::copy
bool copy(const QString &newName)
Kate::SwapFile::discard
void discard()
Definition: kateswapfile.cpp:527
QTextStream
QAction::setToolTip
void setToolTip(const QString &tip)
KateDocument::markClicked
void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled)
KateHighlighting::getCommentEnd
QString getCommentEnd(int attrib=0) const
Definition: katehighlight.cpp:1162
KateBuffer::setHighlight
void setHighlight(int hlMode)
Use highlight for highlighting.
Definition: katebuffer.cpp:357
KateDocument::documentSave
virtual bool documentSave()
Definition: katedocument.cpp:3900
KateView::getViInputModeManager
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1587
KateDocument::revision
virtual qint64 revision() const
Current revision.
Definition: katedocument.cpp:4746
KateDocument::comment
void comment(KateView *view, uint line, uint column, int change)
Definition: katedocument.cpp:3302
QList::size
int size() const
QString::isNull
bool isNull() const
tabChar
static const QChar tabChar('\t')
KateDocument::insertLines
virtual bool insertLines(int line, const QStringList &s)
Definition: katedocument.cpp:712
katebuffer.h
KateBuffer::count
int count() const
Return the total number of lines in the buffer.
Definition: katebuffer.h:158
KateDocument::widget
virtual QWidget * widget()
Definition: katedocument.cpp:273
Kate::TextBuffer::insertText
virtual void insertText(const KTextEditor::Cursor &position, const QString &text)
Insert text at given cursor position.
Definition: katetextbuffer.cpp:306
KateDocument::lastLine
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:691
KateDocument::aboutToRemoveText
void aboutToRemoveText(const KTextEditor::Range &)
QList::value
T value(int i) const
KateHighlighting::getCharacterEncodingsPrefixStore
const KatePrefixStore & getCharacterEncodingsPrefixStore(int attrib) const
Definition: katehighlight.cpp:723
KateDocument::mark
virtual uint mark(int line)
Definition: katedocument.cpp:1646
KateConfig::configStart
void configStart()
start some config changes this method is needed to init some kind of transaction for config changes...
Definition: kateconfig.cpp:54
QString::clear
void clear()
KateDocument::singleViewMode
bool singleViewMode() const
Definition: katedocument.h:140
kateregexp.h
KateHlContext
Definition: katehighlighthelpers.h:72
QByteArray::resize
void resize(int size)
KateDocument::rangeInvalid
void rangeInvalid(KTextEditor::MovingRange *movingRange)
Definition: katedocument.cpp:5195
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2815
QRegExp::matchedLength
int matchedLength() const
KateDocument::aboutToDeleteMovingInterfaceContent
void aboutToDeleteMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the documen...
KateDocument::transformRange
virtual void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision=-1)
Transform a range from one revision to an other.
Definition: katedocument.cpp:4779
KateDocument::mode
virtual QString mode() const
Return the name of the currently used mode.
Definition: katedocument.cpp:1468
KateDocument::setHighlightingMode
virtual bool setHighlightingMode(const QString &name)
Set the current mode of the document by giving its name.
Definition: katedocument.cpp:1484
KateView::slotUpdateUndo
void slotUpdateUndo()
Definition: kateview.cpp:1264
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
KateDocument::Lowercase
Definition: katedocument.h:734
KateDocument::setActiveView
void setActiveView(KTextEditor::View *)
Definition: katedocument.cpp:2552
KateDocumentConfig::replaceTabsDyn
bool replaceTabsDyn() const
Definition: kateconfig.cpp:737
QLinkedList
QRegExp
QChar::isPrint
bool isPrint() const
KateDocument::replaceText
virtual bool replaceText(const KTextEditor::Range &range, const QString &s, bool block=false)
Definition: katedocument.cpp:4686
KateDocument::insertText
virtual bool insertText(const KTextEditor::Cursor &position, const QString &s, bool block=false)
Definition: katedocument.cpp:530
KateDocumentConfig::setBackspaceIndents
void setBackspaceIndents(bool on)
Definition: kateconfig.cpp:640
KateDocument::textLines
virtual QStringList textLines(const KTextEditor::Range &range, bool block=false) const
Definition: katedocument.cpp:398
QFileInfo::canonicalFilePath
QString canonicalFilePath() const
QApplication::activeWindow
QWidget * activeWindow()
KateDocument::popEditState
void popEditState()
Definition: katedocument.cpp:836
QList::count
int count(const T &value) const
KateDocument::decodeCharacters
QString decodeCharacters(const KTextEditor::Range &range, KateDocument::OffsetList &decToEncOffsetList, KateDocument::OffsetList &encToDecOffsetList)
The first OffsetList is from decoded to encoded, and the second OffsetList from encoded to decoded...
Definition: katedocument.cpp:5260
QList::append
void append(const T &value)
KateDocument::makeAttribs
void makeAttribs(bool needInvalidate=true)
Definition: katedocument.cpp:2503
KateDocument::setDefaultDictionary
void setDefaultDictionary(const QString &dict)
Definition: katedocument.cpp:5133
KatePartPluginManager::removeDocument
void removeDocument(KTextEditor::Document *doc)
Definition: katepartpluginmanager.cpp:112
QChar::isSpace
bool isSpace() const
KateDocumentConfig::backupSuffix
const QString & backupSuffix() const
Definition: kateconfig.cpp:1008
KateDocument::print
Q_SCRIPTABLE bool print()
Definition: katedocument.cpp:1853
KateDocument::newBracketMark
void newBracketMark(const KTextEditor::Cursor &start, KTextEditor::Range &bm, int maxLines=-1)
Definition: katedocument.cpp:3573
KTextEditor::DocumentCursor::toCursor
const Cursor & toCursor() const
Convert this clever cursor into a dumb one.
Definition: documentcursor.cpp:238
KateBuffer::openFile
bool openFile(const QString &m_file, bool enforceTextCodec)
Open a file, use the given filename.
Definition: katebuffer.cpp:161
Kate::TextHistory::transformRange
void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision=-1)
Transform a range from one revision to an other.
Definition: katetexthistory.cpp:484
QHash::constEnd
const_iterator constEnd() const
KateDocument::save
virtual bool save()
Definition: katedocument.cpp:4980
katemodemanager.h
KateDocument::character
virtual QChar character(const KTextEditor::Cursor &position) const
Definition: katedocument.cpp:388
QVariant::toInt
int toInt(bool *ok) const
QLinkedList::isEmpty
bool isEmpty() const
KateViewConfig::setAutoCenterLines
void setAutoCenterLines(int lines)
Definition: kateconfig.cpp:1686
KateDocument::pushEditState
void pushEditState()
Definition: katedocument.cpp:831
KateDocument::wrapText
bool wrapText(int startLine, int endLine)
Remove a line.
Definition: katedocument.cpp:855
kateschema.h
KateBuffer::tabWidth
int tabWidth() const
Definition: katebuffer.h:181
KateRenderer::config
KateRendererConfig * config() const
Configuration.
Definition: katerenderer.h:362
QSharedPointer
KateAutoIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:40
KateView::setSelection
virtual bool setSelection(const KTextEditor::Range &selection)
Definition: kateview.cpp:1956
KateDocument::setDictionary
void setDictionary(const QString &dict, const KTextEditor::Range &range)
Definition: katedocument.cpp:5055
KateDocument::transform
void transform(KateView *view, const KTextEditor::Cursor &, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
Definition: katedocument.cpp:3384
KateDocument::editInsertText
bool editInsertText(int line, int col, const QString &s)
Add a string in the given line/column.
Definition: katedocument.cpp:971
QHash
Kate::SwapFile
Class for tracking editing actions.
Definition: kateswapfile.h:46
katepartpluginmanager.h
KateHighlighting::attribute
int attribute(int context) const
Definition: katehighlight.cpp:1078
QObject
KateDocument::setMark
virtual void setMark(int line, uint markType)
Definition: katedocument.cpp:1655
KateDocument::editor
virtual KTextEditor::Editor * editor()
Definition: katedocument.cpp:314
KTextEditor::DocumentCursor::line
int line() const
Retrieve the line on which this cursor is situated.
Definition: documentcursor.cpp:77
KateView::editEnd
void editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom)
Definition: kateview.cpp:1866
QChar::fromLatin1
QChar fromLatin1(char c)
KateUndoManager::slotLineInserted
void slotLineInserted(int line, const QString &s)
Notify KateUndoManager that a line was inserted.
Definition: kateundomanager.cpp:169
KateDocument::m_defaultDictionary
QString m_defaultDictionary
Definition: katedocument.h:1150
KateHighlighting::attributes
QList< KTextEditor::Attribute::Ptr > attributes(const QString &schema)
Definition: katehighlight.cpp:2172
kateglobal.h
Kate::TextBuffer::setDigest
void setDigest(const QByteArray &md5sum)
Set the md5sum of this buffer.
Definition: katetextbuffer.cpp:697
KateDocumentConfig::setWordWrapAt
void setWordWrapAt(int col)
Definition: kateconfig.cpp:561
KateDocument::dictionaryRanges
QList< QPair< KTextEditor::MovingRange *, QString > > dictionaryRanges() const
Definition: katedocument.cpp:5036
KateGlobal::deregisterDocument
void deregisterDocument(KateDocument *doc)
unregister document at the factory
Definition: kateglobal.cpp:481
QString::toInt
int toInt(bool *ok, int base) const
KateBuffer::editTagStart
int editTagStart() const
dirty lines start
Definition: katebuffer.h:77
KateView::postMessage
void postMessage(KTextEditor::Message *message, QList< QSharedPointer< QAction > > actions)
Used by Document::postMessage().
Definition: kateview.cpp:3254
KateDocument::editRemoveLine
bool editRemoveLine(int line)
Remove a line.
Definition: katedocument.cpp:1289
QList::isEmpty
bool isEmpty() const
KateDocument::variable
virtual QString variable(const QString &name) const
Definition: katedocument.cpp:4338
QString::isEmpty
bool isEmpty() const
QList::removeAll
int removeAll(const T &value)
QString::trimmed
QString trimmed() const
KateDocument::lineAttributes
virtual QList< KTextEditor::HighlightInterface::AttributeBlock > lineAttributes(const unsigned int line)
Definition: katedocument.cpp:5366
Kate::TextBuffer::invalidateRanges
void invalidateRanges()
Invalidate all ranges in this buffer.
Definition: katetextbuffer.cpp:100
QHash::begin
iterator begin()
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QByteArray::replace
QByteArray & replace(int pos, int len, const char *after)
KateDocument::defStyleNum
int defStyleNum(int line, int column)
Definition: katedocument.cpp:5464
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
KateHighlighting::getReverseCharacterEncodings
const QHash< QChar, QString > & getReverseCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:728
KateBuffer::brokenEncoding
bool brokenEncoding() const
Did encoding errors occur on load?
Definition: katebuffer.h:109
KateDocument::isDataRecoveryAvailable
virtual bool isDataRecoveryAvailable() const
Definition: katedocument.cpp:2452
KateDocument::KateDocument
KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, bool bReadOnly=false, QWidget *parentWidget=0, QObject *=0)
Definition: katedocument.cpp:111
KateDocument::documentEnd
virtual KTextEditor::Cursor documentEnd() const
Definition: katedocument.cpp:4681
KateViewConfig::persistentSelection
bool persistentSelection() const
Definition: kateconfig.cpp:1777
KateDocument::editableMarks
virtual uint editableMarks() const
Definition: katedocument.cpp:1841
KateViewConfig::setPersistentSelection
void setPersistentSelection(bool on)
Definition: kateconfig.cpp:1785
KateDocument::rangeOnLine
KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const
Definition: katedocument.cpp:319
KateRendererConfig::global
static KateRendererConfig * global()
Definition: kateconfig.h:640
KateDocument::undoCount
uint undoCount() const
Definition: katedocument.cpp:1365
spaceChar
static const QChar spaceChar(' ')
KateDocument::wordWrap
bool wordWrap() const
Definition: katedocument.cpp:3928
KateUndoManager::clearRedo
void clearRedo()
Definition: kateundomanager.cpp:354
QList::first
T & first()
KateView::blockSelection
virtual bool blockSelection() const
Definition: kateview.cpp:2221
KateRendererConfig::setBackgroundColor
void setBackgroundColor(const QColor &col)
Definition: kateconfig.cpp:2335
KateDocument::newLine
void newLine(KateView *view)
Definition: katedocument.cpp:2660
KateDocument::m_dictionaryRanges
QList< QPair< KTextEditor::MovingRange *, QString > > m_dictionaryRanges
Definition: katedocument.h:1151
KateDocument::unlockRevision
virtual void unlockRevision(qint64 revision)
Release a revision.
Definition: katedocument.cpp:4761
KateDocumentConfig::setSmartHome
void setSmartHome(bool on)
Definition: kateconfig.cpp:661
QString
kateprinter.h
QList< KTextEditor::View * >
KateDocument::defaultDictionaryChanged
void defaultDictionaryChanged(KateDocument *document)
katedocumenthelpers.h
KateDocument::setModified
virtual void setModified(bool m)
Definition: katedocument.cpp:2484
QColor
QHash::remove
int remove(const Key &key)
KateDocumentConfig::setRemoveSpaces
void setRemoveSpaces(int triState)
Remove trailing spaces on save.
Definition: kateconfig.cpp:745
KateView::clear
void clear()
Definition: kateview.cpp:1903
KateDocument::isEditRunning
bool isEditRunning() const
Definition: katedocument.cpp:4717
KateDocument::queryClose
virtual bool queryClose()
Definition: katedocument.cpp:4806
KateDocument::configValue
virtual QVariant configValue(const QString &key)
Definition: katedocument.cpp:4608
KateDocumentConfig::setShowTabs
void setShowTabs(bool on)
Definition: kateconfig.cpp:682
KateDocument::markPixmap
virtual QPixmap markPixmap(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1816
KateBuffer::editTagEnd
int editTagEnd() const
dirty lines end
Definition: katebuffer.h:83
Kate::Mark
Mark
Definition: katedefaultcolors.h:55
KateView::selection
virtual bool selection() const
Definition: kateview.cpp:2033
QList::iterator
KateDocumentConfig::encoding
const QString & encoding() const
Definition: kateconfig.cpp:829
KateDocument::configKeys
virtual QStringList configKeys() const
Definition: katedocument.cpp:4603
KateDocument::Uppercase
Definition: katedocument.h:734
QStringList
KatePartPluginManager::self
static KatePartPluginManager * self()
Definition: katepartpluginmanager.cpp:70
KateDocument::handleMarkContextMenu
bool handleMarkContextMenu(int line, QPoint position)
Returns true if the context-menu event should not further be processed.
Definition: katedocument.cpp:1774
KateDocument::markColor
virtual QColor markColor(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1821
QHash::erase
iterator erase(iterator pos)
KateBuffer::unwrapLine
void unwrapLine(int line)
Unwrap given line.
Definition: katebuffer.cpp:337
KateDocument::typeChars
bool typeChars(KateView *type, const QString &realChars)
Type chars in a view.
Definition: katedocument.cpp:2595
QHash::keys
QList< Key > keys() const
KateDocument::encoding
virtual const QString & encoding() const
Definition: katedocument.cpp:3959
KateHighlighting::getEmbeddedHighlightingModes
QStringList getEmbeddedHighlightingModes() const
Returns a list of names of embedded modes.
Definition: katehighlight.cpp:2204
QPair< KTextEditor::MovingRange *, QString >
KateDocumentConfig::setBackupPrefix
void setBackupPrefix(const QString &prefix)
Definition: kateconfig.cpp:1016
KateView
Definition: kateview.h:77
QPixmap
KateBuffer::setTabWidth
void setTabWidth(int w)
Definition: katebuffer.cpp:346
KateDocument::closeUrl
virtual bool closeUrl()
Definition: katedocument.cpp:2337
KateUndoManager::redoCount
uint redoCount() const
Returns how many redo() actions can be performed.
Definition: kateundomanager.cpp:229
KateBuffer::editStart
void editStart()
start some editing action
Definition: katebuffer.cpp:88
KateDocument::digest
const QByteArray & digest() const
md5 digest of this document
Definition: katedocument.cpp:4409
KateView::editStart
void editStart()
Definition: kateview.cpp:1861
isInWord
static bool isInWord(const KTextEditor::View *view, const KTextEditor::Cursor &position, QChar c)
Definition: katekeywordcompletion.cpp:118
QFileInfo
KateDocument::messageDestroyed
void messageDestroyed(KTextEditor::Message *message)
Definition: katedocument.cpp:5578
QChar::isNull
bool isNull() const
QHash::clear
void clear()
KateGlobal::dirWatch
KDirWatch * dirWatch()
global dirwatch
Definition: kateglobal.h:285
KateDocument::saveAs
virtual bool saveAs(const KUrl &url)
Definition: katedocument.cpp:5003
QList::end
iterator end()
KateFileType
Definition: katemodemanager.h:34
QString::toLower
QString toLower() const
QHash::value
const T value(const Key &key) const
QVector::reserve
void reserve(int size)
QHash::find
iterator find(const Key &key)
KateView::slotTextInserted
void slotTextInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
Definition: kateview.cpp:2270
KateView::updateView
void updateView(bool changed=false)
Definition: kateview.cpp:1916
KateOnTheFlyChecker::refreshSpellCheck
void refreshSpellCheck(const KTextEditor::Range &range=KTextEditor::Range::invalid())
Definition: ontheflycheck.cpp:677
EDIT_DEBUG
#define EDIT_DEBUG
Definition: katedocument.cpp:98
KateDocument::attributeAt
virtual KTextEditor::Attribute::Ptr attributeAt(const KTextEditor::Cursor &position)
Definition: katedocument.cpp:5395
KateDocument
Definition: katedocument.h:74
QObject::setParent
void setParent(QObject *parent)
KateRenderer::updateAttributes
void updateAttributes()
update the highlighting attributes (for example after an hl change or after hl config changed) ...
Definition: katerenderer.cpp:74
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
KateAutoIndent::userTypedChar
void userTypedChar(KateView *view, const KTextEditor::Cursor &position, QChar typedChar)
The user typed some char, the indenter can react on this ' ' will be send as char if the user wraps a...
Definition: kateautoindent.cpp:436
KateUndoManager::updateLineModifications
void updateLineModifications()
Definition: kateundomanager.cpp:382
KateDocument::requestMarkTooltip
void requestMarkTooltip(int line, QPoint position)
Definition: katedocument.cpp:1752
QLatin1Char
KateDocument::defaultDictionary
QString defaultDictionary() const
Definition: katedocument.cpp:5031
Kate::TextBuffer::removeText
virtual void removeText(const KTextEditor::Range &range)
Remove text at given range.
Definition: katetextbuffer.cpp:338
KateDocument::findMatchingBracket
bool findMatchingBracket(KTextEditor::Range &range, int maxLines=-1)
Definition: katedocument.cpp:3589
KateDocument::del
void del(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2806
KateDocument::setUndoMergeAllEdits
void setUndoMergeAllEdits(bool merge)
Definition: katedocument.cpp:4722
KateAutoIndent::changeIndent
bool changeIndent(const KTextEditor::Range &range, int change)
Function to provide the common indent/unindent/clean indent functionality to the document This should...
Definition: kateautoindent.cpp:381
KateViewConfig::setFoldingBar
void setFoldingBar(bool on)
Definition: kateconfig.cpp:1623
KateDocument::text
virtual QString text() const
Definition: katedocument.cpp:332
Kate::TextHistory::unlockRevision
void unlockRevision(qint64 revision)
Release a revision.
Definition: katetexthistory.cpp:159
KateUndoManager::undoSafePoint
void undoSafePoint()
Prevent latest KateUndoGroup from being merged with the next one.
Definition: kateundomanager.cpp:190
isStartBracket
bool isStartBracket(const QChar &c)
Definition: katedocument.cpp:103
KateViInputModeManager::getViReplaceMode
KateViReplaceMode * getViReplaceMode()
Definition: kateviinputmodemanager.cpp:561
KateDocument::variableChanged
void variableChanged(KTextEditor::Document *, const QString &, const QString &)
KateDocument::kateTextLine
Kate::TextLine kateTextLine(uint i)
Definition: katedocument.cpp:4706
KateDocument::editWrapLine
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=0)
Wrap line.
Definition: katedocument.cpp:1083
KateDocument::searchText
virtual QVector< KTextEditor::Range > searchText(const KTextEditor::Range &range, const QString &pattern, const KTextEditor::Search::SearchOptions options)
Definition: katedocument.cpp:1387
KateDocumentConfig::indentationMode
const QString & indentationMode() const
Definition: kateconfig.cpp:492
KatePartPluginManager::addDocument
void addDocument(KTextEditor::Document *doc)
Definition: katepartpluginmanager.cpp:100
KateDocumentConfig::indentationWidth
int indentationWidth() const
Definition: kateconfig.cpp:468
removeNewLines
static QString removeNewLines(const QString &str)
Definition: katedocument.cpp:3666
KateView::cursorPosition
KTextEditor::Cursor cursorPosition() const
Definition: kateview.cpp:2423
KateDocumentConfig::setWordWrap
void setWordWrap(bool on)
Definition: kateconfig.cpp:540
KateRendererConfig::schema
const QString & schema() const
Definition: kateconfig.cpp:2175
QString::replace
QString & replace(int position, int n, QChar after)
KateDocument::isComment
bool isComment(int line, int column)
Definition: katedocument.cpp:5511
QVector::at
const T & at(int i) const
KateView::removeSelectedText
bool removeSelectedText()
Definition: kateview.cpp:2046
QHash::constBegin
const_iterator constBegin() const
KateDocument::charactersSemiInteractivelyInserted
void charactersSemiInteractivelyInserted(const KTextEditor::Cursor &position, const QString &text)
KateDocument::setAnnotationModel
virtual void setAnnotationModel(KTextEditor::AnnotationModel *model)
Definition: katedocument.cpp:4792
KateRegExpSearch::search
QVector< KTextEditor::Range > search(const QString &pattern, const KTextEditor::Range &inputRange, bool backwards=false)
Search for the regular expression regexp inside the range inputRange.
Definition: kateregexpsearch.cpp:201
KateDocumentConfig::setEol
void setEol(int mode)
Definition: kateconfig.cpp:903
QString::toLatin1
QByteArray toLatin1() const
KateDocumentConfig::wordWrap
bool wordWrap() const
Definition: kateconfig.cpp:532
QString::mid
QString mid(int position, int n) const
KateDocument::setModifiedOnDisk
virtual void setModifiedOnDisk(ModifiedOnDiskReason reason)
Definition: katedocument.cpp:3787
KateDocument::setEncoding
virtual bool setEncoding(const QString &e)
Definition: katedocument.cpp:3954
QVector< KTextEditor::Range >
KateDocument::editRemoveText
bool editRemoveText(int line, int col, int len)
Remove a string in the given line/column.
Definition: katedocument.cpp:1012
QHash::take
T take(const Key &key)
KateView::viInputMode
bool viInputMode() const
Definition: kateview.cpp:1530
KateUndoManager::isActive
bool isActive() const
Definition: kateundomanager.h:90
KateRendererConfig::font
const QFont & font() const
Definition: kateconfig.cpp:2276
Kate::TextHistory::revision
qint64 revision() const
Current revision, just relay the revision of the buffer.
Definition: katetexthistory.cpp:39
KateHlManager::hlSection
QString hlSection(int n)
Definition: katesyntaxmanager.cpp:370
KateDocument::getWord
QString getWord(const KTextEditor::Cursor &cursor)
Definition: katedocument.cpp:3538
QChar::toUpper
QChar toUpper() const
KateHighlighting::getCommentSingleLineStart
QString getCommentSingleLineStart(int attrib=0) const
Definition: katehighlight.cpp:1167
QLatin1String
KateDocumentConfig::setShowSpaces
void setShowSpaces(bool on)
Definition: kateconfig.cpp:703
KateDocument::readSessionConfig
virtual void readSessionConfig(const KConfigGroup &)
Definition: katedocument.cpp:1543
KateDocumentConfig::setPageUpDownMovesCursor
void setPageUpDownMovesCursor(bool on)
Definition: kateconfig.cpp:585
QHash::isEmpty
bool isEmpty() const
KateBuffer::unwrapLines
void unwrapLines(int from, int to)
Unwrap given lines.
Definition: katebuffer.cpp:310
KateDocument::wordWrapAt
uint wordWrapAt() const
Definition: katedocument.cpp:3938
KateHighlighting::getCharacterEncodings
const QHash< QString, QChar > & getCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:718
Kate::TextCursor
Class representing a 'clever' text cursor.
Definition: katetextcursor.h:43
KateBuffer::editEnd
void editEnd()
finish some editing action
Definition: katebuffer.cpp:94
KateDocument::removeMark
virtual void removeMark(int line, uint markType)
Definition: katedocument.cpp:1714
QString::count
int count() const
KateDocument::modes
virtual QStringList modes() const
Return a list of the names of all possible modes.
Definition: katedocument.cpp:1473
KateDocument::editEnd
void editEnd()
End a editor operation.
Definition: katedocument.cpp:796
KateDocument::setEditableMarks
virtual void setEditableMarks(uint markMask)
Definition: katedocument.cpp:1836
KateDocument::aboutToInvalidateMovingInterfaceContent
void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the ranges of a document are invalidated and the revisions are deleted ...
KateDocument::setVariable
virtual QString setVariable(const QString &name, const QString &value)
Definition: katedocument.cpp:4343
QCryptographicHash
KateHighlighting
Definition: katehighlight.h:119
KateOnTheFlyChecker::clearMisspellingForWord
void clearMisspellingForWord(const QString &word)
Definition: ontheflycheck.cpp:106
KateDocument::recoverData
virtual void recoverData()
Definition: katedocument.cpp:2457
KateBuffer::highlight
KateHighlighting * highlight()
Definition: katebuffer.h:194
QString::at
const QChar at(int position) const
KateHlManager::nameFind
int nameFind(const QString &name)
Definition: katesyntaxmanager.cpp:116
QAction
QFont::setFamily
void setFamily(const QString &family)
QList::last
T & last()
QChar::fromAscii
QChar fromAscii(char c)
KateBuffer::canEncode
bool canEncode()
Can the current codec handle all chars.
Definition: katebuffer.cpp:232
KateUndoManager::clearUndo
void clearUndo()
Definition: kateundomanager.cpp:343
KateDocument::clearMarks
virtual void clearMarks()
Definition: katedocument.cpp:1787
KateDocument::markToolTipRequested
void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled)
QVector::count
int count(const T &value) const
KateHighlighting::CSLPosColumn0
Definition: katehighlight.h:227
KateDocument::modifiedOnDisk
void modifiedOnDisk(KTextEditor::Document *doc, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason)
Indicate this file is modified on disk.
KateDocument::m_undoManager
KateUndoManager *const m_undoManager
Definition: katedocument.h:344
KateDocumentConfig::setReplaceTabsDyn
void setReplaceTabsDyn(bool on)
Definition: kateconfig.cpp:724
KateDocument::isOnTheFlySpellCheckingEnabled
bool isOnTheFlySpellCheckingEnabled() const
Definition: katedocument.cpp:5167
QString::length
int length() const
KateModOnHdPrompt::Save
Definition: katedialogs.h:407
KateDocument::views
virtual const QList< KTextEditor::View * > & views() const
Definition: katedocument.cpp:309
KateRendererConfig::backgroundColor
const QColor & backgroundColor() const
Definition: kateconfig.cpp:2327
katevireplacemode.h
KateDocument::ownedView
bool ownedView(KateView *)
Definition: katedocument.cpp:2560
KateDocument::openFile
virtual bool openFile()
open the file obtained by the kparts framework the framework abstracts the loading of remote files ...
Definition: katedocument.cpp:1931
QVariant::toBool
bool toBool() const
KateDocument::containsCharacterEncoding
bool containsCharacterEncoding(const KTextEditor::Range &range)
Definition: katedocument.cpp:5222
KateDocument::setMarkDescription
virtual void setMarkDescription(MarkInterface::MarkTypes, const QString &)
Definition: katedocument.cpp:1811
Kate::TextBuffer::text
QString text() const
Retrieve text of complete buffer.
Definition: katetextbuffer.cpp:159
KateDocument::undo
void undo()
Definition: katedocument.cpp:1375
KateDocument::refreshOnTheFlyCheck
void refreshOnTheFlyCheck(const KTextEditor::Range &range=KTextEditor::Range::invalid())
Definition: katedocument.cpp:5188
KateDocumentConfig::pageUpDownMovesCursor
bool pageUpDownMovesCursor() const
Definition: kateconfig.cpp:577
KateRendererConfig::setWordWrapMarkerColor
void setWordWrapMarkerColor(const QColor &col)
Definition: kateconfig.cpp:2453
KateDocument::slotQueryClose_save
void slotQueryClose_save(bool *handled, bool *abortClosing)
Definition: katedocument.cpp:4558
KateDocument::marks
virtual const QHash< int, KTextEditor::Mark * > & marks()
Definition: katedocument.cpp:1747
KateDocumentConfig
Definition: kateconfig.h:145
KateUndoManager::undo
void undo()
Undo the latest undo group.
Definition: kateundomanager.cpp:234
kateundomanager.h
KateDocument::configChanged
void configChanged()
KateViewConfig::setLineNumbers
void setLineNumbers(bool on)
Definition: kateconfig.cpp:1476
KateModOnHdPrompt::Reload
Definition: katedialogs.h:406
KateDocument::inputMethodStart
void inputMethodStart()
Definition: katedocument.cpp:845
KateRendererConfig::setIconBarColor
void setIconBarColor(const QColor &col)
Definition: kateconfig.cpp:2516
KateView::setBlockSelection
virtual bool setBlockSelection(bool on)
Definition: kateview.cpp:2226
KateDocument::insertTab
void insertTab(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2914
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
QList::prepend
void prepend(const T &value)
KateDocument::lockRevision
virtual void lockRevision(qint64 revision)
Lock a revision, this will keep it around until released again.
Definition: katedocument.cpp:4756
QMap::insert
iterator insert(const Key &key, const T &value)
KateDocument::toVirtualColumn
int toVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2565
QHash::contains
bool contains(const Key &key) const
KateDocument::editUnWrapLine
bool editUnWrapLine(int line, bool removeLine=true, int length=0)
Unwrap line.
Definition: katedocument.cpp:1153
KateBuffer::invalidateHighlighting
void invalidateHighlighting()
Invalidate highlighting of whole buffer.
Definition: katebuffer.cpp:389
KateView::tagAll
void tagAll()
Definition: kateview.cpp:1898
KateUndoManager::slotLineWrapped
void slotLineWrapped(int line, int col, int length, bool newLine)
Notify KateUndoManager that a line was wrapped.
Definition: kateundomanager.cpp:157
KateDocument::Capitalize
Definition: katedocument.h:734
KateModOnHdPrompt
This dialog will prompt the user for what do with a file that is modified on disk.
Definition: katedialogs.h:401
KateDocument::postMessage
virtual bool postMessage(KTextEditor::Message *message)
Definition: katedocument.cpp:5533
KTextEditor::DocumentCursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: documentcursor.cpp:82
Kate::SwapFile::shouldRecover
bool shouldRecover() const
Definition: kateswapfile.cpp:518
QLinkedList::first
T & first()
KatePrinter::print
static bool print(KateDocument *doc)
Definition: kateprinter.cpp:102
KateDocument::redoCount
uint redoCount() const
Definition: katedocument.cpp:1370
KateDocumentConfig::setIndentPastedText
void setIndentPastedText(bool on)
Definition: kateconfig.cpp:619
KateView::reflectOnTheFlySpellCheckStatus
void reflectOnTheFlySpellCheckStatus(bool enabled)
Definition: kateview.cpp:3096
KateDocument::pageUpDownMovesCursor
bool pageUpDownMovesCursor() const
Definition: katedocument.cpp:3948
KateDocument::lastSavedRevision
virtual qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
Definition: katedocument.cpp:4751
KateDocument::highlightingModes
virtual QStringList highlightingModes() const
Return a list of the names of all possible modes.
Definition: katedocument.cpp:1499
Kate::TextHistory::transformCursor
void transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision=-1)
Transform a cursor from one revision to an other.
Definition: katetexthistory.cpp:436
QHash::end
iterator end()
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:161
KateUndoManager::slotMarkLineAutoWrapped
void slotMarkLineAutoWrapped(int line, bool autowrapped)
Notify KateUndoManager that a line was marked as autowrapped.
Definition: kateundomanager.cpp:151
KateView::slotReadWriteChanged
void slotReadWriteChanged()
Definition: kateview.cpp:1225
KateDocument::markContextMenuRequested
void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled)
katescriptmanager.h
KateUndoManager::undoCount
uint undoCount() const
Returns how many undo() actions can be performed.
Definition: kateundomanager.cpp:224
KateDocument::editStart
void editStart()
Enclose editor actions with editStart() and editEnd() to group them.
Definition: katedocument.cpp:776
ontheflycheck.h
QVariant::type
Type type() const
KateDocument::revertToDefaultDictionary
void revertToDefaultDictionary(const KTextEditor::Range &range)
Definition: katedocument.cpp:5128
KateDocument::removeView
void removeView(KTextEditor::View *)
removes the view from the list of views.
Definition: katedocument.cpp:2541
KateFileType::name
QString name
Definition: katemodemanager.h:38
KateViInputModeManager::getCurrentViMode
ViMode getCurrentViMode() const
Definition: kateviinputmodemanager.cpp:451
QFileInfo::absolutePath
QString absolutePath() const
KateViewConfig::setDynWordWrap
void setDynWordWrap(bool wrap)
Definition: kateconfig.cpp:1413
KateDocumentConfig::backspaceIndents
bool backspaceIndents() const
Definition: kateconfig.cpp:653
QLinkedList::removeAll
int removeAll(const T &value)
Kate::Error
Definition: katedefaultcolors.h:62
KateDocumentConfig::setBom
void setBom(bool bom)
Definition: kateconfig.cpp:916
KatePrefixStore::findPrefix
QString findPrefix(const QString &s, int start=0) const
Returns the shortest prefix of the given string that is contained in this prefix store starting at po...
Definition: prefixstore.cpp:120
KateDocument::m_onTheFlyChecker
KateOnTheFlyChecker * m_onTheFlyChecker
Definition: katedocument.h:1149
KateUndoManager::setAllowComplexMerge
void setAllowComplexMerge(bool allow)
Allows or disallows merging of "complex" undo groups.
Definition: kateundomanager.cpp:429
KateDocumentConfig::setTabWidth
void setTabWidth(int tabWidth)
Definition: kateconfig.cpp:452
QVector::size
int size() const
KateDocumentConfig::tabWidth
int tabWidth() const
Definition: kateconfig.cpp:444
KateView::config
KateViewConfig * config()
Configuration.
Definition: kateview.h:653
KateHighlighting::isInWord
bool isInWord(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1122
KateDocument::transformCursor
virtual void transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision=-1)
Transform a cursor from one revision to an other.
Definition: katedocument.cpp:4771
KateDocument::mimeTypeForContent
KMimeType::Ptr mimeTypeForContent()
Definition: katedocument.cpp:1874
KateDocument::saveFile
virtual bool saveFile()
save the file obtained by the kparts framework the framework abstracts the uploading of remote files ...
Definition: katedocument.cpp:2077
KateDocument::writeParameterizedSessionConfig
virtual void writeParameterizedSessionConfig(KConfigGroup &, unsigned long configParameters)
Definition: katedocument.cpp:1602
Kate::TextBuffer::history
TextHistory & history()
TextHistory of this buffer.
Definition: katetextbuffer.h:304
KateUndoManager::updateConfig
void updateConfig()
Definition: kateundomanager.cpp:424
Kate::Warning
Definition: katedefaultcolors.h:61
katehighlighthelpers.h
KateView::updateDocumentConfig
void updateDocumentConfig()
Definition: kateview.cpp:1769
KateModeManager::list
const QList< KateFileType * > & list() const
Don't modify.
Definition: katemodemanager.h:93
kateconfig.h
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
KateDocument::highlightingModeSection
virtual QString highlightingModeSection(int index) const
Returns the name of the section for a highlight given its index in the highlight list (as returned by...
Definition: katedocument.cpp:1509
KateUndoManager::editStart
void editStart()
Notify KateUndoManager about the beginning of an edit.
Definition: kateundomanager.cpp:65
Kate::TextHistory::lockRevision
void lockRevision(qint64 revision)
Lock a revision, this will keep it around until released again.
Definition: katetexthistory.cpp:143
KateDocument::activeKateView
KateView * activeKateView() const
Definition: katedocument.cpp:4676
KateDocument::joinLines
void joinLines(uint first, uint last)
Unwrap a range of lines.
Definition: katedocument.cpp:3497
KateView::setCursorPositionInternal
bool setCursorPositionInternal(const KTextEditor::Cursor &position, uint tabwidth=1, bool calledExternally=false)
Definition: kateview.cpp:1293
isBracket
bool isBracket(const QChar &c)
Definition: katedocument.cpp:105
KateDocumentConfig::searchDirConfigDepth
int searchDirConfigDepth() const
Should Kate Part search for dir wide config file and if, how depth?
Definition: kateconfig.cpp:1063
Kate::TextRange
Class representing a 'clever' text range.
Definition: katetextrange.h:46
QList::begin
iterator begin()
QString::repeated
QString repeated(int times) const
KateHlManager::self
static KateHlManager * self()
Definition: katesyntaxmanager.cpp:103
KateDocument::findModifiedLine
int findModifiedLine(int startLine, bool down)
Definition: katedocument.cpp:5517
KateDocument::editInsertLine
bool editInsertLine(int line, const QString &s)
Insert a string at the given line.
Definition: katedocument.cpp:1223
KateDocumentConfig::setIndentationWidth
void setIndentationWidth(int indentationWidth)
Definition: kateconfig.cpp:476
KateDocument::setMarkPixmap
virtual void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &)
Definition: katedocument.cpp:1806
KateOnTheFlyChecker
Definition: ontheflycheck.h:40
KateDocument::editMarkLineAutoWrapped
bool editMarkLineAutoWrapped(int line, bool autowrapped)
Mark line as autowrapped.
Definition: katedocument.cpp:1056
KateDocument::annotationModelChanged
void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *)
QLinkedList::size
int size() const
KTextEditor::DocumentCursor::setPosition
void setPosition(const KTextEditor::Cursor &position)
Set the current cursor position to position.
Definition: documentcursor.cpp:68
KateUndoManager::slotLineRemoved
void slotLineRemoved(int line, const QString &s)
Notify KateUndoManager that a line was removed.
Definition: kateundomanager.cpp:175
KateBuffer::tooLongLinesWrapped
bool tooLongLinesWrapped() const
Too long lines wrapped on load?
Definition: katebuffer.h:115
KateDocument::deleteDictionaryRange
void deleteDictionaryRange(KTextEditor::MovingRange *movingRange)
Definition: katedocument.cpp:5205
KateDocument::removeText
virtual bool removeText(const KTextEditor::Range &range, bool block=false)
Definition: katedocument.cpp:633
KateDocument::setPageUpDownMovesCursor
void setPageUpDownMovesCursor(bool on)
Definition: katedocument.cpp:3943
KateUndoManager::slotLineUnWrapped
void slotLineUnWrapped(int line, int col, int length, bool lineRemoved)
Notify KateUndoManager that a line was un-wrapped.
Definition: kateundomanager.cpp:163
KateDocumentConfig::allowSimpleMode
bool allowSimpleMode() const
Definition: kateconfig.cpp:958
KateRendererConfig::setHighlightedLineColor
void setHighlightedLineColor(const QColor &col)
Definition: kateconfig.cpp:2377
prefixstore.h
KateBuffer
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:39
QLinkedList::contains
bool contains(const T &value) const
KateHighlighting::contextNum
KateHlContext * contextNum(int n)
Definition: katehighlight.h:275
KateDocument::discardDataRecovery
virtual void discardDataRecovery()
Definition: katedocument.cpp:2463
KateDocument::slotModifiedOnDisk
virtual void slotModifiedOnDisk(KTextEditor::View *v=0)
Ask the user what to do, if the file has been modified on disk.
Definition: katedocument.cpp:3713
QLinkedList::append
void append(const T &value)
KateAutoIndent::checkRequiredStyle
void checkRequiredStyle()
Check if the current highlighting mode provides the style required by the current indenter...
Definition: kateautoindent.cpp:355
KateModeManager::fileType
QString fileType(KateDocument *doc, const QString &fileToReadFrom)
get the right fileType for the given document -1 if none found !
Definition: katemodemanager.cpp:205
Kate::SwapFile::fileClosed
void fileClosed()
Definition: kateswapfile.cpp:121
KateHlContext::attr
int attr
Definition: katehighlighthelpers.h:84
QColor::isValid
bool isValid() const
KateDocumentConfig::setEncoding
bool setEncoding(const QString &encoding)
Definition: kateconfig.cpp:852
KateDocumentConfig::bom
bool bom() const
Definition: kateconfig.cpp:929
KateDocument::readParameterizedSessionConfig
virtual void readParameterizedSessionConfig(const KConfigGroup &, unsigned long configParameters)
Definition: katedocument.cpp:1548
KateDocument::supportedSearchOptions
virtual KTextEditor::Search::SearchOptions supportedSearchOptions() const
Definition: katedocument.cpp:1432
KateDocumentConfig::setBackupFlags
void setBackupFlags(uint flags)
Definition: kateconfig.cpp:987
QMap::value
const T value(const Key &key) const
KateDocument::rangeEmpty
void rangeEmpty(KTextEditor::MovingRange *movingRange)
Definition: katedocument.cpp:5200
QTimer::singleShot
singleShot
QVariant
KateHlManager::highlights
int highlights()
Definition: katesyntaxmanager.cpp:355
KateDocument::markDescription
virtual QString markDescription(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1831
KateDocument::checkOverwrite
static bool checkOverwrite(KUrl u, QWidget *parent)
Definition: katedocument.cpp:4584
KateOnTheFlyChecker::updateConfig
void updateConfig()
Definition: ontheflycheck.cpp:667
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal