* work save

This commit is contained in:
royqh1979 2021-07-01 19:44:38 +08:00
parent effd416389
commit 38edefa59b
15 changed files with 269 additions and 11 deletions

View File

@ -45,11 +45,13 @@ SOURCES += \
settingsdialog/editorsymbolcompletionwidget.cpp \
settingsdialog/editorsyntaxcheckwidget.cpp \
settingsdialog/environmentappearencewidget.cpp \
settingsdialog/executorgeneralwidget.cpp \
settingsdialog/settingsdialog.cpp \
settingsdialog/settingswidget.cpp \
systemconsts.cpp \
utils.cpp \
widgets/coloredit.cpp \
widgets/consolewidget.cpp \
widgets/issuestable.cpp \
widgets/qpatchedcombobox.cpp
@ -90,12 +92,14 @@ HEADERS += \
settingsdialog/editorsymbolcompletionwidget.h \
settingsdialog/editorsyntaxcheckwidget.h \
settingsdialog/environmentappearencewidget.h \
settingsdialog/executorgeneralwidget.h \
settingsdialog/settingsdialog.h \
settingsdialog/settingswidget.h \
systemconsts.h \
utils.h \
common.h \
widgets/coloredit.h \
widgets/consolewidget.h \
widgets/issuestable.h \
widgets/qpatchedcombobox.h
@ -110,6 +114,7 @@ FORMS += \
settingsdialog/editorsymbolcompletionwidget.ui \
settingsdialog/editorsyntaxcheckwidget.ui \
settingsdialog/environmentappearencewidget.ui \
settingsdialog/executorgeneralwidget.ui \
settingsdialog/settingsdialog.ui
TRANSLATIONS += \

View File

@ -5,6 +5,7 @@
#include "../mainwindow.h"
#include "executablerunner.h"
#include "utils.h"
#include "../settings.h"
CompilerManager::CompilerManager(QObject *parent) : QObject(parent)
{
@ -74,7 +75,7 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con
if (mRunner!=nullptr) {
return;
}
if (programHasConsole(filename)) {
if (pSettings->executor().pauseConsole() && programHasConsole(filename)) {
QString newArguments = QString(" 0 \"%1\" %2").arg(toLocalPath(filename)).arg(arguments);
mRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",newArguments,workDir);
} else {

View File

@ -279,7 +279,7 @@ void Editor::wheelEvent(QWheelEvent *event) {
pMainWindow->updateEditorSettings();
event->accept();
return;
} else {
} else if (event->angleDelta().y()<0) {
size = std::max(2,size-1);
pSettings->editor().setFontSize(size);
pMainWindow->updateEditorSettings();

View File

@ -122,14 +122,12 @@ void MainWindow::updateEditorActions()
ui->actionEncode_in_UTF_8->setEnabled(false);
ui->actionConvert_to_ANSI->setEnabled(false);
ui->actionConvert_to_UTF_8->setEnabled(false);
ui->actionCompile->setEnabled(false);
ui->actionCopy->setEnabled(false);
ui->actionCut->setEnabled(false);
ui->actionFoldAll->setEnabled(false);
ui->actionIndent->setEnabled(false);
ui->actionPaste->setEnabled(false);
ui->actionRedo->setEnabled(false);
ui->actionRun->setEnabled(false);
ui->actionSave->setEnabled(false);
ui->actionSaveAs->setEnabled(false);
ui->actionSaveAll->setEnabled(false);
@ -138,15 +136,19 @@ void MainWindow::updateEditorActions()
ui->actionUnIndent->setEnabled(false);
ui->actionUndo->setEnabled(false);
ui->actionUnfoldAll->setEnabled(false);
ui->actionCompile->setEnabled(false);
ui->actionCompile_Run->setEnabled(false);
ui->actionRun->setEnabled(false);
ui->actionRebuild->setEnabled(false);
ui->actionStop_Execution->setEnabled(false);
} else {
ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true);
ui->actionEncode_in_UTF_8->setEnabled(true);
ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT && e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT);
ui->actionConvert_to_UTF_8->setEnabled(e->encodingOption()!=ENCODING_UTF8 && e->fileEncoding()!=ENCODING_UTF8);
//if (e->compilable())
ui->actionCompile->setEnabled(true);
ui->actionRun->setEnabled(true);
ui->actionCopy->setEnabled(e->selAvail());
ui->actionCut->setEnabled(e->selAvail());
ui->actionFoldAll->setEnabled(e->lines()->count()>0);
@ -162,10 +164,28 @@ void MainWindow::updateEditorActions()
ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnfoldAll->setEnabled(e->lines()->count()>0);
updateCompileActions();
}
}
void MainWindow::updateCompileActions()
{
if (mCompilerManager->compiling()|| mCompilerManager->running()) {
ui->actionCompile->setEnabled(false);
ui->actionCompile_Run->setEnabled(false);
ui->actionRun->setEnabled(false);
ui->actionRebuild->setEnabled(false);
} else {
ui->actionCompile->setEnabled(true);
ui->actionCompile_Run->setEnabled(true);
ui->actionRun->setEnabled(true);
ui->actionRebuild->setEnabled(true);
}
ui->actionStop_Execution->setEnabled(mCompilerManager->running());
}
void MainWindow::updateEditorColorSchemes()
{
mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
@ -310,7 +330,8 @@ bool MainWindow::compile(bool rebuild)
if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename());
}
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
updateCompileActions();
openCloseMessageSheet(true);
ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput);
return true;
@ -371,6 +392,10 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename)
// MainForm.UpdateAppTitle;
// end;
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
updateCompileActions();
if (pSettings->executor().minimizeOnRun()) {
showMinimized();
}
}
void MainWindow::runExecutable()
@ -616,6 +641,7 @@ void MainWindow::onCompileFinished()
}
}
mCheckSyntaxInBack=false;
updateCompileActions();
}
void MainWindow::onCompileErrorOccured(const QString &reason)
@ -630,7 +656,10 @@ void MainWindow::onRunErrorOccured(const QString &reason)
void MainWindow::onRunFinished()
{
qDebug()<<"run finished";
updateCompileActions();
if (pSettings->executor().minimizeOnRun()) {
showNormal();
}
}
void MainWindow::on_actionCompile_triggered()

View File

@ -41,6 +41,7 @@ public:
void updateForStatusbarModeInfo();
void updateEditorSettings();
void updateEditorActions();
void updateCompileActions();
void updateEditorColorSchemes();
void updateCompilerSet();
void checkSyntaxInBack(Editor* e);

View File

@ -5173,8 +5173,9 @@ void SynEdit::wheelEvent(QWheelEvent *event)
{
if (event->angleDelta().y()>0) {
verticalScrollBar()->setValue(verticalScrollBar()->value()-1);
event->accept();
return;
} else {
} else if (event->angleDelta().y()<0) {
verticalScrollBar()->setValue(verticalScrollBar()->value()+1);
event->accept();
return;

View File

@ -20,7 +20,8 @@ Settings::Settings(const QString &filename):
mDirs(this),
mEditor(this),
mEnvironment(this),
mCompilerSets(this)
mCompilerSets(this),
mExecutor(this)
{
}
@ -2199,3 +2200,43 @@ void Settings::Environment::setTheme(const QString &theme)
{
mTheme = theme;
}
Settings::Executor::Executor(Settings *settings):_Base(settings, SETTING_EXECUTOR)
{
}
bool Settings::Executor::minimizeOnRun() const
{
return mMinimizeOnRun;
}
void Settings::Executor::setMinimizeOnRun(bool minimizeOnRun)
{
mMinimizeOnRun = minimizeOnRun;
}
void Settings::Executor::doSave()
{
//Appearence
saveValue("pause_console", mPauseConsole);
saveValue("minimize_on_run", mMinimizeOnRun);
}
bool Settings::Executor::pauseConsole() const
{
return mPauseConsole;
}
void Settings::Executor::setPauseConsole(bool pauseConsole)
{
mPauseConsole = pauseConsole;
}
void Settings::Executor::doLoad()
{
//Appearence
mPauseConsole = boolValue("pause_console",true);
mMinimizeOnRun = boolValue("minimize_on_run",false);
}

View File

@ -15,6 +15,7 @@
#define SETTING_DIRS "Dirs"
#define SETTING_EDITOR "Editor"
#define SETTING_ENVIRONMENT "Environment"
#define SETTING_EXECUTOR "Executor"
#define SETTING_COMPILTER_SETS "CompilerSets"
#define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex"
#define SETTING_COMPILTER_SETS_COUNT "count"
@ -367,6 +368,27 @@ public:
void doLoad() override;
};
class Executor: public _Base {
public:
explicit Executor(Settings * settings);
bool pauseConsole() const;
void setPauseConsole(bool pauseConsole);
bool minimizeOnRun() const;
void setMinimizeOnRun(bool minimizeOnRun);
private:
// general
bool mPauseConsole;
bool mMinimizeOnRun;
protected:
void doSave() override;
void doLoad() override;
};
class CompilerSet {
public:
explicit CompilerSet(const QString& compilerFolder = QString());
@ -540,6 +562,7 @@ public:
Editor& editor();
CompilerSets& compilerSets();
Environment& environment();
Executor& executor();
QString filename() const;
private:
@ -549,6 +572,7 @@ private:
Editor mEditor;
Environment mEnvironment;
CompilerSets mCompilerSets;
Executor mExecutor;
};

View File

@ -0,0 +1,29 @@
#include "executorgeneralwidget.h"
#include "ui_executorgeneralwidget.h"
#include "../settings.h"
ExecutorGeneralWidget::ExecutorGeneralWidget(const QString& name, const QString& group, QWidget *parent):
SettingsWidget(name,group,parent),
ui(new Ui::ExecutorGeneralWidget)
{
ui->setupUi(this);
}
ExecutorGeneralWidget::~ExecutorGeneralWidget()
{
delete ui;
}
void ExecutorGeneralWidget::doLoad()
{
ui->chkPauseConsole->setChecked(pSettings->executor().pauseConsole());
ui->chkMinimizeOnRun->setChecked(pSettings->executor().minimizeOnRun());
}
void ExecutorGeneralWidget::doSave()
{
pSettings->executor().setPauseConsole(ui->chkPauseConsole->isChecked());
pSettings->executor().setMinimizeOnRun(ui->chkMinimizeOnRun->isChecked());
pSettings->executor().save();
}

View File

@ -0,0 +1,28 @@
#ifndef EXECUTORGENERALWIDGET_H
#define EXECUTORGENERALWIDGET_H
#include <QWidget>
#include "settingswidget.h"
namespace Ui {
class ExecutorGeneralWidget;
}
class ExecutorGeneralWidget : public SettingsWidget
{
Q_OBJECT
public:
explicit ExecutorGeneralWidget(const QString& name, const QString& group, QWidget *parent = nullptr);
~ExecutorGeneralWidget();
private:
Ui::ExecutorGeneralWidget *ui;
// SettingsWidget interface
protected:
void doLoad() override;
void doSave() override;
};
#endif // EXECUTORGENERALWIDGET_H

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExecutorGeneralWidget</class>
<widget class="QWidget" name="ExecutorGeneralWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkPauseConsole">
<property name="text">
<string>Pause console programs after return</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkMinimizeOnRun">
<property name="text">
<string>Minimize IDE when running programs</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -9,6 +9,7 @@
#include "editorsyntaxcheckwidget.h"
#include "editorsymbolcompletionwidget.h"
#include "environmentappearencewidget.h"
#include "executorgeneralwidget.h"
#include <QDebug>
#include <QMessageBox>
#include <QModelIndex>
@ -58,6 +59,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
addWidget(pEditorSyntaxCheckWidget);
pExecutorGeneralWidget = new ExecutorGeneralWidget(tr("General"),tr("Program Runner"));
pExecutorGeneralWidget->init();
addWidget(pExecutorGeneralWidget);
ui->widgetsView->expandAll();
//select the first widget of the first group
auto groupIndex = ui->widgetsView->model()->index(0,0);

View File

@ -19,6 +19,7 @@ class EditorSymbolCompletionWidget;
class EditorColorSchemeWidget;
class EditorSyntaxCheckWidget;
class EnvironmentAppearenceWidget;
class ExecutorGeneralWidget;
class SettingsWidget;
class SettingsDialog : public QDialog
{
@ -56,6 +57,7 @@ private:
EnvironmentAppearenceWidget* pEnvironmentAppearenceWidget;
EditorSymbolCompletionWidget* pEditorSymbolCompletionWidget;
EditorSyntaxCheckWidget* pEditorSyntaxCheckWidget;
ExecutorGeneralWidget * pExecutorGeneralWidget;
};
#endif // SETTINGSDIALOG_H

View File

@ -0,0 +1,6 @@
#include "consolewidget.h"
ConsoleWidget::ConsoleWidget(QWidget *parent):QTextEdit(parent)
{
}

View File

@ -0,0 +1,19 @@
#ifndef CONSOLEWIDGET_H
#define CONSOLEWIDGET_H
#include <QTextEdit>
class ConsoleWidget : public QTextEdit
{
Q_OBJECT
public:
explicit ConsoleWidget(QWidget* parent = nullptr);
private:
QString mCurrentCommand;
QStringList mCommandHistory;
int mHistoryIndex;
int mHistorySize;
QString mPrompt;
};
#endif // CONSOLEWIDGET_H