forked from qt-creator/qt-creator
CompilerExplorer: Add Toolbar button to add source
Change-Id: I0d8fb50fe1ce5305a93b524a9807997124ab119b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QToolBar>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
|
||||||
@@ -719,17 +720,13 @@ void HelperWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWidget::addNewSource()
|
|
||||||
{
|
|
||||||
auto newSource = std::make_shared<SourceSettings>(
|
|
||||||
[settings = m_document->settings()] { return settings->apiConfig(); });
|
|
||||||
m_document->settings()->m_sources.addItem(newSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *EditorWidget::createHelpWidget() const
|
QWidget *EditorWidget::createHelpWidget() const
|
||||||
{
|
{
|
||||||
auto w = new HelperWidget;
|
auto w = new HelperWidget;
|
||||||
connect(w, &HelperWidget::addSource, this, &EditorWidget::addNewSource);
|
connect(w,
|
||||||
|
&HelperWidget::addSource,
|
||||||
|
m_document->settings(),
|
||||||
|
&CompilerExplorerSettings::addNewSource);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -783,6 +780,25 @@ static bool childHasFocus(QWidget *parent)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *Editor::toolBar()
|
||||||
|
{
|
||||||
|
if (!m_toolBar) {
|
||||||
|
m_toolBar = std::make_unique<QToolBar>();
|
||||||
|
|
||||||
|
QAction *newSource = new QAction(m_toolBar.get());
|
||||||
|
newSource->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
||||||
|
newSource->setToolTip(Tr::tr("Add source"));
|
||||||
|
m_toolBar->addAction(newSource);
|
||||||
|
|
||||||
|
connect(newSource,
|
||||||
|
&QAction::triggered,
|
||||||
|
m_document->settings(),
|
||||||
|
&CompilerExplorerSettings::addNewSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_toolBar.get();
|
||||||
|
}
|
||||||
|
|
||||||
EditorFactory::EditorFactory()
|
EditorFactory::EditorFactory()
|
||||||
: m_actionHandler(Constants::CE_EDITOR_ID,
|
: m_actionHandler(Constants::CE_EDITOR_ID,
|
||||||
Constants::CE_EDITOR_ID,
|
Constants::CE_EDITOR_ID,
|
||||||
|
|||||||
@@ -214,8 +214,6 @@ protected:
|
|||||||
void setupHelpWidget();
|
void setupHelpWidget();
|
||||||
QWidget *createHelpWidget() const;
|
QWidget *createHelpWidget() const;
|
||||||
|
|
||||||
void addNewSource();
|
|
||||||
|
|
||||||
void addCompiler(const std::shared_ptr<SourceSettings> &sourceSettings,
|
void addCompiler(const std::shared_ptr<SourceSettings> &sourceSettings,
|
||||||
const std::shared_ptr<CompilerSettings> &compilerSettings,
|
const std::shared_ptr<CompilerSettings> &compilerSettings,
|
||||||
int idx,
|
int idx,
|
||||||
@@ -244,10 +242,11 @@ public:
|
|||||||
~Editor();
|
~Editor();
|
||||||
|
|
||||||
Core::IDocument *document() const override { return m_document.data(); }
|
Core::IDocument *document() const override { return m_document.data(); }
|
||||||
QWidget *toolBar() override { return nullptr; }
|
QWidget *toolBar() override;
|
||||||
|
|
||||||
QSharedPointer<JsonSettingsDocument> m_document;
|
QSharedPointer<JsonSettingsDocument> m_document;
|
||||||
QUndoStack m_undoStack;
|
QUndoStack m_undoStack;
|
||||||
|
std::unique_ptr<QToolBar> m_toolBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EditorFactory : public Core::IEditorFactory
|
class EditorFactory : public Core::IEditorFactory
|
||||||
|
|||||||
@@ -337,4 +337,10 @@ CompilerExplorerSettings::CompilerExplorerSettings()
|
|||||||
|
|
||||||
CompilerExplorerSettings::~CompilerExplorerSettings() = default;
|
CompilerExplorerSettings::~CompilerExplorerSettings() = default;
|
||||||
|
|
||||||
|
void CompilerExplorerSettings::addNewSource()
|
||||||
|
{
|
||||||
|
auto newSource = std::make_shared<SourceSettings>([this] { return apiConfig(); });
|
||||||
|
m_sources.addItem(newSource);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CompilerExplorer
|
} // namespace CompilerExplorer
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public:
|
|||||||
return Api::Config(m_networkAccessManager, compilerExplorerUrl());
|
return Api::Config(m_networkAccessManager, compilerExplorerUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addNewSource();
|
||||||
|
|
||||||
QNetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
|
QNetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user