diff --git a/3rdparty/AngelScript b/3rdparty/AngelScript index b2af78b..f203476 160000 --- a/3rdparty/AngelScript +++ b/3rdparty/AngelScript @@ -1 +1 @@ -Subproject commit b2af78b2b0a9d9370a69f0f762fd0f405cf63e41 +Subproject commit f2034769ce887367e97a5fbaced5b14aa8039fd3 diff --git a/3rdparty/qcodeedit2/lib/qeditor.cpp b/3rdparty/qcodeedit2/lib/qeditor.cpp index 0e21064..00e2753 100644 --- a/3rdparty/qcodeedit2/lib/qeditor.cpp +++ b/3rdparty/qcodeedit2/lib/qeditor.cpp @@ -76,7 +76,7 @@ #endif #ifdef Q_GL_EDITOR -#include +#include #endif #define QCE_ACTION(name, action) \ @@ -444,7 +444,7 @@ QEditor::~QEditor() { */ void QEditor::init(bool actions) { #ifdef Q_GL_EDITOR - setViewport(new QGLWidget); + setViewport(new QOpenGLWidget); #endif viewport()->setCursor(Qt::IBeamCursor); @@ -512,7 +512,7 @@ void QEditor::init(bool actions) { QAction *a, *sep; - a = new QAction(QIcon(":/undo.png"), tr("&Undo"), this); + a = new QAction(QIcon(":/qeditor/undo.png"), tr("&Undo"), this); a->setObjectName("undo"); Q_SHORTCUT(a, "Ctrl+Z", "Edit"); a->setEnabled(false); @@ -521,7 +521,7 @@ void QEditor::init(bool actions) { addAction(a, "&Edit", "Edit"); - a = new QAction(QIcon(":/redo.png"), tr("&Redo"), this); + a = new QAction(QIcon(":/qeditor/redo.png"), tr("&Redo"), this); a->setObjectName("redo"); Q_SHORTCUT(a, "Ctrl+Y", "Edit"); a->setEnabled(false); @@ -534,7 +534,7 @@ void QEditor::init(bool actions) { sep->setSeparator(true); addAction(sep, "&Edit", "Edit"); - a = new QAction(QIcon(":/cut.png"), tr("Cu&t"), this); + a = new QAction(QIcon(":/qeditor/cut.png"), tr("Cu&t"), this); a->setObjectName("cut"); Q_SHORTCUT(a, "Ctrl+X", "Edit"); a->setEnabled(false); @@ -543,7 +543,7 @@ void QEditor::init(bool actions) { addAction(a, "&Edit", "Edit"); - a = new QAction(QIcon(":/copy.png"), tr("&Copy"), this); + a = new QAction(QIcon(":/qeditor/copy.png"), tr("&Copy"), this); a->setObjectName("copy"); Q_SHORTCUT(a, "Ctrl+C", "Edit"); a->setEnabled(false); @@ -552,7 +552,7 @@ void QEditor::init(bool actions) { addAction(a, "&Edit", "Edit"); - a = new QAction(QIcon(":/paste.png"), tr("&Paste"), this); + a = new QAction(QIcon(":/qeditor/paste.png"), tr("&Paste"), this); a->setObjectName("paste"); // aPaste->setEnabled(QApplication::clipboard()->text().count()); Q_SHORTCUT(a, "Ctrl+V", "Edit"); @@ -567,14 +567,14 @@ void QEditor::init(bool actions) { sep->setSeparator(true); addAction(sep, "&Edit", "Edit"); - a = new QAction(QIcon(":/indent.png"), tr("&Indent"), this); + a = new QAction(tr("&Indent"), this); a->setObjectName("indent"); Q_SHORTCUT(a, "Ctrl+I", "Edit"); connect(a, SIGNAL(triggered()), this, SLOT(indentSelection())); addAction(a, "&Edit", "Edit"); - a = new QAction(QIcon(":/unindent.png"), tr("&Unindent"), this); + a = new QAction(tr("&Unindent"), this); a->setObjectName("unindent"); Q_SHORTCUT(a, "Ctrl+Shift+I", "Edit"); connect(a, SIGNAL(triggered()), this, SLOT(unindentSelection())); @@ -585,14 +585,14 @@ void QEditor::init(bool actions) { sep->setSeparator(true); addAction(sep, "&Edit", ""); - a = new QAction(QIcon(":/comment.png"), tr("Co&mment"), this); + a = new QAction(tr("Co&mment"), this); a->setObjectName("comment"); Q_SHORTCUT(a, "Ctrl+D", "Edit"); connect(a, SIGNAL(triggered()), this, SLOT(commentSelection())); addAction(a, "&Edit", "Edit"); - a = new QAction(QIcon(":/uncomment.png"), tr("Unc&omment"), this); + a = new QAction(tr("Unc&omment"), this); a->setObjectName("uncomment"); Q_SHORTCUT(a, "Ctrl+Shift+D", "Edit"); connect(a, SIGNAL(triggered()), this, SLOT(uncommentSelection())); @@ -614,21 +614,21 @@ void QEditor::init(bool actions) { sep->setSeparator(true); addAction(sep, QString()); - a = new QAction(QIcon(":/find.png"), tr("&Find"), this); + a = new QAction(QIcon(":/qeditor/find.png"), tr("&Find"), this); a->setObjectName("find"); Q_SHORTCUT(a, "Ctrl+F", "Search"); connect(a, SIGNAL(triggered()), this, SLOT(find())); addAction(a, "&Search", "Search"); - a = new QAction(QIcon(":/next.png"), tr("Fin&d next"), pMenu); + a = new QAction(tr("Fin&d next"), pMenu); a->setObjectName("findNext"); Q_SHORTCUT(a, "F3", "Search"); connect(a, SIGNAL(triggered()), this, SLOT(findNext())); addAction(a, "&Search", "Search"); - a = new QAction(QIcon(":/replace.png"), tr("&Replace"), this); + a = new QAction(QIcon(":/qeditor/replace.png"), tr("&Replace"), this); a->setObjectName("replace"); Q_SHORTCUT(a, "Ctrl+R", "Search"); connect(a, SIGNAL(triggered()), this, SLOT(replace())); @@ -639,7 +639,7 @@ void QEditor::init(bool actions) { sep->setSeparator(true); addAction(sep, "&Search", "Search"); - a = new QAction(QIcon(":/goto.png"), tr("&Goto line..."), this); + a = new QAction(QIcon(":/qeditor/goto.png"), tr("&Goto line..."), this); a->setObjectName("goto"); Q_SHORTCUT(a, "Ctrl+G", "Search"); connect(a, SIGNAL(triggered()), this, SLOT(gotoLine())); diff --git a/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.cpp b/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.cpp index 8dfc170..2918a42 100644 --- a/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.cpp +++ b/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.cpp @@ -156,23 +156,12 @@ void QLineMarkPanel::mouseReleaseEvent(QMouseEvent *e) { } // QMessageBox::warning(0, 0, "clik."); - - QDocumentLine l; - QLanguageDefinition *d = editor()->languageDefinition(); - const int id = - QLineMarksInfoCenter::instance()->markTypeId(d->defaultLineMark()); - - if (id < 0) - return; - e->accept(); for (int i = 0; i < m_rects.count(); ++i) { if (m_rects.at(i).contains(e->pos())) { - l = editor()->document()->line(m_lines.at(i)); - l.toggleMark(id); - // m->toggleDefaultMark(l, -1); - + auto l = editor()->document()->line(m_lines.at(i)); + emit onToggleMark(i); break; } } diff --git a/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.h b/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.h index bb624e6..4f576fa 100644 --- a/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.h +++ b/3rdparty/qcodeedit2/lib/widgets/qlinemarkpanel.h @@ -41,6 +41,9 @@ public: virtual QString type() const; +signals: + void onToggleMark(int lineIndex); + protected: virtual bool paint(QPainter *p, QEditor *e); virtual void mousePressEvent(QMouseEvent *e); diff --git a/CMakeLists.txt b/CMakeLists.txt index eefb484..68a998b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) option(QWINDOWKIT_BUILD_STATIC "Build static libraries" TRUE) option(QWINDOWKIT_INSTALL "Install library" OFF) set(ADS_VERSION 4.3.1) +option(BUILD_EXAMPLES "Build the examples" FALSE) add_subdirectory(3rdparty/qwindowkit) add_subdirectory(3rdparty/QHexView) @@ -287,8 +288,6 @@ set(CODEEDIT_WIDGET src/qcodeeditwidget/qeditconfig.h src/qcodeeditwidget/qeditconfig.cpp src/qcodeeditwidget/qeditconfig.ui - src/qcodeeditwidget/qstatuspanel.cpp - src/qcodeeditwidget/qstatuspanel.h src/qcodeeditwidget/qformatconfig.h src/qcodeeditwidget/qformatconfig.cpp src/qcodeeditwidget/qformatconfig.ui) diff --git a/lang/zh_CN/winghex.ts b/lang/zh_CN/winghex.ts index b5e5165..61820e2 100644 --- a/lang/zh_CN/winghex.ts +++ b/lang/zh_CN/winghex.ts @@ -1818,7 +1818,7 @@ &Trigger completion - + 触发填充(&T) @@ -1941,25 +1941,30 @@ Restart from the begining ? Preserve trailing indent 保留尾部缩进 + + + Edit + 编辑 + QEditor Panels - + 面板 &View - + 视图(&V) Default - 默认 + 默认 @@ -1995,102 +2000,102 @@ Restart from the begining ? &Indent - + 缩进(&I) &Unindent - + 取消缩进(&U) Co&mment - + 批注(&M) Unc&omment - + 取消批注(&O) &Select all - + 全选(&S) &Find - + 查找(&F) Fin&d next - + 查找下一个(&D) &Replace - + 替换(&R) &Goto line... - + 跳转到行(&G) Dynamic line wrapping - + 自动换行 Input binding - + 输入绑定 Line endings - + 行尾 Conservative - + 老式 Local - 本地 + 本地 Unix/Linux - Unix/Linux + Unix/Linux Dos/Windows - + Dos/Windows Old Mac - 老版 Mac + 老版 Mac Conflict! - + 冲突! @@ -2100,12 +2105,16 @@ Press "Save" to overwrite the file on disk Press "Reset"to be reload the file from disk. Press "Discard" to ignore this warning. - + %1 +已被另一个应用程序修改。 +按“保存”覆盖磁盘上的文件 +按“重置”从磁盘重新加载文件。 +按“放弃”忽略此警告。 File changed - + 文件被修改 @@ -2114,37 +2123,41 @@ has been modified by another application. Undo/Redo stack would be discarded by the auto-reload. Do you wish to keep up to date by reloading the file? - + %1 +已被另一个应用程序修改。 + +撤消/重做堆栈将被自动重新加载丢弃。 +您是否希望通过重新加载文件来保持最新状态? &Edit - + 编辑(&E) &Search - + 查找(&S) Edit - 编辑 + 编辑 Search - + 查找 Windows - + 窗口 Unix - + Unix @@ -2180,59 +2193,64 @@ Do you wish to keep up to date by reloading the file? - + + Format + + + + Bold - + Italic - + Underline - + Overline - + Strikeout - + Wave underline - + Text color (aka foreground) - + Background color - + Lines color (used by all lines formatting : underline, overline, ...) - - + + Unsaved changes - - + + There are unsaved changes in this format scheme. Do you want them to be saved? @@ -2452,29 +2470,6 @@ Do you want them to be saved? - - QStatusPanel - - - Line : %1 Visual column : %2 Text column : %3 - - - - - OVERWRITE - - - - - INSERT - - - - - Conflict - - - RecentFileManager @@ -4298,353 +4293,354 @@ Do you want them to be saved? ScriptingDialog - + ScriptEditor 脚本编辑器 - + File 文件 - + Edit 编辑 - + Debugger 调试器 - - Setting - 设置 - - - + About 关于 - + Basic 基础 - + New 新建 - + OpenF 打开文件 - + RecentFiles 最近打开 - + Reload 重新加载 - - + + Save 保存 - + SaveAs 另存为 - + General 基本 - + Undo 撤销 - + Redo 恢复 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + Delete 删除 - + Lookup 查询 - + Find 查找 - + Replace 替换 - + Goto 跳转 - + Display 显示 - + Scale 缩放 - + ResetScale 重置缩放 - + Window 窗体 - - + + Editor 编辑器 - + Tools 工具 - + BreakPoint 断点 - + ToggleBreakPoint 切换断点 - + AddBreakPoint 添加断点 - + Settings 设置 - + Local 本地 - + Global 全局 - + Variables 变量 - + BreakPoints 断点 - + ConsoleOutput 输出 - + StackTrace 栈跟踪 - + Watch 监视 - - - - - - + + + + + + Error 错误 - + Too much opened files 打开的文件过多,无法继续操作! - - + + ChooseFile 选择文件 - - - + + + FilePermission 因文件权限无法继续! - + ReloadSuccessfully 文件重新加载成功! - + ReloadUnSuccessfully 文件重新加载失败! - + ChooseSaveFile 请选择保存文件路径: - - + + SaveSuccessfully 保存成功! - + SaveUnSuccessfully 保存失败! - + + + CannotSave2RunScript + 无法保存,故无法继续运行脚本。 + + + ScriptStillRunning 脚本仍在运行,你确定要退出吗? - + View 视图 - + Debug 调试 - + Run 运行 - + RunWithDbg 调试运行 - + Pause 暂停 - + Continue 继续 - + Stop 停止 - + Restart 重启 - + StepInto 单步步入 - + StepOver 单步步过 - + StepOut 单步跳出 - + RemoveBreakPoint 删除断点 - + Info 信息 - + Software 软件 - + Sponsor 赞助 - + Wiki 网页 Wiki - + AboutQT 关于 QT @@ -4924,29 +4920,29 @@ Do you want them to be saved? Failed to open script file - 带卡脚本文件失败 + 打开脚本文件失败 Invalid file name for #include; it contains a line-break: - + #include 的文件名无效;它包含换行符: Invalid file name for #include; it contains a line-break or unpaired symbol - + #include 的文件名无效;它包含换行符或不成对的符号 Invalid #pragma directive - + #pragma 指令无效 asDebugger - + {no engine} {无引擎} diff --git a/resources.qrc b/resources.qrc index d456fa7..967c4b7 100644 --- a/resources.qrc +++ b/resources.qrc @@ -110,4 +110,15 @@ src/qxs/as_light.qxf src/qxs/marks.qxm + + images/copy.png + images/cut.png + images/find.png + images/paste.png + images/redo.png + images/replace.png + images/undo.png + images/goto.png + + diff --git a/src/class/asdebugger.cpp b/src/class/asdebugger.cpp index ff0915a..2667df4 100644 --- a/src/class/asdebugger.cpp +++ b/src/class/asdebugger.cpp @@ -21,10 +21,6 @@ void asDebugger::registerToStringCallback(const asITypeInfo *ti, m_toStringCallbacks.insert(ti, callback); } -void asDebugger::registerBreakPointHitCallback(BreakPointHitCallback callback) { - m_bphitCallback = callback; -} - void asDebugger::takeCommands(asIScriptContext *ctx) { emit onPullVariables(globalVariables(ctx), localVariables(ctx)); emit onPullCallStack(retriveCallstack(ctx)); @@ -38,11 +34,14 @@ void asDebugger::takeCommands(asIScriptContext *ctx) { ctx->Abort(); return; case PAUSE: + Q_ASSERT(false); break; case STEP_OVER: - case STEP_OUT: m_lastCommandAtStackLevel = ctx ? ctx->GetCallstackSize() : 1; break; + case STEP_OUT: + m_lastCommandAtStackLevel = ctx ? ctx->GetCallstackSize() : 0; + break; case CONTINUE: case STEP_INTO: break; @@ -56,6 +55,25 @@ void asDebugger::lineCallback(asIScriptContext *ctx) { if (ctx == nullptr) return; + const char *file = 0; + int lineNbr = ctx->GetLineNumber(0, nullptr, &file); + + // why? + // LineCallBack will be called each only a sentence, + // just like a bytecode level debugger + // for(auto i = 0; i < 5 ; i++) this line will break twice at first + if (ctx->GetUserData() == nullptr) { + auto dbgContext = new ContextDbgInfo; + ctx->SetUserData(dbgContext); + } else { + auto dbgContext = + reinterpret_cast(ctx->GetUserData()); + if (dbgContext->line == lineNbr && dbgContext->file == file && + dbgContext->stackCount == ctx->GetCallstackSize()) { + return; + } + } + // By default we ignore callbacks when the context is not active. // An application might override this to for example disconnect the // debugger as the execution finished. @@ -64,18 +82,14 @@ void asDebugger::lineCallback(asIScriptContext *ctx) { switch (m_action) { case ABORT: - ctx->Abort(); return; case PAUSE: - break; + return; case CONTINUE: if (!checkBreakPoint(ctx)) return; break; case STEP_INTO: - // Always break, but we call the check break point anyway - // to tell user when break point has been reached - checkBreakPoint(ctx); m_action = PAUSE; break; case STEP_OVER: @@ -89,8 +103,12 @@ void asDebugger::lineCallback(asIScriptContext *ctx) { break; } - const char *file = 0; - int lineNbr = ctx->GetLineNumber(0, nullptr, &file); + auto dbgContext = reinterpret_cast(ctx->GetUserData()); + Q_ASSERT(dbgContext); + dbgContext->file = file; + dbgContext->line = lineNbr; + dbgContext->stackCount = ctx->GetCallstackSize(); + emit onRunCurrentLine(file, lineNbr); takeCommands(ctx); @@ -213,7 +231,7 @@ void asDebugger::listMemberProperties(asIScriptContext *ctx) { } bool asDebugger::checkBreakPoint(asIScriptContext *ctx) { - if (ctx == 0) + if (ctx == nullptr) return false; const char *tmp = 0; @@ -272,8 +290,6 @@ bool asDebugger::checkBreakPoint(asIScriptContext *ctx) { #else bpName == file) { #endif - ctx->Suspend(); - m_bphitCallback(m_breakPoints[n], this); m_action = PAUSE; // hit and pause script return true; } @@ -414,6 +430,8 @@ asDebugger::GCStatistic asDebugger::gcStatistics() { void asDebugger::runDebugAction(DebugAction action) { m_action = action; } +asDebugger::DebugAction asDebugger::currentState() const { return m_action; } + void asDebugger::setEngine(asIScriptEngine *engine) { if (m_engine != engine) { if (m_engine) diff --git a/src/class/asdebugger.h b/src/class/asdebugger.h index 03264b0..8d596b1 100644 --- a/src/class/asdebugger.h +++ b/src/class/asdebugger.h @@ -78,10 +78,6 @@ public: void registerToStringCallback(const asITypeInfo *ti, ToStringCallback callback); - typedef void (*BreakPointHitCallback)(const BreakPoint &bp, - asDebugger *dbg); - void registerBreakPointHitCallback(BreakPointHitCallback callback); - // Commands void addFileBreakPoint(const QString &file, int lineNbr); void removeFileBreakPoint(const QString &file, int lineNbr); @@ -108,6 +104,8 @@ public: void runDebugAction(DebugAction action); + DebugAction currentState() const; + private: QVector globalVariables(asIScriptContext *ctx); QVector localVariables(asIScriptContext *ctx); @@ -131,6 +129,13 @@ signals: void onPullCallStack(const QList &callstacks); void onRunCurrentLine(const QString &file, int lineNr); +private: + struct ContextDbgInfo { + QString file; + int line = -1; + int stackCount = -1; + }; + private: std::atomic m_action; @@ -143,7 +148,6 @@ private: // Registered callbacks for converting types to strings QMap m_toStringCallbacks; - BreakPointHitCallback m_bphitCallback; QStringList m_watchVars; diff --git a/src/control/scripteditor.cpp b/src/control/scripteditor.cpp index 955b620..589ebbf 100644 --- a/src/control/scripteditor.cpp +++ b/src/control/scripteditor.cpp @@ -31,12 +31,16 @@ ScriptEditor::ScriptEditor(QWidget *parent) auto lineMark = new QLineMarkPanel(editor); m_editor->addPanel(lineMark, QCodeEdit::West, true); + connect(lineMark, &QLineMarkPanel::onToggleMark, this, + &ScriptEditor::onToggleMark); auto lineNum = new QLineNumberPanel(editor); lineNum->setVerboseMode(true); m_editor->addPanel(lineNum, QCodeEdit::West, true); m_editor->addPanel(QStringLiteral("Fold Panel"), QCodeEdit::West, true); + m_editor->addPanel(QStringLiteral("Line Change Panel"), QCodeEdit::West, + true); m_editor->addPanel(QStringLiteral("Goto Line Panel"), QCodeEdit::South, true); m_editor->addPanel(QStringLiteral("Search Replace Panel"), QCodeEdit::South, diff --git a/src/control/scripteditor.h b/src/control/scripteditor.h index d1ea9e6..2061fad 100644 --- a/src/control/scripteditor.h +++ b/src/control/scripteditor.h @@ -15,6 +15,9 @@ public: QEditor *editor() const; +signals: + void onToggleMark(int lineIndex); + public slots: bool openFile(const QString &filename); diff --git a/src/dialog/scriptingdialog.cpp b/src/dialog/scriptingdialog.cpp index 189ba5d..4a09f89 100644 --- a/src/dialog/scriptingdialog.cpp +++ b/src/dialog/scriptingdialog.cpp @@ -57,6 +57,8 @@ ScriptingDialog::ScriptingDialog(QWidget *parent) layout->addWidget(m_status); buildUpContent(cw); + buildUpSettingDialog(); + QFormatScheme *format = nullptr; switch (SkinManager::instance().currentTheme()) { @@ -98,7 +100,9 @@ void ScriptingDialog::initConsole() { m_consoleout->init(); auto machine = m_consoleout->machine(); connect(machine, &ScriptMachine::onDebugFinished, this, [=] { - this->setRunDebugMode(false); + _DebugingScript.clear(); + + this->updateRunDebugMode(); m_callstack->updateData({}); // clean up @@ -106,23 +110,28 @@ void ScriptingDialog::initConsole() { // no need return; } - QLineMark mrk(_lastCurLine.first, _lastCurLine.second, - m_symID.value(Symbols::DbgRunCurrentLine)); - QLineMarksInfoCenter::instance()->removeLineMark(mrk); + + auto bpMark = m_symID.value(Symbols::BreakPoint); + auto curMark = m_symID.value(Symbols::DbgRunCurrentLine); + auto curHitMark = m_symID.value(Symbols::DbgRunHitBreakPoint); + + // remove the last mark + if (!_lastCurLine.first.isEmpty() && _lastCurLine.second >= 0) { + auto lastCur = QCodeEdit::managed(_lastCurLine.first); + auto doc = lastCur->document(); + auto line = doc->line(_lastCurLine.second - 1); + if (line.hasMark(curMark)) { + line.removeMark(curMark); + } else if (line.hasMark(curHitMark)) { + line.removeMark(curHitMark); + line.addMark(bpMark); + } + } _lastCurLine.first.clear(); _lastCurLine.second = -1; }); auto dbg = machine->debugger(); Q_ASSERT(dbg); - dbg->setProperty("scriptdlg", QVariant::fromValue(this)); - dbg->registerBreakPointHitCallback( - [](const asDebugger::BreakPoint &bp, asDebugger *dbg) { - auto p = dbg->property("scriptdlg"); - if (p.isValid()) { - auto dlg = p.value(); - QMessageBox::information(dlg, "", "Hint"); - } - }); connect(dbg, &asDebugger::onAdjustBreakPointLine, this, [=](const asDebugger::BreakPoint &old, int newLineNr) { @@ -152,16 +161,36 @@ void ScriptingDialog::initConsole() { } } - // remove the last mark - QLineMark mrk(_lastCurLine.first, _lastCurLine.second, - m_symID.value(Symbols::DbgRunCurrentLine)); - QLineMarksInfoCenter::instance()->removeLineMark(mrk); - - auto doc = e->editor()->document(); + auto bpMark = m_symID.value(Symbols::BreakPoint); auto curMark = m_symID.value(Symbols::DbgRunCurrentLine); + auto curHitMark = m_symID.value(Symbols::DbgRunHitBreakPoint); + + // remove the last mark + if (!_lastCurLine.first.isEmpty() && _lastCurLine.second >= 0) { + auto lastCur = QCodeEdit::managed(_lastCurLine.first); + auto doc = lastCur->document(); + auto line = doc->line(_lastCurLine.second - 1); + if (line.hasMark(curMark)) { + line.removeMark(curMark); + } else if (line.hasMark(curHitMark)) { + line.removeMark(curHitMark); + line.addMark(bpMark); + } + } + + // add the new mark + auto doc = e->editor()->document(); auto line = doc->line(lineNr - 1); - line.addMark(curMark); + if (line.hasMark(bpMark)) { + line.removeMark(bpMark); + line.addMark(curHitMark); + } else { + line.addMark(curMark); + } + _lastCurLine = {file, lineNr}; + + updateRunDebugMode(); }); } @@ -171,7 +200,9 @@ void ScriptingDialog::buildUpRibbonBar() { m_editStateWidgets << buildEditPage(m_ribbon->addTab(tr("Edit"))); buildViewPage(m_ribbon->addTab(tr("View"))); m_editStateWidgets << buildDebugPage(m_ribbon->addTab(tr("Debugger"))); - buildSettingPage(m_ribbon->addTab(tr("Setting"))); + + // TODO: not available for v1.0.0 + // buildSettingPage(m_ribbon->addTab(tr("Setting"))); buildAboutPage(m_ribbon->addTab(tr("About"))); connect(m_ribbon, &Ribbon::onDragDropFiles, this, @@ -326,35 +357,50 @@ RibbonTabContent *ScriptingDialog::buildViewPage(RibbonTabContent *tab) { RibbonTabContent *ScriptingDialog::buildDebugPage(RibbonTabContent *tab) { { auto pannel = tab->addGroup(tr("Debug")); - m_Tbtneditors[ToolButtonIndex::DBG_RUN] = + m_Tbtneditors.insert( + ToolButtonIndex::DBG_RUN_ACTION, addPannelAction(pannel, QStringLiteral("dbgrun"), tr("Run"), &ScriptingDialog::on_runscript, - QKeySequence(Qt::CTRL | Qt::Key_F5)); - m_Tbtneditors[ToolButtonIndex::DBG_RUN_DBG] = addPannelAction( - pannel, QStringLiteral("dbgdebug"), tr("RunWithDbg"), - &ScriptingDialog::on_rundbgscript, QKeySequence(Qt::Key_F5)); - m_dbgStateWidgets << addPannelAction(pannel, QStringLiteral("dbgpause"), + QKeySequence(Qt::CTRL | Qt::Key_F5))); + m_Tbtneditors.insert(ToolButtonIndex::DBG_RUN_DBG_ACTION, + addPannelAction(pannel, QStringLiteral("dbgdebug"), + tr("RunWithDbg"), + &ScriptingDialog::on_rundbgscript, + QKeySequence(Qt::Key_F5))); + + m_Tbtneditors.insert(ToolButtonIndex::DBG_PAUSE_ACTION, + addPannelAction(pannel, QStringLiteral("dbgpause"), tr("Pause"), - &ScriptingDialog::on_pausescript); - m_dbgStateWidgets << addPannelAction( - pannel, QStringLiteral("dbgcontinue"), tr("Continue"), - &ScriptingDialog::on_continuescript); - m_dbgStateWidgets << addPannelAction(pannel, QStringLiteral("dbgstop"), + &ScriptingDialog::on_pausescript)); + m_Tbtneditors.insert( + ToolButtonIndex::DBG_CONTINUE_ACTION, + addPannelAction(pannel, QStringLiteral("dbgcontinue"), + tr("Continue"), + &ScriptingDialog::on_continuescript)); + + m_Tbtneditors.insert(ToolButtonIndex::DBG_STOP_ACTION, + addPannelAction(pannel, QStringLiteral("dbgstop"), tr("Stop"), - &ScriptingDialog::on_stopscript); - m_dbgStateWidgets << addPannelAction( - pannel, QStringLiteral("dbgrestart"), tr("Restart"), - &ScriptingDialog::on_restartscript); - m_dbgStateWidgets << addPannelAction( - pannel, QStringLiteral("dbgstepinto"), tr("StepInto"), - &ScriptingDialog::on_stepinscript, QKeySequence(Qt::Key_F11)); - m_dbgStateWidgets << addPannelAction( - pannel, QStringLiteral("dbgstepover"), tr("StepOver"), - &ScriptingDialog::on_stepoverscript, QKeySequence(Qt::Key_F10)); - m_dbgStateWidgets << addPannelAction( - pannel, QStringLiteral("dbgstepout"), tr("StepOut"), - &ScriptingDialog::on_stepoutscript, - QKeySequence(Qt::SHIFT | Qt::Key_F11)); + &ScriptingDialog::on_stopscript)); + m_Tbtneditors.insert( + ToolButtonIndex::DBG_RESTART_ACTION, + addPannelAction(pannel, QStringLiteral("dbgrestart"), tr("Restart"), + &ScriptingDialog::on_restartscript)); + m_Tbtneditors.insert( + ToolButtonIndex::DBG_STEPINTO_ACTION, + addPannelAction(pannel, QStringLiteral("dbgstepinto"), + tr("StepInto"), &ScriptingDialog::on_stepinscript, + QKeySequence(Qt::Key_F11))); + m_Tbtneditors.insert( + ToolButtonIndex::DBG_STEPOVER_ACTION, + addPannelAction(pannel, QStringLiteral("dbgstepover"), + tr("StepOver"), &ScriptingDialog::on_stepoverscript, + QKeySequence(Qt::Key_F10))); + m_Tbtneditors.insert( + ToolButtonIndex::DBG_STEPOUT_ACTION, + addPannelAction(pannel, QStringLiteral("dbgstepout"), tr("StepOut"), + &ScriptingDialog::on_stepoutscript, + QKeySequence(Qt::SHIFT | Qt::Key_F11))); m_editStateWidgets << pannel; } @@ -590,7 +636,7 @@ void ScriptingDialog::registerEditorView(ScriptEditor *editor) { auto m = m_consoleout->machine(); if (m->isInDebugMode()) { - auto dbg = m->debugger(); + // TODO } m_views.removeOne(editor); @@ -637,12 +683,7 @@ void ScriptingDialog::updateEditModeEnabled() { item->setEnabled(b); } - auto runner = m_consoleout->machine(); - if (runner) { - setRunDebugMode(runner->isRunning(), runner->isInDebugMode()); - } else { - setRunDebugMode(false); - } + updateRunDebugMode(); } ScriptEditor *ScriptingDialog::currentEditor() const { return m_curEditor; } @@ -653,6 +694,7 @@ void ScriptingDialog::swapEditor(ScriptEditor *old, ScriptEditor *cur) { } if (old != nullptr) { + old->disconnect(SLOT(onToggleMark(int))); auto editor = old->editor(); editor->disconnect(SLOT(copyAvailable(bool))); editor->disconnect(SLOT(contentModified(bool))); @@ -672,6 +714,11 @@ void ScriptingDialog::swapEditor(ScriptEditor *old, ScriptEditor *cur) { m_Tbtneditors.value(ToolButtonIndex::COPY_ACTION) ->setEnabled(editor->cursor().hasSelection()); + connect(cur, &ScriptEditor::onToggleMark, this, [=](int lineIndex) { + auto editor = qobject_cast(sender()); + Q_ASSERT(editor); + toggleBreakPoint(editor, lineIndex); + }); connect(editor, &QEditor::copyAvailable, m_Tbtneditors.value(ToolButtonIndex::COPY_ACTION), &QToolButton::setEnabled); @@ -695,12 +742,34 @@ void ScriptingDialog::swapEditor(ScriptEditor *old, ScriptEditor *cur) { m_curEditor = cur; } -void ScriptingDialog::setRunDebugMode(bool isRun, bool isDebug) { - m_Tbtneditors.value(ToolButtonIndex::DBG_RUN)->setEnabled(!isRun); - m_Tbtneditors.value(ToolButtonIndex::DBG_RUN_DBG)->setEnabled(!isRun); - for (auto &w : m_dbgStateWidgets) { - w->setEnabled(isRun && isDebug); +void ScriptingDialog::updateRunDebugMode() { + auto runner = m_consoleout->machine(); + bool isRun = false; + bool isDbg = false; + bool isPaused = false; + if (runner) { + isRun = runner->isRunning(); + isDbg = runner->isInDebugMode(); + auto dbg = runner->debugger(); + isPaused = dbg->currentState() == asDebugger::PAUSE; } + m_Tbtneditors.value(ToolButtonIndex::DBG_RUN_ACTION)->setEnabled(!isRun); + m_Tbtneditors.value(ToolButtonIndex::DBG_RUN_DBG_ACTION) + ->setEnabled(!isRun); + m_Tbtneditors.value(ToolButtonIndex::DBG_RESTART_ACTION) + ->setEnabled(isRun && isDbg); + m_Tbtneditors.value(ToolButtonIndex::DBG_STOP_ACTION)->setEnabled(isRun); + m_Tbtneditors.value(ToolButtonIndex::DBG_PAUSE_ACTION) + ->setEnabled(isRun && isDbg && !isPaused); + + auto dbgop = isRun && isDbg && isPaused; + m_Tbtneditors.value(ToolButtonIndex::DBG_CONTINUE_ACTION) + ->setEnabled(dbgop); + m_Tbtneditors.value(ToolButtonIndex::DBG_STEPINTO_ACTION) + ->setEnabled(dbgop); + m_Tbtneditors.value(ToolButtonIndex::DBG_STEPOVER_ACTION) + ->setEnabled(dbgop); + m_Tbtneditors.value(ToolButtonIndex::DBG_STEPOUT_ACTION)->setEnabled(dbgop); } ScriptEditor *ScriptingDialog::findEditorView(const QString &filename) { @@ -758,6 +827,70 @@ void ScriptingDialog::runDbgCommand(asDebugger::DebugAction action) { } } +void ScriptingDialog::buildUpSettingDialog() { + m_setdialog = new SettingDialog(this); + + auto edit = new QEditConfig(m_setdialog); + m_setdialog->addPage(edit); + + m_setdialog->build(); +} + +void ScriptingDialog::startDebugScript(const QString &fileName) { + m_consoleout->clear(); + + // add breakpoints + auto marks = QLineMarksInfoCenter::instance()->marks( + fileName, m_symID.value(Symbols::BreakPoint)); + auto dbg = m_consoleout->machine()->debugger(); + for (auto &bp : marks) { + dbg->addFileBreakPoint(bp.file, bp.line); + } + m_consoleout->machine()->executeScript(fileName, true); + updateRunDebugMode(); +} + +void ScriptingDialog::toggleBreakPoint(ScriptEditor *editor, int lineIndex) { + Q_ASSERT(editor); + auto curLine = lineIndex + 1; + +#ifdef Q_OS_WIN + if (m_consoleout->machine()->isInDebugMode() && + editor->fileName().compare(_lastCurLine.first, Qt::CaseInsensitive) == 0 +#else + if (editor->fileName() == _lastCurLine.first +#endif + && _lastCurLine.second == curLine) { + auto line = editor->editor()->document()->line(lineIndex); + auto bpMark = m_symID.value(Symbols::BreakPoint); + auto hitCur = m_symID.value(Symbols::DbgRunHitBreakPoint); + auto curSym = m_symID.value(Symbols::DbgRunCurrentLine); + + auto dbg = m_consoleout->machine()->debugger(); + if (line.hasMark(hitCur)) { + line.removeMark(hitCur); + line.addMark(curSym); + dbg->removeFileBreakPoint(editor->fileName(), curLine); + } else if (line.hasMark(curSym)) { + line.removeMark(curSym); + line.addMark(hitCur); + dbg->addFileBreakPoint(editor->fileName(), curLine); + } else { + if (line.hasMark(bpMark)) { + line.removeMark(bpMark); + dbg->removeFileBreakPoint(editor->fileName(), curLine); + } else { + line.addMark(bpMark); + dbg->addFileBreakPoint(editor->fileName(), curLine); + } + } + } else { + QLineMark mrk(editor->fileName(), curLine, + m_symID.value(Symbols::BreakPoint)); + QLineMarksInfoCenter::instance()->toggleLineMark(mrk); + } +} + void ScriptingDialog::on_newfile() { if (!newOpenFileSafeCheck()) { return; @@ -927,11 +1060,7 @@ void ScriptingDialog::on_gotoline() { } } -void ScriptingDialog::on_setting() { - // TODO - QEditConfig cfg; - cfg.show(); -} +void ScriptingDialog::on_setting() { m_setdialog->showConfig(); } void ScriptingDialog::on_about() { AboutSoftwareDialog().exec(); } @@ -964,12 +1093,14 @@ void ScriptingDialog::on_runscript() { auto editor = currentEditor(); if (editor) { auto e = editor->editor(); - m_consoleout->clear(); - setRunDebugMode(true, false); - if (!m_consoleout->machine()->executeScript(e->fileName())) { - setRunDebugMode(false); + if (!e->save()) { + WingMessageBox::critical(this, qAppName(), + tr("CannotSave2RunScript")); + return; } - setRunDebugMode(false); + m_consoleout->clear(); + m_consoleout->machine()->executeScript(e->fileName()); + updateRunDebugMode(); } } @@ -977,20 +1108,12 @@ void ScriptingDialog::on_rundbgscript() { auto editor = currentEditor(); if (editor) { auto e = editor->editor(); - m_consoleout->clear(); - setRunDebugMode(true, true); - - // add breakpoints - auto marks = QLineMarksInfoCenter::instance()->marks( - e->fileName(), m_symID.value(Symbols::BreakPoint)); - auto dbg = m_consoleout->machine()->debugger(); - for (auto &bp : marks) { - dbg->addFileBreakPoint(bp.file, bp.line); - } - - if (!m_consoleout->machine()->executeScript(e->fileName(), true)) { - setRunDebugMode(false); + if (!e->save()) { + WingMessageBox::critical(this, qAppName(), + tr("CannotSave2RunScript")); + return; } + startDebugScript(e->fileName()); } } @@ -1002,7 +1125,10 @@ void ScriptingDialog::on_continuescript() { void ScriptingDialog::on_stopscript() { runDbgCommand(asDebugger::ABORT); } -void ScriptingDialog::on_restartscript() {} +void ScriptingDialog::on_restartscript() { + on_stopscript(); + startDebugScript(_DebugingScript); +} void ScriptingDialog::on_stepinscript() { runDbgCommand(asDebugger::STEP_INTO); @@ -1019,21 +1145,44 @@ void ScriptingDialog::on_stepoverscript() { void ScriptingDialog::on_togglebreakpoint() { auto editor = currentEditor(); if (editor) { - QLineMark mrk(editor->fileName(), - editor->editor()->cursor().lineNumber() + 1, - m_symID.value(Symbols::BreakPoint)); - QLineMarksInfoCenter::instance()->toggleLineMark(mrk); + toggleBreakPoint(editor, editor->editor()->cursor().lineNumber()); } } void ScriptingDialog::on_addbreakpoint() { auto editor = currentEditor(); if (editor) { - auto line = editor->editor()->document()->line( - editor->editor()->cursor().lineNumber()); - auto id = m_symID.value(Symbols::BreakPoint); - if (!line.hasMark(id)) { - line.addMark(id); + auto curLineInd = editor->editor()->cursor().lineNumber(); + auto bpMark = m_symID.value(Symbols::BreakPoint); + +#ifdef Q_OS_WIN + if (m_consoleout->machine()->isInDebugMode() && + editor->fileName().compare(_lastCurLine.first, + Qt::CaseInsensitive) == 0 +#else + if (editor->fileName() == _lastCurLine.first +#endif + && _lastCurLine.second == curLineInd + 1) { + auto line = editor->editor()->document()->line(curLineInd); + auto hitCur = m_symID.value(Symbols::DbgRunHitBreakPoint); + auto curSym = m_symID.value(Symbols::DbgRunCurrentLine); + + auto dbg = m_consoleout->machine()->debugger(); + if (line.hasMark(curSym)) { + line.removeMark(curSym); + line.addMark(hitCur); + dbg->addFileBreakPoint(editor->fileName(), curLineInd + 1); + } else { + if (!line.hasMark(bpMark)) { + line.addMark(bpMark); + dbg->addFileBreakPoint(editor->fileName(), curLineInd + 1); + } + } + } else { + auto line = editor->editor()->document()->line(curLineInd); + if (!line.hasMark(bpMark)) { + line.addMark(bpMark); + } } } } @@ -1041,11 +1190,38 @@ void ScriptingDialog::on_addbreakpoint() { void ScriptingDialog::on_removebreakpoint() { auto editor = currentEditor(); if (editor) { - auto line = editor->editor()->document()->line( - editor->editor()->cursor().lineNumber()); - auto id = m_symID.value(Symbols::BreakPoint); - if (line.hasMark(id)) { - line.removeMark(id); + auto curLineInd = editor->editor()->cursor().lineNumber(); + auto bpMark = m_symID.value(Symbols::BreakPoint); + +#ifdef Q_OS_WIN + if (m_consoleout->machine()->isInDebugMode() && + editor->fileName().compare(_lastCurLine.first, + Qt::CaseInsensitive) == 0 +#else + if (editor->fileName() == _lastCurLine.first +#endif + && _lastCurLine.second == curLineInd + 1) { + auto line = editor->editor()->document()->line(curLineInd); + auto hitCur = m_symID.value(Symbols::DbgRunHitBreakPoint); + auto curSym = m_symID.value(Symbols::DbgRunCurrentLine); + + auto dbg = m_consoleout->machine()->debugger(); + if (line.hasMark(hitCur)) { + line.removeMark(hitCur); + line.addMark(curSym); + dbg->removeFileBreakPoint(editor->fileName(), curLineInd + 1); + } else { + if (line.hasMark(bpMark)) { + line.removeMark(bpMark); + dbg->removeFileBreakPoint(editor->fileName(), + curLineInd + 1); + } + } + } else { + auto line = editor->editor()->document()->line(curLineInd); + if (line.hasMark(bpMark)) { + line.removeMark(bpMark); + } } } } @@ -1059,7 +1235,7 @@ void ScriptingDialog::closeEvent(QCloseEvent *event) { event->ignore(); return; } - // TODO stop the script + on_stopscript(); } auto &set = SettingManager::instance(); diff --git a/src/dialog/scriptingdialog.h b/src/dialog/scriptingdialog.h index ed1dbd1..0a4e79f 100644 --- a/src/dialog/scriptingdialog.h +++ b/src/dialog/scriptingdialog.h @@ -2,6 +2,7 @@ #define SCRIPTINGDIALOG_H #include "control/scriptingconsole.h" +#include "dialog/settingdialog.h" #include "framelessmainwindow.h" #include "QWingRibbon/ribbon.h" @@ -29,8 +30,15 @@ private: REDO_ACTION, SAVE_ACTION, COPY_ACTION, - DBG_RUN, - DBG_RUN_DBG, + DBG_RUN_ACTION, + DBG_RUN_DBG_ACTION, + DBG_PAUSE_ACTION, + DBG_CONTINUE_ACTION, + DBG_STOP_ACTION, + DBG_RESTART_ACTION, + DBG_STEPINTO_ACTION, + DBG_STEPOVER_ACTION, + DBG_STEPOUT_ACTION, EDITOR_VIEWS, TOOL_VIEWS }; @@ -153,7 +161,7 @@ private: ScriptEditor *currentEditor() const; void swapEditor(ScriptEditor *old, ScriptEditor *cur); - void setRunDebugMode(bool isRun, bool isDebug = false); + void updateRunDebugMode(); ScriptEditor *findEditorView(const QString &filename); @@ -165,6 +173,12 @@ private: void runDbgCommand(asDebugger::DebugAction action); + void buildUpSettingDialog(); + + void startDebugScript(const QString &fileName); + + void toggleBreakPoint(ScriptEditor *editor, int lineIndex); + private slots: void on_newfile(); void on_openfile(); @@ -213,13 +227,13 @@ private: ScriptEditor *m_curEditor = nullptr; QList m_editStateWidgets; - QList m_dbgStateWidgets; QMap m_Tbtneditors; QMenu *m_recentMenu = nullptr; RecentFileManager *m_recentmanager = nullptr; Ribbon *m_ribbon = nullptr; + SettingDialog *m_setdialog = nullptr; size_t m_newIndex = 1; QPair _lastCurLine = {QString(), -1}; @@ -236,6 +250,8 @@ private: DbgVarShowModel *m_watch = nullptr; DbgCallStackModel *m_callstack = nullptr; + QString _DebugingScript; + QStatusBar *m_status = nullptr; }; diff --git a/src/qcodeeditwidget/qeditconfig.cpp b/src/qcodeeditwidget/qeditconfig.cpp index 6625b70..afaf309 100644 --- a/src/qcodeeditwidget/qeditconfig.cpp +++ b/src/qcodeeditwidget/qeditconfig.cpp @@ -26,6 +26,7 @@ #include "qdocument_p.h" #include "qeditor.h" #include "ui_qeditconfig.h" +#include "utilities.h" #include @@ -39,108 +40,14 @@ */ QEditConfig::QEditConfig(QWidget *w) - : QWidget(w), ui(new Ui::QEditConfig()), m_direct(false) { + : WingHex::SettingPage(w), ui(new Ui::QEditConfig()) { ui->setupUi(this); - restore(); + reset(); } QEditConfig::~QEditConfig() { delete ui; } -/*! - \brief run-time translation entry point -*/ -void QEditConfig::retranslate() { ui->retranslateUi(this); } - -/*! - \brief -*/ -bool QEditConfig::hasUnsavedChanges() const { - if (m_direct) - return false; - - QFont font = ui->cbFont->currentFont(); - // font.setPointSize(spnFontSize->value()); - - const QFont &docFont = QDocument::font(); - - if (font.family() != docFont.family() || - ui->spnFontSize->value() != docFont.pointSize()) { - // qDebug("font!"); - return true; - } - - if (ui->spnTabWidth->value() != QDocument::tabStop()) { - // qDebug("tab stop!"); - return true; - } - - QDocument::LineEnding le = QDocument::defaultLineEnding(); - - if (ui->chkDetectLE->isChecked()) { - if (le != QDocument::Conservative) { - // qDebug("conservative line endings! : %i", le); - return true; - } - } else { - if (le != - QDocument::LineEnding(ui->cbLineEndings->currentIndex() + 1)) { - // qDebug("line endings!"); - return true; - } - } - - QDocument::WhiteSpaceMode ws = QDocument::ShowNone; - - if (ui->chkShowLeadingWhitespace->isChecked()) - ws |= QDocument::ShowLeading; - - if (ui->chkShowTrailingWhitespace->isChecked()) - ws |= QDocument::ShowTrailing; - - if (ui->chkShowTabsInText->isChecked()) - ws |= QDocument::ShowTabs; - - if (ws != QDocument::showSpaces()) { - // qDebug("spaces!"); - return true; - } - - int flags = QEditor::defaultFlags(); - - if (ui->chkReplaceTabs->isChecked()) - flags |= QEditor::ReplaceTabs; - else - flags &= ~QEditor::ReplaceTabs; - - if (ui->chkAutoRemoveTrailingWhitespace->isChecked()) - flags |= QEditor::RemoveTrailing; - else - flags &= ~QEditor::RemoveTrailing; - - if (ui->chkPreserveTrailingIndent->isChecked()) - flags |= QEditor::PreserveTrailingIndent; - else - flags &= ~QEditor::PreserveTrailingIndent; - - if (flags != QEditor::defaultFlags()) { - // qDebug("flags!"); - return true; - } - - return false; -} - -/*! - \return whether user changes are immediately applied -*/ -bool QEditConfig::applyImmediately() const { return m_direct; } - -/*! - \brief Set whether user changes are immediately applied -*/ -void QEditConfig::setApplyImmediately(bool y) { m_direct = y; } - /*! \brief Apply changes */ @@ -199,11 +106,6 @@ void QEditConfig::apply() { */ void QEditConfig::cancel() { // reload the current config - - bool oldDir = m_direct; - - m_direct = false; - ui->cbFont->setFont(QDocument::font()); ui->spnFontSize->setValue(QDocument::font().pointSize()); @@ -224,10 +126,6 @@ void QEditConfig::cancel() { QEditor::RemoveTrailing); ui->chkPreserveTrailingIndent->setChecked(flags & QEditor::PreserveTrailingIndent); - - auto c = QEditor::defaultCodecName(); - - m_direct = oldDir; } /*! @@ -235,13 +133,9 @@ void QEditConfig::cancel() { \note The widgets are changed but these changes are NOT applied. */ -void QEditConfig::restore() { +void QEditConfig::reset() { // restore default configuration - bool oldDir = m_direct; - - m_direct = false; - QFont font("Monospace", 10); font.setStyleHint(QFont::Courier); @@ -260,8 +154,6 @@ void QEditConfig::restore() { ui->chkReplaceTabs->setChecked(false); ui->chkAutoRemoveTrailingWhitespace->setChecked(false); ui->chkPreserveTrailingIndent->setChecked(true); - - m_direct = oldDir; } /*! @@ -296,6 +188,12 @@ QMap QEditConfig::dumpKeys() const { return m; } +QIcon QEditConfig::categoryIcon() const { return ICONRES("file"); } + +QString QEditConfig::name() const { return tr("Edit"); } + +bool QEditConfig::isInPluginPage() const { return false; } + /*! \brief Fills the widget subcontrols from a settings map @@ -314,40 +212,31 @@ void QEditConfig::loadKeys(const QMap &keys) { ui->cbFont->setCurrentFont(f); ui->spnFontSize->setValue(f.pointSize()); - if (m_direct) - QDocument::setFont(f); + QDocument::setFont(f); ui->lblSampleText->setFont(f); } else if (it.key() == "tab_width") { ui->spnTabWidth->setValue(it->toInt()); - - if (m_direct) - on_spnTabWidth_valueChanged(it->toInt()); + on_spnTabWidth_valueChanged(it->toInt()); } else if (it.key() == "replace_tabs") { ui->chkReplaceTabs->setChecked(it->toBool()); - if (m_direct) - on_chkReplaceTabs_toggled(it->toBool()); + on_chkReplaceTabs_toggled(it->toBool()); } else if (it.key() == "remove_trailing") { ui->chkAutoRemoveTrailingWhitespace->setChecked(it->toBool()); - if (m_direct) - on_chkAutoRemoveTrailingWhitespace_toggled(it->toBool()); + on_chkAutoRemoveTrailingWhitespace_toggled(it->toBool()); } else if (it.key() == "preserve_trailing_indent") { ui->chkPreserveTrailingIndent->setChecked(it->toBool()); - if (m_direct) - on_chkPreserveTrailingIndent_toggled(it->toBool()); + on_chkPreserveTrailingIndent_toggled(it->toBool()); } else if (it.key() == "show_tabs_in_text") { ui->chkShowTabsInText->setChecked(it->toBool()); - if (m_direct) - on_chkShowTabsInText_toggled(it->toBool()); + on_chkShowTabsInText_toggled(it->toBool()); } else if (it.key() == "show_leading_whitespace") { ui->chkShowLeadingWhitespace->setChecked(it->toBool()); - if (m_direct) - on_chkShowLeadingWhitespace_toggled(it->toBool()); + on_chkShowLeadingWhitespace_toggled(it->toBool()); } else if (it.key() == "show_trailing_whitespace") { ui->chkShowTrailingWhitespace->setChecked(it->toBool()); - if (m_direct) - on_chkShowTrailingWhitespace_toggled(it->toBool()); + on_chkShowTrailingWhitespace_toggled(it->toBool()); } else if (it.key() == "line_endings") { int le = it->toInt(); @@ -379,10 +268,8 @@ void QEditConfig::on_spnFontSize_valueChanged(int size) { ui->lblSampleText->setFont(font); - if (m_direct) { - QDocument::setFont(font); - emit keyChanged("font", font); - } + QDocument::setFont(font); + emit keyChanged("font", font); } /*! @@ -392,90 +279,76 @@ void QEditConfig::on_cbFont_currentFontChanged(QFont font) { font.setPointSize(ui->spnFontSize->value()); ui->lblSampleText->setFont(font); - if (m_direct) { - QDocument::setFont(font); - emit keyChanged("font", font); - } + QDocument::setFont(font); + emit keyChanged("font", font); } /*! \brief Slot used to apply tab width settings */ void QEditConfig::on_spnTabWidth_valueChanged(int n) { - if (m_direct) { - QDocument::setTabStop(n); - emit keyChanged("tab_width", n); - } + + QDocument::setTabStop(n); + emit keyChanged("tab_width", n); } /*! \brief Slot used to apply tabs replacement settings */ void QEditConfig::on_chkReplaceTabs_toggled(bool y) { - if (m_direct) { - // FIXME - foreach (QEditor *e, QEditor::m_editors) { - e->setFlag(QEditor::ReplaceTabs, y); - } - emit keyChanged("replace_tabs", y); + // FIXME + foreach (QEditor *e, QEditor::m_editors) { + e->setFlag(QEditor::ReplaceTabs, y); } + emit keyChanged("replace_tabs", y); } /*! \brief Slot used to apply tabs display settings */ void QEditConfig::on_chkShowTabsInText_toggled(bool y) { - if (m_direct) { - if (y) - QDocument::setShowSpaces(QDocument::showSpaces() | - QDocument::ShowTabs); - else - QDocument::setShowSpaces(QDocument::showSpaces() & - ~QDocument::ShowTabs); + if (y) + QDocument::setShowSpaces(QDocument::showSpaces() | QDocument::ShowTabs); + else + QDocument::setShowSpaces(QDocument::showSpaces() & + ~QDocument::ShowTabs); - emit keyChanged("show_tabs_in_text", y); - } + emit keyChanged("show_tabs_in_text", y); } /*! \brief Slot used to apply trailing whitespace display settings */ void QEditConfig::on_chkShowLeadingWhitespace_toggled(bool y) { - if (m_direct) { - if (y) - QDocument::setShowSpaces(QDocument::showSpaces() | - QDocument::ShowLeading); - else - QDocument::setShowSpaces(QDocument::showSpaces() & - ~QDocument::ShowLeading); + if (y) + QDocument::setShowSpaces(QDocument::showSpaces() | + QDocument::ShowLeading); + else + QDocument::setShowSpaces(QDocument::showSpaces() & + ~QDocument::ShowLeading); - emit keyChanged("show_leading_whitespace", y); - } + emit keyChanged("show_leading_whitespace", y); } /*! \brief Slot used to apply leading whitespace display settings */ void QEditConfig::on_chkShowTrailingWhitespace_toggled(bool y) { - if (m_direct) { - if (y) - QDocument::setShowSpaces(QDocument::showSpaces() | - QDocument::ShowTrailing); - else - QDocument::setShowSpaces(QDocument::showSpaces() & - ~QDocument::ShowTrailing); + if (y) + QDocument::setShowSpaces(QDocument::showSpaces() | + QDocument::ShowTrailing); + else + QDocument::setShowSpaces(QDocument::showSpaces() & + ~QDocument::ShowTrailing); - emit keyChanged("show_trailing_whitespace", y); - } + emit keyChanged("show_trailing_whitespace", y); } void QEditConfig::on_cbLineEndings_currentIndexChanged(int idx) { QDocument::LineEnding le = QDocument::LineEnding(idx + 1); - if (m_direct) { - QDocument::setDefaultLineEnding(le); - emit keyChanged("line_endings", (int)le); - } + QDocument::setDefaultLineEnding(le); + emit keyChanged("line_endings", (int)le); } /*! @@ -488,36 +361,30 @@ void QEditConfig::on_chkDetectLE_toggled(bool y) { le = QDocument::LineEnding(ui->cbLineEndings->currentIndex() + 1); } - if (m_direct) { - QDocument::setDefaultLineEnding(le); - emit keyChanged("line_endings", (int)le); - } + QDocument::setDefaultLineEnding(le); + emit keyChanged("line_endings", (int)le); } /*! \brief Slot used to apply trailing space removal settings */ void QEditConfig::on_chkAutoRemoveTrailingWhitespace_toggled(bool y) { - if (m_direct) { - // FIXME - foreach (QEditor *e, QEditor::m_editors) { - e->setFlag(QEditor::RemoveTrailing, y); - } - emit keyChanged("remove_trailing", y); + // FIXME + foreach (QEditor *e, QEditor::m_editors) { + e->setFlag(QEditor::RemoveTrailing, y); } + emit keyChanged("remove_trailing", y); } /*! \brief Slot used to indent preservation settings */ void QEditConfig::on_chkPreserveTrailingIndent_toggled(bool y) { - if (m_direct) { - // FIXME - foreach (QEditor *e, QEditor::m_editors) { - e->setFlag(QEditor::PreserveTrailingIndent, y); - } - emit keyChanged("preserve_trailing_indent", y); + // FIXME + foreach (QEditor *e, QEditor::m_editors) { + e->setFlag(QEditor::PreserveTrailingIndent, y); } + emit keyChanged("preserve_trailing_indent", y); } /*! @} */ diff --git a/src/qcodeeditwidget/qeditconfig.h b/src/qcodeeditwidget/qeditconfig.h index 7f6bbac..2064090 100644 --- a/src/qcodeeditwidget/qeditconfig.h +++ b/src/qcodeeditwidget/qeditconfig.h @@ -1,36 +1,34 @@ #ifndef QEDITCONFIG_H #define QEDITCONFIG_H +#include "plugin/settingpage.h" #include namespace Ui { class QEditConfig; } -class QEditConfig : public QWidget { +class QEditConfig : public WingHex::SettingPage { Q_OBJECT public: explicit QEditConfig(QWidget *parent = nullptr); virtual ~QEditConfig(); - bool hasUnsavedChanges() const; - - bool applyImmediately() const; - QMap dumpKeys() const; +public: + virtual QIcon categoryIcon() const override; + virtual QString name() const override; + virtual bool isInPluginPage() const override; + + virtual void apply() override; + virtual void cancel() override; + virtual void reset() override; + public slots: - void retranslate(); - - void apply(); - void cancel(); - void restore(); - void loadKeys(const QMap &keys); - void setApplyImmediately(bool y); - signals: void keyChanged(const QString &key, const QVariant &value); @@ -53,8 +51,6 @@ private slots: private: Ui::QEditConfig *ui; - - bool m_direct; }; #endif // QEDITCONFIG_H diff --git a/src/qcodeeditwidget/qformatconfig.cpp b/src/qcodeeditwidget/qformatconfig.cpp index 5381fc8..39f640d 100644 --- a/src/qcodeeditwidget/qformatconfig.cpp +++ b/src/qcodeeditwidget/qformatconfig.cpp @@ -37,6 +37,7 @@ #include #include "class/wingmessagebox.h" +#include "utilities.h" /*! \ingroup dialogs @@ -48,7 +49,7 @@ */ QFormatConfig::QFormatConfig(QWidget *w) - : QWidget(w), ui(new Ui::QFormatConfig()), m_autonomous(false), + : WingHex::SettingPage(w), ui(new Ui::QFormatConfig()), m_autonomous(false), m_currentScheme(0) { ui->setupUi(this); @@ -72,11 +73,6 @@ QFormatConfig::QFormatConfig(QWidget *w) QFormatConfig::~QFormatConfig() { delete ui; } -/*! - \brief run-time translation entry point -*/ -void QFormatConfig::retranslate() { ui->retranslateUi(this); } - /*! \return Whether the format config widget is in "autonomous" mode */ @@ -103,6 +99,12 @@ bool QFormatConfig::hasUnsavedChanges() const { */ QList QFormatConfig::schemes() const { return m_schemes; } +QIcon QFormatConfig::categoryIcon() const { return ICONRES(""); } + +QString QFormatConfig::name() const { return tr("Format"); } + +bool QFormatConfig::isInPluginPage() const { return false; } + /*! \brief Add a format scheme to the config widget @@ -325,7 +327,7 @@ void QFormatConfig::cancel() { \note The widgets are changed but these changes are NOT applied. */ -void QFormatConfig::restore() { +void QFormatConfig::reset() { // restoring what? this is only provided for API consistency and in case // (very unlikely to ever happen) design changes make restore() a sensible // thing to do on format schemes diff --git a/src/qcodeeditwidget/qformatconfig.h b/src/qcodeeditwidget/qformatconfig.h index 1685ff8..178eb2b 100644 --- a/src/qcodeeditwidget/qformatconfig.h +++ b/src/qcodeeditwidget/qformatconfig.h @@ -1,6 +1,7 @@ #ifndef QFORMATCONFIG_H #define QFORMATCONFIG_H +#include "plugin/settingpage.h" #include namespace Ui { @@ -9,7 +10,7 @@ class QFormatConfig; class QFormatScheme; -class QFormatConfig : public QWidget { +class QFormatConfig : public WingHex::SettingPage { Q_OBJECT public: @@ -22,13 +23,15 @@ public: QList schemes() const; +public: + virtual QIcon categoryIcon() const override; + virtual QString name() const override; + virtual bool isInPluginPage() const override; + virtual void apply() override; + virtual void cancel() override; + virtual void reset() override; + public slots: - void retranslate(); - - void apply(); - void cancel(); - void restore(); - void setAutonomous(bool y); void addScheme(const QString &name, QFormatScheme *scheme); @@ -37,7 +40,7 @@ public slots: void setCurrentScheme(QFormatScheme *scheme); protected: - virtual void hideEvent(QHideEvent *e); + virtual void hideEvent(QHideEvent *e) override; private slots: void on_m_selector_currentIndexChanged(int idx); diff --git a/src/qcodeeditwidget/qstatuspanel.cpp b/src/qcodeeditwidget/qstatuspanel.cpp deleted file mode 100644 index feb8c8f..0000000 --- a/src/qcodeeditwidget/qstatuspanel.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2006-2009 fullmetalcoder -** -** This file is part of the Edyuk project -** -** This file may be used under the terms of the GNU General Public License -** version 3 as published by the Free Software Foundation and appearing in the -** file GPL.txt included in the packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include "qstatuspanel.h" - -/*! - \file qstatuspanel.cpp - \brief Implementation of the QStatusPanel class. - - \see QStatusPanel -*/ - -#include "qeditor.h" - -#include "qdocument.h" -#include "qdocumentcursor.h" -#include "qdocumentline.h" - -#include -#include -#include -#include -#include -#include - -/*! - \ingroup widgets - @{ -*/ - -/*! - \class QStatusPanel - \brief A panel that display some status informations -*/ - -QCE_AUTO_REGISTER(QStatusPanel) - -/*! - \brief Constructor -*/ -QStatusPanel::QStatusPanel(QWidget *p) : QPanel(p) { - setFixedHeight(fontMetrics().lineSpacing() + 4); -} - -/*! - \brief Empty destructor -*/ -QStatusPanel::~QStatusPanel() {} - -/*! - -*/ -QString QStatusPanel::type() const { return "Status"; } - -/*! - -*/ -void QStatusPanel::editorChange(QEditor *e) { - if (editor()) { - disconnect(editor(), SIGNAL(cursorPositionChanged()), this, - SLOT(update())); - } - - if (e) { - connect(e, SIGNAL(cursorPositionChanged()), this, SLOT(update())); - } -} - -/*! - -*/ -bool QStatusPanel::paint(QPainter *p, QEditor *e) { - // qDebug("drawing status panel... [%i, %i, %i, %i]", - // geometry().x(), - // geometry().y(), - // geometry().width(), - // geometry().height()); - static QPixmap _warn(":/warning.png"), _mod(":/save.png"); - - QString s; - int xpos = 10; - QDocumentCursor c = e->cursor(); - const QFontMetrics fm(fontMetrics()); - - const int ls = fm.lineSpacing(); - const int ascent = fm.ascent() + 3; - - s = tr("Line : %1 Visual column : %2 Text column : %3") - .arg(c.lineNumber() + 1) - .arg(c.visualColumnNumber()) - .arg(c.columnNumber()); - - p->drawText(xpos, ascent, s); - xpos += fm.horizontalAdvance(s) + 10; - - int sz = qMin(height(), _mod.height()); - // int lastMod = d->lastModified().secsTo(QDateTime::currentDateTime()); - // QString timeDiff = tr("(%1 min %2 s ago)").arg(lastMod / 60).arg(lastMod - // % 60); - - // xpos += 10; - if (e->isContentModified()) { - p->drawPixmap(xpos, (height() - sz) / 2, sz, sz, _mod); - // xpos += sz; - // xpos += 10; - // p->drawText(xpos, ascent, timeDiff); - } - xpos += sz + 10; - // xpos += fm.width(timeDiff); - // xpos += 20; - - s = editor()->flag(QEditor::Overwrite) ? tr("OVERWRITE") : tr("INSERT"); - p->drawText(xpos, ascent, s); - xpos += fm.horizontalAdvance(s) + 10; - - m_conflictSpot = 0; - - if (editor()->isInConflict()) { - s = tr("Conflict"); - int w = fm.horizontalAdvance(s) + 30; - - if (xpos + w + _warn.width() < width()) { - m_conflictSpot = width() - (w + _warn.width()); - p->drawText(width() - w + 15, ascent, s); - p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn); - } else if (xpos + _warn.width() < width()) { - m_conflictSpot = width() - _warn.width(); - p->drawPixmap(m_conflictSpot, (ls - _warn.height()) / 2 + 2, _warn); - } - } - - setFixedHeight(ls + 4); - - QTimer::singleShot(1000, this, SLOT(update())); - - return true; -} - -/*! - -*/ -void QStatusPanel::mousePressEvent(QMouseEvent *e) { - if (!editor() || (e->button() != Qt::LeftButton) || !m_conflictSpot || -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - e->position().x() < m_conflictSpot) { -#else - e->x() < m_conflictSpot) { -#endif - editor()->setFocus(); - return; - } - - editor()->save(); -} - -/*! - -*/ -void QStatusPanel::mouseReleaseEvent(QMouseEvent *e) { - Q_UNUSED(e) - - editor()->setFocus(); -} - -/*! @} */ diff --git a/src/qcodeeditwidget/qstatuspanel.h b/src/qcodeeditwidget/qstatuspanel.h deleted file mode 100644 index b9e5d18..0000000 --- a/src/qcodeeditwidget/qstatuspanel.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2006-2009 fullmetalcoder -** -** This file is part of the Edyuk project -** -** This file may be used under the terms of the GNU General Public License -** version 3 as published by the Free Software Foundation and appearing in the -** file GPL.txt included in the packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#ifndef _QSTATUS_PANEL_H_ -#define _QSTATUS_PANEL_H_ - -#include "qpanel.h" - -/*! - \file qstatuspanel.h - \brief Definition of the QStatusPanel class. - - \see QStatusPanel -*/ - -class QLabel; - -class QDocumentLine; - -class QCE_EXPORT QStatusPanel : public QPanel { - Q_OBJECT - -public: - Q_PANEL(QStatusPanel, "Status Panel") - - QStatusPanel(QWidget *p = nullptr); - virtual ~QStatusPanel(); - - virtual QString type() const; - -protected: - virtual void editorChange(QEditor *e); - virtual bool paint(QPainter *p, QEditor *e); - - virtual void mousePressEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); - -private: - int m_conflictSpot; -}; - -#endif // _QSTATUS_PANEL_H_ diff --git a/src/settings/generalsettingdialog.h b/src/settings/generalsettingdialog.h index 911a95f..f2f801c 100644 --- a/src/settings/generalsettingdialog.h +++ b/src/settings/generalsettingdialog.h @@ -1,7 +1,7 @@ #ifndef GENERALSETTINGDIALOG_H #define GENERALSETTINGDIALOG_H -#include "../plugin/settingpage.h" +#include "plugin/settingpage.h" #include namespace Ui {