File indexing completed on 2024-04-28 04:37:28

0001 /*
0002     SPDX-FileCopyrightText: David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_WORKINGSETCONTROLLER_H
0008 #define KDEVPLATFORM_WORKINGSETCONTROLLER_H
0009 
0010 #include <QObject>
0011 #include <QSet>
0012 #include <QMap>
0013 #include <QPointer>
0014 
0015 class QPoint;
0016 class QWidget;
0017 class QTimer;
0018 
0019 namespace Sublime {
0020 class Area;
0021 class AreaIndex;
0022 class View;
0023 }
0024 
0025 namespace KDevelop {
0026 
0027 class ActiveToolTip;
0028 class UiController;
0029 class MainWindow;
0030 class Core;
0031 
0032 class WorkingSet;
0033 class WorkingSetToolTipWidget;
0034 
0035 class WorkingSetController : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     WorkingSetController();
0041     void initialize();
0042     void cleanup();
0043 
0044     ///Returns a working-set management widget
0045 //     QWidget* createManagerWidget(QObject* parent);
0046 
0047     WorkingSet* newWorkingSet(const QString& prefix);
0048 
0049     /**
0050      * Get WorkingSet for given @p id.
0051      *
0052      * NOTE: Never pass an empty @p id, this means there is no working set
0053      *       for the given area you got that @p id from.
0054      */
0055     WorkingSet* workingSet(const QString& id);
0056 
0057     QList<WorkingSet*> allWorkingSets() const;
0058 
0059     //The returned widget is owned by the caller
0060     QWidget* createSetManagerWidget(MainWindow* parent, Sublime::Area* fixedArea = nullptr);
0061 
0062     void initializeController(UiController* controller);
0063 
0064     KDevelop::ActiveToolTip* tooltip() const;
0065     void showToolTip( KDevelop::WorkingSet* set, const QPoint& pos);
0066 
0067 Q_SIGNALS:
0068     void workingSetAdded(WorkingSet* set);
0069     void aboutToRemoveWorkingSet(WorkingSet* set);
0070     // Emitted after a working-set in a main-window was switched
0071     void workingSetSwitched();
0072 
0073 public Q_SLOTS:
0074     void saveArea(Sublime::Area* area);
0075 
0076 private Q_SLOTS:
0077     void areaCreated(Sublime::Area* area);
0078 
0079     void nextDocument();
0080     void previousDocument();
0081     void showGlobalToolTip();
0082 
0083     /**
0084      * Disconnect @p oldSet from @p area and save it. Connect @p newSet with @p area.
0085      */
0086     void changingWorkingSet(Sublime::Area *area, Sublime::Area *oldArea, const QString &oldSet, const QString &newSet);
0087     /**
0088      * Notify about working set change and setup @p area with contents of @p newSet.
0089      */
0090     void changedWorkingSet(Sublime::Area *area, Sublime::Area *oldArea, const QString &oldSet, const QString &newSet);
0091     /**
0092      * Spawn new WorkingSet when we don't have one already for the view.
0093      */
0094     void viewAdded( Sublime::AreaIndex*, Sublime::View* );
0095 
0096     /**
0097      * Clears the files in the working set
0098      */
0099     void clearWorkingSet(Sublime::Area* area);
0100 
0101 private:
0102     WorkingSetToolTipWidget* workingSetToolTip();
0103     void setupActions();
0104     const QString makeSetId(const QString& prefix) const;
0105 
0106     QSet<QString> m_usedIcons;
0107     QMap<QString, WorkingSet*> m_workingSets;
0108     WorkingSet* m_emptyWorkingSet = nullptr;
0109     QTimer* m_hideToolTipTimer;
0110     QPointer<KDevelop::ActiveToolTip> m_tooltip;
0111     // This is set to true while the working-set controller is forcing a working-set
0112     // onto an area. We ignore the low-level feedback then, as we handle the switch on a higher level.
0113     bool m_changingWorkingSet = false;
0114 };
0115 
0116 }
0117 
0118 #endif // KDEVPLATFORM_WORKINGSETCONTROLLER_H