Browse Source

small usability fixes

cl-refactor
arkpar 10 years ago
parent
commit
2a39486972
  1. 1
      mix/CodeModel.cpp
  2. 120
      mix/qml/CodeEditor.qml
  3. 13
      mix/qml/CodeEditorView.qml
  4. 17
      mix/qml/NewProjectDialog.qml
  5. 20
      mix/qml/ProjectList.qml
  6. 2
      mix/qml/StateDialog.qml
  7. 98
      mix/qml/WebCodeEditor.qml
  8. 6
      mix/qml/html/WebContainer.html

1
mix/CodeModel.cpp

@ -46,6 +46,7 @@ CompilationResult::CompilationResult():
m_successful(false), m_successful(false),
m_codeHash(qHash(QString())), m_codeHash(qHash(QString())),
m_contract(new QContractDefinition()), m_contract(new QContractDefinition()),
m_contractInterface("[]"),
m_codeHighlighter(new CodeHighlighter()) m_codeHighlighter(new CodeHighlighter())
{} {}

120
mix/qml/CodeEditor.qml

@ -4,78 +4,76 @@ import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1 import QtQuick.Controls.Styles 1.1
Component { Item {
Item { signal editorTextChanged
signal editorTextChanged
function setText(text) { function setText(text) {
codeEditor.text = text; codeEditor.text = text;
} }
function getText() { function getText() {
return codeEditor.text; return codeEditor.text;
} }
anchors.fill: parent anchors.fill: parent
id: contentView id: contentView
width: parent.width width: parent.width
height: parent.height * 0.7 height: parent.height * 0.7
Rectangle { Rectangle {
id: lineColumn id: lineColumn
property int rowHeight: codeEditor.font.pixelSize + 3 property int rowHeight: codeEditor.font.pixelSize + 3
color: "#202020" color: "#202020"
width: 50 width: 50
height: parent.height height: parent.height
Column { Column {
y: -codeEditor.flickableItem.contentY + 4 y: -codeEditor.flickableItem.contentY + 4
width: parent.width width: parent.width
Repeater { Repeater {
model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight)) model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight))
delegate: Text { delegate: Text {
id: text id: text
color: codeEditor.textColor color: codeEditor.textColor
font: codeEditor.font font: codeEditor.font
width: lineColumn.width - 4 width: lineColumn.width - 4
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
height: lineColumn.rowHeight height: lineColumn.rowHeight
renderType: Text.NativeRendering renderType: Text.NativeRendering
text: index + 1 text: index + 1
}
} }
} }
} }
}
TextArea { TextArea {
id: codeEditor id: codeEditor
textColor: "#EEE8D5" textColor: "#EEE8D5"
style: TextAreaStyle { style: TextAreaStyle {
backgroundColor: "#002B36" backgroundColor: "#002B36"
} }
anchors.left: lineColumn.right anchors.left: lineColumn.right
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
wrapMode: TextEdit.NoWrap wrapMode: TextEdit.NoWrap
frameVisible: false frameVisible: false
height: parent.height height: parent.height
font.family: "Monospace" font.family: "Monospace"
font.pointSize: 12 font.pointSize: 12
width: parent.width width: parent.width
tabChangesFocus: false tabChangesFocus: false
Keys.onPressed: { Keys.onPressed: {
if (event.key === Qt.Key_Tab) { if (event.key === Qt.Key_Tab) {
codeEditor.insert(codeEditor.cursorPosition, "\t"); codeEditor.insert(codeEditor.cursorPosition, "\t");
event.accepted = true; event.accepted = true;
}
} }
onTextChanged: {
editorTextChanged();
}
} }
onTextChanged: {
editorTextChanged();
}
} }
} }

13
mix/qml/CodeEditorView.qml

@ -56,18 +56,15 @@ Item {
} }
} }
CodeEditor {
id: codeEditor
}
Repeater { Repeater {
id: editors id: editors
model: editorListModel model: editorListModel
delegate: Loader { delegate: Loader {
active: false; id: loader
active: false
asynchronous: true asynchronous: true
anchors.fill: parent anchors.fill: parent
sourceComponent: codeEditor source: "CodeEditor.qml"
visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId) visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId)
onVisibleChanged: { onVisibleChanged: {
loadIfNotLoaded() loadIfNotLoaded()
@ -75,7 +72,9 @@ Item {
Component.onCompleted: { Component.onCompleted: {
loadIfNotLoaded() loadIfNotLoaded()
} }
onLoaded: { doLoadDocument(item, editorListModel.get(index)) } onLoaded: {
doLoadDocument(loader.item, editorListModel.get(index))
}
function loadIfNotLoaded () { function loadIfNotLoaded () {
if(visible && !active) { if(visible && !active) {

17
mix/qml/NewProjectDialog.qml

@ -26,6 +26,11 @@ Window {
visible = false; visible = false;
} }
function acceptAndClose() {
close();
accepted();
}
GridLayout { GridLayout {
id: dialogContent id: dialogContent
columns: 2 columns: 2
@ -41,6 +46,10 @@ Window {
id: titleField id: titleField
focus: true focus: true
Layout.fillWidth: true Layout.fillWidth: true
Keys.onReturnPressed: {
if (okButton.enabled)
acceptAndClose();
}
} }
Label { Label {
@ -50,6 +59,10 @@ Window {
TextField { TextField {
id: pathField id: pathField
Layout.fillWidth: true Layout.fillWidth: true
Keys.onReturnPressed: {
if (okButton.enabled)
acceptAndClose();
}
} }
Button { Button {
text: qsTr("Browse") text: qsTr("Browse")
@ -63,11 +76,11 @@ Window {
anchors.right: parent.right; anchors.right: parent.right;
Button { Button {
id: okButton;
enabled: titleField.text != "" && pathField.text != "" enabled: titleField.text != "" && pathField.text != ""
text: qsTr("OK"); text: qsTr("OK");
onClicked: { onClicked: {
close(); acceptAndClose();
accepted();
} }
} }
Button { Button {

20
mix/qml/ProjectList.qml

@ -10,7 +10,7 @@ Item {
Text { Text {
Layout.fillWidth: true Layout.fillWidth: true
color: "blue" color: "blue"
text: projectModel.projectData ? projectModel.projectData.title : "" text: projectModel.projectTitle
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
visible: !projectModel.isEmpty; visible: !projectModel.isEmpty;
} }
@ -117,12 +117,18 @@ Item {
contextMenu.popup(); contextMenu.popup();
} }
} }
Connections { }
target: projectModel }
onProjectLoaded: { Connections {
projectList.currentIndex = 0; target: projectModel
} onProjectLoaded: {
} projectList.currentIndex = 0;
if (projectList.currentIndex >= 0 && projectList.currentIndex < projectModel.listModel.count)
projectModel.openDocument(projectModel.listModel.get(projectList.currentIndex).documentId);
}
onProjectClosed: {
projectList.currentIndex = -1;
} }
} }
} }

2
mix/qml/StateDialog.qml

@ -184,7 +184,7 @@ Window {
if (transactionDialog.transactionIndex < transactionsModel.count) { if (transactionDialog.transactionIndex < transactionsModel.count) {
transactionsModel.set(transactionDialog.transactionIndex, item); transactionsModel.set(transactionDialog.transactionIndex, item);
stateTransactions[index] = item; stateTransactions[transactionDialog.transactionIndex] = item;
} else { } else {
transactionsModel.append(item); transactionsModel.append(item);
stateTransactions.push(item); stateTransactions.push(item);

98
mix/qml/WebCodeEditor.qml

@ -5,64 +5,62 @@ import QtQuick.Controls.Styles 1.1
import CodeEditorExtensionManager 1.0 import CodeEditorExtensionManager 1.0
import QtWebEngine 1.0 import QtWebEngine 1.0
Component { Item {
Item { signal editorTextChanged
signal editorTextChanged property string currentText: ""
property string currentText: "" property string currentMode: ""
property string currentMode: "" property bool initialized: false
property bool initialized: false
function setText(text, mode) { function setText(text, mode) {
currentText = text; currentText = text;
currentMode = mode; currentMode = mode;
if (initialized) { if (initialized) {
editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")"); editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")");
editorBrowser.runJavaScript("setMode(\"" + mode + "\")"); editorBrowser.runJavaScript("setMode(\"" + mode + "\")");
}
editorBrowser.forceActiveFocus();
} }
editorBrowser.forceActiveFocus();
}
function getText() { function getText() {
return currentText; return currentText;
} }
anchors.top: parent.top anchors.top: parent.top
id: codeEditorView id: codeEditorView
anchors.fill: parent
WebEngineView {
id: editorBrowser
url: "qrc:///qml/html/codeeditor.html"
anchors.fill: parent anchors.fill: parent
WebEngineView { onJavaScriptConsoleMessage: {
id: editorBrowser console.log("editor: " + sourceID + ":" + lineNumber + ":" + message);
url: "qrc:///qml/html/codeeditor.html" }
anchors.fill: parent
onJavaScriptConsoleMessage: {
console.log("editor: " + sourceID + ":" + lineNumber + ":" + message);
}
onLoadingChanged: onLoadingChanged:
{ {
if (!loading) { if (!loading) {
initialized = true; initialized = true;
setText(currentText, currentMode); setText(currentText, currentMode);
runJavaScript("getTextChanged()", function(result) { }); runJavaScript("getTextChanged()", function(result) { });
pollTimer.running = true; pollTimer.running = true;
}
} }
}
Timer Timer
{ {
id: pollTimer id: pollTimer
interval: 30 interval: 30
running: false running: false
repeat: true repeat: true
onTriggered: { onTriggered: {
editorBrowser.runJavaScript("getTextChanged()", function(result) { editorBrowser.runJavaScript("getTextChanged()", function(result) {
if (result === true) { if (result === true) {
editorBrowser.runJavaScript("getText()" , function(textValue) { editorBrowser.runJavaScript("getText()" , function(textValue) {
currentText = textValue; currentText = textValue;
editorTextChanged(); editorTextChanged();
}); });
} }
}); });
}
} }
} }
} }

6
mix/qml/html/WebContainer.html

@ -16,11 +16,11 @@ reloadPage = function() {
preview.contentWindow.location.reload(); preview.contentWindow.location.reload();
}; };
updateContract = function(address, definition) { updateContract = function(address, contractFace) {
if (window.web3) { if (window.web3) {
window.contractAddress = address; window.contractAddress = address;
window.contractDefinition = definition; window.contractInterface = contractFace;
window.contract = window.web3.eth.contract(address, definition); window.contract = window.web3.eth.contract(address, contractFace);
} }
}; };

Loading…
Cancel
Save