265 lines
6.3 KiB
C++
265 lines
6.3 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "editorlist.h"
|
|
#include "editor.h"
|
|
#include "systemconsts.h"
|
|
#include "settings.h"
|
|
|
|
#include <QCloseEvent>
|
|
#include <QComboBox>
|
|
#include <QFileDialog>
|
|
#include <QLabel>
|
|
|
|
#include "settingsdialog/settingsdialog.h"
|
|
#include "compiler/compilermanager.h"
|
|
#include <QDebug>
|
|
|
|
MainWindow* pMainWindow;
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
// status bar
|
|
mFileInfoStatus=new QLabel();
|
|
mFileEncodingStatus = new QLabel();
|
|
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
|
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
|
|
ui->statusbar->addWidget(mFileInfoStatus);
|
|
ui->statusbar->addWidget(mFileEncodingStatus);
|
|
mEditorList = new EditorList(ui->EditorTabsLeft,
|
|
ui->EditorTabsRight,
|
|
ui->EditorPanelSplitter,
|
|
ui->EditorPanel);
|
|
setupActions();
|
|
ui->EditorTabsRight->setVisible(false);
|
|
|
|
mCompilerSet = new QComboBox();
|
|
ui->toolbarCompilerSet->addWidget(mCompilerSet);
|
|
connect(mCompilerSet,QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
this, &MainWindow::onCompilerSetChanged);
|
|
updateCompilerSet();
|
|
|
|
mCompilerManager = new CompilerManager(this);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::updateStatusBarForEncoding() {
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor!=NULL) {
|
|
mFileEncodingStatus->setText(editor->fileEncoding());
|
|
}
|
|
}
|
|
|
|
void MainWindow::updateStatusBarForEditingInfo(int line,int col,int lines,int charCount)
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor!=NULL) {
|
|
mFileInfoStatus->setText(
|
|
QString(tr("Line: %1 Col: %2 Lines: %3 Chars: %4")).arg(line)
|
|
.arg(col).arg(lines).arg(charCount));
|
|
}
|
|
}
|
|
|
|
void MainWindow::openFiles(const QStringList &files)
|
|
{
|
|
mEditorList->beginUpdate();
|
|
auto end = finally([this] {
|
|
this->mEditorList->endUpdate();
|
|
});
|
|
for (QString file:files) {
|
|
openFile(file);
|
|
}
|
|
mEditorList->endUpdate();
|
|
}
|
|
|
|
void MainWindow::openFile(const QString &filename)
|
|
{
|
|
Editor* editor = mEditorList->findOpenedEditor(filename);
|
|
if (editor!=nullptr) {
|
|
editor->activate();
|
|
return;
|
|
}
|
|
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
|
|
false,false);
|
|
editor->activate();
|
|
this->updateStatusBarForEncoding();
|
|
}
|
|
|
|
void MainWindow::setupActions() {
|
|
|
|
}
|
|
|
|
void MainWindow::updateCompilerSet()
|
|
{
|
|
mCompilerSet->clear();
|
|
int index=pSettings->compilerSets().defaultIndex();
|
|
for (int i=0;i<pSettings->compilerSets().list().size();i++) {
|
|
mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
|
|
}
|
|
if (index < 0 || index>=mCompilerSet->count()) {
|
|
index = 0;
|
|
}
|
|
mCompilerSet->setCurrentIndex(index);
|
|
}
|
|
|
|
|
|
void MainWindow::on_actionNew_triggered()
|
|
{
|
|
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
|
|
editor->activate();
|
|
updateStatusBarForEncoding();
|
|
}
|
|
|
|
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
|
|
{
|
|
Editor* editor = mEditorList->getEditor(index);
|
|
mEditorList->closeEditor(editor);
|
|
}
|
|
|
|
void MainWindow::on_actionOpen_triggered()
|
|
{
|
|
QString selectedFileFilter = pSystemConsts->defaultFileFilter();
|
|
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
|
|
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
|
|
&selectedFileFilter);
|
|
openFiles(files);
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
|
if (!mEditorList->closeAll(true)) {
|
|
event->ignore();
|
|
return ;
|
|
}
|
|
|
|
delete mEditorList;
|
|
event->accept();
|
|
return;
|
|
}
|
|
|
|
void MainWindow::on_actionSave_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL) {
|
|
editor->save();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionSaveAs_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL) {
|
|
editor->saveAs();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionOptions_triggered()
|
|
{
|
|
SettingsDialog settingsDialog;
|
|
settingsDialog.exec();
|
|
}
|
|
|
|
void MainWindow::onCompilerSetChanged(int index)
|
|
{
|
|
if (index<0)
|
|
return;
|
|
pSettings->compilerSets().setDefaultIndex(index);
|
|
pSettings->compilerSets().saveDefaultIndex();
|
|
}
|
|
|
|
void MainWindow::onCompileLog(const QString &msg)
|
|
{
|
|
ui->txtCompilerOutput->appendPlainText(msg);
|
|
}
|
|
|
|
void MainWindow::onCompileError(const QString &msg)
|
|
{
|
|
qDebug()<<msg;
|
|
}
|
|
|
|
void MainWindow::on_actionCompile_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
mCompilerManager->compile(editor->filename(),editor->fileEncoding());
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionRun_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
QString exeName= getCompiledExecutableName(editor->filename());
|
|
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionUndo_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->undo();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionRedo_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->redo();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionCut_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->cut();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionSelectAll_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->selectAll();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionCopy_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->copy();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionPaste_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->paste();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionIndent_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->indent();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionUnIndent_triggered()
|
|
{
|
|
Editor * editor = mEditorList->getEditor();
|
|
if (editor != NULL ) {
|
|
editor->unindent();
|
|
}
|
|
}
|