lists.geany.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
List overview
Plugins-Commits
October 2014
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
plugins-commits@lists.geany.org
1 participants
98 discussions
Start a n
N
ew thread
[geany/geany-plugins] 84fa33: geanyctags: convert line ends from CRLF->LF
by Jiří Techet
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 20 Oct 2014 17:12:23 UTC Commit: 84fa336fc5fb757775d4bebada24cb6b6544a9d7
https://github.com/geany/geany-plugins/commit/84fa336fc5fb757775d4bebada24c…
Log Message: ----------- geanyctags: convert line ends from CRLF->LF WTF? Modified Paths: -------------- geanyctags/src/geanyctags.c Modified: geanyctags/src/geanyctags.c 1350 lines changed, 675 insertions(+), 675 deletions(-) =================================================================== @@ -1,675 +1,675 @@ -/* - * Copyright 2010-2014 Jiri Techet <techet(a)gmail.com> - * - * 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 <sys/time.h> -#include <string.h> - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <geanyplugin.h> - -#include "readtags.h" - -#include <errno.h> -#include <glib/gstdio.h> - -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <signal.h> - - -/* Pre-GTK 2.24 compatibility */ -#ifndef GTK_COMBO_BOX_TEXT -# define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX -# define gtk_combo_box_text_new gtk_combo_box_new_text -# define gtk_combo_box_text_append_text gtk_combo_box_append_text -#endif - - -PLUGIN_VERSION_CHECK(211) -PLUGIN_SET_INFO("GeanyCtags", - _("Ctags generation and search plugin for geany projects"), - VERSION, - "Jiri Techet <techet(a)gmail.com>") - -GeanyPlugin *geany_plugin; -GeanyData *geany_data; -GeanyFunctions *geany_functions; - - -static GtkWidget *s_context_fdec_item, *s_context_fdef_item, *s_context_sep_item, - *s_gt_item, *s_sep_item, *s_ft_item; - -static struct -{ - GtkWidget *widget; - - GtkWidget *combo; - GtkWidget *combo_match; - GtkWidget *case_sensitive; - GtkWidget *declaration; -} s_ft_dialog = {NULL, NULL, NULL, NULL, NULL}; - - -enum -{ - KB_FIND_TAG, - KB_GENERATE_TAGS, - KB_COUNT -}; - - - -void plugin_init(G_GNUC_UNUSED GeanyData * data); -void plugin_cleanup(void); - - -static void set_widgets_sensitive(gboolean sensitive) -{ - gtk_widget_set_sensitive(GTK_WIDGET(s_gt_item), sensitive); - gtk_widget_set_sensitive(GTK_WIDGET(s_context_fdec_item), sensitive); - gtk_widget_set_sensitive(GTK_WIDGET(s_context_fdef_item), sensitive); -} - -static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, G_GNUC_UNUSED gpointer user_data) -{ - set_widgets_sensitive(TRUE); -} - -static void on_project_close(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED gpointer user_data) -{ - set_widgets_sensitive(FALSE); -} - -static void on_project_save(G_GNUC_UNUSED GObject * obj, GKeyFile * config, G_GNUC_UNUSED gpointer user_data) -{ - set_widgets_sensitive(TRUE); -} - -PluginCallback plugin_callbacks[] = { - {"project-open", (GCallback) & on_project_open, TRUE, NULL}, - {"project-close", (GCallback) & on_project_close, TRUE, NULL}, - {"project-save", (GCallback) & on_project_save, TRUE, NULL}, - {NULL, NULL, FALSE, NULL} -}; - - -static void spawn_cmd(const gchar *cmd, const gchar *dir) -{ - GError *error = NULL; - gchar **argv; - gchar *working_dir; - gchar *utf8_working_dir; - gchar *utf8_cmd_string; - gchar *out; - gint exitcode; - gboolean success; - -#ifndef G_OS_WIN32 - /* run within shell so we can use pipes */ - argv = g_new0(gchar *, 4); - argv[0] = g_strdup("/bin/sh"); - argv[1] = g_strdup("-c"); - argv[2] = g_strdup(cmd); - argv[3] = NULL; -#else - /* no shell on windows */ - argv = g_new0(gchar *, 2); - argv[0] = g_strdup(cmd); - argv[1] = NULL; -#endif - - utf8_cmd_string = utils_get_utf8_from_locale(cmd); - utf8_working_dir = g_strdup(dir); - working_dir = utils_get_locale_from_utf8(utf8_working_dir); - - msgwin_clear_tab(MSG_MESSAGE); - msgwin_switch_tab(MSG_MESSAGE, TRUE); - msgwin_msg_add(COLOR_BLUE, -1, NULL, _("%s (in directory: %s)"), utf8_cmd_string, utf8_working_dir); - g_free(utf8_working_dir); - g_free(utf8_cmd_string); - -#ifndef G_OS_WIN32 - success = utils_spawn_sync(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, &out, &exitcode, &error); -#else - success = utils_spawn_sync(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, &out, NULL, &exitcode, &error); -#endif - if (!success || exitcode != 0) - { - if (error != NULL) - { - msgwin_msg_add(COLOR_RED, -1, NULL, _("Process execution failed (%s)"), error->message); - g_error_free(error); - } - msgwin_msg_add(COLOR_RED, -1, NULL, "%s", out); - } - else - { - msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", out); - } - - g_strfreev(argv); - g_free(working_dir); - g_free(out); -} - -static gchar *get_tags_filename(void) -{ - gchar *ret = NULL; - - if (geany_data->app->project) - { - ret = utils_remove_ext_from_filename(geany_data->app->project->file_name); - SETPTR(ret, g_strconcat(ret, ".tags", NULL)); - } - return ret; -} - -static gchar *generate_find_string(GeanyProject *prj) -{ - gchar *ret; - - ret = g_strdup("find . -not -path '*/\\.*'"); - - if (!EMPTY(prj->file_patterns)) - { - guint i; - - SETPTR(ret, g_strconcat(ret, " \\( -name \"", prj->file_patterns[0], "\"", NULL)); - for (i = 1; prj->file_patterns[i]; i++) - SETPTR(ret, g_strconcat(ret, " -o -name \"", prj->file_patterns[i], "\"", NULL)); - SETPTR(ret, g_strconcat(ret, " \\)", NULL)); - } - return ret; -} - - -static void -on_generate_tags(GtkMenuItem *menuitem, gpointer user_data) -{ - GeanyProject *prj; - - prj = geany_data->app->project; - if (prj) - { - gchar *cmd; - gchar *tag_filename; - - tag_filename = get_tags_filename(); - -#ifndef G_OS_WIN32 - gchar *find_string = generate_find_string(prj); - cmd = g_strconcat(find_string, - " | ctags --totals --fields=fKsSt --extra=-fq --c-kinds=+p --sort=foldcase --excmd=number -L - -f ", - tag_filename, NULL); - g_free(find_string); -#else - /* We don't have find and | on windows, generate tags for all files in the project (-R recursively) */ - - /* Unfortunately, there's a bug in ctags - when run with -R, the first line is - * empty, ctags doesn't recognize the tags file as a valid ctags file and - * refuses to overwrite it. Therefore, we need to delete the tags file manually. */ - g_unlink(tag_filename); - - cmd = g_strconcat("ctags.exe -R --totals --fields=fKsSt --extra=-fq --c-kinds=+p --sort=foldcase --excmd=number -f ", - tag_filename, NULL); -#endif - - spawn_cmd(cmd, prj->base_path); - - g_free(cmd); - g_free(tag_filename); - } -} - -static void show_entry(tagEntry *entry) -{ - const gchar *kind; - const gchar *signature; - const gchar *scope; - const gchar *file; - const gchar *name; - gchar *scope_str; - gchar *kind_str; - - file = entry->file; - if (!file) - file = ""; - - name = entry->name; - if (!name) - name = ""; - - signature = tagsField(entry, "signature"); - if (!signature) - signature = ""; - - scope = tagsField(entry, "class"); - if (!scope) - scope = tagsField(entry, "struct"); - if (!scope) - scope = tagsField(entry, "union"); - if (!scope) - scope = tagsField(entry, "enum"); - - if (scope) - scope_str = g_strconcat(scope, "::", NULL); - else - scope_str = g_strdup(""); - - kind = entry->kind; - if (kind) - { - kind_str = g_strconcat(kind, ": ", NULL); - SETPTR(kind_str, g_strdup_printf("%-14s", kind_str)); - } - else - kind_str = g_strdup(""); - - msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n %s%s%s%s", file, - entry->address.lineNumber, kind_str, scope_str, name, signature); - - g_free(scope_str); - g_free(kind_str); -} - - -static gchar *get_selection(void) -{ - gchar *ret = NULL; - GeanyDocument *doc = document_get_current(); - GeanyEditor *editor; - - if (!doc) - return NULL; - - editor = doc->editor; - - if (sci_has_selection(editor->sci)) - ret = sci_get_selection_contents(editor->sci); - else - ret = editor_get_word_at_pos(editor, -1, GEANY_WORDCHARS); - - return ret; -} - -/* TODO: Not possible to do it the way below because some of the API is private - * in Geany. This means the cursor has to be placed at the symbol first and - * then right-clicked (right-clicking without having the cursor at the symbol - * doesn't work) */ - -/* -static gchar *get_selection() -{ - gchar *ret = NULL; - GeanyDocument *doc = document_get_current(); - - if (!doc) - return NULL; - - if (!sci_has_selection(doc->editor->sci)) - sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE); - - if (sci_has_selection(doc->editor->sci)) - return sci_get_selection_contents(doc->editor->sci); - - gint len = sci_get_selected_text_length(doc->editor->sci); - - ret = g_malloc(len + 1); - sci_get_selected_text(doc->editor->sci, ret); - - editor_find_current_word(doc->editor, -1, - editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL); - - return editor_info.current_word != 0 ? g_strdup(editor_info.current_word) : NULL; -} -*/ - -typedef enum -{ - MATCH_FULL, - MATCH_PREFIX, - MATCH_PATTERN -} MatchType; - -static gboolean find_first(tagFile *tf, tagEntry *entry, const gchar *name, MatchType match_type) -{ - gboolean ret; - - if (match_type == MATCH_PATTERN) - ret = tagsFirst(tf, entry) == TagSuccess; - else - { - int options = TAG_IGNORECASE; - - options |= match_type == MATCH_PREFIX ? TAG_PARTIALMATCH : TAG_FULLMATCH; - ret = tagsFind(tf, entry, name, options) == TagSuccess; - } - return ret; -} - -static gboolean find_next(tagFile *tf, tagEntry *entry, MatchType match_type) -{ - gboolean ret; - - if (match_type == MATCH_PATTERN) - ret = tagsNext(tf, entry) == TagSuccess; - else - ret = tagsFindNext(tf, entry) == TagSuccess; - return ret; -} - -static gboolean filter_tag(tagEntry *entry, GPatternSpec *name, gboolean declaration, gboolean case_sensitive) -{ - gboolean filter = TRUE; - gchar *entry_name; - - if (!EMPTY(entry->kind)) - { - gboolean is_prototype; - - is_prototype = g_strcmp0(entry->kind, "prototype") == 0; - filter = (declaration && !is_prototype) || (!declaration && is_prototype); - if (filter) - return TRUE; - } - - if (case_sensitive) - entry_name = g_strdup(entry->name); - else - entry_name = g_utf8_strdown(entry->name, -1); - - filter = !g_pattern_match_string(name, entry_name); - - g_free(entry_name); - - return filter; -} - -static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type) -{ - tagFile *tf; - GeanyProject *prj; - gchar *tag_filename = NULL; - tagEntry entry; - tagFileInfo info; - - prj = geany_data->app->project; - if (!prj) - return; - - msgwin_clear_tab(MSG_MESSAGE); - msgwin_set_messages_dir(prj->base_path); - - tag_filename = get_tags_filename(); - tf = tagsOpen(tag_filename, &info); - - if (tf) - { - if (find_first(tf, &entry, name, match_type)) - { - GPatternSpec *name_pat; - gchar *name_case; - gchar *path = NULL; - gint num = 0; - - if (case_sensitive) - name_case = g_strdup(name); - else - name_case = g_utf8_strdown(name, -1); - - SETPTR(name_case, g_strconcat("*", name_case, "*", NULL)); - name_pat = g_pattern_spec_new(name_case); - - if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) - { - path = g_build_filename(prj->base_path, entry.file, NULL); - show_entry(&entry); - num++; - } - - while (find_next(tf, &entry, match_type)) - { - if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) - { - if (!path) - path = g_build_filename(prj->base_path, entry.file, NULL); - show_entry(&entry); - num++; - } - } - - if (num == 1) - { - GeanyDocument *doc = document_open_file(path, FALSE, NULL, NULL); - if (doc != NULL) - { - navqueue_goto_line(document_get_current(), doc, entry.address.lineNumber); - gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); - } - } - - g_pattern_spec_free(name_pat); - g_free(name_case); - g_free(path); - } - - tagsClose(tf); - } - - msgwin_switch_tab(MSG_MESSAGE, TRUE); - - g_free(tag_filename); -} - -static void on_find_declaration(GtkMenuItem *menuitem, gpointer user_data) -{ - gchar *name; - - name = get_selection(); - if (name) - find_tags(name, TRUE, TRUE, MATCH_FULL); - g_free(name); -} - -static void on_find_definition(GtkMenuItem *menuitem, gpointer user_data) -{ - gchar *name; - - name = get_selection(); - if (name) - find_tags(name, FALSE, TRUE, MATCH_FULL); - g_free(name); -} - -static void create_dialog_find_file(void) -{ - GtkWidget *label, *vbox, *ebox, *entry; - GtkSizeGroup *size_group; - - if (s_ft_dialog.widget) - return; - - s_ft_dialog.widget = gtk_dialog_new_with_buttons( - _("Find Tag"), GTK_WINDOW(geany->main_widgets->window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - gtk_dialog_add_button(GTK_DIALOG(s_ft_dialog.widget), "gtk-find", GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response(GTK_DIALOG(s_ft_dialog.widget), GTK_RESPONSE_ACCEPT); - - vbox = ui_dialog_vbox_new(GTK_DIALOG(s_ft_dialog.widget)); - gtk_box_set_spacing(GTK_BOX(vbox), 9); - - size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - - label = gtk_label_new(_("Search for:")); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_size_group_add_widget(size_group, label); - - s_ft_dialog.combo = gtk_combo_box_text_new_with_entry(); - entry = gtk_bin_get_child(GTK_BIN(s_ft_dialog.combo)); - - ui_entry_add_clear_icon(GTK_ENTRY(entry)); - gtk_entry_set_width_chars(GTK_ENTRY(entry), 40); - gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry); - ui_entry_add_clear_icon(GTK_ENTRY(entry)); - gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); - - ebox = gtk_hbox_new(FALSE, 6); - gtk_box_pack_start(GTK_BOX(ebox), label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(ebox), s_ft_dialog.combo, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(vbox), ebox, TRUE, FALSE, 0); - - label = gtk_label_new(_("Match type:")); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_size_group_add_widget(size_group, label); - - s_ft_dialog.combo_match = gtk_combo_box_text_new(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "full"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "prefix"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "pattern"); - gtk_combo_box_set_active(GTK_COMBO_BOX(s_ft_dialog.combo_match), 1); - gtk_label_set_mnemonic_widget(GTK_LABEL(label), s_ft_dialog.combo_match); - - ebox = gtk_hbox_new(FALSE, 6); - gtk_box_pack_start(GTK_BOX(ebox), label, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(ebox), s_ft_dialog.combo_match, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(vbox), ebox, TRUE, FALSE, 0); - - s_ft_dialog.case_sensitive = gtk_check_button_new_with_mnemonic(_("C_ase sensitive")); - gtk_button_set_focus_on_click(GTK_BUTTON(s_ft_dialog.case_sensitive), FALSE); - - s_ft_dialog.declaration = gtk_check_button_new_with_mnemonic(_("_Declaration")); - gtk_button_set_focus_on_click(GTK_BUTTON(s_ft_dialog.declaration), FALSE); - - g_object_unref(G_OBJECT(size_group)); /* auto destroy the size group */ - - gtk_container_add(GTK_CONTAINER(vbox), s_ft_dialog.case_sensitive); - gtk_container_add(GTK_CONTAINER(vbox), s_ft_dialog.declaration); - gtk_widget_show_all(vbox); -} - -static void on_find_tag(GtkMenuItem *menuitem, gpointer user_data) -{ - gchar *selection; - GtkWidget *entry; - - create_dialog_find_file(); - - entry = gtk_bin_get_child(GTK_BIN(s_ft_dialog.combo)); - - selection = get_selection(); - if (selection) - gtk_entry_set_text(GTK_ENTRY(entry), selection); - g_free(selection); - - gtk_widget_grab_focus(entry); - - if (gtk_dialog_run(GTK_DIALOG(s_ft_dialog.widget)) == GTK_RESPONSE_ACCEPT) - { - const gchar *name; - gboolean case_sensitive, declaration; - MatchType match_type; - - name = gtk_entry_get_text(GTK_ENTRY(entry)); - case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_ft_dialog.case_sensitive)); - declaration = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_ft_dialog.declaration)); - match_type = gtk_combo_box_get_active(GTK_COMBO_BOX(s_ft_dialog.combo_match)); - - ui_combo_box_add_to_history(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo), name, 0); - - find_tags(name, declaration, case_sensitive, match_type); - } - - gtk_widget_hide(s_ft_dialog.widget); -} - -static gboolean kb_callback(guint key_id) -{ - switch (key_id) - { - case KB_FIND_TAG: - on_find_tag(NULL, NULL); - return TRUE; - case KB_GENERATE_TAGS: - on_generate_tags(NULL, NULL); - return TRUE; - } - return FALSE; -} - -void plugin_init(G_GNUC_UNUSED GeanyData * data) -{ - GeanyKeyGroup *key_group = plugin_set_key_group(geany_plugin, "GeanyCtags", KB_COUNT, kb_callback); - - s_context_sep_item = gtk_separator_menu_item_new(); - gtk_widget_show(s_context_sep_item); - gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_sep_item); - - s_context_fdec_item = gtk_menu_item_new_with_mnemonic(_("Find Tag Declaration (geanyctags)")); - gtk_widget_show(s_context_fdec_item); - gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_fdec_item); - g_signal_connect((gpointer) s_context_fdec_item, "activate", G_CALLBACK(on_find_declaration), NULL); - - s_context_fdef_item = gtk_menu_item_new_with_mnemonic(_("Find Tag Definition (geanyctags)")); - gtk_widget_show(s_context_fdef_item); - gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_fdef_item); - g_signal_connect((gpointer) s_context_fdef_item, "activate", G_CALLBACK(on_find_definition), NULL); - - s_sep_item = gtk_separator_menu_item_new(); - gtk_widget_show(s_sep_item); - gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_sep_item); - - s_gt_item = gtk_menu_item_new_with_mnemonic(_("Generate tags")); - gtk_widget_show(s_gt_item); - gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_gt_item); - g_signal_connect((gpointer) s_gt_item, "activate", G_CALLBACK(on_generate_tags), NULL); - keybindings_set_item(key_group, KB_GENERATE_TAGS, NULL, - 0, 0, "generate_tags", _("Generate tags"), s_gt_item); - - s_ft_item = gtk_menu_item_new_with_mnemonic(_("Find tag")); - gtk_widget_show(s_ft_item); - gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_ft_item); - g_signal_connect((gpointer) s_ft_item, "activate", G_CALLBACK(on_find_tag), NULL); - keybindings_set_item(key_group, KB_FIND_TAG, NULL, - 0, 0, "find_tag", _("Find tag"), s_ft_item); - - set_widgets_sensitive(FALSE); -} - -void plugin_cleanup(void) -{ - gtk_widget_destroy(s_context_fdec_item); - gtk_widget_destroy(s_context_fdef_item); - gtk_widget_destroy(s_context_sep_item); - - gtk_widget_destroy(s_ft_item); - gtk_widget_destroy(s_gt_item); - gtk_widget_destroy(s_sep_item); - - if (s_ft_dialog.widget) - gtk_widget_destroy(s_ft_dialog.widget); - s_ft_dialog.widget = NULL; -} +/* + * Copyright 2010-2014 Jiri Techet <techet(a)gmail.com> + * + * 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 <sys/time.h> +#include <string.h> + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <geanyplugin.h> + +#include "readtags.h" + +#include <errno.h> +#include <glib/gstdio.h> + +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> +#include <sys/types.h> +#include <signal.h> + + +/* Pre-GTK 2.24 compatibility */ +#ifndef GTK_COMBO_BOX_TEXT +# define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX +# define gtk_combo_box_text_new gtk_combo_box_new_text +# define gtk_combo_box_text_append_text gtk_combo_box_append_text +#endif + + +PLUGIN_VERSION_CHECK(211) +PLUGIN_SET_INFO("GeanyCtags", + _("Ctags generation and search plugin for geany projects"), + VERSION, + "Jiri Techet <techet(a)gmail.com>") + +GeanyPlugin *geany_plugin; +GeanyData *geany_data; +GeanyFunctions *geany_functions; + + +static GtkWidget *s_context_fdec_item, *s_context_fdef_item, *s_context_sep_item, + *s_gt_item, *s_sep_item, *s_ft_item; + +static struct +{ + GtkWidget *widget; + + GtkWidget *combo; + GtkWidget *combo_match; + GtkWidget *case_sensitive; + GtkWidget *declaration; +} s_ft_dialog = {NULL, NULL, NULL, NULL, NULL}; + + +enum +{ + KB_FIND_TAG, + KB_GENERATE_TAGS, + KB_COUNT +}; + + + +void plugin_init(G_GNUC_UNUSED GeanyData * data); +void plugin_cleanup(void); + + +static void set_widgets_sensitive(gboolean sensitive) +{ + gtk_widget_set_sensitive(GTK_WIDGET(s_gt_item), sensitive); + gtk_widget_set_sensitive(GTK_WIDGET(s_context_fdec_item), sensitive); + gtk_widget_set_sensitive(GTK_WIDGET(s_context_fdef_item), sensitive); +} + +static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, G_GNUC_UNUSED gpointer user_data) +{ + set_widgets_sensitive(TRUE); +} + +static void on_project_close(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED gpointer user_data) +{ + set_widgets_sensitive(FALSE); +} + +static void on_project_save(G_GNUC_UNUSED GObject * obj, GKeyFile * config, G_GNUC_UNUSED gpointer user_data) +{ + set_widgets_sensitive(TRUE); +} + +PluginCallback plugin_callbacks[] = { + {"project-open", (GCallback) & on_project_open, TRUE, NULL}, + {"project-close", (GCallback) & on_project_close, TRUE, NULL}, + {"project-save", (GCallback) & on_project_save, TRUE, NULL}, + {NULL, NULL, FALSE, NULL} +}; + + +static void spawn_cmd(const gchar *cmd, const gchar *dir) +{ + GError *error = NULL; + gchar **argv; + gchar *working_dir; + gchar *utf8_working_dir; + gchar *utf8_cmd_string; + gchar *out; + gint exitcode; + gboolean success; + +#ifndef G_OS_WIN32 + /* run within shell so we can use pipes */ + argv = g_new0(gchar *, 4); + argv[0] = g_strdup("/bin/sh"); + argv[1] = g_strdup("-c"); + argv[2] = g_strdup(cmd); + argv[3] = NULL; +#else + /* no shell on windows */ + argv = g_new0(gchar *, 2); + argv[0] = g_strdup(cmd); + argv[1] = NULL; +#endif + + utf8_cmd_string = utils_get_utf8_from_locale(cmd); + utf8_working_dir = g_strdup(dir); + working_dir = utils_get_locale_from_utf8(utf8_working_dir); + + msgwin_clear_tab(MSG_MESSAGE); + msgwin_switch_tab(MSG_MESSAGE, TRUE); + msgwin_msg_add(COLOR_BLUE, -1, NULL, _("%s (in directory: %s)"), utf8_cmd_string, utf8_working_dir); + g_free(utf8_working_dir); + g_free(utf8_cmd_string); + +#ifndef G_OS_WIN32 + success = utils_spawn_sync(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, &out, &exitcode, &error); +#else + success = utils_spawn_sync(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, &out, NULL, &exitcode, &error); +#endif + if (!success || exitcode != 0) + { + if (error != NULL) + { + msgwin_msg_add(COLOR_RED, -1, NULL, _("Process execution failed (%s)"), error->message); + g_error_free(error); + } + msgwin_msg_add(COLOR_RED, -1, NULL, "%s", out); + } + else + { + msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", out); + } + + g_strfreev(argv); + g_free(working_dir); + g_free(out); +} + +static gchar *get_tags_filename(void) +{ + gchar *ret = NULL; + + if (geany_data->app->project) + { + ret = utils_remove_ext_from_filename(geany_data->app->project->file_name); + SETPTR(ret, g_strconcat(ret, ".tags", NULL)); + } + return ret; +} + +static gchar *generate_find_string(GeanyProject *prj) +{ + gchar *ret; + + ret = g_strdup("find . -not -path '*/\\.*'"); + + if (!EMPTY(prj->file_patterns)) + { + guint i; + + SETPTR(ret, g_strconcat(ret, " \\( -name \"", prj->file_patterns[0], "\"", NULL)); + for (i = 1; prj->file_patterns[i]; i++) + SETPTR(ret, g_strconcat(ret, " -o -name \"", prj->file_patterns[i], "\"", NULL)); + SETPTR(ret, g_strconcat(ret, " \\)", NULL)); + } + return ret; +} + + +static void +on_generate_tags(GtkMenuItem *menuitem, gpointer user_data) +{ + GeanyProject *prj; + + prj = geany_data->app->project; + if (prj) + { + gchar *cmd; + gchar *tag_filename; + + tag_filename = get_tags_filename(); + +#ifndef G_OS_WIN32 + gchar *find_string = generate_find_string(prj); + cmd = g_strconcat(find_string, + " | ctags --totals --fields=fKsSt --extra=-fq --c-kinds=+p --sort=foldcase --excmd=number -L - -f ", + tag_filename, NULL); + g_free(find_string); +#else + /* We don't have find and | on windows, generate tags for all files in the project (-R recursively) */ + + /* Unfortunately, there's a bug in ctags - when run with -R, the first line is + * empty, ctags doesn't recognize the tags file as a valid ctags file and + * refuses to overwrite it. Therefore, we need to delete the tags file manually. */ + g_unlink(tag_filename); + + cmd = g_strconcat("ctags.exe -R --totals --fields=fKsSt --extra=-fq --c-kinds=+p --sort=foldcase --excmd=number -f ", + tag_filename, NULL); +#endif + + spawn_cmd(cmd, prj->base_path); + + g_free(cmd); + g_free(tag_filename); + } +} + +static void show_entry(tagEntry *entry) +{ + const gchar *kind; + const gchar *signature; + const gchar *scope; + const gchar *file; + const gchar *name; + gchar *scope_str; + gchar *kind_str; + + file = entry->file; + if (!file) + file = ""; + + name = entry->name; + if (!name) + name = ""; + + signature = tagsField(entry, "signature"); + if (!signature) + signature = ""; + + scope = tagsField(entry, "class"); + if (!scope) + scope = tagsField(entry, "struct"); + if (!scope) + scope = tagsField(entry, "union"); + if (!scope) + scope = tagsField(entry, "enum"); + + if (scope) + scope_str = g_strconcat(scope, "::", NULL); + else + scope_str = g_strdup(""); + + kind = entry->kind; + if (kind) + { + kind_str = g_strconcat(kind, ": ", NULL); + SETPTR(kind_str, g_strdup_printf("%-14s", kind_str)); + } + else + kind_str = g_strdup(""); + + msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n %s%s%s%s", file, + entry->address.lineNumber, kind_str, scope_str, name, signature); + + g_free(scope_str); + g_free(kind_str); +} + + +static gchar *get_selection(void) +{ + gchar *ret = NULL; + GeanyDocument *doc = document_get_current(); + GeanyEditor *editor; + + if (!doc) + return NULL; + + editor = doc->editor; + + if (sci_has_selection(editor->sci)) + ret = sci_get_selection_contents(editor->sci); + else + ret = editor_get_word_at_pos(editor, -1, GEANY_WORDCHARS); + + return ret; +} + +/* TODO: Not possible to do it the way below because some of the API is private + * in Geany. This means the cursor has to be placed at the symbol first and + * then right-clicked (right-clicking without having the cursor at the symbol + * doesn't work) */ + +/* +static gchar *get_selection() +{ + gchar *ret = NULL; + GeanyDocument *doc = document_get_current(); + + if (!doc) + return NULL; + + if (!sci_has_selection(doc->editor->sci)) + sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE); + + if (sci_has_selection(doc->editor->sci)) + return sci_get_selection_contents(doc->editor->sci); + + gint len = sci_get_selected_text_length(doc->editor->sci); + + ret = g_malloc(len + 1); + sci_get_selected_text(doc->editor->sci, ret); + + editor_find_current_word(doc->editor, -1, + editor_info.current_word, GEANY_MAX_WORD_LENGTH, NULL); + + return editor_info.current_word != 0 ? g_strdup(editor_info.current_word) : NULL; +} +*/ + +typedef enum +{ + MATCH_FULL, + MATCH_PREFIX, + MATCH_PATTERN +} MatchType; + +static gboolean find_first(tagFile *tf, tagEntry *entry, const gchar *name, MatchType match_type) +{ + gboolean ret; + + if (match_type == MATCH_PATTERN) + ret = tagsFirst(tf, entry) == TagSuccess; + else + { + int options = TAG_IGNORECASE; + + options |= match_type == MATCH_PREFIX ? TAG_PARTIALMATCH : TAG_FULLMATCH; + ret = tagsFind(tf, entry, name, options) == TagSuccess; + } + return ret; +} + +static gboolean find_next(tagFile *tf, tagEntry *entry, MatchType match_type) +{ + gboolean ret; + + if (match_type == MATCH_PATTERN) + ret = tagsNext(tf, entry) == TagSuccess; + else + ret = tagsFindNext(tf, entry) == TagSuccess; + return ret; +} + +static gboolean filter_tag(tagEntry *entry, GPatternSpec *name, gboolean declaration, gboolean case_sensitive) +{ + gboolean filter = TRUE; + gchar *entry_name; + + if (!EMPTY(entry->kind)) + { + gboolean is_prototype; + + is_prototype = g_strcmp0(entry->kind, "prototype") == 0; + filter = (declaration && !is_prototype) || (!declaration && is_prototype); + if (filter) + return TRUE; + } + + if (case_sensitive) + entry_name = g_strdup(entry->name); + else + entry_name = g_utf8_strdown(entry->name, -1); + + filter = !g_pattern_match_string(name, entry_name); + + g_free(entry_name); + + return filter; +} + +static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type) +{ + tagFile *tf; + GeanyProject *prj; + gchar *tag_filename = NULL; + tagEntry entry; + tagFileInfo info; + + prj = geany_data->app->project; + if (!prj) + return; + + msgwin_clear_tab(MSG_MESSAGE); + msgwin_set_messages_dir(prj->base_path); + + tag_filename = get_tags_filename(); + tf = tagsOpen(tag_filename, &info); + + if (tf) + { + if (find_first(tf, &entry, name, match_type)) + { + GPatternSpec *name_pat; + gchar *name_case; + gchar *path = NULL; + gint num = 0; + + if (case_sensitive) + name_case = g_strdup(name); + else + name_case = g_utf8_strdown(name, -1); + + SETPTR(name_case, g_strconcat("*", name_case, "*", NULL)); + name_pat = g_pattern_spec_new(name_case); + + if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) + { + path = g_build_filename(prj->base_path, entry.file, NULL); + show_entry(&entry); + num++; + } + + while (find_next(tf, &entry, match_type)) + { + if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) + { + if (!path) + path = g_build_filename(prj->base_path, entry.file, NULL); + show_entry(&entry); + num++; + } + } + + if (num == 1) + { + GeanyDocument *doc = document_open_file(path, FALSE, NULL, NULL); + if (doc != NULL) + { + navqueue_goto_line(document_get_current(), doc, entry.address.lineNumber); + gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); + } + } + + g_pattern_spec_free(name_pat); + g_free(name_case); + g_free(path); + } + + tagsClose(tf); + } + + msgwin_switch_tab(MSG_MESSAGE, TRUE); + + g_free(tag_filename); +} + +static void on_find_declaration(GtkMenuItem *menuitem, gpointer user_data) +{ + gchar *name; + + name = get_selection(); + if (name) + find_tags(name, TRUE, TRUE, MATCH_FULL); + g_free(name); +} + +static void on_find_definition(GtkMenuItem *menuitem, gpointer user_data) +{ + gchar *name; + + name = get_selection(); + if (name) + find_tags(name, FALSE, TRUE, MATCH_FULL); + g_free(name); +} + +static void create_dialog_find_file(void) +{ + GtkWidget *label, *vbox, *ebox, *entry; + GtkSizeGroup *size_group; + + if (s_ft_dialog.widget) + return; + + s_ft_dialog.widget = gtk_dialog_new_with_buttons( + _("Find Tag"), GTK_WINDOW(geany->main_widgets->window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + gtk_dialog_add_button(GTK_DIALOG(s_ft_dialog.widget), "gtk-find", GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response(GTK_DIALOG(s_ft_dialog.widget), GTK_RESPONSE_ACCEPT); + + vbox = ui_dialog_vbox_new(GTK_DIALOG(s_ft_dialog.widget)); + gtk_box_set_spacing(GTK_BOX(vbox), 9); + + size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + + label = gtk_label_new(_("Search for:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_size_group_add_widget(size_group, label); + + s_ft_dialog.combo = gtk_combo_box_text_new_with_entry(); + entry = gtk_bin_get_child(GTK_BIN(s_ft_dialog.combo)); + + ui_entry_add_clear_icon(GTK_ENTRY(entry)); + gtk_entry_set_width_chars(GTK_ENTRY(entry), 40); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry); + ui_entry_add_clear_icon(GTK_ENTRY(entry)); + gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); + + ebox = gtk_hbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(ebox), label, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(ebox), s_ft_dialog.combo, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), ebox, TRUE, FALSE, 0); + + label = gtk_label_new(_("Match type:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_size_group_add_widget(size_group, label); + + s_ft_dialog.combo_match = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "full"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "prefix"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "pattern"); + gtk_combo_box_set_active(GTK_COMBO_BOX(s_ft_dialog.combo_match), 1); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), s_ft_dialog.combo_match); + + ebox = gtk_hbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(ebox), label, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(ebox), s_ft_dialog.combo_match, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), ebox, TRUE, FALSE, 0); + + s_ft_dialog.case_sensitive = gtk_check_button_new_with_mnemonic(_("C_ase sensitive")); + gtk_button_set_focus_on_click(GTK_BUTTON(s_ft_dialog.case_sensitive), FALSE); + + s_ft_dialog.declaration = gtk_check_button_new_with_mnemonic(_("_Declaration")); + gtk_button_set_focus_on_click(GTK_BUTTON(s_ft_dialog.declaration), FALSE); + + g_object_unref(G_OBJECT(size_group)); /* auto destroy the size group */ + + gtk_container_add(GTK_CONTAINER(vbox), s_ft_dialog.case_sensitive); + gtk_container_add(GTK_CONTAINER(vbox), s_ft_dialog.declaration); + gtk_widget_show_all(vbox); +} + +static void on_find_tag(GtkMenuItem *menuitem, gpointer user_data) +{ + gchar *selection; + GtkWidget *entry; + + create_dialog_find_file(); + + entry = gtk_bin_get_child(GTK_BIN(s_ft_dialog.combo)); + + selection = get_selection(); + if (selection) + gtk_entry_set_text(GTK_ENTRY(entry), selection); + g_free(selection); + + gtk_widget_grab_focus(entry); + + if (gtk_dialog_run(GTK_DIALOG(s_ft_dialog.widget)) == GTK_RESPONSE_ACCEPT) + { + const gchar *name; + gboolean case_sensitive, declaration; + MatchType match_type; + + name = gtk_entry_get_text(GTK_ENTRY(entry)); + case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_ft_dialog.case_sensitive)); + declaration = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_ft_dialog.declaration)); + match_type = gtk_combo_box_get_active(GTK_COMBO_BOX(s_ft_dialog.combo_match)); + + ui_combo_box_add_to_history(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo), name, 0); + + find_tags(name, declaration, case_sensitive, match_type); + } + + gtk_widget_hide(s_ft_dialog.widget); +} + +static gboolean kb_callback(guint key_id) +{ + switch (key_id) + { + case KB_FIND_TAG: + on_find_tag(NULL, NULL); + return TRUE; + case KB_GENERATE_TAGS: + on_generate_tags(NULL, NULL); + return TRUE; + } + return FALSE; +} + +void plugin_init(G_GNUC_UNUSED GeanyData * data) +{ + GeanyKeyGroup *key_group = plugin_set_key_group(geany_plugin, "GeanyCtags", KB_COUNT, kb_callback); + + s_context_sep_item = gtk_separator_menu_item_new(); + gtk_widget_show(s_context_sep_item); + gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_sep_item); + + s_context_fdec_item = gtk_menu_item_new_with_mnemonic(_("Find Tag Declaration (geanyctags)")); + gtk_widget_show(s_context_fdec_item); + gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_fdec_item); + g_signal_connect((gpointer) s_context_fdec_item, "activate", G_CALLBACK(on_find_declaration), NULL); + + s_context_fdef_item = gtk_menu_item_new_with_mnemonic(_("Find Tag Definition (geanyctags)")); + gtk_widget_show(s_context_fdef_item); + gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_fdef_item); + g_signal_connect((gpointer) s_context_fdef_item, "activate", G_CALLBACK(on_find_definition), NULL); + + s_sep_item = gtk_separator_menu_item_new(); + gtk_widget_show(s_sep_item); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_sep_item); + + s_gt_item = gtk_menu_item_new_with_mnemonic(_("Generate tags")); + gtk_widget_show(s_gt_item); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_gt_item); + g_signal_connect((gpointer) s_gt_item, "activate", G_CALLBACK(on_generate_tags), NULL); + keybindings_set_item(key_group, KB_GENERATE_TAGS, NULL, + 0, 0, "generate_tags", _("Generate tags"), s_gt_item); + + s_ft_item = gtk_menu_item_new_with_mnemonic(_("Find tag")); + gtk_widget_show(s_ft_item); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->project_menu), s_ft_item); + g_signal_connect((gpointer) s_ft_item, "activate", G_CALLBACK(on_find_tag), NULL); + keybindings_set_item(key_group, KB_FIND_TAG, NULL, + 0, 0, "find_tag", _("Find tag"), s_ft_item); + + set_widgets_sensitive(FALSE); +} + +void plugin_cleanup(void) +{ + gtk_widget_destroy(s_context_fdec_item); + gtk_widget_destroy(s_context_fdef_item); + gtk_widget_destroy(s_context_sep_item); + + gtk_widget_destroy(s_ft_item); + gtk_widget_destroy(s_gt_item); + gtk_widget_destroy(s_sep_item); + + if (s_ft_dialog.widget) + gtk_widget_destroy(s_ft_dialog.widget); + s_ft_dialog.widget = NULL; +} -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 48b3d4: geanyctags: Remove unnecessary trailing semicolons
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 20 Oct 2014 17:04:35 UTC Commit: 48b3d42f79e49988dfe596f4ef2c512cba6ef06c
https://github.com/geany/geany-plugins/commit/48b3d42f79e49988dfe596f4ef2c5…
Log Message: ----------- geanyctags: Remove unnecessary trailing semicolons Modified Paths: -------------- geanyctags/src/geanyctags.c Modified: geanyctags/src/geanyctags.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -38,11 +38,11 @@ #include <signal.h> -PLUGIN_VERSION_CHECK(211); +PLUGIN_VERSION_CHECK(211) PLUGIN_SET_INFO("GeanyCtags", _("Ctags generation and search plugin for geany projects"), VERSION, - "Jiri Techet <techet(a)gmail.com>"); + "Jiri Techet <techet(a)gmail.com>") GeanyPlugin *geany_plugin; GeanyData *geany_data; -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 1b764b: geanyctags: Use proper C prototypes for functions without arguments
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 20 Oct 2014 17:04:35 UTC Commit: 1b764ba86e2eb51a929f30a61a1144790a08a18c
https://github.com/geany/geany-plugins/commit/1b764ba86e2eb51a929f30a61a114…
Log Message: ----------- geanyctags: Use proper C prototypes for functions without arguments Modified Paths: -------------- geanyctags/src/geanyctags.c Modified: geanyctags/src/geanyctags.c 6 lines changed, 3 insertions(+), 3 deletions(-) =================================================================== @@ -167,7 +167,7 @@ static void spawn_cmd(const gchar *cmd, const gchar *dir) g_free(out); } -static gchar *get_tags_filename() +static gchar *get_tags_filename(void) { gchar *ret = NULL; @@ -288,7 +288,7 @@ static void show_entry(tagEntry *entry) } -static gchar *get_selection() +static gchar *get_selection(void) { gchar *ret = NULL; GeanyDocument *doc = document_get_current(); @@ -496,7 +496,7 @@ static void on_find_definition(GtkMenuItem *menuitem, gpointer user_data) g_free(name); } -static void create_dialog_find_file() +static void create_dialog_find_file(void) { GtkWidget *label, *vbox, *ebox, *entry; GtkSizeGroup *size_group; -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 4a2f4b: geanyctags: Fix GTK3 compatibility
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 20 Oct 2014 17:04:35 UTC Commit: 4a2f4b1fff33e53e08b368b1d185926a4826ec8a
https://github.com/geany/geany-plugins/commit/4a2f4b1fff33e53e08b368b1d1859…
Log Message: ----------- geanyctags: Fix GTK3 compatibility Modified Paths: -------------- geanyctags/src/geanyctags.c Modified: geanyctags/src/geanyctags.c 16 lines changed, 12 insertions(+), 4 deletions(-) =================================================================== @@ -38,6 +38,14 @@ #include <signal.h> +/* Pre-GTK 2.24 compatibility */ +#ifndef GTK_COMBO_BOX_TEXT +# define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX +# define gtk_combo_box_text_new gtk_combo_box_new_text +# define gtk_combo_box_text_append_text gtk_combo_box_append_text +#endif + + PLUGIN_VERSION_CHECK(211) PLUGIN_SET_INFO("GeanyCtags", _("Ctags generation and search plugin for geany projects"), @@ -538,10 +546,10 @@ static void create_dialog_find_file(void) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_size_group_add_widget(size_group, label); - s_ft_dialog.combo_match = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(s_ft_dialog.combo_match), "full"); - gtk_combo_box_append_text(GTK_COMBO_BOX(s_ft_dialog.combo_match), "prefix"); - gtk_combo_box_append_text(GTK_COMBO_BOX(s_ft_dialog.combo_match), "pattern"); + s_ft_dialog.combo_match = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "full"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "prefix"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo_match), "pattern"); gtk_combo_box_set_active(GTK_COMBO_BOX(s_ft_dialog.combo_match), 1); gtk_label_set_mnemonic_widget(GTK_LABEL(label), s_ft_dialog.combo_match); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 4bec45: geanyctags: Add a missing initializer
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 20 Oct 2014 17:04:35 UTC Commit: 4bec454d347c9a452c4453d2de6c8c33bf08544e
https://github.com/geany/geany-plugins/commit/4bec454d347c9a452c4453d2de6c8…
Log Message: ----------- geanyctags: Add a missing initializer Modified Paths: -------------- geanyctags/src/geanyctags.c Modified: geanyctags/src/geanyctags.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -60,7 +60,7 @@ static struct GtkWidget *combo_match; GtkWidget *case_sensitive; GtkWidget *declaration; -} s_ft_dialog = {NULL, NULL, NULL, NULL}; +} s_ft_dialog = {NULL, NULL, NULL, NULL, NULL}; enum -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] e233f5: Merge pull request #169 from b4n/xmlsnippets/use-tests
by Frank Lanitz
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Frank Lanitz <frank(a)frank.uvena.de> Committer: Frank Lanitz <frank(a)frank.uvena.de> Date: Mon, 20 Oct 2014 16:22:26 UTC Commit: e233f5fd3e6b3738d193f4acfda007739159951f
https://github.com/geany/geany-plugins/commit/e233f5fd3e6b3738d193f4acfda00…
Log Message: ----------- Merge pull request #169 from b4n/xmlsnippets/use-tests xmlsnippets: Build and run tests Modified Paths: -------------- xmlsnippets/src/Makefile.am Modified: xmlsnippets/src/Makefile.am 14 lines changed, 12 insertions(+), 2 deletions(-) =================================================================== @@ -2,12 +2,22 @@ include $(top_srcdir)/build/vars.build.mk geanyplugins_LTLIBRARIES = xmlsnippets.la +check_PROGRAMS = xmlsnippets-check + +common_sources = xmlsnippets.c xmlsnippets.h + xmlsnippets_la_SOURCES = \ plugin.c plugin.h \ + $(common_sources) + +xmlsnippets_la_LIBADD = $(COMMONLIBS) + +xmlsnippets_check_SOURCES = \ tests.c \ test-stubs.c test-stubs.h \ - xmlsnippets.c xmlsnippets.h + $(common_sources) -xmlsnippets_la_LIBADD = $(COMMONLIBS) +xmlsnippets_check_CPPFLAGS = -DTEST +xmlsnippets_check_LDADD = $(COMMONLIBS) include $(top_srcdir)/build/cppcheck.mk -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 89a0a7: geanypg: Simplify string building a lot
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Colomban Wendling <ban(a)herbesfolles.org> Date: Mon, 20 Oct 2014 15:49:36 UTC Commit: 89a0a7bc5a1ec007e0897ec39a433e7ca88af4ef
https://github.com/geany/geany-plugins/commit/89a0a7bc5a1ec007e0897ec39a433…
Log Message: ----------- geanypg: Simplify string building a lot Use `g_strdup_printf()` instead of manually computing the string size and then `sprintf()` in it. This makes the code a lot simpler and less likely to break when changed as there is no more error-prone code duplication. Also, fix the size passed to `strncpy()` to make sure the strings are always properly nul-terminated. Modified Paths: -------------- geanypg/src/verify_aux.c Modified: geanypg/src/verify_aux.c 60 lines changed, 19 insertions(+), 41 deletions(-) =================================================================== @@ -90,58 +90,37 @@ static char * geanypg_summary(gpgme_sigsum_t summary, char * buffer) return buffer; } -static char * geanypg_result(gpgme_signature_t sig) +static gchar * geanypg_result(gpgme_signature_t sig) { - char * format = - _("status ....: %s\n" - "summary ...:%s\n" - "fingerprint: %s\n" - "created ...: %s" - "expires ...: %s" - "validity ..: %s\n" - "val.reason : %s\n" - "pubkey algo: %s\n" - "digest algo: %s\n" - "pka address: %s\n" - "pka trust .: %s\n" - "other flags:%s%s\n" - "notations .: %s\n"); - char * buffer; char summary[128] = {0}; const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo); const char * hash = gpgme_hash_algo_name(sig->hash_algo); char created[64] = {0}; char expires[64] = {0}; - size_t buffer_size; if (sig->timestamp) - strncpy(created, ctime((time_t*)&sig->timestamp), 64); + strncpy(created, ctime((time_t*)&sig->timestamp), sizeof(created) - 1); else strcpy(created, _("Unknown\n")); if (sig->exp_timestamp) - strncpy(expires, ctime((time_t*)&sig->exp_timestamp), 64); + strncpy(expires, ctime((time_t*)&sig->exp_timestamp), sizeof(expires) - 1); else strcpy(expires, _("Unknown\n")); - buffer_size = strlen(format) + - strlen(gpgme_strerror(sig->status)) + - strlen(geanypg_summary(sig->summary, summary)) + - strlen(sig->fpr ? sig->fpr : _("[None]")) + - strlen(created) + - strlen(expires) + - strlen(geanypg_validity(sig->validity)) + - strlen(gpgme_strerror(sig->status)) + - strlen(pubkey ? pubkey : _("Unknown")) + - strlen(hash ? hash : _("Unknown")) + - strlen(sig->pka_address ? sig->pka_address : _("[None]")) + - strlen(sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU")) + - strlen(sig->wrong_key_usage ? _(" wrong-key-usage") : "") + - strlen(sig->chain_model ? _(" chain-model") : "") + - strlen(sig->notations ? _("yes") : _("no")) + 1; /* and a trailing \0 */ - - buffer = (char *)calloc(buffer_size, 1); - memset(summary, 0, 128); - sprintf(buffer, format, + return g_strdup_printf( + _("status ....: %s\n" + "summary ...:%s\n" + "fingerprint: %s\n" + "created ...: %s" + "expires ...: %s" + "validity ..: %s\n" + "val.reason : %s\n" + "pubkey algo: %s\n" + "digest algo: %s\n" + "pka address: %s\n" + "pka trust .: %s\n" + "other flags:%s%s\n" + "notations .: %s\n"), gpgme_strerror(sig->status), geanypg_summary(sig->summary, summary), sig->fpr ? sig->fpr : _("[None]"), @@ -155,13 +134,12 @@ static char * geanypg_result(gpgme_signature_t sig) sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU"), sig->wrong_key_usage ? _(" wrong-key-usage") : "", sig->chain_model ? _(" chain-model") : "", sig->notations ? _("yes") : _("no")); - return buffer; } void geanypg_check_sig(encrypt_data * ed, gpgme_signature_t sig) { GtkWidget * dialog; char buffer[512] = {0}; - char * result; + gchar * result; strncpy(buffer, sig->fpr, 40); buffer[40] = 0; geanypg_get_keys_with_fp(ed, buffer); @@ -178,7 +156,7 @@ void geanypg_check_sig(encrypt_data * ed, gpgme_signature_t sig) gtk_window_set_title(GTK_WINDOW(dialog), _("Signature")); gtk_dialog_run(GTK_DIALOG(dialog)); - free(result); + g_free(result); gtk_widget_destroy(dialog); } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] ef7892: xmlsnippets: Build and run tests
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Colomban Wendling <ban(a)herbesfolles.org> Date: Mon, 20 Oct 2014 15:41:39 UTC Commit: ef78921ee60d231c4114ba73365c5b85fdfbdd09
https://github.com/geany/geany-plugins/commit/ef78921ee60d231c4114ba73365c5…
Log Message: ----------- xmlsnippets: Build and run tests Modified Paths: -------------- xmlsnippets/src/Makefile.am Modified: xmlsnippets/src/Makefile.am 14 lines changed, 12 insertions(+), 2 deletions(-) =================================================================== @@ -2,12 +2,22 @@ include $(top_srcdir)/build/vars.build.mk geanyplugins_LTLIBRARIES = xmlsnippets.la +check_PROGRAMS = xmlsnippets-check + +common_sources = xmlsnippets.c xmlsnippets.h + xmlsnippets_la_SOURCES = \ plugin.c plugin.h \ + $(common_sources) + +xmlsnippets_la_LIBADD = $(COMMONLIBS) + +xmlsnippets_check_SOURCES = \ tests.c \ test-stubs.c test-stubs.h \ - xmlsnippets.c xmlsnippets.h + $(common_sources) -xmlsnippets_la_LIBADD = $(COMMONLIBS) +xmlsnippets_check_CPPFLAGS = -DTEST +xmlsnippets_check_LDADD = $(COMMONLIBS) include $(top_srcdir)/build/cppcheck.mk -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 55bd84: codenav: Fix signed vs. unsigned comparisons
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Colomban Wendling <ban(a)herbesfolles.org> Date: Mon, 20 Oct 2014 15:35:39 UTC Commit: 55bd845b9593fe7312028b6b548d78a407722124
https://github.com/geany/geany-plugins/commit/55bd845b9593fe7312028b6b548d7…
Log Message: ----------- codenav: Fix signed vs. unsigned comparisons Modified Paths: -------------- codenav/src/codenavigation.c codenav/src/switch_head_impl.c Modified: codenav/src/codenavigation.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -120,7 +120,7 @@ static void load_configuration(void) gchar *config_filename = NULL; gchar **impl_list = NULL, **head_list = NULL; gsize head_list_len, impl_list_len; - int i; + gsize i; /* Load user configuration */ config = g_key_file_new(); @@ -220,7 +220,7 @@ void plugin_cleanup(void) static void on_configure_response(GtkDialog* dialog, gint response, gpointer user_data) { - gint i=0; + gsize i=0; GKeyFile *config = NULL; gchar *config_filename = NULL; Modified: codenav/src/switch_head_impl.c 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -141,7 +141,8 @@ fill_languages_list(const gchar** impl_list, const gchar** head_list, gsize n) { gchar **splitted_list; Language* lang = NULL; - gint i, j; + gsize i; + guint j; languages_clean(); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 2a3aca: codenav: Use proper C prototypes for functions without arguments
by Colomban Wendling
20 Oct '14
20 Oct '14
Branch: refs/heads/master Author: Colomban Wendling <ban(a)herbesfolles.org> Committer: Colomban Wendling <ban(a)herbesfolles.org> Date: Mon, 20 Oct 2014 15:35:24 UTC Commit: 2a3acacbb9d0403ad9617aa7fb37762a2fc08356
https://github.com/geany/geany-plugins/commit/2a3acacbb9d0403ad9617aa7fb377…
Log Message: ----------- codenav: Use proper C prototypes for functions without arguments Modified Paths: -------------- codenav/src/codenavigation.c codenav/src/switch_head_impl.c codenav/src/switch_head_impl.h Modified: codenav/src/codenavigation.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -74,7 +74,7 @@ GtkWidget* config_widget(void); static void -load_configuration(); +load_configuration(void); static void on_configure_add_language(GtkWidget* widget, gpointer data); @@ -114,7 +114,7 @@ void plugin_init(GeanyData *data) * @return void * */ -static void load_configuration() +static void load_configuration(void) { GKeyFile *config = NULL; gchar *config_filename = NULL; Modified: codenav/src/switch_head_impl.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -440,7 +440,7 @@ menu_item_activate(guint key_id) * @return GSList* languages list * */ -GSList* switch_head_impl_get_languages() +GSList* switch_head_impl_get_languages(void) { return languages; } Modified: codenav/src/switch_head_impl.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -51,7 +51,7 @@ fill_languages_list(const gchar**, const gchar**, gsize); -GSList* switch_head_impl_get_languages(); +GSList* switch_head_impl_get_languages(void); #endif /* SWITCH_HEAD_IMPL_H */ -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
← Newer
1
2
3
4
5
6
7
8
9
10
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
Results per page:
10
25
50
100
200