Move preferences dialog layout code into separate ui file
[vlp.git] / src / edit / editor.cpp
index 5559ac4dbd0c95a45d48944b6abbb219719524ea..b507a6fb6ee796149135d1c6dc044988657ce2fa 100644 (file)
 #include <QtGui/QListWidget>
 #include <QtGui/QListWidgetItem>
 
-#include "editor.h"
-
-#define TYPENUM        5
+#include "ProgramStructureDialog.h"
+#include "UnitStructureDialog.h"
+#include "PreferencesDialog.h"
 
-/**
- * @attention Currently not in use
- */
-char *UnitTypes[TYPENUM] = {
-       "CLASS",
-       "PROCEDURE",
-       "FUNCTION",
-       "PROCESS",
-       "COROUTINE"
-};
+#include "editor.h"
 
 /**
  * Editor constructor. Initializes and sets variables of Loglan Editor.
@@ -138,19 +129,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;
        }
 
@@ -178,7 +169,7 @@ void Editor::compile(int mode)
  */
 void Editor::on_actionNew_triggered()
 {
-       editor->clear();
+       on_actionClear_all_triggered();
        fname.sprintf("%s", "");}
 
 /**
@@ -232,15 +223,19 @@ void Editor::on_actionQuit_triggered()
 }
 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();
 }
 
 /**
@@ -314,69 +309,16 @@ void Editor::on_actionFind_Next_triggered()
  */
 void Editor::on_actionPreferences_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);
+       PreferencesDialog dialog(this);
 
-       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);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton("Cancel", &dlg);
-       tmpQPushButton->setGeometry(180, 100, 70, 30);
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       dlg.resize(400, 140);
+       dialog.setCompilerPath(compiler_path);
+       dialog.setFilesPath(file_path);
+       dialog.setGenPath(gen_path);
 
-       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());
+       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());
        };
 }
 
@@ -408,102 +350,19 @@ void Editor::on_actionCompile_Gen_triggered()
 
 void Editor::on_actionProgram_structure_triggered()
 {
-       QDialog dlg(this, "unit", TRUE);
-       char uname[255];
+       ProgramStructureDialog dialog(this);
 
-       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);
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Program name:");
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(40, 70, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(130, 70, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-
-               QString txt;
-               txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", uname);
-
-               editor->textCursor().insertText(txt);
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
        }
 }
 
 void Editor::on_actionUnit_structure_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       int 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);
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Unit name:");
-       tmpQLabel->setAlignment(289);
-       tmpQLabel->setMargin(-1);
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(40, 170, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(130, 170, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
+       UnitStructureDialog dialog(this);
 
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(10, 50, 100, 60);
-       tmpQLabel->setText("Unit type:");
-
-       QListWidget *listWidget = new QListWidget(&dlg);
-       for(i = 0; i < TYPENUM; i++) {
-               QListWidgetItem *newItem = new QListWidgetItem;
-               newItem->setText(UnitTypes[i]);
-               listWidget->insertItem(i, newItem);
-       }
-       listWidget->setCurrentItem(0);
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-
-               QString txt;
-               txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
-                       uname,
-                       listWidget->currentItem()->text().toStdString().c_str(),
-                       uname
-               );
-
-               editor->textCursor().insertText(txt);
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
        }
 }
 
@@ -511,6 +370,7 @@ void Editor::on_actionUnit_structure_triggered()
  * 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
  */