File: screem-ctags-view.c

package info (click to toggle)
screem 0.12.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,728 kB
  • ctags: 8,333
  • sloc: ansic: 98,234; sh: 8,278; xml: 2,278; makefile: 1,054
file content (238 lines) | stat: -rw-r--r-- 6,187 bytes parent folder | download
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*  Screem:  screem-ctags-view.c
 *
 *  Copyright (C) 2003 David A Knight
 *
 *  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
 */

#include "config.h"

#include <libgnome/gnome-macros.h>
#include <glib/gi18n.h>

#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellrendererpixbuf.h>

#include "screem-ctags-view.h"
#include "screem-ctags-model.h"

#include "readtags.h"

#include "screemmarshal.h"

static void screem_ctags_view_class_init( ScreemCtagsViewClass *klass );
static void screem_ctags_view_instance_init( ScreemCtagsView *ctags_view );
static void screem_ctags_view_finalize( GObject *object );
static void screem_ctags_view_set_prop( GObject *object, guint prop_id,
				const GValue *value, GParamSpec *spec );
static void screem_ctags_view_get_prop( GObject *object, guint prop_id,
				GValue *value, GParamSpec *spec );

static void row_activated( GtkTreeView *view, GtkTreePath *path,
			GtkTreeViewColumn *column, gpointer *data );

struct ScreemCtagsViewPrivate {
	gpointer dummy;
};

enum {
	JUMPTO,
	LAST_SIGNAL
};

enum {
	PROP_0
};

static guint screem_ctags_view_signals[ LAST_SIGNAL ] = { 0 };

GNOME_CLASS_BOILERPLATE( ScreemCtagsView, screem_ctags_view,
			  GtkTreeView,
			  GTK_TYPE_TREE_VIEW )

static void screem_ctags_view_class_init( ScreemCtagsViewClass *klass )
{
	GObjectClass *obj_class;
	
	obj_class = G_OBJECT_CLASS( klass );
	obj_class->finalize = screem_ctags_view_finalize;
	obj_class->get_property = screem_ctags_view_get_prop;
	obj_class->set_property = screem_ctags_view_set_prop;

	screem_ctags_view_signals[ JUMPTO ] = 
		g_signal_new( "jumpto",
			      G_OBJECT_CLASS_TYPE( obj_class ),
			      G_SIGNAL_RUN_LAST,
			      G_STRUCT_OFFSET( ScreemCtagsViewClass, 
					       jumpto ),
			      NULL, NULL,
			      screem_marshal_VOID__STRING_STRING_UINT,
			      G_TYPE_NONE, 3,
			      G_TYPE_STRING,
			      G_TYPE_STRING,
			      G_TYPE_UINT );
}

static void screem_ctags_view_instance_init( ScreemCtagsView *ctags_view )
{
	ScreemCtagsViewPrivate *priv;
	GtkTreeView *view;
	GtkCellRenderer *rend;
	GtkCellRenderer *prend;
	GtkTreeViewColumn *col;
	
	priv = ctags_view->priv = g_new0( ScreemCtagsViewPrivate, 1 );

	view = GTK_TREE_VIEW( ctags_view );
	
	gtk_tree_view_set_rules_hint( view, TRUE );

	prend = gtk_cell_renderer_pixbuf_new();
	rend = gtk_cell_renderer_text_new ();
	col = gtk_tree_view_column_new();
	
	gtk_tree_view_column_set_title( col, _( "Name" ) );
	gtk_tree_view_column_pack_start( col, prend, FALSE );
	gtk_tree_view_column_pack_start( col, rend, TRUE );
	gtk_tree_view_column_set_attributes( col, rend,
					     "text", CTAGS_NAME_COL,
					     NULL );
	gtk_tree_view_column_set_attributes( col, prend,
					     "pixbuf",
					     CTAGS_ICON_COL,
					     NULL );
	gtk_tree_view_column_set_resizable( col, TRUE );
	gtk_tree_view_append_column( view, col );

	rend = gtk_cell_renderer_text_new ();
	col = gtk_tree_view_column_new();
	gtk_tree_view_column_set_title( col, _( "In File" ) );
	gtk_tree_view_column_pack_start( col, rend, TRUE );
	gtk_tree_view_column_set_attributes( col, rend,
					     "text", CTAGS_FILE_COL,
					     NULL );
	gtk_tree_view_column_set_resizable( col, TRUE );
	gtk_tree_view_append_column( view, col );

	g_signal_connect( G_OBJECT( view ), "row_activated",
			G_CALLBACK( row_activated ),
			NULL );
}

static void screem_ctags_view_finalize( GObject *object )
{
	ScreemCtagsView *ctags_view;
	ScreemCtagsViewPrivate *priv;
	
	g_return_if_fail( object != NULL );
	g_return_if_fail( SCREEM_IS_CTAGS_VIEW( object ) );

	ctags_view = SCREEM_CTAGS_VIEW( object );

	priv = ctags_view->priv;

	g_free( priv );
	
	GNOME_CALL_PARENT( G_OBJECT_CLASS, finalize, (object) );
}

static void screem_ctags_view_set_prop( GObject *object, guint prop_id,
				const GValue *value, GParamSpec *spec )
{
	ScreemCtagsView *ctags_view;
	ScreemCtagsViewPrivate *priv;
	
	ctags_view = SCREEM_CTAGS_VIEW( object );
	priv = ctags_view->priv;

	switch( prop_id ) {
		default:
			break;
	}
}

static void screem_ctags_view_get_prop( GObject *object, guint prop_id,
				GValue *value, GParamSpec *spec )
{
	ScreemCtagsView *ctags_view;
	ScreemCtagsViewPrivate *priv;
	
	ctags_view = SCREEM_CTAGS_VIEW( object );
	priv = ctags_view->priv;

	switch( prop_id ) {
		default:
			break;
	}
}

/* static stuff */

static void row_activated( GtkTreeView *view, GtkTreePath *path,
			GtkTreeViewColumn *column, gpointer *data )
{
	ScreemCtagsView *cview;
	ScreemCtagsViewPrivate *priv;
	GtkTreeModel *model;
	GtkTreeIter it;
	gchar *mpath;
	gchar *pathname;
	gchar *file;
	gchar *pattern;
	guint line;
	
	cview = SCREEM_CTAGS_VIEW( view );
	priv = cview->priv;
	
	model = gtk_tree_view_get_model( view );
	if( gtk_tree_model_get_iter( model, &it, path ) ) {
	
		gtk_tree_model_get( model, &it,
				CTAGS_FILE_COL, &file,
				CTAGS_PATTERN_COL, &pattern,
				CTAGS_LINE_COL, &line,
				-1 );
		mpath = NULL;
		if( file ) {
			mpath = screem_ctags_model_get_pathname( SCREEM_CTAGS_MODEL( model ) );
		}
		if( mpath ) {
			pathname = g_build_path( G_DIR_SEPARATOR_S,
					mpath, file, NULL );
			g_free( mpath );
			
			g_signal_emit( G_OBJECT( view ),
				screem_ctags_view_signals[ JUMPTO ], 0,
				pathname, pattern, line );

			g_free( pathname );
		}
		g_free( file );
		g_free( pattern );
	}
}

/* public stuff */

ScreemCtagsView *screem_ctags_view_new( void )
{
	ScreemCtagsView *ctags_view;

	ctags_view = g_object_new( SCREEM_TYPE_CTAGS_VIEW, NULL );

	return ctags_view;
}