Skip to content

Commit

Permalink
Add highlight when clicking a pinned item
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Feb 18, 2024
1 parent dad9089 commit 8fc302a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pinner.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ static GtkWidget* pinned_view_vbox;
static gint page_number = 0;
static GHashTable* doc_to_widget_map = NULL;

static void
init_css(void)
{
GtkCssProvider* provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(
provider,
"label.highlight { background-color: #007bff; color: #ffffff; }",
-1,
NULL);
gtk_style_context_add_provider_for_screen(
gdk_screen_get_default(),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);
}

static gboolean
remove_highlight(gpointer data)
{
GtkWidget* label = GTK_WIDGET(data);
GtkStyleContext* context = gtk_widget_get_style_context(label);
gtk_style_context_remove_class(context, "highlight");
return G_SOURCE_REMOVE; // Same as returning FALSE
}

static void
destroy_widget(gpointer pdata)
{
Expand Down Expand Up @@ -252,6 +277,14 @@ on_button_press_cb(GtkWidget* widget, GdkEventButton* event, gpointer pdata)
if (GTK_IS_LABEL(label)) {
const gchar* file_name = gtk_label_get_text(GTK_LABEL(label));
document_open_file(file_name, FALSE, NULL, NULL);

// Highlight the label
GtkStyleContext* context = gtk_widget_get_style_context(label);
gtk_style_context_add_class(context, "highlight");

// Set a timeout to remove the highlight after 1 second (1000
// milliseconds)
g_timeout_add(500, remove_highlight, label);
}
}
} else if (event->type == GDK_BUTTON_PRESS &&
Expand Down Expand Up @@ -282,6 +315,8 @@ pin_init(GeanyPlugin* plugin, gpointer pdata)
// warning that the value is not used.
(void)pdata;

init_css();

GtkWidget** tools_item =
g_new0(GtkWidget*,
3); // Allocate memory for 3 pointers (2 items + NULL terminator)
Expand Down

0 comments on commit 8fc302a

Please sign in to comment.