gmc-window.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* Toplevel file window for the Midnight Commander
  2. *
  3. * Copyright (C) 1998 The Free Software Foundation
  4. *
  5. * Author: Federico Mena <federico@nuclecu.unam.mx>
  6. */
  7. /* #include <config.h> */
  8. #include <gnome.h>
  9. #include "gdesktop.h"
  10. #include "gmc-window.h"
  11. /* Magic numbers */
  12. #define ICON_LIST_SEPARATORS " /-_."
  13. #define ICON_LIST_ROW_SPACING 2
  14. #define ICON_LIST_COL_SPACING 2
  15. #define ICON_LIST_ICON_BORDER 2
  16. #define ICON_LIST_TEXT_SPACING 2
  17. static void gmc_window_init (GmcWindow *gmc);
  18. /**
  19. * gmc_window_get_type:
  20. *
  21. * Returns the unique Gtk type assigned to the GmcWindow widget.
  22. *
  23. * Return Value: the type ID of the GmcWindow widget.
  24. **/
  25. GtkType
  26. gmc_window_get_type (void)
  27. {
  28. static GtkType gmc_window_type = 0;
  29. if (!gmc_window_type) {
  30. GtkTypeInfo gmc_window_info = {
  31. "GmcWindow",
  32. sizeof (GmcWindow),
  33. sizeof (GmcWindowClass),
  34. (GtkClassInitFunc) NULL,
  35. (GtkObjectInitFunc) gmc_window_init,
  36. NULL, /* reserved_1 */
  37. NULL, /* reserved_2 */
  38. (GtkClassInitFunc) NULL
  39. };
  40. gmc_window_type = gtk_type_unique (gnome_app_get_type (), &gmc_window_info);
  41. }
  42. return gmc_window_type;
  43. }
  44. /* Displays GMC's About dialog */
  45. static void
  46. about_dialog (GtkWidget *widget, gpointer data)
  47. {
  48. GtkWidget *about;
  49. const gchar *authors[] = {
  50. "The Midnight Commander Team",
  51. "http://www.gnome.org/mc",
  52. "Bug reports: mc-bugs@nuclecu.unam.mx",
  53. NULL
  54. };
  55. about = gnome_about_new (_("GNU Midnight Commander"), VERSION,
  56. _("Copyright (C) 1998 The Free Software Foundation"),
  57. authors,
  58. _("The GNOME edition of the Midnight Commander file manager."),
  59. NULL);
  60. gnome_dialog_run_modal (GNOME_DIALOG (about));
  61. }
  62. /* FIXME: put in the callbacks */
  63. /* File menu */
  64. static GnomeUIInfo file_menu[] = {
  65. { GNOME_APP_UI_ITEM, N_("Open _new window"), NULL, NULL, NULL, NULL,
  66. GNOME_APP_PIXMAP_NONE, NULL, 'n', GDK_CONTROL_MASK, NULL },
  67. GNOMEUIINFO_SEPARATOR,
  68. { GNOME_APP_UI_ITEM, N_("_Close this window"), NULL, NULL, NULL, NULL,
  69. GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_CLOSE, 'w', GDK_CONTROL_MASK, NULL },
  70. { GNOME_APP_UI_ITEM, N_("E_xit"), NULL, NULL, NULL, NULL,
  71. GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_EXIT, 'q', GDK_CONTROL_MASK, NULL },
  72. GNOMEUIINFO_END
  73. };
  74. /* View types radioitem list */
  75. static GnomeUIInfo view_list_types_radioitems[] = {
  76. GNOMEUIINFO_ITEM_NONE (N_("_Listing view"), NULL, NULL),
  77. GNOMEUIINFO_ITEM_NONE (N_("_Icon view"), NULL, NULL),
  78. GNOMEUIINFO_END
  79. };
  80. /* View menu */
  81. static GnomeUIInfo view_menu[] = {
  82. GNOMEUIINFO_TOGGLEITEM (N_("Display _tree view"), NULL, NULL, NULL),
  83. GNOMEUIINFO_SEPARATOR,
  84. GNOMEUIINFO_RADIOLIST (view_list_types_radioitems),
  85. GNOMEUIINFO_END
  86. };
  87. /* Help menu */
  88. static GnomeUIInfo help_menu[] = {
  89. { GNOME_APP_UI_ITEM, N_("_About the Midnight Commander..."), NULL, about_dialog, NULL, NULL,
  90. GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT, 0, 0, NULL },
  91. GNOMEUIINFO_END
  92. };
  93. /* Main menu */
  94. static GnomeUIInfo main_menu[] = {
  95. GNOMEUIINFO_SUBTREE (N_("_File"), file_menu),
  96. GNOMEUIINFO_SUBTREE (N_("_View"), view_menu),
  97. GNOMEUIINFO_SUBTREE (N_("_Help"), help_menu),
  98. GNOMEUIINFO_END
  99. };
  100. /* Sets up the menu bar for a gmc window */
  101. static void
  102. setup_menus (GmcWindow *gmc)
  103. {
  104. gnome_app_create_menus_with_data (GNOME_APP (gmc), main_menu, gmc);
  105. }
  106. /* Sets up the toolbar for a gmc window */
  107. static void
  108. setup_toolbar (GmcWindow *gmc)
  109. {
  110. /* FIXME */
  111. }
  112. /* Sets up the contents for a gmc window */
  113. static void
  114. setup_contents (GmcWindow *gmc)
  115. {
  116. /* Paned container */
  117. gmc->paned = gtk_hpaned_new ();
  118. gnome_app_set_contents (GNOME_APP (gmc), gmc->paned);
  119. gtk_widget_show (gmc->paned);
  120. /* Tree view */
  121. gmc->tree = gtk_button_new_with_label ("Look at me!\nI am a nice tree!");
  122. gtk_paned_add1 (GTK_PANED (gmc->paned), gmc->tree);
  123. gtk_widget_show (gmc->tree);
  124. /* Notebook */
  125. gmc->notebook = gtk_notebook_new ();
  126. gtk_notebook_set_show_tabs (GTK_NOTEBOOK (gmc->notebook), FALSE);
  127. gtk_notebook_set_show_border (GTK_NOTEBOOK (gmc->notebook), FALSE);
  128. gtk_paned_add2 (GTK_PANED (gmc->paned), gmc->notebook);
  129. gtk_widget_show (gmc->notebook);
  130. /* List view */
  131. gmc->clist_sw = gtk_scrolled_window_new (NULL, NULL);
  132. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (gmc->clist_sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  133. gtk_notebook_append_page (GTK_NOTEBOOK (gmc->notebook), gmc->clist_sw, NULL);
  134. gtk_widget_show (gmc->clist_sw);
  135. gmc->clist = gtk_clist_new (1); /* FIXME: how many columns? */
  136. gtk_container_add (GTK_CONTAINER (gmc->clist_sw), gmc->clist);
  137. gtk_widget_show (gmc->clist);
  138. /* Icon view */
  139. gmc->ilist_sw = gtk_scrolled_window_new (NULL, NULL);
  140. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (gmc->ilist_sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  141. gtk_notebook_append_page (GTK_NOTEBOOK (gmc->notebook), gmc->ilist_sw, NULL);
  142. gtk_widget_show (gmc->ilist_sw);
  143. gmc->ilist = gnome_icon_list_new (DESKTOP_SNAP_X, NULL, TRUE);
  144. gnome_icon_list_set_separators (GNOME_ICON_LIST (gmc->ilist), ICON_LIST_SEPARATORS);
  145. gnome_icon_list_set_row_spacing (GNOME_ICON_LIST (gmc->ilist), ICON_LIST_ROW_SPACING);
  146. gnome_icon_list_set_col_spacing (GNOME_ICON_LIST (gmc->ilist), ICON_LIST_COL_SPACING);
  147. gnome_icon_list_set_icon_border (GNOME_ICON_LIST (gmc->ilist), ICON_LIST_ICON_BORDER);
  148. gnome_icon_list_set_text_spacing (GNOME_ICON_LIST (gmc->ilist), ICON_LIST_TEXT_SPACING);
  149. gnome_icon_list_set_selection_mode (GNOME_ICON_LIST (gmc->ilist), GTK_SELECTION_MULTIPLE);
  150. GTK_WIDGET_SET_FLAGS (gmc->ilist, GTK_CAN_FOCUS);
  151. gtk_container_add (GTK_CONTAINER (gmc->ilist_sw), gmc->ilist);
  152. gtk_widget_show (gmc->ilist);
  153. gtk_notebook_set_page (GTK_NOTEBOOK (gmc->notebook), gmc->list_type);
  154. /* FIXME: connect the clist/ilist signals, setup DnD, etc. */
  155. }
  156. /* Initializes the gmc window by creating all its contents */
  157. static void
  158. gmc_window_init (GmcWindow *gmc)
  159. {
  160. gmc->list_type = FILE_LIST_ICONS; /* FIXME: load this from the configuration */
  161. setup_menus (gmc);
  162. setup_toolbar (gmc);
  163. setup_contents (gmc);
  164. }
  165. /**
  166. * gmc_window_new:
  167. *
  168. * Creates a new GMC toplevel file window.
  169. *
  170. * Return Value: the newly-created window.
  171. **/
  172. GtkWidget *
  173. gmc_window_new (void)
  174. {
  175. return gtk_type_new (gmc_window_get_type ());
  176. }