Skip to content

Commit

Permalink
Add Pinner plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Feb 13, 2024
1 parent 6227d2b commit 3d954c3
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pinner/pinner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* pin.c
*
* 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>

static GtkWidget *pinned_view_vbox;
static gint page_number = 0;


static void pin_activate_cb(GtkMenuItem *menuitem, gpointer pdata, GSList *pin_list)
{
GeanyPlugin *plugin = pdata;
GeanyDocument *doc = document_get_current();

if (doc != NULL && pin_list == NULL)
{
GtkWidget *label = gtk_label_new_with_mnemonic(doc->file_name);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(pinned_view_vbox), label, FALSE, FALSE, 0);
gtk_notebook_set_current_page(GTK_NOTEBOOK(plugin->geany_data->main_widgets->sidebar_notebook), page_number);
}
}


static gboolean pin_init(GeanyPlugin *plugin, gpointer pdata)
{
GtkWidget *main_menu_item;
GSList *pin_list = NULL;

// Create a new menu item and show it
main_menu_item = gtk_menu_item_new_with_mnemonic("Pin Document");
gtk_widget_show(main_menu_item);
gtk_container_add(GTK_CONTAINER(plugin->geany_data->main_widgets->tools_menu),
main_menu_item);
g_signal_connect(main_menu_item, "activate",
G_CALLBACK(pin_activate_cb), plugin, pin_list);

geany_plugin_set_data(plugin, main_menu_item, NULL);

pinned_view_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_show_all(pinned_view_vbox);
page_number = gtk_notebook_append_page(GTK_NOTEBOOK(plugin->geany_data->main_widgets->sidebar_notebook),
pinned_view_vbox, gtk_label_new(_("Pinned")));
return TRUE;
}


static void pin_cleanup(GeanyPlugin *plugin, gpointer pdata)
{
GtkWidget *main_menu_item = (GtkWidget *) pdata;

gtk_widget_destroy(main_menu_item);
}


G_MODULE_EXPORT
void geany_load_module(GeanyPlugin *plugin)
{
plugin->info->name = "Pinner";
plugin->info->description = "Pin a document";
plugin->info->version = "0.1.0";
plugin->info->author = "Andy Alt <[email protected]>";

plugin->funcs->init = pin_init;
plugin->funcs->cleanup = pin_cleanup;

GEANY_PLUGIN_REGISTER(plugin, 225);
}

0 comments on commit 3d954c3

Please sign in to comment.