add completion for group id
This commit is contained in:
@ -129,7 +129,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
|||||||
improper_comp(new QCompleter(this)), kspace_comp(new QCompleter(this)),
|
improper_comp(new QCompleter(this)), kspace_comp(new QCompleter(this)),
|
||||||
region_comp(new QCompleter(this)), integrate_comp(new QCompleter(this)),
|
region_comp(new QCompleter(this)), integrate_comp(new QCompleter(this)),
|
||||||
minimize_comp(new QCompleter(this)), variable_comp(new QCompleter(this)),
|
minimize_comp(new QCompleter(this)), variable_comp(new QCompleter(this)),
|
||||||
units_comp(new QCompleter(this)), highlight(NO_HIGHLIGHT)
|
units_comp(new QCompleter(this)), group_comp(new QCompleter(this)), highlight(NO_HIGHLIGHT)
|
||||||
{
|
{
|
||||||
help_action = new QShortcut(QKeySequence::fromString("Ctrl+?"), parent);
|
help_action = new QShortcut(QKeySequence::fromString("Ctrl+?"), parent);
|
||||||
connect(help_action, &QShortcut::activated, this, &CodeEditor::get_help);
|
connect(help_action, &QShortcut::activated, this, &CodeEditor::get_help);
|
||||||
@ -160,6 +160,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
|||||||
COMPLETER_SETUP(minimize_comp);
|
COMPLETER_SETUP(minimize_comp);
|
||||||
COMPLETER_SETUP(variable_comp);
|
COMPLETER_SETUP(variable_comp);
|
||||||
COMPLETER_SETUP(units_comp);
|
COMPLETER_SETUP(units_comp);
|
||||||
|
COMPLETER_SETUP(group_comp);
|
||||||
#undef COMPLETER_SETUP
|
#undef COMPLETER_SETUP
|
||||||
|
|
||||||
// initialize help system
|
// initialize help system
|
||||||
@ -223,6 +224,7 @@ CodeEditor::~CodeEditor()
|
|||||||
delete minimize_comp;
|
delete minimize_comp;
|
||||||
delete variable_comp;
|
delete variable_comp;
|
||||||
delete units_comp;
|
delete units_comp;
|
||||||
|
delete group_comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CodeEditor::lineNumberAreaWidth()
|
int CodeEditor::lineNumberAreaWidth()
|
||||||
@ -284,6 +286,8 @@ QString CodeEditor::reformatLine(const QString &line)
|
|||||||
int namesize = settings.value("name", "8").toInt();
|
int namesize = settings.value("name", "8").toInt();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
bool rebuildGroupComp = false;
|
||||||
|
|
||||||
if (words.size()) {
|
if (words.size()) {
|
||||||
// commented line. do nothing
|
// commented line. do nothing
|
||||||
if (words[0][0] == '#') return line;
|
if (words[0][0] == '#') return line;
|
||||||
@ -293,6 +297,8 @@ QString CodeEditor::reformatLine(const QString &line)
|
|||||||
if (words.size() > 1) {
|
if (words.size() > 1) {
|
||||||
for (int i = words[0].size() + 1; i < cmdsize; ++i)
|
for (int i = words[0].size() + 1; i < cmdsize; ++i)
|
||||||
newtext += ' ';
|
newtext += ' ';
|
||||||
|
// new/updated group command -> update completer
|
||||||
|
if (words[0] == "group") rebuildGroupComp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// append remaining words with just a single blank added.
|
// append remaining words with just a single blank added.
|
||||||
@ -329,6 +335,7 @@ QString CodeEditor::reformatLine(const QString &line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (rebuildGroupComp) setGroupList();
|
||||||
return newtext;
|
return newtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +364,28 @@ COMPLETER_INIT_FUNC(units, Units)
|
|||||||
|
|
||||||
#undef COMPLETER_INIT_FUNC
|
#undef COMPLETER_INIT_FUNC
|
||||||
|
|
||||||
|
// build completer for groups by parsing through edit buffer
|
||||||
|
|
||||||
|
void CodeEditor::setGroupList()
|
||||||
|
{
|
||||||
|
QStringList groups;
|
||||||
|
QRegularExpression groupcmd(QStringLiteral("^\\s*group\\s+(\\S+)(\\s+|$)"));
|
||||||
|
auto saved = textCursor();
|
||||||
|
// reposition cursor to beginning of text and search for group commands
|
||||||
|
auto cursor = textCursor();
|
||||||
|
cursor.movePosition(QTextCursor::Start);
|
||||||
|
setTextCursor(cursor);
|
||||||
|
while (find(groupcmd)) {
|
||||||
|
auto words = textCursor().block().text().replace('\t', ' ').split(' ', Qt::SkipEmptyParts);
|
||||||
|
if (words.size() > 1) groups << words[1];
|
||||||
|
}
|
||||||
|
groups.sort();
|
||||||
|
groups.prepend(QStringLiteral("all"));
|
||||||
|
|
||||||
|
setTextCursor(saved);
|
||||||
|
group_comp->setModel(new QStringListModel(groups, group_comp));
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEditor::keyPressEvent(QKeyEvent *event)
|
void CodeEditor::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
const auto key = event->key();
|
const auto key = event->key();
|
||||||
@ -630,6 +659,9 @@ void CodeEditor::runCompletion()
|
|||||||
current_comp = minimize_comp;
|
current_comp = minimize_comp;
|
||||||
else if (words[0] == "units")
|
else if (words[0] == "units")
|
||||||
current_comp = units_comp;
|
current_comp = units_comp;
|
||||||
|
else if ((words[0] == "change_box") || (words[0] == "displace_atoms") ||
|
||||||
|
(words[0] == "velocity") || (words[0] == "write_dump"))
|
||||||
|
current_comp = group_comp;
|
||||||
|
|
||||||
if (current_comp) {
|
if (current_comp) {
|
||||||
current_comp->setCompletionPrefix(words[1].c_str());
|
current_comp->setCompletionPrefix(words[1].c_str());
|
||||||
@ -655,6 +687,12 @@ void CodeEditor::runCompletion()
|
|||||||
current_comp = region_comp;
|
current_comp = region_comp;
|
||||||
else if (words[0] == "variable")
|
else if (words[0] == "variable")
|
||||||
current_comp = variable_comp;
|
current_comp = variable_comp;
|
||||||
|
else if (words[0] == "fix")
|
||||||
|
current_comp = group_comp;
|
||||||
|
else if (words[0] == "compute")
|
||||||
|
current_comp = group_comp;
|
||||||
|
else if (words[0] == "dump")
|
||||||
|
current_comp = group_comp;
|
||||||
|
|
||||||
if (current_comp) {
|
if (current_comp) {
|
||||||
current_comp->setCompletionPrefix(words[2].c_str());
|
current_comp->setCompletionPrefix(words[2].c_str());
|
||||||
|
|||||||
@ -56,6 +56,7 @@ public:
|
|||||||
void setMinimizeList(const QStringList &words);
|
void setMinimizeList(const QStringList &words);
|
||||||
void setVariableList(const QStringList &words);
|
void setVariableList(const QStringList &words);
|
||||||
void setUnitsList(const QStringList &words);
|
void setUnitsList(const QStringList &words);
|
||||||
|
void setGroupList();
|
||||||
|
|
||||||
static constexpr int NO_HIGHLIGHT = 1 << 30;
|
static constexpr int NO_HIGHLIGHT = 1 << 30;
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ private:
|
|||||||
QShortcut *help_action;
|
QShortcut *help_action;
|
||||||
QCompleter *current_comp, *command_comp, *fix_comp, *compute_comp, *dump_comp, *atom_comp,
|
QCompleter *current_comp, *command_comp, *fix_comp, *compute_comp, *dump_comp, *atom_comp,
|
||||||
*pair_comp, *bond_comp, *angle_comp, *dihedral_comp, *improper_comp, *kspace_comp,
|
*pair_comp, *bond_comp, *angle_comp, *dihedral_comp, *improper_comp, *kspace_comp,
|
||||||
*region_comp, *integrate_comp, *minimize_comp, *variable_comp, *units_comp;
|
*region_comp, *integrate_comp, *minimize_comp, *variable_comp, *units_comp, *group_comp;
|
||||||
|
|
||||||
int highlight;
|
int highlight;
|
||||||
bool reformat_on_return;
|
bool reformat_on_return;
|
||||||
|
|||||||
@ -627,6 +627,7 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
ui->textEdit->document()->setPlainText(text);
|
ui->textEdit->document()->setPlainText(text);
|
||||||
ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
|
ui->textEdit->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
|
||||||
ui->textEdit->document()->setModified(false);
|
ui->textEdit->document()->setModified(false);
|
||||||
|
ui->textEdit->setGroupList();
|
||||||
file.close();
|
file.close();
|
||||||
dirstatus->setText(QString(" Directory: ") + current_dir);
|
dirstatus->setText(QString(" Directory: ") + current_dir);
|
||||||
status->setText("Ready.");
|
status->setText("Ready.");
|
||||||
|
|||||||
Reference in New Issue
Block a user