diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -158,9 +158,17 @@ auto *gcodeEditor = new GCodeEditorWidget(this); connect(gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, [this](KTextEditor::View* view){ - guiFactory()->removeClient(m_currEditorView); - guiFactory()->addClient(view); - m_currEditorView = view; + if(m_currEditorView != view && view) { + guiFactory()->removeClient(m_currEditorView); + guiFactory()->addClient(view); + m_currEditorView = view; + } + }); + connect(gcodeEditor, &GCodeEditorWidget::fileClosed, this, [this] (const QUrl& file) { + qDebug() << "Current Open Files" <= QColor(Qt::lightGray).value() ? \ QString("dark") : QString("light"); -} \ No newline at end of file +} diff --git a/src/widgets/gcodeeditorwidget.h b/src/widgets/gcodeeditorwidget.h --- a/src/widgets/gcodeeditorwidget.h +++ b/src/widgets/gcodeeditorwidget.h @@ -1,6 +1,7 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodrigues@gmail.com + Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,4 +47,5 @@ signals: void updateClientFactory(KTextEditor::View* view); + void fileClosed(const QUrl file); }; diff --git a/src/widgets/gcodeeditorwidget.cpp b/src/widgets/gcodeeditorwidget.cpp --- a/src/widgets/gcodeeditorwidget.cpp +++ b/src/widgets/gcodeeditorwidget.cpp @@ -35,25 +35,21 @@ connect(m_tabwidget, &QTabWidget::tabCloseRequested, this, &GCodeEditorWidget::closeTab); connect(m_tabwidget, &QTabWidget::currentChanged, this, &GCodeEditorWidget::currentIndexChanged); m_tabwidget->setTabsClosable(true); - m_tabwidget->addTab(newView(newDoc()), i18n("New file")); + //m_tabwidget->addTab(newView(newDoc()), i18n("New file")); } KTextEditor::View* GCodeEditorWidget::gcodeView() const{ return qobject_cast(m_editor->documents().first()->views().first()); } void GCodeEditorWidget::loadFile(const QUrl &file) { - auto doc = m_editor->documents().first(); - if(!doc->isEmpty()){ - doc = newDoc(); - int t = m_tabwidget->addTab(newView(doc), file.fileName()); - m_tabwidget->setCurrentIndex(t); - } else { - m_tabwidget->setTabText(0, file.fileName()); - emit updateClientFactory(doc->views().first()); - } + auto doc = newDoc(); + int t = m_tabwidget->addTab(newView(doc), file.fileName()); + m_tabwidget->setCurrentIndex(t); doc->openUrl(file); doc->setHighlightingMode(QString("G-Code")); + emit updateClientFactory(doc->views().first()); + } void GCodeEditorWidget::setupInterface(const KTextEditor::View* view) @@ -77,13 +73,24 @@ void GCodeEditorWidget::closeTab(int index) { - m_tabwidget->removeTab(index); - if(!m_tabwidget->count()){ - m_tabwidget->addTab(newView(newDoc()), i18n("New file")); + auto doc = m_editor->documents().at(index); + qDebug() << "Closing Tab" << QString::number(index) << "URL:" <url(); + auto fileName = doc->url(); + if( doc->closeUrl()) { + m_tabwidget->removeTab(index); + emit fileClosed(fileName); + //delete doc; + // if(!m_tabwidget->count()){ + // m_tabwidget->addTab(newView(newDoc()), i18n("New file")); + // } } } void GCodeEditorWidget::currentIndexChanged(int index){ - if(index != -1) - emit updateClientFactory(qobject_cast(m_tabwidget->currentWidget())); + if(index != -1) { + auto view = qobject_cast(m_tabwidget->currentWidget()); + if (view) { + emit updateClientFactory(view); + } + } }