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

Kate

  • sources
  • kde-4.12
  • 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  QPointer<KTextEditor::Message> message
2057  = new KTextEditor::Message(i18n ("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters).<br />"
2058  "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.",
2059  this->url().pathOrUrl(),config()->lineLengthLimit()),
2060  KTextEditor::Message::Warning);
2061  message->setWordWrap(true);
2062  postMessage(message);
2063 
2064  // remember error
2065  setOpeningError(true);
2066  setOpeningErrorMessage(i18n ("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters)."
2067  " Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", this->url().pathOrUrl(),config()->lineLengthLimit()));
2068  }
2069 
2070  //
2071  // return the success
2072  //
2073  return success;
2074 }
2075 
2076 bool KateDocument::saveFile()
2077 {
2078  QWidget *parentWidget(dialogParent());
2079 
2080  // some warnings, if file was changed by the outside!
2081  if ( !url().isEmpty() )
2082  {
2083  if (m_fileChangedDialogsActivated && m_modOnHd)
2084  {
2085  QString str = reasonedMOHString() + "\n\n";
2086 
2087  if (!isModified())
2088  {
2089  if (KMessageBox::warningContinueCancel(parentWidget,
2090  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)
2091  return false;
2092  }
2093  else
2094  {
2095  if (KMessageBox::warningContinueCancel(parentWidget,
2096  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)
2097  return false;
2098  }
2099  }
2100  }
2101 
2102  //
2103  // can we encode it if we want to save it ?
2104  //
2105  if (!m_buffer->canEncode ()
2106  && (KMessageBox::warningContinueCancel(parentWidget,
2107  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))
2108  {
2109  return false;
2110  }
2111 
2112  //
2113  // try to create backup file..
2114  //
2115 
2116  // local file or not is here the question
2117  bool l ( url().isLocalFile() );
2118 
2119  // does the user want any backup, if not, not our problem?
2120  if ( ( l && config()->backupFlags() & KateDocumentConfig::LocalFiles )
2121  || ( ! l && config()->backupFlags() & KateDocumentConfig::RemoteFiles ) )
2122  {
2123  KUrl u( url() );
2124  if (config()->backupPrefix().contains(QDir::separator())) {
2125  u.setPath( config()->backupPrefix() + url().fileName() + config()->backupSuffix() );
2126  } else {
2127  u.setFileName( config()->backupPrefix() + url().fileName() + config()->backupSuffix() );
2128  }
2129 
2130  kDebug( 13020 ) << "backup src file name: " << url();
2131  kDebug( 13020 ) << "backup dst file name: " << u;
2132 
2133  // handle the backup...
2134  bool backupSuccess = false;
2135 
2136  // local file mode, no kio
2137  if (u.isLocalFile ())
2138  {
2139  if (QFile::exists (url().toLocalFile ()))
2140  {
2141  // first: check if backupFile is already there, if true, unlink it
2142  QFile backupFile (u.toLocalFile ());
2143  if (backupFile.exists()) backupFile.remove ();
2144 
2145  backupSuccess = QFile::copy (url().toLocalFile (), u.toLocalFile ());
2146  }
2147  else
2148  backupSuccess = true;
2149  }
2150  else // remote file mode, kio
2151  {
2152  // get the right permissions, start with safe default
2153  KIO::UDSEntry fentry;
2154  if (KIO::NetAccess::stat (url(), fentry, QApplication::activeWindow())) {
2155  // do a evil copy which will overwrite target if possible
2156  KFileItem item (fentry, url());
2157  KIO::FileCopyJob *job = KIO::file_copy ( url(), u, item.permissions(), KIO::Overwrite );
2158  backupSuccess = KIO::NetAccess::synchronousRun(job, QApplication::activeWindow());
2159  }
2160  else
2161  backupSuccess = true;
2162  }
2163 
2164  // backup has failed, ask user how to proceed
2165  if (!backupSuccess && (KMessageBox::warningContinueCancel (parentWidget
2166  , i18n ("For file %1 no backup copy could be created before saving."
2167  " If an error occurs while saving, you might lose the data of this file."
2168  " 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())
2169  , i18n ("Failed to create backup copy.")
2170  , KGuiItem(i18n("Try to Save Nevertheless"))
2171  , KStandardGuiItem::cancel(), "Backup Failed Warning") != KMessageBox::Continue))
2172  {
2173  return false;
2174  }
2175  }
2176 
2177  // update file type, pass no file path, read file type content from this document
2178  updateFileType (KateGlobal::self()->modeManager()->fileType (this, QString ()));
2179 
2180  // remember the oldpath...
2181  QString oldPath = m_dirWatchFile;
2182 
2183  // read dir config (if possible and wanted)
2184  if ( url().isLocalFile())
2185  {
2186  QFileInfo fo (oldPath), fn (localFilePath());
2187 
2188  if (fo.path() != fn.path())
2189  readDirConfig();
2190  }
2191 
2192  // read our vars
2193  readVariables();
2194 
2195  // remove file from dirwatch
2196  deactivateDirWatch ();
2197 
2198  // remove all trailing spaces in the document (as edit actions)
2199  // NOTE: we need this as edit actions, since otherwise the edit actions
2200  // in the swap file recovery may happen at invalid cursor positions
2201  removeTrailingSpaces ();
2202 
2203  //
2204  // try to save
2205  //
2206  if (!m_buffer->saveFile (localFilePath()))
2207  {
2208  // add m_file again to dirwatch
2209  activateDirWatch (oldPath);
2210 
2211  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()));
2212 
2213  return false;
2214  }
2215 
2216  // update the md5 digest
2217  createDigest ();
2218 
2219  // add m_file again to dirwatch
2220  activateDirWatch ();
2221 
2222  //
2223  // we are not modified
2224  //
2225  if (m_modOnHd)
2226  {
2227  m_modOnHd = false;
2228  m_modOnHdReason = OnDiskUnmodified;
2229  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
2230  }
2231 
2232  // update document name...
2233  updateDocName ();
2234 
2235  // url may have changed...
2236  emit documentUrlChanged (this);
2237 
2238  // (dominik) mark last undo group as not mergeable, otherwise the next
2239  // edit action might be merged and undo will never stop at the saved state
2240  m_undoManager->undoSafePoint();
2241  m_undoManager->updateLineModifications();
2242 
2243  //
2244  // return success
2245  //
2246  return true;
2247 }
2248 
2249 void KateDocument::readDirConfig ()
2250 {
2251  int depth = config()->searchDirConfigDepth ();
2252 
2253  if (this->url().isLocalFile() && (depth > -1))
2254  {
2255  QString currentDir = QFileInfo (localFilePath()).absolutePath();
2256 
2257  // only search as deep as specified or not at all ;)
2258  while (depth > -1)
2259  {
2260  //kDebug (13020) << "search for config file in path: " << currentDir;
2261 
2262  // try to open config file in this dir
2263  QFile f (currentDir + "/.kateconfig");
2264 
2265  if (f.open (QIODevice::ReadOnly))
2266  {
2267  QTextStream stream (&f);
2268 
2269  uint linesRead = 0;
2270  QString line = stream.readLine();
2271  while ((linesRead < 32) && !line.isNull())
2272  {
2273  readVariableLine( line );
2274 
2275  line = stream.readLine();
2276 
2277  linesRead++;
2278  }
2279 
2280  break;
2281  }
2282 
2283  QString newDir = QFileInfo (currentDir).absolutePath();
2284 
2285  // bail out on looping (for example reached /)
2286  if (currentDir == newDir)
2287  break;
2288 
2289  currentDir = newDir;
2290  --depth;
2291  }
2292  }
2293 }
2294 
2295 void KateDocument::activateDirWatch (const QString &useFileName)
2296 {
2297  QString fileToUse = useFileName;
2298  if (fileToUse.isEmpty())
2299  fileToUse = localFilePath();
2300 
2301  QFileInfo fileInfo = QFileInfo(fileToUse);
2302  if (fileInfo.isSymLink()) {
2303  // Monitor the actual data and not the symlink
2304  fileToUse = fileInfo.canonicalFilePath();
2305  }
2306 
2307  // same file as we are monitoring, return
2308  if (fileToUse == m_dirWatchFile)
2309  return;
2310 
2311  // remove the old watched file
2312  deactivateDirWatch ();
2313 
2314  // add new file if needed
2315  if (url().isLocalFile() && !fileToUse.isEmpty())
2316  {
2317  KateGlobal::self()->dirWatch ()->addFile (fileToUse);
2318  m_dirWatchFile = fileToUse;
2319  }
2320 }
2321 
2322 void KateDocument::deactivateDirWatch ()
2323 {
2324  if (!m_dirWatchFile.isEmpty())
2325  KateGlobal::self()->dirWatch ()->removeFile (m_dirWatchFile);
2326 
2327  m_dirWatchFile.clear();
2328 }
2329 
2330 bool KateDocument::openUrl( const KUrl &url ) {
2331  bool res=KTextEditor::Document::openUrl(url);
2332  updateDocName();
2333  return res;
2334 }
2335 
2336 bool KateDocument::closeUrl()
2337 {
2338  //
2339  // file mod on hd
2340  //
2341  if ( !m_reloading && !url().isEmpty() )
2342  {
2343  if (m_fileChangedDialogsActivated && m_modOnHd)
2344  {
2345  QWidget *parentWidget(dialogParent());
2346 
2347  if (!(KMessageBox::warningContinueCancel(
2348  parentWidget,
2349  reasonedMOHString() + "\n\n" + i18n("Do you really want to continue to close this file? Data loss may occur."),
2350  i18n("Possible Data Loss"), KGuiItem(i18n("Close Nevertheless")), KStandardGuiItem::cancel(),
2351  QString("kate_close_modonhd_%1").arg( m_modOnHdReason ) ) == KMessageBox::Continue)) {
2355  m_reloading = false;
2356  return false;
2357  }
2358  }
2359  }
2360 
2361  //
2362  // first call the normal kparts implementation
2363  //
2364  if (!KParts::ReadWritePart::closeUrl ()) {
2368  m_reloading = false;
2369  return false;
2370  }
2371 
2372  // Tell the world that we're about to go ahead with the close
2373  if (!m_reloading)
2374  emit aboutToClose(this);
2375 
2379  if (m_messageHash.count()) {
2380  QList<KTextEditor::Message*> keys = m_messageHash.keys ();
2381  foreach (KTextEditor::Message* message, keys)
2382  delete message;
2383  }
2384 
2388  emit aboutToInvalidateMovingInterfaceContent (this);
2389 
2390  // remove file from dirwatch
2391  deactivateDirWatch ();
2392 
2393  //
2394  // empty url + fileName
2395  //
2396  setUrl(KUrl());
2397  setLocalFilePath(QString());
2398 
2399  // we are not modified
2400  if (m_modOnHd)
2401  {
2402  m_modOnHd = false;
2403  m_modOnHdReason = OnDiskUnmodified;
2404  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
2405  }
2406 
2407  emit KTextEditor::Document::textRemoved(this, documentRange());
2408  emit KTextEditor::Document::textRemoved(this, documentRange(), m_buffer->text());
2409 
2410  {
2411  // remove all marks
2412  clearMarks ();
2413 
2414  // clear the buffer
2415  m_buffer->clear();
2416 
2417  // clear undo/redo history
2418  m_undoManager->clearUndo();
2419  m_undoManager->clearRedo();
2420  }
2421 
2422  // no, we are no longer modified
2423  setModified(false);
2424 
2425  // we have no longer any hl
2426  m_buffer->setHighlight(0);
2427 
2428  // update all our views
2429  foreach (KateView * view, m_views )
2430  {
2431  view->clearSelection(); // fix bug #118588
2432  view->clear();
2433  }
2434 
2435  if (!m_reloading)
2436  {
2437  // uh, fileName changed
2438  emit documentUrlChanged (this);
2439 
2440  // update doc name
2441  updateDocName ();
2442  }
2443 
2444  // purge swap file
2445  m_swapfile->fileClosed ();
2446 
2447  // success
2448  return true;
2449 }
2450 
2451 bool KateDocument::isDataRecoveryAvailable() const
2452 {
2453  return m_swapfile->shouldRecover();
2454 }
2455 
2456 void KateDocument::recoverData()
2457 {
2458  if (isDataRecoveryAvailable())
2459  m_swapfile->recover();
2460 }
2461 
2462 void KateDocument::discardDataRecovery()
2463 {
2464  if (isDataRecoveryAvailable())
2465  m_swapfile->discard();
2466 }
2467 
2468 void KateDocument::setReadWrite( bool rw )
2469 {
2470  if (isReadWrite() != rw)
2471  {
2472  KParts::ReadWritePart::setReadWrite (rw);
2473 
2474  foreach( KateView* view, m_views)
2475  {
2476  view->slotUpdateUndo();
2477  view->slotReadWriteChanged ();
2478  }
2479  emit readWriteChanged(this);
2480  }
2481 }
2482 
2483 void KateDocument::setModified(bool m) {
2484 
2485  if (isModified() != m) {
2486  KParts::ReadWritePart::setModified (m);
2487 
2488  foreach( KateView* view,m_views)
2489  {
2490  view->slotUpdateUndo();
2491  }
2492 
2493  emit modifiedChanged (this);
2494  }
2495 
2496  m_undoManager->setModified (m);
2497 }
2498 //END
2499 
2500 //BEGIN Kate specific stuff ;)
2501 
2502 void KateDocument::makeAttribs(bool needInvalidate)
2503 {
2504  foreach(KateView *view,m_views)
2505  view->renderer()->updateAttributes ();
2506 
2507  if (needInvalidate)
2508  m_buffer->invalidateHighlighting();
2509 
2510  foreach(KateView *view,m_views)
2511  {
2512  view->tagAll();
2513  view->updateView (true);
2514  }
2515 }
2516 
2517 // the attributes of a hl have changed, update
2518 void KateDocument::internalHlChanged()
2519 {
2520  makeAttribs();
2521 }
2522 
2523 void KateDocument::addView(KTextEditor::View *view) {
2524  if (!view)
2525  return;
2526 
2527  m_views.append( static_cast<KateView*>(view) );
2528  m_textEditViews.append( view );
2529 
2530  // apply the view & renderer vars from the file type
2531  if (!m_fileType.isEmpty())
2532  readVariableLine(KateGlobal::self()->modeManager()->fileType(m_fileType).varLine, true);
2533 
2534  // apply the view & renderer vars from the file
2535  readVariables (true);
2536 
2537  setActiveView(view);
2538 }
2539 
2540 void KateDocument::removeView(KTextEditor::View *view) {
2541  if (!view)
2542  return;
2543 
2544  if (activeView() == view)
2545  setActiveView(0L);
2546 
2547  m_views.removeAll( static_cast<KateView *>(view) );
2548  m_textEditViews.removeAll( view );
2549 }
2550 
2551 void KateDocument::setActiveView(KTextEditor::View* view)
2552 {
2553  if ( m_activeView == view )
2554  return;
2555 
2556  m_activeView = static_cast<KateView*>(view);
2557 }
2558 
2559 bool KateDocument::ownedView(KateView *view) {
2560  // do we own the given view?
2561  return (m_views.contains(view));
2562 }
2563 
2564 int KateDocument::toVirtualColumn( int line, int column ) const
2565 {
2566  Kate::TextLine textLine = m_buffer->plainLine(line);
2567 
2568  if (textLine)
2569  return textLine->toVirtualColumn(column, config()->tabWidth());
2570  else
2571  return 0;
2572 }
2573 
2574 int KateDocument::toVirtualColumn( const KTextEditor::Cursor& cursor ) const
2575 {
2576  return toVirtualColumn(cursor.line(), cursor.column());
2577 }
2578 
2579 int KateDocument::fromVirtualColumn( int line, int column ) const
2580 {
2581  Kate::TextLine textLine = m_buffer->plainLine(line);
2582 
2583  if (textLine)
2584  return textLine->fromVirtualColumn(column, config()->tabWidth());
2585  else
2586  return 0;
2587 }
2588 
2589 int KateDocument::fromVirtualColumn( const KTextEditor::Cursor& cursor ) const
2590 {
2591  return fromVirtualColumn(cursor.line(), cursor.column());
2592 }
2593 
2594 bool KateDocument::typeChars ( KateView *view, const QString &realChars )
2595 {
2596  Kate::TextLine textLine = m_buffer->plainLine(view->cursorPosition().line ());
2597  if (!textLine)
2598  return false;
2599 
2603  QString chars;
2604  Q_FOREACH (QChar c, realChars)
2605  if (c.isPrint() || c == QChar::fromLatin1('\t'))
2606  chars.append (c);
2607 
2608  if (chars.isEmpty())
2609  return false;
2610 
2611  editStart ();
2612 
2613  if (!view->config()->persistentSelection() && view->selection() )
2614  view->removeSelectedText();
2615 
2616  KTextEditor::Cursor oldCur (view->cursorPosition());
2617 
2618  if (config()->ovr()
2619  || (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode)) {
2620 
2621  KTextEditor::Range r = KTextEditor::Range(view->cursorPosition(), qMin(chars.length(),
2622  textLine->length() - view->cursorPosition().column()));
2623 
2624  // replace mode needs to know what was removed so it can be restored with backspace
2625  if (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode
2626  && oldCur.column() < line( view->cursorPosition().line() ).length() ) {
2627  QChar removed = line( view->cursorPosition().line() ).at( r.start().column() );
2628  view->getViInputModeManager()->getViReplaceMode()->overwrittenChar( removed );
2629  }
2630 
2631  removeText(r);
2632  }
2633 
2634  if (view->blockSelection() && view->selection()) {
2635  KTextEditor::Range selectionRange = view->selectionRange();
2636  int startLine = qMax(0, selectionRange.start().line());
2637  int endLine = qMin(selectionRange.end().line(), lastLine());
2638  int column = toVirtualColumn(selectionRange.end());
2639  for (int line = endLine; line >= startLine; --line)
2640  editInsertText(line, fromVirtualColumn(line, column), chars);
2641  int newSelectionColumn = toVirtualColumn(view->cursorPosition());
2642  selectionRange.start().setColumn(fromVirtualColumn(selectionRange.start().line(), newSelectionColumn));
2643  selectionRange.end().setColumn(fromVirtualColumn(selectionRange.end().line(), newSelectionColumn));
2644  view->setSelection(selectionRange);
2645  }
2646  else
2647  insertText(view->cursorPosition(), chars);
2648 
2649  // end edit session here, to have updated HL in userTypedChar!
2650  editEnd();
2651 
2652  KTextEditor::Cursor b(view->cursorPosition());
2653  m_indenter->userTypedChar (view, b, chars.isEmpty() ? QChar() : chars.at(chars.length() - 1));
2654 
2655  view->slotTextInserted (view, oldCur, chars);
2656  return true;
2657 }
2658 
2659 void KateDocument::newLine( KateView *v )
2660 {
2661  editStart();
2662 
2663  if( !v->config()->persistentSelection() && v->selection() ) {
2664  v->removeSelectedText();
2665  v->clearSelection();
2666  }
2667 
2668  // query cursor position
2669  KTextEditor::Cursor c = v->cursorPosition();
2670 
2671  if (c.line() > (int)lastLine())
2672  c.setLine(lastLine());
2673 
2674  if (c.line() < 0)
2675  c.setLine(0);
2676 
2677  uint ln = c.line();
2678 
2679  Kate::TextLine textLine = plainKateTextLine(ln);
2680 
2681  if (c.column() > (int)textLine->length())
2682  c.setColumn(textLine->length());
2683 
2684  // first: wrap line
2685  editWrapLine (c.line(), c.column());
2686 
2687  // end edit session here, to have updated HL in userTypedChar!
2688  editEnd();
2689 
2690  // second: indent the new line, if needed...
2691  m_indenter->userTypedChar(v, v->cursorPosition(), '\n');
2692 }
2693 
2694 void KateDocument::transpose( const KTextEditor::Cursor& cursor)
2695 {
2696  Kate::TextLine textLine = m_buffer->plainLine(cursor.line());
2697 
2698  if (!textLine || (textLine->length() < 2))
2699  return;
2700 
2701  uint col = cursor.column();
2702 
2703  if (col > 0)
2704  col--;
2705 
2706  if ((textLine->length() - col) < 2)
2707  return;
2708 
2709  uint line = cursor.line();
2710  QString s;
2711 
2712  //clever swap code if first character on the line swap right&left
2713  //otherwise left & right
2714  s.append (textLine->at(col+1));
2715  s.append (textLine->at(col));
2716  //do the swap
2717 
2718  // do it right, never ever manipulate a textline
2719  editStart ();
2720  editRemoveText (line, col, 2);
2721  editInsertText (line, col, s);
2722  editEnd ();
2723 }
2724 
2725 void KateDocument::backspace( KateView *view, const KTextEditor::Cursor& c )
2726 {
2727  if ( !view->config()->persistentSelection() && view->selection() ) {
2728  if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) {
2729  // Remove one character after selection line
2730  KTextEditor::Range range = view->selectionRange();
2731  range.start().setColumn(range.start().column() - 1);
2732  view->setSelection(range);
2733  }
2734  view->removeSelectedText();
2735  return;
2736  }
2737 
2738  uint col = qMax( c.column(), 0 );
2739  uint line = qMax( c.line(), 0 );
2740 
2741  if ((col == 0) && (line == 0))
2742  return;
2743 
2744  if (col > 0)
2745  {
2746  if (!(config()->backspaceIndents()))
2747  {
2748  // ordinary backspace
2749  //c.cursor.col--;
2750  removeText(KTextEditor::Range(line, col-1, line, col));
2751  // in most cases cursor is moved by removeText, but we should do it manually
2752  // for past-end-of-line cursors in block mode
2753  view->setCursorPosition(KTextEditor::Cursor(line, col-1));
2754  }
2755  else
2756  {
2757  // backspace indents: erase to next indent position
2758  Kate::TextLine textLine = m_buffer->plainLine(line);
2759 
2760  // don't forget this check!!!! really!!!!
2761  if (!textLine)
2762  return;
2763 
2764  int colX = textLine->toVirtualColumn(col, config()->tabWidth());
2765  int pos = textLine->firstChar();
2766  if (pos > 0)
2767  pos = textLine->toVirtualColumn(pos, config()->tabWidth());
2768 
2769  if (pos < 0 || pos >= (int)colX)
2770  {
2771  // only spaces on left side of cursor
2772  indent( KTextEditor::Range( line, 0, line, 0), -1);
2773  }
2774  else
2775  {
2776  removeText(KTextEditor::Range(line, col-1, line, col));
2777  // in most cases cursor is moved by removeText, but we should do it manually
2778  // for past-end-of-line cursors in block mode
2779  view->setCursorPosition(KTextEditor::Cursor(line, col-1));
2780  }
2781  }
2782  }
2783  else
2784  {
2785  // col == 0: wrap to previous line
2786  if (line >= 1)
2787  {
2788  Kate::TextLine textLine = m_buffer->plainLine(line-1);
2789 
2790  // don't forget this check!!!! really!!!!
2791  if (!textLine)
2792  return;
2793 
2794  if (config()->wordWrap() && textLine->endsWith(QLatin1String(" ")))
2795  {
2796  // gg: in hard wordwrap mode, backspace must also eat the trailing space
2797  removeText (KTextEditor::Range(line-1, textLine->length()-1, line, 0));
2798  }
2799  else
2800  removeText (KTextEditor::Range(line-1, textLine->length(), line, 0));
2801  }
2802  }
2803 }
2804 
2805 void KateDocument::del( KateView *view, const KTextEditor::Cursor& c )
2806 {
2807  if ( !view->config()->persistentSelection() && view->selection() ) {
2808  if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) {
2809  // Remove one character after selection line
2810  KTextEditor::Range range = view->selectionRange();
2811  range.end().setColumn(range.end().column() + 1);
2812  view->setSelection(range);
2813  }
2814  view->removeSelectedText();
2815  return;
2816  }
2817 
2818  if( c.column() < (int) m_buffer->plainLine(c.line())->length())
2819  {
2820  removeText(KTextEditor::Range(c, 1));
2821  }
2822  else if ( c.line() < lastLine() )
2823  {
2824  removeText(KTextEditor::Range(c.line(), c.column(), c.line()+1, 0));
2825  }
2826 }
2827 
2828 void KateDocument::paste ( KateView* view, const QString &text )
2829 {
2830  static const QChar newLineChar('\n');
2831  QString s = text;
2832 
2833  if (s.isEmpty())
2834  return;
2835 
2836  int lines = s.count (newLineChar);
2837 
2838  m_undoManager->undoSafePoint();
2839 
2840  editStart ();
2841 
2842  KTextEditor::Cursor pos = view->cursorPosition();
2843  if (!view->config()->persistentSelection() && view->selection()) {
2844  pos = view->selectionRange().start();
2845  if (view->blockSelection()) {
2846  pos = rangeOnLine(view->selectionRange(), pos.line()).start();
2847  if (lines == 0) {
2848  s += newLineChar;
2849  s = s.repeated(view->selectionRange().numberOfLines() + 1);
2850  s.chop(1);
2851  }
2852  }
2853  view->removeSelectedText();
2854  }
2855 
2856  if (config()->ovr()) {
2857  QStringList pasteLines = s.split(newLineChar);
2858 
2859  if (!view->blockSelection()) {
2860  int endColumn = (pasteLines.count() == 1 ? pos.column() : 0) + pasteLines.last().length();
2861  removeText(KTextEditor::Range(pos,
2862  pos.line()+pasteLines.count()-1, endColumn));
2863  } else {
2864  int maxi = qMin(pos.line() + pasteLines.count(), this->lines());
2865 
2866  for (int i = pos.line(); i < maxi; ++i) {
2867  int pasteLength = pasteLines.at(i-pos.line()).length();
2868  removeText(KTextEditor::Range(i, pos.column(),
2869  i, qMin(pasteLength + pos.column(), lineLength(i))));
2870  }
2871  }
2872  }
2873 
2874 
2875  insertText(pos, s, view->blockSelection());
2876  editEnd();
2877 
2878  // move cursor right for block select, as the user is moved right internal
2879  // even in that case, but user expects other behavior in block selection
2880  // mode !
2881  // just let cursor stay, that was it before I changed to moving ranges!
2882  if (view->blockSelection())
2883  view->setCursorPositionInternal(pos);
2884 
2885  if (config()->indentPastedText())
2886  {
2887  KTextEditor::Range range = KTextEditor::Range(KTextEditor::Cursor(pos.line(), 0),
2888  KTextEditor::Cursor(pos.line() + lines, 0));
2889 
2890  m_indenter->indent(view, range);
2891  }
2892 
2893  if (!view->blockSelection())
2894  emit charactersSemiInteractivelyInserted (pos, s);
2895  m_undoManager->undoSafePoint();
2896 }
2897 
2898 void KateDocument::indent (KTextEditor::Range range, int change)
2899 {
2900  if (!isReadWrite())
2901  return;
2902 
2903  editStart();
2904  m_indenter->changeIndent(range, change);
2905  editEnd();
2906 }
2907 
2908 void KateDocument::align(KateView *view, const KTextEditor::Range &range)
2909 {
2910  m_indenter->indent(view, range);
2911 }
2912 
2913 void KateDocument::insertTab( KateView *view, const KTextEditor::Cursor&)
2914 {
2915  if (!isReadWrite())
2916  return;
2917 
2918  int lineLen = line(view->cursorPosition().line()).length();
2919  KTextEditor::Cursor c = view->cursorPosition();
2920 
2921  editStart();
2922 
2923 
2924  if (!view->config()->persistentSelection() && view->selection() ) {
2925  view->removeSelectedText();
2926  }
2927  else if (config()->ovr() && c.column() < lineLen)
2928  {
2929  KTextEditor::Range r = KTextEditor::Range(view->cursorPosition(), 1);
2930 
2931  if (view->viInputMode() && view->getViInputModeManager()->getCurrentViMode() == ReplaceMode)
2932  {
2933  // vi replace mode needs to know what was removed so it can be restored with backspace
2934  QChar removed = line(view->cursorPosition().line()).at( r.start().column());
2935  view->getViInputModeManager()->getViReplaceMode()->overwrittenChar(removed);
2936  }
2937  removeText(r);
2938  }
2939 
2940  c = view->cursorPosition();
2941  editInsertText(c.line(), c.column(), QChar('\t'));
2942 
2943  editEnd();
2944 }
2945 
2946 /*
2947  Remove a given string at the beginning
2948  of the current line.
2949 */
2950 bool KateDocument::removeStringFromBeginning(int line, const QString &str)
2951 {
2952  Kate::TextLine textline = m_buffer->plainLine(line);
2953 
2954  KTextEditor::Cursor cursor (line, 0);
2955  bool there = textline->startsWith(str);
2956 
2957  if (!there)
2958  {
2959  cursor.setColumn(textline->firstChar());
2960  there = textline->matchesAt(cursor.column(), str);
2961  }
2962 
2963  if (there)
2964  {
2965  // Remove some chars
2966  removeText (KTextEditor::Range(cursor, str.length()));
2967  }
2968 
2969  return there;
2970 }
2971 
2972 /*
2973  Remove a given string at the end
2974  of the current line.
2975 */
2976 bool KateDocument::removeStringFromEnd(int line, const QString &str)
2977 {
2978  Kate::TextLine textline = m_buffer->plainLine(line);
2979 
2980  KTextEditor::Cursor cursor (line, 0);
2981  bool there = textline->endsWith(str);
2982 
2983  if (there)
2984  {
2985  cursor.setColumn(textline->length() - str.length());
2986  }
2987  else
2988  {
2989  cursor.setColumn(textline->lastChar() - str.length() + 1);
2990  there = textline->matchesAt(cursor.column(), str);
2991  }
2992 
2993  if (there)
2994  {
2995  // Remove some chars
2996  removeText (KTextEditor::Range(cursor, str.length()));
2997  }
2998 
2999  return there;
3000 }
3001 
3002 /*
3003  Add to the current line a comment line mark at the beginning.
3004 */
3005 void KateDocument::addStartLineCommentToSingleLine( int line, int attrib )
3006 {
3007  QString commentLineMark = highlight()->getCommentSingleLineStart(attrib);
3008  int pos = -1;
3009 
3010  if (highlight()->getCommentSingleLinePosition(attrib) == KateHighlighting::CSLPosColumn0)
3011  {
3012  pos = 0;
3013  commentLineMark += ' ';
3014  } else {
3015  const Kate::TextLine l = kateTextLine(line);
3016  pos = l->firstChar();
3017  }
3018 
3019  if (pos >= 0)
3020  insertText (KTextEditor::Cursor(line, pos), commentLineMark);
3021 }
3022 
3023 /*
3024  Remove from the current line a comment line mark at
3025  the beginning if there is one.
3026 */
3027 bool KateDocument::removeStartLineCommentFromSingleLine( int line, int attrib )
3028 {
3029  const QString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3030  const QString longCommentMark = shortCommentMark + ' ';
3031 
3032  editStart();
3033 
3034  // Try to remove the long comment mark first
3035  bool removed = (removeStringFromBeginning(line, longCommentMark)
3036  || removeStringFromBeginning(line, shortCommentMark));
3037 
3038  editEnd();
3039 
3040  return removed;
3041 }
3042 
3043 /*
3044  Add to the current line a start comment mark at the
3045  beginning and a stop comment mark at the end.
3046 */
3047 void KateDocument::addStartStopCommentToSingleLine( int line, int attrib )
3048 {
3049  const QString startCommentMark = highlight()->getCommentStart( attrib ) + ' ';
3050  const QString stopCommentMark = ' ' + highlight()->getCommentEnd( attrib );
3051 
3052  editStart();
3053 
3054  // Add the start comment mark
3055  insertText (KTextEditor::Cursor(line, 0), startCommentMark);
3056 
3057  // Go to the end of the line
3058  const int col = m_buffer->plainLine(line)->length();
3059 
3060  // Add the stop comment mark
3061  insertText (KTextEditor::Cursor(line, col), stopCommentMark);
3062 
3063  editEnd();
3064 }
3065 
3066 /*
3067  Remove from the current line a start comment mark at
3068  the beginning and a stop comment mark at the end.
3069 */
3070 bool KateDocument::removeStartStopCommentFromSingleLine( int line, int attrib )
3071 {
3072  QString shortStartCommentMark = highlight()->getCommentStart( attrib );
3073  QString longStartCommentMark = shortStartCommentMark + ' ';
3074  QString shortStopCommentMark = highlight()->getCommentEnd( attrib );
3075  QString longStopCommentMark = ' ' + shortStopCommentMark;
3076 
3077  editStart();
3078 
3079  // TODO "that's a bad idea, can lead to stray endings, FIXME"
3080 
3081  // Try to remove the long start comment mark first
3082  bool removedStart = (removeStringFromBeginning(line, longStartCommentMark)
3083  || removeStringFromBeginning(line, shortStartCommentMark));
3084 
3085  bool removedStop = false;
3086  if (removedStart)
3087  {
3088  // Try to remove the long stop comment mark first
3089  removedStop = (removeStringFromEnd(line, longStopCommentMark)
3090  || removeStringFromEnd(line, shortStopCommentMark));
3091  }
3092 
3093  editEnd();
3094 
3095  return (removedStart || removedStop);
3096 }
3097 
3098 /*
3099  Add to the current selection a start comment mark at the beginning
3100  and a stop comment mark at the end.
3101 */
3102 void KateDocument::addStartStopCommentToSelection( KateView *view, int attrib )
3103 {
3104  const QString startComment = highlight()->getCommentStart( attrib );
3105  const QString endComment = highlight()->getCommentEnd( attrib );
3106 
3107  KTextEditor::Range range = view->selectionRange();
3108 
3109  if ((range.end().column() == 0) && (range.end().line() > 0))
3110  range.end().setPosition(range.end().line() - 1, lineLength(range.end().line() - 1));
3111 
3112  editStart();
3113 
3114  if (!view->blockSelection()) {
3115  insertText(range.end(), endComment);
3116  insertText(range.start(), startComment);
3117  } else {
3118  for (int line = range.start().line(); line <= range.end().line(); line++ ) {
3119  KTextEditor::Range subRange = rangeOnLine(range, line);
3120  insertText(subRange.end(), endComment);
3121  insertText(subRange.start(), startComment);
3122  }
3123  }
3124 
3125  editEnd ();
3126  // selection automatically updated (MovingRange)
3127 }
3128 
3129 /*
3130  Add to the current selection a comment line mark at the beginning of each line.
3131 */
3132 void KateDocument::addStartLineCommentToSelection( KateView *view, int attrib )
3133 {
3134  const QString commentLineMark = highlight()->getCommentSingleLineStart( attrib ) + ' ';
3135 
3136  int sl = view->selectionRange().start().line();
3137  int el = view->selectionRange().end().line();
3138 
3139  // if end of selection is in column 0 in last line, omit the last line
3140  if ((view->selectionRange().end().column() == 0) && (el > 0))
3141  {
3142  el--;
3143  }
3144 
3145  editStart();
3146 
3147  // For each line of the selection
3148  for (int z = el; z >= sl; z--) {
3149  //insertText (z, 0, commentLineMark);
3150  addStartLineCommentToSingleLine(z, attrib );
3151  }
3152 
3153  editEnd ();
3154  // selection automatically updated (MovingRange)
3155 }
3156 
3157 bool KateDocument::nextNonSpaceCharPos(int &line, int &col)
3158 {
3159  for(; line < (int)m_buffer->count(); line++) {
3160  Kate::TextLine textLine = m_buffer->plainLine(line);
3161 
3162  if (!textLine)
3163  break;
3164 
3165  col = textLine->nextNonSpaceChar(col);
3166  if(col != -1)
3167  return true; // Next non-space char found
3168  col = 0;
3169  }
3170  // No non-space char found
3171  line = -1;
3172  col = -1;
3173  return false;
3174 }
3175 
3176 bool KateDocument::previousNonSpaceCharPos(int &line, int &col)
3177 {
3178  while(true)
3179  {
3180  Kate::TextLine textLine = m_buffer->plainLine(line);
3181 
3182  if (!textLine)
3183  break;
3184 
3185  col = textLine->previousNonSpaceChar(col);
3186  if(col != -1) return true;
3187  if(line == 0) return false;
3188  --line;
3189  col = textLine->length();
3190  }
3191  // No non-space char found
3192  line = -1;
3193  col = -1;
3194  return false;
3195 }
3196 
3197 /*
3198  Remove from the selection a start comment mark at
3199  the beginning and a stop comment mark at the end.
3200 */
3201 bool KateDocument::removeStartStopCommentFromSelection( KateView *view, int attrib )
3202 {
3203  const QString startComment = highlight()->getCommentStart( attrib );
3204  const QString endComment = highlight()->getCommentEnd( attrib );
3205 
3206  int sl = qMax<int> (0, view->selectionRange().start().line());
3207  int el = qMin<int> (view->selectionRange().end().line(), lastLine());
3208  int sc = view->selectionRange().start().column();
3209  int ec = view->selectionRange().end().column();
3210 
3211  // The selection ends on the char before selectEnd
3212  if (ec != 0) {
3213  --ec;
3214  } else if (el > 0) {
3215  --el;
3216  ec = m_buffer->plainLine(el)->length() - 1;
3217  }
3218 
3219  const int startCommentLen = startComment.length();
3220  const int endCommentLen = endComment.length();
3221 
3222  // had this been perl or sed: s/^\s*$startComment(.+?)$endComment\s*/$2/
3223 
3224  bool remove = nextNonSpaceCharPos(sl, sc)
3225  && m_buffer->plainLine(sl)->matchesAt(sc, startComment)
3226  && previousNonSpaceCharPos(el, ec)
3227  && ( (ec - endCommentLen + 1) >= 0 )
3228  && m_buffer->plainLine(el)->matchesAt(ec - endCommentLen + 1, endComment);
3229 
3230  if (remove) {
3231  editStart();
3232 
3233  removeText (KTextEditor::Range(el, ec - endCommentLen + 1, el, ec + 1));
3234  removeText (KTextEditor::Range(sl, sc, sl, sc + startCommentLen));
3235 
3236  editEnd ();
3237  // selection automatically updated (MovingRange)
3238  }
3239 
3240  return remove;
3241 }
3242 
3243 bool KateDocument::removeStartStopCommentFromRegion(const KTextEditor::Cursor &start,const KTextEditor::Cursor &end,int attrib)
3244 {
3245  const QString startComment = highlight()->getCommentStart( attrib );
3246  const QString endComment = highlight()->getCommentEnd( attrib );
3247  const int startCommentLen = startComment.length();
3248  const int endCommentLen = endComment.length();
3249 
3250  const bool remove = m_buffer->plainLine(start.line())->matchesAt(start.column(), startComment)
3251  && m_buffer->plainLine(end.line())->matchesAt(end.column() - endCommentLen , endComment);
3252  if (remove) {
3253  editStart();
3254  removeText(KTextEditor::Range(end.line(), end.column() - endCommentLen, end.line(), end.column()));
3255  removeText(KTextEditor::Range(start, startCommentLen));
3256  editEnd();
3257  }
3258  return remove;
3259 }
3260 
3261 /*
3262  Remove from the beginning of each line of the
3263  selection a start comment line mark.
3264 */
3265 bool KateDocument::removeStartLineCommentFromSelection( KateView *view, int attrib )
3266 {
3267  const QString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3268  const QString longCommentMark = shortCommentMark + ' ';
3269 
3270  int sl = view->selectionRange().start().line();
3271  int el = view->selectionRange().end().line();
3272 
3273  if ((view->selectionRange().end().column() == 0) && (el > 0))
3274  {
3275  el--;
3276  }
3277 
3278  bool removed = false;
3279 
3280  editStart();
3281 
3282  // For each line of the selection
3283  for (int z = el; z >= sl; z--)
3284  {
3285  // Try to remove the long comment mark first
3286  removed = (removeStringFromBeginning(z, longCommentMark)
3287  || removeStringFromBeginning(z, shortCommentMark)
3288  || removed);
3289  }
3290 
3291  editEnd();
3292  // selection automatically updated (MovingRange)
3293 
3294  return removed;
3295 }
3296 
3297 /*
3298  Comment or uncomment the selection or the current
3299  line if there is no selection.
3300 */
3301 void KateDocument::comment( KateView *v, uint line,uint column, int change)
3302 {
3303  // skip word wrap bug #105373
3304  const bool skipWordWrap = wordWrap();
3305  if (skipWordWrap) setWordWrap(false);
3306 
3307  bool hassel = v->selection();
3308  int c = 0;
3309 
3310  if ( hassel )
3311  c = v->selectionRange().start().column();
3312 
3313  int startAttrib = 0;
3314  Kate::TextLine ln = kateTextLine( line );
3315 
3316  if ( c < ln->length() )
3317  startAttrib = ln->attribute( c );
3318  else if ( !ln->contextStack().isEmpty() )
3319  startAttrib = highlight()->attribute( ln->contextStack().last() );
3320 
3321  bool hasStartLineCommentMark = !(highlight()->getCommentSingleLineStart( startAttrib ).isEmpty());
3322  bool hasStartStopCommentMark = ( !(highlight()->getCommentStart( startAttrib ).isEmpty())
3323  && !(highlight()->getCommentEnd( startAttrib ).isEmpty()) );
3324 
3325  bool removed = false;
3326 
3327  if (change > 0) // comment
3328  {
3329  if ( !hassel )
3330  {
3331  if ( hasStartLineCommentMark )
3332  addStartLineCommentToSingleLine( line, startAttrib );
3333  else if ( hasStartStopCommentMark )
3334  addStartStopCommentToSingleLine( line, startAttrib );
3335  }
3336  else
3337  {
3338  // anders: prefer single line comment to avoid nesting probs
3339  // If the selection starts after first char in the first line
3340  // or ends before the last char of the last line, we may use
3341  // multiline comment markers.
3342  // TODO We should try to detect nesting.
3343  // - if selection ends at col 0, most likely she wanted that
3344  // line ignored
3345  const KTextEditor::Range sel = v->selectionRange();
3346  if ( hasStartStopCommentMark &&
3347  ( !hasStartLineCommentMark || (
3348  ( sel.start().column() > m_buffer->plainLine( sel.start().line() )->firstChar() ) ||
3349  ( sel.end().column() > 0 &&
3350  sel.end().column() < (m_buffer->plainLine( sel.end().line() )->length()) )
3351  ) ) )
3352  addStartStopCommentToSelection( v, startAttrib );
3353  else if ( hasStartLineCommentMark )
3354  addStartLineCommentToSelection( v, startAttrib );
3355  }
3356  }
3357  else // uncomment
3358  {
3359  if ( !hassel )
3360  {
3361  removed = ( hasStartLineCommentMark
3362  && removeStartLineCommentFromSingleLine( line, startAttrib ) )
3363  || ( hasStartStopCommentMark
3364  && removeStartStopCommentFromSingleLine( line, startAttrib ) );
3365  }
3366  else
3367  {
3368  // anders: this seems like it will work with above changes :)
3369  removed = ( hasStartStopCommentMark
3370  && removeStartStopCommentFromSelection( v, startAttrib ) )
3371  || ( hasStartLineCommentMark
3372  && removeStartLineCommentFromSelection( v, startAttrib ) );
3373  }
3374 
3375  // recursive call for toggle comment
3376  if (!removed && change == 0)
3377  comment(v, line, column, 1);
3378  }
3379 
3380  if (skipWordWrap) setWordWrap(true); // see begin of function ::comment (bug #105373)
3381 }
3382 
3383 void KateDocument::transform( KateView *v, const KTextEditor::Cursor &c,
3384  KateDocument::TextTransform t )
3385 {
3386  if ( v->selection() )
3387  {
3388  editStart();
3389 
3390  // remember cursor
3391  KTextEditor::Cursor cursor = c;
3392 
3393  // cache the selection and cursor, so we can be sure to restore.
3394  KTextEditor::Range selection = v->selectionRange();
3395 
3396  KTextEditor::Range range(selection.start(), 0);
3397  while ( range.start().line() <= selection.end().line() )
3398  {
3399  int start = 0;
3400  int end = lineLength( range.start().line() );
3401 
3402  if (range.start().line() == selection.start().line() || v->blockSelection())
3403  start = selection.start().column();
3404 
3405  if (range.start().line() == selection.end().line() || v->blockSelection())
3406  end = selection.end().column();
3407 
3408  if ( start > end )
3409  {
3410  int swapCol = start;
3411  start = end;
3412  end = swapCol;
3413  }
3414  range.start().setColumn( start );
3415  range.end().setColumn( end );
3416 
3417  QString s = text( range );
3418  QString old = s;
3419 
3420  if ( t == Uppercase )
3421  s = s.toUpper();
3422  else if ( t == Lowercase )
3423  s = s.toLower();
3424  else // Capitalize
3425  {
3426  Kate::TextLine l = m_buffer->plainLine( range.start().line() );
3427  int p ( 0 );
3428  while( p < s.length() )
3429  {
3430  // If bol or the character before is not in a word, up this one:
3431  // 1. if both start and p is 0, upper char.
3432  // 2. if blockselect or first line, and p == 0 and start-1 is not in a word, upper
3433  // 3. if p-1 is not in a word, upper.
3434  if ( ( ! range.start().column() && ! p ) ||
3435  ( ( range.start().line() == selection.start().line() || v->blockSelection() ) &&
3436  ! p && ! highlight()->isInWord( l->at( range.start().column() - 1 )) ) ||
3437  ( p && ! highlight()->isInWord( s.at( p-1 ) ) )
3438  ) {
3439  s[p] = s.at(p).toUpper();
3440  }
3441  p++;
3442  }
3443  }
3444 
3445  if ( s != old )
3446  {
3447  removeText( range );
3448  insertText( range.start(), s );
3449  }
3450 
3451  range.setBothLines(range.start().line() + 1);
3452  }
3453 
3454  editEnd();
3455 
3456  // restore selection & cursor
3457  v->setSelection( selection );
3458  v->setCursorPosition( c );
3459 
3460  } else { // no selection
3461  editStart();
3462 
3463  // get cursor
3464  KTextEditor::Cursor cursor = c;
3465 
3466  QString old = text( KTextEditor::Range(cursor, 1) );
3467  QString s;
3468  switch ( t ) {
3469  case Uppercase:
3470  s = old.toUpper();
3471  break;
3472  case Lowercase:
3473  s = old.toLower();
3474  break;
3475  case Capitalize:
3476  {
3477  Kate::TextLine l = m_buffer->plainLine( cursor.line() );
3478  while ( cursor.column() > 0 && highlight()->isInWord( l->at( cursor.column() - 1 ), l->attribute( cursor.column() - 1 ) ) )
3479  cursor.setColumn(cursor.column() - 1);
3480  old = text( KTextEditor::Range(cursor, 1) );
3481  s = old.toUpper();
3482  }
3483  break;
3484  default:
3485  break;
3486  }
3487 
3488  removeText( KTextEditor::Range(cursor, 1) );
3489  insertText( cursor, s );
3490 
3491  editEnd();
3492  }
3493 
3494 }
3495 
3496 void KateDocument::joinLines( uint first, uint last )
3497 {
3498 // if ( first == last ) last += 1;
3499  editStart();
3500  int line( first );
3501  while ( first < last )
3502  {
3503  // Normalize the whitespace in the joined lines by making sure there's
3504  // always exactly one space between the joined lines
3505  // This cannot be done in editUnwrapLine, because we do NOT want this
3506  // behavior when deleting from the start of a line, just when explicitly
3507  // calling the join command
3508  Kate::TextLine l = kateTextLine( line );
3509  Kate::TextLine tl = kateTextLine( line + 1 );
3510 
3511  if ( !l || !tl )
3512  {
3513  editEnd();
3514  return;
3515  }
3516 
3517  int pos = tl->firstChar();
3518  if ( pos >= 0 )
3519  {
3520  if (pos != 0)
3521  editRemoveText( line + 1, 0, pos );
3522  if ( !( l->length() == 0 || l->at( l->length() - 1 ).isSpace() ) )
3523  editInsertText( line + 1, 0, " " );
3524  }
3525  else
3526  {
3527  // Just remove the whitespace and let Kate handle the rest
3528  editRemoveText( line + 1, 0, tl->length() );
3529  }
3530 
3531  editUnWrapLine( line );
3532  first++;
3533  }
3534  editEnd();
3535 }
3536 
3537 QString KateDocument::getWord( const KTextEditor::Cursor& cursor )
3538 {
3539  int start, end, len;
3540 
3541  Kate::TextLine textLine = m_buffer->plainLine(cursor.line());
3542  len = textLine->length();
3543  start = end = cursor.column();
3544  if (start > len) // Probably because of non-wrapping cursor mode.
3545  return QString();
3546 
3547  while (start > 0 && highlight()->isInWord(textLine->at(start - 1), textLine->attribute(start - 1))) start--;
3548  while (end < len && highlight()->isInWord(textLine->at(end), textLine->attribute(end))) end++;
3549  len = end - start;
3550  return textLine->string().mid(start, len);
3551 }
3552 
3553 void KateDocument::tagLines(int start, int end)
3554 {
3555  foreach(KateView *view,m_views)
3556  view->tagLines (start, end, true);
3557 }
3558 
3559 void KateDocument::repaintViews(bool paintOnlyDirty)
3560 {
3561  foreach(KateView *view,m_views)
3562  view->repaintText(paintOnlyDirty);
3563 }
3564 
3565 /*
3566  Bracket matching uses the following algorithm:
3567  If in overwrite mode, match the bracket currently underneath the cursor.
3568  Otherwise, if the character to the left is a bracket,
3569  match it. Otherwise if the character to the right of the cursor is a
3570  bracket, match it. Otherwise, don't match anything.
3571 */
3572 void KateDocument::newBracketMark( const KTextEditor::Cursor& cursor, KTextEditor::Range& bm, int maxLines )
3573 {
3574  // search from cursor for brackets
3575  KTextEditor::Range range (cursor, cursor);
3576 
3577  // if match found, remember the range
3578  if( findMatchingBracket( range, maxLines ) ) {
3579  bm = range;
3580  return;
3581  }
3582 
3583  // else, invalidate, if still valid
3584  if (bm.isValid())
3585  bm = KTextEditor::Range::invalid();
3586 }
3587 
3588 bool KateDocument::findMatchingBracket( KTextEditor::Range& range, int maxLines )
3589 {
3590  Kate::TextLine textLine = m_buffer->plainLine( range.start().line() );
3591  if( !textLine )
3592  return false;
3593 
3594  QChar right = textLine->at( range.start().column() );
3595  QChar left = textLine->at( range.start().column() - 1 );
3596  QChar bracket;
3597 
3598  if ( config()->ovr() ) {
3599  if( isBracket( right ) ) {
3600  bracket = right;
3601  } else {
3602  return false;
3603  }
3604  } else if ( isBracket( left ) ) {
3605  range.start().setColumn(range.start().column() - 1);
3606  bracket = left;
3607  } else if ( isBracket( right ) ) {
3608  bracket = right;
3609  } else {
3610  return false;
3611  }
3612 
3613  QChar opposite;
3614 
3615  switch( bracket.toAscii() ) {
3616  case '{': opposite = '}'; break;
3617  case '}': opposite = '{'; break;
3618  case '[': opposite = ']'; break;
3619  case ']': opposite = '['; break;
3620  case '(': opposite = ')'; break;
3621  case ')': opposite = '('; break;
3622  default: return false;
3623  }
3624 
3625  const int searchDir = isStartBracket( bracket ) ? 1 : -1;
3626  uint nesting = 0;
3627 
3628  int minLine = qMax( range.start().line() - maxLines, 0 );
3629  int maxLine = qMin( range.start().line() + maxLines, documentEnd().line() );
3630 
3631  range.end() = range.start();
3632  KTextEditor::DocumentCursor cursor(this);
3633  cursor.setPosition(range.start());
3634  int validAttr = kateTextLine(cursor.line())->attribute(cursor.column());
3635 
3636  while( cursor.line() >= minLine && cursor.line() <= maxLine ) {
3637 
3638  if (!cursor.move(searchDir))
3639  return false;
3640 
3641  Kate::TextLine textLine = kateTextLine(cursor.line());
3642  if (textLine->attribute(cursor.column()) == validAttr )
3643  {
3644  // Check for match
3645  QChar c = textLine->at(cursor.column());
3646  if( c == opposite ) {
3647  if( nesting == 0 ) {
3648  if (searchDir > 0) // forward
3649  range.end() = cursor.toCursor();
3650  else
3651  range.start() = cursor.toCursor();
3652  return true;
3653  }
3654  nesting--;
3655  } else if( c == bracket ) {
3656  nesting++;
3657  }
3658  }
3659  }
3660 
3661  return false;
3662 }
3663 
3664 // helper: remove \r and \n from visible document name (bug #170876)
3665 inline static QString removeNewLines(const QString& str)
3666 {
3667  QString tmp(str);
3668  return tmp.replace(QLatin1String("\r\n"), QLatin1String(" "))
3669  .replace(QChar('\r'), QLatin1Char(' '))
3670  .replace(QChar('\n'), QLatin1Char(' '));
3671 }
3672 
3673 void KateDocument::updateDocName ()
3674 {
3675  // if the name is set, and starts with FILENAME, it should not be changed!
3676  if ( ! url().isEmpty()
3677  && (m_docName == removeNewLines(url().fileName()) ||
3678  m_docName.startsWith (removeNewLines(url().fileName()) + " (") ) ) {
3679  return;
3680  }
3681 
3682  int count = -1;
3683 
3684 
3685  foreach(KateDocument* doc, KateGlobal::self()->kateDocuments())
3686  {
3687  if ( (doc != this) && (doc->url().fileName() == url().fileName()) )
3688  if ( doc->m_docNameNumber > count )
3689  count = doc->m_docNameNumber;
3690  }
3691 
3692  m_docNameNumber = count + 1;
3693 
3694  QString oldName = m_docName;
3695  m_docName = removeNewLines(url().fileName());
3696 
3697  m_isUntitled = m_docName.isEmpty();
3698  if (m_isUntitled) {
3699  m_docName = i18n ("Untitled");
3700  }
3701 
3702  if (m_docNameNumber > 0)
3703  m_docName = QString(m_docName + " (%1)").arg(m_docNameNumber+1);
3704 
3708  if (oldName != m_docName)
3709  emit documentNameChanged (this);
3710 }
3711 
3712 void KateDocument::slotModifiedOnDisk( KTextEditor::View * /*v*/ )
3713 {
3714  if ( m_isasking < 0 )
3715  {
3716  m_isasking = 0;
3717  return;
3718  }
3719 
3720  if ( !m_fileChangedDialogsActivated || m_isasking )
3721  return;
3722 
3723  if (m_modOnHd && !url().isEmpty())
3724  {
3725  m_isasking = 1;
3726 
3727  QWidget *parentWidget(dialogParent());
3728 
3729  KateModOnHdPrompt p( this, m_modOnHdReason, reasonedMOHString(), parentWidget );
3730  switch ( p.exec() )
3731  {
3732  case KateModOnHdPrompt::Save:
3733  {
3734  m_modOnHd = false;
3735  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
3736  url().url(),QString(),parentWidget,i18n("Save File"));
3737 
3738  kDebug(13020)<<"got "<<res.URLs.count()<<" URLs";
3739  if( ! res.URLs.isEmpty() && ! res.URLs.first().isEmpty() && checkOverwrite( res.URLs.first(), parentWidget ) )
3740  {
3741  setEncoding( res.encoding );
3742 
3743  if( ! saveAs( res.URLs.first() ) )
3744  {
3745  KMessageBox::error( parentWidget, i18n("Save failed") );
3746  m_modOnHd = true;
3747  }
3748  else
3749  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3750  }
3751  else // the save as dialog was canceled, we are still modified on disk
3752  {
3753  m_modOnHd = true;
3754  }
3755 
3756  m_isasking = 0;
3757  break;
3758  }
3759 
3760  case KateModOnHdPrompt::Reload:
3761  m_modOnHd = false;
3762  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3763  documentReload();
3764  m_isasking = 0;
3765  break;
3766 
3767  case KateModOnHdPrompt::Ignore:
3768  m_modOnHd = false;
3769  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3770  m_isasking = 0;
3771  break;
3772 
3773  case KateModOnHdPrompt::Overwrite:
3774  m_modOnHd = false;
3775  emit modifiedOnDisk( this, false, OnDiskUnmodified );
3776  m_isasking = 0;
3777  save();
3778  break;
3779 
3780  default: // Delay/cancel: ignore next focus event
3781  m_isasking = -1;
3782  }
3783  }
3784 }
3785 
3786 void KateDocument::setModifiedOnDisk( ModifiedOnDiskReason reason )
3787 {
3788  m_modOnHdReason = reason;
3789  m_modOnHd = (reason != OnDiskUnmodified);
3790  emit modifiedOnDisk( this, (reason != OnDiskUnmodified), reason );
3791 }
3792 
3793 class KateDocumentTmpMark
3794 {
3795  public:
3796  QString line;
3797  KTextEditor::Mark mark;
3798 };
3799 
3800 void KateDocument::setModifiedOnDiskWarning (bool on)
3801 {
3802  m_fileChangedDialogsActivated = on;
3803 }
3804 
3805 bool KateDocument::documentReload()
3806 {
3807  if ( !url().isEmpty() )
3808  {
3809  if (m_modOnHd && m_fileChangedDialogsActivated)
3810  {
3811  QWidget *parentWidget(dialogParent());
3812 
3813  int i = KMessageBox::warningYesNoCancel
3814  (parentWidget, reasonedMOHString() + "\n\n" + i18n("What do you want to do?"),
3815  i18n("File Was Changed on Disk"),
3816  KGuiItem(i18n("&Reload File"), "view-refresh"),
3817  KGuiItem(i18n("&Ignore Changes"), "dialog-warning"));
3818 
3819  if ( i != KMessageBox::Yes)
3820  {
3821  if (i == KMessageBox::No)
3822  {
3823  m_modOnHd = false;
3824  m_modOnHdReason = OnDiskUnmodified;
3825  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
3826  }
3827 
3828  // reset some flags only valid for one reload!
3829  m_userSetEncodingForNextReload = false;
3830  return false;
3831  }
3832  }
3833 
3834  emit aboutToReload(this);
3835 
3836  QList<KateDocumentTmpMark> tmp;
3837 
3838  for (QHash<int, KTextEditor::Mark*>::const_iterator i = m_marks.constBegin(); i != m_marks.constEnd(); ++i)
3839  {
3840  KateDocumentTmpMark m;
3841 
3842  m.line = line (i.value()->line);
3843  m.mark = *i.value();
3844 
3845  tmp.append (m);
3846  }
3847 
3848  const QString oldMode = mode ();
3849  const bool byUser = m_fileTypeSetByUser;
3850  const QString hl_mode = highlightingMode ();
3851  KTextEditor::View* oldActiveView = activeView();
3852 
3853  m_storedVariables.clear();
3854 
3855  // save cursor positions for all views
3856  QVector<KTextEditor::Cursor> cursorPositions;
3857  cursorPositions.reserve(m_views.size());
3858  foreach (KateView *v, m_views)
3859  cursorPositions.append( v->cursorPosition() );
3860 
3861  m_reloading = true;
3862  KateDocument::openUrl( url() );
3863 
3864  // reset some flags only valid for one reload!
3865  m_userSetEncodingForNextReload = false;
3866 
3867  // restore cursor positions for all views
3868  QLinkedList<KateView*>::iterator it = m_views.begin();
3869  for(int i = 0; i < m_views.size(); ++i, ++it) {
3870  setActiveView(*it);
3871  (*it)->setCursorPositionInternal( cursorPositions.at(i), m_config->tabWidth(), false );
3872  if ((*it)->isVisible()) {
3873  (*it)->repaintText(false);
3874  }
3875  }
3876  setActiveView(oldActiveView);
3877 
3878  for (int z=0; z < tmp.size(); z++)
3879  {
3880  if (z < (int)lines())
3881  {
3882  if (line(tmp.at(z).mark.line) == tmp.at(z).line)
3883  setMark (tmp.at(z).mark.line, tmp.at(z).mark.type);
3884  }
3885  }
3886 
3887  if (byUser)
3888  setMode (oldMode);
3889  setHighlightingMode (hl_mode);
3890 
3891  emit reloaded(this);
3892 
3893  return true;
3894  }
3895 
3896  return false;
3897 }
3898 
3899 bool KateDocument::documentSave()
3900 {
3901  if( !url().isValid() || !isReadWrite() )
3902  return documentSaveAs();
3903 
3904  return save();
3905 }
3906 
3907 bool KateDocument::documentSaveAs()
3908 {
3909  QWidget *parentWidget(dialogParent());
3910 
3911  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
3912  url().url(),QString(),parentWidget,i18n("Save File"));
3913 
3914  if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first(), parentWidget ) )
3915  return false;
3916 
3917  setEncoding( res.encoding );
3918 
3919  return saveAs( res.URLs.first() );
3920 }
3921 
3922 void KateDocument::setWordWrap (bool on)
3923 {
3924  config()->setWordWrap (on);
3925 }
3926 
3927 bool KateDocument::wordWrap () const
3928 {
3929  return config()->wordWrap ();
3930 }
3931 
3932 void KateDocument::setWordWrapAt (uint col)
3933 {
3934  config()->setWordWrapAt (col);
3935 }
3936 
3937 unsigned int KateDocument::wordWrapAt () const
3938 {
3939  return config()->wordWrapAt ();
3940 }
3941 
3942 void KateDocument::setPageUpDownMovesCursor (bool on)
3943 {
3944  config()->setPageUpDownMovesCursor (on);
3945 }
3946 
3947 bool KateDocument::pageUpDownMovesCursor () const
3948 {
3949  return config()->pageUpDownMovesCursor ();
3950 }
3951 //END
3952 
3953 bool KateDocument::setEncoding (const QString &e)
3954 {
3955  return m_config->setEncoding(e);
3956 }
3957 
3958 const QString &KateDocument::encoding() const
3959 {
3960  return m_config->encoding();
3961 }
3962 
3963 void KateDocument::updateConfig ()
3964 {
3965  m_undoManager->updateConfig ();
3966 
3967  // switch indenter if needed and update config....
3968  m_indenter->setMode (m_config->indentationMode());
3969  m_indenter->updateConfig();
3970 
3971  // set tab width there, too
3972  m_buffer->setTabWidth (config()->tabWidth());
3973 
3974  // update all views, does tagAll and updateView...
3975  foreach (KateView * view, m_views)
3976  view->updateDocumentConfig ();
3977 
3978  // update on-the-fly spell checking as spell checking defaults might have changes
3979  if(m_onTheFlyChecker) {
3980  m_onTheFlyChecker->updateConfig();
3981  }
3982 
3983  emit configChanged();
3984 }
3985 
3986 //BEGIN Variable reader
3987 // "local variable" feature by anders, 2003
3988 /* TODO
3989  add config options (how many lines to read, on/off)
3990  add interface for plugins/apps to set/get variables
3991  add view stuff
3992 */
3993 QRegExp KateDocument::kvLine = QRegExp("kate:(.*)");
3994 QRegExp KateDocument::kvLineWildcard = QRegExp("kate-wildcard\\((.*)\\):(.*)");
3995 QRegExp KateDocument::kvLineMime = QRegExp("kate-mimetype\\((.*)\\):(.*)");
3996 QRegExp KateDocument::kvVar = QRegExp("([\\w\\-]+)\\s+([^;]+)");
3997 
3998 void KateDocument::readVariables(bool onlyViewAndRenderer)
3999 {
4000  if (!onlyViewAndRenderer)
4001  m_config->configStart();
4002 
4003  // views!
4004  KateView *v;
4005  foreach (v,m_views)
4006  {
4007  v->config()->configStart();
4008  v->renderer()->config()->configStart();
4009  }
4010  // read a number of lines in the top/bottom of the document
4011  for (int i=0; i < qMin( 9, lines() ); ++i )
4012  {
4013  readVariableLine( line( i ), onlyViewAndRenderer );
4014  }
4015  if ( lines() > 10 )
4016  {
4017  for ( int i = qMax( 10, lines() - 10); i < lines(); i++ )
4018  {
4019  readVariableLine( line( i ), onlyViewAndRenderer );
4020  }
4021  }
4022 
4023  if (!onlyViewAndRenderer)
4024  m_config->configEnd();
4025 
4026  foreach (v,m_views)
4027  {
4028  v->config()->configEnd();
4029  v->renderer()->config()->configEnd();
4030  }
4031 }
4032 
4033 void KateDocument::readVariableLine( QString t, bool onlyViewAndRenderer )
4034 {
4035  // simple check first, no regex
4036  // no kate inside, no vars, simple...
4037  if (!t.contains("kate"))
4038  return;
4039 
4040  // found vars, if any
4041  QString s;
4042 
4043  // now, try first the normal ones
4044  if ( kvLine.indexIn( t ) > -1 )
4045  {
4046  s = kvLine.cap(1);
4047 
4048  kDebug (13020) << "normal variable line kate: matched: " << s;
4049  }
4050  else if (kvLineWildcard.indexIn( t ) > -1) // regex given
4051  {
4052  const QStringList wildcards (kvLineWildcard.cap(1).split (';', QString::SkipEmptyParts));
4053  const QString nameOfFile = url().fileName();
4054 
4055  bool found = false;
4056  foreach(const QString& pattern, wildcards)
4057  {
4058  QRegExp wildcard (pattern, Qt::CaseSensitive, QRegExp::Wildcard);
4059 
4060  found = wildcard.exactMatch (nameOfFile);
4061  }
4062 
4063  // nothing usable found...
4064  if (!found)
4065  return;
4066 
4067  s = kvLineWildcard.cap(2);
4068 
4069  kDebug (13020) << "guarded variable line kate-wildcard: matched: " << s;
4070  }
4071  else if (kvLineMime.indexIn( t ) > -1) // mime-type given
4072  {
4073  const QStringList types (kvLineMime.cap(1).split (';', QString::SkipEmptyParts));
4074 
4075  // no matching type found
4076  if (!types.contains (mimeType ()))
4077  return;
4078 
4079  s = kvLineMime.cap(2);
4080 
4081  kDebug (13020) << "guarded variable line kate-mimetype: matched: " << s;
4082  }
4083  else // nothing found
4084  {
4085  return;
4086  }
4087 
4088  QStringList vvl; // view variable names
4089  vvl << "dynamic-word-wrap" << "dynamic-word-wrap-indicators"
4090  << "line-numbers" << "icon-border" << "folding-markers"
4091  << "bookmark-sorting" << "auto-center-lines"
4092  << "icon-bar-color"
4093  // renderer
4094  << "background-color" << "selection-color"
4095  << "current-line-color" << "bracket-highlight-color"
4096  << "word-wrap-marker-color"
4097  << "font" << "font-size" << "scheme";
4098  int spaceIndent = -1; // for backward compatibility; see below
4099  bool replaceTabsSet = false;
4100  int p( 0 );
4101 
4102  QString var, val;
4103  while ( (p = kvVar.indexIn( s, p )) > -1 )
4104  {
4105  p += kvVar.matchedLength();
4106  var = kvVar.cap( 1 );
4107  val = kvVar.cap( 2 ).trimmed();
4108  bool state; // store booleans here
4109  int n; // store ints here
4110 
4111  // only apply view & renderer config stuff
4112  if (onlyViewAndRenderer)
4113  {
4114  if ( vvl.contains( var ) ) // FIXME define above
4115  setViewVariable( var, val );
4116  }
4117  else
4118  {
4119  // BOOL SETTINGS
4120  if ( var == "word-wrap" && checkBoolValue( val, &state ) )
4121  setWordWrap( state ); // ??? FIXME CHECK
4122  // KateConfig::configFlags
4123  // FIXME should this be optimized to only a few calls? how?
4124  else if ( var == "backspace-indents" && checkBoolValue( val, &state ) )
4125  m_config->setBackspaceIndents( state );
4126  else if ( var == "indent-pasted-text" && checkBoolValue( val, &state ) )
4127  m_config->setIndentPastedText( state );
4128  else if ( var == "replace-tabs" && checkBoolValue( val, &state ) )
4129  {
4130  m_config->setReplaceTabsDyn( state );
4131  replaceTabsSet = true; // for backward compatibility; see below
4132  }
4133  else if ( var == "remove-trailing-space" && checkBoolValue( val, &state ) ) {
4134  kWarning() << i18n("Using deprecated modeline 'remove-trailing-space'. "
4135  "Please replace with 'remove-trailing-spaces modified;', see "
4136  "http://docs.kde.org/stable/en/kde-baseapps/kate/config-variables.html#variable-remove-trailing-spaces");
4137  m_config->setRemoveSpaces( state ? 1 : 0 );
4138  }
4139  else if ( var == "replace-trailing-space-save" && checkBoolValue( val, &state ) ) {
4140  kWarning() << i18n("Using deprecated modeline 'replace-trailing-space-save'. "
4141  "Please replace with 'remove-trailing-spaces all;', see "
4142  "http://docs.kde.org/stable/en/kde-baseapps/kate/config-variables.html#variable-remove-trailing-spaces");
4143  m_config->setRemoveSpaces( state ? 2 : 0 );
4144  }
4145  else if ( var == "overwrite-mode" && checkBoolValue( val, &state ) )
4146  m_config->setOvr( state );
4147  else if ( var == "keep-extra-spaces" && checkBoolValue( val, &state ) )
4148  m_config->setKeepExtraSpaces( state );
4149  else if ( var == "tab-indents" && checkBoolValue( val, &state ) )
4150  m_config->setTabIndents( state );
4151  else if ( var == "show-tabs" && checkBoolValue( val, &state ) )
4152  m_config->setShowTabs( state );
4153  else if ( var == "show-trailing-spaces" && checkBoolValue( val, &state ) )
4154  m_config->setShowSpaces( state );
4155  else if ( var == "space-indent" && checkBoolValue( val, &state ) )
4156  {
4157  // this is for backward compatibility; see below
4158  spaceIndent = state;
4159  }
4160  else if ( var == "smart-home" && checkBoolValue( val, &state ) )
4161  m_config->setSmartHome( state );
4162  else if ( var == "newline-at-eof" && checkBoolValue( val, &state ) )
4163  m_config->setNewLineAtEof( state );
4164 
4165  // INTEGER SETTINGS
4166  else if ( var == "tab-width" && checkIntValue( val, &n ) )
4167  m_config->setTabWidth( n );
4168  else if ( var == "indent-width" && checkIntValue( val, &n ) )
4169  m_config->setIndentationWidth( n );
4170  else if ( var == "indent-mode" )
4171  {
4172  m_config->setIndentationMode( val );
4173  }
4174  else if ( var == "word-wrap-column" && checkIntValue( val, &n ) && n > 0 ) // uint, but hard word wrap at 0 will be no fun ;)
4175  m_config->setWordWrapAt( n );
4176 
4177  // STRING SETTINGS
4178  else if ( var == "eol" || var == "end-of-line" )
4179  {
4180  QStringList l;
4181  l << "unix" << "dos" << "mac";
4182  if ( (n = l.indexOf( val.toLower() )) != -1 )
4183  m_config->setEol( n );
4184  }
4185  else if (var == "bom" || var =="byte-order-marker")
4186  {
4187  if (checkBoolValue(val,&state)) {
4188  m_config->setBom(state);
4189  }
4190  }
4191  else if ( var == "remove-trailing-spaces" ) {
4192  val = val.toLower();
4193  if (val == "1" || val == "modified" || val == "mod" || val == "+") {
4194  m_config->setRemoveSpaces(1);
4195  } else if (val == "2" || val == "all" || val == "*") {
4196  m_config->setRemoveSpaces(2);
4197  } else {
4198  m_config->setRemoveSpaces(0);
4199  }
4200 
4201  m_config->setRemoveSpaces( state ? 1 : 0 );
4202  }
4203  else if ( var == "syntax" || var == "hl" )
4204  {
4205  setHighlightingMode( val );
4206  }
4207  else if ( var == "mode" )
4208  {
4209  setMode( val );
4210  }
4211  else if ( var == "encoding" )
4212  {
4213  setEncoding( val );
4214  }
4215  else if ( var == "default-dictionary" )
4216  {
4217  setDefaultDictionary( val );
4218  }
4219  else if ( var == "automatic-spell-checking" && checkBoolValue( val, &state ) )
4220  {
4221  onTheFlySpellCheckingEnabled( state );
4222  }
4223 
4224  // VIEW SETTINGS
4225  else if ( vvl.contains( var ) )
4226  setViewVariable( var, val );
4227  else
4228  {
4229  m_storedVariables.insert( var, val );
4230  emit variableChanged( this, var, val );
4231  }
4232  }
4233  }
4234 
4235  // Backward compatibility
4236  // If space-indent was set, but replace-tabs was not set, we assume
4237  // that the user wants to replace tabulators and set that flag.
4238  // If both were set, replace-tabs has precedence.
4239  // At this point spaceIndent is -1 if it was never set,
4240  // 0 if it was set to off, and 1 if it was set to on.
4241  // Note that if onlyViewAndRenderer was requested, spaceIndent is -1.
4242  if ( !replaceTabsSet && spaceIndent >= 0 )
4243  {
4244  m_config->setReplaceTabsDyn( spaceIndent > 0 );
4245  }
4246 }
4247 
4248 void KateDocument::setViewVariable( QString var, QString val )
4249 {
4250  KateView *v;
4251  bool state;
4252  int n;
4253  QColor c;
4254  foreach (v,m_views)
4255  {
4256  if ( var == "dynamic-word-wrap" && checkBoolValue( val, &state ) )
4257  v->config()->setDynWordWrap( state );
4258  else if ( var == "persistent-selection" && checkBoolValue( val, &state ) )
4259  v->config()->setPersistentSelection( state );
4260  else if ( var == "block-selection" && checkBoolValue( val, &state ) )
4261  v->setBlockSelection( state );
4262  //else if ( var = "dynamic-word-wrap-indicators" )
4263  else if ( var == "line-numbers" && checkBoolValue( val, &state ) )
4264  v->config()->setLineNumbers( state );
4265  else if (var == "icon-border" && checkBoolValue( val, &state ) )
4266  v->config()->setIconBar( state );
4267  else if (var == "folding-markers" && checkBoolValue( val, &state ) )
4268  v->config()->setFoldingBar( state );
4269  else if ( var == "auto-center-lines" && checkIntValue( val, &n ) )
4270  v->config()->setAutoCenterLines( n );
4271  else if ( var == "icon-bar-color" && checkColorValue( val, c ) )
4272  v->renderer()->config()->setIconBarColor( c );
4273  // RENDERER
4274  else if ( var == "background-color" && checkColorValue( val, c ) )
4275  v->renderer()->config()->setBackgroundColor( c );
4276  else if ( var == "selection-color" && checkColorValue( val, c ) )
4277  v->renderer()->config()->setSelectionColor( c );
4278  else if ( var == "current-line-color" && checkColorValue( val, c ) )
4279  v->renderer()->config()->setHighlightedLineColor( c );
4280  else if ( var == "bracket-highlight-color" && checkColorValue( val, c ) )
4281  v->renderer()->config()->setHighlightedBracketColor( c );
4282  else if ( var == "word-wrap-marker-color" && checkColorValue( val, c ) )
4283  v->renderer()->config()->setWordWrapMarkerColor( c );
4284  else if ( var == "font" || ( var == "font-size" && checkIntValue( val, &n ) ) )
4285  {
4286  QFont _f( v->renderer()->config()->font() );
4287 
4288  if ( var == "font" )
4289  {
4290  _f.setFamily( val );
4291  _f.setFixedPitch( QFont( val ).fixedPitch() );
4292  }
4293  else
4294  _f.setPointSize( n );
4295 
4296  v->renderer()->config()->setFont( _f );
4297  }
4298  else if ( var == "scheme" )
4299  {
4300  v->renderer()->config()->setSchema( val );
4301  }
4302  }
4303 }
4304 
4305 bool KateDocument::checkBoolValue( QString val, bool *result )
4306 {
4307  val = val.trimmed().toLower();
4308  QStringList l;
4309  l << "1" << "on" << "true";
4310  if ( l.contains( val ) )
4311  {
4312  *result = true;
4313  return true;
4314  }
4315  l.clear();
4316  l << "0" << "off" << "false";
4317  if ( l.contains( val ) )
4318  {
4319  *result = false;
4320  return true;
4321  }
4322  return false;
4323 }
4324 
4325 bool KateDocument::checkIntValue( QString val, int *result )
4326 {
4327  bool ret( false );
4328  *result = val.toInt( &ret );
4329  return ret;
4330 }
4331 
4332 bool KateDocument::checkColorValue( QString val, QColor &c )
4333 {
4334  c.setNamedColor( val );
4335  return c.isValid();
4336 }
4337 
4338 // KTextEditor::variable
4339 QString KateDocument::variable( const QString &name ) const
4340 {
4341  return m_storedVariables.value(name, QString());
4342 }
4343 
4344 QString KateDocument::setVariable( const QString &name, const QString &value)
4345 {
4346  QString s = "kate: ";
4347  s.append(name);
4348  s.append(" ");
4349  s.append(value);
4350  readVariableLine(s);
4351  return m_storedVariables.value(name, QString());
4352 }
4353 
4354 //END
4355 
4356 void KateDocument::slotModOnHdDirty (const QString &path)
4357 {
4358  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskModified))
4359  {
4360  // compare md5 with the one we have (if we have one)
4361  if ( !digest().isEmpty() )
4362  {
4363  QByteArray oldDigest = digest();
4364  if ( createDigest () && oldDigest == digest() ) {
4365  return;
4366  }
4367  }
4368 
4369  m_modOnHd = true;
4370  m_modOnHdReason = OnDiskModified;
4371 
4372  // reenable dialog if not running atm
4373  if (m_isasking == -1)
4374  m_isasking = false;
4375 
4376  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4377  }
4378 }
4379 
4380 void KateDocument::slotModOnHdCreated (const QString &path)
4381 {
4382  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskCreated))
4383  {
4384  m_modOnHd = true;
4385  m_modOnHdReason = OnDiskCreated;
4386 
4387  // reenable dialog if not running atm
4388  if (m_isasking == -1)
4389  m_isasking = false;
4390 
4391  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4392  }
4393 }
4394 
4395 void KateDocument::slotModOnHdDeleted (const QString &path)
4396 {
4397  if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != OnDiskDeleted))
4398  {
4399  m_modOnHd = true;
4400  m_modOnHdReason = OnDiskDeleted;
4401 
4402  // reenable dialog if not running atm
4403  if (m_isasking == -1)
4404  m_isasking = false;
4405 
4406  emit modifiedOnDisk (this, m_modOnHd, m_modOnHdReason);
4407  }
4408 }
4409 
4410 const QByteArray &KateDocument::digest () const
4411 {
4412  return m_buffer->digest();
4413 }
4414 
4415 bool KateDocument::createDigest ()
4416 {
4417  QByteArray md5sum;
4418 
4419  if ( url().isLocalFile() )
4420  {
4421  QFile f ( url().toLocalFile() );
4422  if ( f.open( QIODevice::ReadOnly) )
4423  {
4424  QCryptographicHash crypto(QCryptographicHash::Md5);
4425  while(!f.atEnd())
4426  crypto.addData (f.read(256 * 1024));
4427  md5sum = crypto.result();
4428  }
4429  }
4430 
4431  m_buffer->setDigest( md5sum );
4432 
4433  return !md5sum.isEmpty();
4434 }
4435 
4436 QString KateDocument::reasonedMOHString() const
4437 {
4438  // squeeze path
4439  QString str = KStringHandler::csqueeze(url().pathOrUrl());
4440 
4441  switch( m_modOnHdReason )
4442  {
4443  case OnDiskModified:
4444  return i18n("The file '%1' was modified by another program.", str );
4445  break;
4446  case OnDiskCreated:
4447  return i18n("The file '%1' was created by another program.", str );
4448  break;
4449  case OnDiskDeleted:
4450  return i18n("The file '%1' was deleted by another program.", str );
4451  break;
4452  default:
4453  return QString();
4454  }
4455  return QString();
4456 }
4457 
4458 void KateDocument::removeTrailingSpaces()
4459 {
4460  const int remove = config()->removeSpaces();
4461  if (remove == 0)
4462  return;
4463 
4464  // temporarily disable static word wrap (see bug #328900)
4465  const bool wordWrapEnabled = config()->wordWrap ();
4466  if (wordWrapEnabled) setWordWrap(false);
4467 
4468  // get cursor position of active view
4469  KTextEditor::Cursor curPos = KTextEditor::Cursor::invalid();
4470  if (activeView()) {
4471  curPos = activeView()->cursorPosition();
4472  }
4473 
4474  editStart();
4475 
4476  for (int line = 0; line < lines(); ++line)
4477  {
4478  Kate::TextLine textline = plainKateTextLine(line);
4479 
4480  // remove trailing spaces in entire document, remove = 2
4481  // remove trailing spaces of touched lines, remove = 1
4482  // remove trailing spaces of lines saved on disk, remove = 1
4483  if (remove == 2 || textline->markedAsModified() || textline->markedAsSavedOnDisk()) {
4484  const int p = textline->lastChar() + 1;
4485  const int l = textline->length() - p;
4486  if (l > 0 ) {
4487  // if the cursor is in the trailing space, only delete behind cursor
4488  if (curPos.line() != line || curPos.column() <= p || curPos.column() > p + l) {
4489  editRemoveText(line, p, l);
4490  } else {
4491  editRemoveText(line, curPos.column(), l - (curPos.column() - p));
4492  }
4493  }
4494  }
4495  }
4496 
4497  editEnd();
4498 
4499  // enable word wrap again, if it was enabled (see bug #328900)
4500  if (wordWrapEnabled) setWordWrap(true); // see begin of this function
4501 }
4502 
4503 
4504 void KateDocument::updateFileType (const QString &newType, bool user)
4505 {
4506  if (user || !m_fileTypeSetByUser)
4507  {
4508  if (!newType.isEmpty())
4509  {
4510  // remember that we got set by user
4511  m_fileTypeSetByUser = user;
4512 
4513  m_fileType = newType;
4514 
4515  m_config->configStart();
4516 
4517  if (!m_hlSetByUser && !KateGlobal::self()->modeManager()->fileType(newType).hl.isEmpty())
4518  {
4519  int hl (KateHlManager::self()->nameFind (KateGlobal::self()->modeManager()->fileType(newType).hl));
4520 
4521  if (hl >= 0)
4522  m_buffer->setHighlight(hl);
4523  }
4524 
4529  if (!m_indenterSetByUser && !KateGlobal::self()->modeManager()->fileType(newType).indenter.isEmpty())
4530  config()->setIndentationMode (KateGlobal::self()->modeManager()->fileType(newType).indenter);
4531 
4532  // views!
4533  KateView *v;
4534  foreach (v,m_views)
4535  {
4536  v->config()->configStart();
4537  v->renderer()->config()->configStart();
4538  }
4539 
4540  bool bom_settings = false;
4541  if (m_bomSetByUser)
4542  bom_settings=m_config->bom();
4543  readVariableLine( KateGlobal::self()->modeManager()->fileType(newType).varLine );
4544  if (m_bomSetByUser)
4545  m_config->setBom(bom_settings);
4546  m_config->configEnd();
4547  foreach (v,m_views)
4548  {
4549  v->config()->configEnd();
4550  v->renderer()->config()->configEnd();
4551  }
4552  }
4553  }
4554 
4555  // fixme, make this better...
4556  emit modeChanged (this);
4557 }
4558 
4559 void KateDocument::slotQueryClose_save(bool *handled, bool* abortClosing) {
4560  *handled=true;
4561  *abortClosing=true;
4562  if (this->url().isEmpty())
4563  {
4564  QWidget *parentWidget(dialogParent());
4565 
4566  KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveUrlAndEncoding(config()->encoding(),
4567  QString(),QString(),parentWidget,i18n("Save File"));
4568 
4569  if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first(), parentWidget ) ) {
4570  *abortClosing=true;
4571  return;
4572  }
4573  setEncoding( res.encoding );
4574  saveAs( res.URLs.first() );
4575  *abortClosing=false;
4576  }
4577  else
4578  {
4579  save();
4580  *abortClosing=false;
4581  }
4582 
4583 }
4584 
4585 bool KateDocument::checkOverwrite( KUrl u, QWidget *parent )
4586 {
4587  if( !u.isLocalFile() )
4588  return true;
4589 
4590  QFileInfo info( u.path() );
4591  if( !info.exists() )
4592  return true;
4593 
4594  return KMessageBox::Cancel != KMessageBox::warningContinueCancel( parent,
4595  i18n( "A file named \"%1\" already exists. "
4596  "Are you sure you want to overwrite it?" , info.fileName() ),
4597  i18n( "Overwrite File?" ), KStandardGuiItem::overwrite(),
4598  KStandardGuiItem::cancel(), QString(), KMessageBox::Notify | KMessageBox::Dangerous );
4599 }
4600 
4601 //BEGIN KTextEditor::ConfigInterface
4602 
4603 // BEGIN ConfigInterface stff
4604 QStringList KateDocument::configKeys() const
4605 {
4606  return QStringList() << "tab-width" << "indent-width";
4607 }
4608 
4609 QVariant KateDocument::configValue(const QString &key)
4610 {
4611  if (key == "backup-on-save-local") {
4612  return m_config->backupFlags() & KateDocumentConfig::LocalFiles;
4613  } else if (key == "backup-on-save-remote") {
4614  return m_config->backupFlags() & KateDocumentConfig::RemoteFiles;
4615  } else if (key == "backup-on-save-suffix") {
4616  return m_config->backupSuffix();
4617  } else if (key == "backup-on-save-prefix") {
4618  return m_config->backupPrefix();
4619  } else if (key == "replace-tabs") {
4620  return m_config->replaceTabsDyn();
4621  } else if (key == "indent-pasted-text") {
4622  return m_config->indentPastedText();
4623  } else if (key == "tab-width") {
4624  return m_config->tabWidth();
4625  } else if (key == "indent-width") {
4626  return m_config->indentationWidth();
4627  }
4628 
4629  // return invalid variant
4630  return QVariant();
4631 }
4632 
4633 void KateDocument::setConfigValue(const QString &key, const QVariant &value)
4634 {
4635  if (value.type() == QVariant::String) {
4636  if (key == "backup-on-save-suffix") {
4637  m_config->setBackupSuffix(value.toString());
4638  } else if (key == "backup-on-save-prefix") {
4639  m_config->setBackupPrefix(value.toString());
4640  }
4641  } else if (value.canConvert(QVariant::Bool)) {
4642  const bool bValue = value.toBool();
4643  if (key == "backup-on-save-local" && value.type() == QVariant::String) {
4644  uint f = m_config->backupFlags();
4645  if (bValue) {
4646  f |= KateDocumentConfig::LocalFiles;
4647  } else {
4648  f ^= KateDocumentConfig::LocalFiles;
4649  }
4650 
4651  m_config->setBackupFlags(f);
4652  } else if (key == "backup-on-save-remote") {
4653  uint f = m_config->backupFlags();
4654  if (bValue) {
4655  f |= KateDocumentConfig::RemoteFiles;
4656  } else {
4657  f ^= KateDocumentConfig::RemoteFiles;
4658  }
4659 
4660  m_config->setBackupFlags(f);
4661  } else if (key == "replace-tabs") {
4662  m_config->setReplaceTabsDyn(bValue);
4663  } else if (key == "indent-pasted-text") {
4664  m_config->setIndentPastedText(bValue);
4665  }
4666  } else if (value.canConvert(QVariant::Int)) {
4667  if (key == "tab-width") {
4668  config()->setTabWidth(value.toInt());
4669  } else if (key == "indent-width") {
4670  config()->setIndentationWidth(value.toInt());
4671  }
4672  }
4673 }
4674 
4675 //END KTextEditor::ConfigInterface
4676 
4677 KateView * KateDocument::activeKateView( ) const
4678 {
4679  return static_cast<KateView*>(m_activeView);
4680 }
4681 
4682 KTextEditor::Cursor KateDocument::documentEnd( ) const
4683 {
4684  return KTextEditor::Cursor(lastLine(), lineLength(lastLine()));
4685 }
4686 
4687 bool KateDocument::replaceText( const KTextEditor::Range & range, const QString & s, bool block )
4688 {
4689  // TODO more efficient?
4690  editStart();
4691  bool changed = removeText(range, block);
4692  changed |= insertText(range.start(), s, block);
4693  editEnd();
4694  return changed;
4695 }
4696 
4697 void KateDocument::ignoreModifiedOnDiskOnce( )
4698 {
4699  m_isasking = -1;
4700 }
4701 
4702 KateHighlighting * KateDocument::highlight( ) const
4703 {
4704  return m_buffer->highlight();
4705 }
4706 
4707 Kate::TextLine KateDocument::kateTextLine( uint i )
4708 {
4709  m_buffer->ensureHighlighted (i);
4710  return m_buffer->plainLine (i);
4711 }
4712 
4713 Kate::TextLine KateDocument::plainKateTextLine( uint i )
4714 {
4715  return m_buffer->plainLine (i);
4716 }
4717 
4718 bool KateDocument::isEditRunning() const
4719 {
4720  return editIsRunning;
4721 }
4722 
4723 void KateDocument::setUndoMergeAllEdits(bool merge)
4724 {
4725  if (merge && m_undoMergeAllEdits)
4726  {
4727  // Don't add another undo safe point: it will override our current one,
4728  // meaning we'll need two undo's to get back there - which defeats the object!
4729  return;
4730  }
4731  m_undoManager->undoSafePoint();
4732  m_undoManager->setAllowComplexMerge(merge);
4733  m_undoMergeAllEdits = merge;
4734 }
4735 
4736 //BEGIN KTextEditor::MovingInterface
4737 KTextEditor::MovingCursor *KateDocument::newMovingCursor (const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior)
4738 {
4739  return new Kate::TextCursor(buffer(), position, insertBehavior);
4740 }
4741 
4742 KTextEditor::MovingRange *KateDocument::newMovingRange (const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior)
4743 {
4744  return new Kate::TextRange(buffer(), range, insertBehaviors, emptyBehavior);
4745 }
4746 
4747 qint64 KateDocument::revision () const
4748 {
4749  return m_buffer->history().revision ();
4750 }
4751 
4752 qint64 KateDocument::lastSavedRevision () const
4753 {
4754  return m_buffer->history().lastSavedRevision ();
4755 }
4756 
4757 void KateDocument::lockRevision (qint64 revision)
4758 {
4759  m_buffer->history().lockRevision (revision);
4760 }
4761 
4762 void KateDocument::unlockRevision (qint64 revision)
4763 {
4764  m_buffer->history().unlockRevision (revision);
4765 }
4766 
4767 void KateDocument::transformCursor(int& line, int& column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision)
4768 {
4769  m_buffer->history().transformCursor (line, column, insertBehavior, fromRevision, toRevision);
4770 }
4771 
4772 void KateDocument::transformCursor (KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision)
4773 {
4774  int line = cursor.line(), column = cursor.column();
4775  m_buffer->history().transformCursor (line, column, insertBehavior, fromRevision, toRevision);
4776  cursor.setLine(line);
4777  cursor.setColumn(column);
4778 }
4779 
4780 void KateDocument::transformRange (KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision)
4781 {
4782  m_buffer->history().transformRange (range, insertBehaviors, emptyBehavior, fromRevision, toRevision);
4783 }
4784 
4785 //END
4786 
4787 bool KateDocument::simpleMode ()
4788 {
4789  return KateGlobal::self()->simpleMode () && KateGlobal::self()->documentConfig()->allowSimpleMode ();
4790 }
4791 
4792 //BEGIN KTextEditor::AnnotationInterface
4793 void KateDocument::setAnnotationModel( KTextEditor::AnnotationModel* model )
4794 {
4795  KTextEditor::AnnotationModel* oldmodel = m_annotationModel;
4796  m_annotationModel = model;
4797  emit annotationModelChanged(oldmodel, m_annotationModel);
4798 }
4799 
4800 KTextEditor::AnnotationModel* KateDocument::annotationModel() const
4801 {
4802  return m_annotationModel;
4803 }
4804 //END KTextEditor::AnnotationInterface
4805 
4806 //TAKEN FROM kparts.h
4807 bool KateDocument::queryClose()
4808 {
4809  if ( !isReadWrite() || !isModified() )
4810  return true;
4811 
4812  QString docName = documentName();
4813 
4814  int res = KMessageBox::warningYesNoCancel( dialogParent(),
4815  i18n( "The document \"%1\" has been modified.\n"
4816  "Do you want to save your changes or discard them?" , docName ),
4817  i18n( "Close Document" ), KStandardGuiItem::save(), KStandardGuiItem::discard() );
4818 
4819  bool abortClose=false;
4820  bool handled=false;
4821 
4822  switch(res) {
4823  case KMessageBox::Yes :
4824  sigQueryClose(&handled,&abortClose);
4825  if (!handled)
4826  {
4827  if (url().isEmpty())
4828  {
4829  KUrl url = KFileDialog::getSaveUrl(KUrl(), QString(), dialogParent());
4830  if (url.isEmpty())
4831  return false;
4832 
4833  saveAs( url );
4834  }
4835  else
4836  {
4837  save();
4838  }
4839  } else if (abortClose) return false;
4840  return waitSaveComplete();
4841  case KMessageBox::No :
4842  return true;
4843  default : // case KMessageBox::Cancel :
4844  return false;
4845  }
4846 }
4847 
4848 void KateDocument::slotStarted (KIO::Job *job)
4849 {
4853  if (m_documentState == DocumentIdle)
4854  m_documentState = DocumentLoading;
4855 
4863  if (m_documentState == DocumentLoading) {
4867  m_readWriteStateBeforeLoading = isReadWrite ();
4868 
4872  if (job) {
4876  setReadWrite (false);
4877 
4882  m_loadingJob = job;
4883  QTimer::singleShot (1000, this, SLOT(slotTriggerLoadingMessage()));
4884  }
4885  }
4886 }
4887 
4888 void KateDocument::slotCompleted() {
4893  if (m_documentState == DocumentLoading) {
4894  setReadWrite (m_readWriteStateBeforeLoading);
4895  delete m_loadingMessage;
4896  }
4897 
4901  if (m_documentState == DocumentSaving || m_documentState == DocumentSavingAs)
4902  emit documentSavedOrUploaded (this, m_documentState == DocumentSavingAs);
4903 
4907  m_documentState = DocumentIdle;
4908  m_reloading = false;
4909 }
4910 
4911 void KateDocument::slotCanceled() {
4916  if (m_documentState == DocumentLoading) {
4917  setReadWrite (m_readWriteStateBeforeLoading);
4918  delete m_loadingMessage;
4919 
4920  showAndSetOpeningErrorAccess();
4921 
4922  updateDocName();
4923  }
4924 
4928  m_documentState = DocumentIdle;
4929  m_reloading = false;
4930 
4931 
4932 }
4933 
4934 void KateDocument::slotTriggerLoadingMessage ()
4935 {
4940  if (m_documentState != DocumentLoading)
4941  return;
4942 
4946  delete m_loadingMessage;
4947  m_loadingMessage = new KTextEditor::Message(i18n ("The file <a href=\"%1\">%2</a> is still loading.", url().pathOrUrl(), url().fileName()));
4948  m_loadingMessage->setPosition(KTextEditor::Message::TopInView);
4949 
4953  if (m_loadingJob) {
4954  QAction *cancel = new QAction ( i18n ("&Abort Loading"), 0);
4955  connect (cancel, SIGNAL(triggered()), this, SLOT(slotAbortLoading()));
4956  m_loadingMessage->addAction (cancel);
4957  }
4958 
4962  postMessage(m_loadingMessage);
4963 }
4964 
4965 void KateDocument::slotAbortLoading ()
4966 {
4970  if (!m_loadingJob)
4971  return;
4972 
4977  m_loadingJob->kill (KJob::EmitResult);
4978  m_loadingJob = 0;
4979 }
4980 
4981 bool KateDocument::save()
4982 {
4987  if ((m_documentState != DocumentIdle) && (m_documentState != DocumentPreSavingAs))
4988  return false;
4989 
4993  if (m_documentState == DocumentIdle)
4994  m_documentState = DocumentSaving;
4995  else
4996  m_documentState = DocumentSavingAs;
4997 
5001  return KTextEditor::Document::save();
5002 }
5003 
5004 bool KateDocument::saveAs( const KUrl &url )
5005 {
5012  if (!url.isValid())
5013  return false;
5014 
5018  if (m_documentState != DocumentIdle)
5019  return false;
5020 
5024  m_documentState = DocumentPreSavingAs;
5025 
5029  return KTextEditor::Document::saveAs(url);
5030 }
5031 
5032 QString KateDocument::defaultDictionary() const
5033 {
5034  return m_defaultDictionary;
5035 }
5036 
5037 QList<QPair<KTextEditor::MovingRange*, QString> > KateDocument::dictionaryRanges() const
5038 {
5039  return m_dictionaryRanges;
5040 }
5041 
5042 void KateDocument::clearDictionaryRanges()
5043 {
5044  for(QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5045  i != m_dictionaryRanges.end();++i)
5046  {
5047  delete (*i).first;
5048  }
5049  m_dictionaryRanges.clear();
5050  if(m_onTheFlyChecker)
5051  {
5052  m_onTheFlyChecker->refreshSpellCheck();
5053  }
5054  emit dictionaryRangesPresent(false);
5055 }
5056 
5057 void KateDocument::setDictionary(const QString& newDictionary, const KTextEditor::Range &range)
5058 {
5059  KTextEditor::Range newDictionaryRange = range;
5060  if(!newDictionaryRange.isValid() || newDictionaryRange.isEmpty())
5061  {
5062  return;
5063  }
5064  QList<QPair<KTextEditor::MovingRange*, QString> > newRanges;
5065  // all ranges is 'm_dictionaryRanges' are assumed to be mutually disjoint
5066  for(QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5067  i != m_dictionaryRanges.end();)
5068  {
5069  kDebug(13000) << "new iteration" << newDictionaryRange;
5070  if(newDictionaryRange.isEmpty())
5071  {
5072  break;
5073  }
5074  QPair<KTextEditor::MovingRange*, QString> pair = *i;
5075  QString dictionarySet = pair.second;
5076  KTextEditor::MovingRange *dictionaryRange = pair.first;
5077  kDebug(13000) << *dictionaryRange << dictionarySet;
5078  if(dictionaryRange->contains(newDictionaryRange) && newDictionary == dictionarySet)
5079  {
5080  kDebug(13000) << "dictionaryRange contains newDictionaryRange";
5081  return;
5082  }
5083  if(newDictionaryRange.contains(*dictionaryRange))
5084  {
5085  delete dictionaryRange;
5086  i = m_dictionaryRanges.erase(i);
5087  kDebug(13000) << "newDictionaryRange contains dictionaryRange";
5088  continue;
5089  }
5090 
5091  KTextEditor::Range intersection = dictionaryRange->toRange().intersect(newDictionaryRange);
5092  if(!intersection.isEmpty() && intersection.isValid())
5093  {
5094  if(dictionarySet == newDictionary) // we don't have to do anything for 'intersection'
5095  { // except cut off the intersection
5096  QList<KTextEditor::Range> remainingRanges = KateSpellCheckManager::rangeDifference(newDictionaryRange, intersection);
5097  Q_ASSERT(remainingRanges.size() == 1);
5098  newDictionaryRange = remainingRanges.first();
5099  ++i;
5100  kDebug(13000) << "dictionarySet == newDictionary";
5101  continue;
5102  }
5103  QList<KTextEditor::Range> remainingRanges = KateSpellCheckManager::rangeDifference(*dictionaryRange, intersection);
5104  for(QList<KTextEditor::Range>::iterator j = remainingRanges.begin(); j != remainingRanges.end(); ++j)
5105  {
5106  KTextEditor::MovingRange *remainingRange = newMovingRange(*j,
5107  KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight);
5108  remainingRange->setFeedback(this);
5109  newRanges.push_back(QPair<KTextEditor::MovingRange*, QString>(remainingRange, dictionarySet));
5110  }
5111  i = m_dictionaryRanges.erase(i);
5112  delete dictionaryRange;
5113  } else {
5114  ++i;
5115  }
5116  }
5117  m_dictionaryRanges += newRanges;
5118  if(!newDictionaryRange.isEmpty() && !newDictionary.isEmpty()) // we don't add anything for the default dictionary
5119  {
5120  KTextEditor::MovingRange *newDictionaryMovingRange = newMovingRange(newDictionaryRange,
5121  KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight);
5122  newDictionaryMovingRange->setFeedback(this);
5123  m_dictionaryRanges.push_back(QPair<KTextEditor::MovingRange*, QString>(newDictionaryMovingRange, newDictionary));
5124  }
5125  if(m_onTheFlyChecker && !newDictionaryRange.isEmpty())
5126  {
5127  m_onTheFlyChecker->refreshSpellCheck(newDictionaryRange);
5128  }
5129  emit dictionaryRangesPresent(!m_dictionaryRanges.isEmpty());
5130 }
5131 
5132 void KateDocument::revertToDefaultDictionary(const KTextEditor::Range &range)
5133 {
5134  setDictionary(QString(), range);
5135 }
5136 
5137 void KateDocument::setDefaultDictionary(const QString& dict)
5138 {
5139  if(m_defaultDictionary == dict)
5140  {
5141  return;
5142  }
5143  m_defaultDictionary = dict;
5144  if(m_onTheFlyChecker)
5145  {
5146  m_onTheFlyChecker->updateConfig();
5147  }
5148  refreshOnTheFlyCheck();
5149  emit defaultDictionaryChanged(this);
5150 }
5151 
5152 void KateDocument::onTheFlySpellCheckingEnabled(bool enable)
5153 {
5154  if (isOnTheFlySpellCheckingEnabled() == enable)
5155  {
5156  return;
5157  }
5158  if (enable)
5159  {
5160  if (!m_onTheFlyChecker) {
5161  m_onTheFlyChecker = new KateOnTheFlyChecker(this);
5162  }
5163  } else {
5164  delete m_onTheFlyChecker;
5165  m_onTheFlyChecker = 0;
5166  }
5167  foreach(KateView *view, m_views) {
5168  view->reflectOnTheFlySpellCheckStatus(enable);
5169  }
5170 }
5171 
5172 bool KateDocument::isOnTheFlySpellCheckingEnabled() const
5173 {
5174  return m_onTheFlyChecker != 0;
5175 }
5176 
5177 QString KateDocument::dictionaryForMisspelledRange(const KTextEditor::Range& range) const
5178 {
5179  if (!m_onTheFlyChecker)
5180  {
5181  return QString();
5182  } else {
5183  return m_onTheFlyChecker->dictionaryForMisspelledRange(range);
5184  }
5185 }
5186 
5187 void KateDocument::clearMisspellingForWord(const QString& word)
5188 {
5189  if(m_onTheFlyChecker) {
5190  m_onTheFlyChecker->clearMisspellingForWord(word);
5191  }
5192 }
5193 
5194 void KateDocument::refreshOnTheFlyCheck(const KTextEditor::Range &range)
5195 {
5196  if(m_onTheFlyChecker) {
5197  m_onTheFlyChecker->refreshSpellCheck(range);
5198  }
5199 }
5200 
5201 void KateDocument::rangeInvalid(KTextEditor::MovingRange *movingRange)
5202 {
5203  deleteDictionaryRange(movingRange);
5204 }
5205 
5206 void KateDocument::rangeEmpty(KTextEditor::MovingRange *movingRange)
5207 {
5208  deleteDictionaryRange(movingRange);
5209 }
5210 
5211 void KateDocument::deleteDictionaryRange(KTextEditor::MovingRange *movingRange)
5212 {
5213  kDebug(13020) << "deleting" << movingRange;
5214  for(QList<QPair<KTextEditor::MovingRange*, QString> >::iterator i = m_dictionaryRanges.begin();
5215  i != m_dictionaryRanges.end();)
5216  {
5217  KTextEditor::MovingRange *dictionaryRange = (*i).first;
5218  if(dictionaryRange == movingRange)
5219  {
5220  delete movingRange;
5221  i = m_dictionaryRanges.erase(i);
5222  } else {
5223  ++i;
5224  }
5225  }
5226 }
5227 
5228 bool KateDocument::containsCharacterEncoding(const KTextEditor::Range& range)
5229 {
5230  KateHighlighting *highlighting = highlight();
5231  Kate::TextLine textLine;
5232 
5233  const int rangeStartLine = range.start().line();
5234  const int rangeStartColumn = range.start().column();
5235  const int rangeEndLine = range.end().line();
5236  const int rangeEndColumn = range.end().column();
5237 
5238  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5239  textLine = kateTextLine(line);
5240  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5241  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5242  for(int col = startColumn; col < endColumn; ++col) {
5243  int attr = textLine->attribute(col);
5244  const KatePrefixStore& prefixStore = highlighting->getCharacterEncodingsPrefixStore(attr);
5245  if(!prefixStore.findPrefix(textLine, col).isEmpty()) {
5246  return true;
5247  }
5248  }
5249  }
5250 
5251  return false;
5252 }
5253 
5254 int KateDocument::computePositionWrtOffsets(const OffsetList& offsetList, int pos)
5255 {
5256  int previousOffset = 0;
5257  for(OffsetList::const_iterator i = offsetList.begin(); i != offsetList.end(); ++i) {
5258  if((*i).first > pos) {
5259  break;
5260  }
5261  previousOffset = (*i).second;
5262  }
5263  return pos + previousOffset;
5264 }
5265 
5266 QString KateDocument::decodeCharacters(const KTextEditor::Range& range, KateDocument::OffsetList& decToEncOffsetList,
5267  KateDocument::OffsetList& encToDecOffsetList)
5268 {
5269  QString toReturn;
5270  KTextEditor::Cursor previous = range.start();
5271  int decToEncCurrentOffset = 0, encToDecCurrentOffset = 0;
5272  int i = 0;
5273  int newI = 0;
5274 
5275  KateHighlighting *highlighting = highlight();
5276  Kate::TextLine textLine;
5277 
5278  const int rangeStartLine = range.start().line();
5279  const int rangeStartColumn = range.start().column();
5280  const int rangeEndLine = range.end().line();
5281  const int rangeEndColumn = range.end().column();
5282 
5283  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5284  textLine = kateTextLine(line);
5285  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5286  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5287  for(int col = startColumn; col < endColumn;) {
5288  int attr = textLine->attribute(col);
5289  const KatePrefixStore& prefixStore = highlighting->getCharacterEncodingsPrefixStore(attr);
5290  const QHash<QString, QChar>& characterEncodingsHash = highlighting->getCharacterEncodings(attr);
5291  QString matchingPrefix = prefixStore.findPrefix(textLine, col);
5292  if(!matchingPrefix.isEmpty()) {
5293  toReturn += text(KTextEditor::Range(previous, KTextEditor::Cursor(line, col)));
5294  const QChar& c = characterEncodingsHash.value(matchingPrefix);
5295  const bool isNullChar = c.isNull();
5296  if(!c.isNull()) {
5297  toReturn += c;
5298  }
5299  i += matchingPrefix.length();
5300  col += matchingPrefix.length();
5301  previous = KTextEditor::Cursor(line, col);
5302  decToEncCurrentOffset = decToEncCurrentOffset - (isNullChar ? 0 : 1) + matchingPrefix.length();
5303  encToDecCurrentOffset = encToDecCurrentOffset - matchingPrefix.length() + (isNullChar ? 0 : 1);
5304  newI += (isNullChar ? 0 : 1);
5305  decToEncOffsetList.push_back(QPair<int, int>(newI, decToEncCurrentOffset));
5306  encToDecOffsetList.push_back(QPair<int, int>(i, encToDecCurrentOffset));
5307  continue;
5308  }
5309  ++col;
5310  ++i;
5311  ++newI;
5312  }
5313  ++i;
5314  ++newI;
5315  }
5316  if(previous < range.end()) {
5317  toReturn += text(KTextEditor::Range(previous, range.end()));
5318  }
5319  return toReturn;
5320 }
5321 
5322 void KateDocument::replaceCharactersByEncoding(const KTextEditor::Range& range)
5323 {
5324  KateHighlighting *highlighting = highlight();
5325  Kate::TextLine textLine;
5326 
5327  const int rangeStartLine = range.start().line();
5328  const int rangeStartColumn = range.start().column();
5329  const int rangeEndLine = range.end().line();
5330  const int rangeEndColumn = range.end().column();
5331 
5332  for(int line = range.start().line(); line <= rangeEndLine; ++line) {
5333  textLine = kateTextLine(line);
5334  int startColumn = (line == rangeStartLine) ? rangeStartColumn : 0;
5335  int endColumn = (line == rangeEndLine) ? rangeEndColumn : textLine->length();
5336  for(int col = startColumn; col < endColumn;) {
5337  int attr = textLine->attribute(col);
5338  const QHash<QChar, QString>& reverseCharacterEncodingsHash = highlighting->getReverseCharacterEncodings(attr);
5339  QHash<QChar, QString>::const_iterator it = reverseCharacterEncodingsHash.find(textLine->at(col));
5340  if(it != reverseCharacterEncodingsHash.end()) {
5341  replaceText(KTextEditor::Range(line, col, line, col + 1), *it);
5342  col += (*it).length();
5343  continue;
5344  }
5345  ++col;
5346  }
5347  }
5348 }
5349 
5350 //
5351 // KTextEditor::HighlightInterface
5352 //
5353 
5354 KTextEditor::Attribute::Ptr KateDocument::defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
5355 {
5357  KateView* view = activeKateView();
5358  if ( !view ) {
5359  kWarning() << "ATTENTION: cannot access defaultStyle() without any View (will be fixed eventually)";
5360  return KTextEditor::Attribute::Ptr(0);
5361  }
5362 
5363  KTextEditor::Attribute::Ptr style = highlight()->attributes(view->renderer()->config()->schema()).at(ds);
5364  if (!style->hasProperty(QTextFormat::BackgroundBrush)) {
5365  // make sure the returned style has the default background color set
5366  style.attach(new KTextEditor::Attribute(*style));
5367  style->setBackground( QBrush(view->renderer()->config()->backgroundColor()) );
5368  }
5369  return style;
5370 }
5371 
5372 QList< KTextEditor::HighlightInterface::AttributeBlock > KateDocument::lineAttributes(const unsigned int line)
5373 {
5375 
5376  QList< KTextEditor::HighlightInterface::AttributeBlock > attribs;
5377 
5378  KateView* view = activeKateView();
5379  if ( !view ) {
5380  kWarning() << "ATTENTION: cannot access lineAttributes() without any View (will be fixed eventually)";
5381  return attribs;
5382  }
5383 
5384  Kate::TextLine kateLine = kateTextLine(line);
5385  if ( !kateLine )
5386  return attribs;
5387 
5388  const QVector<Kate::TextLineData::Attribute> &intAttrs = kateLine->attributesList();
5389  for ( int i = 0; i < intAttrs.size(); ++i ) {
5390  if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0)
5391  attribs << KTextEditor::HighlightInterface::AttributeBlock(
5392  intAttrs.at(i).offset,
5393  intAttrs.at(i).length,
5394  view->renderer()->attribute(intAttrs.at(i).attributeValue)
5395  );
5396  }
5397 
5398  return attribs;
5399 }
5400 
5401 QStringList KateDocument::embeddedHighlightingModes() const
5402 {
5403  return highlight()->getEmbeddedHighlightingModes();
5404 }
5405 
5406 QString KateDocument::highlightingModeAt(const KTextEditor::Cursor& position)
5407 {
5408  Kate::TextLine kateLine = kateTextLine(position.line());
5409 
5410 // const QVector< short >& attrs = kateLine->ctxArray();
5411 // kDebug() << "----------------------------------------------------------------------";
5412 // foreach( short a, attrs ) {
5413 // kDebug() << a;
5414 // }
5415 // kDebug() << "----------------------------------------------------------------------";
5416 // kDebug() << "col: " << position.column() << " lastchar:" << kateLine->lastChar() << " length:" << kateLine->length() << "global mode:" << highlightingMode();
5417 
5418  int len = kateLine->length();
5419  int pos = position.column();
5420  if ( pos >= len ) {
5421  const Kate::TextLineData::ContextStack &ctxs = kateLine->contextStack();
5422  int ctxcnt = ctxs.count();
5423  if ( ctxcnt == 0 ) {
5424  return highlightingMode();
5425  }
5426  int ctx = ctxs.at(ctxcnt-1);
5427  if ( ctx == 0 ) {
5428  return highlightingMode();
5429  }
5430  return KateHlManager::self()->nameForIdentifier(highlight()->hlKeyForContext(ctx));
5431  }
5432 
5433  int attr = kateLine->attribute(pos);
5434  if ( attr == 0 ) {
5435  return mode();
5436  }
5437 
5438  return KateHlManager::self()->nameForIdentifier(highlight()->hlKeyForAttrib(attr));
5439 
5440 }
5441 
5442 Kate::SwapFile* KateDocument::swapFile()
5443 {
5444  return m_swapfile;
5445 }
5446 
5451 int KateDocument::defStyleNum(int line, int column)
5452 {
5453  // Validate parameters to prevent out of range access
5454  if (line < 0 || line >= lines() || column < 0)
5455  return -1;
5456 
5457  // get highlighted line
5458  Kate::TextLine tl = kateTextLine(line);
5459 
5460  // make sure the textline is a valid pointer
5461  if (!tl)
5462  return -1;
5463 
5467  int attribute = 0;
5468  if (column < tl->length())
5469  attribute = tl->attribute (column);
5470  else if (column == tl->length()) {
5471  KateHlContext *context = tl->contextStack().isEmpty() ? highlight()->contextNum(0) : highlight()->contextNum (tl->contextStack().back());
5472  attribute = context->attr;
5473  } else
5474  return -1;
5475 
5476  QList<KTextEditor::Attribute::Ptr> attributes = highlight()->attributes(
5477  static_cast<KateView*>(activeView())
5478  ->renderer()
5479  ->config()
5480  ->schema()
5481  );
5482 
5483  // sanity check for the attribute
5484  if (attribute < 0 || attribute >= attributes.size())
5485  return -1;
5486 
5487  KTextEditor::Attribute::Ptr a = attributes[attribute];
5488  return a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
5489 }
5490 
5491 bool KateDocument::isComment(int line, int column)
5492 {
5493  const int defaultStyle = defStyleNum(line, column);
5494  return defaultStyle == KTextEditor::HighlightInterface::dsComment;
5495 }
5496 
5497 //BEGIN KTextEditor::MessageInterface
5498 bool KateDocument::postMessage(KTextEditor::Message* message)
5499 {
5500  // no message -> cancel
5501  if (!message)
5502  return false;
5503 
5504  // make sure the desired view belongs to this document
5505  if (message->view() && message->view()->document() != this) {
5506  kWarning(13020) << "trying to post a message to a view of another document:" << message->text();
5507  return false;
5508  }
5509 
5510  message->setParent(this);
5511  message->setDocument(this);
5512 
5513  // if there are no actions, add a close action by default if widget does not auto-hide
5514  if (message->actions().count() == 0 && message->autoHide() < 0) {
5515  QAction* closeAction = new QAction(KIcon("window-close"), i18n("&Close"), 0);
5516  closeAction->setToolTip(i18n("Close message"));
5517  message->addAction(closeAction);
5518  }
5519 
5520  // make sure the message is registered even if no actions and no views exist
5521  m_messageHash[message] = QList<QSharedPointer<QAction> >();
5522 
5523  // reparent actions, as we want full control over when they are deleted
5524  foreach (QAction *action, message->actions()) {
5525  action->setParent(0);
5526  m_messageHash[message].append(QSharedPointer<QAction>(action));
5527  }
5528 
5529  // post message to requested view, or to all views
5530  if (KateView *view = qobject_cast<KateView*>(message->view())) {
5531  view->postMessage(message, m_messageHash[message]);
5532  } else {
5533  foreach (KateView *view, m_views)
5534  view->postMessage(message, m_messageHash[message]);
5535  }
5536 
5537  // also catch if the user manually calls delete message
5538  connect(message, SIGNAL(closed(KTextEditor::Message*)), SLOT(messageDestroyed(KTextEditor::Message*)));
5539 
5540  return true;
5541 }
5542 
5543 void KateDocument::messageDestroyed(KTextEditor::Message* message)
5544 {
5545  // KTE:Message is already in destructor
5546  Q_ASSERT(m_messageHash.contains(message));
5547  m_messageHash.remove(message);
5548 }
5549 //END KTextEditor::MessageInterface
5550 
5551 // kate: space-indent on; indent-width 2; replace-tabs on;
KateDocument::documentName
virtual const QString & documentName() const
Definition: katedocument.h:828
QVariant
Kate::TextBuffer::line
TextLine line(int line) const
Retrieve a text line.
Definition: katetextbuffer.cpp:150
KateModOnHdPrompt::Ignore
Definition: katedialogs.h:403
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:4633
KStandardGuiItem::cancel
KGuiItem cancel()
KTextEditor::MovingRange::setFeedback
virtual void setFeedback(MovingRangeFeedback *feedback)=0
KateDocument::align
void align(KateView *view, const KTextEditor::Range &range)
Definition: katedocument.cpp:2908
KateDocument::buffer
KateBuffer & buffer()
Get access to buffer of this document.
Definition: katedocument.h:946
QColor
message
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
KParts::ReadOnlyPart::setLocalFilePath
void setLocalFilePath(const QString &localFilePath)
KateBrowserExtension
Interface for embedding KateDocument into a browser.
Definition: katedocumenthelpers.h:36
KTextEditor::Message::view
KTextEditor::View * view() const
KIO::NetAccess::stat
static bool stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window)
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
KateDocumentConfig::setKeepExtraSpaces
void setKeepExtraSpaces(bool on)
Definition: kateconfig.cpp:557
KatePrefixStore
This class can be used to efficiently search for occurrences of strings in a given string...
Definition: prefixstore.h:41
KTextEditor::Document::modifiedChanged
void modifiedChanged(KTextEditor::Document *document)
KateDocument::setText
virtual bool setText(const QString &)
Definition: katedocument.cpp:457
KTextEditor::Range::start
Cursor & start()
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:1863
KTextEditor::Mark::type
uint type
KateDocument::setWordWrap
void setWordWrap(bool on)
Definition: katedocument.cpp:3922
KIO::Overwrite
KTextEditor::Editor::simpleMode
bool simpleMode() const
KMessageBox::No
KSharedPtr< Attribute >
KateDocumentConfig::LocalFiles
Definition: kateconfig.h:279
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
KParts::ReadWritePart::saveAs
virtual bool saveAs(const KUrl &url)
KateOnTheFlyChecker::dictionaryForMisspelledRange
QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const
Definition: ontheflycheck.cpp:95
qint64
KateRendererConfig::setSchema
void setSchema(const QString &schema)
Definition: kateconfig.cpp:2002
KTextEditor::MarkInterface::markType01
KateDocument::mimeType
virtual QString mimeType()
Definition: katedocument.cpp:1860
katehighlight.h
katetextline.h
KTextEditor::Document::exclusiveEditEnd
void exclusiveEditEnd(KTextEditor::Document *document)
KateDocument::ignoreModifiedOnDiskOnce
void ignoreModifiedOnDiskOnce()
Definition: katedocument.cpp:4697
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:471
kateview.h
KateDocumentConfig::backupPrefix
const QString & backupPrefix() const
Definition: kateconfig.cpp:959
KTextEditor::Cursor::invalid
static Cursor invalid()
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
KateDocumentConfig::setIndentationMode
void setIndentationMode(const QString &identationMode)
Definition: kateconfig.cpp:459
KateDocument::updateFileType
void updateFileType(const QString &newType, bool user=false)
Definition: katedocument.cpp:4504
KateGlobal::modeManager
KateModeManager * modeManager()
global mode manager used to manage the modes centrally
Definition: kateglobal.h:291
netaccess.h
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:4737
KateDocument::computePositionWrtOffsets
int computePositionWrtOffsets(const OffsetList &offsetList, int pos)
Definition: katedocument.cpp:5254
KateDocument::printDialog
bool printDialog()
Definition: katedocument.cpp:1848
KTextEditor::Message::setDocument
void setDocument(KTextEditor::Document *document)
KMessageBox::Continue
KateView::clearSelection
bool clearSelection()
Definition: kateview.cpp:1966
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:3800
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:4742
dummy
static int dummy
Definition: katedocument.cpp:101
KateGlobal::kateDocuments
QList< KateDocument * > & kateDocuments()
return a list of all registered docs
Definition: kateglobal.h:266
KateRendererConfig::setHighlightedBracketColor
void setHighlightedBracketColor(const QColor &col)
Definition: kateconfig.cpp:2283
kdebug.h
KDirWatch::addFile
void addFile(const QString &file)
KateDocument::replaceCharactersByEncoding
void replaceCharactersByEncoding(const KTextEditor::Range &range)
Definition: katedocument.cpp:5322
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1653
KateDocument::repaintViews
void repaintViews(bool paintOnlyDirty=true)
Definition: katedocument.cpp:3559
KateDocument::clearDictionaryRanges
void clearDictionaryRanges()
Definition: katedocument.cpp:5042
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
KTextEditor::Document::reloaded
void reloaded(KTextEditor::Document *document)
KTextEditor::Attribute
KStandardGuiItem::discard
KGuiItem discard()
KateDocumentConfig::RemoteFiles
Definition: kateconfig.h:280
KateRendererConfig::lineMarkerColor
const QColor & lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type=KTextEditor::MarkInterface::markType01) const
Definition: kateconfig.cpp:2241
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
KParts::ReadWritePart::waitSaveComplete
bool waitSaveComplete()
KateDocument::clearMark
virtual void clearMark(int line)
Definition: katedocument.cpp:1661
KateDocument::setReadWrite
virtual void setReadWrite(bool rw=true)
Definition: katedocument.cpp:2468
KateDocument::removeLine
virtual bool removeLine(int line)
Definition: katedocument.cpp:727
KateDocumentConfig::ovr
bool ovr() const
Definition: kateconfig.cpp:759
KateBuffer::editTagFrom
bool editTagFrom() const
line inserted/removed?
Definition: katebuffer.h:89
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4702
KTextEditor::Range::isValid
virtual bool isValid() const
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:725
KIO::UDSEntry
Kate::TextHistory::lastSavedRevision
qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
Definition: katetexthistory.h:54
KateDocument::undoChanged
void undoChanged()
kateplaintextsearch.h
kglobalsettings.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
Kate::TextLineData::ContextStack
QVector< short > ContextStack
Context stack.
Definition: katetextline.h:47
KateDocument::dictionaryForMisspelledRange
QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const
Definition: katedocument.cpp:5177
KateDocumentConfig::setOvr
void setOvr(bool on)
Definition: kateconfig.cpp:746
KateBuffer::editChanged
bool editChanged() const
were there changes in the current running editing session?
Definition: katebuffer.h:71
kdirwatch.h
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:303
KateDocument::transpose
void transpose(const KTextEditor::Cursor &)
Definition: katedocument.cpp:2694
KateDocument::handleMarkClick
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
Definition: katedocument.cpp:1762
KTextEditor::MovingRange::EmptyBehavior
EmptyBehavior
KateDocument::clear
virtual bool clear()
Definition: katedocument.cpp:509
kfiledialog.h
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:3907
KateDocument::readWriteChanged
void readWriteChanged(KTextEditor::Document *document)
KateDocument::paste
void paste(KateView *view, const QString &text)
Definition: katedocument.cpp:2828
KateDocumentConfig::setBackupSuffix
void setBackupSuffix(const QString &suffix)
Definition: kateconfig.cpp:988
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:4787
KateDocumentConfig::indentPastedText
bool indentPastedText() const
Definition: kateconfig.cpp:591
KParts::ReadOnlyPart::completed
void completed()
KateViewConfig::setIconBar
void setIconBar(bool on)
Definition: kateconfig.cpp:1494
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
KateHighlighting::getCommentStart
QString getCommentStart(int attrib=0) const
Definition: katehighlight.cpp:1119
kconfig.h
KTextEditor::ModificationInterface::OnDiskUnmodified
KateDocumentConfig::setTabIndents
void setTabIndents(bool on)
Definition: kateconfig.cpp:767
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
KTextEditor::Document::documentNameChanged
void documentNameChanged(KTextEditor::Document *document)
KateConfig::configEnd
void configEnd()
end a config change transaction, update the concerned documents/views/renderers
Definition: kateconfig.cpp:63
KParts::ReadWritePart::save
virtual bool save()
QWidget
KateUndoManager::editEnd
void editEnd()
Notify KateUndoManager about the end of an edit.
Definition: kateundomanager.cpp:82
KateDocument::updateConfig
void updateConfig()
Definition: katedocument.cpp:3963
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:5152
ReplaceMode
Definition: kateviinputmodemanager.h:54
KateDocument::swapFile
Kate::SwapFile * swapFile()
Definition: katedocument.cpp:5442
KTextEditor::DocumentCursor
A Cursor which is bound to a specific Document.
Definition: documentcursor.h:69
KTextEditor::Document::highlightingModeChanged
void highlightingModeChanged(KTextEditor::Document *document)
KGlobal::dirs
KStandardDirs * dirs()
KateDocument::clearMisspellingForWord
void clearMisspellingForWord(const QString &word)
Definition: katedocument.cpp:5187
KTextEditor::MovingCursor
KateDocument::setWordWrapAt
void setWordWrapAt(uint col)
Definition: katedocument.cpp:3932
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:3805
KateDocument::tagLines
void tagLines(int start, int end)
Definition: katedocument.cpp:3553
KTextEditor::Document::setOpeningErrorMessage
void setOpeningErrorMessage(const QString &message)
KateView::repaintText
void repaintText(bool paintOnlyDirty=false)
Definition: kateview.cpp:1883
name
const char * name(StandardAction id)
KateDocument::addView
void addView(KTextEditor::View *)
Definition: katedocument.cpp:2523
plugin.h
kxmlguifactory.h
KIO::NetAccess::synchronousRun
static bool synchronousRun(Job *job, QWidget *window, QByteArray *data=0, KUrl *finalURL=0, QMap< QString, QString > *metaData=0)
KateDocument::highlightingModeAt
virtual QString highlightingModeAt(const KTextEditor::Cursor &position)
Definition: katedocument.cpp:5406
KateDocument::defaultStyle
virtual KTextEditor::Attribute::Ptr defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const
Definition: katedocument.cpp:5354
KateDocument::fileType
QString fileType() const
Definition: katedocument.h:939
KateDocument::annotationModel
virtual KTextEditor::AnnotationModel * annotationModel() const
Definition: katedocument.cpp:4800
KateDocument::embeddedHighlightingModes
virtual QStringList embeddedHighlightingModes() const
Definition: katedocument.cpp:5401
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:512
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
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KParts::Part::widget
virtual QWidget * widget()
KateExtendedAttribute::AttributeDefaultStyleIndex
Definition: kateextendedattribute.h:44
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
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
KTextEditor::MovingRange::toRange
const Range toRange() const
KateRegExpSearch
Object to help to search for regexp.
Definition: kateregexpsearch.h:40
KParts::ReadWritePart::setModified
void setModified()
KateUndoManager::inputMethodEnd
void inputMethodEnd()
Definition: kateundomanager.cpp:121
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
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:2143
KFileItem::permissions
mode_t permissions() const
KParts::ReadOnlyPart::setUrl
void setUrl(const KUrl &url)
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:462
KTextEditor::MovingRange
KateUndoManager
KateUndoManager implements a document's history.
Definition: kateundomanager.h:45
KateDocument::createView
virtual KTextEditor::View * createView(QWidget *parent)
Definition: katedocument.cpp:292
KTextEditor::ModificationInterface::OnDiskCreated
KateRendererConfig::setSelectionColor
void setSelectionColor(const QColor &col)
Definition: kateconfig.cpp:2207
QString
KateHighlighting::canBreakAt
bool canBreakAt(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1091
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
QHash
KateDocument::markChanged
void markChanged(KTextEditor::Document *, KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction)
KTextEditor::Mark::line
int line
KTextEditor::ParameterizedSessionConfigInterface::SkipHighlighting
KateDocument::totalCharacters
virtual int totalCharacters() const
Definition: katedocument.cpp:738
KTextEditor::Cursor::start
static Cursor start()
KateDocument::writeSessionConfig
virtual void writeSessionConfig(KConfigGroup &)
Definition: katedocument.cpp:1597
KateDocument::openUrl
virtual bool openUrl(const KUrl &url)
Definition: katedocument.cpp:2330
katedialogs.h
KateView::setCursorPosition
bool setCursorPosition(KTextEditor::Cursor position)
Definition: kateview.cpp:2393
QObject
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KTextEditor::Cursor
klocale.h
KateDocument::bomSetByUser
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
Definition: katedocument.cpp:1536
KTextEditor::Document::modeChanged
void modeChanged(KTextEditor::Document *document)
KateDocument::marksChanged
void marksChanged(KTextEditor::Document *)
k_funcinfo
#define k_funcinfo
KTextEditor::DocumentCursor::move
bool move(int chars, WrapBehavior wrapBehavior=Wrap)
Moves the cursor chars character forward or backwards.
Definition: documentcursor.cpp:150
KateDocument::plainKateTextLine
Kate::TextLine plainKateTextLine(uint i)
Definition: katedocument.cpp:4713
KateDocumentConfig::removeSpaces
int removeSpaces() const
Definition: kateconfig.cpp:717
KateDocumentConfig::backupFlags
uint backupFlags() const
Definition: kateconfig.cpp:938
KateDocument::indent
void indent(KTextEditor::Range range, int change)
Definition: katedocument.cpp:2898
KateModOnHdPrompt::Overwrite
Definition: katedialogs.h:402
KParts::ReadOnlyPart::started
void started(KIO::Job *)
KParts::ReadWritePart::closeUrl
virtual bool closeUrl()
KateDocument::backspace
void backspace(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2725
KateDocument::fromVirtualColumn
int fromVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2579
kateregexpsearch.h
KateDocument::dictionaryRangesPresent
void dictionaryRangesPresent(bool yesNo)
spellcheck.h
loadsavefiltercheckplugin.h
KParts::OpenUrlArguments::mimeType
QString mimeType() const
KParts::ReadOnlyPart::url
KUrl url
KUrl
Kate::SwapFile::discard
void discard()
Definition: kateswapfile.cpp:528
KateDocument::markClicked
void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled)
KateHighlighting::getCommentEnd
QString getCommentEnd(int attrib=0) const
Definition: katehighlight.cpp:1124
KateBuffer::setHighlight
void setHighlight(int hlMode)
Use highlight for highlighting.
Definition: katebuffer.cpp:357
KateDocument::documentSave
virtual bool documentSave()
Definition: katedocument.cpp:3899
KateView::getViInputModeManager
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1567
KateDocument::revision
virtual qint64 revision() const
Current revision.
Definition: katedocument.cpp:4747
kencodingfiledialog.h
KateDocument::comment
void comment(KateView *view, uint line, uint column, int change)
Definition: katedocument.cpp:3301
KateDocument::insertLines
virtual bool insertLines(int line, const QStringList &s)
Definition: katedocument.cpp:712
KUrl::setPath
void setPath(const QString &path)
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
KMessageBox::Cancel
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 &)
KateHighlighting::getCharacterEncodingsPrefixStore
const KatePrefixStore & getCharacterEncodingsPrefixStore(int attrib) const
Definition: katehighlight.cpp:694
KTextEditor::Range::columnWidth
int columnWidth() const
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:53
KTextEditor::ParameterizedSessionConfigInterface::SkipUrl
KateDocument::singleViewMode
bool singleViewMode() const
Definition: katedocument.h:140
KTextEditor::Search::Regex
kateregexp.h
KateHlContext
Definition: katehighlighthelpers.h:72
KateDocument::rangeInvalid
void rangeInvalid(KTextEditor::MovingRange *movingRange)
Definition: katedocument.cpp:5201
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2760
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:4780
KTextEditor::MovingRange::contains
bool contains(const Range &range) const
KateDocument::mode
virtual QString mode() const
Return the name of the currently used mode.
Definition: katedocument.cpp:1468
KMessageBox::warningYesNoCancel
static int warningYesNoCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KateDocument::setHighlightingMode
virtual bool setHighlightingMode(const QString &name)
Set the current mode of the document by giving its name.
Definition: katedocument.cpp:1484
kservicetypetrader.h
KateView::slotUpdateUndo
void slotUpdateUndo()
Definition: kateview.cpp:1249
KateDocument::Lowercase
Definition: katedocument.h:734
KateDocument::setActiveView
void setActiveView(KTextEditor::View *)
Definition: katedocument.cpp:2551
KateDocumentConfig::replaceTabsDyn
bool replaceTabsDyn() const
Definition: kateconfig.cpp:696
KateDocument::replaceText
virtual bool replaceText(const KTextEditor::Range &range, const QString &s, bool block=false)
Definition: katedocument.cpp:4687
KTextEditor::Document::viewCreated
void viewCreated(KTextEditor::Document *document, KTextEditor::View *view)
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:599
KateDocument::textLines
virtual QStringList textLines(const KTextEditor::Range &range, bool block=false) const
Definition: katedocument.cpp:398
kglobal.h
KTextEditor::Search::WholeWords
KEncodingFileDialog::getSaveUrlAndEncoding
static Result getSaveUrlAndEncoding(const QString &encoding=QString(), const QString &startDir=QString(), const QString &filter=QString(), QWidget *parent=0, const QString &caption=QString())
KateDocument::popEditState
void popEditState()
Definition: katedocument.cpp:836
KTextEditor::MovingRange::ExpandLeft
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:5266
KateDocument::makeAttribs
void makeAttribs(bool needInvalidate=true)
Definition: katedocument.cpp:2502
KateDocument::setDefaultDictionary
void setDefaultDictionary(const QString &dict)
Definition: katedocument.cpp:5137
KatePartPluginManager::removeDocument
void removeDocument(KTextEditor::Document *doc)
Definition: katepartpluginmanager.cpp:112
KateDocumentConfig::backupSuffix
const QString & backupSuffix() const
Definition: kateconfig.cpp:967
KateDocument::print
Q_SCRIPTABLE bool print()
Definition: katedocument.cpp:1853
KTextEditor::MovingCursor::InsertBehavior
InsertBehavior
KateDocument::newBracketMark
void newBracketMark(const KTextEditor::Cursor &start, KTextEditor::Range &bm, int maxLines=-1)
Definition: katedocument.cpp:3572
KStandardGuiItem::overwrite
KGuiItem overwrite()
KTextEditor::DocumentCursor::toCursor
const Cursor & toCursor() const
Convert this clever cursor into a dumb one.
Definition: documentcursor.cpp:217
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
KIO::file_copy
FileCopyJob * file_copy(const KUrl &src, const KUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
KateDocument::save
virtual bool save()
Definition: katedocument.cpp:4981
katemodemanager.h
KateDocument::character
virtual QChar character(const KTextEditor::Cursor &position) const
Definition: katedocument.cpp:388
KateViewConfig::setAutoCenterLines
void setAutoCenterLines(int lines)
Definition: kateconfig.cpp:1578
KTextEditor::ModificationInterface::OnDiskDeleted
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
KateAutoIndent
Provides Auto-Indent functionality for katepart.
Definition: kateautoindent.h:40
attribute.h
KParts::ReadOnlyPart::canceled
void canceled(const QString &errMsg)
KateView::setSelection
virtual bool setSelection(const KTextEditor::Range &selection)
Definition: kateview.cpp:1931
KateDocument::setDictionary
void setDictionary(const QString &dict, const KTextEditor::Range &range)
Definition: katedocument.cpp:5057
KateDocument::transform
void transform(KateView *view, const KTextEditor::Cursor &, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
Definition: katedocument.cpp:3383
KateDocument::editInsertText
bool editInsertText(int line, int col, const QString &s)
Add a string in the given line/column.
Definition: katedocument.cpp:971
Kate::SwapFile
Class for tracking editing actions.
Definition: kateswapfile.h:46
kmenu.h
katepartpluginmanager.h
KateHighlighting::attribute
int attribute(int context) const
Definition: katehighlight.cpp:1040
KXMLGUIClient::componentData
virtual KComponentData componentData() const
KTextEditor::Document
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
KTextEditor::Document::textRemoved
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range)
KateView::editEnd
void editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom)
Definition: kateview.cpp:1841
KTextEditor::Attribute::Ptr
KSharedPtr< Attribute > Ptr
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:1148
KGuiItem
KateHighlighting::attributes
QList< KTextEditor::Attribute::Ptr > attributes(const QString &schema)
Definition: katehighlight.cpp:2134
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:520
KParts::ReadWritePart::sigQueryClose
void sigQueryClose(bool *handled, bool *abortClosing)
KateDocument::dictionaryRanges
QList< QPair< KTextEditor::MovingRange *, QString > > dictionaryRanges() const
Definition: katedocument.cpp:5037
KateGlobal::deregisterDocument
void deregisterDocument(KateDocument *doc)
unregister document at the factory
Definition: kateglobal.cpp:478
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:3192
KateDocument::editRemoveLine
bool editRemoveLine(int line)
Remove a line.
Definition: katedocument.cpp:1289
QStringList
spaceChar
static const QChar spaceChar(' ')
KTextEditor::Document::isEmpty
virtual bool isEmpty() const
KateDocument::variable
virtual QString variable(const QString &name) const
Definition: katedocument.cpp:4339
KTextEditor::Range::invalid
static Range invalid()
KateDocument::lineAttributes
virtual QList< KTextEditor::HighlightInterface::AttributeBlock > lineAttributes(const unsigned int line)
Definition: katedocument.cpp:5372
Kate::TextBuffer::invalidateRanges
void invalidateRanges()
Invalidate all ranges in this buffer.
Definition: katetextbuffer.cpp:100
KMessageBox::Notify
KTextEditor::View::document
virtual Document * document() const =0
KSharedPtr::attach
void attach(T *p)
KateDocument::defStyleNum
int defStyleNum(int line, int column)
Definition: katedocument.cpp:5451
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
KParts::ReadWritePart::isReadWrite
bool isReadWrite() const
KTextEditor::ParameterizedSessionConfigInterface::SkipNone
KateHighlighting::getReverseCharacterEncodings
const QHash< QChar, QString > & getReverseCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:699
KTextEditor::Mark
KateBuffer::brokenEncoding
bool brokenEncoding() const
Did encoding errors occur on load?
Definition: katebuffer.h:109
KIcon
KateDocument::isDataRecoveryAvailable
virtual bool isDataRecoveryAvailable() const
Definition: katedocument.cpp:2451
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:4682
KateViewConfig::persistentSelection
bool persistentSelection() const
Definition: kateconfig.cpp:1669
KateDocument::editableMarks
virtual uint editableMarks() const
Definition: katedocument.cpp:1841
KTextEditor::MarkInterface::MarkRemoved
KateViewConfig::setPersistentSelection
void setPersistentSelection(bool on)
Definition: kateconfig.cpp:1677
KTextEditor::Document::textChanged
void textChanged(KTextEditor::Document *document)
KateDocument::rangeOnLine
KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const
Definition: katedocument.cpp:319
KTextEditor::Message::actions
QList< QAction * > actions() const
KTextEditor::Search::Backwards
KateRendererConfig::global
static KateRendererConfig * global()
Definition: kateconfig.h:613
KateDocument::undoCount
uint undoCount() const
Definition: katedocument.cpp:1365
KateDocument::wordWrap
bool wordWrap() const
Definition: katedocument.cpp:3927
KateUndoManager::clearRedo
void clearRedo()
Definition: kateundomanager.cpp:354
KStringHandler::csqueeze
QString csqueeze(const QString &str, int maxlen=40)
KateView::blockSelection
virtual bool blockSelection() const
Definition: kateview.cpp:2196
KateRendererConfig::setBackgroundColor
void setBackgroundColor(const QColor &col)
Definition: kateconfig.cpp:2186
KateDocument::newLine
void newLine(KateView *view)
Definition: katedocument.cpp:2659
KateDocument::m_dictionaryRanges
QList< QPair< KTextEditor::MovingRange *, QString > > m_dictionaryRanges
Definition: katedocument.h:1149
KateDocument::unlockRevision
virtual void unlockRevision(qint64 revision)
Release a revision.
Definition: katedocument.cpp:4762
KateDocumentConfig::setSmartHome
void setSmartHome(bool on)
Definition: kateconfig.cpp:620
kstandardaction.h
kateprinter.h
KateDocument::defaultDictionaryChanged
void defaultDictionaryChanged(KateDocument *document)
katedocumenthelpers.h
KTextEditor::View::cursorPosition
virtual Cursor cursorPosition() const =0
KParts::ReadOnlyPart::url
KUrl url() const
KXMLGUIClient::setComponentData
virtual void setComponentData(const KComponentData &componentData)
KateDocumentConfig::setRemoveSpaces
void setRemoveSpaces(int triState)
Remove trailing spaces on save.
Definition: kateconfig.cpp:704
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KateView::clear
void clear()
Definition: kateview.cpp:1878
KateDocument::isEditRunning
bool isEditRunning() const
Definition: katedocument.cpp:4718
KTextEditor::Document::documentRange
Range documentRange() const
KateDocument::queryClose
virtual bool queryClose()
Definition: katedocument.cpp:4807
KateDocument::configValue
virtual QVariant configValue(const QString &key)
Definition: katedocument.cpp:4609
KTextEditor::AnnotationModel
KateDocumentConfig::setShowTabs
void setShowTabs(bool on)
Definition: kateconfig.cpp:641
KateDocument::markPixmap
virtual QPixmap markPixmap(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1816
KateBuffer::editTagEnd
int editTagEnd() const
dirty lines end
Definition: katebuffer.h:83
KateView::selection
virtual bool selection() const
Definition: kateview.cpp:2008
KateDocumentConfig::encoding
const QString & encoding() const
Definition: kateconfig.cpp:788
KateDocument::configKeys
virtual QStringList configKeys() const
Definition: katedocument.cpp:4604
KateDocument::Uppercase
Definition: katedocument.h:734
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
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:2594
KateDocument::encoding
virtual const QString & encoding() const
Definition: katedocument.cpp:3958
KateHighlighting::getEmbeddedHighlightingModes
QStringList getEmbeddedHighlightingModes() const
Returns a list of names of embedded modes.
Definition: katehighlight.cpp:2166
KateDocumentConfig::setBackupPrefix
void setBackupPrefix(const QString &prefix)
Definition: kateconfig.cpp:975
KateView
Definition: kateview.h:78
KateBuffer::setTabWidth
void setTabWidth(int w)
Definition: katebuffer.cpp:346
KateDocument::closeUrl
virtual bool closeUrl()
Definition: katedocument.cpp:2336
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:4410
KateView::editStart
void editStart()
Definition: kateview.cpp:1836
KTextEditor::Range
jobuidelegate.h
KateDocument::messageDestroyed
void messageDestroyed(KTextEditor::Message *message)
Definition: katedocument.cpp:5543
types
QStringList types(Mode mode=Writing)
KateGlobal::dirWatch
KDirWatch * dirWatch()
global dirwatch
Definition: kateglobal.h:284
KateDocument::saveAs
virtual bool saveAs(const KUrl &url)
Definition: katedocument.cpp:5004
KateFileType
Definition: katemodemanager.h:34
KTextEditor::ParameterizedSessionConfigInterface::SkipMode
KTextEditor::Document::aboutToReload
void aboutToReload(KTextEditor::Document *document)
KTextEditor::Message::text
QString text() const
KateView::slotTextInserted
void slotTextInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
Definition: kateview.cpp:2245
KateView::updateView
void updateView(bool changed=false)
Definition: kateview.cpp:1891
KTextEditor::Range::onSingleLine
bool onSingleLine() const
KateOnTheFlyChecker::refreshSpellCheck
void refreshSpellCheck(const KTextEditor::Range &range=KTextEditor::Range::invalid())
Definition: ontheflycheck.cpp:680
EDIT_DEBUG
#define EDIT_DEBUG
Definition: katedocument.cpp:98
KateDocument
Definition: katedocument.h:74
KateRenderer::updateAttributes
void updateAttributes()
update the highlighting attributes (for example after an hl change or after hl config changed) ...
Definition: katerenderer.cpp:74
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
KateDocument::defaultDictionary
QString defaultDictionary() const
Definition: katedocument.cpp:5032
KTextEditor::Search::EscapeSequences
KTextEditor::ParameterizedSessionConfigInterface::SkipEncoding
KParts::ReadOnlyPart::arguments
OpenUrlArguments arguments() const
Kate::TextBuffer::removeText
virtual void removeText(const KTextEditor::Range &range)
Remove text at given range.
Definition: katetextbuffer.cpp:338
tabChar
static const QChar tabChar('\t')
KateDocument::findMatchingBracket
bool findMatchingBracket(KTextEditor::Range &range, int maxLines=-1)
Definition: katedocument.cpp:3588
KateDocument::del
void del(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2805
KateDocument::setUndoMergeAllEdits
void setUndoMergeAllEdits(bool merge)
Definition: katedocument.cpp:4723
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:1515
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
kstringhandler.h
KateViInputModeManager::getViReplaceMode
KateViReplaceMode * getViReplaceMode()
Definition: kateviinputmodemanager.cpp:549
KateDocument::variableChanged
void variableChanged(KTextEditor::Document *, const QString &, const QString &)
KParts::Part::setWidget
virtual void setWidget(QWidget *widget)
KateDocument::kateTextLine
Kate::TextLine kateTextLine(uint i)
Definition: katedocument.cpp:4707
KConfigGroup::hasKey
bool hasKey(const QString &key) const
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
KTextEditor::MovingRange::ExpandRight
KateDocumentConfig::indentationMode
const QString & indentationMode() const
Definition: kateconfig.cpp:451
KatePartPluginManager::addDocument
void addDocument(KTextEditor::Document *doc)
Definition: katepartpluginmanager.cpp:100
job.h
KTextEditor::ModificationInterface::ModifiedOnDiskReason
ModifiedOnDiskReason
KateDocumentConfig::indentationWidth
int indentationWidth() const
Definition: kateconfig.cpp:427
removeNewLines
static QString removeNewLines(const QString &str)
Definition: katedocument.cpp:3665
KateView::cursorPosition
KTextEditor::Cursor cursorPosition() const
Definition: kateview.cpp:2398
KateDocumentConfig::setWordWrap
void setWordWrap(bool on)
Definition: kateconfig.cpp:499
KConfigGroup
KateRendererConfig::schema
const QString & schema() const
Definition: kateconfig.cpp:1994
KateDocument::isComment
bool isComment(int line, int column)
Definition: katedocument.cpp:5491
KTextEditor::Cursor::line
virtual int line() const
KEncodingFileDialog::Result
KateView::removeSelectedText
bool removeSelectedText()
Definition: kateview.cpp:2021
KateDocument::charactersSemiInteractivelyInserted
void charactersSemiInteractivelyInserted(const KTextEditor::Cursor &position, const QString &text)
QFont
KEncodingFileDialog::Result::URLs
KUrl::List URLs
KateDocument::setAnnotationModel
virtual void setAnnotationModel(KTextEditor::AnnotationModel *model)
Definition: katedocument.cpp:4793
KUrl::setFileName
void setFileName(const QString &_txt)
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:862
KTextEditor::MarkInterface::MarkAdded
KXMLGUIClient::action
QAction * action(const char *name) const
KateDocumentConfig::wordWrap
bool wordWrap() const
Definition: kateconfig.cpp:491
KTextEditor::Cursor::setLine
virtual void setLine(int line)
KateDocument::setModifiedOnDisk
virtual void setModifiedOnDisk(ModifiedOnDiskReason reason)
Definition: katedocument.cpp:3786
KateDocument::setEncoding
virtual bool setEncoding(const QString &e)
Definition: katedocument.cpp:3953
KateDocument::editRemoveText
bool editRemoveText(int line, int col, int len)
Remove a string in the given line/column.
Definition: katedocument.cpp:1012
KateView::viInputMode
bool viInputMode() const
Definition: kateview.cpp:1515
KParts::ReadOnlyPart::setProgressInfoEnabled
void setProgressInfoEnabled(bool show)
KateUndoManager::isActive
bool isActive() const
Definition: kateundomanager.h:90
KateRendererConfig::font
const QFont & font() const
Definition: kateconfig.cpp:2127
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:3537
KTextEditor::Message::autoHide
int autoHide() const
QPoint
KateHighlighting::getCommentSingleLineStart
QString getCommentSingleLineStart(int attrib=0) const
Definition: katehighlight.cpp:1129
KateDocumentConfig::setShowSpaces
void setShowSpaces(bool on)
Definition: kateconfig.cpp:662
KateDocument::readSessionConfig
virtual void readSessionConfig(const KConfigGroup &)
Definition: katedocument.cpp:1543
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
KTextEditor::Cursor::setPosition
virtual void setPosition(const Cursor &position)
KateDocumentConfig::setPageUpDownMovesCursor
void setPageUpDownMovesCursor(bool on)
Definition: kateconfig.cpp:544
KateBuffer::unwrapLines
void unwrapLines(int from, int to)
Unwrap given lines.
Definition: katebuffer.cpp:310
KateDocument::wordWrapAt
uint wordWrapAt() const
Definition: katedocument.cpp:3937
KateHighlighting::getCharacterEncodings
const QHash< QString, QChar > & getCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:689
Kate::TextCursor
Class representing a 'clever' text cursor.
Definition: katetextcursor.h:43
KTextEditor::ModificationInterface::OnDiskModified
KateBuffer::editEnd
void editEnd()
finish some editing action
Definition: katebuffer.cpp:94
KIO::FileCopyJob
kstandarddirs.h
KateDocument::removeMark
virtual void removeMark(int line, uint markType)
Definition: katedocument.cpp:1714
KTextEditor::Message::setWordWrap
void setWordWrap(bool wordWrap)
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 ...
KEncodingFileDialog::Result::encoding
QString encoding
KateDocument::setVariable
virtual QString setVariable(const QString &name, const QString &value)
Definition: katedocument.cpp:4344
KTextEditor::HighlightInterface::DefaultStyle
DefaultStyle
KTextEditor::Range::end
Cursor & end()
KateHighlighting
Definition: katehighlight.h:119
KateOnTheFlyChecker::clearMisspellingForWord
void clearMisspellingForWord(const QString &word)
Definition: ontheflycheck.cpp:106
KateDocument::recoverData
virtual void recoverData()
Definition: katedocument.cpp:2456
KateBuffer::highlight
KateHighlighting * highlight()
Definition: katebuffer.h:194
KateHlManager::nameFind
int nameFind(const QString &name)
Definition: katesyntaxmanager.cpp:116
Kate::TextLine
QSharedPointer< TextLineData > TextLine
The normal world only accesses the text lines with shared pointers.
Definition: katetextline.h:443
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
KTextEditor::Message::TopInView
KateDocument::markToolTipRequested
void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled)
KateHighlighting::CSLPosColumn0
Definition: katehighlight.h:219
KIO::Job
KateDocument::modifiedOnDisk
void modifiedOnDisk(KTextEditor::Document *doc, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason)
Indicate this file is modified on disk.
KTextEditor::MarkInterface::reservedMarkersCount
static int reservedMarkersCount()
KateDocument::m_undoManager
KateUndoManager *const m_undoManager
Definition: katedocument.h:344
KateDocumentConfig::setReplaceTabsDyn
void setReplaceTabsDyn(bool on)
Definition: kateconfig.cpp:683
KateDocument::isOnTheFlySpellCheckingEnabled
bool isOnTheFlySpellCheckingEnabled() const
Definition: katedocument.cpp:5172
KParts::Part::setAutoDeletePart
void setAutoDeletePart(bool autoDeletePart)
KParts::ReadOnlyPart::openUrl
virtual bool openUrl(const KUrl &url)
KateModOnHdPrompt::Save
Definition: katedialogs.h:401
KateDocument::views
virtual const QList< KTextEditor::View * > & views() const
Definition: katedocument.cpp:309
KTextEditor::Range::numberOfLines
int numberOfLines() const
KateRendererConfig::backgroundColor
const QColor & backgroundColor() const
Definition: kateconfig.cpp:2178
katevireplacemode.h
KateDocument::ownedView
bool ownedView(KateView *)
Definition: katedocument.cpp:2559
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
KateDocument::containsCharacterEncoding
bool containsCharacterEncoding(const KTextEditor::Range &range)
Definition: katedocument.cpp:5228
KateDocument::setMarkDescription
virtual void setMarkDescription(MarkInterface::MarkTypes, const QString &)
Definition: katedocument.cpp:1811
KParts::ReadWritePart::setReadWrite
virtual void setReadWrite(bool readwrite=true)
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
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:5194
KateDocumentConfig::pageUpDownMovesCursor
bool pageUpDownMovesCursor() const
Definition: kateconfig.cpp:536
KateRendererConfig::setWordWrapMarkerColor
void setWordWrapMarkerColor(const QColor &col)
Definition: kateconfig.cpp:2304
KStandardGuiItem::save
KGuiItem save()
KTextEditor::Range::intersect
Range intersect(const Range &range) const
KateDocument::slotQueryClose_save
void slotQueryClose_save(bool *handled, bool *abortClosing)
Definition: katedocument.cpp:4559
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:1389
KateModOnHdPrompt::Reload
Definition: katedialogs.h:400
KateDocument::inputMethodStart
void inputMethodStart()
Definition: katedocument.cpp:845
QPair< KTextEditor::MovingRange *, QString >
KateRendererConfig::setIconBarColor
void setIconBarColor(const QColor &col)
Definition: kateconfig.cpp:2367
KateView::setBlockSelection
virtual bool setBlockSelection(bool on)
Definition: kateview.cpp:2201
KateDocument::insertTab
void insertTab(KateView *view, const KTextEditor::Cursor &)
Definition: katedocument.cpp:2913
KTextEditor::Editor
KateDocument::lockRevision
virtual void lockRevision(qint64 revision)
Lock a revision, this will keep it around until released again.
Definition: katedocument.cpp:4757
KateDocument::toVirtualColumn
int toVirtualColumn(int line, int column) const
Definition: katedocument.cpp:2564
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:1873
KateUndoManager::slotLineWrapped
void slotLineWrapped(int line, int col, int length, bool newLine)
Notify KateUndoManager that a line was wrapped.
Definition: kateundomanager.cpp:157
KMessageBox::Yes
KateDocument::Capitalize
Definition: katedocument.h:734
KTextEditor::Range::contains
bool contains(const Range &range) const
KateModOnHdPrompt
This dialog will prompt the user for what do with a file that is modified on disk.
Definition: katedialogs.h:395
KateDocument::postMessage
virtual bool postMessage(KTextEditor::Message *message)
Definition: katedocument.cpp:5498
KTextEditor::DocumentCursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: documentcursor.cpp:82
kcodecs.h
Kate::SwapFile::shouldRecover
bool shouldRecover() const
Definition: kateswapfile.cpp:519
KTextEditor::Search::CaseInsensitive
KTextEditor::Document::setOpeningError
void setOpeningError(bool errors)
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:578
KateView::reflectOnTheFlySpellCheckStatus
void reflectOnTheFlySpellCheckStatus(bool enabled)
Definition: kateview.cpp:3034
KateDocument::pageUpDownMovesCursor
bool pageUpDownMovesCursor() const
Definition: katedocument.cpp:3947
KXMLGUIClient::insertChildClient
void insertChildClient(KXMLGUIClient *child)
KateDocument::lastSavedRevision
virtual qint64 lastSavedRevision() const
Last revision the buffer got successful saved.
Definition: katedocument.cpp:4752
KateDocument::highlightingModes
virtual QStringList highlightingModes() const
Return a list of the names of all possible modes.
Definition: katedocument.cpp:1499
KTextEditor::Document::aboutToClose
void aboutToClose(KTextEditor::Document *document)
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
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:153
KTextEditor::Document::documentUrlChanged
void documentUrlChanged(KTextEditor::Document *document)
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:1210
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
KateDocument::revertToDefaultDictionary
void revertToDefaultDictionary(const KTextEditor::Range &range)
Definition: katedocument.cpp:5132
KTextEditor::View
KateDocument::removeView
void removeView(KTextEditor::View *)
removes the view from the list of views.
Definition: katedocument.cpp:2540
KateFileType::name
QString name
Definition: katemodemanager.h:38
KTextEditor::Message::Error
KateViInputModeManager::getCurrentViMode
ViMode getCurrentViMode() const
Definition: kateviinputmodemanager.cpp:449
KateViewConfig::setDynWordWrap
void setDynWordWrap(bool wrap)
Definition: kateconfig.cpp:1326
KUrl::isLocalFile
bool isLocalFile() const
KateDocumentConfig::backspaceIndents
bool backspaceIndents() const
Definition: kateconfig.cpp:612
kmessagebox.h
KateDocumentConfig::setBom
void setBom(bool bom)
Definition: kateconfig.cpp:875
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
KMessageBox::Dangerous
KateDocument::m_onTheFlyChecker
KateOnTheFlyChecker * m_onTheFlyChecker
Definition: katedocument.h:1147
KTextEditor::Range::isEmpty
bool isEmpty() const
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:411
KDirWatch::removeFile
void removeFile(const QString &file)
KateDocumentConfig::tabWidth
int tabWidth() const
Definition: kateconfig.cpp:403
KTextEditor::Document::textInserted
void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range)
KateView::config
KateViewConfig * config()
Configuration.
Definition: kateview.h:654
KTextEditor::HighlightInterface::AttributeBlock
KateHighlighting::isInWord
bool isInWord(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1084
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:4772
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:2076
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
katehighlighthelpers.h
KateView::updateDocumentConfig
void updateDocumentConfig()
Definition: kateview.cpp:1744
KateModeManager::list
const QList< KateFileType * > & list() const
Don't modify.
Definition: katemodemanager.h:93
kateconfig.h
KTextEditor::Cursor::setColumn
virtual void setColumn(int column)
KTextEditor::Cursor::column
int column() 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
KTextEditor::Message
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:4677
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KateDocument::joinLines
void joinLines(uint first, uint last)
Unwrap a range of lines.
Definition: katedocument.cpp:3496
KateView::setCursorPositionInternal
bool setCursorPositionInternal(const KTextEditor::Cursor &position, uint tabwidth=1, bool calledExternally=false)
Definition: kateview.cpp:1278
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:1022
KMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
Kate::TextRange
Class representing a 'clever' text range.
Definition: katetextrange.h:46
KTextEditor::Range::setBothLines
void setBothLines(int line)
KateHlManager::self
static KateHlManager * self()
Definition: katesyntaxmanager.cpp:103
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:435
KateDocument::setMarkPixmap
virtual void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &)
Definition: katedocument.cpp:1806
KateOnTheFlyChecker
Definition: ontheflycheck.h:40
kfileitem.h
KateDocument::editMarkLineAutoWrapped
bool editMarkLineAutoWrapped(int line, bool autowrapped)
Mark line as autowrapped.
Definition: katedocument.cpp:1056
KateDocument::annotationModelChanged
void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *)
KTextEditor::HighlightInterface::dsComment
KTextEditor::Message::Warning
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:5211
KateDocument::removeText
virtual bool removeText(const KTextEditor::Range &range, bool block=false)
Definition: katedocument.cpp:633
KTextEditor::Search::Default
KTextEditor::Document::documentSavedOrUploaded
void documentSavedOrUploaded(KTextEditor::Document *document, bool saveAs)
KateDocument::setPageUpDownMovesCursor
void setPageUpDownMovesCursor(bool on)
Definition: katedocument.cpp:3942
QAction
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:917
KateRendererConfig::setHighlightedLineColor
void setHighlightedLineColor(const QColor &col)
Definition: kateconfig.cpp:2228
prefixstore.h
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KateBuffer
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:39
KParts::ReadWritePart::isModified
bool isModified() const
KFileItem
KateHighlighting::contextNum
KateHlContext * contextNum(int n)
Definition: katehighlight.h:267
KateDocument::discardDataRecovery
virtual void discardDataRecovery()
Definition: katedocument.cpp:2462
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:3712
KateAutoIndent::checkRequiredStyle
void checkRequiredStyle()
Check if the current highlighting mode provides the style required by the current indenter...
Definition: kateautoindent.cpp:355
KTextEditor::Message::addAction
void addAction(QAction *action, bool closeOnTrigger=true)
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
QList< KTextEditor::View * >
KateDocumentConfig::setEncoding
bool setEncoding(const QString &encoding)
Definition: kateconfig.cpp:811
KateDocumentConfig::bom
bool bom() const
Definition: kateconfig.cpp:888
KParts::Part::setAutoDeleteWidget
void setAutoDeleteWidget(bool autoDeleteWidget)
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:946
list
QStringList list(const QString &fileClass)
KParts::ReadOnlyPart::localFilePath
QString localFilePath() const
KateDocument::rangeEmpty
void rangeEmpty(KTextEditor::MovingRange *movingRange)
Definition: katedocument.cpp:5206
KateHlManager::highlights
int highlights()
Definition: katesyntaxmanager.cpp:355
KateDocument::markDescription
virtual QString markDescription(MarkInterface::MarkTypes) const
Definition: katedocument.cpp:1831
KTextEditor::Document::exclusiveEditStart
void exclusiveEditStart(KTextEditor::Document *document)
KateDocument::checkOverwrite
static bool checkOverwrite(KUrl u, QWidget *parent)
Definition: katedocument.cpp:4585
KateOnTheFlyChecker::updateConfig
void updateConfig()
Definition: ontheflycheck.cpp:670
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:52 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
  • Applications
  •   Libraries
  •     libkonq
  • 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