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 14, 2024
1 parent 6227d2b commit 565320a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ if ENABLE_PAIRTAGHIGHLIGHTER
SUBDIRS += pairtaghighlighter
endif

if ENABLE_PINNER
SUBDIRS += pinner
endif

if ENABLE_POHELPER
SUBDIRS += pohelper
endif
Expand Down
9 changes: 9 additions & 0 deletions build/pinner.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AC_DEFUN([GP_CHECK_PINNER],
[
GP_ARG_DISABLE([pinner], [auto])
GP_COMMIT_PLUGIN_STATUS([Pinner])
AC_CONFIG_FILES([
pinner/Makefile
])
])
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ GP_CHECK_LIPSUM
GP_CHECK_MARKDOWN
GP_CHECK_OVERVIEW
GP_CHECK_PAIRTAGHIGHLIGHTER
GP_CHECK_PINNER
GP_CHECK_POHELPER
GP_CHECK_PRETTYPRINTER
GP_CHECK_PROJECTORGANIZER
Expand Down
25 changes: 25 additions & 0 deletions pinner/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include $(top_srcdir)/build/vars.build.mk

plugin = pinner

geanyplugins_LTLIBRARIES = pinner.la

pinner_la_SOURCES = \
pinner.c

pinner_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DG_LOG_DOMAIN=\"Pinner\"

pinner_la_CFLAGS = \
$(AM_CFLAGS) \
-fsanitize=address,undefined

pinner_la_LDFLAGS = \
$(AM_LDFLAGS) \
-fsanitize=address,undefined

pinner_la_LIBADD = \
$(COMMONLIBS)

AM_CPPCHECKFLAGS = -DSCE_PAS_DEFAULT=0
include $(top_srcdir)/build/cppcheck.mk
113 changes: 113 additions & 0 deletions pinner/pinner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* pinner.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;

struct pindata {
GeanyPlugin *plugin;
GSList *list;
};

static struct pindata *init_pindata(GeanyPlugin *plugin)
{
static struct pindata container = {
NULL,
NULL
};
return &container;
}

static void pin_activate_cb(GtkMenuItem *menuitem, gpointer pdata)
{
struct pindata *container = pdata;
GeanyPlugin *plugin = container->plugin;
GSList *list = container->list;

GeanyDocument *doc = document_get_current();
// Let's not add the pointer to the list, otherwise
// it won't be around when the function returns.
// We might find that it's better to store *doc to the list
// in which case we'll need to use malloc()
gchar tmp_file_name[strlen(doc->file_name) + 1];
strcpy(tmp_file_name, doc->file_name);

if (doc != NULL)
{
list = g_slist_append(list, tmp_file_name);
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;

struct pindata *container = init_pindata(plugin);
container->plugin = plugin;

// 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), container);

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);
}
3 changes: 3 additions & 0 deletions po/POTFILES.skip
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# geanyvc
geanyvc/src/commit.glade

# Pinner
pinner/pinner.c

# WebHelper
webhelper/src/gwh-enum-types.c

0 comments on commit 565320a

Please sign in to comment.