Commit 67e01221 authored by Denis Khachko's avatar Denis Khachko

Merge branch 'master' of ssh://git.lpm.org.ru:7999/niisi/kumir2

parents d414a413 06856649
...@@ -140,8 +140,11 @@ def cmake_disabled_modules(): ...@@ -140,8 +140,11 @@ def cmake_disabled_modules():
def _split_into_branch_and_hash(s): def _split_into_branch_and_hash(s):
assert isinstance(s, str) assert isinstance(s, str)
index = s.rindex("-") index = s.rfind("-")
return s[:index], s[index+1:] if -1==index:
return s, "unknown"
else:
return s[:index], s[index+1:]
def cmake_version_info(): def cmake_version_info():
version_name = get_version_information(os.getcwd()) version_name = get_version_information(os.getcwd())
......
<?xml version='1.0' encoding='UTF-8'?>
<macros>
<macro title="использовать Чертежник" key="2" last="true">
<command name="InsertImport" text="Чертежник" />
</macros>
<?xml version='1.0' encoding='UTF-8'?>
<macros>
<macro title="использовать Вертун" key="4" last="true">
<command name="InsertImport" text="Вертун" />
</macros>
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<macros> <macros>
<macro title="использовать Рисователь" key="2"> <macro title="использовать Рисователь" key="3" last="true">
<command name="InsertImport" text="Рисователь" /> <command name="InsertImport" text="Рисователь" />
......
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<macros> <macros>
<macro title="использовать Робот" key="1"> <macro title="использовать Робот" key="1" last="true">
<command name="InsertImport" text="Робот" /> <command name="InsertImport" text="Робот" />
</macro> </macro>
<macro title="вверх" key="Up"> <macro title="вверх" key="Up">
......
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<macros> <macros>
<macro title="использовать Водолей" key="3"> <macro title="использовать Водолей" key="5" last="true">
<command name="InsertImport" text="Водолей" /> <command name="InsertImport" text="Водолей" />
......
...@@ -52,10 +52,14 @@ void EditorInstance::lock() ...@@ -52,10 +52,14 @@ void EditorInstance::lock()
if (toggleBreakpoint_) if (toggleBreakpoint_)
toggleBreakpoint_->setEnabled(false); toggleBreakpoint_->setEnabled(false);
for (int i=0; i<userMacros_.size(); i++) { for (int i=0; i<userMacros_.size(); i++) {
userMacros_[i].action->setEnabled(false); QSharedPointer<Macro> macro = userMacros_[i];
QAction * action = macro->action;
action->setEnabled(false);
} }
for (int i=0; i<systemMacros_.size(); i++) { for (int i=0; i<systemMacros_.size(); i++) {
systemMacros_[i].action->setEnabled(false); QSharedPointer<Macro> macro = systemMacros_[i];
QAction * action = macro->action;
action->setEnabled(false);
} }
} }
...@@ -71,10 +75,14 @@ void EditorInstance::unlock() ...@@ -71,10 +75,14 @@ void EditorInstance::unlock()
if (toggleBreakpoint_) if (toggleBreakpoint_)
toggleBreakpoint_->setEnabled(true); toggleBreakpoint_->setEnabled(true);
for (int i=0; i<userMacros_.size(); i++) { for (int i=0; i<userMacros_.size(); i++) {
userMacros_[i].action->setEnabled(true); QSharedPointer<Macro> macro = userMacros_[i];
QAction * action = macro->action;
action->setEnabled(true);
} }
for (int i=0; i<systemMacros_.size(); i++) { for (int i=0; i<systemMacros_.size(); i++) {
systemMacros_[i].action->setEnabled(true); QSharedPointer<Macro> macro = systemMacros_[i];
QAction * action = macro->action;
action->setEnabled(true);
} }
} }
...@@ -204,21 +212,21 @@ void EditorInstance::setLineHighlighted(int lineNo, const QColor &color, quint32 ...@@ -204,21 +212,21 @@ void EditorInstance::setLineHighlighted(int lineNo, const QColor &color, quint32
void EditorInstance::disableInsertActions() void EditorInstance::disableInsertActions()
{ {
foreach (Macro m , userMacros_) { foreach (QSharedPointer<Macro> m , userMacros_) {
m.action->setEnabled(false); m->action->setEnabled(false);
} }
foreach (Macro m , systemMacros_) { foreach (QSharedPointer<Macro> m , systemMacros_) {
m.action->setEnabled(false); m->action->setEnabled(false);
} }
} }
void EditorInstance::enableInsertActions() void EditorInstance::enableInsertActions()
{ {
foreach (Macro m , userMacros_) { foreach (QSharedPointer<Macro> m , userMacros_) {
m.action->setEnabled(true); m->action->setEnabled(true);
} }
foreach (Macro m , systemMacros_) { foreach (QSharedPointer<Macro> m , systemMacros_) {
m.action->setEnabled(true); m->action->setEnabled(true);
} }
} }
...@@ -296,12 +304,13 @@ void EditorInstance::loadMacros() ...@@ -296,12 +304,13 @@ void EditorInstance::loadMacros()
foreach (const KPlugin* plugin, actorPlugins) { foreach (const KPlugin* plugin, actorPlugins) {
ActorInterface * actor = qobject_cast<ActorInterface*>(plugin); ActorInterface * actor = qobject_cast<ActorInterface*>(plugin);
const QString canonicalName = actorCanonicalName<QString>(actor->asciiModuleName()); QString canonicalName = actorCanonicalName<QString>(actor->asciiModuleName());
canonicalName.remove(" ");
const QString actorMacrosFileName = plugin_->myResourcesDir().absoluteFilePath( const QString actorMacrosFileName = plugin_->myResourcesDir().absoluteFilePath(
"macros-" + analizerName + "-" + canonicalName + ".xml" "macros-" + analizerName + "-" + canonicalName + ".xml"
); );
if (QFile::exists(actorMacrosFileName)) { if (QFile::exists(actorMacrosFileName)) {
systemMacros_.push_back(Macro()); systemMacros_.push_back(QSharedPointer<Macro>(new Macro()));
systemMacros_ += loadFromFile(actorMacrosFileName); systemMacros_ += loadFromFile(actorMacrosFileName);
} }
} }
...@@ -356,66 +365,72 @@ ExtensionSystem::SettingsPtr EditorInstance::mySettings() const ...@@ -356,66 +365,72 @@ ExtensionSystem::SettingsPtr EditorInstance::mySettings() const
return plugin_->mySettings(); return plugin_->mySettings();
} }
static bool operator<(QSharedPointer<Macro> a, QSharedPointer<Macro> b) {
return a->key.unicode() < b->key.unicode();
}
void EditorInstance::updateInsertMenu() void EditorInstance::updateInsertMenu()
{ {
loadMacros(); loadMacros();
insertMenu_->clear(); insertMenu_->clear();
const QString escComa = "Esc, "; const QString escComa = "Esc, ";
for (int i=0; i<systemMacros_.size(); i++) { QVector< QList<QSharedPointer<Macro> > > groups(2);
Macro m = systemMacros_[i]; for (int i=0; i<systemMacros_.size(); ++i) {
if (m.title.isEmpty()) { QSharedPointer<Macro> m = systemMacros_[i];
int groupNo = m->showInLastBlock ? 1 : 0;
groups[groupNo].append(m);
}
qSort(groups[1]);
for (int z=0; z<2; ++z) {
QList<QSharedPointer<Macro> > group = groups[z];
if (1==z && groups[1].size() > 0) {
insertMenu_->addSeparator();
}
for (int i=0; i<group.size(); i++) {
QSharedPointer<Macro> m = group[i];
if (m->title.isEmpty()) {
// Separator // Separator
systemMacros_[i].action = insertMenu_->addSeparator(); m->action = insertMenu_->addSeparator();
} }
else { else {
m.action = new QAction(m.title, insertMenu_); m->action = new QAction(m->title, insertMenu_);
systemMacros_[i].action = m.action; insertMenu_->addAction(m->action);
insertMenu_->addAction(m.action); connect(m->action, SIGNAL(triggered()), this, SLOT(playMacro()));
connect(m.action, SIGNAL(triggered()), this, SLOT(playMacro())); if (!m->key.isNull()) {
if (!m.key.isNull()) { const QKeySequence ks2(escComa + QString(m->key));
// const QKeySequence ks(escComa+QString(Utils::latinKey(m.key))); m->action->setProperty("fakeShortcut", ks2.toString());
const QKeySequence ks2(escComa + QString(m.key));
m.action->setProperty("fakeShortcut", ks2.toString());
// if (ks == ks2) {
// m.action->setShortcut(ks);
// }
// else {
// const QList<QKeySequence> shortcuts = QList<QKeySequence>() << ks << ks2;
// m.action->setShortcuts(shortcuts);
// }
} }
else if (uint(m.extKey) != 0u) { else if (uint(m->extKey) != 0u) {
QString repr; QString repr;
if (m.extKey == Qt::Key_Left) if (m->extKey == Qt::Key_Left)
repr = "Left"; repr = "Left";
else if (m.extKey == Qt::Key_Right) else if (m->extKey == Qt::Key_Right)
repr = "Right"; repr = "Right";
else if (m.extKey == Qt::Key_Up) else if (m->extKey == Qt::Key_Up)
repr = "Up"; repr = "Up";
else if (m.extKey == Qt::Key_Down) else if (m->extKey == Qt::Key_Down)
repr = "Down"; repr = "Down";
else if (m.extKey == Qt::Key_Space) else if (m->extKey == Qt::Key_Space)
repr = "Space"; repr = "Space";
const QKeySequence ks(escComa + repr); const QKeySequence ks(escComa + repr);
m.action->setShortcut(ks); m->action->setShortcut(ks);
} }
} }
} }
}
if (!userMacros_.isEmpty()) if (!userMacros_.isEmpty())
insertMenu_->addSeparator(); insertMenu_->addSeparator();
for (int i=0; i<userMacros_.size(); i++) { for (int i=0; i<userMacros_.size(); i++) {
Macro m = userMacros_[i]; QSharedPointer<Macro> m = userMacros_[i];
m.action = new QAction(m.title, insertMenu_); m->action = new QAction(m->title, insertMenu_);
if (!m.key.isNull()) { if (!m->key.isNull()) {
const QKeySequence ks(escComa+QString(Utils::latinKey(m.key))); const QKeySequence ks(escComa+QString(Utils::latinKey(m->key)));
const QKeySequence ks2(escComa + QString(m.key)); const QKeySequence ks2(escComa + QString(m->key));
const QList<QKeySequence> shortcuts = QList<QKeySequence>() << ks << ks2; const QList<QKeySequence> shortcuts = QList<QKeySequence>() << ks << ks2;
m.action->setShortcuts(shortcuts); m->action->setShortcuts(shortcuts);
} }
userMacros_[i].action = m.action; insertMenu_->addAction(m->action);
insertMenu_->addAction(m.action); connect(m->action, SIGNAL(triggered()), this, SLOT(playMacro()));
connect(m.action, SIGNAL(triggered()), this, SLOT(playMacro()));
} }
editMacros_->setEnabled(userMacros_.size() > 0); editMacros_->setEnabled(userMacros_.size() > 0);
Widgets::CyrillicMenu * insMenu = qobject_cast<Widgets::CyrillicMenu*>(insertMenu_); Widgets::CyrillicMenu * insMenu = qobject_cast<Widgets::CyrillicMenu*>(insertMenu_);
...@@ -429,15 +444,15 @@ bool EditorInstance::tryEscKeyAction(const QString &text) ...@@ -429,15 +444,15 @@ bool EditorInstance::tryEscKeyAction(const QString &text)
if (text.length()!=1 && text.at(0).toLatin1()) { if (text.length()!=1 && text.at(0).toLatin1()) {
return false; // workarund required only for non-latin keys return false; // workarund required only for non-latin keys
} }
const QList<Macro> allMacros = systemMacros_ + userMacros_; const QList<QSharedPointer<Macro> > allMacros = systemMacros_ + userMacros_;
const QChar ch = text.at(0).toUpper(); const QChar ch = text.at(0).toUpper();
const QChar altCh = Utils::cyrillicKey(ch).toUpper(); const QChar altCh = Utils::cyrillicKey(ch).toUpper();
foreach (const Macro & m, allMacros) { foreach (QSharedPointer<Macro> m, allMacros) {
bool keyMatch = m.key.toUpper() == ch; bool keyMatch = m->key.toUpper() == ch;
bool altKeyMatch = m.key.toUpper() == altCh; bool altKeyMatch = m->key.toUpper() == altCh;
bool enabled = m.action && m.action->isEnabled(); bool enabled = m->action && m->action->isEnabled();
if ( (keyMatch || altKeyMatch) && enabled) { if ( (keyMatch || altKeyMatch) && enabled) {
m.action->trigger(); m->action->trigger();
return true; return true;
} }
} }
...@@ -470,18 +485,18 @@ void EditorInstance::playMacro() ...@@ -470,18 +485,18 @@ void EditorInstance::playMacro()
{ {
QAction * a = qobject_cast<QAction*>(sender()); QAction * a = qobject_cast<QAction*>(sender());
Q_CHECK_PTR(a); Q_CHECK_PTR(a);
Macro m; QSharedPointer<Macro> m;
bool found = false; bool found = false;
foreach (Macro mm, systemMacros_) { foreach (QSharedPointer<Macro> mm, systemMacros_) {
if (mm.action==a) { if (mm->action==a) {
found = true; found = true;
m = mm; m = mm;
break; break;
} }
} }
if (!found) { if (!found) {
foreach (Macro mm, userMacros_) { foreach (QSharedPointer<Macro> mm, userMacros_) {
if (mm.action==a) { if (mm->action==a) {
found = true; found = true;
m = mm; m = mm;
break; break;
...@@ -489,9 +504,9 @@ void EditorInstance::playMacro() ...@@ -489,9 +504,9 @@ void EditorInstance::playMacro()
} }
} }
if (found) { if (found) {
document()->undoStack()->beginMacro(m.title); document()->undoStack()->beginMacro(m->title);
for (int i=0; i<m.commands.size(); i++) { for (int i=0; i<m->commands.size(); i++) {
cursor_->evaluateCommand(m.commands[i]); cursor_->evaluateCommand(m->commands[i]);
} }
document()->undoStack()->endMacro(); document()->undoStack()->endMacro();
plane_->updateScrollBars(); plane_->updateScrollBars();
...@@ -1061,29 +1076,27 @@ void EditorInstance::toggleRecordMacro(bool on) ...@@ -1061,29 +1076,27 @@ void EditorInstance::toggleRecordMacro(bool on)
cursor_->startRecordMacro(); cursor_->startRecordMacro();
} }
else { else {
Macro * macro = cursor_->endRecordMacro(); QSharedPointer<Macro> macro = cursor_->endRecordMacro();
if (macro->commands.size() > 0) { if (macro->commands.size() > 0) {
MacroEditor * editor = new MacroEditor(this); MacroEditor * editor = new MacroEditor(this);
editor->setWindowTitle(tr("New keyboard sequence...")); editor->setWindowTitle(tr("New keyboard sequence..."));
QList<Macro> allMacros = systemMacros_ + userMacros_; QList<QSharedPointer<Macro> > allMacros = systemMacros_ + userMacros_;
QString usedLetters; QString usedLetters;
QStringList usedNames; QStringList usedNames;
foreach(Macro m, allMacros) { foreach(QSharedPointer<Macro> m, allMacros) {
if (!m.key.isNull()) { if (!m->key.isNull()) {
usedLetters.push_back(m.key); usedLetters.push_back(m->key);
usedNames.push_back(m.title); usedNames.push_back(m->title);
} }
} }
editor->setUsedSymbols(usedLetters, usedNames); editor->setUsedSymbols(usedLetters, usedNames);
editor->setMacro(macro); editor->setMacro(macro);
if (editor->exec() == QDialog::Accepted) { if (editor->exec() == QDialog::Accepted) {
Macro newMacro = *macro; userMacros_.push_back(macro);
userMacros_.push_back(newMacro);
plugin_->updateUserMacros(analizerPlugin_ ? analizerPlugin_->defaultDocumentFileNameSuffix() : QString(), userMacros_, true); plugin_->updateUserMacros(analizerPlugin_ ? analizerPlugin_->defaultDocumentFileNameSuffix() : QString(), userMacros_, true);
} }
editor->deleteLater(); editor->deleteLater();
} }
delete macro;
} }
emit recordMacroChanged(on); emit recordMacroChanged(on);
} }
......
...@@ -195,8 +195,8 @@ private /* fields */: ...@@ -195,8 +195,8 @@ private /* fields */:
QAction * separatorAction_; QAction * separatorAction_;
mutable QAction * toggleBreakpoint_; mutable QAction * toggleBreakpoint_;
QList<Macro> systemMacros_; QList<QSharedPointer<Macro>> systemMacros_;
QList<Macro> userMacros_; QList<QSharedPointer<Macro>> userMacros_;
int timerId_; int timerId_;
int autoScrollTimerId_; int autoScrollTimerId_;
......
...@@ -244,7 +244,7 @@ void EditorPlugin::connectGlobalSignalsToEditor(EditorInstance *editor) ...@@ -244,7 +244,7 @@ void EditorPlugin::connectGlobalSignalsToEditor(EditorInstance *editor)
} }
void EditorPlugin::updateUserMacros(const QString & analizerName, const QList<Macro> &macros, bool rewrite) void EditorPlugin::updateUserMacros(const QString & analizerName, const QList<QSharedPointer<Macro> > &macros, bool rewrite)
{ {
if (rewrite) { if (rewrite) {
QString fileName = analizerName.length() > 0 QString fileName = analizerName.length() > 0
......
...@@ -80,11 +80,11 @@ protected: ...@@ -80,11 +80,11 @@ protected:
inline void changeCurrentDirectory(const QString & path) { inline void changeCurrentDirectory(const QString & path) {
currentDirectory_ = path; currentDirectory_ = path;
updateSettings(QStringList()); updateSettings(QStringList());
updateUserMacros(QString(), QList<Macro>(), false); updateUserMacros(QString(), QList<QSharedPointer<Macro> >(), false);
} }
void start(); void start();
void stop(); void stop();
void updateUserMacros(const QString & analizerName, const QList<Macro> & macros, bool rewrite); void updateUserMacros(const QString & analizerName, const QList<QSharedPointer<Macro> > & macros, bool rewrite);
private: private:
struct Ed { struct Ed {
inline Ed() { e = 0; a=0; id =-1; } inline Ed() { e = 0; a=0; id =-1; }
......
...@@ -14,14 +14,14 @@ QString screenString(QString s) ...@@ -14,14 +14,14 @@ QString screenString(QString s)
return s; return s;
} }
extern QDomElement dumpMacro(const Macro &m, QDomDocument &document, QDomElement &root) extern QDomElement dumpMacro(QSharedPointer<Macro> m, QDomDocument &document, QDomElement &root)
{ {
QDomElement macroElement = document.createElement("macro"); QDomElement macroElement = document.createElement("macro");
macroElement.setAttribute("title", m.title); macroElement.setAttribute("title", m->title);
if (!m.key.isNull()) if (!m->key.isNull())
macroElement.setAttribute("key", m.key); macroElement.setAttribute("key", m->key);
for (int i=0; i<m.commands.size(); i++) { for (int i=0; i<m->commands.size(); i++) {
const KeyCommand & cmd = m.commands[i]; const KeyCommand & cmd = m->commands[i];
QDomElement commandElement = document.createElement("command"); QDomElement commandElement = document.createElement("command");
commandElement.setAttribute("name", dumpKeyCommandType(cmd.type)); commandElement.setAttribute("name", dumpKeyCommandType(cmd.type));
if (cmd.text.length() > 0) if (cmd.text.length() > 0)
...@@ -32,26 +32,28 @@ extern QDomElement dumpMacro(const Macro &m, QDomDocument &document, QDomElement ...@@ -32,26 +32,28 @@ extern QDomElement dumpMacro(const Macro &m, QDomDocument &document, QDomElement
return macroElement; return macroElement;
} }
extern bool loadMacro(const QDomElement &v, Macro &m) extern bool loadMacro(const QDomElement &v, QSharedPointer<Macro> m)
{ {
m.action = 0; m->action = 0;
m.commands.clear(); m->commands.clear();
m.title = v.attribute("title"); m->title = v.attribute("title");
const QString key = v.attribute("key").trimmed(); const QString key = v.attribute("key").trimmed();
const QString last = v.attribute("last", "false").toLower().trimmed();
m->showInLastBlock = last=="true" || last=="1";
if (key.length()==1) if (key.length()==1)
m.key = key[0]; m->key = key[0];
else else
m.key = QChar(QChar::Null); m->key = QChar(QChar::Null);
if ( key.toLower() == "up" ) if ( key.toLower() == "up" )
m.extKey = Qt::Key_Up; m->extKey = Qt::Key_Up;
else if ( key.toLower() == "down" ) else if ( key.toLower() == "down" )
m.extKey = Qt::Key_Down; m->extKey = Qt::Key_Down;
else if ( key.toLower() == "left" ) else if ( key.toLower() == "left" )
m.extKey = Qt::Key_Left; m->extKey = Qt::Key_Left;
else if ( key.toLower() == "right" ) else if ( key.toLower() == "right" )
m.extKey = Qt::Key_Right; m->extKey = Qt::Key_Right;
else if ( key.toLower() == "space" ) else if ( key.toLower() == "space" )
m.extKey = Qt::Key_Space; m->extKey = Qt::Key_Space;
const QDomNodeList commands = v.elementsByTagName("command"); const QDomNodeList commands = v.elementsByTagName("command");
for (int i=0; i<commands.count(); i++) { for (int i=0; i<commands.count(); i++) {
...@@ -64,21 +66,21 @@ extern bool loadMacro(const QDomElement &v, Macro &m) ...@@ -64,21 +66,21 @@ extern bool loadMacro(const QDomElement &v, Macro &m)
loadKeyCommandType(cmd.attribute("name")), loadKeyCommandType(cmd.attribute("name")),
text text
); );
m.commands.push_back(command); m->commands.push_back(command);
} }
return m.commands.size() > 0; return m->commands.size() > 0;
} }