-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
executable file
·94 lines (80 loc) · 2.94 KB
/
menu.c
File metadata and controls
executable file
·94 lines (80 loc) · 2.94 KB
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
#include <gtk/gtk.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include "main.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);
#define MENU_NEW 1
#define MENU_OPEN 2
#define MENU_SAVE 3
#define MENU_SAVE_AS 4
#define MENU_CRUN 5
#define MENU_QUIT 6
void set_text() {
GtkTextBuffer *buffer;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
FILE * fp = fopen("run", "r");
char output[2000];
fgets(output, 2000, fp);
gtk_text_buffer_set_text (buffer, output, -1);
}
static void menu_show(gpointer data, guint action, GtkWidget *widget)
{
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_CRUN:
compile_and_run("run.c");
set_text();
break;
case MENU_QUIT:
if(save_if_modified()) /* call save if modified when user opens a new file */
gtk_widget_destroy(window);
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/_Compile_&_Run", (char *)"<control>R", menu_show, MENU_CRUN, (char *)"<StockItem>", GTK_STOCK_OK },
{ (char *)"/File/sep", NULL, NULL, 0, (char *)"<Separator>", NULL },
{ (char *)"/File/_Quit", (char *)"<control>Q", menu_show, MENU_QUIT, (char *)"<StockItem>", GTK_STOCK_QUIT },
};