summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-26 03:48:32 (UTC)
committer llornkcor <llornkcor>2002-12-26 03:48:32 (UTC)
commitf736bf0ae774159a80a97b9492d7624e7caf07a3 (patch) (side-by-side diff)
tree6e66396c264e2d878920ba273487c81abe7a474e
parent451d6a8692cf65d970b0c582e96e8a59072df191 (diff)
downloadopie-f736bf0ae774159a80a97b9492d7624e7caf07a3.zip
opie-f736bf0ae774159a80a97b9492d7624e7caf07a3.tar.gz
opie-f736bf0ae774159a80a97b9492d7624e7caf07a3.tar.bz2
added setDocFile function to change the filename needs more work
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
@@ -299,64 +299,65 @@ void KateDocument::openURL(const QString &filename)
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 );
@@ -1896,65 +1897,66 @@ void KateDocument::tagLines(int start, int end) {
}
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;
}
}
@@ -3001,64 +3003,70 @@ found:
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();
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
@@ -425,64 +425,65 @@ class KateDocument: public Kate::Document
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; };
@@ -499,69 +500,69 @@ class KateDocument: public Kate::Document
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