Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jan 13, 2012
1 parent a01c4ae commit c72e89a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,7 +5,7 @@ test/build/*
*.Debug
*.Release
*.tbc
package
OpenTuring
debug
release
Makefile
Binary file renamed package.zip → OpenTuring.zip
Binary file not shown.
4 changes: 0 additions & 4 deletions QScintilla/lexers/LexTuring.cpp
Expand Up @@ -73,10 +73,6 @@ static void ColouriseTuringDoc(
}

StyleContext sc(startPos, length, initStyle, styler);
if (startPos == 0 && sc.ch == '#') {
// shbang line: # is a comment only if first char of the script
sc.SetState(SCE_LUA_COMMENTLINE);
}
for (; sc.More(); sc.Forward()) {
if (sc.atLineEnd) {
// Update the line state, so it can be seen by next line
Expand Down
2 changes: 2 additions & 0 deletions TuringEditor/documentmanager.cpp
Expand Up @@ -116,6 +116,8 @@ TuringEditorWidget *DocumentManager::newFile() {

documents.append(doc);

setCurrentWidget(doc);

return doc;
}

Expand Down
3 changes: 2 additions & 1 deletion TuringEditor/documentmanager.h
Expand Up @@ -28,12 +28,13 @@ public slots:
bool promptCloseAll();
void clearAllErrors();

void closeTab (int index);

void handleErrorFile(int line,QString errMsg, QString file, int from, int to);



private slots:
void closeTab(int index);
void currentTabChanged(int index);
void updateName(TuringEditorWidget *doc);
void documentChanged(bool state);
Expand Down
17 changes: 16 additions & 1 deletion TuringEditor/mainwindow.cpp
Expand Up @@ -76,6 +76,8 @@ MainWindow::MainWindow()
runDoc = NULL;

readSettings();

docMan->currentDoc()->setFocus();
}

QSize MainWindow::sizeHint() const {
Expand Down Expand Up @@ -134,11 +136,12 @@ void MainWindow::runProgram() {

void MainWindow::compileComplete(bool success) {
if (success){
if (currentRunner != NULL) {
if (currentRunner != NULL && currentRunner->isCompiled()) {
statusBar()->showMessage(tr("Compile suceeded. Running..."));
currentRunner->startRun();
}
} else {
currentRunner = NULL;
statusBar()->showMessage(tr("Compile failed."));
}
}
Expand Down Expand Up @@ -185,6 +188,11 @@ void MainWindow::open()
}
}

void MainWindow::closeTab()
{
docMan->closeTab(docMan->currentIndex());
}

void MainWindow::addRecentFile(const QString &fileName) {
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
Expand Down Expand Up @@ -269,6 +277,11 @@ void MainWindow::createActions()
settingsAct->setStatusTip(tr("Change settings/preferences."));
connect(settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));

closeTabAct = new QAction(tr("&Close Tab"), this);
closeTabAct->setShortcut(tr("Ctrl+W"));
closeTabAct->setStatusTip(tr("Closes the current file"));
connect(closeTabAct, SIGNAL(triggered()), this, SLOT(closeTab()));

helpAct = new QAction(QIcon(":/images/help.png"),tr("Turing &Help"), this);
helpAct->setShortcut(Qt::Key_F10);
helpAct->setStatusTip(tr("Open Turing help."));
Expand Down Expand Up @@ -322,6 +335,7 @@ void MainWindow::createActions()
docMan->multiplex->connect(saveAct, SIGNAL(triggered()), SLOT(save()));

saveAsAct = new QAction(tr("Save &As..."), this);
saveAsAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_S);
saveAsAct->setStatusTip(tr("Save the document under a new name"));
docMan->multiplex->connect(saveAsAct, SIGNAL(triggered()), SLOT(saveAs()));

Expand Down Expand Up @@ -378,6 +392,7 @@ void MainWindow::createMenus()
fileMenu->addMenu(recentMenu);
fileMenu->addAction(saveAct);
fileMenu->addAction(saveAsAct);
fileMenu->addAction(closeTabAct);
fileMenu->addAction(runAct);
fileMenu->addSeparator();

Expand Down
3 changes: 3 additions & 0 deletions TuringEditor/mainwindow.h
Expand Up @@ -69,6 +69,8 @@ private slots:
void populateMarkMenu();
void goToMark();

void closeTab();

void cursorMoved(int line, int index);

void runProgram();
Expand Down Expand Up @@ -126,6 +128,7 @@ private slots:
QAction *exitAct;
QAction *cutAct;
QAction *copyAct;
QAction *closeTabAct;
QAction *pasteAct;
QAction *aboutAct;
QAction *aboutQtAct;
Expand Down
Empty file.
29 changes: 26 additions & 3 deletions TuringEditor/turingeditorwidget.cpp
Expand Up @@ -313,8 +313,8 @@ QList<TuringEditorWidget::POILine*> TuringEditorWidget::findPOIs() {
QList<TuringEditorWidget::POILine*> pois;

QRegExp endRegex("[\\t ]*end[\\t ]+([_a-zA-Z0-9]+).*");
QRegExp funcRegex("[\\t ]*(body +|pervasive +)*(proc|procedure|fcn|function|class|module)[\\t\\* ]+([_a-zA-Z0-9]+).*");
QRegExp structRegex("[\\t ]*(if|for|loop|case|record|monitor|union|handler).*");
QRegExp funcRegex("[\\t ]*(body +|pervasive +)*(proc|procedure|fcn|function|class|module|process|monitor)[\\t\\* ]+([_a-zA-Z0-9]+).*");
QRegExp structRegex("[\\t ]*(if|for|loop|case|record|union|handler).*");

// -1 to account for zero-indexing
int lastLine = lines()-1;
Expand Down Expand Up @@ -435,19 +435,42 @@ void TuringEditorWidget::autoIndentAll() {
QList<TuringEditorWidget::POILine *> pois;
pois = findPOIs(); // TODO FIXME memory leaked

// lines that are indented one less than the rest of the body
QRegExp oneLess("(else|elsif|label).*");
// next line is indented if one of these is at the end
QRegExp endContinue(".*(,|or|and)");

// reset everything. Removes hard tabs
for(int i = 0; i < lines();++i) {
setIndentation(i,0);
}

int lastLine = 0;
int curLevel = 0;
bool nextInd = false; // indent next line
foreach(TuringEditorWidget::POILine *poi, pois) {
// all the lines before the first POI should have 0 indent
for(int i = lastLine + 1; i <= poi->line;++i) {
setIndentation(i,curLevel * tabWidth());
int indent = curLevel * tabWidth();
QString line = text(i).trimmed();

if(nextInd) {
indent += tabWidth();
nextInd = false;
}

if(oneLess.exactMatch(line)) {
indent -= tabWidth();
}

if(endContinue.exactMatch(line)) {
nextInd = true;
}

setIndentation(i,indent);
}


if(poi->type == "end") {
setIndentation(poi->line,(curLevel-1) * tabWidth());
curLevel--;
Expand Down

0 comments on commit c72e89a

Please sign in to comment.