-
Notifications
You must be signed in to change notification settings - Fork 2
/
gtk_toolbar.c
324 lines (249 loc) · 13.9 KB
/
gtk_toolbar.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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include "gtk_toolbar.h"
GtkWidget *create_toolbar (GtkAccelGroup *mainaccel, gpointer data)
{
mainwin_t *app = data;
GtkWidget *toolbar;
GtkToolItem *new; /* new, open, recent, save/saveas */
GtkToolItem *open;
GtkToolItem *recent;
GtkToolItem *save;
GtkToolItem *saveas;
GtkToolItem *print; /* print */
GtkToolItem *close; /* close, exit */
GtkToolItem *exit;
GtkToolItem *undo; /* undo, redo */
GtkToolItem *redo;
GtkToolItem *copy; /* copy, cut, paste */
GtkToolItem *cut;
GtkToolItem *paste;
GtkToolItem *indent; /* indent, unindent */
GtkToolItem *unindent;
GtkToolItem *find; /* find, replace, goto-line */
GtkToolItem *replace;
GtkToolItem *gotoln;
GtkToolItem *split; /* add editor split, remove split */
GtkToolItem *rmsplit;
GtkToolItem *insdtm; /* insert date/time */
// GtkToolItem *style; /* TODO: move to preferences */
GtkToolItem *preferences; /* preferences */
GtkToolItem *sep; /* seperator & separator-right */
GtkToolItem *seprt;
toolbar = gtk_toolbar_new ();
gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2);
gtk_toolbar_set_show_arrow (GTK_TOOLBAR(toolbar), TRUE);
/* GTK_TOOLBAR_ICONS, GTK_TOOLBAR_TEXT, GTK_TOOLBAR_BOTH, GTK_TOOLBAR_BOTH_HORIZ */
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
// gtk_toolbar_set_style(GTK_TOOLBAR(*toolbar), GTK_TOOLBAR_BOTH);
/* Note: accelerators commented out below
* there is not need to duplicate accelerators between
* the menu and toolbar.
*/
if(mainaccel) {} /* stub to prevent [-Wunused-parameter] */
new = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
gtk_tool_item_set_homogeneous (new, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), new, -1);
/* set_label to change text shown when TEXT, or BOTH style shown
* // gtk_tool_button_set_label (GTK_TOOL_BUTTON(new), "Clear");
*/
gtk_widget_set_tooltip_text (GTK_WIDGET(new), "New file ");
open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
gtk_tool_item_set_homogeneous (open, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), open, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(open), "Open existing file ");
/* TODO: recent files drop-down on tool bar next to open (look at menu) */
// GtkToolItem *recent;
// GtkWidget *menu;
// GtkRecentManager *manager;
// manager = gtk_recent_manager_get_default ();
// recent = gtk_menu_tool_button_new (open, "Recent Files");
// menu = gtk_recent_chooser_menu_new_for_manager (manager);
// gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (recent), menu);
//
// gtk_recent_chooser_set_show_not_found (GTK_RECENT_CHOOSER (menu), FALSE);
// gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (menu), TRUE);
// gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (menu), 20);
// gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu),
// GTK_RECENT_SORT_MRU);
/* Removed until upstream bug fixed
* see: https://bugzilla.gnome.org/show_bug.cgi?id=779605
*/
recent = gtk_tool_button_new_from_stock(GTK_STOCK_DND_MULTIPLE);
gtk_tool_item_set_homogeneous (recent, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), recent, -1);
gtk_widget_add_accelerator (GTK_WIDGET(recent), "clicked", mainaccel,
GDK_KEY_o, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_set_tooltip_text (GTK_WIDGET(recent), "Open recent file.");
save = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_tool_item_set_homogeneous (save, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), save, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(save), "Save file ");
saveas = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE_AS);
gtk_tool_item_set_homogeneous (saveas, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), saveas, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(saveas), "Save as new file ");
sep = gtk_separator_tool_item_new();
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), sep, -1);
print = gtk_tool_button_new_from_stock(GTK_STOCK_PRINT);
gtk_tool_item_set_homogeneous (print, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), print, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(print), "Print file ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
close = gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE);
gtk_tool_item_set_homogeneous (close, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), close, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(close), "Close current file ");
exit = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
gtk_tool_item_set_homogeneous (exit, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), exit, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(exit), "Quit ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
undo = gtk_tool_button_new_from_stock(GTK_STOCK_UNDO);
gtk_tool_item_set_homogeneous (undo, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), undo, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(undo), "Undo previous edits ");
redo = gtk_tool_button_new_from_stock(GTK_STOCK_REDO);
gtk_tool_item_set_homogeneous (redo, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), redo, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(redo), "Redo previous edits ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
cut = gtk_tool_button_new_from_stock(GTK_STOCK_CUT);
gtk_tool_item_set_homogeneous (cut, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), cut, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(cut), "Cut selected text to clipboard ");
copy = gtk_tool_button_new_from_stock(GTK_STOCK_COPY);
gtk_tool_item_set_homogeneous (copy, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), copy, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(copy), "Copy selected text to clipboard ");
paste = gtk_tool_button_new_from_stock(GTK_STOCK_PASTE);
gtk_tool_item_set_homogeneous (paste, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), paste, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(paste), "Paste text from clipboard ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
indent = gtk_tool_button_new_from_stock(GTK_STOCK_INDENT);
gtk_tool_item_set_homogeneous (indent, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), indent, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(indent), "Indent");
gtk_widget_set_tooltip_text (GTK_WIDGET(indent), "Increase indent ");
unindent = gtk_tool_button_new_from_stock(GTK_STOCK_UNINDENT);
gtk_tool_item_set_homogeneous (unindent, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), unindent, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(unindent), "Unindent");
gtk_widget_set_tooltip_text (GTK_WIDGET(unindent), "Decrease indent ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
find = gtk_tool_button_new_from_stock(GTK_STOCK_FIND);
gtk_tool_item_set_homogeneous (find, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), find, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(find), "Find text ");
replace = gtk_tool_button_new_from_stock(GTK_STOCK_FIND_AND_REPLACE);
gtk_tool_item_set_homogeneous (replace, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), replace, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(replace), "Replace");
gtk_widget_set_tooltip_text (GTK_WIDGET(replace), "Find and replace text ");
gotoln = gtk_tool_button_new_from_stock(GTK_STOCK_INDEX);
gtk_tool_item_set_homogeneous (gotoln, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gotoln, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(gotoln), "Goto");
gtk_widget_set_tooltip_text (GTK_WIDGET(gotoln), "Goto line in text ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
split = gtk_tool_button_new_from_stock(GTK_STOCK_ADD);
gtk_tool_item_set_homogeneous (split, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), split, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(split), "Split Window ");
rmsplit = gtk_tool_button_new_from_stock(GTK_STOCK_REMOVE);
gtk_tool_item_set_homogeneous (rmsplit, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), rmsplit, -1);
gtk_widget_set_tooltip_text (GTK_WIDGET(rmsplit), "Remove Current Split ");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
insdtm = gtk_tool_button_new_from_stock(GTK_STOCK_EDIT);
gtk_tool_item_set_homogeneous (insdtm, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), insdtm, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(insdtm), "Date/Time");
gtk_widget_set_tooltip_text (GTK_WIDGET(insdtm), "Insert Date/Time ");
/* TODO: move to perferences - doesn't need to be in toolbar */
// #ifdef HAVESOURCEVIEW
// gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
//
// /* add syntax style combobox created in sourceview_syntax_styles_menu */
// style = gtk_tool_item_new ();
// gtk_tool_item_set_homogeneous (style, FALSE);
// gtk_container_add (GTK_CONTAINER(style), app->stylelist);
// gtk_toolbar_insert(GTK_TOOLBAR(*toolbar), style, -1);
// gtk_widget_set_tooltip_text (GTK_WIDGET(style), "Set Syntax Style ");
// #endif
/* separator that will force remaining items to right of toolbar */
seprt = gtk_separator_tool_item_new();
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM(seprt), FALSE);
gtk_tool_item_set_expand (GTK_TOOL_ITEM(seprt), TRUE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), seprt, -1);
preferences = gtk_tool_button_new_from_stock(GTK_STOCK_PREFERENCES);
gtk_tool_item_set_homogeneous (preferences, FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), preferences, -1);
gtk_tool_button_set_label (GTK_TOOL_BUTTON(preferences), "Settings");
gtk_widget_set_tooltip_text (GTK_WIDGET(preferences), "Preferences ");
/*
* Toolbar callbacks - simply connect to menu functions
*/
g_signal_connect (G_OBJECT (new), "clicked", /* file New */
G_CALLBACK (menu_file_new_activate), data);
g_signal_connect (G_OBJECT (open), "clicked", /* file Open */
G_CALLBACK (menu_file_open_activate), data);
/* Removed until upstream bug fixed
* see: https://bugzilla.gnome.org/show_bug.cgi?id=779605
*/
g_signal_connect (G_OBJECT (recent), "clicked", /* recent file */
G_CALLBACK (toolbar_file_open_recent), data);
g_signal_connect (G_OBJECT (save), "clicked", /* file Save */
G_CALLBACK (menu_file_save_activate), data);
g_signal_connect (G_OBJECT (saveas), "clicked", /* file Save as */
G_CALLBACK (menu_file_saveas_activate), data);
g_signal_connect (G_OBJECT (print), "clicked", /* file Print */
G_CALLBACK (menu_file_print_activate), data);
g_signal_connect (G_OBJECT (close), "clicked", /* file Close */
G_CALLBACK (menu_file_close_activate), data);
g_signal_connect (G_OBJECT (exit), "clicked", /* file Quit */
G_CALLBACK (menu_file_quit_activate), data);
g_signal_connect (G_OBJECT (undo), "clicked", /* edit Undo */
G_CALLBACK (menu_edit_undo_activate), data);
g_signal_connect (G_OBJECT (redo), "clicked", /* edit Redo */
G_CALLBACK (menu_edit_redo_activate), data);
g_signal_connect (G_OBJECT (cut), "clicked", /* edit Cut */
G_CALLBACK (menu_edit_cut_activate), data);
g_signal_connect (G_OBJECT (copy), "clicked", /* edit Copy */
G_CALLBACK (menu_edit_copy_activate), data);
g_signal_connect (G_OBJECT (paste), "clicked", /* edit Paste */
G_CALLBACK (menu_edit_paste_activate), data);
g_signal_connect (G_OBJECT (find), "clicked", /* edit Find */
G_CALLBACK (menu_edit_find_activate), data);
g_signal_connect (G_OBJECT (replace), "clicked", /* edit Replace */
G_CALLBACK (menu_edit_replace_activate), data);
g_signal_connect (G_OBJECT (gotoln), "clicked", /* edit Goto */
G_CALLBACK (menu_edit_goto_activate), data);
g_signal_connect (G_OBJECT (split), "clicked", /* split btn */
G_CALLBACK (menu_createview_activate), app);
g_signal_connect (G_OBJECT (rmsplit), "clicked", /* rmsplit btn */
G_CALLBACK (menu_removeview_activate), app);
g_signal_connect (G_OBJECT (indent), "clicked", /* tools Ind+ */
G_CALLBACK (menu_tools_indent_activate), data);
g_signal_connect (G_OBJECT (unindent), "clicked", /* tools Ind- */
G_CALLBACK (menu_tools_unindent_activate), data);
g_signal_connect (G_OBJECT (insdtm), "clicked", /* tools Ind- */
G_CALLBACK (menu_tools_insdtm_activate), data);
g_signal_connect (G_OBJECT (preferences), "clicked", /* edit Prefs */
G_CALLBACK (menu_edit_preferences_activate), data);
gtk_widget_show_all (toolbar);
return toolbar;
}
/* Removed until upstream bug fixed
* see: https://bugzilla.gnome.org/show_bug.cgi?id=779605
*/
void toolbar_file_open_recent (GtkWidget *widget, gpointer data)
{
file_open_recent_dlg (data);
// /* get new filename */
// gchar *newfile = file_open_recent_dlg (app);
// g_print ("oolbar_file_open_recent : %s\n", newfile);
//
// /* open newfile in current or new editor instance */
// file_open (app, newfile);
if (widget) {}
}