diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -24,6 +24,7 @@ #include #include #include +#include struct LateralArea { // Area with the the lateral buttons that will open the views. @@ -54,13 +55,15 @@ QString m_theme; KTextEditor::View *m_currEditorView; LateralArea m_lateral; + GCodeEditorWidget* m_gcodeEditor; QTabWidget *m_instances; void setupLateralArea(); void newAtCoreInstance(); void initWidgets(); void setupActions(); void openFile(); bool askToClose(); + void updateClientFactory(KTextEditor::View* view); void atCoreInstanceNameChange(const QString &name); QString getTheme(); void toggleGCodeActions(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include @@ -77,6 +76,7 @@ event->ignore(); } } + disconnect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); } void MainWindow::initWidgets() @@ -183,16 +183,10 @@ }); }; - auto *gcodeEditor = new GCodeEditorWidget(this); - connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [this](KTextEditor::View* view){ - if(m_lateral.m_stack->currentWidget() == m_lateral.m_map["gcode"].second) { - guiFactory()->removeClient(m_currEditorView); - guiFactory()->addClient(view); - } - m_currEditorView = view; - }); + m_gcodeEditor = new GCodeEditorWidget(this); + connect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); setupButton("3d", i18n("&3D"), QIcon::fromTheme("draw-cuboid", QIcon(QString(":/%1/3d").arg(m_theme))), new Viewer3D(this)); - setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/edit")), gcodeEditor); + setupButton("gcode", i18n("&GCode"), QIcon::fromTheme("accessories-text-editor", QIcon(":/icon/edit")), m_gcodeEditor); setupButton("video", i18n("&Video"), QIcon::fromTheme("camera-web", QIcon(":/icon/video")), new VideoMonitorWidget(this)); buttonLayout->addStretch(); m_lateral.m_toolBar->setLayout(buttonLayout); @@ -295,3 +289,16 @@ guiFactory()->removeClient(m_currEditorView); } } + +void MainWindow::updateClientFactory(KTextEditor::View* view) +{ + if(m_lateral.m_stack->currentWidget() == m_lateral.m_map["gcode"].second) { + if(m_currEditorView) { + guiFactory()->removeClient(m_currEditorView); + } + if (view) { + guiFactory()->addClient(view); + } + } + m_currEditorView = view; +}