22 #include "katedocument.h"
23 #include "katedocument.moc"
24 #include "katekeyinterceptorfunctor.h"
25 #include "katefactory.h"
26 #include "katedialogs.h"
27 #include "katehighlight.h"
29 #include "katesearch.h"
30 #include "kateautoindent.h"
31 #include "katetextline.h"
32 #include "katedocumenthelpers.h"
33 #include "kateprinter.h"
34 #include "katelinerange.h"
35 #include "katesupercursor.h"
36 #include "katearbitraryhighlight.h"
37 #include "katerenderer.h"
38 #include "kateattribute.h"
39 #include "kateconfig.h"
40 #include "katefiletype.h"
41 #include "kateschema.h"
42 #include "katetemplatehandler.h"
43 #include <tdetexteditor/plugin.h>
45 #include <tdeio/job.h>
46 #include <tdeio/netaccess.h>
47 #include <tdeio/tdefileitem.h>
50 #include <tdeparts/event.h>
53 #include <tdeglobal.h>
54 #include <tdeapplication.h>
55 #include <tdepopupmenu.h>
56 #include <tdeconfig.h>
57 #include <tdefiledialog.h>
58 #include <tdemessagebox.h>
59 #include <kstdaction.h>
60 #include <kiconloader.h>
61 #include <kxmlguifactory.h>
62 #include <kdialogbase.h>
64 #include <tdeglobalsettings.h>
65 #include <klibloader.h>
66 #include <kdirwatch.h>
68 #include <kencodingfiledialog.h>
69 #include <tdetempfile.h>
71 #include <kstandarddirs.h>
75 #include <tqclipboard.h>
76 #include <tqtextstream.h>
77 #include <tqtextcodec.h>
82 class KatePartPluginItem
85 KTextEditor::Plugin *plugin;
93 KateDocument::KateDocument (
bool bSingleViewMode,
bool bBrowserView,
94 bool bReadOnly, TQWidget *parentWidget,
95 const char *widgetName, TQObject *parent,
const char *name)
97 m_plugins (KateFactory::self()->plugins().count()),
98 m_undoDontMerge(false),
99 m_undoIgnoreCancel(false),
100 lastUndoGroupWhenSaved( 0 ),
101 lastRedoGroupWhenSaved( 0 ),
102 docWasSavedWhenUndoWasEmpty( true ),
103 docWasSavedWhenRedoWasEmpty( true ),
110 m_undoComplexMerge=
false;
113 setObjId (
"KateDocument#"+documentDCOPSuffix());
116 setBlockSelectionInterfaceDCOPSuffix (documentDCOPSuffix());
117 setConfigInterfaceDCOPSuffix (documentDCOPSuffix());
118 setConfigInterfaceExtensionDCOPSuffix (documentDCOPSuffix());
119 setCursorInterfaceDCOPSuffix (documentDCOPSuffix());
120 setEditInterfaceDCOPSuffix (documentDCOPSuffix());
121 setEncodingInterfaceDCOPSuffix (documentDCOPSuffix());
122 setHighlightingInterfaceDCOPSuffix (documentDCOPSuffix());
123 setMarkInterfaceDCOPSuffix (documentDCOPSuffix());
124 setMarkInterfaceExtensionDCOPSuffix (documentDCOPSuffix());
125 setPrintInterfaceDCOPSuffix (documentDCOPSuffix());
126 setSearchInterfaceDCOPSuffix (documentDCOPSuffix());
127 setSelectionInterfaceDCOPSuffix (documentDCOPSuffix());
128 setSelectionInterfaceExtDCOPSuffix (documentDCOPSuffix());
129 setSessionConfigInterfaceDCOPSuffix (documentDCOPSuffix());
130 setUndoInterfaceDCOPSuffix (documentDCOPSuffix());
131 setWordWrapInterfaceDCOPSuffix (documentDCOPSuffix());
137 KateFactory::self()->registerDocument (
this);
141 m_encodingSticky =
false;
147 m_config =
new KateDocumentConfig (
this);
154 m_fileTypeSetByUser =
false;
155 setInstance( KateFactory::self()->
instance() );
157 editSessionNumber = 0;
158 editIsRunning =
false;
159 m_editCurrentUndo = 0L;
160 editWithUndo =
false;
164 m_bSingleViewMode = bSingleViewMode;
165 m_bBrowserView = bBrowserView;
166 m_bReadOnly = bReadOnly;
168 m_marks.setAutoDelete(
true );
169 m_markPixmaps.setAutoDelete(
true );
170 m_markDescriptions.setAutoDelete(
true );
171 setMarksUserChangable( markType01 );
173 m_undoMergeTimer =
new TQTimer(
this);
174 connect(m_undoMergeTimer, TQ_SIGNAL(timeout()), TQ_SLOT(undoCancel()));
180 docWasSavedWhenUndoWasEmpty =
true;
183 m_buffer->setHighlight (0);
189 m_indenter->updateConfig ();
192 connect(m_buffer, TQ_SIGNAL(tagLines(
int,
int)),
this, TQ_SLOT(tagLines(
int,
int)));
193 connect(m_buffer, TQ_SIGNAL(codeFoldingUpdated()),
this,TQ_SIGNAL(codeFoldingUpdated()));
196 connect(KateHlManager::self(),TQ_SIGNAL(changed()),TQ_SLOT(internalHlChanged()));
202 connect( KateFactory::self()->dirWatch(), TQ_SIGNAL(dirty (
const TQString &)),
203 this, TQ_SLOT(slotModOnHdDirty (
const TQString &)) );
205 connect( KateFactory::self()->dirWatch(), TQ_SIGNAL(created (
const TQString &)),
206 this, TQ_SLOT(slotModOnHdCreated (
const TQString &)) );
208 connect( KateFactory::self()->dirWatch(), TQ_SIGNAL(deleted (
const TQString &)),
209 this, TQ_SLOT(slotModOnHdDeleted (
const TQString &)) );
215 if ( m_bSingleViewMode )
217 KTextEditor::View *view = createView( parentWidget, widgetName );
218 insertChildClient( view );
223 connect(
this,TQ_SIGNAL(sigQueryClose(
bool *,
bool*)),
this,TQ_SLOT(slotQueryClose_save(
bool *,
bool*)));
228 for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
230 if (config()->plugin (i))
238 KateDocument::~KateDocument()
241 deactivateDirWatch ();
243 if (!singleViewMode())
246 m_views.setAutoDelete(
true );
250 delete m_editCurrentUndo;
252 delete m_arbitraryHL;
255 undoItems.setAutoDelete(
true);
263 KateFactory::self()->deregisterDocument (
this);
268 void KateDocument::unloadAllPlugins ()
270 for (uint i=0; i<m_plugins.count(); i++)
274 void KateDocument::enableAllPluginsGUI (KateView *view)
276 for (uint i=0; i<m_plugins.count(); i++)
277 enablePluginGUI (m_plugins[i], view);
280 void KateDocument::disableAllPluginsGUI (KateView *view)
282 for (uint i=0; i<m_plugins.count(); i++)
283 disablePluginGUI (m_plugins[i], view);
286 void KateDocument::loadPlugin (uint pluginIndex)
288 if (m_plugins[pluginIndex])
return;
290 m_plugins[pluginIndex] = KTextEditor::createPlugin (TQFile::encodeName((KateFactory::self()->plugins())[pluginIndex]->library()),
this);
292 enablePluginGUI (m_plugins[pluginIndex]);
295 void KateDocument::unloadPlugin (uint pluginIndex)
297 if (!m_plugins[pluginIndex])
return;
299 disablePluginGUI (m_plugins[pluginIndex]);
301 delete m_plugins[pluginIndex];
302 m_plugins[pluginIndex] = 0L;
305 void KateDocument::enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view)
308 if (!KTextEditor::pluginViewInterface(plugin))
return;
314 KTextEditor::pluginViewInterface(plugin)->addView(view);
320 void KateDocument::enablePluginGUI (KTextEditor::Plugin *plugin)
323 if (!KTextEditor::pluginViewInterface(plugin))
return;
325 for (uint i=0; i< m_views.count(); i++)
326 enablePluginGUI (plugin, m_views.at(i));
329 void KateDocument::disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view)
332 if (!KTextEditor::pluginViewInterface(plugin))
return;
338 KTextEditor::pluginViewInterface( plugin )->removeView( view );
344 void KateDocument::disablePluginGUI (KTextEditor::Plugin *plugin)
347 if (!KTextEditor::pluginViewInterface(plugin))
return;
349 for (uint i=0; i< m_views.count(); i++)
350 disablePluginGUI (plugin, m_views.at(i));
356 KTextEditor::View *KateDocument::createView( TQWidget *parent,
const char *name )
358 KateView* newView =
new KateView(
this, parent, name);
359 connect(newView, TQ_SIGNAL(cursorPositionChanged()), TQ_SLOT(undoCancel()));
360 if ( s_fileChangedDialogsActivated )
361 connect( newView, TQ_SIGNAL(gotFocus(
Kate::View * )),
this, TQ_SLOT(slotModifiedOnDisk()) );
365 TQPtrList<KTextEditor::View> KateDocument::views ()
const
367 return m_textEditViews;
370 void KateDocument::setActiveView( KateView *view )
372 if ( m_activeView == view )
return;
380 uint KateDocument::configPages ()
const
385 KTextEditor::ConfigPage *KateDocument::configPage (uint number, TQWidget *parent,
const char * )
390 return new KateViewDefaultsConfig (parent);
393 return new KateSchemaConfigPage (parent,
this);
396 return new KateSelectConfigTab (parent);
399 return new KateEditConfigTab (parent);
402 return new KateIndentConfigTab (parent);
405 return new KateSaveConfigTab (parent);
408 return new KateHlConfigPage (parent,
this);
411 return new KateFileTypeConfigTab (parent);
414 return new KateEditKeyConfiguration (parent,
this);
417 return new KatePartPluginConfigPage (parent);
426 TQString KateDocument::configPageName (uint number)
const
431 return i18n (
"Appearance");
434 return i18n (
"Fonts & Colors");
437 return i18n (
"Cursor & Selection");
440 return i18n (
"Editing");
443 return i18n (
"Indentation");
446 return i18n(
"Open/Save");
449 return i18n (
"Highlighting");
452 return i18n(
"Filetypes");
455 return i18n (
"Shortcuts");
458 return i18n (
"Plugins");
461 return TQString (
"");
464 return TQString (
"");
467 TQString KateDocument::configPageFullName (uint number)
const
472 return i18n(
"Appearance");
475 return i18n (
"Font & Color Schemas");
478 return i18n (
"Cursor & Selection Behavior");
481 return i18n (
"Editing Options");
484 return i18n (
"Indentation Rules");
487 return i18n(
"File Opening & Saving");
490 return i18n (
"Highlighting Rules");
493 return i18n(
"Filetype Specific Settings");
496 return i18n (
"Shortcuts Configuration");
499 return i18n (
"Plugin Manager");
502 return TQString (
"");
505 return TQString (
"");
508 TQPixmap KateDocument::configPagePixmap (uint number,
int size)
const
513 return BarIcon(
"view_text",size);
516 return BarIcon(
"colorize", size);
519 return BarIcon(
"frame_edit", size);
522 return BarIcon(
"edit", size);
525 return BarIcon(
"format-justify-right", size);
528 return BarIcon(
"document-save", size);
531 return BarIcon(
"text-x-src", size);
534 return BarIcon(
"edit", size);
537 return BarIcon(
"key_enter", size);
540 return BarIcon(
"connect_established", size);
543 return BarIcon(
"edit", size);
546 return BarIcon(
"edit", size);
552 TQString KateDocument::text()
const
556 for (uint i = 0; i < m_buffer->count(); i++)
562 s.append (textLine->string());
564 if ((i+1) < m_buffer->count())
572 TQString KateDocument::text ( uint startLine, uint startCol, uint endLine, uint endCol )
const
574 return text(startLine, startCol, endLine, endCol,
false);
577 TQString KateDocument::text ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise)
const
579 if ( blockwise && (startCol > endCol) )
584 if (startLine == endLine)
586 if (startCol > endCol)
594 return textLine->string(startCol, endCol-startCol);
599 for (uint i = startLine; (i <= endLine) && (i < m_buffer->count()); i++)
606 s.append (textLine->string(startCol, textLine->length()-startCol));
607 else if (i == endLine)
608 s.append (textLine->string(0, endCol));
610 s.append (textLine->string());
614 s.append( textLine->string( startCol, endCol-startCol));
625 TQString KateDocument::textLine( uint line )
const
635 bool KateDocument::setText(
const TQString &s)
640 TQPtrList<KTextEditor::Mark> m = marks ();
641 TQValueList<KTextEditor::Mark> msave;
643 for (uint i=0; i < m.count(); i++)
644 msave.append (*m.at(i));
652 insertText (0, 0, s);
656 for (uint i=0; i < msave.count(); i++)
657 setMark (msave[i].line, msave[i].type);
662 bool KateDocument::clear()
667 for (KateView * view = m_views.first(); view != 0L; view = m_views.next() ) {
675 return removeText (0,0,lastLine()+1, 0);
678 bool KateDocument::insertText( uint line, uint col,
const TQString &s)
680 return insertText (line, col, s,
false);
683 bool KateDocument::insertText( uint line, uint col,
const TQString &s,
bool blockwise )
691 if (line == numLines())
692 editInsertLine(line,
"");
693 else if (line > lastLine())
698 uint insertPos = col;
699 uint len = s.length();
703 bool replacetabs = ( config()->configFlags() & KateDocumentConfig::cfReplaceTabsDyn && ! m_isInUndo );
704 uint tw = config()->tabWidth();
705 uint insertPosExpanded = insertPos;
708 insertPosExpanded = l->cursorX( insertPos, tw );
710 for (uint pos = 0; pos < len; pos++)
716 editInsertText (line, insertPos, buf);
720 editWrapLine (line, insertPos + buf.length());
721 insertPos = insertPosExpanded = 0;
725 if ( line == lastLine() )
726 editWrapLine (line, insertPos + buf.length());
731 l = m_buffer->line( line );
733 insertPosExpanded = l->cursorX( insertPos, tw );
737 if ( replacetabs && ch ==
'\t' )
739 uint tr = tw - ( insertPosExpanded+buf.length() )%tw;
740 for ( uint i=0; i < tr; i++ )
748 editInsertText (line, insertPos, buf);
751 emit textInserted(line,insertPos);
755 bool KateDocument::removeText ( uint startLine, uint startCol, uint endLine, uint endCol )
757 return removeText (startLine, startCol, endLine, endCol,
false);
760 bool KateDocument::removeText ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise)
765 if ( blockwise && (startCol > endCol) )
768 if ( startLine > endLine )
771 if ( startLine > lastLine() )
775 emit aboutToRemoveText(KateTextRange(startLine,startCol,endLine,endCol));
781 if ( endLine > lastLine() )
783 endLine = lastLine()+1;
787 if (startLine == endLine)
789 editRemoveText (startLine, startCol, endCol-startCol);
791 else if ((startLine+1) == endLine)
793 if ( (m_buffer->plainLine(startLine)->length()-startCol) > 0 )
794 editRemoveText (startLine, startCol, m_buffer->plainLine(startLine)->length()-startCol);
796 editRemoveText (startLine+1, 0, endCol);
797 editUnWrapLine (startLine);
801 for (uint line = endLine; line >= startLine; line--)
803 if ((line > startLine) && (line < endLine))
805 editRemoveLine (line);
811 if ( endLine <= lastLine() )
812 editRemoveText (line, 0, endCol);
816 if ( (m_buffer->plainLine(line)->length()-startCol) > 0 )
817 editRemoveText (line, startCol, m_buffer->plainLine(line)->length()-startCol);
819 editUnWrapLine (startLine);
830 if ( endLine > lastLine() )
831 endLine = lastLine ();
833 for (uint line = endLine; line >= startLine; line--)
836 editRemoveText (line, startCol, endCol-startCol);
848 bool KateDocument::insertLine( uint l,
const TQString &str )
856 return editInsertLine (l, str);
859 bool KateDocument::removeLine( uint line )
864 if (line > lastLine())
867 return editRemoveLine (line);
870 uint KateDocument::length()
const
874 for (uint i = 0; i < m_buffer->count(); i++)
885 uint KateDocument::numLines()
const
887 return m_buffer->
count();
890 uint KateDocument::numVisLines()
const
892 return m_buffer->countVisible ();
895 int KateDocument::lineLength ( uint line )
const
910 void KateDocument::editStart (
bool withUndo)
914 if (editSessionNumber > 1)
917 editIsRunning =
true;
918 editWithUndo = withUndo;
925 for (uint z = 0; z < m_views.count(); z++)
927 m_views.at(z)->editStart ();
930 m_buffer->editStart ();
933 void KateDocument::undoStart()
935 if (m_editCurrentUndo || (m_activeView && m_activeView->imComposeEvent()))
return;
938 if ((config()->undoSteps() > 0) && (undoItems.count() > config()->undoSteps()))
940 undoItems.setAutoDelete(
true);
941 undoItems.removeFirst();
942 undoItems.setAutoDelete(
false);
943 docWasSavedWhenUndoWasEmpty =
false;
950 void KateDocument::undoEnd()
952 if (m_activeView && m_activeView->imComposeEvent())
955 if (m_editCurrentUndo)
957 bool changedUndo =
false;
959 if (m_editCurrentUndo->isEmpty())
960 delete m_editCurrentUndo;
961 else if (!m_undoDontMerge && undoItems.last() && undoItems.last()->merge(m_editCurrentUndo,m_undoComplexMerge))
962 delete m_editCurrentUndo;
965 undoItems.append(m_editCurrentUndo);
969 m_undoDontMerge =
false;
970 m_undoIgnoreCancel =
true;
972 m_editCurrentUndo = 0L;
976 m_undoMergeTimer->start(5000,
true);
983 void KateDocument::undoCancel()
985 if (m_undoIgnoreCancel) {
986 m_undoIgnoreCancel =
false;
990 m_undoDontMerge =
true;
992 Q_ASSERT(!m_editCurrentUndo);
995 delete m_editCurrentUndo;
996 m_editCurrentUndo = 0L;
999 void KateDocument::undoSafePoint() {
1000 Q_ASSERT(m_editCurrentUndo);
1001 if (!m_editCurrentUndo)
return;
1002 m_editCurrentUndo->safePoint();
1008 void KateDocument::editEnd ()
1010 if (editSessionNumber == 0)
1014 if (m_buffer->editChanged() && (editSessionNumber == 1))
1015 if (editWithUndo && config()->wordWrap())
1016 wrapText (m_buffer->editTagStart(), m_buffer->editTagEnd());
1018 editSessionNumber--;
1020 if (editSessionNumber > 0)
1025 m_buffer->editEnd ();
1031 for (uint z = 0; z < m_views.count(); z++)
1032 m_views.at(z)->editEnd (m_buffer->editTagStart(), m_buffer->editTagEnd(), m_buffer->editTagFrom());
1034 if (m_buffer->editChanged())
1037 emit textChanged ();
1040 editIsRunning =
false;
1043 bool KateDocument::wrapText (uint startLine, uint endLine)
1045 uint col = config()->wordWrapAt();
1052 for (uint line = startLine; (line <= endLine) && (line < numLines()); line++)
1059 kdDebug (13020) <<
"try wrap line: " << line <<
endl;
1061 if (l->lengthWithTabs(m_buffer->tabWidth()) > col)
1065 kdDebug (13020) <<
"do wrap line: " << line <<
endl;
1067 const TQChar *text = l->text();
1068 uint eolPosition = l->length()-1;
1072 const TQString & t = l->string();
1074 for ( ; z2 < l->length(); z2++)
1076 if (t[z2] == TQChar(
'\t'))
1077 x += m_buffer->tabWidth() - (x % m_buffer->tabWidth());
1085 uint searchStart = kMin (z2, l->length()-1);
1089 if (searchStart == eolPosition && text[searchStart].isSpace())
1100 for (z=searchStart; z > 0; z--)
1102 if (text[z].isSpace())
break;
1103 if ( ! nw && highlight()->canBreakAt( text[z] , l->attribute(z) ) )
1110 editRemoveText (line, z, 1);
1117 if ( nw && nw < col ) nw++;
1121 if (nextl && !nextl->isAutoWrapped())
1123 editWrapLine (line, z,
true);
1124 editMarkLineAutoWrapped (line+1,
true);
1130 if (nextl && (nextl->length() > 0) && !nextl->getChar(0).isSpace() && ((l->length() < 1) || !l->getChar(l->length()-1).isSpace()))
1131 editInsertText (line+1, 0, TQString (
" "));
1133 bool newLineAdded =
false;
1134 editWrapLine (line, z,
false, &newLineAdded);
1136 editMarkLineAutoWrapped (line+1,
true);
1148 void KateDocument::editAddUndo (
KateUndoGroup::UndoType type, uint line, uint col, uint len,
const TQString &text)
1150 if (editIsRunning && editWithUndo && m_editCurrentUndo) {
1151 m_editCurrentUndo->addItem(type, line, col, len, text);
1154 if (redoItems.count()) {
1155 redoItems.setAutoDelete(
true);
1157 redoItems.setAutoDelete(
false);
1162 bool KateDocument::editInsertText ( uint line, uint col,
const TQString &str )
1174 if ( config()->configFlags() & KateDocumentConfig::cfReplaceTabsDyn && ! m_isInUndo )
1176 uint tw = config()->tabWidth();
1179 while ( (pos = s.find(
'\t')) > -1 )
1181 l = tw - ( (col + pos)%tw );
1182 s.replace( pos, 1, TQString().fill(
' ', l ) );
1188 editAddUndo (KateUndoGroup::editInsertText, line, col, s.length(), s);
1190 l->insertText (col, s.length(), s.unicode());
1193 m_buffer->changeLine(line);
1195 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1196 it.current()->editTextInserted (line, col, s.length());
1203 bool KateDocument::editRemoveText ( uint line, uint col, uint len )
1215 editAddUndo (KateUndoGroup::editRemoveText, line, col, len, l->string().mid(col, len));
1217 l->removeText (col, len);
1218 removeTrailingSpace( line );
1220 m_buffer->changeLine(line);
1222 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1223 it.current()->editTextRemoved (line, col, len);
1230 bool KateDocument::editMarkLineAutoWrapped ( uint line,
bool autowrapped )
1242 editAddUndo (KateUndoGroup::editMarkLineAutoWrapped, line, autowrapped ? 1 : 0, 0, TQString::null);
1244 l->setAutoWrapped (autowrapped);
1246 m_buffer->changeLine(line);
1253 bool KateDocument::editWrapLine ( uint line, uint col,
bool newLine,
bool *newLineAdded)
1267 int pos = l->length() - col;
1272 editAddUndo (KateUndoGroup::editWrapLine, line, col, pos, (!nextLine || newLine) ?
"1" :
"0");
1274 if (!nextLine || newLine)
1278 textLine->insertText (0, pos, l->text()+col, l->attributes()+col);
1281 m_buffer->insertLine (line+1, textLine);
1282 m_buffer->changeLine(line);
1284 TQPtrList<KTextEditor::Mark> list;
1285 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks ); it.current(); ++it )
1287 if( it.current()->line >= line )
1289 if ((col == 0) || (it.current()->line > line))
1290 list.append( it.current() );
1294 for( TQPtrListIterator<KTextEditor::Mark> it( list ); it.current(); ++it )
1296 KTextEditor::Mark* mark = m_marks.take( it.current()->line );
1298 m_marks.insert( mark->line, mark );
1301 if( !list.isEmpty() )
1302 emit marksChanged();
1306 (*newLineAdded) =
true;
1310 nextLine->insertText (0, pos, l->text()+col, l->attributes()+col);
1313 m_buffer->changeLine(line);
1314 m_buffer->changeLine(line+1);
1318 (*newLineAdded) =
false;
1321 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1322 it.current()->editLineWrapped (line, col, !nextLine || newLine);
1329 bool KateDocument::editUnWrapLine ( uint line,
bool removeLine, uint length )
1337 if (!l || !nextLine)
1342 uint col = l->length ();
1344 editAddUndo (KateUndoGroup::editUnWrapLine, line, col, length, removeLine ?
"1" :
"0");
1348 l->insertText (col, nextLine->length(), nextLine->text(), nextLine->attributes());
1350 m_buffer->changeLine(line);
1351 m_buffer->removeLine(line+1);
1355 l->insertText (col, (nextLine->length() < length) ? nextLine->length() : length,
1356 nextLine->text(), nextLine->attributes());
1357 nextLine->removeText (0, (nextLine->length() < length) ? nextLine->length() : length);
1359 m_buffer->changeLine(line);
1360 m_buffer->changeLine(line+1);
1363 TQPtrList<KTextEditor::Mark> list;
1364 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks ); it.current(); ++it )
1366 if( it.current()->line >= line+1 )
1367 list.append( it.current() );
1369 if ( it.current()->line == line+1 )
1371 KTextEditor::Mark* mark = m_marks.take( line );
1375 it.current()->type |= mark->type;
1380 for( TQPtrListIterator<KTextEditor::Mark> it( list ); it.current(); ++it )
1382 KTextEditor::Mark* mark = m_marks.take( it.current()->line );
1384 m_marks.insert( mark->line, mark );
1387 if( !list.isEmpty() )
1388 emit marksChanged();
1390 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1391 it.current()->editLineUnWrapped (line, col, removeLine, length);
1398 bool KateDocument::editInsertLine ( uint line,
const TQString &s )
1403 if ( line > numLines() )
1408 editAddUndo (KateUndoGroup::editInsertLine, line, 0, s.length(), s);
1410 removeTrailingSpace( line );
1413 tl->insertText (0, s.length(), s.unicode(), 0);
1414 m_buffer->insertLine(line, tl);
1415 m_buffer->changeLine(line);
1417 removeTrailingSpace( line );
1419 TQPtrList<KTextEditor::Mark> list;
1420 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks ); it.current(); ++it )
1422 if( it.current()->line >= line )
1423 list.append( it.current() );
1426 for( TQPtrListIterator<KTextEditor::Mark> it( list ); it.current(); ++it )
1428 KTextEditor::Mark* mark = m_marks.take( it.current()->line );
1430 m_marks.insert( mark->line, mark );
1433 if( !list.isEmpty() )
1434 emit marksChanged();
1436 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1437 it.current()->editLineInserted (line);
1444 bool KateDocument::editRemoveLine ( uint line )
1449 if ( line > lastLine() )
1452 if ( numLines() == 1 )
1453 return editRemoveText (0, 0, m_buffer->line(0)->length());
1457 editAddUndo (KateUndoGroup::editRemoveLine, line, 0, lineLength(line), textLine(line));
1459 m_buffer->removeLine(line);
1461 TQPtrList<KTextEditor::Mark> list;
1462 KTextEditor::Mark* rmark = 0;
1463 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks ); it.current(); ++it )
1465 if ( (it.current()->line > line) )
1466 list.append( it.current() );
1467 else if ( (it.current()->line == line) )
1468 rmark = it.current();
1472 delete (m_marks.take (rmark->line));
1474 for( TQPtrListIterator<KTextEditor::Mark> it( list ); it.current(); ++it )
1476 KTextEditor::Mark* mark = m_marks.take( it.current()->line );
1478 m_marks.insert( mark->line, mark );
1481 if( !list.isEmpty() )
1482 emit marksChanged();
1484 for( TQPtrListIterator<KateSuperCursor> it (m_superCursors); it.current(); ++it )
1485 it.current()->editLineRemoved (line);
1495 uint KateDocument::undoCount ()
const
1497 return undoItems.count ();
1500 uint KateDocument::redoCount ()
const
1502 return redoItems.count ();
1505 uint KateDocument::undoSteps ()
const
1507 return m_config->undoSteps();
1510 void KateDocument::setUndoSteps(uint steps)
1512 m_config->setUndoSteps (steps);
1515 void KateDocument::undo()
1518 if ((undoItems.count() > 0) && undoItems.last())
1522 undoItems.last()->undo();
1523 redoItems.append (undoItems.last());
1524 undoItems.removeLast ();
1527 emit undoChanged ();
1532 void KateDocument::redo()
1535 if ((redoItems.count() > 0) && redoItems.last())
1539 redoItems.last()->redo();
1540 undoItems.append (redoItems.last());
1541 redoItems.removeLast ();
1544 emit undoChanged ();
1549 void KateDocument::updateModified()
1574 unsigned char currentPattern = 0;
1575 const unsigned char patterns[] = {5,16,24,26,88,90,93,133,144,149,165};
1576 const unsigned char patternCount =
sizeof(patterns);
1580 if (undoItems.isEmpty())
1582 currentPattern |= 1;
1586 undoLast = undoItems.last();
1589 if (redoItems.isEmpty())
1591 currentPattern |= 2;
1595 redoLast = redoItems.last();
1598 if (docWasSavedWhenUndoWasEmpty) currentPattern |= 4;
1599 if (docWasSavedWhenRedoWasEmpty) currentPattern |= 8;
1600 if (lastUndoGroupWhenSaved == undoLast) currentPattern |= 16;
1601 if (lastUndoGroupWhenSaved == redoLast) currentPattern |= 32;
1602 if (lastRedoGroupWhenSaved == undoLast) currentPattern |= 64;
1603 if (lastRedoGroupWhenSaved == redoLast) currentPattern |= 128;
1608 <<
"Pattern:" <<
static_cast<unsigned int>(currentPattern) <<
endl;
1610 for (uint patternIndex = 0; patternIndex < patternCount; ++patternIndex)
1612 if ( currentPattern == patterns[patternIndex] )
1614 setModified(
false );
1615 kdDebug(13020) << k_funcinfo <<
"setting modified to false!" <<
endl;
1621 void KateDocument::clearUndo()
1623 undoItems.setAutoDelete (
true);
1625 undoItems.setAutoDelete (
false);
1627 lastUndoGroupWhenSaved = 0;
1628 docWasSavedWhenUndoWasEmpty =
false;
1630 emit undoChanged ();
1633 void KateDocument::clearRedo()
1635 redoItems.setAutoDelete (
true);
1637 redoItems.setAutoDelete (
false);
1639 lastRedoGroupWhenSaved = 0;
1640 docWasSavedWhenRedoWasEmpty =
false;
1642 emit undoChanged ();
1645 TQPtrList<KTextEditor::Cursor> KateDocument::cursors ()
const
1653 bool KateDocument::searchText (
unsigned int startLine,
unsigned int startCol,
const TQString &text,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
unsigned int *matchLen,
bool casesensitive,
bool backwards)
1658 int line = startLine;
1663 int searchEnd = lastLine();
1665 while (line <= searchEnd)
1672 uint foundAt, myMatchLen;
1673 bool found = textLine->searchText (col, text, &foundAt, &myMatchLen, casesensitive,
false);
1677 (*foundAtLine) = line;
1678 (*foundAtCol) = foundAt;
1679 (*matchLen) = myMatchLen;
1692 while (line >= searchEnd)
1699 uint foundAt, myMatchLen;
1700 bool found = textLine->searchText (col, text, &foundAt, &myMatchLen, casesensitive,
true);
1719 (*foundAtLine) = line;
1720 (*foundAtCol) = foundAt;
1721 (*matchLen) = myMatchLen;
1726 col = lineLength(line-1);
1735 bool KateDocument::searchText (
unsigned int startLine,
unsigned int startCol,
const TQRegExp ®exp,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
unsigned int *matchLen,
bool backwards)
1737 kdDebug(13020)<<
"KateDocument::searchText( "<<startLine<<
", "<<startCol<<
", "<<TQString(regexp.pattern())<<
", "<<backwards<<
" )"<<
endl;
1738 if (regexp.isEmpty() || !regexp.isValid())
1741 int line = startLine;
1746 int searchEnd = lastLine();
1748 while (line <= searchEnd)
1755 uint foundAt, myMatchLen;
1756 bool found = textLine->searchText (col, regexp, &foundAt, &myMatchLen,
false);
1762 if (myMatchLen == 0 && (uint) line == startLine && foundAt == (uint) col)
1764 if (col < lineLength(line))
1773 (*foundAtLine) = line;
1774 (*foundAtCol) = foundAt;
1775 (*matchLen) = myMatchLen;
1788 while (line >= searchEnd)
1795 uint foundAt, myMatchLen;
1796 bool found = textLine->searchText (col, regexp, &foundAt, &myMatchLen,
true);
1815 (*foundAtLine) = line;
1816 (*foundAtCol) = foundAt;
1817 (*matchLen) = myMatchLen;
1822 col = lineLength(line-1);
1834 uint KateDocument::hlMode ()
1836 return KateHlManager::self()->findHl(highlight());
1839 bool KateDocument::setHlMode (uint mode)
1841 m_buffer->setHighlight (mode);
1845 setDontChangeHlOnSave();
1852 void KateDocument::bufferHlChanged ()
1860 uint KateDocument::hlModeCount ()
1862 return KateHlManager::self()->highlights();
1865 TQString KateDocument::hlModeName (uint mode)
1867 return KateHlManager::self()->hlName (mode);
1870 TQString KateDocument::hlModeSectionName (uint mode)
1872 return KateHlManager::self()->hlSection (mode);
1875 void KateDocument::setDontChangeHlOnSave()
1882 void KateDocument::readConfig(
TDEConfig *config)
1884 config->
setGroup(
"Kate Document Defaults");
1889 KateDocumentConfig::global()->readConfig (config);
1891 config->
setGroup(
"Kate View Defaults");
1892 KateViewConfig::global()->readConfig (config);
1894 config->
setGroup(
"Kate Renderer Defaults");
1895 KateRendererConfig::global()->readConfig (config);
1898 void KateDocument::writeConfig(
TDEConfig *config)
1900 config->
setGroup(
"Kate Document Defaults");
1905 KateDocumentConfig::global()->writeConfig (config);
1907 config->
setGroup(
"Kate View Defaults");
1908 KateViewConfig::global()->writeConfig (config);
1910 config->
setGroup(
"Kate Renderer Defaults");
1911 KateRendererConfig::global()->writeConfig (config);
1914 void KateDocument::readConfig()
1917 readConfig (config);
1920 void KateDocument::writeConfig()
1923 writeConfig (config);
1927 void KateDocument::readSessionConfig(
TDEConfig *tdeconfig)
1933 TQString tmpenc=tdeconfig->
readEntry(
"Encoding");
1934 if (!tmpenc.isEmpty() && (tmpenc != encoding()))
1935 setEncoding(tmpenc);
1938 if (!url.isEmpty() && url.isValid())
1942 m_buffer->setHighlight(KateHlManager::self()->nameFind(tdeconfig->
readEntry(
"Highlighting")));
1948 config()->setIndentationMode( (uint)tdeconfig->
readNumEntry(
"Indentation Mode", config()->indentationMode() ) );
1952 for( uint i = 0; i < marks.count(); i++ )
1953 addMark( marks[i], KateDocument::markType01 );
1956 void KateDocument::writeSessionConfig(
TDEConfig *tdeconfig)
1961 tdeconfig->
writeEntry(
"URL", m_url.prettyURL() );
1964 tdeconfig->
writeEntry(
"Encoding",encoding());
1969 tdeconfig->
writeEntry(
"Indentation Mode", config()->indentationMode() );
1972 TQValueList<int> marks;
1973 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks );
1974 it.current() && it.current()->type & KTextEditor::MarkInterface::markType01;
1976 marks << it.current()->line;
1981 void KateDocument::configDialog()
1987 kapp->mainWidget() );
1993 TQPtrList<KTextEditor::ConfigPage> editorPages;
1995 for (uint i = 0; i < KTextEditor::configInterfaceExtension (
this)->configPages (); i++)
1999 path << KTextEditor::configInterfaceExtension (
this)->configPageName (i);
2000 TQVBox *page = kd->
addVBoxPage(path, KTextEditor::configInterfaceExtension (
this)->configPageFullName (i),
2003 editorPages.append (KTextEditor::configInterfaceExtension (
this)->configPage(i, page));
2008 KateDocumentConfig::global()->configStart ();
2009 KateViewConfig::global()->configStart ();
2010 KateRendererConfig::global()->configStart ();
2012 for (uint i=0; i<editorPages.count(); i++)
2014 editorPages.at(i)->apply();
2017 KateDocumentConfig::global()->configEnd ();
2018 KateViewConfig::global()->configEnd ();
2019 KateRendererConfig::global()->configEnd ();
2027 uint KateDocument::mark( uint line )
2029 if( !m_marks[line] )
2031 return m_marks[line]->type;
2034 void KateDocument::setMark( uint line, uint markType )
2037 addMark( line, markType );
2040 void KateDocument::clearMark( uint line )
2042 if( line > lastLine() )
2045 if( !m_marks[line] )
2048 KTextEditor::Mark* mark = m_marks.take( line );
2049 emit markChanged( *mark, MarkRemoved );
2050 emit marksChanged();
2052 tagLines( line, line );
2056 void KateDocument::addMark( uint line, uint markType )
2058 if( line > lastLine())
2064 if( m_marks[line] ) {
2065 KTextEditor::Mark* mark = m_marks[line];
2068 markType &= ~mark->type;
2074 mark->type |= markType;
2076 KTextEditor::Mark *mark =
new KTextEditor::Mark;
2078 mark->type = markType;
2079 m_marks.insert( line, mark );
2083 KTextEditor::Mark temp;
2085 temp.type = markType;
2086 emit markChanged( temp, MarkAdded );
2088 emit marksChanged();
2089 tagLines( line, line );
2093 void KateDocument::removeMark( uint line, uint markType )
2095 if( line > lastLine() )
2097 if( !m_marks[line] )
2100 KTextEditor::Mark* mark = m_marks[line];
2103 markType &= mark->type;
2109 mark->type &= ~markType;
2112 KTextEditor::Mark temp;
2114 temp.type = markType;
2115 emit markChanged( temp, MarkRemoved );
2117 if( mark->type == 0 )
2118 m_marks.remove( line );
2120 emit marksChanged();
2121 tagLines( line, line );
2125 TQPtrList<KTextEditor::Mark> KateDocument::marks()
2127 TQPtrList<KTextEditor::Mark> list;
2129 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks );
2130 it.current(); ++it ) {
2131 list.append( it.current() );
2137 void KateDocument::clearMarks()
2139 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks );
2140 it.current(); ++it ) {
2141 KTextEditor::Mark* mark = it.current();
2142 emit markChanged( *mark, MarkRemoved );
2143 tagLines( mark->line, mark->line );
2148 emit marksChanged();
2152 void KateDocument::setPixmap( MarkInterface::MarkTypes type,
const TQPixmap& pixmap )
2154 m_markPixmaps.replace( type,
new TQPixmap( pixmap ) );
2157 void KateDocument::setDescription( MarkInterface::MarkTypes type,
const TQString& description )
2159 m_markDescriptions.replace( type,
new TQString( description ) );
2162 TQPixmap *KateDocument::markPixmap( MarkInterface::MarkTypes type )
2164 return m_markPixmaps[type];
2167 TQColor KateDocument::markColor( MarkInterface::MarkTypes type )
2169 uint reserved = (0x1 << KTextEditor::MarkInterface::reservedMarkersCount()) - 1;
2170 if ((uint)type >= (uint)markType01 && (uint)type <= reserved) {
2171 return KateRendererConfig::global()->lineMarkerColor(type);
2177 TQString KateDocument::markDescription( MarkInterface::MarkTypes type )
2179 if( m_markDescriptions[type] )
2180 return *m_markDescriptions[type];
2181 return TQString::null;
2184 void KateDocument::setMarksUserChangable( uint markMask )
2186 m_editableMarks = markMask;
2189 uint KateDocument::editableMarks()
2191 return m_editableMarks;
2196 bool KateDocument::printDialog ()
2198 return KatePrinter::print (
this);
2201 bool KateDocument::print ()
2203 return KatePrinter::print (
this);
2208 TQString KateDocument::mimeType()
2210 KMimeType::Ptr result = KMimeType::defaultMimeTypePtr();
2213 if ( ! m_url.isEmpty() )
2214 result = KMimeType::findByURL( m_url );
2216 else if ( m_url.isEmpty() || ! m_url.isLocalFile() )
2217 result = mimeTypeForContent();
2219 return result->name();
2223 long KateDocument::fileSize()
2229 TQString KateDocument::niceFileSize()
2234 KMimeType::Ptr KateDocument::mimeTypeForContent()
2236 TQByteArray buf (1024);
2239 for (uint i=0; i < numLines(); i++)
2241 TQString line = textLine( i );
2242 uint len = line.length() + 1;
2244 if (bufpos + len > 1024)
2245 len = 1024 - bufpos;
2247 memcpy(&buf[bufpos], (line +
"\n").latin1(), len);
2254 buf.resize( bufpos );
2257 return KMimeType::findByContent( buf, &accuracy );
2264 bool KateDocument::openURL(
const KURL &url )
2278 if ( m_url.isLocalFile() )
2282 m_file = m_url.
path();
2289 emit setWindowCaption( m_url.prettyURL() );
2303 m_file = m_tempFile->name();
2305 m_job = TDEIO::get ( url,
false, isProgressInfoEnabled() );
2308 connect( m_job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
2309 TQ_SLOT( slotDataKate( TDEIO::Job*,
const TQByteArray& ) ) );
2311 connect( m_job, TQ_SIGNAL( result( TDEIO::Job* ) ),
2312 TQ_SLOT( slotFinishedKate( TDEIO::Job* ) ) );
2314 TQWidget *w = widget ();
2315 if (!w && !m_views.isEmpty ())
2316 w = m_views.first();
2319 m_job->setWindow (w->topLevelWidget());
2321 emit started( m_job );
2327 void KateDocument::slotDataKate ( TDEIO::Job *,
const TQByteArray &data )
2331 if (!m_tempFile || !m_tempFile->file())
2334 m_tempFile->file()->writeBlock (data);
2337 void KateDocument::slotFinishedKate ( TDEIO::Job * job )
2349 emit canceled( job->errorString() );
2352 if ( openFile(job) )
2353 emit setWindowCaption( m_url.prettyURL() );
2358 void KateDocument::abortLoadKate()
2362 kdDebug(13020) <<
"Aborting job " << m_job <<
endl;
2371 bool KateDocument::openFile()
2373 return openFile (0);
2376 bool KateDocument::openFile(TDEIO::Job * job)
2380 activateDirWatch ();
2387 TQString metaDataCharset = job->queryMetaData(
"charset");
2390 if (!metaDataCharset.isEmpty () && (!m_config->isSetEncoding() || m_config->encoding().isEmpty()))
2391 setEncoding (metaDataCharset);
2397 TQString serviceType = m_extension->urlArgs().serviceType.simplifyWhiteSpace();
2398 int pos = serviceType.find(
';');
2400 setEncoding (serviceType.mid(pos+1));
2404 bool encodingSticky = m_encodingSticky;
2405 m_encodingSticky = m_config->isSetEncoding();
2408 int fileTypeFound = KateFactory::self()->fileTypeManager()->fileType (
this);
2409 if ( fileTypeFound > -1 )
2410 updateFileType( fileTypeFound );
2417 bool success = m_buffer->openFile (m_file);
2432 int hl (KateHlManager::self()->detectHighlighting (
this));
2435 m_buffer->setHighlight(hl);
2439 if ( fileTypeFound < 0 )
2440 updateFileType (KateFactory::self()->fileTypeManager()->fileType (
this));
2446 createDigest( m_digest );
2452 for (KateView * view = m_views.first(); view != 0L; view = m_views.next() )
2454 view->updateView(
true);
2460 emit fileNameChanged ();
2465 setDocName (TQString::null);
2473 m_modOnHdReason = 0;
2474 emit modifiedOnDisc (
this, m_modOnHd, 0);
2480 if (s_openErrorDialogsActivated)
2482 if (!success && m_buffer->loadingBorked())
2483 KMessageBox::error (widget(), i18n (
"The file %1 could not be loaded completely, as there is not enough temporary disk storage for it.").arg(m_url.url()));
2485 KMessageBox::error (widget(), 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.").arg(m_url.url()));
2489 if (m_buffer->binary())
2492 setReadWrite(
false );
2495 , i18n (
"The file %1 is a binary, saving it will result in a corrupt file.").arg(m_url.url())
2496 , i18n (
"Binary File Opened")
2497 ,
"Binary File Opened Warning");
2500 m_encodingSticky = encodingSticky;
2508 bool KateDocument::save()
2510 bool l ( url().isLocalFile() );
2512 if ( ( l && config()->backupFlags() & KateDocumentConfig::LocalFiles )
2513 || ( ! l && config()->backupFlags() & KateDocumentConfig::RemoteFiles ) )
2516 u.setFileName( config()->backupPrefix() + url().fileName() + config()->backupSuffix() );
2518 kdDebug () <<
"backup src file name: " << url() <<
endl;
2519 kdDebug () <<
"backup dst file name: " << u <<
endl;
2522 mode_t perms = 0600;
2523 TDEIO::UDSEntry fentry;
2524 if (TDEIO::NetAccess::stat (url(), fentry, kapp->mainWidget()))
2526 kdDebug () <<
"stating succesfull: " << url() <<
endl;
2527 KFileItem item (fentry, url());
2528 perms = item.permissions();
2533 if ( (!TDEIO::NetAccess::exists( u,
false, kapp->mainWidget() ) || TDEIO::NetAccess::del( u, kapp->mainWidget() ))
2534 && TDEIO::NetAccess::file_copy( url(), u, perms,
true,
false, kapp->mainWidget() ) )
2536 kdDebug(13020)<<
"backing up successfull ("<<url().
prettyURL()<<
" -> "<<u.prettyURL()<<
")"<<
endl;
2548 bool KateDocument::saveFile()
2554 i18n(
"This file could not be loaded correctly due to lack of temporary disk space. Saving it could cause data loss.\n\nDo you really want to save it?"),i18n(
"Possible Data Loss"),i18n(
"Save Nevertheless")) != KMessageBox::Continue))
2561 , i18n (
"The file %1 is a binary, saving it will result in a corrupt file.").arg(m_url.url())
2562 , i18n (
"Trying to Save Binary File")
2563 , i18n(
"Save Nevertheless"),
"Binary File Save Warning") != KMessageBox::Continue))
2566 if ( !url().isEmpty() )
2568 if (s_fileChangedDialogsActivated && m_modOnHd)
2570 TQString str = reasonedMOHString() +
"\n\n";
2575 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"),i18n(
"Save Nevertheless")) != KMessageBox::Continue)
2581 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"),i18n(
"Save Nevertheless")) != KMessageBox::Continue)
2590 if (!m_buffer->canEncode ()
2592 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"),i18n(
"Save Nevertheless")) != KMessageBox::Continue))
2598 deactivateDirWatch ();
2603 bool success = m_buffer->saveFile (m_file);
2606 createDigest( m_digest );
2609 activateDirWatch ();
2619 int hl (KateHlManager::self()->detectHighlighting (
this));
2622 m_buffer->setHighlight(hl);
2632 if (success && m_modOnHd)
2635 m_modOnHdReason = 0;
2636 emit modifiedOnDisc (
this, m_modOnHd, 0);
2643 KMessageBox::error (widget(), 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.").arg(m_url.url()));
2651 bool KateDocument::saveAs(
const KURL &u )
2658 setDocName( TQString::null );
2663 emit fileNameChanged();
2672 void KateDocument::readDirConfig ()
2674 int depth = config()->searchDirConfigDepth ();
2676 if (m_url.isLocalFile() && (depth > -1))
2678 TQString currentDir = TQFileInfo (m_file).dirPath();
2683 kdDebug (13020) <<
"search for config file in path: " << currentDir <<
endl;
2686 TQFile f (currentDir +
"/.kateconfig");
2688 if (f.open (IO_ReadOnly))
2690 TQTextStream stream (&f);
2693 TQString line = stream.readLine();
2694 while ((linesRead < 32) && !line.isNull())
2696 readVariableLine( line );
2698 line = stream.readLine();
2706 TQString newDir = TQFileInfo (currentDir).dirPath();
2709 if (currentDir == newDir)
2712 currentDir = newDir;
2718 void KateDocument::activateDirWatch ()
2721 if (m_file == m_dirWatchFile)
2725 deactivateDirWatch ();
2728 if (m_url.isLocalFile() && !m_file.isEmpty())
2730 KateFactory::self()->dirWatch ()->addFile (m_file);
2731 m_dirWatchFile = m_file;
2735 void KateDocument::deactivateDirWatch ()
2737 if (!m_dirWatchFile.isEmpty())
2738 KateFactory::self()->dirWatch ()->removeFile (m_dirWatchFile);
2740 m_dirWatchFile = TQString::null;
2743 bool KateDocument::closeURL()
2750 if ( !m_reloading && !url().isEmpty() )
2752 if (s_fileChangedDialogsActivated && m_modOnHd)
2756 reasonedMOHString() +
"\n\n" + i18n(
"Do you really want to continue to close this file? Data loss may occur."),
2757 i18n(
"Possible Data Loss"), i18n(
"Close Nevertheless"),
2758 TQString(
"kate_close_modonhd_%1").arg( m_modOnHdReason ) ) == KMessageBox::Continue))
2770 deactivateDirWatch ();
2776 m_file = TQString::null;
2782 m_modOnHdReason = 0;
2783 emit modifiedOnDisc (
this, m_modOnHd, 0);
2800 m_buffer->setHighlight(0);
2803 for (KateView * view = m_views.first(); view != 0L; view = m_views.next() )
2807 view->setCursorPositionInternal(0, 0, 1,
false);
2808 view->clearSelection();
2809 view->updateView(
true);
2813 emit fileNameChanged ();
2816 setDocName (TQString::null);
2822 void KateDocument::setReadWrite(
bool rw )
2824 if (isReadWrite() != rw)
2828 for( KateView* view = m_views.first(); view != 0L; view = m_views.next() )
2831 view->slotReadWriteChanged ();
2836 void KateDocument::setModified(
bool m) {
2838 if (isModified() != m) {
2841 for( KateView* view = m_views.first(); view != 0L; view = m_views.next() )
2846 emit modifiedChanged ();
2851 if ( ! undoItems.isEmpty() )
2853 lastUndoGroupWhenSaved = undoItems.last();
2856 if ( ! redoItems.isEmpty() )
2858 lastRedoGroupWhenSaved = redoItems.last();
2861 docWasSavedWhenUndoWasEmpty = undoItems.isEmpty();
2862 docWasSavedWhenRedoWasEmpty = redoItems.isEmpty();
2869 void KateDocument::makeAttribs(
bool needInvalidate)
2871 for (uint z = 0; z < m_views.count(); z++)
2872 m_views.at(z)->renderer()->updateAttributes ();
2875 m_buffer->invalidateHighlighting();
2881 void KateDocument::internalHlChanged()
2886 void KateDocument::addView(KTextEditor::View *view) {
2890 m_views.append( (KateView *) view );
2891 m_textEditViews.append( view );
2894 const KateFileType *t = 0;
2895 if ((m_fileType > -1) && (t = KateFactory::self()->fileTypeManager()->fileType(m_fileType)))
2896 readVariableLine (t->varLine,
true);
2899 readVariables (
true);
2901 m_activeView = (KateView *) view;
2904 void KateDocument::removeView(KTextEditor::View *view) {
2908 if (m_activeView == view)
2911 m_views.removeRef( (KateView *) view );
2912 m_textEditViews.removeRef( view );
2915 void KateDocument::addSuperCursor(
KateSuperCursor *cursor,
bool privateC) {
2919 m_superCursors.append( cursor );
2922 myCursors.append( cursor );
2925 void KateDocument::removeSuperCursor(
KateSuperCursor *cursor,
bool privateC) {
2930 myCursors.removeRef( cursor );
2932 m_superCursors.removeRef( cursor );
2935 bool KateDocument::ownedView(KateView *view) {
2937 return (m_views.containsRef(view) > 0);
2940 bool KateDocument::isLastView(
int numViews) {
2941 return ((
int) m_views.count() == numViews);
2949 return textLine->cursorX(cursor.col(), config()->tabWidth());
2954 bool KateDocument::typeChars ( KateView *view,
const TQString &chars )
2961 bool bracketInserted =
false;
2965 for( uint z = 0; z < chars.length(); z++ )
2967 TQChar ch = c = chars[z];
2968 if (ch.isPrint() || ch ==
'\t')
2972 if (!bracketInserted && (config()->configFlags() & KateDocument::cfAutoBrackets))
2975 bool complete =
true;
2976 TQChar prevChar = textLine->getChar(view->cursorColumnReal()-1);
2977 TQChar nextChar = textLine->getChar(view->cursorColumnReal());
2979 case '(': end_ch =
')';
break;
2980 case '[': end_ch =
']';
break;
2981 case '{': end_ch =
'}';
break;
2982 case '\'':end_ch =
'\'';
break;
2983 case '"': end_ch =
'"';
break;
2984 default: complete =
false;
2988 if (view->hasSelection())
2990 buf.append (view->selection());
2991 buf.append (end_ch);
2992 bracketInserted =
true;
2996 if ( ( (ch ==
'\'' || ch ==
'"') &&
2997 (prevChar.isLetterOrNumber() || prevChar == ch) )
2998 || nextChar.isLetterOrNumber()
2999 || (nextChar == end_ch && prevChar != ch) )
3001 kdDebug(13020) <<
"AutoBracket refused before: " << nextChar <<
"\n";
3005 buf.append (end_ch);
3006 bracketInserted =
true;
3019 if (!view->config()->persistentSelection() && view->hasSelection() )
3020 view->removeSelectedText();
3022 int oldLine = view->cursorLine ();
3023 int oldCol = view->cursorColumnReal ();
3026 if (config()->configFlags() & KateDocument::cfOvr)
3027 removeText (view->cursorLine(), view->cursorColumnReal(), view->cursorLine(), kMin( view->cursorColumnReal()+buf.length(), textLine->length() ) );
3029 insertText (view->cursorLine(), view->cursorColumnReal(), buf);
3030 m_indenter->processChar(c);
3034 if (bracketInserted)
3035 view->setCursorPositionInternal (view->cursorLine(), view->cursorColumnReal()-1);
3037 emit charactersInteractivelyInserted (oldLine, oldCol, chars);
3042 void KateDocument::newLine(
KateTextCursor& c, KateViewInternal *v )
3046 if( !v->view()->config()->persistentSelection() && v->view()->hasSelection() )
3047 v->view()->removeSelectedText();
3050 c = v->getCursor ();
3052 if (c.line() > (
int)lastLine())
3053 c.setLine(lastLine());
3062 if (c.col() > (
int)textLine->length())
3063 c.setCol(textLine->length());
3065 if (m_indenter->canProcessNewLine ())
3067 int pos = textLine->firstChar();
3071 pos = textLine->length();
3076 editWrapLine (c.line(), c.col());
3079 m_indenter->processNewline(cursor,
true);
3085 editWrapLine (c.line(), c.col());
3086 c.setPos(c.line() + 1, 0);
3089 removeTrailingSpace( ln );
3098 if (!textLine || (textLine->length() < 2))
3101 uint col = cursor.col();
3106 if ((textLine->length() - col) < 2)
3109 uint line = cursor.line();
3114 s.append (textLine->getChar(col+1));
3115 s.append (textLine->getChar(col));
3120 editRemoveText (line, col, 2);
3121 editInsertText (line, col, s);
3125 void KateDocument::backspace( KateView *view,
const KateTextCursor& c )
3127 if ( !view->config()->persistentSelection() && view->hasSelection() ) {
3128 view->removeSelectedText();
3132 uint col = kMax( c.col(), 0 );
3133 uint line = kMax( c.line(), 0 );
3135 if ((col == 0) && (line == 0))
3141 if (config()->configFlags() & KateDocument::cfAutoBrackets)
3146 TQChar prevChar = tl->getChar(col-1);
3147 TQChar nextChar = tl->getChar(col);
3149 if ( (prevChar ==
'"' && nextChar ==
'"') ||
3150 (prevChar ==
'\'' && nextChar ==
'\'') ||
3151 (prevChar ==
'(' && nextChar ==
')') ||
3152 (prevChar ==
'[' && nextChar ==
']') ||
3153 (prevChar ==
'{' && nextChar ==
'}') )
3158 if (!(config()->configFlags() & KateDocument::cfBackspaceIndents))
3162 removeText(line, col-1, line, col+complement);
3173 int colX = textLine->cursorX(col, config()->tabWidth());
3174 int pos = textLine->firstChar();
3176 pos = textLine->cursorX(pos, config()->tabWidth());
3178 if (pos < 0 || pos >= (
int)colX)
3181 indent( view, line, -1);
3184 removeText(line, col-1, line, col+complement);
3198 if (config()->wordWrap() && textLine->endingWith(TQString::fromLatin1(
" ")))
3201 removeText (line-1, textLine->length()-1, line, 0);
3204 removeText (line-1, textLine->length(), line, 0);
3208 emit backspacePressed();
3211 void KateDocument::del( KateView *view,
const KateTextCursor& c )
3213 if ( !view->config()->persistentSelection() && view->hasSelection() ) {
3214 view->removeSelectedText();
3218 if( c.col() < (
int) m_buffer->plainLine(c.line())->length())
3220 removeText(c.line(), c.col(), c.line(), c.col()+1);
3222 else if ( (uint)c.line() < lastLine() )
3224 removeText(c.line(), c.col(), c.line()+1, 0);
3228 void KateDocument::paste ( KateView* view )
3230 TQString s = TQApplication::clipboard()->text();
3235 uint lines = s.contains (TQChar (
'\n'));
3237 m_undoDontMerge =
true;
3241 if (!view->config()->persistentSelection() && view->hasSelection() )
3242 view->removeSelectedText();
3244 uint line = view->cursorLine ();
3245 uint column = view->cursorColumnReal ();
3247 insertText ( line, column, s, view->blockSelectionMode() );
3254 if (view->blockSelectionMode())
3255 view->setCursorPositionInternal (line+lines, column);
3257 if (m_indenter->canProcessLine()
3258 && config()->configFlags() & KateDocumentConfig::cfIndentPastedText)
3265 m_indenter->processSection (begin, end);
3270 if (!view->blockSelectionMode()) emit charactersSemiInteractivelyInserted (line, column, s);
3271 m_undoDontMerge =
true;
3274 void KateDocument::insertIndentChars ( KateView *view )
3279 if (config()->configFlags() & KateDocument::cfSpaceIndent)
3281 int width = config()->indentationWidth();
3282 s.fill (
' ', width - (view->cursorColumnReal() % width));
3287 insertText (view->cursorLine(), view->cursorColumnReal(), s);
3292 void KateDocument::indent ( KateView *v, uint line,
int change)
3296 if (!hasSelection())
3299 optimizeLeadingSpace(line, config()->configFlags(), change);
3303 int sl = v->selStartLine();
3304 int el = v->selEndLine();
3305 int ec = v->selEndCol();
3307 if ((ec == 0) && ((el-1) >= 0))
3312 if (config()->configFlags() & KateDocument::cfKeepIndentProfile && change < 0) {
3315 int adjustedChange = -change;
3317 for (line = sl; (int) line <= el && adjustedChange > 0; line++) {
3319 int firstChar = textLine->firstChar();
3320 if (firstChar >= 0 && (v->lineSelected(line) || v->lineHasSelected(line))) {
3321 int maxUnindent = textLine->cursorX(firstChar, config()->tabWidth()) / config()->indentationWidth();
3322 if (maxUnindent < adjustedChange)
3323 adjustedChange = maxUnindent;
3327 change = -adjustedChange;
3330 const bool rts = config()->configFlags() & KateDocumentConfig::cfRemoveTrailingDyn;
3331 for (line = sl; (int) line <= el; line++) {
3332 if ((v->lineSelected(line) || v->lineHasSelected(line))
3333 && (!rts || lineLength(line) > 0)) {
3334 optimizeLeadingSpace(line, config()->configFlags(), change);
3342 void KateDocument::align(KateView *view, uint line)
3344 if (m_indenter->canProcessLine())
3348 if (!view->hasSelection())
3351 m_indenter->processLine (curLine);
3353 activeView()->setCursorPosition (line, curLine.col());
3357 m_indenter->processSection (view->selStart(), view->selEnd());
3372 void KateDocument::optimizeLeadingSpace(uint line,
int flags,
int change)
3376 int first_char = textline->firstChar();
3379 if (flags & KateDocument::cfSpaceIndent)
3380 w = config()->indentationWidth();
3382 w = config()->tabWidth();
3385 first_char = textline->length();
3387 int space = textline->cursorX(first_char, config()->tabWidth()) + change * w;
3391 if (!(flags & KateDocument::cfKeepExtraSpaces))
3393 uint extra = space % w;
3396 if (extra && change < 0) {
3403 replaceWithOptimizedSpace(line, first_char, space, flags);
3406 void KateDocument::replaceWithOptimizedSpace(uint line, uint upto_column, uint space,
int flags)
3411 if (flags & KateDocument::cfSpaceIndent && ! (flags & KateDocumentConfig::cfMixedIndent) ) {
3413 new_space.fill(
' ', length);
3416 length = space / config()->tabWidth();
3417 new_space.fill(
'\t', length);
3419 TQString extra_space;
3420 extra_space.fill(
' ', space % config()->tabWidth());
3421 length += space % config()->tabWidth();
3422 new_space += extra_space;
3427 for (change_from = 0; change_from < upto_column && change_from < length; change_from++) {
3428 if (textline->getChar(change_from) != new_space[change_from])
3434 if (change_from < upto_column)
3435 removeText(line, change_from, line, upto_column);
3437 if (change_from < length)
3438 insertText(line, change_from, new_space.right(length - change_from));
3447 bool KateDocument::removeStringFromBegining(
int line, TQString &str)
3454 if (textline->startingWith(str))
3458 index = textline->firstChar ();
3460 if ((index >= 0) && (textline->length() >= (index + str.length())) && (textline->string(index, str.length()) == str))
3467 removeText (line, index, line, index+str.length());
3477 bool KateDocument::removeStringFromEnd(
int line, TQString &str)
3484 if(textline->endingWith(str))
3486 index = textline->length() - str.length();
3491 index = textline->lastChar ()-str.length()+1;
3493 if ((index >= 0) && (textline->length() >= (index + str.length())) && (textline->string(index, str.length()) == str))
3500 removeText (line, index, line, index+str.length());
3510 void KateDocument::addStartLineCommentToSingleLine(
int line,
int attrib )
3512 if (highlight()->getCommentSingleLinePosition(attrib)==KateHighlighting::CSLPosColumn0)
3514 TQString commentLineMark = highlight()->getCommentSingleLineStart( attrib ) +
" ";
3515 insertText (line, 0, commentLineMark);
3519 TQString commentLineMark=highlight()->getCommentSingleLineStart(attrib);
3521 int pos=l->firstChar();
3523 insertText(line,pos,commentLineMark);
3531 bool KateDocument::removeStartLineCommentFromSingleLine(
int line,
int attrib )
3533 TQString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3534 TQString longCommentMark = shortCommentMark +
" ";
3539 bool removed = (removeStringFromBegining(line, longCommentMark)
3540 || removeStringFromBegining(line, shortCommentMark));
3551 void KateDocument::addStartStopCommentToSingleLine(
int line,
int attrib )
3553 TQString startCommentMark = highlight()->getCommentStart( attrib ) +
" ";
3554 TQString stopCommentMark =
" " + highlight()->getCommentEnd( attrib );
3559 insertText (line, 0, startCommentMark);
3562 int col = m_buffer->plainLine(line)->length();
3565 insertText (line, col, stopCommentMark);
3574 bool KateDocument::removeStartStopCommentFromSingleLine(
int line,
int attrib )
3576 TQString shortStartCommentMark = highlight()->getCommentStart( attrib );
3577 TQString longStartCommentMark = shortStartCommentMark +
" ";
3578 TQString shortStopCommentMark = highlight()->getCommentEnd( attrib );
3579 TQString longStopCommentMark =
" " + shortStopCommentMark;
3584 #warning "that's a bad idea, can lead to stray endings, FIXME"
3587 bool removedStart = (removeStringFromBegining(line, longStartCommentMark)
3588 || removeStringFromBegining(line, shortStartCommentMark));
3590 bool removedStop =
false;
3594 removedStop = (removeStringFromEnd(line, longStopCommentMark)
3595 || removeStringFromEnd(line, shortStopCommentMark));
3600 return (removedStart || removedStop);
3608 void KateDocument::addStartStopCommentToSelection( KateView *view,
int attrib )
3610 TQString startComment = highlight()->getCommentStart( attrib );
3611 TQString endComment = highlight()->getCommentEnd( attrib );
3613 int sl = view->selStartLine();
3614 int el = view->selEndLine();
3615 int sc = view->selStartCol();
3616 int ec = view->selEndCol();
3618 if ((ec == 0) && ((el-1) >= 0))
3621 ec = m_buffer->plainLine (el)->length();
3626 insertText (el, ec, endComment);
3627 insertText (sl, sc, startComment);
3632 ec += endComment.length() + ( (el == sl) ? startComment.length() : 0 );
3633 view->setSelection(sl, sc, el, ec);
3640 void KateDocument::addStartLineCommentToSelection( KateView *view,
int attrib )
3642 TQString commentLineMark = highlight()->getCommentSingleLineStart( attrib ) +
" ";
3644 int sl = view->selStartLine();
3645 int el = view->selEndLine();
3647 if ((view->selEndCol() == 0) && ((el-1) >= 0))
3655 for (
int z = el; z >= sl; z--) {
3657 addStartLineCommentToSingleLine(z, attrib );
3665 end.setCol(view->selEndCol() + ((el == view->selEndLine()) ? commentLineMark.length() : 0) );
3667 view->setSelection(view->selStartLine(), 0,
end.line(),
end.col());
3670 bool KateDocument::nextNonSpaceCharPos(
int &line,
int &col)
3672 for(; line < (int)m_buffer->count(); line++) {
3678 col = textLine->nextNonSpaceChar(col);
3689 bool KateDocument::previousNonSpaceCharPos(
int &line,
int &col)
3698 col = textLine->previousNonSpaceChar(col);
3699 if(col != -1)
return true;
3700 if(line == 0)
return false;
3702 col = textLine->length();
3714 bool KateDocument::removeStartStopCommentFromSelection( KateView *view,
int attrib )
3716 TQString startComment = highlight()->getCommentStart( attrib );
3717 TQString endComment = highlight()->getCommentEnd( attrib );
3719 int sl = kMax<int> (0, view->selStartLine());
3720 int el = kMin<int> (view->selEndLine(), lastLine());
3721 int sc = view->selStartCol();
3722 int ec = view->selEndCol();
3730 ec = m_buffer->plainLine(el)->length() - 1;
3734 int startCommentLen = startComment.length();
3735 int endCommentLen = endComment.length();
3739 bool remove = nextNonSpaceCharPos(sl, sc)
3740 && m_buffer->plainLine(sl)->stringAtPos(sc, startComment)
3741 && previousNonSpaceCharPos(el, ec)
3742 && ( (ec - endCommentLen + 1) >= 0 )
3743 && m_buffer->plainLine(el)->stringAtPos(ec - endCommentLen + 1, endComment);
3748 removeText (el, ec - endCommentLen + 1, el, ec + 1);
3749 removeText (sl, sc, sl, sc + startCommentLen);
3760 TQString startComment = highlight()->getCommentStart( attrib );
3761 TQString endComment = highlight()->getCommentEnd( attrib );
3762 int startCommentLen = startComment.length();
3763 int endCommentLen = endComment.length();
3765 bool remove = m_buffer->plainLine(start.line())->stringAtPos(start.col(), startComment)
3766 && ( (
end.col() - endCommentLen ) >= 0 )
3767 && m_buffer->plainLine(
end.line())->stringAtPos(
end.col() - endCommentLen , endComment);
3770 removeText(
end.line(),
end.col()-endCommentLen,
end.line(),
end.col());
3771 removeText(start.line(),start.col(),start.line(),start.col()+startCommentLen);
3781 bool KateDocument::removeStartLineCommentFromSelection( KateView *view,
int attrib )
3783 TQString shortCommentMark = highlight()->getCommentSingleLineStart( attrib );
3784 TQString longCommentMark = shortCommentMark +
" ";
3786 int sl = view->selStartLine();
3787 int el = view->selEndLine();
3789 if ((view->selEndCol() == 0) && ((el-1) >= 0))
3795 int removeLength = 0;
3796 if (m_buffer->plainLine(el)->startingWith(longCommentMark))
3797 removeLength = longCommentMark.length();
3798 else if (m_buffer->plainLine(el)->startingWith(shortCommentMark))
3799 removeLength = shortCommentMark.length();
3801 bool removed =
false;
3806 for (
int z = el; z >= sl; z--)
3809 removed = (removeStringFromBegining(z, longCommentMark)
3810 || removeStringFromBegining(z, shortCommentMark)
3823 void KateDocument::comment( KateView *v, uint line,uint column,
int change)
3829 bool hassel = v->hasSelection();
3830 int startAttrib, endAttrib;
3834 int l = v->selStartLine(), c = v->selStartCol();
3835 startAttrib = nextNonSpaceCharPos( l, c ) ? kateTextLine( l )->attribute( c ) : 0;
3837 ln = kateTextLine( v->selEndLine() );
3838 l = v->selEndLine(), c = v->selEndCol();
3839 endAttrib = previousNonSpaceCharPos( l, c ) ? kateTextLine( l )->attribute( c ) : 0;
3846 startAttrib = ln->attribute( ln->firstChar() );
3847 endAttrib = ln->attribute( ln->lastChar() );
3851 int l = line, c = 0;
3852 if ( nextNonSpaceCharPos( l, c ) || previousNonSpaceCharPos( l, c ) )
3853 startAttrib = endAttrib = kateTextLine( l )->attribute( c );
3855 startAttrib = endAttrib = 0;
3859 if ( ! highlight()->canComment( startAttrib, endAttrib ) )
3861 kdDebug(13020)<<
"canComment( "<<startAttrib<<
", "<<endAttrib<<
" ) returned false!"<<
endl;
3865 bool hasStartLineCommentMark = !(highlight()->getCommentSingleLineStart( startAttrib ).isEmpty());
3866 bool hasStartStopCommentMark = ( !(highlight()->getCommentStart( startAttrib ).isEmpty())
3867 && !(highlight()->getCommentEnd( endAttrib ).isEmpty()) );
3869 bool removed =
false;
3875 if ( hasStartLineCommentMark )
3876 addStartLineCommentToSingleLine( line, startAttrib );
3877 else if ( hasStartStopCommentMark )
3878 addStartStopCommentToSingleLine( line, startAttrib );
3889 if ( hasStartStopCommentMark &&
3890 ( !hasStartLineCommentMark || (
3891 ( v->selStartCol() > m_buffer->plainLine( v->selStartLine() )->firstChar() ) ||
3892 ( v->selEndCol() < ((
int)m_buffer->plainLine( v->selEndLine() )->length()) )
3894 addStartStopCommentToSelection( v, startAttrib );
3895 else if ( hasStartLineCommentMark )
3896 addStartLineCommentToSelection( v, startAttrib );
3903 removed = ( hasStartLineCommentMark
3904 && removeStartLineCommentFromSingleLine( line, startAttrib ) )
3905 || ( hasStartStopCommentMark
3906 && removeStartStopCommentFromSingleLine( line, startAttrib ) );
3907 if ((!removed) && foldingTree()) {
3908 kdDebug(13020)<<
"easy approach for uncommenting did not work, trying harder (folding tree)"<<
endl;
3909 int commentRegion=(highlight()->commentRegion(startAttrib));
3911 KateCodeFoldingNode *n=foldingTree()->findNodeForPosition(line,column);
3914 if ((n->nodeType()==commentRegion) && n->getBegin(foldingTree(), &start) && n->getEnd(foldingTree(), &end)) {
3915 kdDebug(13020)<<
"Enclosing region found:"<<start.col()<<
"/"<<start.line()<<
"-"<<
end.col()<<
"/"<<
end.line()<<
endl;
3916 removeStartStopCommentFromRegion(start,end,startAttrib);
3918 kdDebug(13020)<<
"Enclosing region found, but not valid"<<
endl;
3919 kdDebug(13020)<<
"Region found: "<<n->nodeType()<<
" region needed: "<<commentRegion<<
endl;
3922 }
else kdDebug(13020)<<
"No enclosing region found"<<
endl;
3923 }
else kdDebug(13020)<<
"No comment region specified for current hl"<<
endl;
3929 removed = ( hasStartLineCommentMark
3930 && removeStartLineCommentFromSelection( v, startAttrib ) )
3931 || ( hasStartStopCommentMark
3932 && removeStartStopCommentFromSelection( v, startAttrib ) );
3937 void KateDocument::transform( KateView *v,
const KateTextCursor &c,
3938 KateDocument::TextTransform t )
3941 uint cl( c.line() ), cc( c.col() );
3942 bool selectionRestored =
false;
3944 if ( hasSelection() )
3950 int ln = v->selStartLine();
3951 while ( ln <= selend.line() )
3954 start = (ln == selstart.line() || v->blockSelectionMode()) ?
3956 end = (ln == selend.line() || v->blockSelectionMode()) ?
3957 selend.col() : lineLength( ln );
3964 TQString s = text( ln, start, ln, end );
3967 if ( t == Uppercase )
3969 else if ( t == Lowercase )
3975 while( p < s.length() )
3981 if ( ( ! start && ! p ) ||
3982 ( ( ln == selstart.line() || v->blockSelectionMode() ) &&
3983 ! p && ! highlight()->isInWord( l->getChar( start - 1 )) ) ||
3984 ( p && ! highlight()->isInWord( s.at( p-1 ) ) )
3986 s[p] = s.at(p).upper();
3993 removeText( ln, start, ln, end );
3994 insertText( ln, start, s );
4001 v->setSelection( selstart, selend );
4002 selectionRestored =
true;
4005 TQString o = text( cl, cc, cl, cc + 1 );
4018 while ( n > 0 && highlight()->isInWord( l->getChar( n-1 ), l->attribute( n-1 ) ) )
4020 o = text( cl, n, cl, n + 1 );
4030 removeText( cl, n, cl, n+1 );
4031 insertText( cl, n, s );
4036 if ( ! selectionRestored )
4037 v->setCursorPosition( cl, cc );
4040 void KateDocument::joinLines( uint first, uint last )
4045 while ( first < last )
4061 int pos = tl->firstChar();
4065 editRemoveText( line + 1, 0, pos );
4066 if ( !( l->length() == 0 || l->getChar( l->length() - 1 ).isSpace() ) )
4067 editInsertText( line + 1, 0,
" " );
4072 editRemoveText( line + 1, 0, tl->length() );
4075 editUnWrapLine( line );
4082 int start,
end, len;
4085 len = textLine->length();
4086 start =
end = cursor.col();
4088 return TQString(
"");
4090 while (start > 0 && highlight()->isInWord(textLine->getChar(start - 1), textLine->attribute(start - 1))) start--;
4091 while (end < len && highlight()->isInWord(textLine->getChar(end), textLine->attribute(end)))
end++;
4093 return TQString(&textLine->text()[start], len);
4096 void KateDocument::tagLines(
int start,
int end)
4098 for (uint z = 0; z < m_views.count(); z++)
4099 m_views.at(z)->tagLines (start, end,
true);
4105 if (blockSelectionMode() && start.col() >
end.col()) {
4106 int sc = start.col();
4107 start.setCol(
end.col());
4111 for (uint z = 0; z < m_views.count(); z++)
4112 m_views.at(z)->tagLines(start, end,
true);
4115 void KateDocument::repaintViews(
bool paintOnlyDirty)
4117 for (uint z = 0; z < m_views.count(); z++)
4118 m_views.at(z)->repaintText(paintOnlyDirty);
4121 void KateDocument::tagAll()
4123 for (uint z = 0; z < m_views.count(); z++)
4125 m_views.at(z)->tagAll();
4126 m_views.at(z)->updateView (
true);
4130 uint KateDocument::configFlags ()
4132 return config()->configFlags();
4135 void KateDocument::setConfigFlags (uint flags)
4137 config()->setConfigFlags(flags);
4140 inline bool isStartBracket(
const TQChar& c ) {
return c ==
'{' || c ==
'[' || c ==
'('; }
4141 inline bool isEndBracket (
const TQChar& c ) {
return c ==
'}' || c ==
']' || c ==
')'; }
4142 inline bool isBracket (
const TQChar& c ) {
return isStartBracket( c ) || isEndBracket( c ); }
4154 void KateDocument::newBracketMark(
const KateTextCursor& cursor, KateBracketRange& bm,
int maxLines )
4158 bm.start() = cursor;
4160 if( !findMatchingBracket( bm.start(), bm.end(), maxLines ) )
4165 const int tw = config()->tabWidth();
4166 const int indentStart = m_buffer->plainLine(bm.start().line())->indentDepth(tw);
4167 const int indentEnd = m_buffer->plainLine(bm.end().line())->indentDepth(tw);
4168 bm.setIndentMin(kMin(indentStart, indentEnd));
4177 TQChar right = textLine->getChar( start.col() );
4178 TQChar left = textLine->getChar( start.col() - 1 );
4181 if ( config()->configFlags() & cfOvr ) {
4182 if( isBracket( right ) ) {
4187 }
else if ( isStartBracket( right ) ) {
4189 }
else if ( isEndBracket( left ) ) {
4190 start.setCol(start.col() - 1);
4192 }
else if ( isBracket( left ) ) {
4193 start.setCol(start.col() - 1);
4195 }
else if ( isBracket( right ) ) {
4204 case '{': opposite =
'}';
break;
4205 case '}': opposite =
'{';
break;
4206 case '[': opposite =
']';
break;
4207 case ']': opposite =
'[';
break;
4208 case '(': opposite =
')';
break;
4209 case ')': opposite =
'(';
break;
4210 default:
return false;
4213 bool forward = isStartBracket( bracket );
4214 int startAttr = textLine->attribute( start.col() );
4222 end.setCol(
end.col() + 1);
4223 if(
end.col() >= lineLength(
end.line() ) ) {
4224 if(
end.line() >= (
int)lastLine() )
4226 end.setPos(
end.line() + 1, 0);
4227 textLine = m_buffer->plainLine(
end.line() );
4231 end.setCol(
end.col() - 1);
4232 if(
end.col() < 0 ) {
4233 if(
end.line() <= 0 )
4235 end.setLine(
end.line() - 1);
4236 end.setCol(lineLength(
end.line() ) - 1);
4237 textLine = m_buffer->plainLine(
end.line() );
4242 if ((maxLines != -1) && (lines > maxLines))
4246 if( textLine->attribute(
end.col() ) != startAttr )
4250 TQChar c = textLine->getChar(
end.col() );
4251 if( c == bracket ) {
4253 }
else if( c == opposite ) {
4265 if ( ev->activated() )
4266 emit selectionChanged();
4269 void KateDocument::setDocName (TQString name )
4271 if ( name == m_docName )
4274 if ( !
name.isEmpty() )
4278 updateFileType (KateFactory::self()->fileTypeManager()->fileType (
this));
4284 if ( ! url().isEmpty() && m_docName.startsWith( url().filename() ) )
return;
4288 for (uint z=0; z < KateFactory::self()->documents()->count(); z++)
4290 if ( (KateFactory::self()->documents()->at(z) !=
this) && (KateFactory::self()->documents()->at(z)->url().filename() == url().
filename()) )
4291 if ( KateFactory::self()->documents()->at(z)->m_docNameNumber > count )
4292 count = KateFactory::self()->documents()->at(z)->m_docNameNumber;
4295 m_docNameNumber = count + 1;
4299 if (m_docName.isEmpty())
4300 m_docName = i18n (
"Untitled");
4302 if (m_docNameNumber > 0)
4303 m_docName = TQString(m_docName +
" (%1)").arg(m_docNameNumber+1);
4305 updateFileType (KateFactory::self()->fileTypeManager()->fileType (
this));
4309 void KateDocument::slotModifiedOnDisk(
Kate::View * )
4311 if ( m_isasking < 0 )
4317 if ( !s_fileChangedDialogsActivated || m_isasking )
4320 if (m_modOnHd && !url().isEmpty())
4327 case KateModOnHdPrompt::Save:
4330 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(config()->encoding(),
4331 url().url(),TQString::null,widget(),i18n(
"Save File"));
4333 kdDebug(13020)<<
"got "<<res.URLs.count()<<
" URLs"<<
endl;
4334 if( ! res.URLs.isEmpty() && ! res.URLs.first().isEmpty() && checkOverwrite( res.URLs.first() ) )
4336 setEncoding( res.encoding );
4338 if( !
saveAs( res.URLs.first() ) )
4344 emit modifiedOnDisc(
this,
false, 0 );
4355 case KateModOnHdPrompt::Reload:
4357 emit modifiedOnDisc(
this,
false, 0 );
4362 case KateModOnHdPrompt::Ignore:
4364 emit modifiedOnDisc(
this,
false, 0 );
4368 case KateModOnHdPrompt::Overwrite:
4370 emit modifiedOnDisc(
this,
false, 0 );
4381 void KateDocument::setModifiedOnDisk(
int reason )
4383 m_modOnHdReason = reason;
4384 m_modOnHd = (reason > 0);
4385 emit modifiedOnDisc(
this, (reason > 0), reason );
4388 class KateDocumentTmpMark
4392 KTextEditor::Mark mark;
4395 void KateDocument::reloadFile()
4397 if ( !url().isEmpty() )
4399 if (m_modOnHd && s_fileChangedDialogsActivated)
4402 (0, reasonedMOHString() +
"\n\n" + i18n(
"What do you want to do?"),
4403 i18n(
"File Was Changed on Disk"), i18n(
"&Reload File"), i18n(
"&Ignore Changes"));
4405 if ( i != KMessageBox::Yes)
4407 if (i == KMessageBox::No)
4410 m_modOnHdReason = 0;
4411 emit modifiedOnDisc (
this, m_modOnHd, 0);
4418 TQValueList<KateDocumentTmpMark> tmp;
4420 for( TQIntDictIterator<KTextEditor::Mark> it( m_marks ); it.current(); ++it )
4422 KateDocumentTmpMark m;
4424 m.line = textLine (it.current()->line);
4425 m.mark = *it.current();
4430 uint mode = hlMode ();
4431 bool byUser = hlSetByUser;
4433 m_storedVariables.clear();
4437 TQValueList<int> lines, cols;
4438 for ( uint i=0; i < m_views.count(); i++ )
4440 lines.append( m_views.at( i )->cursorLine() );
4441 cols.append( m_views.at( i )->cursorColumn() );
4444 KateDocument::openURL( url() );
4446 for ( uint i=0; i < m_views.count(); i++ )
4447 m_views.at( i )->setCursorPositionInternal( lines[ i ], cols[ i ], m_config->tabWidth(),
false );
4449 m_reloading =
false;
4451 for ( TQValueList<int>::size_type z=0; z < tmp.size(); z++ )
4455 if (textLine(tmp[z].mark.line) == tmp[z].line)
4456 setMark (tmp[z].mark.line, tmp[z].mark.type);
4470 void KateDocument::setWordWrap (
bool on)
4472 config()->setWordWrap (on);
4475 bool KateDocument::wordWrap ()
4477 return config()->wordWrap ();
4480 void KateDocument::setWordWrapAt (uint col)
4482 config()->setWordWrapAt (col);
4485 unsigned int KateDocument::wordWrapAt ()
4487 return config()->wordWrapAt ();
4490 void KateDocument::applyWordWrap ()
4495 void KateDocument::setPageUpDownMovesCursor (
bool on)
4497 config()->setPageUpDownMovesCursor (on);
4500 bool KateDocument::pageUpDownMovesCursor ()
4502 return config()->pageUpDownMovesCursor ();
4505 void KateDocument::dumpRegionTree()
4507 m_buffer->foldingTree()->debugDump();
4513 KTextEditor::Cursor *KateDocument::createCursor ( )
4518 void KateDocument::tagArbitraryLines(KateView* view,
KateSuperRange* range)
4521 view->tagLines(range->start(), range->end());
4523 tagLines(range->start(), range->end());
4526 void KateDocument::lineInfo (KateLineInfo *info,
unsigned int line)
4528 m_buffer->lineInfo(info,line);
4531 KateCodeFoldingTree *KateDocument::foldingTree ()
4533 return m_buffer->foldingTree();
4536 void KateDocument::setEncoding (
const TQString &e)
4538 if ( m_encodingSticky )
4541 TQString ce = m_config->encoding().lower();
4542 if ( e.lower() == ce )
4545 m_config->setEncoding( e );
4550 TQString KateDocument::encoding()
const
4552 return m_config->encoding();
4555 void KateDocument::updateConfig ()
4557 emit undoChanged ();
4560 for (KateView * view = m_views.first(); view != 0L; view = m_views.next() )
4562 view->updateDocumentConfig ();
4566 if (m_indenter->modeNumber() != m_config->indentationMode())
4572 m_indenter->updateConfig();
4574 m_buffer->setTabWidth (config()->tabWidth());
4577 for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
4579 if (config()->plugin (i))
4593 TQRegExp KateDocument::kvLine = TQRegExp(
"kate:(.*)");
4594 TQRegExp KateDocument::kvLineWildcard = TQRegExp(
"kate-wildcard\\((.*)\\):(.*)");
4595 TQRegExp KateDocument::kvLineMime = TQRegExp(
"kate-mimetype\\((.*)\\):(.*)");
4596 TQRegExp KateDocument::kvVar = TQRegExp(
"([\\w\\-]+)\\s+([^;]+)");
4598 void KateDocument::readVariables(
bool onlyViewAndRenderer)
4600 if (!onlyViewAndRenderer)
4601 m_config->configStart();
4605 for (v = m_views.first(); v != 0L; v= m_views.next() )
4607 v->config()->configStart();
4608 v->renderer()->config()->configStart();
4611 for (uint i=0; i < kMin( 9U, numLines() ); ++i )
4613 readVariableLine( textLine( i ), onlyViewAndRenderer );
4615 if ( numLines() > 10 )
4617 for ( uint i = kMax(10U, numLines() - 10); i < numLines(); ++i )
4619 readVariableLine( textLine( i ), onlyViewAndRenderer );
4623 if (!onlyViewAndRenderer)
4624 m_config->configEnd();
4626 for (v = m_views.first(); v != 0L; v= m_views.next() )
4628 v->config()->configEnd();
4629 v->renderer()->config()->configEnd();
4633 void KateDocument::readVariableLine( TQString t,
bool onlyViewAndRenderer )
4637 if (t.find(
"kate") < 0)
4643 if ( kvLine.search( t ) > -1 )
4647 kdDebug (13020) <<
"normal variable line kate: matched: " << s <<
endl;
4649 else if (kvLineWildcard.search( t ) > -1)
4651 TQStringList wildcards (TQStringList::split(
';', kvLineWildcard.cap(1)));
4652 TQString nameOfFile = url().
fileName();
4655 for (TQStringList::size_type i = 0; !found && i < wildcards.size(); ++i)
4657 TQRegExp wildcard (wildcards[i],
true,
true);
4659 found = wildcard.exactMatch (nameOfFile);
4666 s = kvLineWildcard.cap(2);
4668 kdDebug (13020) <<
"guarded variable line kate-wildcard: matched: " << s <<
endl;
4670 else if (kvLineMime.search( t ) > -1)
4672 TQStringList types (TQStringList::split(
';', kvLineMime.cap(1)));
4675 if (!types.contains (mimeType ()))
4678 s = kvLineMime.cap(2);
4680 kdDebug (13020) <<
"guarded variable line kate-mimetype: matched: " << s <<
endl;
4688 vvl <<
"dynamic-word-wrap" <<
"dynamic-word-wrap-indicators"
4689 <<
"line-numbers" <<
"icon-border" <<
"folding-markers"
4690 <<
"bookmark-sorting" <<
"auto-center-lines"
4693 <<
"background-color" <<
"selection-color"
4694 <<
"current-line-color" <<
"bracket-highlight-color"
4695 <<
"word-wrap-marker-color"
4696 <<
"font" <<
"font-size" <<
"scheme";
4700 while ( (p = kvVar.search( s, p )) > -1 )
4702 p += kvVar.matchedLength();
4703 var = kvVar.cap( 1 );
4704 val = TQString(kvVar.cap( 2 )).stripWhiteSpace();
4709 if (onlyViewAndRenderer)
4711 if ( vvl.contains( var ) )
4712 setViewVariable( var, val );
4717 if ( var ==
"word-wrap" && checkBoolValue( val, &state ) )
4718 setWordWrap( state );
4719 else if ( var ==
"block-selection" && checkBoolValue( val, &state ) )
4720 setBlockSelectionMode( state );
4723 else if ( var ==
"backspace-indents" && checkBoolValue( val, &state ) )
4724 m_config->setConfigFlags( KateDocumentConfig::cfBackspaceIndents, state );
4725 else if ( var ==
"replace-tabs" && checkBoolValue( val, &state ) )
4726 m_config->setConfigFlags( KateDocumentConfig::cfReplaceTabsDyn, state );
4727 else if ( var ==
"remove-trailing-space" && checkBoolValue( val, &state ) )
4728 m_config->setConfigFlags( KateDocumentConfig::cfRemoveTrailingDyn, state );
4729 else if ( var ==
"wrap-cursor" && checkBoolValue( val, &state ) )
4730 m_config->setConfigFlags( KateDocumentConfig::cfWrapCursor, state );
4731 else if ( var ==
"auto-brackets" && checkBoolValue( val, &state ) )
4732 m_config->setConfigFlags( KateDocumentConfig::cfAutoBrackets, state );
4733 else if ( var ==
"overwrite-mode" && checkBoolValue( val, &state ) )
4734 m_config->setConfigFlags( KateDocumentConfig::cfOvr, state );
4735 else if ( var ==
"keep-indent-profile" && checkBoolValue( val, &state ) )
4736 m_config->setConfigFlags( KateDocumentConfig::cfKeepIndentProfile, state );
4737 else if ( var ==
"keep-extra-spaces" && checkBoolValue( val, &state ) )
4738 m_config->setConfigFlags( KateDocumentConfig::cfKeepExtraSpaces, state );
4739 else if ( var ==
"tab-indents" && checkBoolValue( val, &state ) )
4740 m_config->setConfigFlags( KateDocumentConfig::cfTabIndents, state );
4741 else if ( var ==
"show-tabs" && checkBoolValue( val, &state ) )
4742 m_config->setConfigFlags( KateDocumentConfig::cfShowTabs, state );
4743 else if ( var ==
"space-indent" && checkBoolValue( val, &state ) )
4744 m_config->setConfigFlags( KateDocumentConfig::cfSpaceIndent, state );
4745 else if ( var ==
"smart-home" && checkBoolValue( val, &state ) )
4746 m_config->setConfigFlags( KateDocumentConfig::cfSmartHome, state );
4747 else if ( var ==
"replace-trailing-space-save" && checkBoolValue( val, &state ) )
4748 m_config->setConfigFlags( KateDocumentConfig::cfRemoveSpaces, state );
4749 else if ( var ==
"auto-insert-doxygen" && checkBoolValue( val, &state) )
4750 m_config->setConfigFlags( KateDocumentConfig::cfDoxygenAutoTyping, state);
4751 else if ( var ==
"mixed-indent" && checkBoolValue( val, &state ) )
4752 m_config->setConfigFlags( KateDocumentConfig::cfMixedIndent, state );
4755 else if ( var ==
"tab-width" && checkIntValue( val, &n ) )
4756 m_config->setTabWidth( n );
4757 else if ( var ==
"indent-width" && checkIntValue( val, &n ) )
4758 m_config->setIndentationWidth( n );
4759 else if ( var ==
"indent-mode" )
4761 if ( checkIntValue( val, &n ) )
4762 m_config->setIndentationMode( n );
4766 else if ( var ==
"word-wrap-column" && checkIntValue( val, &n ) && n > 0 )
4767 m_config->setWordWrapAt( n );
4768 else if ( var ==
"undo-steps" && checkIntValue( val, &n ) && n >= 0 )
4772 else if ( var ==
"eol" || var ==
"end-of-line" )
4775 l <<
"unix" <<
"dos" <<
"mac";
4776 if ( (n = l.findIndex( val.lower() )) != -1 )
4777 m_config->setEol( n );
4779 else if ( var ==
"encoding" )
4780 m_config->setEncoding( val );
4781 else if ( var ==
"syntax" || var ==
"hl" )
4783 for ( uint i=0; i < hlModeCount(); i++ )
4785 if ( hlModeName( i ).lower() == val.lower() )
4794 else if ( vvl.contains( var ) )
4795 setViewVariable( var, val );
4798 m_storedVariables.insert( var, val );
4799 emit variableChanged( var, val );
4805 void KateDocument::setViewVariable( TQString var, TQString val )
4811 for (v = m_views.first(); v != 0L; v= m_views.next() )
4813 if ( var ==
"dynamic-word-wrap" && checkBoolValue( val, &state ) )
4814 v->config()->setDynWordWrap( state );
4815 else if ( var ==
"persistent-selection" && checkBoolValue( val, &state ) )
4816 v->config()->setPersistentSelection( state );
4818 else if ( var ==
"line-numbers" && checkBoolValue( val, &state ) )
4819 v->config()->setLineNumbers( state );
4820 else if (var ==
"icon-border" && checkBoolValue( val, &state ) )
4821 v->config()->setIconBar( state );
4822 else if (var ==
"folding-markers" && checkBoolValue( val, &state ) )
4823 v->config()->setFoldingBar( state );
4824 else if ( var ==
"auto-center-lines" && checkIntValue( val, &n ) )
4825 v->config()->setAutoCenterLines( n );
4826 else if ( var ==
"icon-bar-color" && checkColorValue( val, c ) )
4827 v->renderer()->config()->setIconBarColor( c );
4829 else if ( var ==
"background-color" && checkColorValue( val, c ) )
4830 v->renderer()->config()->setBackgroundColor( c );
4831 else if ( var ==
"selection-color" && checkColorValue( val, c ) )
4832 v->renderer()->config()->setSelectionColor( c );
4833 else if ( var ==
"current-line-color" && checkColorValue( val, c ) )
4834 v->renderer()->config()->setHighlightedLineColor( c );
4835 else if ( var ==
"bracket-highlight-color" && checkColorValue( val, c ) )
4836 v->renderer()->config()->setHighlightedBracketColor( c );
4837 else if ( var ==
"word-wrap-marker-color" && checkColorValue( val, c ) )
4838 v->renderer()->config()->setWordWrapMarkerColor( c );
4839 else if ( var ==
"font" || ( var ==
"font-size" && checkIntValue( val, &n ) ) )
4841 TQFont _f( *v->renderer()->config()->font( ) );
4843 if ( var ==
"font" )
4845 _f.setFamily( val );
4846 _f.setFixedPitch( TQFont( val ).fixedPitch() );
4849 _f.setPointSize( n );
4851 v->renderer()->config()->setFont( _f );
4853 else if ( var ==
"scheme" )
4855 v->renderer()->config()->setSchema( KateFactory::self()->schemaManager()->number( val ) );
4860 bool KateDocument::checkBoolValue( TQString val,
bool *result )
4862 val = val.stripWhiteSpace().lower();
4864 l <<
"1" <<
"on" <<
"true";
4865 if ( l.contains( val ) )
4871 l <<
"0" <<
"off" <<
"false";
4872 if ( l.contains( val ) )
4880 bool KateDocument::checkIntValue( TQString val,
int *result )
4883 *result = val.toInt( &ret );
4887 bool KateDocument::checkColorValue( TQString val, TQColor &c )
4889 c.setNamedColor( val );
4894 TQString KateDocument::variable(
const TQString &name )
const
4896 if ( m_storedVariables.contains( name ) )
4897 return m_storedVariables[
name ];
4904 void KateDocument::slotModOnHdDirty (
const TQString &path)
4906 if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != 1))
4909 if ( ! m_digest.isEmpty() )
4912 if ( createDigest( tmp ) && tmp == m_digest )
4917 m_modOnHdReason = 1;
4920 if (m_isasking == -1)
4923 emit modifiedOnDisc (
this, m_modOnHd, m_modOnHdReason);
4927 void KateDocument::slotModOnHdCreated (
const TQString &path)
4929 if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != 2))
4932 m_modOnHdReason = 2;
4935 if (m_isasking == -1)
4938 emit modifiedOnDisc (
this, m_modOnHd, m_modOnHdReason);
4942 void KateDocument::slotModOnHdDeleted (
const TQString &path)
4944 if ((path == m_dirWatchFile) && (!m_modOnHd || m_modOnHdReason != 3))
4947 m_modOnHdReason = 3;
4950 if (m_isasking == -1)
4953 emit modifiedOnDisc (
this, m_modOnHd, m_modOnHdReason);
4957 bool KateDocument::createDigest( TQCString &result )
4961 if ( url().isLocalFile() )
4963 TQFile f ( url().path() );
4964 if ( f.open( IO_ReadOnly) )
4976 TQString KateDocument::reasonedMOHString()
const
4978 switch( m_modOnHdReason )
4981 return i18n(
"The file '%1' was modified by another program.").arg( url().pathOrURL() );
4984 return i18n(
"The file '%1' was created by another program.").arg( url().pathOrURL() );
4987 return i18n(
"The file '%1' was deleted by another program.").arg( url().pathOrURL() );
4994 void KateDocument::removeTrailingSpace( uint line )
4997 if ( config()->configFlags() & KateDocumentConfig::cfRemoveTrailingDyn )
5003 if ( line == activeView()->cursorLine()
5004 && activeView()->cursorColumnReal() >= (uint)kMax(0,ln->lastChar()) )
5009 uint p = ln->lastChar() + 1;
5010 uint l = ln->length() - p;
5012 editRemoveText( line, p, l);
5017 void KateDocument::updateFileType (
int newType,
bool user)
5019 if (user || !m_fileTypeSetByUser)
5021 const KateFileType *t = 0;
5022 if ((newType == -1) || (t = KateFactory::self()->fileTypeManager()->fileType (newType)))
5024 m_fileType = newType;
5028 m_config->configStart();
5031 for (v = m_views.first(); v != 0L; v= m_views.next() )
5033 v->config()->configStart();
5034 v->renderer()->config()->configStart();
5037 readVariableLine( t->varLine );
5039 m_config->configEnd();
5040 for (v = m_views.first(); v != 0L; v= m_views.next() )
5042 v->config()->configEnd();
5043 v->renderer()->config()->configEnd();
5050 uint KateDocument::documentNumber ()
const
5052 return KTextEditor::Document::documentNumber ();
5055 long KateDocument::documentListPosition ()
const
5057 return KTextEditor::Document::documentListPosition ();
5060 void KateDocument::setDocumentListPosition (
long pos)
5062 KTextEditor::Document::setDocumentListPosition (pos);
5067 void KateDocument::slotQueryClose_save(
bool *handled,
bool* abortClosing) {
5070 if (m_url.isEmpty())
5072 KEncodingFileDialog::Result res=KEncodingFileDialog::getSaveURLAndEncoding(config()->encoding(),
5073 TQString::null,TQString::null,0,i18n(
"Save File"));
5075 if( res.URLs.isEmpty() || !checkOverwrite( res.URLs.first() ) ) {
5079 setEncoding( res.encoding );
5080 saveAs( res.URLs.first() );
5081 *abortClosing=
false;
5086 *abortClosing=
false;
5091 bool KateDocument::checkOverwrite(
KURL u )
5096 TQFileInfo info( u.
path() );
5097 if( !info.exists() )
5101 i18n(
"A file named \"%1\" already exists. "
5102 "Are you sure you want to overwrite it?" ).arg( info.fileName() ),
5103 i18n(
"Overwrite File?" ),
5104 i18n(
"&Overwrite" ) );
5107 void KateDocument::setDefaultEncoding (
const TQString &encoding)
5109 s_defaultEncoding = encoding;
5113 bool KateDocument::insertTemplateTextImplementation ( uint line, uint column,
const TQString &templateString,
const TQMap<TQString,TQString> &initialValues, TQWidget *) {
5114 return (
new KateTemplateHandler(
this,line,column,templateString,initialValues))->initOk();
5117 void KateDocument::testTemplateCode() {
5118 int col=activeView()->cursorColumn();
5119 int line=activeView()->cursorLine();
5120 insertTemplateText(line,col,
"for ${index} \\${NOPLACEHOLDER} ${index} ${blah} ${fullname} \\$${Placeholder} \\${${PLACEHOLDER2}}\n next line:${ANOTHERPLACEHOLDER} $${DOLLARBEFOREPLACEHOLDER} {NOTHING} {\n${cursor}\n}",TQMap<TQString,TQString>());
5123 bool KateDocument::invokeTabInterceptor(
KKey key) {
5124 if (m_tabInterceptor)
return (*m_tabInterceptor)(
key);
5128 bool KateDocument::setTabInterceptor(KateKeyInterceptorFunctor *interceptor) {
5129 if (m_tabInterceptor)
return false;
5130 m_tabInterceptor=interceptor;
5134 bool KateDocument::removeTabInterceptor(KateKeyInterceptorFunctor *interceptor) {
5135 if (m_tabInterceptor!=interceptor)
return false;
5142 bool KateDocument::setSelection ( uint startLine, uint startCol, uint endLine, uint endCol )
5143 {
if (m_activeView)
return m_activeView->setSelection (startLine, startCol, endLine, endCol);
return false; }
5145 bool KateDocument::clearSelection ()
5146 {
if (m_activeView)
return m_activeView->clearSelection();
return false; }
5148 bool KateDocument::hasSelection ()
const
5149 {
if (m_activeView)
return m_activeView->hasSelection ();
return false; }
5151 TQString KateDocument::selection ()
const
5152 {
if (m_activeView)
return m_activeView->selection ();
return TQString(
""); }
5154 bool KateDocument::removeSelectedText ()
5155 {
if (m_activeView)
return m_activeView->removeSelectedText ();
return false; }
5157 bool KateDocument::selectAll()
5158 {
if (m_activeView)
return m_activeView->selectAll ();
return false; }
5160 int KateDocument::selStartLine()
5161 {
if (m_activeView)
return m_activeView->selStartLine ();
return 0; }
5163 int KateDocument::selStartCol()
5164 {
if (m_activeView)
return m_activeView->selStartCol ();
return 0; }
5166 int KateDocument::selEndLine()
5167 {
if (m_activeView)
return m_activeView->selEndLine ();
return 0; }
5169 int KateDocument::selEndCol()
5170 {
if (m_activeView)
return m_activeView->selEndCol ();
return 0; }
5172 bool KateDocument::blockSelectionMode ()
5173 {
if (m_activeView)
return m_activeView->blockSelectionMode ();
return false; }
5175 bool KateDocument::setBlockSelectionMode (
bool on)
5176 {
if (m_activeView)
return m_activeView->setBlockSelectionMode (on);
return false; }
5178 bool KateDocument::toggleBlockSelectionMode ()
5179 {
if (m_activeView)
return m_activeView->toggleBlockSelectionMode ();
return false; }
TQVBox * addVBoxPage(const TQString &itemName, const TQString &header=TQString::null, const TQPixmap &pixmap=TQPixmap())
void update(const char *in, int len=-1)
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
static int warningYesNoCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
virtual void guiActivateEvent(GUIActivateEvent *event)
virtual void setReadWrite(bool readwrite=true)
virtual bool saveAs(const KURL &url)
virtual void setModified()
TQString directory(bool _strip_trailing_slash_from_result=true, bool _ignore_trailing_slash_in_path=true) const
TQString fileName(bool _ignore_trailing_slash_in_path=true) const
TQString filename(bool _ignore_trailing_slash_in_path=true) const
TQString prettyURL(int _trailing=0) const
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
void removeClient(KXMLGUIClient *client)
void addClient(KXMLGUIClient *client)
An arbitrary highlighting interface for Kate.
virtual uint modeNumber() const
Mode index of this mode.
static KateAutoIndent * createIndenter(KateDocument *doc, uint mode)
Static methods to create and list indention modes.
Interface for embedding KateDocument into a browser.
The KateBuffer class maintains a collections of lines.
static void setMaxLoadedBlocks(uint count)
modifier for max loaded blocks limit
static uint maxLoadedBlocks()
maximal loaded block count
Cursor class with a pointer to its document.
This dialog will prompt the user for what do with a file that is modified on disk.
Possible additional features:
Represents a range of text, from the start() to the end().
Simple cursor class with no document pointer.
The KateTextLine represents a line of text.
Class to manage a group of undo items.
UndoType
Types for undo items.
This interface provides access to the Kate Document class.
The Kate::View text editor interface.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
int readNumEntry(const TQString &pKey, int nDefault=0) const
TQValueList< int > readIntListEntry(const TQString &pKey) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void setGroup(const TQString &group)
static TDEStandardDirs * dirs()
TQString relativeLocation(const char *type, const TQString &absPath)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
kndbgstream & flush(kndbgstream &s)
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * saveAs(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
Kate namespace All classes in this namespace must stay BC during one major release series (e....
const TDEShortcut & forward()
TQString name(StdAccel id)
const TDEShortcut & end()
const TDEShortcut & save()