Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katedocument.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 0c742d7..6dc4fd2 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1,21 +1,21 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.cpp - description | 2 | katedocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
@@ -30,62 +30,63 @@ | |||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "katedocument.h" | 41 | #include "katedocument.h" |
42 | #include "kmessagebox.h" | ||
43 | #include "kglobal.h" | ||
42 | 44 | ||
45 | //#include "kcharsets.h" | ||
46 | #include "kdebug.h" | ||
47 | //#include "kinstance.h" | ||
43 | 48 | ||
44 | #include <qfileinfo.h> | 49 | #include "kglobalsettings.h" |
45 | #include <qdatetime.h> | 50 | //#include "kaction.h" |
51 | //#include "kstdaction.h" | ||
46 | 52 | ||
47 | #include <kmessagebox.h> | 53 | #include "../view/kateview.h" |
48 | #include <qpe/config.h> | 54 | #include "katebuffer.h" |
49 | #include <qstring.h> | 55 | #include "katetextline.h" |
50 | 56 | ||
51 | #include <sys/time.h> | 57 | #include "katecmd.h" |
52 | #include <unistd.h> | ||
53 | 58 | ||
54 | #include <stdio.h> | 59 | /* OPIE */ |
60 | #include <opie2/odebug.h> | ||
61 | #include <qpe/config.h> | ||
55 | 62 | ||
63 | /* QT */ | ||
64 | #include <qfileinfo.h> | ||
65 | #include <qdatetime.h> | ||
66 | #include <qstring.h> | ||
56 | #include <qtimer.h> | 67 | #include <qtimer.h> |
57 | #include <qobject.h> | 68 | #include <qobject.h> |
58 | #include <qapplication.h> | 69 | #include <qapplication.h> |
59 | #include <qclipboard.h> | 70 | #include <qclipboard.h> |
60 | #include <qfont.h> | 71 | #include <qfont.h> |
61 | #include <qpainter.h> | 72 | #include <qpainter.h> |
62 | #include <qfile.h> | 73 | #include <qfile.h> |
63 | #include <qtextstream.h> | 74 | #include <qtextstream.h> |
64 | #include <qtextcodec.h> | 75 | #include <qtextcodec.h> |
65 | #include <kglobal.h> | ||
66 | 76 | ||
67 | //#include <kcharsets.h> | 77 | /* STD */ |
68 | #include <kdebug.h> | 78 | #include <sys/time.h> |
69 | //#include <kinstance.h> | 79 | #include <unistd.h> |
70 | 80 | #include <stdio.h> | |
71 | #include <kglobalsettings.h> | ||
72 | //#include <kaction.h> | ||
73 | //#include <kstdaction.h> | ||
74 | |||
75 | #include "../view/kateview.h" | ||
76 | #include "katebuffer.h" | ||
77 | #include "katetextline.h" | ||
78 | |||
79 | #include "katecmd.h" | ||
80 | 81 | ||
81 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) | 82 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) |
82 | : action(a), cursor(cursor), len(len), text(text) { | 83 | : action(a), cursor(cursor), len(len), text(text) { |
83 | } | 84 | } |
84 | 85 | ||
85 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) | 86 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) |
86 | : start(aStart), action(0L), undoType(type) { | 87 | : start(aStart), action(0L), undoType(type) { |
87 | } | 88 | } |
88 | 89 | ||
89 | KateActionGroup::~KateActionGroup() { | 90 | KateActionGroup::~KateActionGroup() { |
90 | KateAction *current, *next; | 91 | KateAction *current, *next; |
91 | 92 | ||
@@ -121,47 +122,47 @@ const char * KateActionGroup::typeName(int type) | |||
121 | case ugDelLine : return "Delete Line"; | 122 | case ugDelLine : return "Delete Line"; |
122 | } | 123 | } |
123 | return ""; | 124 | return ""; |
124 | } | 125 | } |
125 | 126 | ||
126 | const int KateDocument::maxAttribs = 32; | 127 | const int KateDocument::maxAttribs = 32; |
127 | 128 | ||
128 | QStringList KateDocument::searchForList = QStringList(); | 129 | QStringList KateDocument::searchForList = QStringList(); |
129 | QStringList KateDocument::replaceWithList = QStringList(); | 130 | QStringList KateDocument::replaceWithList = QStringList(); |
130 | 131 | ||
131 | uint KateDocument::uniqueID = 0; | 132 | uint KateDocument::uniqueID = 0; |
132 | 133 | ||
133 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; | 134 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; |
134 | 135 | ||
135 | 136 | ||
136 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, | 137 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, |
137 | QWidget *parentWidget, const char *widgetName, | 138 | QWidget *parentWidget, const char *widgetName, |
138 | QObject *, const char *) | 139 | QObject *, const char *) |
139 | : Kate::Document (), | 140 | : Kate::Document (), |
140 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), | 141 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), |
141 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), | 142 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), |
142 | hlManager(HlManager::self ()) | 143 | hlManager(HlManager::self ()) |
143 | { | 144 | { |
144 | 145 | ||
145 | d(this)->hlSetByUser = false; | 146 | d(this)->hlSetByUser = false; |
146 | PreHighlightedTill=0; | 147 | PreHighlightedTill=0; |
147 | RequestPreHighlightTill=0; | 148 | RequestPreHighlightTill=0; |
148 | 149 | ||
149 | m_bSingleViewMode=bSingleViewMode; | 150 | m_bSingleViewMode=bSingleViewMode; |
150 | m_bBrowserView = bBrowserView; | 151 | m_bBrowserView = bBrowserView; |
151 | 152 | ||
152 | m_url = QString::null; | 153 | m_url = QString::null; |
153 | 154 | ||
154 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports | 155 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports |
155 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) | 156 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) |
156 | 157 | ||
157 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); | 158 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); |
158 | 159 | ||
159 | maxLength = -1; | 160 | maxLength = -1; |
160 | 161 | ||
161 | setFont (KGlobalSettings::generalFont()); | 162 | setFont (KGlobalSettings::generalFont()); |
162 | 163 | ||
163 | myDocID = uniqueID; | 164 | myDocID = uniqueID; |
164 | uniqueID++; | 165 | uniqueID++; |
165 | 166 | ||
166 | myDocName = QString (""); | 167 | myDocName = QString (""); |
167 | fileInfo = new QFileInfo (); | 168 | fileInfo = new QFileInfo (); |
@@ -283,60 +284,60 @@ KateDocument::~KateDocument() | |||
283 | if ( !m_bSingleViewMode ) | 284 | if ( !m_bSingleViewMode ) |
284 | { | 285 | { |
285 | m_views.setAutoDelete( true ); | 286 | m_views.setAutoDelete( true ); |
286 | m_views.clear(); | 287 | m_views.clear(); |
287 | m_views.setAutoDelete( false ); | 288 | m_views.setAutoDelete( false ); |
288 | } | 289 | } |
289 | delete_d(this); | 290 | delete_d(this); |
290 | } | 291 | } |
291 | 292 | ||
292 | void KateDocument::openURL(const QString &filename) | 293 | void KateDocument::openURL(const QString &filename) |
293 | { | 294 | { |
294 | 295 | ||
295 | m_file=filename; | 296 | m_file=filename; |
296 | fileInfo->setFile (m_file); | 297 | fileInfo->setFile (m_file); |
297 | setMTime(); | 298 | setMTime(); |
298 | 299 | ||
299 | if (!fileInfo->exists() || !fileInfo->isReadable()) | 300 | if (!fileInfo->exists() || !fileInfo->isReadable()) |
300 | { | 301 | { |
301 | qDebug("File doesn't exit or couldn't be read"); | 302 | odebug << "File doesn't exit or couldn't be read" << oendl; |
302 | return ; | 303 | return ; |
303 | } | 304 | } |
304 | 305 | ||
305 | buffer->clear(); | 306 | buffer->clear(); |
306 | #warning fixme | 307 | #warning fixme |
307 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); | 308 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); |
308 | qDebug("Telling buffer to open file"); | 309 | odebug << "Telling buffer to open file" << oendl; |
309 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); | 310 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); |
310 | 311 | ||
311 | setMTime(); | 312 | setMTime(); |
312 | 313 | ||
313 | if (myWordWrap) | 314 | if (myWordWrap) |
314 | wrapText (myWordWrapAt); | 315 | wrapText (myWordWrapAt); |
315 | 316 | ||
316 | int hl = hlManager->wildcardFind( m_file ); | 317 | int hl = hlManager->wildcardFind( m_file ); |
317 | 318 | ||
318 | setHighlight(hl); | 319 | setHighlight(hl); |
319 | 320 | ||
320 | updateLines(); | 321 | updateLines(); |
321 | updateViews(); | 322 | updateViews(); |
322 | 323 | ||
323 | emit fileNameChanged(); | 324 | emit fileNameChanged(); |
324 | 325 | ||
325 | return ; | 326 | return ; |
326 | } | 327 | } |
327 | 328 | ||
328 | bool KateDocument::saveFile() | 329 | bool KateDocument::saveFile() |
329 | { | 330 | { |
330 | 331 | ||
331 | QFile f( m_file ); | 332 | QFile f( m_file ); |
332 | if ( !f.open( IO_WriteOnly ) ) | 333 | if ( !f.open( IO_WriteOnly ) ) |
333 | return false; // Error | 334 | return false; // Error |
334 | 335 | ||
335 | QTextStream stream(&f); | 336 | QTextStream stream(&f); |
336 | 337 | ||
337 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers | 338 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers |
338 | #warning fixme | 339 | #warning fixme |
339 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); | 340 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); |
340 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec | 341 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec |
341 | 342 | ||
342 | int maxLine = numLines(); | 343 | int maxLine = numLines(); |
@@ -602,25 +603,25 @@ void KateDocument::readConfig() | |||
602 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); | 603 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); |
603 | if (myWordWrap) | 604 | if (myWordWrap) |
604 | wrapText (myWordWrapAt); | 605 | wrapText (myWordWrapAt); |
605 | 606 | ||
606 | setTabWidth(config->readNumEntry("TabWidth", 8)); | 607 | setTabWidth(config->readNumEntry("TabWidth", 8)); |
607 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); | 608 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); |
608 | m_singleSelection = config->readBoolEntry("SingleSelection", false); | 609 | m_singleSelection = config->readBoolEntry("SingleSelection", false); |
609 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); | 610 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); |
610 | setFont (config->readFontEntry("Font", myFont)); | 611 | setFont (config->readFontEntry("Font", myFont)); |
611 | 612 | ||
612 | colors[0] = config->readColorEntry("Color Background", colors[0]); | 613 | colors[0] = config->readColorEntry("Color Background", colors[0]); |
613 | colors[1] = config->readColorEntry("Color Selected", colors[1]); | 614 | colors[1] = config->readColorEntry("Color Selected", colors[1]); |
614 | 615 | ||
615 | // config->sync(); | 616 | // config->sync(); |
616 | } | 617 | } |
617 | 618 | ||
618 | void KateDocument::writeConfig() | 619 | void KateDocument::writeConfig() |
619 | { | 620 | { |
620 | KateConfig *config = KGlobal::config(); | 621 | KateConfig *config = KGlobal::config(); |
621 | config->setGroup("Kate Document"); | 622 | config->setGroup("Kate Document"); |
622 | config->writeEntry("Word Wrap On", myWordWrap); | 623 | config->writeEntry("Word Wrap On", myWordWrap); |
623 | config->writeEntry("Word Wrap At", myWordWrapAt); | 624 | config->writeEntry("Word Wrap At", myWordWrapAt); |
624 | config->writeEntry("TabWidth", tabChars); | 625 | config->writeEntry("TabWidth", tabChars); |
625 | config->writeEntry("UndoSteps", undoSteps); | 626 | config->writeEntry("UndoSteps", undoSteps); |
626 | config->writeEntry("SingleSelection", m_singleSelection); | 627 | config->writeEntry("SingleSelection", m_singleSelection); |
@@ -674,25 +675,25 @@ void KateDocument::setHighlight(int n) { | |||
674 | } else { | 675 | } else { |
675 | if (m_highlight != 0L) m_highlight->release(); | 676 | if (m_highlight != 0L) m_highlight->release(); |
676 | h->use(); | 677 | h->use(); |
677 | m_highlight = h; | 678 | m_highlight = h; |
678 | makeAttribs(); | 679 | makeAttribs(); |
679 | } | 680 | } |
680 | PreHighlightedTill=0; | 681 | PreHighlightedTill=0; |
681 | RequestPreHighlightTill=0; | 682 | RequestPreHighlightTill=0; |
682 | emit(highlightChanged()); | 683 | emit(highlightChanged()); |
683 | } | 684 | } |
684 | 685 | ||
685 | void KateDocument::makeAttribs() { | 686 | void KateDocument::makeAttribs() { |
686 | qDebug("KateDocument::makeAttribs()"); | 687 | odebug << "KateDocument::makeAttribs()" << oendl; |
687 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); | 688 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); |
688 | updateFontData(); | 689 | updateFontData(); |
689 | updateLines(); | 690 | updateLines(); |
690 | } | 691 | } |
691 | 692 | ||
692 | void KateDocument::updateFontData() { | 693 | void KateDocument::updateFontData() { |
693 | int maxAscent, maxDescent; | 694 | int maxAscent, maxDescent; |
694 | int tabWidth; | 695 | int tabWidth; |
695 | KateView *view; | 696 | KateView *view; |
696 | 697 | ||
697 | maxAscent = myFontMetrics.ascent(); | 698 | maxAscent = myFontMetrics.ascent(); |
698 | maxDescent = myFontMetrics.descent(); | 699 | maxDescent = myFontMetrics.descent(); |
@@ -1914,26 +1915,26 @@ void KateDocument::updateLines(int startLine, int endLine, int flags, int cursor | |||
1914 | line = startLine; | 1915 | line = startLine; |
1915 | ctxNum = 0; | 1916 | ctxNum = 0; |
1916 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1917 | do { | 1918 | do { |
1918 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1919 | textLine = getTextLine(line); | 1920 | textLine = getTextLine(line); |
1920 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1921 | if (line <= endLine && line != cursorY) { | 1922 | if (line <= endLine && line != cursorY) { |
1922 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1923 | updateMaxLength(textLine); | 1924 | updateMaxLength(textLine); |
1924 | } | 1925 | } |
1925 | endCtx = textLine->getContext(); | 1926 | endCtx = textLine->getContext(); |
1926 | // qDebug("DOHIGHLIGHT"); | 1927 | // odebug << "DOHIGHLIGHT" << oendl; |
1927 | 1928 | ||
1928 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1929 | textLine->setContext(ctxNum); | 1930 | textLine->setContext(ctxNum); |
1930 | line++; | 1931 | line++; |
1931 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1932 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1933 | tagLines(startLine, line - 1); | 1934 | tagLines(startLine, line - 1); |
1934 | } | 1935 | } |
1935 | 1936 | ||
1936 | 1937 | ||
1937 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1938 | int len; | 1939 | int len; |
1939 | 1940 | ||