geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

geanyentryaction.c
Go to the documentation of this file.
1/*
2 * geanyentryaction.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2008 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/* GtkAction subclass to provide a GtkEntry in a toolbar.
22 * This class is missing the action_create_menu_item() function and so can't be
23 * used for creating menu items. */
24
25#ifdef HAVE_CONFIG_H
26# include "config.h"
27#endif
28
29#include "geanyentryaction.h"
30
31#include "ui_utils.h"
32
33#include <ctype.h>
34
35
37
38#define GEANY_ENTRY_ACTION_GET_PRIVATE(obj) (GEANY_ENTRY_ACTION(obj)->priv)
39
40
42{
43 GtkWidget *entry;
44 gboolean numeric;
45 gboolean connected;
46};
47
48enum
49{
53
55};
56static guint signals[LAST_SIGNAL];
57
58
59G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION)
60
61
62static GtkWidget *geany_entry_action_create_tool_item(GtkAction *action)
63{
64 GtkWidget *toolitem;
66
67 priv->entry = gtk_entry_new();
68 if (priv->numeric)
69 gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 9);
70
71 ui_entry_add_clear_icon(GTK_ENTRY(priv->entry));
73
74 gtk_widget_show(priv->entry);
75
76 toolitem = g_object_new(GTK_TYPE_TOOL_ITEM, NULL);
77 gtk_container_add(GTK_CONTAINER(toolitem), priv->entry);
78
79 return toolitem;
80}
81
82
83static void delegate_entry_activate_cb(GtkEntry *entry, GeanyEntryAction *action)
84{
86 const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry));
87
88 g_signal_emit(action, signals[ENTRY_ACTIVATE], 0, text);
89}
90
91
93{
95 const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry));
96
97 g_signal_emit(action, signals[ENTRY_ACTIVATE_BACKWARD], 0, text);
98}
99
100
101static void delegate_entry_changed_cb(GtkEditable *editable, GeanyEntryAction *action)
102{
104 const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry));
105
106 g_signal_emit(action, signals[ENTRY_CHANGED], 0, text);
107}
108
109
110static void geany_entry_action_connect_proxy(GtkAction *action, GtkWidget *widget)
111{
113
114 /* make sure not to connect handlers twice */
115 if (! priv->connected)
116 {
117 if (priv->numeric)
118 g_signal_connect(priv->entry, "insert-text",
120 g_signal_connect(priv->entry, "changed", G_CALLBACK(delegate_entry_changed_cb), action);
121 g_signal_connect(priv->entry, "activate", G_CALLBACK(delegate_entry_activate_cb), action);
122 g_signal_connect(priv->entry, "activate-backward",
123 G_CALLBACK(delegate_entry_activate_backward_cb), action);
124
125 priv->connected = TRUE;
126 }
127
128 GTK_ACTION_CLASS(geany_entry_action_parent_class)->connect_proxy(action, widget);
129}
130
131
133{
134 GtkActionClass *action_class = GTK_ACTION_CLASS(klass);
135
136 action_class->connect_proxy = geany_entry_action_connect_proxy;
137 action_class->create_tool_item = geany_entry_action_create_tool_item;
138 action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
139
140 g_type_class_add_private(klass, sizeof(GeanyEntryActionPrivate));
141
142 signals[ENTRY_CHANGED] = g_signal_new("entry-changed",
143 G_TYPE_FROM_CLASS(klass),
144 G_SIGNAL_RUN_LAST,
145 0,
146 NULL,
147 NULL,
148 g_cclosure_marshal_VOID__STRING,
149 G_TYPE_NONE, 1, G_TYPE_STRING);
150 signals[ENTRY_ACTIVATE] = g_signal_new("entry-activate",
151 G_TYPE_FROM_CLASS(klass),
152 G_SIGNAL_RUN_LAST,
153 0,
154 NULL,
155 NULL,
156 g_cclosure_marshal_VOID__STRING,
157 G_TYPE_NONE, 1, G_TYPE_STRING);
158 signals[ENTRY_ACTIVATE_BACKWARD] = g_signal_new("entry-activate-backward",
159 G_TYPE_FROM_CLASS(klass),
160 G_SIGNAL_RUN_LAST,
161 0,
162 NULL,
163 NULL,
164 g_cclosure_marshal_VOID__STRING,
165 G_TYPE_NONE, 1, G_TYPE_STRING);
166}
167
168
170{
172
173 action->priv = G_TYPE_INSTANCE_GET_PRIVATE(action,
175
176 priv = action->priv;
177 priv->entry = NULL;
178 priv->numeric = FALSE;
179 priv->connected = FALSE;
180}
181
182
183GtkAction *geany_entry_action_new(const gchar *name, const gchar *label,
184 const gchar *tooltip, gboolean numeric)
185{
186 GtkAction *action = g_object_new(GEANY_ENTRY_ACTION_TYPE,
187 "name", name,
188 "label", label,
189 "tooltip", tooltip,
190 NULL);
192
193 priv->numeric = numeric;
194
195 return action;
196}
const gchar * label
Definition: build.c:2676
const gchar * name
Definition: document.c:3219
gchar * text
Definition: editor.c:83
static guint signals[LAST_SIGNAL]
static void geany_entry_action_init(GeanyEntryAction *action)
static void geany_entry_action_connect_proxy(GtkAction *action, GtkWidget *widget)
static void delegate_entry_activate_backward_cb(GtkEntry *entry, GeanyEntryAction *action)
@ LAST_SIGNAL
@ ENTRY_ACTIVATE
@ ENTRY_CHANGED
@ ENTRY_ACTIVATE_BACKWARD
#define GEANY_ENTRY_ACTION_GET_PRIVATE(obj)
static GtkWidget * geany_entry_action_create_tool_item(GtkAction *action)
static void delegate_entry_activate_cb(GtkEntry *entry, GeanyEntryAction *action)
static void delegate_entry_changed_cb(GtkEditable *editable, GeanyEntryAction *action)
static void geany_entry_action_class_init(GeanyEntryActionClass *klass)
GtkAction * geany_entry_action_new(const gchar *name, const gchar *label, const gchar *tooltip, gboolean numeric)
#define GEANY_ENTRY_ACTION_TYPE
static GeanyProjectPrivate priv
Definition: project.c:56
#define NULL
Definition: rbtree.h:150
GtkWidget * entry
Definition: search.c:118
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
struct _GeanyEntryActionPrivate * priv
void ui_entry_add_activate_backward_signal(GtkEntry *entry)
Definition: ui_utils.c:1613
void ui_entry_add_clear_icon(GtkEntry *entry)
Adds a small clear icon to the right end of the passed entry.
Definition: ui_utils.c:1604
void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text, gint new_text_len, gint *position, gpointer data)
Definition: ui_utils.c:3036
User Interface general utility functions.