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; default: /* error checking */ g_printerr("Menu action not defined : %u\n", action); break; } }
static void menu_replace (GtkMenuItem *menuitem, gpointer data) { text_find_replace(); }