summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.cpp10
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h11
2 files changed, 15 insertions, 6 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp
index 10bc976..df1de8d 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.cpp
+++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp
@@ -235,192 +235,193 @@ void KateDocument::setFont (QFont font)
myFontMetricsBold = CachedFontMetrics (myFontBold);
myFontMetricsItalic = CachedFontMetrics (myFontItalic);
myFontMetricsBI = CachedFontMetrics (myFontBI);
int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
updateFontData();
updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
}
long KateDocument::needPreHighlight(long till)
{
int max=numLines()-1;
if (till>max)
{
till=max;
}
if (PreHighlightedTill>=till) return -1;
long tmp=RequestPreHighlightTill;
if (RequestPreHighlightTill<till)
{
RequestPreHighlightTill=till;
if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight()));
}
return RequestPreHighlightTill;
}
void KateDocument::doPreHighlight()
{
int from = PreHighlightedTill;
int till = PreHighlightedTill+200;
int max = numLines()-1;
if (till > max)
{
till = max;
}
PreHighlightedTill = till;
updateLines(from,till);
emit preHighlightChanged(PreHighlightedTill);
if (PreHighlightedTill<RequestPreHighlightTill)
QTimer::singleShot(10,this,SLOT(doPreHighlight()));
}
KateDocument::~KateDocument()
{
m_highlight->release();
if ( !m_bSingleViewMode )
{
m_views.setAutoDelete( true );
m_views.clear();
m_views.setAutoDelete( false );
}
delete_d(this);
}
void KateDocument::openURL(const QString &filename)
{
m_file=filename;
fileInfo->setFile (m_file);
setMTime();
if (!fileInfo->exists() || !fileInfo->isReadable())
{
qDebug("File doesn't exit or couldn't be read");
return ;
}
buffer->clear();
#warning fixme
// buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding));
qDebug("Telling buffer to open file");
buffer->insertFile(0, m_file, QTextCodec::codecForLocale());
setMTime();
if (myWordWrap)
wrapText (myWordWrapAt);
int hl = hlManager->wildcardFind( m_file );
setHighlight(hl);
updateLines();
updateViews();
emit fileNameChanged();
return ;
}
bool KateDocument::saveFile()
{
+
QFile f( m_file );
if ( !f.open( IO_WriteOnly ) )
return false; // Error
QTextStream stream(&f);
stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers
#warning fixme
// stream.setCodec(KGlobal::charsets()->codecForName(myEncoding));
stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec
int maxLine = numLines();
int line = 0;
while(true)
{
stream << getTextLine(line)->getString();
line++;
if (line >= maxLine) break;
if (eolMode == KateDocument::eolUnix) stream << "\n";
else if (eolMode == KateDocument::eolDos) stream << "\r\n";
else if (eolMode == KateDocument::eolMacintosh) stream << '\r';
};
f.close();
fileInfo->setFile (m_file);
setMTime();
if (!(d(this)->hlSetByUser))
{
int hl = hlManager->wildcardFind( m_file );
setHighlight(hl);
}
emit fileNameChanged ();
return (f.status() == IO_Ok);
}
KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name )
{
return new KateView( this, parent, name);
}
QString KateDocument::textLine( int line ) const
{
TextLine::Ptr l = getTextLine( line );
if ( !l )
return QString();
return l->getString();
}
void KateDocument::replaceLine(const QString& s,int line)
{
remove_Line(line,false);
insert_Line(s,line,true);
}
void KateDocument::insertLine( const QString &str, int l ) {
insert_Line(str,l,true);
}
void KateDocument::insert_Line(const QString& s,int line, bool update)
{
kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl;
TextLine::Ptr TL=new TextLine();
TL->append(s.unicode(),s.length());
buffer->insertLine(line,TL);
if (update)
{
newDocGeometry=true;
updateLines(line);
updateViews();
}
}
void KateDocument::insertAt( const QString &s, int line, int col, bool )
{
VConfig c;
c.view = 0; // ### FIXME
c.cursor.x = col;
c.cursor.y = line;
c.cXPos = 0; // ### FIXME
c.flags = 0; // ### FIXME
insert( c, s );
}
void KateDocument::removeLine( int line ) {
remove_Line(line,true);
}
void KateDocument::remove_Line(int line,bool update)
{
kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl;
buffer->removeLine(line);
@@ -1832,193 +1833,194 @@ QString KateDocument::markedText(int flags) {
start = textLine->findUnselected(end);
end = textLine->findSelected(start);
for (i = start; i < end; i++) {
s[len] = textLine->getChar(i);
len++;
}
} while (start < end);
s[len] = '\n';
len++;
}
// s[len] = '\0'; // the final \0 is not counted in length()
return s;
}
}
void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) {
int end = 0;
if (selectEnd < selectStart) return;
// the caller may have already started an undo record for the current action
// if (undo)
//auto deletion of the marked text occurs not very often and can therefore
// be recorded separately
recordStart(c, KateActionGroup::ugDelBlock);
for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) {
TextLine::Ptr textLine = getTextLine(c.cursor.y);
c.cursor.x = textLine->length();
do {
end = textLine->findRevUnselected(c.cursor.x);
if (end == 0) break;
c.cursor.x = textLine->findRevSelected(end);
recordDelete(c.cursor, end - c.cursor.x);
} while (true);
end = c.cursor.x;
c.cursor.x = textLine->length();
if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor);
}
c.cursor.y++;
/*if (end < c.cursor.x)*/ c.cursor.x = end;
selectEnd = -1;
select.x = -1;
/*if (undo)*/ recordEnd(c);
}
void KateDocument::tagLineRange(int line, int x1, int x2) {
int z;
for (z = 0; z < (int) views.count(); z++) {
views.at(z)->tagLines(line, line, x1, x2);
}
}
void KateDocument::tagLines(int start, int end) {
int z;
for (z = 0; z < (int) views.count(); z++) {
views.at(z)->tagLines(start, end, 0, 0xffffff);
}
}
void KateDocument::tagAll() {
int z;
for (z = 0; z < (int) views.count(); z++) {
views.at(z)->tagAll();
}
}
void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) {
TextLine::Ptr textLine;
int line, last_line;
int ctxNum, endCtx;
// kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl;
if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;};
// kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl;
last_line = lastLine();
// if (endLine >= last_line) endLine = last_line;
line = startLine;
ctxNum = 0;
if (line > 0) ctxNum = getTextLine(line - 1)->getContext();
do {
// kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl;
textLine = getTextLine(line);
if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl;
if (line <= endLine && line != cursorY) {
if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces();
updateMaxLength(textLine);
}
endCtx = textLine->getContext();
- qDebug("DOHIGHLIGHT");
+// qDebug("DOHIGHLIGHT");
+
ctxNum = m_highlight->doHighlight(ctxNum,textLine);
textLine->setContext(ctxNum);
line++;
} while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum));
// kdDebug(13020)<<"updateLines :: while loop left"<<endl;
tagLines(startLine, line - 1);
}
void KateDocument::updateMaxLength(TextLine::Ptr &textLine) {
int len;
len = textWidth(textLine,textLine->length());
if (len > maxLength) {
longestLine = textLine;
maxLength = len;
newDocGeometry = true;
} else {
if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) {
maxLength = -1;
for (int i = 0; i < numLines();i++) {
textLine = getTextLine(i);
len = textWidth(textLine,textLine->length());
if (len > maxLength) {
maxLength = len;
longestLine = textLine;
}
}
newDocGeometry = true;
}
}
}
void KateDocument::slotBufferChanged() {
newDocGeometry = true;
//updateLines();//JW
updateViews();
}
void KateDocument::slotBufferHighlight(long start,long stop) {
kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl;
updateLines(start,stop);
// buffer->startLoadTimer();
}
void KateDocument::updateViews(KateView *exclude) {
KateView *view;
int flags;
bool markState = hasMarkedText();
flags = (newDocGeometry) ? KateView::ufDocGeometry : 0;
for (view = views.first(); view != 0L; view = views.next() ) {
if (view != exclude) view->updateView(flags);
// notify every view about the changed mark state....
if (oldMarkState != markState) emit view->newMarkStatus();
}
oldMarkState = markState;
newDocGeometry = false;
}
QColor &KateDocument::cursorCol(int x, int y) {
int attr;
Attribute *a;
TextLine::Ptr textLine = getTextLine(y);
attr = textLine->getRawAttr(x);
a = &m_attribs[attr & taAttrMask];
if (attr & taSelected) return a->selCol; else return a->col;
}
void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs)
{
paintTextLine (paint, line, 0, xStart, xEnd, showTabs);
}
void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs)
{
TextLine::Ptr textLine;
int len;
const QChar *s;
int z, x;
QChar ch;
Attribute *a = 0L;
int attr, nextAttr;
int xs;
int xc, zc;
if (line > lastLine()) {
paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]);
return;
}
textLine = getTextLine(line);
len = textLine->length();
@@ -2937,192 +2939,198 @@ void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm)
opposite = ')';
if (bracket == '[') opposite = ']';
if (bracket == '{') opposite = '}';
//get attribute of bracket (opposite bracket must have the same attribute)
x++;
while (line - cursor.y < 40) {
//go to next line on end of line
while (x >= (int) textLine->length()) {
line++;
if (line > lastLine()) return;
textLine = getTextLine(line);
x = 0;
}
if (textLine->getAttr(x) == attr) {
//try to find opposite bracked
ch = textLine->getChar(x);
if (ch == bracket) count++; //same bracket : increase counter
if (ch == opposite) {
count--;
if (count < 0) goto found;
}
}
x++;
}
}
else if (bracket == ')' || bracket == ']' || bracket == '}')
{
opposite = '(';
if (bracket == ']') opposite = '[';
if (bracket == '}') opposite = '{';
x--;
while (cursor.y - line < 20) {
while (x < 0) {
line--;
if (line < 0) return;
textLine = getTextLine(line);
x = textLine->length() -1;
}
if (textLine->getAttr(x) == attr) {
ch = textLine->getChar(x);
if (ch == bracket) count++;
if (ch == opposite) {
count--;
if (count < 0) goto found;
}
}
x--;
}
}
return;
found:
//cursor position of opposite bracket
bm.cursor.x = x;
bm.cursor.y = line;
//x position (start and end) of related bracket
bm.sXPos = textWidth(textLine, x);
a = &m_attribs[attr];
if (a->bold && a->italic)
bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket);
else if (a->bold)
bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket);
else if (a->italic)
bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket);
else
bm.eXPos = bm.sXPos + myFontMetrics.width(bracket);
}
void KateDocument::clipboardChanged() { //slot
//#if defined(_WS_X11_)
if (m_singleSelection) {
disconnect(QApplication::clipboard(), SIGNAL(dataChanged()),
this, SLOT(clipboardChanged()));
deselectAll();
updateViews();
}
//#endif
}
#if 0
void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev )
{
KParts::ReadWritePart::guiActivateEvent( ev );
if ( ev->activated() )
emit selectionChanged();
}
#endif
void KateDocument::setDocName (QString docName)
{
myDocName = docName;
emit nameChanged (this);
}
+void KateDocument::setDocFile (QString docFile)
+{
+ m_file = docFile;
+ emit fileNameChanged ();
+}
+
void KateDocument::setMTime()
{
if (fileInfo && !fileInfo->fileName().isEmpty()) {
fileInfo->refresh();
mTime = fileInfo->lastModified();
}
}
void KateDocument::isModOnHD(bool forceReload)
{
if (fileInfo && !fileInfo->fileName().isEmpty()) {
fileInfo->refresh();
if (fileInfo->lastModified() > mTime) {
if ( forceReload ||
(KMessageBox::warningContinueCancel(0,
(i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url),
i18n("File has changed on Disk"),
i18n("Yes") ) == KMessageBox::Continue)
)
reloadFile();
else
setMTime();
}
}
}
void KateDocument::reloadFile()
{
#warning fixme
#if 0
if (fileInfo && !fileInfo->fileName().isEmpty()) {
KateDocument::openFile();
setMTime();
}
#endif
}
void KateDocument::slotModChanged()
{
emit modStateChanged (this);
}
QList<Kate::Mark> KateDocument::marks ()
{
QList<Kate::Mark> list;
TextLine::Ptr line;
for (int i=0; i < numLines(); i++)
{
line = getTextLine(i);
if (line->mark() != 0)
{
Kate::Mark *mark=new Kate::Mark;
mark->line = i;
mark->type = line->mark();
list.append (mark);
}
}
return list;
}
void KateDocument::flush ()
{
if (isReadOnly())
return;
m_url = QString::null;
fileInfo->setFile (QString());
setMTime();
clear();
updateViews();
emit fileNameChanged ();
}
void KateDocument::open (const QString &name)
{
openURL (name);
}
void KateDocument::wrapText (uint col)
{
int line = 0;
int z = 0;
while(true)
{
TextLine::Ptr l = getTextLine(line);
if (l->length() > col)
{
TextLine::Ptr tl = new TextLine();
buffer->insertLine(line+1,tl);
const QChar *text = l->getText();
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 220d188..356541f 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -361,209 +361,210 @@ class KateDocument: public Kate::Document
void recordStart(VConfig &, int newUndoType);
void recordStart(KateView *, PointStruc &, int flags, int newUndoType, bool keepModal = false, bool mergeUndo = false);
void recordAction(KateAction::Action, PointStruc &);
void recordInsert(VConfig &, const QString &text);
void recordReplace(VConfig &, int len, const QString &text);
void recordInsert(PointStruc &, const QString &text);
void recordDelete(PointStruc &, int len);
void recordReplace(PointStruc &, int len, const QString &text);
void recordEnd(VConfig &);
void recordEnd(KateView *, PointStruc &, int flags);
void doActionGroup(KateActionGroup *, int flags, bool undo = false);
int nextUndoType();
int nextRedoType();
void undoTypeList(QValueList<int> &lst);
void redoTypeList(QValueList<int> &lst);
void undo(VConfig &, int count = 1);
void redo(VConfig &, int count = 1);
void clearRedo();
void setUndoSteps(int steps);
void setPseudoModal(QWidget *);
void newBracketMark(PointStruc &, BracketMark &);
protected slots:
void clipboardChanged();
void slotBufferChanged();
void slotBufferHighlight(long,long);
void doPreHighlight();
private slots:
void slotViewDestroyed();
// member variables
protected:
long PreHighlightedTill;
long RequestPreHighlightTill;
KWBuffer *buffer;
QColor colors[2];
HlManager *hlManager;
Highlight *m_highlight;
int m_numAttribs;
static const int maxAttribs;
Attribute *m_attribs;
int eolMode;
int tabChars;
int m_tabWidth;
int fontHeight;
int fontAscent;
QList<KateView> views;
bool newDocGeometry;
TextLine::Ptr longestLine;
float maxLength;
PointStruc select;
PointStruc anchor;
int aXPos;
int selectStart;
int selectEnd;
bool oldMarkState;
bool m_singleSelection; // false: windows-like, true: X11-like
bool readOnly;
bool newDoc; // True if the file is a new document (used to determine whether
// to check for overwriting files on save)
bool modified;
bool myWordWrap;
uint myWordWrapAt;
QList<KateActionGroup> undoList;
int currentUndo;
int undoState;
int undoSteps;
int tagStart;
int tagEnd;
int undoCount; //counts merged undo steps
QWidget *pseudoModal; //the replace prompt is pseudo modal
public:
/** Tjecks if the file on disk is newer than document contents.
If forceReload is true, the document is reloaded without asking the user,
otherwise [default] the user is asked what to do. */
void isModOnHD(bool forceReload=false);
uint docID () {return myDocID;};
QString docName () {return myDocName;};
void setDocName (QString docName);
+ void setDocFile (QString docFile);
public slots:
/** Reloads the current document from disk if possible */
void reloadFile();
private slots:
void slotModChanged ();
private:
/** updates mTime to reflect file on fs.
called from constructor and from saveFile. */
void setMTime();
uint myDocID;
QFileInfo* fileInfo;
QDateTime mTime;
QString myDocName;
QString m_url;
QString m_file;
void openURL(const QString &filename);
private:
KateCmd *myCmd;
public:
KateCmd *cmd () { return myCmd; };
private:
QString myEncoding;
public:
void setEncoding (QString e) { myEncoding = e; };
QString encoding() { return myEncoding; };
void setWordWrap (bool on);
bool wordWrap () { return myWordWrap; };
void setWordWrapAt (uint col);
uint wordWrapAt () { return myWordWrapAt; };
signals:
void modStateChanged (KateDocument *doc);
void nameChanged (KateDocument *doc);
public:
QList<Kate::Mark> marks ();
public slots:
// clear buffer/filename - update the views
void flush ();
signals:
/**
The file has been saved (perhaps the name has changed). The main window
can use this to change its caption
*/
void fileNameChanged ();
public:
//end of line settings
enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2};
// for the DCOP interface
public:
void open (const QString &name=0);
public:
// wrap the text of the document at the column col
void wrapText (uint col);
public slots:
void applyWordWrap ();
private:
- class KateDocPrivate
- {
- public:
- bool hlSetByUser;
- };
+ class KateDocPrivate
+ {
+ public:
+ bool hlSetByUser;
+ };
// BCI: Add a real d-pointer in the next BIC release
static QPtrDict<KateDocPrivate>* d_ptr;
static void cleanup_d_ptr()
{
delete d_ptr;
}
KateDocPrivate* d( const KateDocument* foo )
{
if ( !d_ptr ) {
d_ptr = new QPtrDict<KateDocPrivate>;
//qAddPostRoutine( cleanup_d_ptr );
}
KateDocPrivate* ret = d_ptr->find( (void*) foo );
if ( ! ret ) {
ret = new KateDocPrivate;
d_ptr->replace( (void*) foo, ret );
}
return ret;
}
void delete_d( const KateDocument* foo )
{
if ( d_ptr )
d_ptr->remove( (void*) foo );
}
};
#endif