~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to src/geanyentryaction.c

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2009-05-29 21:22:54 UTC
  • mfrom: (1.3.1 upstream) (3.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: james.westby@ubuntu.com-20090529212254-cx6t2a7itgii3p5f
Tags: 0.17-1
* New upstream release
* 20_add_debdiff_as_diff_type.dpatch renamed as
  20_add_debian_specific_filetypes.dpatch, 
  - add .dpatch as a diff filetype
  - add control as a conf filetype
* 20_change_gpl_location.dpatch freshen
* add 20_debian_control_tags.dpatch better handling of debian/control files.
  Thanks to Enrico Tröger. (Closes: #520776)
* debian/copyright Add Frank Lanitz, update years

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      geanyentryaction.c - this file is part of Geany, a fast and lightweight IDE
 
3
 *
 
4
 *      Copyright 2008-2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
 
5
 *      Copyright 2008-2009 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
 
6
 *
 
7
 *      This program is free software; you can redistribute it and/or modify
 
8
 *      it under the terms of the GNU General Public License as published by
 
9
 *      the Free Software Foundation; either vergeany 2 of the License, or
 
10
 *      (at your option) any later vergeany.
 
11
 *
 
12
 *      This program is distributed in the hope that it will be useful,
 
13
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *      GNU General Public License for more details.
 
16
 *
 
17
 *      You should have received a copy of the GNU General Public License
 
18
 *      along with this program; if not, write to the Free Software
 
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
/* GtkAction subclass to provide a GtkEntry in a toolbar.
 
23
 * This class is missing the action_create_menu_item() function and so can't be
 
24
 * used for creating menu items. */
 
25
 
 
26
 
 
27
#include "geany.h"
 
28
#include "support.h"
 
29
#include "ui_utils.h"
 
30
#include "geanyentryaction.h"
 
31
#include <ctype.h>
 
32
 
 
33
 
 
34
typedef struct _GeanyEntryActionPrivate         GeanyEntryActionPrivate;
 
35
 
 
36
#define GEANY_ENTRY_ACTION_GET_PRIVATE(obj)     (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
 
37
                        GEANY_ENTRY_ACTION_TYPE, GeanyEntryActionPrivate))
 
38
 
 
39
 
 
40
struct _GeanyEntryActionPrivate
 
41
{
 
42
        GtkWidget       *entry;
 
43
        gboolean         numeric;
 
44
};
 
45
 
 
46
enum
 
47
{
 
48
        ENTRY_ACTIVATE,
 
49
        ENTRY_CHANGED,
 
50
 
 
51
        LAST_SIGNAL
 
52
};
 
53
static guint signals[LAST_SIGNAL];
 
54
 
 
55
 
 
56
G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION);
 
57
 
 
58
 
 
59
static GtkWidget *geany_entry_action_create_tool_item(GtkAction *action)
 
60
{
 
61
        GtkWidget *toolitem;
 
62
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
63
 
 
64
        priv->entry = gtk_entry_new();
 
65
        if (priv->numeric)
 
66
                gtk_entry_set_width_chars(GTK_ENTRY(priv->entry), 9);
 
67
 
 
68
        ui_entry_add_clear_icon(priv->entry);
 
69
 
 
70
        gtk_widget_show(priv->entry);
 
71
 
 
72
        toolitem = g_object_new(GTK_TYPE_TOOL_ITEM, NULL);
 
73
        gtk_container_add(GTK_CONTAINER(toolitem), priv->entry);
 
74
 
 
75
        return toolitem;
 
76
}
 
77
 
 
78
 
 
79
static void delegate_entry_activate_cb(GtkEntry *entry, GeanyEntryAction *action)
 
80
{
 
81
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
82
        const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry));
 
83
 
 
84
        g_signal_emit(action, signals[ENTRY_ACTIVATE], 0, text);
 
85
}
 
86
 
 
87
 
 
88
static void delegate_entry_changed_cb(GtkEditable *editable, GeanyEntryAction *action)
 
89
{
 
90
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
91
        const gchar *text = gtk_entry_get_text(GTK_ENTRY(priv->entry));
 
92
 
 
93
        g_signal_emit(action, signals[ENTRY_CHANGED], 0, text);
 
94
}
 
95
 
 
96
 
 
97
static void entry_insert_text_cb(GtkEditable *editable, gchar *new_text, gint new_text_len,
 
98
                                                                 gint *position, GeanyEntryAction *action)
 
99
{
 
100
        /* don't insert any text when it is not a digit */
 
101
        if (! isdigit(*new_text))
 
102
                g_signal_stop_emission_by_name(editable, "insert-text");
 
103
}
 
104
 
 
105
 
 
106
static void geany_entry_action_connect_proxy(GtkAction *action, GtkWidget *widget)
 
107
{
 
108
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
109
 
 
110
        if (priv->numeric)
 
111
                g_signal_connect(priv->entry, "insert-text", G_CALLBACK(entry_insert_text_cb), action);
 
112
        g_signal_connect(priv->entry, "changed", G_CALLBACK(delegate_entry_changed_cb), action);
 
113
        g_signal_connect(priv->entry, "activate", G_CALLBACK(delegate_entry_activate_cb), action);
 
114
 
 
115
    GTK_ACTION_CLASS(geany_entry_action_parent_class)->connect_proxy(action, widget);
 
116
}
 
117
 
 
118
 
 
119
static void geany_entry_action_class_init(GeanyEntryActionClass *klass)
 
120
{
 
121
        GtkActionClass *action_class = GTK_ACTION_CLASS(klass);
 
122
 
 
123
        action_class->connect_proxy = geany_entry_action_connect_proxy;
 
124
        action_class->create_tool_item = geany_entry_action_create_tool_item;
 
125
        action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
 
126
 
 
127
        g_type_class_add_private(klass, sizeof(GeanyEntryActionPrivate));
 
128
 
 
129
        signals[ENTRY_CHANGED] = g_signal_new("entry-changed",
 
130
                                                                        G_TYPE_FROM_CLASS(klass),
 
131
                                                                        (GSignalFlags) 0,
 
132
                                                                        0,
 
133
                                                                        0,
 
134
                                                                        NULL,
 
135
                                                                        g_cclosure_marshal_VOID__STRING,
 
136
                                                                        G_TYPE_NONE, 1, G_TYPE_STRING);
 
137
        signals[ENTRY_ACTIVATE] = g_signal_new("entry-activate",
 
138
                                                                        G_TYPE_FROM_CLASS(klass),
 
139
                                                                        (GSignalFlags) 0,
 
140
                                                                        0,
 
141
                                                                        0,
 
142
                                                                        NULL,
 
143
                                                                        g_cclosure_marshal_VOID__STRING,
 
144
                                                                        G_TYPE_NONE, 1, G_TYPE_STRING);
 
145
}
 
146
 
 
147
 
 
148
static void geany_entry_action_init(GeanyEntryAction *action)
 
149
{
 
150
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
151
 
 
152
        priv->entry = NULL;
 
153
        priv->numeric = FALSE;
 
154
}
 
155
 
 
156
 
 
157
GtkAction *geany_entry_action_new(const gchar *name, const gchar *label,
 
158
                                                                  const gchar *tooltip, gboolean numeric)
 
159
{
 
160
        GtkAction *action = g_object_new(GEANY_ENTRY_ACTION_TYPE,
 
161
                "name", name,
 
162
                "label", label,
 
163
                "tooltip", tooltip,
 
164
                NULL);
 
165
        GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
 
166
 
 
167
        priv->numeric = numeric;
 
168
 
 
169
        return action;
 
170
}
 
171