add support for completion on file names
This commit is contained in:
@ -19,8 +19,10 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QDir>
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QDropEvent>
|
#include <QDropEvent>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@ -131,7 +133,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
|||||||
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)), group_comp(new QCompleter(this)),
|
units_comp(new QCompleter(this)), group_comp(new QCompleter(this)),
|
||||||
varname_comp(new QCompleter(this)), fixid_comp(new QCompleter(this)),
|
varname_comp(new QCompleter(this)), fixid_comp(new QCompleter(this)),
|
||||||
compid_comp(new QCompleter(this)), highlight(NO_HIGHLIGHT)
|
compid_comp(new QCompleter(this)), file_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);
|
||||||
@ -166,6 +168,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
|||||||
COMPLETER_SETUP(varname_comp);
|
COMPLETER_SETUP(varname_comp);
|
||||||
COMPLETER_SETUP(fixid_comp);
|
COMPLETER_SETUP(fixid_comp);
|
||||||
COMPLETER_SETUP(compid_comp);
|
COMPLETER_SETUP(compid_comp);
|
||||||
|
COMPLETER_SETUP(file_comp);
|
||||||
#undef COMPLETER_SETUP
|
#undef COMPLETER_SETUP
|
||||||
|
|
||||||
// initialize help system
|
// initialize help system
|
||||||
@ -233,6 +236,7 @@ CodeEditor::~CodeEditor()
|
|||||||
delete varname_comp;
|
delete varname_comp;
|
||||||
delete fixid_comp;
|
delete fixid_comp;
|
||||||
delete compid_comp;
|
delete compid_comp;
|
||||||
|
delete file_comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CodeEditor::lineNumberAreaWidth()
|
int CodeEditor::lineNumberAreaWidth()
|
||||||
@ -506,6 +510,16 @@ void CodeEditor::setFixIDList()
|
|||||||
fixid_comp->setModel(new QStringListModel(fixid, fixid_comp));
|
fixid_comp->setModel(new QStringListModel(fixid, fixid_comp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeEditor::setFileList()
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
QDir dir(".");
|
||||||
|
for (const auto &file : dir.entryInfoList(QDir::Files))
|
||||||
|
files << file.fileName();
|
||||||
|
files.sort();
|
||||||
|
file_comp->setModel(new QStringListModel(files, file_comp));
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEditor::keyPressEvent(QKeyEvent *event)
|
void CodeEditor::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
const auto key = event->key();
|
const auto key = event->key();
|
||||||
@ -801,6 +815,10 @@ void CodeEditor::runCompletion()
|
|||||||
else if ((words[0] == "change_box") || (words[0] == "displace_atoms") ||
|
else if ((words[0] == "change_box") || (words[0] == "displace_atoms") ||
|
||||||
(words[0] == "velocity") || (words[0] == "write_dump"))
|
(words[0] == "velocity") || (words[0] == "write_dump"))
|
||||||
current_comp = group_comp;
|
current_comp = group_comp;
|
||||||
|
else if ((words[0] == "fitpod") || (words[0] == "include") || (words[0] == "ndx2group") ||
|
||||||
|
(words[0] == "read_data") || (words[0] == "read_dump") ||
|
||||||
|
(words[0] == "read_restart") || (words[0] == "rerun"))
|
||||||
|
current_comp = file_comp;
|
||||||
else if (selected.startsWith("v_"))
|
else if (selected.startsWith("v_"))
|
||||||
current_comp = varname_comp;
|
current_comp = varname_comp;
|
||||||
else if (selected.startsWith("c_"))
|
else if (selected.startsWith("c_"))
|
||||||
@ -852,6 +870,8 @@ void CodeEditor::runCompletion()
|
|||||||
current_comp = fixid_comp;
|
current_comp = fixid_comp;
|
||||||
else if (selected.startsWith("F_"))
|
else if (selected.startsWith("F_"))
|
||||||
current_comp = fixid_comp;
|
current_comp = fixid_comp;
|
||||||
|
else if ((words[0] == "fitpod") || (words[0] == "molecule"))
|
||||||
|
current_comp = file_comp;
|
||||||
|
|
||||||
if (current_comp) {
|
if (current_comp) {
|
||||||
current_comp->setCompletionPrefix(words[2].c_str());
|
current_comp->setCompletionPrefix(words[2].c_str());
|
||||||
@ -879,6 +899,8 @@ void CodeEditor::runCompletion()
|
|||||||
current_comp = compute_comp;
|
current_comp = compute_comp;
|
||||||
else if (words[0] == "dump")
|
else if (words[0] == "dump")
|
||||||
current_comp = dump_comp;
|
current_comp = dump_comp;
|
||||||
|
else if ((words[0] == "pair_coeff") && (words[1] == "*") && (words[2] == "*"))
|
||||||
|
current_comp = file_comp;
|
||||||
else if (selected.startsWith("v_"))
|
else if (selected.startsWith("v_"))
|
||||||
current_comp = varname_comp;
|
current_comp = varname_comp;
|
||||||
else if (selected.startsWith("c_"))
|
else if (selected.startsWith("c_"))
|
||||||
|
|||||||
@ -60,6 +60,7 @@ public:
|
|||||||
void setVarNameList();
|
void setVarNameList();
|
||||||
void setComputeIDList();
|
void setComputeIDList();
|
||||||
void setFixIDList();
|
void setFixIDList();
|
||||||
|
void setFileList();
|
||||||
|
|
||||||
static constexpr int NO_HIGHLIGHT = 1 << 30;
|
static constexpr int NO_HIGHLIGHT = 1 << 30;
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ private:
|
|||||||
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, *group_comp,
|
*region_comp, *integrate_comp, *minimize_comp, *variable_comp, *units_comp, *group_comp,
|
||||||
*varname_comp, *fixid_comp, *compid_comp;
|
*varname_comp, *fixid_comp, *compid_comp, *file_comp;
|
||||||
|
|
||||||
int highlight;
|
int highlight;
|
||||||
bool reformat_on_return;
|
bool reformat_on_return;
|
||||||
|
|||||||
@ -305,6 +305,8 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
style_list.sort();
|
style_list.sort();
|
||||||
ui->textEdit->setUnitsList(style_list);
|
ui->textEdit->setUnitsList(style_list);
|
||||||
|
|
||||||
|
ui->textEdit->setFileList();
|
||||||
|
|
||||||
#define ADD_STYLES(keyword, Type) \
|
#define ADD_STYLES(keyword, Type) \
|
||||||
style_list.clear(); \
|
style_list.clear(); \
|
||||||
if ((std::string(#keyword) == "pair") || (std::string(#keyword) == "bond") || \
|
if ((std::string(#keyword) == "pair") || (std::string(#keyword) == "bond") || \
|
||||||
@ -596,6 +598,7 @@ void LammpsGui::open_file(const QString &fileName)
|
|||||||
ui->textEdit->setVarNameList();
|
ui->textEdit->setVarNameList();
|
||||||
ui->textEdit->setComputeIDList();
|
ui->textEdit->setComputeIDList();
|
||||||
ui->textEdit->setFixIDList();
|
ui->textEdit->setFixIDList();
|
||||||
|
ui->textEdit->setFileList();
|
||||||
file.close();
|
file.close();
|
||||||
dirstatus->setText(QString(" Directory: ") + current_dir);
|
dirstatus->setText(QString(" Directory: ") + current_dir);
|
||||||
status->setText("Ready.");
|
status->setText("Ready.");
|
||||||
@ -938,6 +941,7 @@ void LammpsGui::run_done()
|
|||||||
QString("Error running LAMMPS:\n\n") + errorbuf);
|
QString("Error running LAMMPS:\n\n") + errorbuf);
|
||||||
}
|
}
|
||||||
ui->textEdit->setCursor(nline);
|
ui->textEdit->setCursor(nline);
|
||||||
|
ui->textEdit->setFileList();
|
||||||
progress->hide();
|
progress->hide();
|
||||||
dirstatus->show();
|
dirstatus->show();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user