Skip to content
Permalink
Browse files

libslab: code clean up

Since we use GtkSearchEntry a lot of code can be dropped.
afcb324

Eg: GtkSearchEntry has a own menu in result search-context-picker.c
does nothing.
So other code in searchbar.c isn't used.
  • Loading branch information...
raveit65 committed Jun 8, 2018
1 parent f6d429e commit d21cbadc64065b72eb6494247bbc6d876d57eb14
@@ -17,7 +17,6 @@ HEADER_FILES= \
libslab-utils.h \
nameplate-tile.h \
search-bar.h \
search-context-picker.h \
shell-window.h \
slab-mate-util.h \
slab-section.h \
@@ -37,7 +36,6 @@ libmate_slab_la_SOURCES = \
libslab-utils.c \
nameplate-tile.c \
search-bar.c \
search-context-picker.c \
shell-window.c \
slab-mate-util.c \
slab-section.c \
@@ -74,7 +74,7 @@ static void launch_selected_app (AppShellData * app_data);
static void generate_potential_apps (gpointer catdata, gpointer user_data);

static void relayout_shell (AppShellData * app_data);
static gboolean handle_filter_changed (NldSearchBar * search_bar, int context, const char *text,
static gboolean handle_filter_changed (NldSearchBar * search_bar, const char *text,
gpointer user_data);
static void handle_group_clicked (Tile * tile, TileEvent * event, gpointer user_data);
static void set_state (AppShellData * app_data, GtkWidget * widget);
@@ -581,7 +581,7 @@ handle_filter_changed_delayed (gpointer user_data)
}

static gboolean
handle_filter_changed (NldSearchBar * search_bar, int context, const char *text, gpointer data)
handle_filter_changed (NldSearchBar * search_bar, const char *text, gpointer data)
{
AppShellData *app_data;

@@ -1 +1 @@
VOID:INT,STRING
VOID:STRING
@@ -21,15 +21,13 @@
#include "search-bar.h"
#include "config.h"

#include "search-context-picker.h"
#include "nld-marshal.h"

#include <glib/gi18n-lib.h>

typedef struct
{
GtkWidget *hbox;
NldSearchContextPicker *context_picker;
GtkEntry *entry;
GtkWidget *button;

@@ -75,8 +73,7 @@ static void nld_search_bar_class_init (NldSearchBarClass * nld_search_bar_class)
signals[SEARCH] =
g_signal_new ("search", G_TYPE_FROM_CLASS (nld_search_bar_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (NldSearchBarClass, search),
NULL, NULL, nld_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT,
G_TYPE_STRING);
NULL, NULL, nld_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
@@ -151,8 +148,6 @@ nld_search_bar_clear (NldSearchBar * search_bar)

priv->block_signal = TRUE;
gtk_entry_set_text (priv->entry, "");
if (priv->context_picker)
nld_search_context_picker_set_context (priv->context_picker, 0);
priv->block_signal = FALSE;
}

@@ -170,7 +165,7 @@ emit_search (NldSearchBar * search_bar)
priv->timeout_id = 0;
}

g_signal_emit (search_bar, signals[SEARCH], 0, nld_search_bar_get_context_id (search_bar),
g_signal_emit (search_bar, signals[SEARCH], 0,
nld_search_bar_get_text (search_bar));
}

@@ -180,96 +175,6 @@ emit_search_callback (GtkWidget * widget, gpointer search_bar)
emit_search (search_bar);
}

gboolean
nld_search_bar_get_show_contexts (NldSearchBar * search_bar)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

return priv->context_picker && gtk_widget_get_visible (GTK_WIDGET (priv->context_picker));
}

static NldSearchContextPicker *
build_context_picker (NldSearchBar * search_bar)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);
GtkWidget *picker;

picker = nld_search_context_picker_new ();
g_signal_connect (picker, "context_changed", G_CALLBACK (emit_search_callback), search_bar);

gtk_box_pack_start (GTK_BOX (priv->hbox), picker, 0, 0, FALSE);
gtk_box_reorder_child (GTK_BOX (priv->hbox), picker, 0);

return NLD_SEARCH_CONTEXT_PICKER (picker);
}

void
nld_search_bar_set_show_contexts (NldSearchBar * search_bar, gboolean show_contexts)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

if (show_contexts)
{
if (!priv->context_picker)
priv->context_picker = build_context_picker (search_bar);
gtk_widget_show (GTK_WIDGET (priv->context_picker));
}
else if (priv->context_picker)
gtk_widget_hide (GTK_WIDGET (priv->context_picker));
}

void
nld_search_bar_add_context (NldSearchBar * search_bar, const char *label, const char *icon_name,
int context_id)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

if (!priv->context_picker)
priv->context_picker = build_context_picker (search_bar);

nld_search_context_picker_add_context (priv->context_picker, label, icon_name, context_id);
}

gboolean
nld_search_bar_get_show_button (NldSearchBar * search_bar)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

return priv->button != NULL;
}

void
nld_search_bar_set_show_button (NldSearchBar * search_bar, gboolean show_button)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

if (show_button)
{
GtkWidget *image;

if (priv->button)
return;

priv->button = gtk_button_new_with_label (_("Find Now"));
image = gtk_image_new_from_icon_name ("system-search", GTK_ICON_SIZE_MENU);
gtk_button_set_image (GTK_BUTTON (priv->button), image);
gtk_widget_show (priv->button);

g_signal_connect (priv->button, "clicked", G_CALLBACK (emit_search_callback),
search_bar);

gtk_box_pack_end (GTK_BOX (priv->hbox), priv->button, FALSE, FALSE, 0);
}
else
{
if (!priv->button)
return;

gtk_widget_destroy (priv->button);
priv->button = NULL;
}
}

static gboolean
search_timeout (gpointer search_bar)
{
@@ -337,23 +242,3 @@ nld_search_bar_set_text (NldSearchBar * search_bar, const char *text, gboolean a
emit_search (search_bar);
}

int
nld_search_bar_get_context_id (NldSearchBar * search_bar)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

if (priv->context_picker && gtk_widget_get_visible (GTK_WIDGET (priv->context_picker)))
return nld_search_context_picker_get_context (priv->context_picker);
else
return -1;
}

void
nld_search_bar_set_context_id (NldSearchBar * search_bar, int context_id)
{
NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar);

g_return_if_fail (priv->context_picker != NULL);

nld_search_context_picker_set_context (priv->context_picker, context_id);
}
@@ -43,7 +43,7 @@ typedef struct
{
GtkBoxClass parent_class;

void (*search) (NldSearchBar *, int context_id, const char *text);
void (*search) (NldSearchBar *, const char *text);
} NldSearchBarClass;

GType nld_search_bar_get_type (void);
@@ -53,11 +53,6 @@ GtkWidget *nld_search_bar_new (void);
void nld_search_bar_clear (NldSearchBar * search_bar);
gboolean nld_search_bar_has_focus (NldSearchBar * search_bar);

gboolean nld_search_bar_get_show_contexts (NldSearchBar * search_bar);
void nld_search_bar_set_show_contexts (NldSearchBar * search_bar, gboolean show_contexts);
void nld_search_bar_add_context (NldSearchBar * search_bar, const char *label,
const char *icon_name, int context_id);

gboolean nld_search_bar_get_show_button (NldSearchBar * search_bar);
void nld_search_bar_set_show_button (NldSearchBar * search_bar, gboolean show_button);

@@ -67,9 +62,6 @@ void nld_search_bar_set_search_timeout (NldSearchBar * search_bar, int search_ti
const char *nld_search_bar_get_text (NldSearchBar * search_bar);
void nld_search_bar_set_text (NldSearchBar * search_bar, const char *text, gboolean activate);

int nld_search_bar_get_context_id (NldSearchBar * search_bar);
void nld_search_bar_set_context_id (NldSearchBar * search_bar, int context_id);

#ifdef __cplusplus
}
#endif
Oops, something went wrong.

0 comments on commit d21cbad

Please sign in to comment.
You can’t perform that action at this time.