Commit 4c041b2e authored by Ell's avatar Ell

app: allow hiding groups in the dashboard

Add a "groups" submenu to the dashboard popup menu, which can be
used to control which groups are shown in the dashboard.
parent ea48b9f3
......@@ -40,6 +40,8 @@ static const GimpActionEntry dashboard_actions[] =
NC_("dashboard-action", "Dashboard Menu"), NULL, NULL, NULL,
GIMP_HELP_DASHBOARD_DIALOG },
{ "dashboard-groups", NULL,
NC_("dashboard-action", "Groups") },
{ "dashboard-update-interval", NULL,
NC_("dashboard-action", "Update Interval") },
{ "dashboard-history-duration", NULL,
......
......@@ -30,6 +30,7 @@
#include "core/gimp.h"
#include "widgets/gimpactionfactory.h"
#include "widgets/gimpdashboard.h"
#include "widgets/gimpmenufactory.h"
#include "dockable-menu.h"
......@@ -392,8 +393,7 @@ menus_init (Gimp *gimp,
"dashboard",
NULL,
"/dashboard-popup",
"dashboard-menu.xml",
NULL,
"dashboard-menu.xml", gimp_dashboard_menu_setup,
NULL);
}
......
......@@ -42,12 +42,14 @@
#include "core/gimp.h"
#include "gimpactiongroup.h"
#include "gimpdocked.h"
#include "gimpdashboard.h"
#include "gimpdialogfactory.h"
#include "gimphelp-ids.h"
#include "gimpmeter.h"
#include "gimpsessioninfo-aux.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
#include "gimpwindowstrategy.h"
......@@ -160,6 +162,7 @@ struct _GroupInfo
const gchar *name;
const gchar *title;
const gchar *description;
gboolean default_active;
gboolean default_expanded;
gboolean has_meter;
Variable meter_limit;
......@@ -200,19 +203,21 @@ struct _FieldData
struct _GroupData
{
gint n_fields;
gint n_meter_values;
gint n_fields;
gint n_meter_values;
gdouble limit;
gboolean active;
gdouble limit;
GtkExpander *expander;
GtkLabel *header_values_label;
GtkButton *menu_button;
GtkMenu *menu;
GimpMeter *meter;
GtkTable *table;
GtkToggleAction *action;
GtkExpander *expander;
GtkLabel *header_values_label;
GtkButton *menu_button;
GtkMenu *menu;
GimpMeter *meter;
GtkTable *table;
FieldData *fields;
FieldData *fields;
};
struct _GimpDashboardPrivate
......@@ -256,7 +261,9 @@ static gboolean gimp_dashboard_group_expander_button_press (GimpDashboard
GdkEventButton *bevent,
GtkWidget *widget);
static void gimp_dashboard_group_menu_item_toggled (GimpDashboard *dashboard,
static void gimp_dashboard_group_action_toggled (GimpDashboard *dashboard,
GtkToggleAction *action);
static void gimp_dashboard_field_menu_item_toggled (GimpDashboard *dashboard,
GtkCheckMenuItem *item);
static gpointer gimp_dashboard_sample (GimpDashboard *dashboard);
......@@ -302,6 +309,9 @@ static void gimp_dashboard_update_group (GimpDashboard
static void gimp_dashboard_update_group_values (GimpDashboard *dashboard,
Group group);
static void gimp_dashboard_group_set_active (GimpDashboard *dashboard,
Group group,
gboolean active);
static void gimp_dashboard_field_set_active (GimpDashboard *dashboard,
Group group,
gint field,
......@@ -459,6 +469,7 @@ static const GroupInfo groups[] =
{ .name = "cache",
.title = NC_("dashboard-group", "Cache"),
.description = N_("In-memory tile cache"),
.default_active = TRUE,
.default_expanded = TRUE,
.has_meter = TRUE,
.meter_limit = VARIABLE_CACHE_LIMIT,
......@@ -495,6 +506,7 @@ static const GroupInfo groups[] =
{ .name = "swap",
.title = NC_("dashboard-group", "Swap"),
.description = N_("On-disk tile swap"),
.default_active = TRUE,
.default_expanded = TRUE,
.has_meter = TRUE,
.meter_limit = VARIABLE_SWAP_LIMIT,
......@@ -524,6 +536,7 @@ static const GroupInfo groups[] =
{ .name = "cpu",
.title = NC_("dashboard-group", "CPU"),
.description = N_("CPU usage"),
.default_active = TRUE,
.default_expanded = FALSE,
.has_meter = TRUE,
.meter_led = VARIABLE_CPU_ACTIVE,
......@@ -655,7 +668,6 @@ gimp_dashboard_init (GimpDashboard *dashboard)
group_info->default_expanded);
gtk_expander_set_label_fill (GTK_EXPANDER (expander), TRUE);
gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 0);
gtk_widget_show (expander);
g_object_set_data (G_OBJECT (expander),
"gimp-dashboard-group", GINT_TO_POINTER (group));
......@@ -736,7 +748,7 @@ gimp_dashboard_init (GimpDashboard *dashboard)
g_object_set_data (G_OBJECT (item),
"gimp-dashboard-field", GINT_TO_POINTER (field));
g_signal_connect_swapped (item, "toggled",
G_CALLBACK (gimp_dashboard_group_menu_item_toggled),
G_CALLBACK (gimp_dashboard_field_menu_item_toggled),
dashboard);
gimp_dashboard_field_set_active (dashboard, group, field,
......@@ -819,6 +831,8 @@ gimp_dashboard_init (GimpDashboard *dashboard)
gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
gtk_widget_show (table);
gimp_dashboard_group_set_active (dashboard, group,
group_info->default_active);
gimp_dashboard_update_group (dashboard, group);
}
......@@ -847,10 +861,46 @@ gimp_dashboard_docked_iface_init (GimpDockedInterface *iface)
static void
gimp_dashboard_constructed (GObject *object)
{
GimpDashboard *dashboard = GIMP_DASHBOARD (object);
GimpDashboard *dashboard = GIMP_DASHBOARD (object);
GimpDashboardPrivate *priv = dashboard->priv;
GimpUIManager *ui_manager;
GimpActionGroup *action_group;
Group group;
G_OBJECT_CLASS (parent_class)->constructed (object);
ui_manager = gimp_editor_get_ui_manager (GIMP_EDITOR (dashboard));
action_group = gimp_ui_manager_get_action_group (ui_manager, "dashboard");
/* group actions */
for (group = FIRST_GROUP; group < N_GROUPS; group++)
{
const GroupInfo *group_info = &groups[group];
GroupData *group_data = &priv->groups[group];
GimpToggleActionEntry entry = {};
GtkAction *action;
entry.name = g_strdup_printf ("dashboard-group-%s", group_info->name);
entry.label = g_dpgettext2 (NULL, "dashboard-group", group_info->title);
entry.tooltip = g_dgettext (NULL, group_info->description);
entry.help_id = GIMP_HELP_DASHBOARD_GROUPS;
entry.is_active = group_data->active;
gimp_action_group_add_toggle_actions (action_group, "dashboard-groups",
&entry, 1);
action = gimp_ui_manager_find_action (ui_manager, "dashboard", entry.name);
group_data->action = GTK_TOGGLE_ACTION (action);
g_object_set_data (G_OBJECT (action),
"gimp-dashboard-group", GINT_TO_POINTER (group));
g_signal_connect_swapped (action, "toggled",
G_CALLBACK (gimp_dashboard_group_action_toggled),
dashboard);
g_free ((gpointer) entry.name);
}
gimp_editor_add_action_button (GIMP_EDITOR (dashboard), "dashboard",
"dashboard-reset", NULL);
}
......@@ -991,6 +1041,20 @@ gimp_dashboard_set_aux_info (GimpDocked *docked,
const GroupInfo *group_info = &groups[group];
GroupData *group_data = &priv->groups[group];
name = g_strdup_printf ("%s-active", group_info->name);
if (! strcmp (aux->name, name))
{
gboolean active = ! strcmp (aux->value, "yes");
gimp_dashboard_group_set_active (dashboard, group, active);
g_free (name);
goto next_aux_info;
}
g_free (name);
name = g_strdup_printf ("%s-expanded", group_info->name);
if (! strcmp (aux->name, name))
......@@ -1081,8 +1145,18 @@ gimp_dashboard_get_aux_info (GimpDocked *docked)
{
const GroupInfo *group_info = &groups[group];
GroupData *group_data = &priv->groups[group];
gboolean active = group_data->active;
gboolean expanded = gtk_expander_get_expanded (group_data->expander);
if (active != group_info->default_active)
{
name = g_strdup_printf ("%s-active", group_info->name);
value = active ? "yes" : "no";
aux = gimp_session_info_aux_new (name, value);
aux_info = g_list_append (aux_info, aux);
g_free (name);
}
if (expanded != group_info->default_expanded)
{
name = g_strdup_printf ("%s-expanded", group_info->name);
......@@ -1161,7 +1235,24 @@ gimp_dashboard_group_expander_button_press (GimpDashboard *dashboard,
}
static void
gimp_dashboard_group_menu_item_toggled (GimpDashboard *dashboard,
gimp_dashboard_group_action_toggled (GimpDashboard *dashboard,
GtkToggleAction *action)
{
GimpDashboardPrivate *priv = dashboard->priv;
Group group;
GroupData *group_data;
group = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action),
"gimp-dashboard-group"));
group_data = &priv->groups[group];
group_data->active = gtk_toggle_action_get_active (action);
gimp_dashboard_update_group (dashboard, group);
}
static void
gimp_dashboard_field_menu_item_toggled (GimpDashboard *dashboard,
GtkCheckMenuItem *item)
{
GimpDashboardPrivate *priv = dashboard->priv;
......@@ -1806,6 +1897,12 @@ gimp_dashboard_update_group (GimpDashboard *dashboard,
gboolean add_separator;
gint field;
gtk_widget_set_visible (GTK_WIDGET (group_data->expander),
group_data->active);
if (! group_data->active)
return;
n_rows = 0;
add_separator = FALSE;
......@@ -1949,6 +2046,9 @@ gimp_dashboard_update_group_values (GimpDashboard *dashboard,
GString *header_values;
gint field;
if (! group_data->active)
return;
if (group_info->has_meter)
{
if (group_info->meter_limit)
......@@ -2038,6 +2138,33 @@ gimp_dashboard_update_group_values (GimpDashboard *dashboard,
g_string_free (header_values, TRUE);
}
static void
gimp_dashboard_group_set_active (GimpDashboard *dashboard,
Group group,
gboolean active)
{
GimpDashboardPrivate *priv = dashboard->priv;
GroupData *group_data = &priv->groups[group];
if (active != group_data->active)
{
group_data->active = active;
if (group_data->action)
{
g_signal_handlers_block_by_func (group_data->action,
gimp_dashboard_group_action_toggled,
dashboard);
gtk_toggle_action_set_active (group_data->action, active);
g_signal_handlers_unblock_by_func (group_data->action,
gimp_dashboard_group_action_toggled,
dashboard);
}
}
}
static void
gimp_dashboard_field_set_active (GimpDashboard *dashboard,
Group group,
......@@ -2053,13 +2180,13 @@ gimp_dashboard_field_set_active (GimpDashboard *dashboard,
field_data->active = active;
g_signal_handlers_block_by_func (field_data->menu_item,
gimp_dashboard_group_menu_item_toggled,
gimp_dashboard_field_menu_item_toggled,
dashboard);
gtk_check_menu_item_set_active (field_data->menu_item, active);
g_signal_handlers_unblock_by_func (field_data->menu_item,
gimp_dashboard_group_menu_item_toggled,
gimp_dashboard_field_menu_item_toggled,
dashboard);
}
}
......@@ -2467,3 +2594,34 @@ gimp_dashboard_get_low_swap_space_warning (GimpDashboard *dashboard)
return dashboard->priv->low_swap_space_warning;
}
void
gimp_dashboard_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
guint merge_id;
Group group;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
for (group = FIRST_GROUP; group < N_GROUPS; group++)
{
const GroupInfo *group_info = &groups[group];
gchar *action_name;
gchar *action_path;
action_name = g_strdup_printf ("dashboard-group-%s", group_info->name);
action_path = g_strdup_printf ("%s/Groups/Groups", ui_path);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
action_path, action_name, action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
g_free (action_name);
g_free (action_path);
}
}
......@@ -68,5 +68,8 @@ void gimp_dashboard_set_low_swap_space_warning (GimpDa
gboolean low_swap_space_warning);
gboolean gimp_dashboard_get_low_swap_space_warning (GimpDashboard *dashboard);
void gimp_dashboard_menu_setup (GimpUIManager *manager,
const gchar *ui_path);
#endif /* __GIMP_DASHBOARD_H__ */
......@@ -665,6 +665,7 @@
#define GIMP_HELP_SAMPLE_POINT_SAMPLE_MERGED "gimp-sample-point-sample-merged"
#define GIMP_HELP_DASHBOARD_DIALOG "gimp-dashboard-dialog"
#define GIMP_HELP_DASHBOARD_GROUPS "gimp-dashboard-groups"
#define GIMP_HELP_DASHBOARD_UPDATE_INTERVAL "gimp-dashboard-update-interval"
#define GIMP_HELP_DASHBOARD_HISTORY_DURATION "gimp-dashboard-history-duration"
#define GIMP_HELP_DASHBOARD_RESET "gimp-dashboard-reset"
......
......@@ -3,14 +3,17 @@
<ui>
<popup action="dashboard-popup">
<menu action="dashboard-update-interval">
<menu action="dashboard-groups" name="Groups">
<placeholder name="Groups" />
</menu>
<menu action="dashboard-update-interval" name="Update Interval">
<menuitem action="dashboard-update-interval-0-25-sec" />
<menuitem action="dashboard-update-interval-0-5-sec" />
<menuitem action="dashboard-update-interval-1-sec" />
<menuitem action="dashboard-update-interval-2-sec" />
<menuitem action="dashboard-update-interval-4-sec" />
</menu>
<menu action="dashboard-history-duration">
<menu action="dashboard-history-duration" name="History Duration">
<menuitem action="dashboard-history-duration-15-sec" />
<menuitem action="dashboard-history-duration-30-sec" />
<menuitem action="dashboard-history-duration-60-sec" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment