Skip to content

Commit

Permalink
Add non-working popup menu and func to clear list
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Feb 14, 2024
1 parent 4bb86a9 commit 18b58b3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
56 changes: 54 additions & 2 deletions pinner/pinner.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*
*/

#include <geanyplugin.h>
#include <stdbool.h>
#include "pinner.h"


static GtkWidget *pinned_view_vbox;
static gint page_number = 0;
Expand All @@ -42,6 +42,37 @@ static struct pindata *init_pindata(void)
return &container;
}


void slist_free_wrapper(gpointer pdata)
{
struct pindata *container = pdata;
GSList *list = container->list;
GSList *iter;
for (iter = list; iter != NULL; iter = g_slist_next(iter))
g_free(iter->data);

g_slist_free_full(list, g_free);
container->list = NULL;
}


/* A function adapted (pinched) from filebrowser.c */
static GtkWidget *create_popup_menu(gpointer pdata)
{
GtkWidget *item, *menu;

menu = gtk_menu_new();

/* 3? What should the size be? */
/* https://docs.gtk.org/gtk3/ctor.Image.new_from_icon_name.html */
item = gtk_image_new_from_icon_name("edit-clear", 3);
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
g_signal_connect(item, "activate", G_CALLBACK(slist_free_wrapper), pdata);

return menu;
}

bool is_duplicate(GSList *list, const gchar* file_name)
{
GSList *iter;
Expand Down Expand Up @@ -85,6 +116,25 @@ static void pin_activate_cb(GtkMenuItem *menuitem, gpointer pdata)
return;
}

static gboolean on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer pdata)
{
//if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
//{
//on_open_clicked(NULL, NULL);
//return TRUE;
//}
if (event->button == 3)
{
static GtkWidget *popup_menu = NULL;

if (popup_menu == NULL)
popup_menu = create_popup_menu(pdata);

gtk_menu_popup_at_pointer(GTK_MENU(popup_menu), (GdkEvent *) event);
/* don't return TRUE here, unless the selection won't be changed */
}
return FALSE;
}

static gboolean pin_init(GeanyPlugin *plugin, gpointer pdata)
{
Expand All @@ -100,6 +150,8 @@ static gboolean pin_init(GeanyPlugin *plugin, gpointer pdata)
main_menu_item);
g_signal_connect(main_menu_item, "activate",
G_CALLBACK(pin_activate_cb), container);
g_signal_connect(pinned_view_vbox, "button-press-event",
G_CALLBACK(on_button_press), container);

geany_plugin_set_data(plugin, main_menu_item, NULL);

Expand Down
31 changes: 31 additions & 0 deletions pinner/pinner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* pinner.h
*
* Copyright 2024 Andy Alt <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/

#include <geanyplugin.h>
#include <stdbool.h>

static struct pindata *init_pindata(void);
void slist_free_wrapper(gpointer pdata);
static GtkWidget *create_popup_menu(gpointer pdata);
bool is_duplicate(GSList *list, const gchar* file_name);
static void pin_activate_cb(GtkMenuItem *menuitem, gpointer pdata);

0 comments on commit 18b58b3

Please sign in to comment.