diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 09fd3eb6..13405036 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -29,6 +29,7 @@ SOURCES += \ qsynedit/SearchBase.cpp \ qsynedit/SearchRegex.cpp \ settingsdialog/debuggeneralwidget.cpp \ + settingsdialog/editorautosavewidget.cpp \ settingsdialog/editorcodecompletionwidget.cpp \ settingsdialog/editormiscwidget.cpp \ widgets/classbrowser.cpp \ @@ -97,6 +98,7 @@ HEADERS += \ qsynedit/SearchBase.h \ qsynedit/SearchRegex.h \ settingsdialog/debuggeneralwidget.h \ + settingsdialog/editorautosavewidget.h \ settingsdialog/editorcodecompletionwidget.h \ settingsdialog/editormiscwidget.h \ widgets/classbrowser.h \ @@ -151,6 +153,7 @@ HEADERS += \ FORMS += \ settingsdialog/debuggeneralwidget.ui \ + settingsdialog/editorautosavewidget.ui \ settingsdialog/editorcodecompletionwidget.ui \ settingsdialog/editormiscwidget.ui \ widgets/cpudialog.ui \ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.qm b/RedPandaIDE/RedPandaIDE_zh_CN.qm index 692cc2fc..16c3f272 100644 Binary files a/RedPandaIDE/RedPandaIDE_zh_CN.qm and b/RedPandaIDE/RedPandaIDE_zh_CN.qm differ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts index 14cbe4a2..2ff3b925 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -532,59 +532,140 @@ Are you really want to continue? 失败 - - - - - - - + + + + + + + Error 错误 - + File %1 is not writable! 无法写入文件"%1" - + Save As 另存为 - + The text to be copied exceeds count limit! 要复制的内容超过了行数限制! - + The text to be copied exceeds character limit! 要复制的内容超过了字符数限制! - + The text to be cut exceeds count limit! 要剪切的内容超过了行数限制! - + The text to be cut exceeds character limit! 要剪切的内容超过了字符数限制! - - - + + + Ctrl+click for more info Ctrl+单击以获取更多信息 - + + + Symbol '%1' not found! + 未找到符号'%1'! + + + Readonly 只读 + + EditorAutoSaveWidget + + + Form + 表单 + + + + Enable auto save + 启用自动保存 + + + + Time interval: + 时间间隔 + + + + minutes + 分钟 + + + + Objects to save + 保存对象 + + + + Current File + 当前文件 + + + + All files openned + 所有打开的文件 + + + + Project files + 项目文件 + + + + Save strategy + 保存策略 + + + + Overwrite + 自动覆盖 + + + + Append UNIX timestamp + 添加Unix时间戳 + + + + Append formatted timestamp + 添加格式化世时间戳 + + + + Demo file name: + 示例文件名 + + + + + + Demo file name: + 示例文件名 + + EditorClipboardWidget @@ -1256,7 +1337,7 @@ Are you really want to continue? - + Issues 编译器 @@ -1449,8 +1530,8 @@ Are you really want to continue? - - + + Compile 编译 @@ -1742,20 +1823,20 @@ Are you really want to continue? 文件历史 - - + + Debugging 正在调试 - - + + Running 正在运行 - - + + Compiling 正在编译 @@ -1764,145 +1845,150 @@ Are you really want to continue? 行:%1 列:%2 已选择:%3 总行数:%4 总长度:%5 - + Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5 行:%1 列:%2 已选择:%3 总行数:%4 总长度:%5 - + Read Only 只读 - + Insert 插入 - + Overwrite 覆写 - - + + Confirm 确认 - - - + + + Source file is not compiled. 源文件尚未编译。 - - + + Compile now? 现在编译? - - + + Source file is more recent than executable. 源文件比可执行程序新。 - + Recompile now? 重新编译? - + No compiler set 无编译器设置 - + No compiler set is configured. 没有配置编译器设置。 - + Can't start debugging. 无法启动调试器 - + Enable debugging 启用调试参数 - + You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now? 当前编译设置中未启用调试选项(-g3),或启用了信息剥除选项(-s)<br /><br/>是否纠正这一问题? - + Recompile? 重新编译? - - - - - - + + %1 files autosaved + 已自动保存%1个文件 + + + + + + + + Error 错误 - + Open 打开 - + Compile Failed 编译失败 - + Run Failed 运行失败 - - + + Confirm Convertion 确认转换 - - + + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? - + New Watch Expression 新监视表达式 - + Enter Watch Expression (it is recommended to use 'this->' for class members): 输入监视表达式 - + Parsing file %1 of %2: "%3" (%1/%2)正在解析文件"%3" - - + + Done parsing %1 files in %2 seconds - 完成1%个文件的解析,用时%2秒 + 完成%1个文件的解析,用时%2秒 - + (%1 files per second) (每秒%1个文件) @@ -1974,216 +2060,216 @@ Are you really want to continue? 无法写入配置文件夹"%1" - - - - + + + + The following %1 directories don't exist: 下列%1文件夹不存在: - - + + binary 二进制 - + No %1 directories have been specified. 未指定%1文件夹 - + C include C包含 - - + + C++ include C++包含 - - - - + + + + Cannot find the %1 "%2" 无法找到%1程序"%2" - + C options C语言选项 - + Support all ANSI standard C programs (-ansi) 支持所有ANSI标准C程序(-ansi) - + Do not recognize asm,inline or typeof as a keyword (-fno-asm) 不支持将asm、inline和typeof作为关键字(-fno-asm) - + Imitate traditional C preprocessors (-traditional-cpp) 模仿传统C预处理器行为(-traditional-cpp) - + Code Generation 代码生成 - + Optimize for the following machine (-march) 生成特定机器的专用指令(-march) - + Optimize less, while maintaining full compatibility (-tune) 完整兼容特定机器,较少优化(-tune) - + Enable use of specific instructions (-mx) 启用特定指令集(-mx) - + Optimization level (-Ox) 优化级别(-Ox) - + Compile with the following pointer size (-mx) 使用下列指针大小编译(-mx) - + Language standard (-std) 语言标准(-std) - + Generate debugging information (-g3) 生成调试信息(-g3) - + Generate profiling info for analysis (-pg) 生成性能分析信息(-pg) - + Warnings 代码警告 - + Inhibit all warning messages (-w) 忽略所有警告信息(-w) - + Show most warnings (-Wall) 启用常见问题警告(-Wall) - + Show some more warnings (-Wextra) 启用更多问题警告(-Wextra) - + Check ISO C/C++/C++0x conformance (-pedantic) 检查ISO C/C++/C++0x语法一致性(-pedantic) - + Only check the code for syntax errors (-fsyntax-only) 只进行语法检查(不编译)(-fsyntax-only) - + Make all warnings into errors (-Werror) 将警告作为错误处理(-Werror) - + Abort compilation on first error (-Wfatal-errors) 遇到第一个错误后立即中止编译(-Wfatal-errors) - + Linker 链接器 - + Link an Objective C program (-lobjc) - + Do not use standard system libraries (-nostdlib) 不使用标准库和系统启动文件(-nostdlib) - + Do not create a console window (-mwindows) 不产生控制台窗口(-mwindows) - + Strip executable (-s) 剥除附加信息(-s) - + Link libraries statically (-static) 链接Ojbective C程序(-lobjc) - + Output 输出 - + Put comments in generated assembly code (-fverbose-asm) 在生成的汇编代码中加入注释(-fverbose-asm) - + Use pipes instead of temporary files during compilation (-pipe) 编译时使用管道而不是临时文件(-pipe) - + Do not assemble, compile and generate the assemble code (-S) 只生成汇编代码(-S) - - + + Confirm 确认 - + The following problems were found during validation of compiler set "%1": 在验证编译器设置"%1"时遇到了下列问题: - + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -2836,90 +2922,102 @@ Are you really want to continue? 取消 - + Appearence 外观 - + Environment 环境 - + Compiler Set 编译器配置集 - + Compiler 编译器 - - - + + + General 通用 - - - - - - - + + + + + + + + + Editor 编辑器 - + Font 字体 - + Copy & Export 复制/导出 - + Color 配色 - + Code Completion 代码补全 - + Symbol Completion 符号补全 - + Auto Syntax Checking 自动语法检查 - + + Auto save + 自动保存 + + + + Misc + 杂项 + + + Program Runner 程序运行 - + Debugger 调试器 - + Save Changes 保存修改 - + There are changes in the settings, do you want to save them before swtich to other page? 本页中有尚未保存的设置修改,是否保存后再切换到其他页? diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 293aefbd..fb55d627 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -161,16 +161,6 @@ void Editor::saveFile(const QString &filename) { pMainWindow->updateForEncodingInfo(); if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenSave()) pMainWindow->checkSyntaxInBack(this); - switch(getFileType(mFilename)) { - case FileType::CppSource: - mUseCppSyntax = true; - break; - case FileType::CSource: - mUseCppSyntax = false; - break; - default: - mUseCppSyntax = pSettings->editor().defaultFileCpp(); - } } void Editor::convertToEncoding(const QByteArray &encoding) @@ -235,6 +225,16 @@ bool Editor::saveAs(){ exception.reason()); return false; } + switch(getFileType(mFilename)) { + case FileType::CppSource: + mUseCppSyntax = true; + break; + case FileType::CSource: + mUseCppSyntax = false; + break; + default: + mUseCppSyntax = pSettings->editor().defaultFileCpp(); + } //todo: update (reassign highlighter) //todo: remove old file from parser and reparse file @@ -2093,7 +2093,7 @@ void Editor::gotoDeclaration(const BufferCoord &pos) mFilename,phrase,pos.Line); if (!statement) { - pMainWindow->updateStatusBarMessage(tr("Symbol '%1' not found!").arg(phrase)); + pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase)); return; } QString filename; @@ -2123,7 +2123,7 @@ void Editor::gotoDefinition(const BufferCoord &pos) mFilename,phrase,pos.Line); if (!statement) { - pMainWindow->updateStatusBarMessage(tr("Symbol '%1' not found!").arg(phrase)); + pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase)); return; } QString filename; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 95cc6c5a..79512425 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -126,6 +126,10 @@ MainWindow::MainWindow(QWidget *parent) mHeaderCompletionPopup = std::make_shared(); updateAppTitle(); + + connect(&mAutoSaveTimer, &QTimer::timeout, + this, &MainWindow::onAutoSaveTimeout); + resetAutoSaveTimer(); } MainWindow::~MainWindow() @@ -426,6 +430,16 @@ void MainWindow::updateClassBrowserForEditor(Editor *editor) } } +void MainWindow::resetAutoSaveTimer() +{ + if (pSettings->editor().enableAutoSave()) { + //minute to milliseconds + mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000); + } else { + mAutoSaveTimer.stop(); + } +} + QPlainTextEdit *MainWindow::txtLocals() { return ui->txtLocals; @@ -466,7 +480,7 @@ void MainWindow::updateForStatusbarModeInfo() } } -void MainWindow::updateStatusBarMessage(const QString &s) +void MainWindow::updateStatusbarMessage(const QString &s) { ui->statusbar->showMessage(s); } @@ -948,6 +962,65 @@ void MainWindow::prepareDebugger() // mDebugger->deleteWatchVars(false); } +void MainWindow::doAutoSave(Editor *e) +{ + if (!e) + return; + if (!e->modified()) + return; + QString filename = e->filename(); + QFileInfo fileInfo(filename); + QDir parent = fileInfo.absoluteDir(); + QString baseName = fileInfo.completeBaseName(); + QString suffix = fileInfo.suffix(); + switch(pSettings->editor().autoSaveStrategy()) { + case assOverwrite: + break; + case assAppendUnixTimestamp: + filename = parent.filePath( + QString("%1.%2.%3") + .arg(baseName) + .arg(QDateTime::currentSecsSinceEpoch()) + .arg(suffix)); + break; + case assAppendFormatedTimeStamp: { + QDateTime time = QDateTime::currentDateTime(); + filename = parent.filePath( + QString("%1.%2.%3") + .arg(baseName) + .arg(time.toString("yyyy.MM.dd.hh.mm.ss")) + .arg(suffix)); + } + } + e->saveFile(filename); +} + +void MainWindow::onAutoSaveTimeout() +{ + if (!pSettings->editor().enableAutoSave()) + return; + int updateCount = 0; + switch (pSettings->editor().autoSaveTarget()) { + case astCurrentFile: { + Editor *e = mEditorList->getEditor(); + doAutoSave(e); + updateCount++; + } + break; + case astAllOpennedFiles: + for (int i=0;ipageCount();i++) { + Editor *e = (*mEditorList)[i]; + doAutoSave(e); + updateCount++; + } + break; + case astAllProjectFiles: + //todo: auto save project files + break; + } + updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount)); +} + const std::shared_ptr &MainWindow::headerCompletionPopup() const { return mHeaderCompletionPopup; @@ -1611,7 +1684,7 @@ void MainWindow::onParserProgress(const QString &fileName, int total, int curren // Only show if needed (it's a very slow operation) if (current ==1 || current % showStep==0) { - updateStatusBarMessage(tr("Parsing file %1 of %2: \"%3\"") + updateStatusbarMessage(tr("Parsing file %1 of %2: \"%3\"") .arg(current).arg(total).arg(fileName)); } } @@ -1633,13 +1706,13 @@ void MainWindow::onEndParsing(int total, int) } else { parsingFrequency = 999; } - updateStatusBarMessage(tr("Done parsing %1 files in %2 seconds") + updateStatusbarMessage(tr("Done parsing %1 files in %2 seconds") .arg(total).arg(parseTime) + " " + tr("(%1 files per second)") .arg(parsingFrequency)); } else { - updateStatusBarMessage(tr("Done parsing %1 files in %2 seconds") + updateStatusbarMessage(tr("Done parsing %1 files in %2 seconds") .arg(total).arg(parseTime)); } } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9b49d7f2..97a6f459 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include #include "common.h" #include "widgets/searchresultview.h" #include "widgets/classbrowser.h" @@ -52,7 +53,7 @@ public: void updateForEncodingInfo(); void updateStatusbarForLineCol(); void updateForStatusbarModeInfo(); - void updateStatusBarMessage(const QString& s); + void updateStatusbarMessage(const QString& s); void updateEditorSettings(); void updateEditorActions(); void updateCompileActions(); @@ -79,6 +80,8 @@ public: void updateClassBrowserForEditor(Editor* editor); + void resetAutoSaveTimer(); + QPlainTextEdit* txtLocals(); CPUDialog *cpuDialog() const; @@ -91,16 +94,39 @@ public: SearchResultModel* searchResultModel(); - - const std::shared_ptr &completionPopup() const; const std::shared_ptr &headerCompletionPopup() const; +public slots: + void onCompileLog(const QString& msg); + void onCompileIssue(PCompileIssue issue); + void onCompileFinished(); + void onCompileErrorOccured(const QString& reason); + void onRunErrorOccured(const QString& reason); + void onRunFinished(); + void cleanUpCPUDialog(); + void onDebugCommandInput(const QString& command); + void onDebugEvaluateInput(); + void onParserProgress(const QString& fileName, int total, int current); + void onStartParsing(); + void onEndParsing(int total, int updateView); + void onEvalValueReady(const QString& value); protected: void openFiles(const QStringList& files); void openFile(const QString& filename); + +private: + CompileTarget getCompileTarget(); + bool debugInferiorhasBreakpoint(); + void setupActions(); + void openCloseMessageSheet(bool open); + void prepareDebugger(); + void doAutoSave(Editor *e); + private slots: + void onAutoSaveTimeout(); + void on_actionNew_triggered(); void on_EditorTabsLeft_tabCloseRequested(int index); @@ -168,9 +194,6 @@ private slots: void on_actionDebug_triggered(); - CompileTarget getCompileTarget(); - bool debugInferiorhasBreakpoint(); - void on_actionStep_Over_triggered(); void on_actionStep_Into_triggered(); @@ -200,27 +223,6 @@ private slots: void on_cbSearchHistory_currentIndexChanged(int index); void on_btnSearchAgin_clicked(); - -public slots: - void onCompileLog(const QString& msg); - void onCompileIssue(PCompileIssue issue); - void onCompileFinished(); - void onCompileErrorOccured(const QString& reason); - void onRunErrorOccured(const QString& reason); - void onRunFinished(); - void cleanUpCPUDialog(); - void onDebugCommandInput(const QString& command); - void onDebugEvaluateInput(); - void onParserProgress(const QString& fileName, int total, int current); - void onStartParsing(); - void onEndParsing(int total, int updateView); - void onEvalValueReady(const QString& value); - -private: - void setupActions(); - void openCloseMessageSheet(bool open); - void prepareDebugger(); - private: Ui::MainWindow *ui; EditorList *mEditorList; @@ -254,6 +256,8 @@ private: int mPreviousHeight; PCompileSuccessionTask mCompileSuccessionTask; + QTimer mAutoSaveTimer; + // QWidget interface protected: diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 83826c79..27701b8f 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -376,6 +376,46 @@ void Settings::Editor::setDefaultFileCpp(bool newDefaultFileCpp) mDefaultFileCpp = newDefaultFileCpp; } +bool Settings::Editor::enableAutoSave() const +{ + return mEnableAutoSave; +} + +void Settings::Editor::setEnableAutoSave(bool newEnableAutoSave) +{ + mEnableAutoSave = newEnableAutoSave; +} + +int Settings::Editor::autoSaveInterval() const +{ + return mAutoSaveInterval; +} + +void Settings::Editor::setAutoSaveInterval(int newInterval) +{ + mAutoSaveInterval = newInterval; +} + +AutoSaveStrategy Settings::Editor::autoSaveStrategy() const +{ + return mAutoSaveStrategy; +} + +void Settings::Editor::setAutoSaveStrategy(AutoSaveStrategy newAutoSaveStrategy) +{ + mAutoSaveStrategy = newAutoSaveStrategy; +} + +AutoSaveTarget Settings::Editor::autoSaveTarget() const +{ + return mAutoSaveTarget; +} + +void Settings::Editor::setAutoSaveTarget(AutoSaveTarget newAutoSaveTarget) +{ + mAutoSaveTarget = newAutoSaveTarget; +} + bool Settings::Editor::autoLoadLastFiles() const { return mAutoLoadLastFiles; @@ -831,6 +871,12 @@ void Settings::Editor::doSave() saveValue("check_syntax_when_save",mSyntaxCheckWhenSave); saveValue("check_syntax_when_line_changed",mSyntaxCheckWhenLineChanged); + //auto save + saveValue("enable_auto_save",mEnableAutoSave); + saveValue("auto_save_interal",mAutoSaveInterval); + saveValue("auto_save_target",mAutoSaveTarget); + saveValue("auto_save_strategy",mAutoSaveStrategy); + //misc saveValue("default_encoding",mDefaultEncoding); saveValue("readonly_system_header",mReadOnlySytemHeader); @@ -915,6 +961,14 @@ void Settings::Editor::doLoad() mSyntaxCheckWhenSave = boolValue("check_syntax_when_save",true); mSyntaxCheckWhenLineChanged = boolValue("check_syntax_when_line_changed",true); + //auto save + mEnableAutoSave = boolValue("enable_auto_save",false); + mAutoSaveInterval = intValue("auto_save_interal",10); + mAutoSaveTarget = static_cast( + intValue("auto_save_target",AutoSaveTarget::astCurrentFile)); + mAutoSaveStrategy = static_cast( + intValue("auto_save_strategy",AutoSaveStrategy::assOverwrite)); + //misc mDefaultEncoding = value("default_encoding", ENCODING_SYSTEM_DEFAULT).toByteArray(); mReadOnlySytemHeader = boolValue("readonly_system_header",true); @@ -1602,7 +1656,7 @@ void Settings::CompilerSet::setDefines() { arguments.append("-std=c++17"); arguments.append(NULL_FILE); QFileInfo ccompiler(mCCompiler); - QByteArray output = getCompilerOutput(ccompiler.absolutePath(),ccompiler.baseName(),arguments); + QByteArray output = getCompilerOutput(ccompiler.absolutePath(),ccompiler.fileName(),arguments); // 'cpp.exe -dM -E -x c++ -std=c++17 NUL' mDefines.clear(); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 751ecd27..49a9532b 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -271,6 +271,18 @@ public: bool defaultFileCpp() const; void setDefaultFileCpp(bool newDefaultFileCpp); + bool enableAutoSave() const; + void setEnableAutoSave(bool newEnableAutoSave); + + int autoSaveInterval() const; + void setAutoSaveInterval(int newInterval); + + AutoSaveTarget autoSaveTarget() const; + void setAutoSaveTarget(AutoSaveTarget newAutoSaveTarget); + + AutoSaveStrategy autoSaveStrategy() const; + void setAutoSaveStrategy(AutoSaveStrategy newAutoSaveStrategy); + private: //General // indents @@ -346,6 +358,12 @@ public: bool mSyntaxCheckWhenSave; bool mSyntaxCheckWhenLineChanged; + //auto save + bool mEnableAutoSave; + int mAutoSaveInterval; + enum AutoSaveTarget mAutoSaveTarget; + enum AutoSaveStrategy mAutoSaveStrategy; + //Misc QByteArray mDefaultEncoding; bool mReadOnlySytemHeader; diff --git a/RedPandaIDE/settingsdialog/editorautosavewidget.cpp b/RedPandaIDE/settingsdialog/editorautosavewidget.cpp new file mode 100644 index 00000000..1a9fad19 --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorautosavewidget.cpp @@ -0,0 +1,94 @@ +#include "editorautosavewidget.h" +#include "ui_editorautosavewidget.h" +#include "../settings.h" +#include "../mainwindow.h" + +EditorAutoSaveWidget::EditorAutoSaveWidget(const QString& name, const QString& group, + QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::EditorAutoSaveWidget) +{ + ui->setupUi(this); +} + +EditorAutoSaveWidget::~EditorAutoSaveWidget() +{ + delete ui; +} + +void EditorAutoSaveWidget::onAutoSaveStrategyChanged() +{ + if (ui->rbOverwrite->isChecked()) { + ui->lblFilename->setText(tr("Demo file name: ") + "main.cpp"); + } else if (ui->rbAppendUNIXTimestamp->isChecked()) { + ui->lblFilename->setText(tr("Demo file name: ") + + QString("main.%1.cpp").arg(QDateTime::currentSecsSinceEpoch())); + } else if (ui->rbAppendFormattedTimestamp->isChecked()) { + QDateTime time = QDateTime::currentDateTime(); + ui->lblFilename->setText(tr("Demo file name: ") + + QString("main.%1.cpp").arg(time.toString("yyyy.MM.dd.hh.mm.ss"))); + } +} + +void EditorAutoSaveWidget::doLoad() +{ + //pSettings->editor().load(); + //font + ui->chkEnableAutoSave->setChecked(pSettings->editor().enableAutoSave()); + ui->spinInterval->setValue(pSettings->editor().autoSaveInterval()); + switch(pSettings->editor().autoSaveTarget()) { + case astCurrentFile: + ui->rbCurrentFile->setChecked(true); + break; + case astAllOpennedFiles: + ui->rbAllOpennedFiles->setChecked(true); + default: + ui->rbProjectFiles->setChecked(true); + } + switch(pSettings->editor().autoSaveStrategy()) { + case assOverwrite: + ui->rbOverwrite->setChecked(true); + break; + case assAppendUnixTimestamp: + ui->rbAppendUNIXTimestamp->setChecked(true); + break; + default: + ui->rbAppendFormattedTimestamp->setChecked(true); + } +} + +void EditorAutoSaveWidget::doSave() +{ + pSettings->editor().setEnableAutoSave(ui->chkEnableAutoSave->isChecked()); + pSettings->editor().setAutoSaveInterval(ui->spinInterval->value()); + if (ui->rbCurrentFile->isChecked()) + pSettings->editor().setAutoSaveTarget(astCurrentFile); + else if (ui->rbAllOpennedFiles->isChecked()) + pSettings->editor().setAutoSaveTarget(astAllOpennedFiles); + else + pSettings->editor().setAutoSaveTarget(astAllProjectFiles); + if (ui->rbOverwrite->isChecked()) + pSettings->editor().setAutoSaveStrategy(assOverwrite); + else if (ui->rbAppendUNIXTimestamp->isChecked()) + pSettings->editor().setAutoSaveStrategy(assAppendUnixTimestamp); + else + pSettings->editor().setAutoSaveStrategy(assAppendFormatedTimeStamp); +} + +void EditorAutoSaveWidget::on_rbOverwrite_toggled(bool) +{ + onAutoSaveStrategyChanged(); +} + + +void EditorAutoSaveWidget::on_rbAppendUNIXTimestamp_toggled(bool) +{ + onAutoSaveStrategyChanged(); +} + + +void EditorAutoSaveWidget::on_rbAppendFormattedTimestamp_toggled(bool) +{ + onAutoSaveStrategyChanged(); +} + diff --git a/RedPandaIDE/settingsdialog/editorautosavewidget.h b/RedPandaIDE/settingsdialog/editorautosavewidget.h new file mode 100644 index 00000000..9fc289dc --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorautosavewidget.h @@ -0,0 +1,34 @@ +#ifndef EDITORAUTOSAVEWIDGET_H +#define EDITORAUTOSAVEWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class EditorAutoSaveWidget; +} + +class EditorAutoSaveWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit EditorAutoSaveWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~EditorAutoSaveWidget(); + +private: + void onAutoSaveStrategyChanged(); +private: + Ui::EditorAutoSaveWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +private slots: + void on_rbOverwrite_toggled(bool checked); + void on_rbAppendUNIXTimestamp_toggled(bool checked); + void on_rbAppendFormattedTimestamp_toggled(bool checked); +}; + +#endif // EDITORAUTOSAVEWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editorautosavewidget.ui b/RedPandaIDE/settingsdialog/editorautosavewidget.ui new file mode 100644 index 00000000..5f36b260 --- /dev/null +++ b/RedPandaIDE/settingsdialog/editorautosavewidget.ui @@ -0,0 +1,164 @@ + + + EditorAutoSaveWidget + + + + 0 + 0 + 469 + 459 + + + + Form + + + + + + Enable auto save + + + true + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Time interval: + + + + + + + minutes + + + 1 + + + 60 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Objects to save + + + + + + Current File + + + + + + + All files openned + + + + + + + Project files + + + + + + + + + + Save strategy + + + + + + Overwrite + + + + + + + Append UNIX timestamp + + + + + + + Append formatted timestamp + + + + + + + + + + Demo file name: + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 0d3526b2..51b274e1 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -9,6 +9,7 @@ #include "editorcodecompletionwidget.h" #include "editorsyntaxcheckwidget.h" #include "editorsymbolcompletionwidget.h" +#include "editorautosavewidget.h" #include "editormiscwidget.h" #include "environmentappearencewidget.h" #include "executorgeneralwidget.h" @@ -65,6 +66,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : pEditorSyntaxCheckWidget->init(); addWidget(pEditorSyntaxCheckWidget); + pEditorAutoSaveWidget = new EditorAutoSaveWidget(tr("Auto save"),tr("Editor")); + pEditorAutoSaveWidget->init(); + addWidget(pEditorAutoSaveWidget); + pEditorMiscWidget = new EditorMiscWidget(tr("Misc"),tr("Editor")); pEditorMiscWidget->init(); addWidget(pEditorMiscWidget); diff --git a/RedPandaIDE/settingsdialog/settingsdialog.h b/RedPandaIDE/settingsdialog/settingsdialog.h index d44bf449..080db4af 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.h +++ b/RedPandaIDE/settingsdialog/settingsdialog.h @@ -18,6 +18,7 @@ class EditorSymbolCompletionWidget; class EditorColorSchemeWidget; class EditorSyntaxCheckWidget; class EditorCodeCompletionWidget; +class EditorAutoSaveWidget; class EditorMiscWidget; class EnvironmentAppearenceWidget; class ExecutorGeneralWidget; @@ -60,6 +61,7 @@ private: EditorSymbolCompletionWidget *pEditorSymbolCompletionWidget; EditorCodeCompletionWidget *pEditorCodeCompletionWidget; EditorSyntaxCheckWidget *pEditorSyntaxCheckWidget; + EditorAutoSaveWidget *pEditorAutoSaveWidget; EditorMiscWidget *pEditorMiscWidget; ExecutorGeneralWidget *pExecutorGeneralWidget; DebugGeneralWidget *pDebugGeneralWidget; diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 88ef4426..95a4f12e 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -40,6 +40,18 @@ enum class SearchFileScope { openedFiles }; +enum AutoSaveTarget { + astCurrentFile, + astAllOpennedFiles, + astAllProjectFiles +}; + +enum AutoSaveStrategy { + assOverwrite, + assAppendUnixTimestamp, + assAppendFormatedTimeStamp +}; + class BaseError{ public: explicit BaseError(const QString& reason);