#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QApplication>
#include <QMainWindow>
#include <QTextEdit>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QDialog>
#include <QDesktopWidget>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QDockWidget>
#include <QTreeWidget>
#include <QProcess>
#include <QTimer>

#include <vector>
#include <cassert>

#include "CodeArea.h"
#include "Console.h"
#include "FnSelectDialog.h"
#include "Outline.h"


class MainWindow : public QMainWindow
{
  Q_OBJECT

  public:
    MainWindow();

    QSize sizeHint() const;
    void flattenedOutline(FlattenedOutline *outline) const;

  signals:

  public slots:
    void fnSelect();
    void toggleSimple();
    void openFileDialog();
    void saveFile();
    void saveFileAsDialog();
    void setActiveCodeArea(QMdiSubWindow *area);
    void runProgram();
    void runPythonParser();
    void updateConsoleFromProcess();
    void updateCodeOutlineFromProcess(int exitCode, QProcess::ExitStatus exitStatus);
    void jumpToFunction(QTreeWidgetItem* item, int column);

  private:
    QMdiArea *mainArea;

    // process
    QProcess *programProcess;
    QProcess *pythonParserProcess;

    // console
    Console *console;
    QDockWidget *consoleDock;

    // editor
    CodeArea *activeCodeArea;
    std::vector<CodeArea*> codeAreas;
    FnSelectDialog *fnSelectDialog;

    // code outline
    QTreeWidget *codeOutline;
    QDockWidget *codeOutlineDock;
    std::vector<OutlineClass> outlineClasses;
    QTreeWidgetItem *functionsHeader;

    // timer
    QTimer *parseTimer;

    // console actions
    QAction *runProgramAction;

    // menus
    QMenu *fileMenu;
    QMenu *helpMenu;

    // menu actions
    QAction *openFileAction;
    QAction *saveFileAction;
    QAction *saveFileAsAction;

    // code actions
    QAction *fnSelectAction;

    // ui actions
    QAction *toggleSimpleAction;
    bool usingSimple;

    // project actions
    QAction *addFileToProjectAction;
    QAction *removeFileFromProjectAction;

    // git actions
    QAction *openGitDialogAction;

    // program actions
    QAction *exitProgramAction;

    // meta
    QString lastUsedDirectory;
};

#endif
