Fix problem with partial loading of files
[vlp.git] / src / edit / editor.cpp
index b51dcc96aa6b780349379b8189787417e22bab1b..2315c0e1f5d75b9b66b7e4f6bb409ce7622502a9 100644 (file)
 #include <QtGui/QFileDialog>
 #include <QtGui/QColor>
 #include <QtGui/QPalette>
-#include <QtGui/QCloseEvent>
 #include <QtGui/QTextDocument>
 #include <QtGui/QMainWindow>
 #include <QtGui/QStatusBar>
 #include <QtGui/QCheckBox>
 #include <QtGui/QVBoxLayout>
+#include <QtGui/QListWidget>
+#include <QtGui/QListWidgetItem>
 
-#include "editor.h"
+#include "ProgramStructureDialog.h"
+#include "UnitStructureDialog.h"
+#include "PreferencesDialog.h"
+#include "FindDialog.h"
 
-#define TYPENUM        5
+#include "editor.h"
 
-Editor *editor;
+namespace loglan {
+namespace vlp {
 
 /**
- * @attention Currently not in use
- */
-char *UnitTypes[TYPENUM] = {
-       "CLASS",
-       "PROCEDURE",
-       "FUNCTION",
-       "PROCESS",
-       "COROUTINE"
-};
-
-/**
- * My_Edit constructor. Initializes and sets variables of Multiline editor
- * widget.
- * @param parent Parent widget of this widget. If set, this widget becomes a 
- *               child window inside parent. If not set this widget becomes a
- *               top level window. Default: NULL
- * @param name @deprecated If set, name is sent to the Qobject constructor, so widget is
- *             identifiable (e.g. in Qt Designer)
- */
-My_Edit::My_Edit(QWidget *parent, const char *name)
-       : QTextEdit(parent)
-{
-       parent = NULL;
-       name = NULL;
-}
-
-/**
- * @copydoc QWidget::keyPressEvent(QKeyEvent*)
+ * Editor constructor. Initializes and sets variables of Loglan Editor.
+ *
+ * @param argc command line argc parameter
+ * @param argv command line argv parameter
  */
-void My_Edit::keyPressEvent(QKeyEvent *ev)
+Editor::Editor(int argc, char **argv)
 {
-       QTextEdit::keyPressEvent(ev);
-       emit cursorMove();
-}
+       setupUi(this);
 
-/**
- * Event invoked on program close.
- * @copydoc QWidget::closeEvent(QCloseEvent*)
- */
-void Editor::closeEvent(QCloseEvent * e) {
-       e->accept();
-}
+       if (argc > 1) {
+               strcpy(HomeDir, argv[1]);
+               fprintf(stderr, "EDIT: HomeDir inited with: %s (%s)\n", HomeDir, argv[1]);
+       }
 
-/**
- * Editor constructor. Initializes and sets variables of Loglan Editor.
- * @param hdir Home directory of program (specified in configuration file)
- * @param parent Parent widget of this widget. If set, this widget becomes a 
- *               child window inside parent. If not set this widget becomes a
- *               top level window. Default: NULL
- * @param name If set, name is sent to the Qobject constructor, so widget is
- *             identifiable (e.g. in Qt Designer)
- */
-Editor::Editor(char *hdir, QWidget * parent)
-       : QMainWindow(parent)
-{
-       strcpy(HomeDir, hdir);
        find_text = "";
        sensitive = FALSE;
-       QMenu * file = NULL;
-/*     QMenu * comp = new QMenu();*/
-/*     QMenu * loglan = new QMenu();*/
-       QMenu * medit = NULL;
-       QAction* action = NULL;
-
-       file = menuBar()->addMenu("&File");
-       medit = menuBar()->addMenu("&Edit");
-
-       action = menuBar()->addAction("&Compile", this, SLOT(cmp()));
-
-       /*    m->insertItem( "&LOGLAN ", loglan );*/
-
-       action = menuBar()->addAction("&Properties", this, SLOT(props()));
-
-       file->addAction("New", this, SLOT(create()), QKeySequence(Qt::CTRL + Qt::Key_N));
-       file->addAction("Open", this, SLOT(load()), QKeySequence(Qt::CTRL + Qt::Key_O));
-       file->addAction("Save", this, SLOT(save()), QKeySequence(Qt::CTRL + Qt::Key_S));
-       file->addAction("Save as", this, SLOT(save_as()), QKeySequence(Qt::CTRL + Qt::Key_A));
-       file->addSeparator();
-       file->addAction("Quit ", this, SLOT(close()));
-
-       /* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
-       /* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
-       /* comp->insertItem("Compile & Gen ", this, SLOT(comp_all()));*/
-
-       /* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
-       /* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
-
-       e = new My_Edit(this, "editor");
-       connect(e, SIGNAL(cursorMove()), this, SLOT(updateline()));
-       medit->addAction("Copy", e, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_Insert));
-       medit->addAction("Paste", e, SLOT(paste()), QKeySequence(Qt::SHIFT + Qt::Key_Insert));
-       medit->addAction("Cut", e, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_Delete));
-       medit->addAction("Clear All", e, SLOT(clear()));
-       medit->addSeparator();
-       medit->addAction("Find", this, SLOT(findText()), QKeySequence(Qt::CTRL + Qt::Key_F));
-       medit->addAction("Find Next", this, SLOT(find_next()), QKeySequence(Qt::CTRL + Qt::Key_L));
-
-       msg = new QTextEdit(this);
-       msg->setReadOnly(TRUE);
-
-       QVBoxLayout * layout = new QVBoxLayout();
-       layout->setContentsMargins (3, 0, 3, 0);
-       layout->addWidget(e);
-       layout->addWidget(msg);
-       QWidget *window = new QWidget();
-       window->setLayout(layout);
-       setCentralWidget(window);
 
        compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
        gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
        file_path.sprintf("%s", HomeDir);
-
-       QColor col(200, 200, 200);
-       QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col);
-
-       msg->setPalette(grp);
-
-       position = new QLabel();
-       statusBar()->addPermanentWidget(position);
+       
+       
+       connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(on_editor_cursorPositionChanged()));
 }
 
 /**
@@ -150,117 +59,44 @@ Editor::~Editor()
 /**
  * Displays line:column position of cursor
  */
-void Editor::updateline()
+void Editor::on_editor_cursorPositionChanged()
 {
-       char pom[255];
+       QString position;
        int cx;
        int cy;
 
-       cx = e->textCursor().blockNumber();
-       cy = e->textCursor().columnNumber();
-       sprintf(pom,"%d:%d ", cx, cy);
-       position->setText(pom);
-}
+       cx = editor->textCursor().blockNumber();
+       cy = editor->textCursor().columnNumber();
+       position.sprintf("%d:%d", cx, cy);
 
-/**
- * Event invoked on resizing editor application window.
- * @copydoc QWidget::resizeEvent(QResizeEvent*)
- * @param event Currently does nothing
- */
-void Editor::resizeEvent(QResizeEvent *event)
-{
-/*
-TODO: Remove entire method?
-       if (e && m) {
-               e->setGeometry(0, m->height(), width(),
-                               3 * (int)((height() - m->height()) / 4));
-
-               msg->setGeometry(0, m->height() + e->height(), width(),
-                               (int)((height() - m->height()) / 4));
-
-               position->setGeometry(width() - 80,
-                                               m->height() + e->height() - 10,
-                                               position->width(),
-                                               position->height());
-       }
-*/
-}
-
-/**
- * Displays additional window 
- */
-void Editor::load()
-{
-       QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log");
-       if (!fn.isEmpty())
-               load(fn.toAscii().data());
+       statusBar()->showMessage(position);
 }
 
 /**
  * Loads given file content to the editor.
+ *
  * @param fileName Filename of file which will be read.
  */
 void Editor::load(const char *fileName)
 {
        fname.sprintf("%s", fileName);
 
-       QFile f(fileName);
-       if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
+       QFile file(fileName);
+       if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                return;
 
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       e->setAutoUpdate(FALSE);
-*/
-       e->clear();
+       editor->clear();
 
-       QTextStream t(&f);
-       while (!t.atEnd()) {
-               QString s = t.readLine();
-               e->append(s);
-       }
-       f.close();
+       QTextStream textStream(&file);
+       editor->append(textStream.readAll());
+//     while (!file.atEnd()) {
+//             editor->append(textStream.readLine());
+//     }
 
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       e->setAutoUpdate(TRUE);
-*/
-       e->repaint();
-       setWindowTitle(fileName);
-}
+       file.close();
 
-/**
- * Saves editor content to the file.
- * If content has been read from file, it is written to this file. Otherwise
- * dialog is shown to save content to the specified by user, file.
- */
-void Editor::save()
-{
-       if (fname.isEmpty()) {
-               QString fn = QFileDialog::getSaveFileName(this, "Save file", 
-                                                       file_path, "*.log");
-               if (!fn.isEmpty()) {
-                       fname.sprintf("%s", fn.toAscii().data());
-                       save(fn.toAscii().data());
-               }
-       } else {
-               save(fname.toAscii().data());
-       }
-       setWindowTitle(fname);
-}
-
-/**
- * Saves editor content to the file.
- * Forces saving editor content to the new file. Special dialog is shown for
- * that purpose.
- */
-void Editor::save_as()
-{
-       QString fn = QFileDialog::getSaveFileName(this, "Save file as",
-                                                       file_path, "*.log");
-       if (!fn.isEmpty()) {
-               fname.sprintf("%s", fn.toAscii().data());
-               save(fn.toAscii().data());
-       }
-       setWindowTitle(fname);
+       editor->repaint();
+       setWindowTitle(fileName);
 }
 
 /**
@@ -269,60 +105,13 @@ void Editor::save_as()
  */
 void Editor::save(const char *fileName)
 {
-       QFile f(fileName);
-       if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
+       QFile file(fileName);
+       if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                return;
-       f.reset();
-       f.write(e->toPlainText().toAscii().data(), e->toPlainText().length());
-       f.close();
-}
-
-/**
- * Empties editor content.
- */
-void Editor::create()
-{
-       e->clear();
-       fname.sprintf("%s", "");
-}
-
-/**
- * @attention Currently not in use
- */
-void Editor::print()
-{
-}
-
-/**
- * @attention Currently not in use.
- * 
- * Saves and compiles code.
- */
-void Editor::cmp()
-{
-       save();
-       compile(COMP_MODE);
-}
-
-/**
- * @attention Currently not in use.
- * 
- * Generates program.
- */
-void Editor::gen()
-{
-       compile(GEN_MODE);
-}
 
-/**
- * @attention Currently not in use.
- * 
- * Saves, compiles and generates code.
- */
-void Editor::comp_all()
-{
-       save();
-       compile(ALL_MODE);
+       file.reset();
+       file.write(editor->toPlainText().toAscii().data(), editor->toPlainText().length());
+       file.close();
 }
 
 /**
@@ -335,12 +124,9 @@ void Editor::comp_all()
 void Editor::compile(int mode)
 {
        char cmd[255];
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       msg->setAutoUpdate(FALSE);
-*/
-       msg->setReadOnly(FALSE);
-       msg->clear();
-       msg->repaint();
+       messages->setReadOnly(FALSE);
+       messages->clear();
+       messages->repaint();
 
        /*i = fname.find('.');*/
        /* if (i>=0) {*/
@@ -348,19 +134,19 @@ void Editor::compile(int mode)
        /*  fn.truncate(i);*/
        switch(mode) {
        case COMP_MODE:
-               sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
-                                                       fname.toAscii().data());
+               sprintf(cmd, "%s %s > comp_data!", compiler_path.toStdString().c_str(),
+                                                       fname.toStdString().c_str());
                break;
        case GEN_MODE:
-               sprintf(cmd, "%s %s > comp_data!", gen_path.toAscii().data(),
-                                                       fname.toAscii().data());
+               sprintf(cmd, "%s %s > comp_data!", gen_path.toStdString().c_str(),
+                                                       fname.toStdString().c_str());
                break;
        case ALL_MODE:
-               sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
-                                                       fname.toAscii().data());
+               sprintf(cmd, "%s %s > comp_data!", compiler_path.toStdString().c_str(),
+                                                       fname.toStdString().c_str());
                system(cmd);
-               sprintf(cmd, "%s %s >> comp_data!", gen_path.toAscii().data(),
-                                                       fname.toAscii().data());
+               sprintf(cmd, "%s %s >> comp_data!", gen_path.toStdString().c_str(),
+                                                       fname.toStdString().c_str());
        break;
        }
 
@@ -372,214 +158,90 @@ void Editor::compile(int mode)
        QTextStream t(&f);
        while (!t.atEnd()) {
                QString s = t.readLine();
-               msg->append(s);
+               messages->append(s);
        }
        f.close();
 
-       msg->setReadOnly(TRUE);
+       messages->setReadOnly(TRUE);
 
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       msg->setAutoUpdate(TRUE);
-*/
-       msg->repaint();
+       messages->repaint();
        unlink("comp_data!");
        /*}*/
 }
 
 /**
- * Displays window with editor properties
+ * Empties editor content.
  */
-void Editor::props()
+void Editor::on_actionNew_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-
-       QLineEdit *files;
-       files = new QLineEdit(&dlg);
-       files->setGeometry(130, 20, 250, 30);
-       files->setText(file_path);
-       files->setMaxLength(32767);
-       files->setEchoMode(QLineEdit::Normal);
-       files->setFrame(TRUE);
-
-       QLabel *tmpQLabel;
-       tmpQLabel = new QLabel("Path to files:", &dlg);
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setAlignment(Qt::AlignLeft);
-       tmpQLabel->setMargin(-1);
-
-       tmpQLabel = new QLabel("Path to compiler:", &dlg);
-       tmpQLabel->setGeometry(10, 60, 100, 30);
-       tmpQLabel->setAlignment(Qt::AlignLeft);
-       tmpQLabel->setMargin(-1);
-
-       /*
-       tmpQLabel = new QLabel(&dlg, "Label_3");
-       tmpQLabel->setGeometry(10, 100, 100, 30);
-       tmpQLabel->setText("Path to gen:");
-       tmpQLabel->setAlignment(289);
-       tmpQLabel->setMargin(-1);
-       */
-
-       QLineEdit *compp;
-       compp = new QLineEdit(compiler_path, &dlg);
-       compp->setGeometry(130, 60, 250, 30);
-       compp->setMaxLength(32767);
-       compp->setEchoMode(QLineEdit::Normal);
-       compp->setFrame(TRUE);
-
-       /*
-       QLineEdit* genp;
-       genp = new QLineEdit(&dlg, "g_path");
-       genp->setGeometry(130, 100, 250, 30);
-       genp->setText(gen_path.data());
-       genp->setMaxLength(32767);
-       genp->setEchoMode(QLineEdit::Normal);
-       genp->setFrame(TRUE);
-       */
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton("Ok", &dlg);
-       tmpQPushButton->setGeometry(90, 100, 70, 30);
-       tmpQPushButton->setAutoRepeat(FALSE);
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       tmpQPushButton->setAutoResize(FALSE);
-*/
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton("Cancel", &dlg);
-       tmpQPushButton->setGeometry(180, 100, 70, 30);
-       tmpQPushButton->setAutoRepeat(FALSE);
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       tmpQPushButton->setAutoResize(FALSE);
-*/
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-       dlg.resize(400, 140);
-
-       if (dlg.exec()) {
-               compiler_path.sprintf("%s", compp->text().toAscii().data());
-               /* gen_path.sprintf("%s",genp->text()); */
-               file_path.sprintf("%s", files->text().toAscii().data());
-       };
+       on_actionClear_all_triggered();
+       fname.sprintf("%s", "");
 }
 
 /**
- * @attention Currently not in use
+ * Displays additional window 
  */
-void Editor::log_unit()
+void Editor::on_actionOpen_triggered()
 {
-       /*
-       Code commented during Qt4 migration.
-       Code is not used, so there is no rush with this...
-       */
-       /*
-       QString txt;
-       QDialog dlg(this, Qt::Dialog);
-       int cx, cy, i;
-       char uname[255];
-
-       QLineEdit* files;
-       files = new QLineEdit(&dlg, "f_path");
-       files->setGeometry(130, 20, 250, 30);
-       files->setText("");
-       files->setMaxLength(32767);
-       files->setEchoMode(QLineEdit::Normal);
-       files->setFrame(TRUE);
-
-       QLabel* tmpQLabel;
-       tmpQLabel = new QLabel(&dlg, "Label_1");
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Unit name:");
-       tmpQLabel->setAlignment(289);
-       tmpQLabel->setMargin(-1);
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg, "OkBtn");
-       tmpQPushButton->setGeometry(40, 170, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
-       tmpQPushButton->setGeometry(130, 170, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       tmpQLabel = new QLabel(&dlg, "Label_1");
-       tmpQLabel->setGeometry(10, 50, 100, 60);
-       tmpQLabel->setText("Unit type:");
-
-       QListBox lst(&dlg, "type");
-       for(i = 0; i < TYPENUM; i++) {
-               lst.insertItem(UnitTypes[i]);
-       }
-       lst.setGeometry(130, 60, 180, 80);
-       lst.setCurrentItem(0);
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-               e->getCursorPosition(&cx, &cy);
+       QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log");
+       if (!fn.isEmpty())
+               load(fn.toAscii().data());
+}
 
-               txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
-                       uname, lst.text(lst.currentItem()).ascii(), uname);
-               e->insertAt(txt, cx, cy);
+/**
+ * Saves editor content to the file.
+ * If content has been read from file, it is written to this file. Otherwise
+ * dialog is shown to save content to the specified by user, file.
+ */
+void Editor::on_actionSave_triggered()
+{
+       if (fname.isEmpty()) {
+               QString fn = QFileDialog::getSaveFileName(this, "Save file", 
+                                                       file_path, "*.log");
+               if (!fn.isEmpty()) {
+                       fname.sprintf("%s", fn.toAscii().data());
+                       save(fn.toAscii().data());
+               }
+       } else {
+               save(fname.toAscii().data());
        }
-       */
+       setWindowTitle(fname);
 }
 
 /**
- * @attention Currently not in use
+ * Saves editor content to the file.
+ * Forces saving editor content to the new file. Special dialog is shown for
+ * that purpose.
  */
-void Editor::log_prog()
+void Editor::on_actionSave_as_triggered()
 {
-       /*
-       Code commented during Qt4 migration.
-       Code is not used, so there is no rush with this...
-       */
-       /*
-       QString txt;
-       QDialog dlg(this, "unit", TRUE);
-       int cx, cy;
-       char uname[255];
-
-       QLineEdit *files;
-       files = new QLineEdit(&dlg, "f_path");
-       files->setGeometry(130, 20, 250, 30);
-       files->setText("");
-       files->setMaxLength(32767);
-       files->setEchoMode(QLineEdit::Normal);
-       files->setFrame(TRUE);
-
-       QLabel *tmpQLabel;
-       tmpQLabel = new QLabel(&dlg, "Label_1");
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Program name:");
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg, "OkBtn");
-       tmpQPushButton->setGeometry(40, 70, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
-       tmpQPushButton->setGeometry(130, 70, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       tmpQPushButton->setAutoResize(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-               e->getCursorPosition(&cx, &cy);
-
-               txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
-               e->insertAt(txt, cx, cy);
+       QString fn = QFileDialog::getSaveFileName(this, "Save file as",
+                                                       file_path, "*.log");
+       if (!fn.isEmpty()) {
+               fname.sprintf("%s", fn.toAscii().data());
+               save(fn.toAscii().data());
        }
-       */
+       setWindowTitle(fname);
+}
+void Editor::on_actionQuit_triggered()
+{
+       QApplication::instance()->quit();
+}
+void Editor::on_actionCopy_triggered()
+{
+       editor->copy();
+}
+void Editor::on_actionPaste_triggered()
+{
+       editor->paste();
+}
+void Editor::on_actionCut_triggered()
+{
+       editor->cut();
+}
+void Editor::on_actionClear_all_triggered()
+{
+       editor->clear();
 }
 
 /**
@@ -587,52 +249,21 @@ void Editor::log_prog()
  * Displays window to set search parameters. If text is found sets cursor
  * position on it.
  */
-void Editor::findText()
+void Editor::on_actionFind_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       QString *txt;
-       int res, line, pom;
-
-       QLineEdit *tmpQLineEdit;
-       tmpQLineEdit = new QLineEdit("", &dlg);
-       tmpQLineEdit->setGeometry(60, 10, 180, 30);
-
-       QLabel *tmpQLabel;
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(10, 10, 50, 30);
-
-       tmpQLabel->setText("Text:");
-
-       QCheckBox *tmpQRadioButton;
-       tmpQRadioButton = new QCheckBox("Case sensitive", &dlg);
-       tmpQRadioButton->setGeometry(70, 50, 150, 30);
-       tmpQRadioButton->setAutoRepeat(FALSE);
-
-/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
-       tmpQRadioButton->setAutoResize(FALSE);
-*/
-
-       QPushButton *okbtn, *cbtn;
-       okbtn = new QPushButton("Find", &dlg);
-       okbtn->setGeometry(260, 10, 100, 30);
-       okbtn->setDefault(TRUE);
-       connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       cbtn = new QPushButton("Close", &dlg);
-       cbtn->setGeometry(260, 50, 100, 30);
-       connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
-       dlg.resize(380, 90);
-
-       if (dlg.exec()) {
-               sensitive = tmpQRadioButton->isChecked();
-               find_text = tmpQLineEdit->text();
+       dialog::FindDialog dialog(this);
+
+       if (dialog.exec()) {
+               sensitive = dialog.isCaseSensitive();
+               find_text = dialog.getSearchText();
                
                QTextDocument::FindFlags flags = 0;
                
                if (sensitive) {
                        flags |= QTextDocument::FindCaseSensitively;
                }
-               e->find(find_text, flags);
+
+               editor->find(find_text, flags);
        }
 }
 
@@ -641,7 +272,7 @@ void Editor::findText()
  * Displays window to set search parameters. If text is found sets cursor
  * position on it.
  */
-void Editor::find_next()
+void Editor::on_actionFind_Next_triggered()
 {
        if (!find_text.isEmpty()) {
                QTextDocument::FindFlags flags = 0;
@@ -649,22 +280,87 @@ void Editor::find_next()
                if (sensitive) {
                        flags |= QTextDocument::FindCaseSensitively;
                }
-               e->find(find_text, flags);
+               editor->find(find_text, flags);
+       }
+}
+
+/**
+ * Displays window with editor properties
+ */
+void Editor::on_actionPreferences_triggered()
+{
+       dialog::PreferencesDialog dialog(this);
+
+       dialog.setCompilerPath(compiler_path);
+       dialog.setFilesPath(file_path);
+       dialog.setGenPath(gen_path);
+
+       if (dialog.exec()) {
+               compiler_path.sprintf("%s", dialog.getCompilerPath().toStdString().c_str());
+               gen_path.sprintf("%s",dialog.getGenPath().toStdString().c_str());
+               file_path.sprintf("%s", dialog.getFilesPath().toStdString().c_str());
+       };
+}
+
+/**
+ * Saves and compiles code.
+ */
+void Editor::on_actionCompile_triggered()
+{
+       on_actionSave_triggered();
+       compile(COMP_MODE);
+}
+
+/**
+ * Generates program.
+ */
+void Editor::on_actionGen_triggered()
+{
+       compile(GEN_MODE);
+}
+
+/**
+ * Saves, compiles and generates code.
+ */
+void Editor::on_actionCompile_Gen_triggered()
+{
+       on_actionSave_triggered();
+       compile(ALL_MODE);
+}
+
+void Editor::on_actionProgram_structure_triggered()
+{
+       dialog::ProgramStructureDialog dialog(this);
+
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
+       }
+}
+
+void Editor::on_actionUnit_structure_triggered()
+{
+       dialog::UnitStructureDialog dialog(this);
+
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
        }
 }
 
+}
+}
+
 /**
  * Program main function.
  * argv[1] is mandatory and should be a path to the home directory of
  * application (same as in configuration file).
+ *
  * @param argc Number of program arguments
  * @param argv Program arguments
  */
 int main(int argc, char **argv)
 {
        QApplication app(argc, argv);
-       editor = new Editor(argv[1], NULL);
-       editor->resize(600, 400);
+       loglan::vlp::Editor * editor = new loglan::vlp::Editor(argc, argv);
        editor->show();
        return app.exec();
 }