Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. #include <gtk/gtk.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4. #include <stdlib.h>
  5. #include "extra.c"
  6. #include "find.c"
  7. #include "findreplace.c"
  8.  
  9. GtkWidget *view; /* TextView */
  10.  
  11. /* used for selecting the text */
  12. GdkAtom sel_atom = GDK_SELECTION_CLIPBOARD;/* identify the requests menu handler will manage. */
  13. GtkItemFactory *main_menu; /* Item factory creates a menu from array of itemfactory entries */
  14.  
  15. /* prototype */
  16.  
  17. void show_help(void);
  18. void show_about(void);
  19.  
  20. #define MENU_NEW 1
  21. #define MENU_OPEN 2
  22. #define MENU_SAVE 3
  23. #define MENU_SAVE_AS 4
  24. #define MENU_QUIT 5
  25. #define MENU_CUT 6
  26. #define MENU_COPY 7
  27. #define MENU_PASTE 8
  28. #define MENU_USE_CLIPBOARD 9
  29. #define MENU_SELECT_ALL 10
  30. #define MENU_FIND 11
  31. #define MENU_REPLACE 12
  32. #define MENU_HELP 14
  33. #define MENU_ABOUT 15
  34.  
  35. static void menu_show(gpointer data, guint action, GtkWidget *widget)
  36. {
  37. GtkTextIter p;
  38.  
  39. switch(action)
  40. {
  41. case MENU_NEW:
  42. if(save_if_modified()) /* call save if modified wen user opens a new file */
  43. {
  44. /* get all the current tag table n put them in the new buffer */
  45. buf = gtk_text_buffer_new(gtk_text_buffer_get_tag_table(buf));
  46. gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), buf);
  47. g_object_unref(G_OBJECT(buf));
  48. /* needed for freeing memory by the buffer wen a new buffer is created */
  49. }
  50. break;
  51. case MENU_OPEN:
  52. if(save_if_modified())
  53. {
  54. /* call save if modified wen user opens a new file */
  55. buf = gtk_text_buffer_new(gtk_text_buffer_get_tag_table(buf));
  56. gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), buf);
  57.  
  58. /* needed for freeing memory by the buffer wen a new buffer is created */
  59. g_object_unref(G_OBJECT(buf));
  60. load_file(NULL);
  61. }
  62. break;
  63. case MENU_SAVE:
  64. save_file(filename);
  65. break;
  66. case MENU_SAVE_AS:
  67. save_file(NULL);
  68. break;
  69. case MENU_QUIT:
  70. if(save_if_modified()) /* call save if modified wen user opens a new file */
  71. gtk_widget_destroy(window);
  72. break;
  73. case MENU_CUT:
  74. gtk_text_buffer_cut_clipboard(buf,gtk_clipboard_get(sel_atom), TRUE);
  75. break;
  76. case MENU_COPY:
  77. gtk_text_buffer_copy_clipboard(buf,gtk_clipboard_get(sel_atom));
  78. break;
  79. case MENU_PASTE:
  80. /* if null text is inserted at the current cursor position */
  81. gtk_text_buffer_paste_clipboard(buf,gtk_clipboard_get(sel_atom), NULL, TRUE);
  82. break;
  83. case MENU_FIND:
  84. textfind();
  85. break;
  86. case MENU_REPLACE:
  87. text_find_replace();
  88. break;
  89.  
  90. case MENU_SELECT_ALL:
  91. gtk_text_buffer_get_start_iter(buf, &p); /* get the starting pt of the buffer */
  92. gtk_text_buffer_place_cursor(buf, &p); /* ignore the selection made by the mouse */
  93. gtk_text_buffer_get_end_iter(buf, &p); /* get the ending pt of the buffer */
  94. gtk_text_buffer_move_mark_by_name(buf, "selection_bound", &p);
  95. break;
  96. case MENU_HELP:
  97. how_help();
  98. break;
  99. case MENU_ABOUT:
  100. show_about();
  101. break;
  102.  
  103. default: /* error checking */
  104. g_printerr("Menu action not defined : %u\n", action);
  105. break;
  106. }
  107. }
  108.  
  109. /* actual menu creation */
  110.  
  111. GtkItemFactoryEntry menu_def[] =
  112. {
  113. { (char *)"/_File", NULL, NULL, 0, (char *)"<Branch>", NULL },
  114. { (char *)"/File/_New", (char *)"<control>N", menu_show, MENU_NEW, (char *)"<StockItem>", GTK_STOCK_NEW },
  115. { (char *)"/File/_Open...", (char *)"<control>O", menu_show, MENU_OPEN, (char *)"<StockItem>", GTK_STOCK_OPEN },
  116. { (char *)"/File/_Save", (char *)"<control>S", menu_show, MENU_SAVE, (char *)"<StockItem>", GTK_STOCK_SAVE },
  117. { (char *)"/File/Save _As...", NULL, menu_show, MENU_SAVE_AS, (char *)"<StockItem>", GTK_STOCK_SAVE_AS },
  118. { (char *)"/File/sep", NULL, NULL, 0, (char *)"<Separator>", NULL },
  119. { (char *)"/File/_Quit", (char *)"<control>Q", menu_show, MENU_QUIT, (char *)"<StockItem>", GTK_STOCK_QUIT },
  120. { (char *)"/_Edit", NULL, NULL, 0, (char *)"<Branch>", NULL },
  121. { (char *)"/Edit/C_ut", (char *)"<control>X", menu_show, MENU_CUT, (char *)"<StockItem>", GTK_STOCK_CUT },
  122. { (char *)"/Edit/_Copy", (char *)"<control>C", menu_show, MENU_COPY, (char *)"<StockItem>", GTK_STOCK_COPY },
  123. { (char *)"/Edit/_Paste", (char *)"<control>V", menu_show, MENU_PASTE, (char *)"<StockItem>", GTK_STOCK_PASTE },
  124. { (char *)"/Edit/sep", NULL, NULL, 0, (char *)"<Separator>", NULL },
  125. { (char *)"/Edit/Select All", NULL, menu_show, MENU_SELECT_ALL, NULL, NULL },
  126. { (char *)"/_Search", NULL, NULL, 0, (char *)"<Branch>", NULL },
  127. { (char *)"/Search/_Find", (char *)"<control>F" , menu_show, MENU_FIND,(char *)"<StockItem>", GTK_STOCK_FIND },
  128. { (char *)"/Search/_Replace", (char *)"<control>R" , menu_show, MENU_REPLACE,(char *)"<StockItem>", GTK_STOCK_FIND },
  129. { (char *)"/_Help", NULL, NULL, 0, (char *)"<Branch>", NULL },
  130. { (char *)"/Help/_Contents", (char *)"<control>H", menu_show, MENU_HELP, (char *)"<StockItem>", GTK_STOCK_HELP },
  131. { (char *)"/Help/_About", NULL , menu_show, MENU_ABOUT, "<Item>" },
  132.  
  133. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement