-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.c
157 lines (142 loc) · 5.59 KB
/
menu.c
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
#include <gtk/gtk.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "extra.c"
#include "find.c"
#include "findreplace.c"
#include "pull.c"
#include "push.c"
#include "connect.c"
GtkWidget *view; /* TextView */
/* used for selecting the text */
GdkAtom sel_atom = GDK_SELECTION_CLIPBOARD;/* identify the requests menu handler will manage. */
GtkItemFactory *main_menu; /* Item factory creates a menu from array of itemfactory entries */
/* prototype */
void show_help(void);
void show_about(void);
void show_pull(void);
void show_push(void);
void show_connect(void);
#define MENU_NEW 1
#define MENU_OPEN 2
#define MENU_SAVE 3
#define MENU_SAVE_AS 4
#define MENU_QUIT 5
#define MENU_CUT 6
#define MENU_COPY 7
#define MENU_PASTE 8
#define MENU_USE_CLIPBOARD 9
#define MENU_SELECT_ALL 10
#define MENU_FIND 11
#define MENU_REPLACE 12
#define MENU_HELP 14
#define MENU_ABOUT 15
#define MENU_PULL 16
#define MENU_PUSH 17
#define MENU_CONNECT 18
static void menu_show(gpointer data, guint action, GtkWidget *widget)
{
GtkTextIter p;
switch(action)
{
case MENU_NEW:
if(save_if_modified()) /* call save if modified wen user opens a new file */
{
/* get all the current tag table n put them in the new buffer */
buf = gtk_text_buffer_new(gtk_text_buffer_get_tag_table(buf));
gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), buf);
g_object_unref(G_OBJECT(buf));
/* needed for freeing memory by the buffer wen a new buffer is created */
}
break;
case MENU_OPEN:
if(save_if_modified())
{
/* call save if modified wen user opens a new file */
buf = gtk_text_buffer_new(gtk_text_buffer_get_tag_table(buf));
gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), buf);
/* needed for freeing memory by the buffer wen a new buffer is created */
g_object_unref(G_OBJECT(buf));
load_file(NULL);
}
break;
case MENU_SAVE:
save_file(filename);
break;
case MENU_SAVE_AS:
save_file(NULL);
break;
case MENU_QUIT:
if(save_if_modified()) /* call save if modified wen user opens a new file */
gtk_widget_destroy(window);
break;
case MENU_CUT:
gtk_text_buffer_cut_clipboard(buf,gtk_clipboard_get(sel_atom), TRUE);
break;
case MENU_COPY:
gtk_text_buffer_copy_clipboard(buf,gtk_clipboard_get(sel_atom));
break;
case MENU_PASTE:
/* if null text is inserted at the current cursor position */
gtk_text_buffer_paste_clipboard(buf,gtk_clipboard_get(sel_atom), NULL, TRUE);
break;
case MENU_FIND:
textfind();
break;
case MENU_REPLACE:
text_find_replace();
break;
case MENU_SELECT_ALL:
gtk_text_buffer_get_start_iter(buf, &p); /* get the starting pt of the buffer */
gtk_text_buffer_place_cursor(buf, &p); /* ignore the selection made by the mouse */
gtk_text_buffer_get_end_iter(buf, &p); /* get the ending pt of the buffer */
gtk_text_buffer_move_mark_by_name(buf, "selection_bound", &p);
break;
case MENU_HELP:
show_help();
break;
case MENU_ABOUT:
show_about();
break;
case MENU_PULL:
show_pull();
break;
case MENU_PUSH:
show_push();
break;
case MENU_CONNECT:
show_connect();
break;
default: /* error checking */
g_printerr("Menu action not defined : %u\n", action);
break;
}
}
/* actual menu creation */
GtkItemFactoryEntry menu_def[] =
{
{ (char *)"/_File", NULL, NULL, 0, (char *)"<Branch>", NULL },
{ (char *)"/File/_New", (char *)"<control>N", menu_show, MENU_NEW, (char *)"<StockItem>", GTK_STOCK_NEW },
{ (char *)"/File/_Open...", (char *)"<control>O", menu_show, MENU_OPEN, (char *)"<StockItem>", GTK_STOCK_OPEN },
{ (char *)"/File/_Save", (char *)"<control>S", menu_show, MENU_SAVE, (char *)"<StockItem>", GTK_STOCK_SAVE },
{ (char *)"/File/Save _As...", NULL, menu_show, MENU_SAVE_AS, (char *)"<StockItem>", GTK_STOCK_SAVE_AS },
{ (char *)"/File/sep", NULL, NULL, 0, (char *)"<Separator>", NULL },
{ (char *)"/File/_Quit", (char *)"<control>Q", menu_show, MENU_QUIT, (char *)"<StockItem>", GTK_STOCK_QUIT },
{ (char *)"/_Edit", NULL, NULL, 0, (char *)"<Branch>", NULL },
{ (char *)"/Edit/C_ut", (char *)"<control>X", menu_show, MENU_CUT, (char *)"<StockItem>", GTK_STOCK_CUT },
{ (char *)"/Edit/_Copy", (char *)"<control>C", menu_show, MENU_COPY, (char *)"<StockItem>", GTK_STOCK_COPY },
{ (char *)"/Edit/_Paste", (char *)"<control>V", menu_show, MENU_PASTE, (char *)"<StockItem>", GTK_STOCK_PASTE },
{ (char *)"/Edit/sep", NULL, NULL, 0, (char *)"<Separator>", NULL },
{ (char *)"/Edit/Select All", NULL, menu_show, MENU_SELECT_ALL, NULL, NULL },
{ (char *)"/_Search", NULL, NULL, 0, (char *)"<Branch>", NULL },
{ (char *)"/Search/_Find", (char *)"<control>F" , menu_show, MENU_FIND,(char *)"<StockItem>", GTK_STOCK_FIND },
{ (char *)"/Search/_Replace", (char *)"<control>R" , menu_show, MENU_REPLACE,(char *)"<StockItem>", GTK_STOCK_FIND },
{ (char *)"/_Help", NULL, NULL, 0, (char *)"<Branch>", NULL },
{ (char *)"/Help/_Contents", (char *)"<control>H", menu_show, MENU_HELP, (char *)"<StockItem>", GTK_STOCK_HELP },
{ (char *)"/Help/_About", NULL , menu_show, MENU_ABOUT, "<Item>" },
{ (char *)"/_Connect", NULL, NULL, 0, (char *)"<Branch>", NULL },
{ (char *)"/Connect/_Pull", (char *)"<control>U", menu_show, MENU_PULL, (char *)"<StockItem>", GTK_STOCK_APPLY },
{ (char *)"/Connect/_Push", (char *)"<control>P", menu_show, MENU_PUSH, (char *)"<StockItem>", GTK_STOCK_ADD },
{ (char *)"/Connect/_Create Network", (char *)"<control>T", menu_show, MENU_CONNECT, (char *)"<StockItem>", GTK_STOCK_CONNECT }
};