diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 6fe30acd2..bc557f1bd 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -9,133 +9,22 @@ find_package(Qt5Network) set(CMAKE_CXX_STANDARD 17) -set(CXX_H - common.h - inotify/private/inotify_hook.h - inotify/private/inotify_impl.h - inotify/private/inotify_linux.h - inotify/private/inotify_p.h - inotify/inotify.h - lsp/client/private/client_p.h - lsp/client/client.h - lsp/client/stdoutjsonrpcparser.h - lsp/server/servercmdparse.h - lsp/server/serverapplication.h - lsp/server/stdinreadloop.h - lsp/server/stdinjsonrpcparser.h - lsp/server/route.h - lsp/protocol/newprotocol.h - lsp/protocol/protocol.h - lsp/protocol/new/jsonrpcparser.h - lsp/protocol/new/basicjsonstructures.h - lsp/protocol/new/lifecyclemessage.h - lsp/protocol/new/documentsynchronization.h - lsp/protocol/new/languagefeatures.h - lsp/protocol/new/extendedproject.h - lsp/lsp.h - util/processutil.h - util/customicons.h - util/custompaths.h - util/eventdefinitions.h - util/singleton.h - util/polkit.h - util/shortcututil.h - util/fileoperation.h - util/qtcassert.h - util/downloadutil.h - util/environment.h - util/commandparser.h - util/themeparser.h - util/fileutils.h - util/fuzzymatcher.h - supportfile/editorstyle.h - supportfile/language.h - supportfile/windowstyle.h - supportfile/dapconfig.h - dialog/commondialog.h - dialog/propertiesdialog.h - dialog/pip3dialog.h - dialog/processdialog.h - dialog/wgetdialog.h - widget/configurewidget.h - widget/collapsewidget.h - widget/detailsbutton.h - widget/statuswidget.h - widget/singlechoicebox.h - widget/elidedlabel.h - widget/generator.h - widget/pagewidget.h - widget/outputpane.h - type/constants.h - type/menuext.h - type/task.h - toolchain/toolchain.h - actionmanager/actionmanager.h - actionmanager/command.h - unilog.h - project/projectinfo.h - ) - -set(CXX_CPP - inotify/inotify.cpp - lsp/protocol/newprotocol.cpp - lsp/protocol/protocol.cpp - lsp/client/client.cpp - lsp/client/stdoutjsonrpcparser.cpp - lsp/server/servercmdparse.cpp - lsp/server/serverapplication.cpp - lsp/server/stdinreadloop.cpp - lsp/server/stdinjsonrpcparser.cpp - lsp/server/route.cpp - lsp/protocol/new/jsonrpcparser.cpp - lsp/protocol/new/basicjsonstructures.cpp - lsp/protocol/new/lifecyclemessage.cpp - lsp/protocol/new/documentsynchronization.cpp - lsp/protocol/new/languagefeatures.cpp - lsp/protocol/new/extendedproject.cpp - util/processutil.cpp - util/customicons.cpp - util/custompaths.cpp - util/polkit.cpp - util/eventdefinitions.cpp - util/shortcututil.cpp - util/fileoperation.cpp - util/downloadutil.cpp - util/environment.cpp - util/commandparser.cpp - util/themeparser.cpp - util/fileutils.cpp - util/fuzzymatcher.cpp - supportfile/language.cpp - supportfile/editorstyle.cpp - supportfile/windowstyle.cpp - supportfile/dapconfig.cpp - dialog/commondialog.cpp - dialog/propertiesdialog.cpp - dialog/pip3dialog.cpp - dialog/processdialog.cpp - dialog/wgetdialog.cpp - widget/configurewidget.cpp - widget/collapsewidget.cpp - widget/detailsbutton.cpp - widget/statuswidget.cpp - widget/elidedlabel.cpp - widget/singlechoicebox.cpp - widget/generator.cpp - widget/pagewidget.cpp - widget/outputpane.cpp - toolchain/toolchain.cpp - type/constants.cpp - type/task.cpp - actionmanager/actionmanager.cpp - actionmanager/command.cpp +FILE(GLOB COMMON_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*/*/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*/*/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*.json" ) add_library( ${PROJECT_NAME} SHARED - ${CXX_H} - ${CXX_CPP} + ${COMMON_FILES} resource/common.qrc ) diff --git a/src/plugins/debugger/interface/messagebox.cpp b/src/common/widget/messagebox.cpp similarity index 100% rename from src/plugins/debugger/interface/messagebox.cpp rename to src/common/widget/messagebox.cpp diff --git a/src/plugins/debugger/interface/messagebox.h b/src/common/widget/messagebox.h similarity index 100% rename from src/plugins/debugger/interface/messagebox.h rename to src/common/widget/messagebox.h diff --git a/src/plugins/debugger/CMakeLists.txt b/src/plugins/debugger/CMakeLists.txt index 7b080cef3..b560a6dba 100644 --- a/src/plugins/debugger/CMakeLists.txt +++ b/src/plugins/debugger/CMakeLists.txt @@ -5,64 +5,17 @@ project(debugger) set(CPPDAP_DIR ${CMAKE_SOURCE_DIR}/3rdparty/cppdap) include_directories(${CPPDAP_DIR}/include) -set(CXX_CPP - debugger.json - debuggerplugin.cpp - debuggerrunparameters.cpp - dap/dapdebugger.cpp - dap/debugsession.cpp - event/eventreceiver.cpp - debugmanager.cpp - dap/rawdebugsession.cpp - runtimecfgprovider.cpp - dap/debugservice.cpp - dap/debugmodel.cpp - interface/stackframemodel.cpp - stackframe.cpp - interface/localtreeitem.cpp - interface/localtreemodel.cpp - interface/stackframeview.cpp - interface/breakpointitem.cpp - breakpoint.cpp - interface/breakpointmodel.cpp - interface/messagebox.cpp - interface/menumanager.cpp - runner/runner.cpp - ) - -set(CXX_H - debuggerplugin.h - debuggerrunparameters.h - dap/dapdebugger.h - dap/debugsession.h - debuggerglobals.h - debuggersignals.h - event/eventreceiver.h - debugmanager.h - dap/rawdebugsession.h - dap/objects.hpp - runtimecfgprovider.h - debug.h - dap/debugservice.h - dap/debugmodel.h - interface/stackframemodel.h - stackframe.h - interface/localtreeitem.h - interface/localtreemodel.h - interface/variable.h - interface/stackframeview.h - interface/breakpointitem.h - breakpoint.h - interface/breakpointmodel.h - interface/messagebox.h - interface/menumanager.h - runner/runner.h +FILE(GLOB DEBUGGER_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*.h" + "${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/*.json" ) add_library(${PROJECT_NAME} SHARED - ${CXX_H} - ${CXX_CPP} + ${DEBUGGER_FILES} resource.qrc ) diff --git a/src/plugins/debugger/dap/dapdebugger.cpp b/src/plugins/debugger/dap/dapdebugger.cpp index 1ebbd69fc..d6004b2e8 100644 --- a/src/plugins/debugger/dap/dapdebugger.cpp +++ b/src/plugins/debugger/dap/dapdebugger.cpp @@ -13,7 +13,7 @@ #include "interface/appoutputpane.h" #include "interface/stackframemodel.h" #include "interface/stackframeview.h" -#include "interface/messagebox.h" +#include "common/widget/messagebox.h" #include "interface/breakpointmodel.h" #include "event/eventreceiver.h" #include "common/common.h" diff --git a/src/plugins/debugger/interface/appoutputpane.cpp b/src/plugins/debugger/interface/appoutputpane.cpp index 48852f5aa..41873bc8b 100644 --- a/src/plugins/debugger/interface/appoutputpane.cpp +++ b/src/plugins/debugger/interface/appoutputpane.cpp @@ -3,184 +3,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "appoutputpane.h" -#include "common/type/constants.h" -#include -#include -#include - -class OutputWindowPrivate -{ -public: - explicit OutputWindowPrivate(QTextDocument *document) - : cursor(document) - { - } - - ~OutputWindowPrivate() - { - } - - QTextCursor cursor; - QMenu *menu = nullptr; - int maxCharCount = default_max_char_count(); - bool enforceNewline = false; - bool scrollToBottom = true; -}; AppOutputPane::AppOutputPane() - : d(new OutputWindowPrivate(document())) { - setReadOnly(true); } AppOutputPane::~AppOutputPane() { - if (d) { - delete d; - d = nullptr; - } -} - -void AppOutputPane::clearContents() -{ - clear(); -} - -QString normalizeNewlines(const QString &text) -{ - QString res = text; - res.replace(QLatin1String("\r\n"), QLatin1String("\n")); - return res; -} - -bool AppOutputPane::isScrollbarAtBottom() const -{ - return verticalScrollBar()->value() == verticalScrollBar()->maximum(); -} - -QString AppOutputPane::doNewlineEnforcement(const QString &out) -{ - d->scrollToBottom = true; - QString s = out; - if (d->enforceNewline) { - s.prepend(QLatin1Char('\n')); - d->enforceNewline = false; - } - - if (s.endsWith(QLatin1Char('\n'))) { - d->enforceNewline = true; // make appendOutputInline put in a newline next time - s.chop(1); - } - - return s; -} - -void AppOutputPane::scrollToBottom() -{ - verticalScrollBar()->setValue(verticalScrollBar()->maximum()); - // QPlainTextEdit destroys the first calls value in case of multiline - // text, so make sure that the scroll bar actually gets the value set. - // Is a noop if the first call succeeded. - verticalScrollBar()->setValue(verticalScrollBar()->maximum()); -} - -void AppOutputPane::appendText(const QString &textIn, const QTextCharFormat &format) -{ - const QString text = normalizeNewlines(textIn); - if (d->maxCharCount > 0 && document()->characterCount() >= d->maxCharCount) { - qDebug() << "Maximum limit exceeded : " << d->maxCharCount; - return; - } - const bool atBottom = isScrollbarAtBottom(); - if (!d->cursor.atEnd()) - d->cursor.movePosition(QTextCursor::End); - d->cursor.beginEditBlock(); - d->cursor.insertText(doNewlineEnforcement(text), format); - - if (d->maxCharCount > 0 && document()->characterCount() >= d->maxCharCount) { - QTextCharFormat tmp; - tmp.setFontWeight(QFont::Bold); - d->cursor.insertText(doNewlineEnforcement(tr("Additional output omitted") + QLatin1Char('\n')), tmp); - } - - d->cursor.endEditBlock(); - if (atBottom) - scrollToBottom(); -} - -void AppOutputPane::appendText(const QString &text, OutputFormat format) -{ - QTextCharFormat textFormat; - switch (format) { - case OutputFormat::StdOut: - textFormat.setForeground(kTextColorNormal); - textFormat.setFontWeight(QFont::Normal); - break; - case OutputFormat::StdErr: - textFormat.setForeground(kErrorMessageTextColor); - textFormat.setFontWeight(QFont::Normal); - break; - case OutputFormat::NormalMessage: - textFormat.setForeground(kMessageOutput); - break; - case OutputFormat::ErrorMessage: - textFormat.setForeground(kErrorMessageTextColor); - textFormat.setFontWeight(QFont::Bold); - break; - default: - // nothing to do. - break; - } - - appendText(text, textFormat); -} - -void AppOutputPane::contextMenuEvent(QContextMenuEvent * event) -{ - if (nullptr == d->menu) { - d->menu = new QMenu(this); - d->menu->setParent(this); - d->menu->addActions(actionFactory()); - } - - d->menu->move(event->globalX(), event->globalY()); - d->menu->show(); -} - -QList AppOutputPane::actionFactory() -{ - QList list; - - { - auto action = new QAction(this); - action->setText(tr("Copy")); - connect(action, &QAction::triggered, [this](){ - if (!document()->toPlainText().isEmpty()) - copy(); - }); - list.append(action); - } - - { - auto action = new QAction(this); - action->setText(tr("Clear")); - connect(action, &QAction::triggered, [this](){ - if (!document()->toPlainText().isEmpty()) - clear(); - }); - list.append(action); - } - - { - auto action = new QAction(this); - action->setText(tr("Select All")); - connect(action, &QAction::triggered, [this](){ - if (!document()->toPlainText().isEmpty()) - selectAll(); - }); - list.append(action); - } - return list; } diff --git a/src/plugins/debugger/interface/appoutputpane.h b/src/plugins/debugger/interface/appoutputpane.h index 79b1db900..b9688b14f 100644 --- a/src/plugins/debugger/interface/appoutputpane.h +++ b/src/plugins/debugger/interface/appoutputpane.h @@ -6,33 +6,17 @@ #define APPOUTPUTPANE_H #include "debuggerglobals.h" +#include "common/widget/outputpane.h" #include class OutputWindowPrivate; -class AppOutputPane : public QPlainTextEdit +class AppOutputPane : public OutputPane { Q_OBJECT public: AppOutputPane(); ~AppOutputPane() override; - - void clearContents(); - - bool isScrollbarAtBottom() const; - QString doNewlineEnforcement(const QString &out); - void scrollToBottom(); - -protected: - void contextMenuEvent(QContextMenuEvent * event) override; - -public slots: - void appendText(const QString &text, OutputPane::OutputFormat format); - -private: - void appendText(const QString &text, const QTextCharFormat &format = QTextCharFormat()); - QList actionFactory(); - OutputWindowPrivate *d = nullptr; }; #endif // APPOUTPUTPANE_H