Skip to content

Commit 80470f9

Browse files
committed
Allow sidebar icons to be hidden
1 parent 55b3ce7 commit 80470f9

File tree

6 files changed

+91
-5
lines changed

6 files changed

+91
-5
lines changed

ui/globalarea.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,6 @@ class BINARYNINJAUIAPI GlobalAreaCompatibilitySidebarWidgetType : public Sidebar
215215
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::LeftBottom; }
216216
SidebarContextSensitivity contextSensitivity() const override { return GlobalSidebarContext; }
217217
bool alwaysShowTabs() const override { return true; }
218-
bool hideIfNoContent() const override { return true; }
218+
SidebarIconVisibility defaultIconVisibility() const override { return InvisibleIfNoContent; }
219+
SidebarContentClassifier* contentClassifier(ViewFrame*, BinaryViewRef) override;
219220
};

ui/sidebar.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class BINARYNINJAUIAPI Sidebar : public QObject
6060
static std::set<Sidebar*> m_instances;
6161
static std::set<SidebarWidgetType*> m_defaultTypes;
6262
static std::optional<SidebarMetrics> m_metrics;
63+
static std::map<QString, SidebarIconVisibility> m_iconVisibility;
6364

6465
private Q_SLOTS:
6566
void containerUpdated();
@@ -122,6 +123,8 @@ private Q_SLOTS:
122123
bool isContentActive() const;
123124
bool isSideContentActive() const;
124125
bool isBottomContentActive() const;
126+
bool allIconsVisible() const;
127+
std::vector<SidebarWidgetType*> hiddenIcons() const;
125128

126129
void updateTheme();
127130
void updateFonts();
@@ -146,13 +149,20 @@ private Q_SLOTS:
146149
static std::vector<SidebarWidgetType*> typesForContainerLocation(SidebarContainerLocation location);
147150
static void initSavedTypeOrdering();
148151
static void saveTypeOrdering();
152+
static void initIconVisibility();
153+
static void saveIconVisibility();
149154

150155
static SidebarMetrics metrics();
151156
static void refreshMetrics();
152157

153158
static std::set<SidebarWidgetType*> defaultTypes() { return m_defaultTypes; }
154159
static void setDefaultTypes(const std::set<SidebarWidgetType*>& types) { m_defaultTypes = types; }
155160

161+
static SidebarIconVisibility iconVisibility(SidebarWidgetType* type);
162+
static SidebarIconVisibility iconVisibility(const QString& name);
163+
static void setIconVisibility(SidebarWidgetType* type, SidebarIconVisibility visibility);
164+
static void setIconVisibility(const QString& name, SidebarIconVisibility visibility);
165+
156166
static Sidebar* current()
157167
{
158168
UIContext* context = UIContext::activeContext();

ui/sidebarcontainer.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#include <QtWidgets/QStackedWidget>
55
#include <QtWidgets/QWidget>
66
#include "splitter.h"
7+
#include "sidebarwidget.h"
78

89
class Sidebar;
9-
class SidebarWidgetType;
10-
class SidebarWidgetAndHeader;
1110
class SplitPaneWidget;
1211

1312
/*!
@@ -88,17 +87,22 @@ class BINARYNINJAUIAPI SidebarWidgetContainer : public QWidget
8887
std::map<SplitPaneWidget*,
8988
std::map<ViewFrame*, std::map<QString, std::map<SidebarWidgetType*, SidebarWidgetAndHeader*>>>>
9089
m_widgets;
90+
std::map<SplitPaneWidget*,
91+
std::map<ViewFrame*, std::map<QString, std::map<SidebarWidgetType*, SidebarContentClassifier*>>>>
92+
m_contentClassifiers;
9193
std::map<SplitPaneWidget*, std::map<QString, std::set<SidebarWidgetType*>>> m_priorWidgets;
9294

9395
std::map<SidebarWidgetType*, SidebarFloatingWidgetState> m_savedFloatingWidgetState;
9496

9597
SidebarStackedWidget& stackedWidgetForType(SidebarWidgetType* type);
9698
std::vector<SidebarWidgetAndHeader*> widgetsForContext() const;
99+
std::vector<SidebarContentClassifier*> contentClassifiersForContext() const;
97100
void insertWidgetIntoContainer(SidebarWidgetType* type, QStackedWidget* widget);
98101
void updateContentsVisibility();
99102

100103
private Q_SLOTS:
101104
void floatingWidgetClosed(SidebarWidgetType* type);
105+
void childContentClassificationChanged();
102106

103107
public:
104108
SidebarWidgetContainer(Sidebar* sidebar, SidebarContainerLocation location);
@@ -134,8 +138,11 @@ private Q_SLOTS:
134138
SidebarWidget* widgetWithTitle(SidebarWidgetType* type, const QString& title) const;
135139
bool hasWidgetWithTitle(SidebarWidgetType* type, const QString& title) const;
136140
bool activateWidgetWithTitle(SidebarWidgetType* type, const QString& title) const;
137-
bool hasContent(SidebarWidgetType* type) const;
138-
bool shouldHide(SidebarWidgetType* type) const;
141+
SidebarContentClassification contentClassification(SidebarWidgetType* type);
142+
bool hasContent(SidebarWidgetType* type);
143+
bool shouldHide(SidebarWidgetType* type);
144+
145+
SidebarContentClassifier* contentClassifier(SidebarWidgetType* type);
139146

140147
virtual QSize sizeHint() const override;
141148

@@ -162,4 +169,5 @@ private Q_SLOTS:
162169
Q_SIGNALS:
163170
void showContents();
164171
void hideContents();
172+
void contentClassificationChanged();
165173
};

ui/sidebaricons.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ class BINARYNINJAUIAPI SidebarIconsWidget : public QWidget
7878
std::pair<SidebarWidgetLocation, size_t> findDropLocation(int y) const;
7979
QRect placeholderRect() const;
8080
bool shouldBeVisible() const;
81+
bool shouldContainMoreIcon() const;
8182

8283
private Q_SLOTS:
8384
void containerUpdated();
85+
void contentClassificationChanged();
8486

8587
protected:
8688
virtual void paintEvent(QPaintEvent* event) override;

ui/sidebarwidget.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,51 @@ enum SidebarContextSensitivity
185185
PerPaneSidebarContext
186186
};
187187

188+
/*!
189+
\ingroup sidebar
190+
*/
191+
enum SidebarIconVisibility
192+
{
193+
AlwaysShowSidebarIcon,
194+
HideSidebarIconIfNoContent,
195+
AlwaysHideSidebarIcon,
196+
InvisibleIfNoContent
197+
};
198+
199+
/*!
200+
\ingroup sidebar
201+
*/
202+
enum SidebarContentClassification
203+
{
204+
SidebarHasRelevantContent,
205+
SidebarHasGeneralMessage,
206+
SidebarHasNoContent,
207+
SidebarIsWidgetContainer
208+
};
209+
210+
class BINARYNINJAUIAPI SidebarContentClassifier : public QObject
211+
{
212+
Q_OBJECT
213+
214+
public:
215+
virtual SidebarContentClassification contentClassification() = 0;
216+
virtual void notifyViewChanged(ViewFrame*) {}
217+
218+
Q_SIGNALS:
219+
void contentClassificationChanged();
220+
};
221+
222+
class BINARYNINJAUIAPI StaticSidebarContentClassifier : public SidebarContentClassifier
223+
{
224+
Q_OBJECT
225+
226+
SidebarContentClassification m_classification;
227+
228+
public:
229+
StaticSidebarContentClassifier(SidebarContentClassification classification) : m_classification(classification) {}
230+
SidebarContentClassification contentClassification() override { return m_classification; }
231+
};
232+
188233
/*!
189234
\ingroup sidebar
190235
*/
@@ -213,8 +258,14 @@ class BINARYNINJAUIAPI SidebarWidgetType
213258
virtual SidebarWidgetLocation defaultLocation() const;
214259
virtual SidebarContextSensitivity contextSensitivity() const;
215260
virtual bool alwaysShowTabs() const { return false; }
261+
262+
/*!
263+
\deprecated Use `defaultIconVisibility()`
264+
*/
216265
virtual bool hideIfNoContent() const { return false; }
217266

267+
virtual SidebarIconVisibility defaultIconVisibility() const;
268+
218269
virtual SidebarWidget* createWidget(ViewFrame* /*frame*/, BinaryViewRef /*data*/) { return nullptr; }
219270
virtual SidebarWidget* createInvalidContextWidget();
220271
virtual QWidget* headerWidget(SplitPaneWidget* /*panes*/, ViewFrame* /*frame*/, BinaryViewRef /*data*/)
@@ -228,5 +279,18 @@ class BINARYNINJAUIAPI SidebarWidgetType
228279
virtual bool canUseAsPane(SplitPaneWidget* /*panes*/, BinaryViewRef /*data*/) const { return false; }
229280
virtual Pane* createPane(SplitPaneWidget* /*panes*/, BinaryViewRef /*data*/) { return nullptr; }
230281

282+
virtual SidebarContentClassifier* contentClassifier(ViewFrame* /*frame*/, BinaryViewRef /*data*/)
283+
{
284+
return nullptr;
285+
}
286+
231287
void updateTheme();
232288
};
289+
290+
class BINARYNINJAUIAPI MoreSidebarWidgetType : public SidebarWidgetType
291+
{
292+
public:
293+
MoreSidebarWidgetType();
294+
295+
static MoreSidebarWidgetType* instance();
296+
};

ui/workflowmonitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class BINARYNINJAUIAPI WorkflowMonitorSidebarWidgetType : public SidebarWidgetTy
102102

103103
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::LeftReference; }
104104
SidebarContextSensitivity contextSensitivity() const override { return PerViewTypeSidebarContext; }
105+
SidebarIconVisibility defaultIconVisibility() const override { return AlwaysHideSidebarIcon; }
105106

106107
SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override;
107108

0 commit comments

Comments
 (0)