Skip to content

Commit

Permalink
add readonly param to openDocuments
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Feb 18, 2016
1 parent 6cf0e1b commit 5f46218
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
20 changes: 19 additions & 1 deletion qml/CodeEditorView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Item {
signal breakpointsChanged(string documentId)
signal isCleanChanged(var isClean, var document)
signal loadComplete
signal changeDocument(var document)
signal documentClosed(string path)

onDocumentClosed:
Expand Down Expand Up @@ -134,6 +135,9 @@ Item {
editor.onLoadComplete.connect(function() {
codeEditorView.loadComplete();
});
editor.onChangeDocument.connect(function() {
codeEditorView.changeDocument(editor.document);
});
editor.onEditorTextChanged.connect(function() {
documentEdit(editor.document.documentId);
if (editor.document.isContract)
Expand Down Expand Up @@ -321,7 +325,7 @@ Item {
for (var i = 0; i < editorListModel.count; i++)
{
var doc = editorListModel.get(i);
if (doc.path === document.path)
if (doc.path === document.path && !document.readOnly)
{
fileIo.writeFile(document.path, editors.itemAt(i).item.getText());
break;
Expand Down Expand Up @@ -384,6 +388,20 @@ Item {
loadComplete()
}

Connections
{
target: mainContent.codeEditor
onChangeDocument: {
var docs = mainContent.codeEditor.openedDocuments();
for (var d = 0; d < editorListModel.count; d++)
{
if (editorListModel.get(d).path === document.path)
editorListModel.get(d).readOnly = document.readOnly;
}
console.log("signal " + editorListModel.count);
}
}

Connections
{
target: projectModel
Expand Down
8 changes: 6 additions & 2 deletions qml/WebCodeEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Item {
signal breakpointsChanged
signal editorTextChanged
signal loadComplete
signal changeDocument(var document)
property bool isClean: true
property string currentText: ""
property string currentMode: ""
Expand Down Expand Up @@ -172,18 +173,21 @@ Item {
{
if (!loading && editorBrowser) {
initialized = true;
setFontSize(fontSize);

setFontSize(fontSize);
var size = fileIo.getFileSize(document.path);
if (size > c_max_open_filesize)
{
setText("File size is too large!", currentMode);
setReadOnly(true);
document.readOnly = true;
changeDocument(document);
}
else if (!fileIo.isFileText(document.path))
{
setText("Can't read binary file!", currentMode);
setReadOnly(true);
document.readOnly = true;
changeDocument(document);
}
else
setText(currentText, currentMode);
Expand Down
1 change: 1 addition & 0 deletions qml/js/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ 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,
Expand Down
3 changes: 2 additions & 1 deletion src/FileIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ bool FileIo::isFileText(QString const& _url)
return true;
}

for (int i = 0; i < buf.size(); i++)
int checkLength = std::min(buf.size(), 1024000);
for (int i = 0; i < checkLength; i++)
{
if (!isascii(buf[i]) ||
(iscntrl(buf[i]) && !isspace(buf[i]) &&
Expand Down

0 comments on commit 5f46218

Please sign in to comment.