1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* gedit-document.h
* This file is part of gedit
*
* Copyright (C) 2002 Paolo Maggi
*
* 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 2002. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h> /* For strlen */
#include <glib/gutils.h>
#include <libgnome/gnome-i18n.h>
#include <gedit/gedit-menus.h>
#include <gedit/gedit-plugin.h>
#include <gedit/gedit-debug.h>
#define MENU_ITEM_LABEL N_("Insert User Na_me")
#define MENU_ITEM_PATH "/menu/Edit/EditOps_4/"
#define MENU_ITEM_NAME "UserName"
#define MENU_ITEM_TIP N_("Insert the user name at the cursor position")
G_MODULE_EXPORT GeditPluginState update_ui (GeditPlugin *plugin, BonoboWindow *window);
G_MODULE_EXPORT GeditPluginState destroy (GeditPlugin *pd);
G_MODULE_EXPORT GeditPluginState activate (GeditPlugin *pd);
G_MODULE_EXPORT GeditPluginState deactivate (GeditPlugin *pd);
G_MODULE_EXPORT GeditPluginState init (GeditPlugin *pd);
static void
sample_cb (BonoboUIComponent *uic, gpointer user_data, const gchar* verbname)
{
GeditDocument *doc;
gchar *user_name;
gchar *user_name_utf8;
const gchar *temp;
gedit_debug (DEBUG_PLUGINS, "");
doc = gedit_get_active_document ();
g_return_if_fail (doc != NULL);
temp = g_get_real_name ();
g_return_if_fail (temp != NULL);
if (strlen (temp) <= 0)
{
temp = g_get_user_name ();
g_return_if_fail (temp != NULL);
}
user_name = g_strdup_printf ("%s ", temp);
g_return_if_fail (user_name != NULL);
if (g_utf8_validate (user_name, -1, NULL))
user_name_utf8 = user_name;
else
{
user_name_utf8 = g_locale_to_utf8 (user_name, -1, NULL, NULL, NULL);
g_free (user_name);
if (user_name_utf8 == NULL)
user_name_utf8 = g_strdup (" ");
}
gedit_document_begin_user_action (doc);
gedit_document_insert_text_at_cursor (doc, user_name_utf8, -1);
gedit_document_end_user_action (doc);
g_free (user_name_utf8);
}
G_MODULE_EXPORT GeditPluginState
update_ui (GeditPlugin *plugin, BonoboWindow *window)
{
BonoboUIComponent *uic;
GeditDocument *doc;
GeditMDI *mdi;
gedit_debug (DEBUG_PLUGINS, "");
g_return_val_if_fail (window != NULL, PLUGIN_ERROR);
mdi = gedit_get_mdi ();
g_return_val_if_fail (window != NULL, PLUGIN_ERROR);
uic = gedit_get_ui_component_from_window (window);
doc = gedit_get_active_document ();
if ((doc == NULL) || (gedit_document_is_readonly (doc)) || (gedit_mdi_get_state (mdi) != GEDIT_STATE_NORMAL))
gedit_menus_set_verb_sensitive (uic, "/commands/" MENU_ITEM_NAME, FALSE);
else
gedit_menus_set_verb_sensitive (uic, "/commands/" MENU_ITEM_NAME, TRUE);
return PLUGIN_OK;
}
G_MODULE_EXPORT GeditPluginState
destroy (GeditPlugin *plugin)
{
gedit_debug (DEBUG_PLUGINS, "");
return PLUGIN_OK;
}
G_MODULE_EXPORT GeditPluginState
activate (GeditPlugin *pd)
{
GList *top_windows;
gedit_debug (DEBUG_PLUGINS, "");
top_windows = gedit_get_top_windows ();
g_return_val_if_fail (top_windows != NULL, PLUGIN_ERROR);
while (top_windows)
{
gedit_menus_add_menu_item (BONOBO_WINDOW (top_windows->data),
MENU_ITEM_PATH, MENU_ITEM_NAME,
MENU_ITEM_LABEL, MENU_ITEM_TIP, NULL,
sample_cb);
pd->update_ui (pd, BONOBO_WINDOW (top_windows->data));
top_windows = g_list_next (top_windows);
}
return PLUGIN_OK;
}
G_MODULE_EXPORT GeditPluginState
deactivate (GeditPlugin *pd)
{
gedit_menus_remove_menu_item_all (MENU_ITEM_PATH, MENU_ITEM_NAME);
return PLUGIN_OK;
}
G_MODULE_EXPORT GeditPluginState
init (GeditPlugin *pd)
{
/* initialize */
gedit_debug (DEBUG_PLUGINS, "");
pd->private_data = NULL;
return PLUGIN_OK;
}
|