summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Wenninger <jowenn@kde.org>2014-01-24 02:20:17 (GMT)
committerJoseph Wenninger <jowenn@kde.org>2014-01-24 02:20:17 (GMT)
commitabdfa809c6056941f0194911ac6a41c035919703 (patch)
tree3e4f2bd1b5f12d5327e921dba6116fb4fb9fbd5b
parent5a5c7f37c061bf8b68346861057848df65268b7a (diff)
The message that appears after loading, if lines have been wrapped because of being longer than the configured limit allows now to temporarily raise the limit and reload the file. Once there are working remote io-slaves this has to be tested if it also works in that case. For local files it works
-rw-r--r--autotests/src/kateencodingtest.cpp3
-rw-r--r--autotests/src/katetextbuffertest.cpp3
-rw-r--r--src/buffer/katetextbuffer.cpp5
-rw-r--r--src/buffer/katetextbuffer.h3
-rw-r--r--src/document/katebuffer.cpp8
-rw-r--r--src/document/katebuffer.h10
-rw-r--r--src/document/katedocument.cpp40
-rw-r--r--src/document/katedocument.h15
8 files changed, 77 insertions, 10 deletions
diff --git a/autotests/src/kateencodingtest.cpp b/autotests/src/kateencodingtest.cpp
index e06ded3..81587aa 100644
--- a/autotests/src/kateencodingtest.cpp
+++ b/autotests/src/kateencodingtest.cpp
@@ -46,7 +46,8 @@ int main(int argc, char *argv[])
// load file
bool encodingErrors = false;
bool tooLongLines = false;
- if (!buffer.load(inFile, encodingErrors, tooLongLines, false) || encodingErrors) {
+ int longestLineLoaded;
+ if (!buffer.load(inFile, encodingErrors, tooLongLines, longestLineLoaded, false) || encodingErrors) {
return 1;
}
diff --git a/autotests/src/katetextbuffertest.cpp b/autotests/src/katetextbuffertest.cpp
index 9fda71f..163c540 100644
--- a/autotests/src/katetextbuffertest.cpp
+++ b/autotests/src/katetextbuffertest.cpp
@@ -447,7 +447,8 @@ void KateTextBufferTest::saveFileInUnwritableFolder()
buffer.setTextCodec(QTextCodec::codecForName("UTF-8"));
buffer.setFallbackTextCodec(QTextCodec::codecForName("UTF-8"));
bool a, b;
- buffer.load(file_path, a, b, true);
+ int c;
+ buffer.load(file_path, a, b, c, true);
buffer.clear();
buffer.startEditing();
buffer.insertText(KTextEditor::Cursor(0, 0), QLatin1String("ABC"));
diff --git a/src/buffer/katetextbuffer.cpp b/src/buffer/katetextbuffer.cpp
index 60fe0ca..d033136 100644
--- a/src/buffer/katetextbuffer.cpp
+++ b/src/buffer/katetextbuffer.cpp
@@ -535,7 +535,7 @@ void TextBuffer::debugPrint(const QString &title) const
}
}
-bool TextBuffer::load(const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, bool enforceTextCodec)
+bool TextBuffer::load(const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, int &longestLineLoaded, bool enforceTextCodec)
{
// fallback codec must exist
Q_ASSERT(m_fallbackTextCodec);
@@ -615,6 +615,9 @@ bool TextBuffer::load(const QString &filename, bool &encodingErrors, bool &tooLo
// get unicode data for this line
const QChar *unicodeData = file.unicode() + offset;
+
+ if (longestLineLoaded < length) longestLineLoaded=length;
+
/**
* split lines, if too large
*/
diff --git a/src/buffer/katetextbuffer.h b/src/buffer/katetextbuffer.h
index e774110..47d6469 100644
--- a/src/buffer/katetextbuffer.h
+++ b/src/buffer/katetextbuffer.h
@@ -203,11 +203,12 @@ public:
* @param filename file to open
* @param encodingErrors were there problems occurred while decoding the file?
* @param tooLongLinesWrapped were too long lines found and wrapped?
+ * @param longestLineLoaded the longest line in the file (before wrapping)
* @param enforceTextCodec enforce to use only the set text codec
* @return success, the file got loaded, perhaps with encoding errors
* Virtual, can be overwritten.
*/
- virtual bool load(const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, bool enforceTextCodec);
+ virtual bool load(const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, int &longestLineLoaded, bool enforceTextCodec);
/**
* Save the current buffer content to the given file.
diff --git a/src/document/katebuffer.cpp b/src/document/katebuffer.cpp
index 4a86201..c256b86 100644
--- a/src/document/katebuffer.cpp
+++ b/src/document/katebuffer.cpp
@@ -51,6 +51,7 @@ KateBuffer::KateBuffer(KTextEditor::DocumentPrivate *doc)
m_doc(doc),
m_brokenEncoding(false),
m_tooLongLinesWrapped(false),
+ m_longestLineLoaded(0),
m_highlight(0),
m_tabWidth(8),
m_lineHighlighted(0),
@@ -143,6 +144,7 @@ void KateBuffer::clear()
// reset the state
m_brokenEncoding = false;
m_tooLongLinesWrapped = false;
+ m_longestLineLoaded = 0;
// back to line 0 with hl
m_lineHighlighted = 0;
@@ -162,11 +164,12 @@ bool KateBuffer::openFile(const QString &m_file, bool enforceTextCodec)
// over the years again and again. bugs: 306926, 239077, ...
// line length limit
- setLineLengthLimit(m_doc->config()->lineLengthLimit());
+ setLineLengthLimit(m_doc->lineLengthLimit());
// then, try to load the file
m_brokenEncoding = false;
m_tooLongLinesWrapped = false;
+ m_longestLineLoaded = 0;
/**
* allow non-existent files without error, if local file!
@@ -200,7 +203,7 @@ bool KateBuffer::openFile(const QString &m_file, bool enforceTextCodec)
/**
* try to load
*/
- if (!load(m_file, m_brokenEncoding, m_tooLongLinesWrapped, enforceTextCodec)) {
+ if (!load(m_file, m_brokenEncoding, m_tooLongLinesWrapped, m_longestLineLoaded, enforceTextCodec)) {
return false;
}
@@ -268,6 +271,7 @@ bool KateBuffer::saveFile(const QString &m_file)
// no longer broken encoding, or we don't care
m_brokenEncoding = false;
m_tooLongLinesWrapped = false;
+ m_longestLineLoaded = 0;
// okay
return true;
diff --git a/src/document/katebuffer.h b/src/document/katebuffer.h
index c1af056..b3b99c3 100644
--- a/src/document/katebuffer.h
+++ b/src/document/katebuffer.h
@@ -133,6 +133,11 @@ public:
return m_tooLongLinesWrapped;
}
+ int longestLineLoaded() const
+ {
+ return m_longestLineLoaded;
+ }
+
/**
* Can the current codec handle all chars
* @return chars can be encoded
@@ -262,6 +267,11 @@ private:
bool m_tooLongLinesWrapped;
/**
+ * length of the longest line loaded
+ */
+ int m_longestLineLoaded;
+
+ /**
* current highlighting mode or 0
*/
KateHighlighting *m_highlight;
diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
index 52e4900..dfbb74b 100644
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@ -138,7 +138,8 @@ KTextEditor::DocumentPrivate::DocumentPrivate(bool bSingleViewMode,
m_documentState(DocumentIdle),
m_readWriteStateBeforeLoading(false),
m_isUntitled(true),
- m_openingError(false)
+ m_openingError(false),
+ m_lineLengthLimitOverride(0)
{
setComponentData(KTextEditor::EditorPrivate::self()->aboutData());
@@ -2024,6 +2025,32 @@ void KTextEditor::DocumentPrivate::showAndSetOpeningErrorAccess()
}
//END: error
+
+void KTextEditor::DocumentPrivate::openWithLineLengthLimitOverride()
+{
+ m_lineLengthLimitOverride=m_buffer->longestLineLoaded()+1;
+ m_buffer->clear();
+ openFile();
+ if (!m_openingError) {
+ setReadWrite(true);
+ m_readWriteStateBeforeLoading=true;
+ }
+ m_lineLengthLimitOverride=0;
+
+}
+
+int KTextEditor::DocumentPrivate::lineLengthLimit()
+{
+ int result;
+ if (m_lineLengthLimitOverride>0) {
+ result=m_lineLengthLimitOverride;
+ } else {
+ result=config()->lineLengthLimit();
+ }
+
+ return result;
+}
+
//BEGIN KParts::ReadWrite stuff
bool KTextEditor::DocumentPrivate::openFile()
{
@@ -2111,6 +2138,7 @@ bool KTextEditor::DocumentPrivate::openFile()
if (m_buffer->brokenEncoding()) {
// this file can't be saved again without killing it
setReadWrite(false);
+ m_readWriteStateBeforeLoading=false;
QPointer<KTextEditor::Message> message
= new KTextEditor::Message(i18n("The file %1 was opened with %2 encoding but contained invalid characters.<br />"
"It is set to read-only mode, as saving might destroy its content.<br />"
@@ -2134,16 +2162,22 @@ bool KTextEditor::DocumentPrivate::openFile()
m_readWriteStateBeforeLoading=false;
QPointer<KTextEditor::Message> message
= new KTextEditor::Message(i18n("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters).<br />"
+ "The longest of those lines was %3 characters long<br/>"
"Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.",
- this->url().toString(), config()->lineLengthLimit()),
+ this->url().toString(), config()->lineLengthLimit(),m_buffer->longestLineLoaded()),
KTextEditor::Message::Warning);
+ QAction *increaseAndReload=new QAction(i18n("Temporarily raise limit and reload file"),message);
+ connect(increaseAndReload,SIGNAL(triggered()),this,SLOT(openWithLineLengthLimitOverride()));
+ message->addAction(increaseAndReload,true);
+ message->addAction(new QAction(i18n("Close"),message),true);
message->setWordWrap(true);
postMessage(message);
// remember error
m_openingError = true;
m_openingErrorMessage = i18n("The file %1 was opened and contained lines longer than the configured Line Length Limit (%2 characters)."
- " Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", this->url().toString(), config()->lineLengthLimit());
+ "The longest of those lines was %3 characters long<br/>"
+ "Those lines were wrapped and the document is set to read-only mode, as saving will modify its content.", this->url().toString(), config()->lineLengthLimit(),m_buffer->longestLineLoaded());
}
//
diff --git a/src/document/katedocument.h b/src/document/katedocument.h
index 3f1d07f..6580481 100644
--- a/src/document/katedocument.h
+++ b/src/document/katedocument.h
@@ -1284,7 +1284,20 @@ private:
* Last open file error message
*/
QString m_openingErrorMessage;
+
+ /**
+ *
+ */
+ int m_lineLengthLimitOverride;
+
+public:
+ /**
+ * reads the line length limit from config, if it is not overriden
+ */
+ int lineLengthLimit();
+
+public Q_SLOTS:
+ void openWithLineLengthLimitOverride();
};
#endif
-