From b3cb294f589d7cd6651f6faaf58f0d7964c2df4b Mon Sep 17 00:00:00 2001 From: Frank Lanitz Date: Sun, 6 Oct 2019 13:21:53 +0200 Subject: [PATCH] Tableconvert: Disable menu general menu item in case of unsupported file type Fixes #915 --- tableconvert/src/tableconvert.c | 44 ++++++++++++++++++++++++++++-- tableconvert/src/tableconvert.h | 4 +-- tableconvert/src/tableconvert_ui.c | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/tableconvert/src/tableconvert.c b/tableconvert/src/tableconvert.c index b526e326c..d425db09c 100644 --- a/tableconvert/src/tableconvert.c +++ b/tableconvert/src/tableconvert.c @@ -1,7 +1,7 @@ /* * tableconvert.c * - * Copyright 2011-2015 Frank Lanitz + * Copyright 2011-2019 Frank Lanitz * * 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 @@ -35,6 +35,21 @@ PLUGIN_SET_TRANSLATABLE_INFO( GeanyPlugin *geany_plugin; GeanyData *geany_data; + +static void convert_to_table(gboolean header, gint file_type); +static void set_activate_state(); + +PluginCallback plugin_callbacks[] = +{ + { "editor-notify", (GCallback) &cb_table_convert_change_document, FALSE, NULL }, + { "document-activate", (GCallback) &cb_table_convert_change_document, FALSE, NULL }, + { "document-filetype-set", (GCallback) &cb_table_convert_change_document, FALSE, NULL }, + { "document-new", (GCallback) &cb_table_convert_change_document, FALSE, NULL}, + { "document-close", (GCallback) &cb_table_convert_change_document, FALSE, NULL}, + { NULL, NULL, FALSE, NULL } +}; + + TableConvertRule tablerules[] = { /* LaTeX */ { @@ -306,7 +321,7 @@ void convert_to_table(gboolean header, gint file_type) g_strfreev(rows); g_free(replacement); } - /* in case of there was no selection we are just doing nothing */ + /* in case of there was no selection we are just doing nothing */ return; } @@ -338,6 +353,31 @@ void cb_table_convert_type(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp convert_to_table(TRUE, GPOINTER_TO_INT(gdata)); } +void cb_table_convert_change_document(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) +{ + set_activate_state(); +} + +void set_activate_state() +{ + // getting document + GeanyDocument *doc = NULL; + doc = document_get_current(); + + if ( + doc != NULL && ( + doc->file_type->id == GEANY_FILETYPES_HTML || + doc->file_type->id == GEANY_FILETYPES_LATEX || + doc->file_type->id == GEANY_FILETYPES_SQL)) + { + gtk_widget_set_sensitive(main_menu_item, TRUE); + } + else + { + gtk_widget_set_sensitive(main_menu_item, FALSE); + } +} + void plugin_init(GeanyData *data) { init_keybindings(); diff --git a/tableconvert/src/tableconvert.h b/tableconvert/src/tableconvert.h index a7f9e4e6d..909c19a6b 100644 --- a/tableconvert/src/tableconvert.h +++ b/tableconvert/src/tableconvert.h @@ -27,7 +27,7 @@ #include #include - +#include extern GeanyPlugin *geany_plugin; extern GeanyData *geany_data; @@ -70,6 +70,6 @@ extern TableConvertRule tablerules[]; extern void cb_table_convert(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata); extern void cb_table_convert_type(G_GNUC_UNUSED GtkMenuItem *menuitem, gpointer gdata); -extern void convert_to_table(gboolean header, gint file_type); +extern void cb_table_convert_change_document(G_GNUC_UNUSED GtkMenuItem *menuitem, gpointer gdata); #endif diff --git a/tableconvert/src/tableconvert_ui.c b/tableconvert/src/tableconvert_ui.c index a87a0faca..ff2e88548 100644 --- a/tableconvert/src/tableconvert_ui.c +++ b/tableconvert/src/tableconvert_ui.c @@ -1,7 +1,7 @@ /* * tableconvert_ui.c * - * Copyright 2014 Frank Lanitz + * Copyright 2014-2019 Frank Lanitz * * 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