Revision: 2071 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2071&view=re... Author: codebrainz Date: 2011-05-23 00:20:26 +0000 (Mon, 23 May 2011)
Log Message: ----------- Add support for search Google Code.
Modified Paths: -------------- trunk/geany-plugins/devhelp/src/Makefile.am trunk/geany-plugins/devhelp/src/devhelpplugin.c trunk/geany-plugins/devhelp/src/devhelpplugin.h
Added Paths: ----------- trunk/geany-plugins/devhelp/src/codesearch.c trunk/geany-plugins/devhelp/src/codesearch.h
Modified: trunk/geany-plugins/devhelp/src/Makefile.am =================================================================== --- trunk/geany-plugins/devhelp/src/Makefile.am 2011-05-22 22:28:24 UTC (rev 2070) +++ trunk/geany-plugins/devhelp/src/Makefile.am 2011-05-23 00:20:26 UTC (rev 2071) @@ -13,7 +13,8 @@ main-notebook.c \ devhelpplugin.c \ plugin.c \ - manpages.c + manpages.c \ + codesearch.c
noinst_HEADERS = \ plugin.h \
Added: trunk/geany-plugins/devhelp/src/codesearch.c =================================================================== --- trunk/geany-plugins/devhelp/src/codesearch.c (rev 0) +++ trunk/geany-plugins/devhelp/src/codesearch.c 2011-05-23 00:20:26 UTC (rev 2071) @@ -0,0 +1,97 @@ +#include <glib.h> +#include <webkit/webkitwebview.h> + +#include "devhelpplugin.h" +#include "codesearch.h" + + +struct LangMapEnt +{ + const gchar *geany_name; + const gchar *google_name; +}; + + +#define GOOGLE_CODE_SEARCH_URI "http://www.google.com/codesearch" + +#define LANG_MAP_MAX 33 /* update this with lang_map[] size below */ + +/* maps Geany language names to Google Code language names */ +static const struct LangMapEnt lang_map[LANG_MAP_MAX] = { + { "ActionScript", "actionscript" }, + { "Ada", "ada" }, + { "ASM", "assembly" }, + { "FreeBasic", "basic" }, + { "C", "c" }, + { "C++", "c++" }, + { "C#", "c#" }, + { "COBOL", "cobol" }, + { "CSS", "css" }, + { "D", "d" }, + { "Erlang", "erlang" }, + { "Fortran", "fortran" }, + { "Haskell", "haskell" }, + { "Java", "java" }, + { "Javascript", "javascript" }, + { "Lisp", "lisp" }, + { "Lua", "lua" }, + { "Make", "makefile" }, + { "Matlab/Octave", "matlab" }, + { "CAML", "ocaml" }, + { "Pascal", "pascal" }, + { "Perl", "perl" }, + { "PHP", "php" }, + { "Python", "python" }, + { "R", "r" }, + { "Ruby", "ruby" }, + { "Sh", "shell" }, + { "SQL", "sql" }, + { "Tcl", "tcl" }, + { "LaTeX", "tex" }, + { "Verilog", "verilog" }, + { "VHDL", "vhdl" }, + { "None", NULL } +}; + + +void devhelp_plugin_search_code(DevhelpPlugin *self, const gchar *term, const gchar *lang) +{ + gint i; + gchar *uri, *term_enc, *lang_enc; + const gchar *google_lang = NULL; + + g_return_if_fail(self != NULL); + g_return_if_fail(term != NULL); + + if (lang != NULL) + { + for (i = 0; i < LANG_MAP_MAX; i++) + { + if (g_strcmp0(lang, lang_map[i].geany_name) == 0) + { + google_lang = lang_map[i].google_name; + break; + } + } + } + + if (google_lang != NULL) + { + lang_enc = g_uri_escape_string(google_lang, NULL, TRUE); + term_enc = g_uri_escape_string(term, NULL, TRUE); + uri = g_strdup_printf("%s?as_q=%s&as_lang=%s", GOOGLE_CODE_SEARCH_URI, term_enc, lang_enc); + g_free(lang_enc); + g_free(term_enc); + } + else + { + term_enc = g_uri_escape_string(term, NULL, TRUE); + uri = g_strdup_printf("%s?as_q=%s", GOOGLE_CODE_SEARCH_URI, term_enc); + g_free(term_enc); + } + + webkit_web_view_open(devhelp_plugin_get_webview(self), uri); + g_free(uri); + + devhelp_plugin_activate_webview_tab(self); +}
Added: trunk/geany-plugins/devhelp/src/codesearch.h =================================================================== --- trunk/geany-plugins/devhelp/src/codesearch.h (rev 0) +++ trunk/geany-plugins/devhelp/src/codesearch.h 2011-05-23 00:20:26 UTC (rev 2071) @@ -0,0 +1,39 @@ +/* + * codesearch.h + * + * Copyright 2011 Matthew Brush mbrush@desktop + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + * + */ + +#ifndef CODESEARCH_H +#define CODESEARCH_H +#ifdef __cplusplus +extern "C" { +#endif + +#include <glib.h> +#include "devhelpplugin.h" + + +void devhelp_plugin_search_code(DevhelpPlugin *self, const gchar *term, const gchar *lang); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif +#endif /* CODESEARCH_H */
Modified: trunk/geany-plugins/devhelp/src/devhelpplugin.c =================================================================== --- trunk/geany-plugins/devhelp/src/devhelpplugin.c 2011-05-22 22:28:24 UTC (rev 2070) +++ trunk/geany-plugins/devhelp/src/devhelpplugin.c 2011-05-23 00:20:26 UTC (rev 2071) @@ -37,6 +37,7 @@ #include "devhelpplugin.h" #include "plugin.h" #include "manpages.h" +#include "codesearch.h"
struct _DevhelpPluginPrivate @@ -52,7 +53,6 @@ * and webkit view */ GtkWidget* doc_notebook; /* Geany's document notebook */ GtkWidget* editor_menu_item; /* Item in the editor's context menu */ - GtkWidget* editor_man_menu_item; /* Manpage search menu item in the editor's context menu */ GtkWidget* editor_menu_sep; /* Separator item above menu item */ gboolean webview_active; /* Tracks whether webview stuff is shown */ gboolean last_main_tab_id; /* These track the last id of the tabs */ @@ -83,6 +83,7 @@ /* Internal callbacks */ static void on_search_help_activate(GtkMenuItem * menuitem, DevhelpPlugin *self); static void on_search_help_man_activate(GtkMenuItem * menuitem, DevhelpPlugin *self); +static void on_search_help_code_activate(GtkMenuItem *menuitem, DevhelpPlugin *self); static void on_editor_menu_popup(GtkWidget * widget, DevhelpPlugin *self); static void on_link_clicked(GObject * ignored, DhLink * dhlink, DevhelpPlugin *self); static void on_back_button_clicked(GtkToolButton * btn, DevhelpPlugin *self); @@ -118,7 +119,6 @@ } gtk_widget_destroy(self->priv->editor_menu_sep); gtk_widget_destroy(self->priv->editor_menu_item); - gtk_widget_destroy(self->priv->editor_man_menu_item);
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook), self->priv->orig_sb_tab_pos); @@ -180,6 +180,7 @@ /* Initialize the stuff in the editor's context menu */ static void devhelp_plugin_init_edit_menu(DevhelpPlugin *self) { + GtkWidget *doc_menu, *devhelp_item, *man_item, *code_item; DevhelpPluginPrivate *p;
g_return_if_fail(self != NULL); @@ -187,20 +188,33 @@ p = self->priv;
p->editor_menu_sep = gtk_separator_menu_item_new(); - p->editor_menu_item = gtk_menu_item_new_with_label(_("Search Devhelp for Tag")); - p->editor_man_menu_item = gtk_menu_item_new_with_label(_("Search manual pages for Tag")); + p->editor_menu_item = gtk_menu_item_new_with_label(_("Search for 'Tag' Documentation in")); + doc_menu = gtk_menu_new();
+ devhelp_item = gtk_menu_item_new_with_label(_("Devhelp")); + man_item = gtk_menu_item_new_with_label(_("Manual Pages")); + code_item = gtk_menu_item_new_with_label(_("Google Code")); + + gtk_menu_shell_append(GTK_MENU_SHELL(doc_menu), devhelp_item); + gtk_menu_shell_append(GTK_MENU_SHELL(doc_menu), man_item); + gtk_menu_shell_append(GTK_MENU_SHELL(doc_menu), code_item); + g_signal_connect(geany->main_widgets->editor_menu, "show", G_CALLBACK(on_editor_menu_popup), self); - g_signal_connect(p->editor_menu_item, "activate", G_CALLBACK(on_search_help_activate), self); - g_signal_connect(p->editor_man_menu_item, "activate", G_CALLBACK(on_search_help_man_activate), self); + g_signal_connect(devhelp_item, "activate", G_CALLBACK(on_search_help_activate), self); + g_signal_connect(man_item, "activate", G_CALLBACK(on_search_help_man_activate), self); + g_signal_connect(code_item, "activate", G_CALLBACK(on_search_help_code_activate), self);
+ gtk_widget_show(p->editor_menu_sep); + gtk_widget_show(devhelp_item); + gtk_widget_show(man_item); + gtk_widget_show(code_item); + + gtk_menu_item_set_submenu(GTK_MENU_ITEM(p->editor_menu_item), doc_menu); + gtk_widget_show_all(p->editor_menu_item); + gtk_menu_shell_append(GTK_MENU_SHELL(geany->main_widgets->editor_menu), p->editor_menu_sep); gtk_menu_shell_append(GTK_MENU_SHELL(geany->main_widgets->editor_menu), p->editor_menu_item); - gtk_menu_shell_append(GTK_MENU_SHELL(geany->main_widgets->editor_menu), p->editor_man_menu_item);
- gtk_widget_show(p->editor_menu_sep); - gtk_widget_show(p->editor_menu_item); - gtk_widget_show(p->editor_man_menu_item); }
@@ -384,7 +398,7 @@
g_free(man_fn);
- devhelp_plugin_activate_all_tabs(self); + devhelp_plugin_activate_webview_tab(self); }
@@ -665,6 +679,13 @@ }
+WebKitWebView* devhelp_plugin_get_webview(DevhelpPlugin *self) +{ + g_return_val_if_fail(self != NULL, NULL); + return WEBKIT_WEB_VIEW(self->priv->webview); +} + + /* Activates (brings to top/makes visible) the Devhelp plugin's sidebar tab. */ static inline void devhelp_plugin_activate_sidebar_tab(DevhelpPlugin *self) { @@ -846,13 +867,34 @@ }
+static void on_search_help_code_activate(GtkMenuItem *menuitem, DevhelpPlugin *self) +{ + gchar *current_tag; + const gchar *lang = NULL; + GeanyDocument *doc; + + g_return_if_fail(self != NULL); + + if ((current_tag = devhelp_plugin_get_current_tag()) == NULL) + return; + + doc = document_get_current(); + if (doc == NULL || doc->file_type == NULL || doc->file_type->name == NULL) + lang = doc->file_type->name; + + devhelp_plugin_search_code(self, current_tag, lang); + + g_free(current_tag); +} + + /* * Called when the editor context menu is shown so that the devhelp * search item can be disabled if there isn't a selected tag. */ static void on_editor_menu_popup(GtkWidget * widget, DevhelpPlugin *self) { - gchar *label_tag, *curword, *new_label, *new_man_label; + gchar *label_tag, *curword, *new_label;
g_return_if_fail(self != NULL);
@@ -861,23 +903,18 @@ if (curword == NULL) { gtk_widget_set_sensitive(self->priv->editor_menu_item, FALSE); - gtk_widget_set_sensitive(self->priv->editor_man_menu_item, FALSE); return; }
- label_tag = g_strndup(curword, DHPLUG_MAX_LABEL_TAG); - new_label = g_strdup_printf(_("Search Devhelp for: %s..."), g_strstrip(label_tag)); - new_man_label = g_strdup_printf(_("Search manual pages for: %s..."), label_tag); + label_tag = g_strstrip(g_strndup(curword, DHPLUG_MAX_LABEL_TAG)); + new_label = g_strdup_printf(_("Search for '%s' Documentation in"), label_tag);
gtk_menu_item_set_label(GTK_MENU_ITEM(self->priv->editor_menu_item), new_label); - gtk_menu_item_set_label(GTK_MENU_ITEM(self->priv->editor_man_menu_item), new_man_label);
g_free(new_label); - g_free(new_man_label); g_free(label_tag);
gtk_widget_set_sensitive(self->priv->editor_menu_item, TRUE); - gtk_widget_set_sensitive(self->priv->editor_man_menu_item, TRUE);
g_free(curword); }
Modified: trunk/geany-plugins/devhelp/src/devhelpplugin.h =================================================================== --- trunk/geany-plugins/devhelp/src/devhelpplugin.h 2011-05-22 22:28:24 UTC (rev 2070) +++ trunk/geany-plugins/devhelp/src/devhelpplugin.h 2011-05-23 00:20:26 UTC (rev 2071) @@ -23,6 +23,7 @@ #define DEVHELP_PLUGIN_COMMON_H
#include <gtk/gtk.h> +#include <webkit/webkitwebview.h>
G_BEGIN_DECLS
@@ -98,6 +99,8 @@ void devhelp_plugin_toggle_contents_tab (DevhelpPlugin *self); void devhelp_plugin_toggle_webview_tab (DevhelpPlugin *self);
+WebKitWebView* devhelp_plugin_get_webview (DevhelpPlugin *self);
+ G_END_DECLS #endif /* DEVHELP_PLUGIN_H */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org