Browse Source

- add optimize code action menuitem

cl-refactor
yann300 10 years ago
parent
commit
7049251ce9
  1. 8
      mix/CodeModel.cpp
  2. 3
      mix/CodeModel.h
  3. 11
      mix/qml/Application.qml

8
mix/CodeModel.cpp

@ -309,7 +309,7 @@ void CodeModel::runCompilationJob(int _jobId)
sourceNames.push_back(c.first.toStdString());
}
}
cs.compile(false);
cs.compile(m_optimizeCode);
gasEstimation(cs);
collectContracts(cs, sourceNames);
}
@ -599,6 +599,12 @@ QString CodeModel::resolveFunctionName(dev::SourceLocation const& _location)
return QString();
}
void CodeModel::setOptimizeCode(bool _value)
{
m_optimizeCode = _value;
emit scheduleCompilationJob(++m_backgroundJobId);
}
void GasMapWrapper::push(QString _source, int _start, int _end, QString _value, bool _isInfinite, QString _payload)
{
GasMap* gas = new GasMap(_start, _end, _value, _isInfinite, _payload, this);

3
mix/CodeModel.h

@ -179,6 +179,7 @@ public:
Q_PROPERTY(QVariantMap contracts READ contracts NOTIFY codeChanged)
Q_PROPERTY(bool compiling READ isCompiling NOTIFY stateChanged)
Q_PROPERTY(bool hasContract READ hasContract NOTIFY codeChanged)
Q_PROPERTY(bool optimizeCode MEMBER m_optimizeCode WRITE setOptimizeCode)
/// @returns latest compilation results for contracts
QVariantMap contracts() const;
@ -211,6 +212,7 @@ public:
void gasEstimation(solidity::CompilerStack const& _cs);
/// Gas cost by doc id
Q_INVOKABLE QVariantList gasCostByDocumentId(QString const& _documentId) const;
Q_INVOKABLE void setOptimizeCode(bool _value);
signals:
/// Emited on compilation state change
@ -255,6 +257,7 @@ private:
std::map<QString, dev::bytes> m_compiledContracts; //by name
dev::Mutex x_pendingContracts;
std::map<QString, QString> m_pendingContracts; //name to source
bool m_optimizeCode;
friend class BackgroundWorker;
};

11
mix/qml/Application.qml

@ -119,6 +119,7 @@ ApplicationWindow {
Menu {
title: qsTr("Tools")
MenuItem { action: gasEstimationAction }
MenuItem { action: optimizeCodeAction }
}
Menu {
title: qsTr("Windows")
@ -424,4 +425,14 @@ ApplicationWindow {
mainContent.codeEditor.displayGasEstimation(checked);
}
}
Action {
id: optimizeCodeAction
text: qsTr("Optimize contract code")
shortcut: "Ctrl+Shift+O"
checkable: true
checked: true
Component.onCompleted: codeModel.setOptimizeCode(true);
onTriggered: codeModel.setOptimizeCode(checked);
}
}

Loading…
Cancel
Save