2 * (c) 2010 Cyrill Gorcunov, gorcunov@gmail.com
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 #include <sys/param.h>
29 #include <sys/types.h>
35 #include "backend-proto.h"
41 #include "sourceview.h"
47 static void cb_notebook_page_switched(struct notebook_page
*page
)
49 struct source_view
*source_view
;
51 if (!(page
->status
& NB_STATUS_SOURCE
))
54 source_view
= page
->private;
56 gscope_info
.title_buf
[0] = 0;
57 strlcat(gscope_info
.title_buf
, source_view
->file_path
, sizeof(gscope_info
.title_buf
));
59 gtk_window_set_title(GTK_WINDOW(gscope_info
.main_window
), gscope_info
.title_buf
);
62 void read_file_into_notebook(struct gscope_info
*info
, char *filename
)
64 struct notebook_page
*page
;
65 struct source_view
*source_view
;
67 source_view
= source_view_create(filename
);
70 page
= notebook_create_page(info
->notebook_source
, g_path_get_basename(filename
),
71 strlen(g_path_get_basename(filename
)), NB_STATUS_SOURCE
);
72 notebook_page_child_attach(page
, source_view
->me
, source_view
, cb_notebook_page_switched
, source_view
->delete_hook
);
73 notebook_activate_page(info
->notebook_source
, page
);
74 gtk_widget_show_all(info
->main_window
);
77 void do_cscope_query(struct gscope_info
*info
, char *query_name
, int type
, int nocase
)
79 struct notebook_page
*page
;
80 struct list_head
*head
;
81 struct query_result query_result
;
82 struct query_view
*query_view
;
84 struct backend_proto_query_params params
= {
85 .u
.cscope
.name
= query_name
,
86 .u
.cscope
.type
= type
,
87 .u
.cscope
.nocase
= nocase
,
90 query_result
.proto
= backend_proto_find(BACKEND_PROTO_CSCOPE
);
91 DIE_IF(!query_result
.proto
);
93 head
= query_result
.proto
->backend_proto_query(¶ms
);
94 if (!head
|| list_empty(head
))
96 query_result
.head
= head
;
99 * A special case -- single entry
101 if (list_is_singular(head
)) {
102 struct backend_proto_item item
;
104 list_for_each(t
, head
)
105 query_result
.proto
->backend_proto_get(t
, &item
);
106 query_switch_or_read_source_into_notebook(info
, &item
);
108 query_view
= query_view_create(&query_result
);
111 page
= notebook_create_page(info
->notebook_query
, query_name
, strlen(query_name
), NB_STATUS_QUERY
);
112 notebook_page_child_attach(page
, query_view
->me
, query_view
, NULL
, query_view_destroy
);
114 gtk_widget_show_all(info
->main_window
);
118 void do_id_utils_query(struct gscope_info
*info
, char *query_name
)
120 struct notebook_page
*page
;
121 struct list_head
*head
;
122 struct query_result query_result
;
123 struct query_view
*query_view
;
125 struct backend_proto_query_params params
= {
126 .u
.idutils
.name
= query_name
,
129 query_result
.proto
= backend_proto_find(BACKEND_PROTO_ID_UTILS
);
130 DIE_IF(!query_result
.proto
);
132 head
= query_result
.proto
->backend_proto_query(¶ms
);
133 if (!head
|| list_empty(head
))
135 query_result
.head
= head
;
137 query_view
= query_view_create(&query_result
);
140 page
= notebook_create_page(info
->notebook_query
, query_name
, 8, NB_STATUS_QUERY
);
141 notebook_page_child_attach(page
, query_view
->me
, query_view
, NULL
, query_view_destroy
);
143 gtk_widget_show_all(info
->main_window
);
146 struct cscope_cb_params
{
151 static void cb_response(GtkWidget
*w
, gint resp_code
, gpointer param
)
153 if (resp_code
== GTK_RESPONSE_OK
) {
154 GtkWidget
*entry
= ((struct cscope_cb_params
*)param
)->entry
;
155 unsigned int opcode
= ((struct cscope_cb_params
*)param
)->opcode
;
156 do_cscope_query(&gscope_info
, (char *)gtk_entry_get_text(GTK_ENTRY(entry
)),
159 gtk_widget_destroy(w
);
162 static struct cscope_cb_params params
;
164 void do_cscope_query_dialog(gpointer opcode
)
170 GtkEntryBuffer
*buffer
;
171 const char *desc
= cscope_param_desc((unsigned int)(unsigned long)opcode
);
176 window
= gtk_dialog_new_with_buttons(desc
, GTK_WINDOW(gscope_info
.main_window
), 0,
177 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
178 GTK_STOCK_CANCEL
, GTK_RESPONSE_NONE
,
181 gtk_window_set_destroy_with_parent(GTK_WINDOW(window
), TRUE
);
182 gtk_dialog_set_default_response(GTK_DIALOG(window
), GTK_RESPONSE_OK
);
183 gtk_window_set_resizable(GTK_WINDOW(window
), FALSE
);
185 vbox
= gtk_vbox_new(FALSE
, 5);
186 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window
)->vbox
), vbox
, TRUE
, TRUE
, 0);
187 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 5);
189 label
= gtk_label_new(NULL
);
190 gtk_label_set_markup(GTK_LABEL(label
), "Enter the symbol");
191 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
193 /* Create a buffer */
194 buffer
= gtk_entry_buffer_new(NULL
, 0);
196 /* Create our first entry */
197 entry
= gtk_entry_new_with_buffer(buffer
);
198 gtk_box_pack_start(GTK_BOX(vbox
), entry
, FALSE
, FALSE
, 0);
199 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
201 params
.opcode
= (unsigned int)(unsigned long)opcode
;
202 params
.entry
= entry
;
204 g_signal_connect(window
, "response", G_CALLBACK(cb_response
), ¶ms
);
205 g_signal_connect(window
, "destroy", G_CALLBACK(gtk_widget_destroyed
), &window
);
207 g_object_unref(buffer
);
209 gtk_widget_show_all(window
);
212 void do_cscope_rebuild(gpointer pointer
)
214 struct backend_proto
*proto
= backend_proto_find(BACKEND_PROTO_CSCOPE
);
217 proto
->backend_proto_refresh();