File indexing completed on 2024-05-12 04:38:24
0001 /* 0002 SPDX-FileCopyrightText: David Nolden <david.nolden.kdevelop@art-master.de> 0003 SPDX-FileCopyrightText: 2010 Milian Wolff <mail@milianw.de> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "workingsetwidget.h" 0009 #include "debug_workingset.h" 0010 0011 #include <sublime/area.h> 0012 0013 #include "workingsetcontroller.h" 0014 #include "workingset.h" 0015 #include "workingsettoolbutton.h" 0016 0017 #include <core.h> 0018 0019 using namespace KDevelop; 0020 0021 WorkingSet* getSet(const QString& id) 0022 { 0023 if (id.isEmpty()) { 0024 return nullptr; 0025 } 0026 0027 return Core::self()->workingSetControllerInternal()->workingSet(id); 0028 } 0029 0030 WorkingSetWidget::WorkingSetWidget(Sublime::Area* area, QWidget* parent) 0031 : WorkingSetToolButton(parent, nullptr) 0032 , m_area(area) 0033 { 0034 //Queued connect so the change is already applied to the area when we start processing 0035 connect(m_area.data(), &Sublime::Area::changingWorkingSet, this, 0036 &WorkingSetWidget::changingWorkingSet, Qt::QueuedConnection); 0037 0038 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored)); 0039 0040 changingWorkingSet(m_area, nullptr, QString(), area->workingSet()); 0041 } 0042 0043 void WorkingSetWidget::setVisible( bool visible ) 0044 { 0045 // never show empty working sets 0046 // TODO: I overloaded this only because hide() in the ctor does not work, other ideas? 0047 // It's not that it doesn't work from the constructor, it's that the value changes when the button is added on a layout. 0048 QWidget::setVisible( visible && (workingSet() && !workingSet()->isEmpty()) ); 0049 } 0050 0051 void WorkingSetWidget::changingWorkingSet(Sublime::Area* area, Sublime::Area* /*oldArea*/, const QString& /*from*/, const QString& newSet) 0052 { 0053 qCDebug(WORKINGSET) << "re-creating widget" << m_area; 0054 0055 Q_ASSERT(area == m_area); 0056 Q_UNUSED(area); 0057 0058 if (workingSet()) { 0059 disconnect(workingSet(), &WorkingSet::setChangedSignificantly, 0060 this, &WorkingSetWidget::setChangedSignificantly); 0061 } 0062 0063 WorkingSet* set = getSet(newSet); 0064 setWorkingSet(set); 0065 0066 if (set) { 0067 connect(set, &WorkingSet::setChangedSignificantly, 0068 this, &WorkingSetWidget::setChangedSignificantly); 0069 } 0070 setVisible(set && !set->isEmpty()); 0071 } 0072 0073 void WorkingSetWidget::setChangedSignificantly() 0074 { 0075 setVisible(!workingSet()->isEmpty()); 0076 } 0077 0078 #include "moc_workingsetwidget.cpp"