From 3a2ef8b7ec40d4f1ff07ca5007cdeecb5f327aa8 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Tue, 16 Feb 2016 17:40:08 +0000 Subject: [PATCH] remove doc readonly remove isTextFile --- qml/WebCodeEditor.qml | 7 ----- qml/js/ProjectModel.js | 1 - src/FileIo.cpp | 60 ------------------------------------------ src/FileIo.h | 2 -- 4 files changed, 70 deletions(-) diff --git a/qml/WebCodeEditor.qml b/qml/WebCodeEditor.qml index 8d835e6..de1254b 100644 --- a/qml/WebCodeEditor.qml +++ b/qml/WebCodeEditor.qml @@ -178,13 +178,6 @@ Item { { setText("File size is too large!", currentMode); setReadOnly(true); - document.readOnly = true; - } - else if (!fileIo.isFileText(document.path)) - { - setText("Can't read binary file!", currentMode); - setReadOnly(true); - document.readOnly = true; } else setText(currentText, currentMode); diff --git a/qml/js/ProjectModel.js b/qml/js/ProjectModel.js index 1c9e15f..5c3c02c 100644 --- a/qml/js/ProjectModel.js +++ b/qml/js/ProjectModel.js @@ -253,7 +253,6 @@ function file(docData) var groupName = isContract ? qsTr("Contracts") : isJs ? qsTr("Javascript") : isHtml ? qsTr("Web Pages") : isCss ? qsTr("Styles") : isImg ? qsTr("Images") : qsTr("Misc"); var docData = { contract: false, - readOnly: false, path: path, fileName: fileName, name: fileName, diff --git a/src/FileIo.cpp b/src/FileIo.cpp index 09a607c..1dae1c9 100644 --- a/src/FileIo.cpp +++ b/src/FileIo.cpp @@ -183,66 +183,6 @@ int FileIo::getFileSize(QString const& _url) return 0; } -bool FileIo::isFileText(QString const& _url) -{ - try - { - QString path = pathFromUrl(_url); - QFile file(path); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - QByteArray buf = file.read(file.bytesAvailable()); - - if (buf.size() >= 2) - { - //FF FE UTF - 16, little endian - if ((quint8)buf[0] == 0xFF && (quint8)buf[1] == 0xFE) - return true; - - //FE FF UTF - 16, big endian - if ((quint8)buf[0] == 0xFE && (quint8)buf[1] == 0xFF) - return true; - } - - if (buf.size() >= 3) - { - //EF BB BF UTF - 8 - if ((quint8)buf[0] == 0xEF && (quint8)buf[1] == 0xBB && (quint8)buf[2] == 0xBF) - return true; - } - - if (buf.size() >= 4) - { - //FF FE 00 00 UTF - 32, little endian - if ((quint8)buf[0] == 0xFF && (quint8)buf[1] == 0xFE && (quint8)buf[2] == 0x00 && (quint8)buf[3] == 0x00) - return true; - - //00 00 FE FF UTF - 32, big - endian - if ((quint8)buf[0] == 0x00 && (quint8)buf[1] == 0x00 && (quint8)buf[2] == 0xFE && (quint8)buf[3] == 0xFF) - return true; - } - - int checkLength = std::min(buf.size(), 1024000); - for (int i = 0; i < checkLength; i++) - { - if (!isascii(buf[i]) || - (iscntrl(buf[i]) && !isspace(buf[i]) && - buf[i] != '\b' && buf[i] != '\032' && buf[i] != '\033')) - return false; /* not all ASCII */ - } - return true; - } - else - error(tr("Error reading file %1").arg(_url)); - } - catch (...) - { - manageException(); - } - - return false; -} - void FileIo::writeFile(QString const& _url, QString const& _data) { try diff --git a/src/FileIo.h b/src/FileIo.h index d5c1d31..a0cb751 100644 --- a/src/FileIo.h +++ b/src/FileIo.h @@ -56,8 +56,6 @@ class FileIo: public QObject Q_INVOKABLE QString readFile(QString const& _url); /// Returns file size Q_INVOKABLE int getFileSize(QString const& _url); - /// Is file represent readable text - Q_INVOKABLE bool isFileText(QString const& _url); /// Write contents to a file. Signals on failure. Q_INVOKABLE void writeFile(QString const& _url, QString const& _data); /// Copy a file from _sourcePath to _destPath. Signals on failure.