Skip to content

Commit

Permalink
Work around FileManager/Language issues (IDE-181)
Browse files Browse the repository at this point in the history
- Auto-complete had no search paths because it had no access to
  the main project view, which did have paths.

- Add hacky, unsafe workaround to issue that FileManager is a
  GUI component instead of separate from the interface.

- This may justify working on new File system sooner.
  • Loading branch information
bweir committed Feb 13, 2016
1 parent fd16fec commit 0aaba81
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
27 changes: 13 additions & 14 deletions src/propelleride/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

#include "mainwindow.h"

Editor::Editor(QWidget *parent) : QPlainTextEdit(parent)
#include "logging.h"

Editor::Editor(Language * language, QWidget *parent) : QPlainTextEdit(parent)
{
this->language = language;
this->parser = language->getParser();

propDialog = &((MainWindow *) parent)->preferences;

blocks = lang.listBlocks();
re_blocks = lang.buildTokenizer(blocks);
blocks = language->listBlocks();
re_blocks = language->buildTokenizer(blocks);

ctrlPressed = false;
expectAutoComplete = false;
Expand Down Expand Up @@ -332,38 +337,32 @@ QString Editor::selectAutoComplete()
int Editor::spinAutoComplete()
{
QString text = selectAutoComplete();
// qDebug() << "keyPressEvent object dot pressed" << text;

QSettings settings;
settings.beginGroup("Paths");
lang.parser.setLibraryPaths(QStringList() << settings.value("Library").toString());
settings.endGroup();

cbAuto->clear();
cbAuto->addItem(".");

QList<ProjectParser::Match> matches;
if(text.length() > 0)
{
matches = lang.parser.matchRule("_includes_",toPlainText());
matches = parser->matchRule("_includes_",toPlainText());

QStringList filenames;
foreach(ProjectParser::Match m, matches)
{
if (m.exact.contains(text))
filenames << lang.parser.findFileName(m.pretty);
filenames << parser->findFileName(m.pretty);
}

if (!(filenames.count() > 0))
return 0;

lang.parser.setFile(filenames[0]);
parser->setFile(filenames[0]);

matches = lang.parser.matchRuleFromFile("public",filenames[0]);
matches = parser->matchRuleFromFile("public",filenames[0]);
}
else
{
matches = lang.parser.matchRule("public",toPlainText());
matches = parser->matchRule("public",toPlainText());

if (!(matches.count() > 0))
return 0;
Expand Down
23 changes: 13 additions & 10 deletions src/propelleride/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@
#include "highlighter.h"
#include "preferences.h"

#include "language.h"

class LineNumberArea;

class Editor : public QPlainTextEdit
{
Q_OBJECT

public:
Editor(QWidget *parent);
virtual ~Editor();

void saveContent();
int contentChanged();
Language * language;
ProjectParser * parser;

private:
Language lang;

QStringList blocks;
QRegularExpression re_blocks;

bool tabOn;

int tabStop;

bool smartIndent;
bool indentGuides;
bool autoComplete;
bool highlightLine;

public:
Editor(Language * language,
QWidget * parent);
virtual ~Editor();

void saveContent();
int contentChanged();

public slots:
bool getUndo();
bool getRedo();
Expand Down
8 changes: 7 additions & 1 deletion src/propelleride/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ FileManager::FileManager(QWidget *parent) :
connect(this, SIGNAL(currentChanged(int)), this, SLOT(changeTab(int)));
}

// THIS IS A HACK OMG SUCH A HACK
void FileManager::setLanguage(Language * language)
{
this->language = language;
}

int FileManager::newFile()
{
// removes the background image (need to move this elsewhere)
setStyleSheet("");

Editor *editor = new Editor(QWidget::window());
Editor * editor = new Editor(language, QWidget::window());
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->installEventFilter(QWidget::window());
editor->saveContent();
Expand Down
6 changes: 5 additions & 1 deletion src/propelleride/filemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#include <QMessageBox>
#include <QStatusBar>

#include "language.h"
#include "editor.h"
#include "logging.h"

class FileManager : public QTabWidget
{
Q_OBJECT
private:

Language * language;

void createBackgroundImage();
QString reformatText(QString text);

Expand All @@ -20,6 +23,7 @@ class FileManager : public QTabWidget
Editor * getEditor(int num);
int isFileOpen(const QString & fileName);
int isFileEmpty(int index);
void setLanguage(Language * language);

public slots:
int newFile();
Expand Down
4 changes: 2 additions & 2 deletions src/propelleride/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

class Language
{
private:
ProjectParser parser;

bool case_sensitive;
bool enable_blocks;
QString escape_char;
Expand All @@ -28,7 +29,6 @@ class Language
QStringList mergeList(QStringList list);

public:
ProjectParser parser;

void buildParser(QJsonArray projectparser);
void loadLanguage(QString filename);
Expand Down
4 changes: 4 additions & 0 deletions src/propelleride/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ MainWindow::MainWindow(QWidget *parent)
setWindowTitle(QCoreApplication::applicationName());
ui.setupUi(this);

// ===== HACK ZONE =====
ui.editorTabs->setLanguage(&language);
// ===== END HACK ZONE =====

// setup preferences dialog
connect(&preferences, SIGNAL(accepted()), this, SLOT(getApplicationSettings()));

Expand Down

0 comments on commit 0aaba81

Please sign in to comment.