add support for completion on file names
This commit is contained in:
@ -19,8 +19,10 @@
|
||||
#include <QAction>
|
||||
#include <QCompleter>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QKeySequence>
|
||||
#include <QMenu>
|
||||
@ -131,7 +133,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
||||
minimize_comp(new QCompleter(this)), variable_comp(new QCompleter(this)),
|
||||
units_comp(new QCompleter(this)), group_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);
|
||||
connect(help_action, &QShortcut::activated, this, &CodeEditor::get_help);
|
||||
@ -166,6 +168,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
|
||||
COMPLETER_SETUP(varname_comp);
|
||||
COMPLETER_SETUP(fixid_comp);
|
||||
COMPLETER_SETUP(compid_comp);
|
||||
COMPLETER_SETUP(file_comp);
|
||||
#undef COMPLETER_SETUP
|
||||
|
||||
// initialize help system
|
||||
@ -233,6 +236,7 @@ CodeEditor::~CodeEditor()
|
||||
delete varname_comp;
|
||||
delete fixid_comp;
|
||||
delete compid_comp;
|
||||
delete file_comp;
|
||||
}
|
||||
|
||||
int CodeEditor::lineNumberAreaWidth()
|
||||
@ -506,6 +510,16 @@ void CodeEditor::setFixIDList()
|
||||
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)
|
||||
{
|
||||
const auto key = event->key();
|
||||
@ -801,6 +815,10 @@ void CodeEditor::runCompletion()
|
||||
else if ((words[0] == "change_box") || (words[0] == "displace_atoms") ||
|
||||
(words[0] == "velocity") || (words[0] == "write_dump"))
|
||||
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_"))
|
||||
current_comp = varname_comp;
|
||||
else if (selected.startsWith("c_"))
|
||||
@ -852,6 +870,8 @@ void CodeEditor::runCompletion()
|
||||
current_comp = fixid_comp;
|
||||
else if (selected.startsWith("F_"))
|
||||
current_comp = fixid_comp;
|
||||
else if ((words[0] == "fitpod") || (words[0] == "molecule"))
|
||||
current_comp = file_comp;
|
||||
|
||||
if (current_comp) {
|
||||
current_comp->setCompletionPrefix(words[2].c_str());
|
||||
@ -879,6 +899,8 @@ void CodeEditor::runCompletion()
|
||||
current_comp = compute_comp;
|
||||
else if (words[0] == "dump")
|
||||
current_comp = dump_comp;
|
||||
else if ((words[0] == "pair_coeff") && (words[1] == "*") && (words[2] == "*"))
|
||||
current_comp = file_comp;
|
||||
else if (selected.startsWith("v_"))
|
||||
current_comp = varname_comp;
|
||||
else if (selected.startsWith("c_"))
|
||||
|
||||
Reference in New Issue
Block a user