menus.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            menus.c
00003  *
00004  *  Sun Sep 24 12:12:13 2006
00005  *  Copyright  2006-2007  Neil Williams
00006  *  linux@codehelp.co.uk
00007  ****************************************************************************/
00012 /*
00013     This package is free software; you can redistribute it and/or modify
00014     it under the terms of the GNU General Public License as published by
00015     the Free Software Foundation; either version 3 of the License, or
00016     (at your option) any later version.
00017 
00018     This program is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021     GNU General Public License for more details.
00022 
00023     You should have received a copy of the GNU General Public License
00024     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025 */
00026 
00027 #include "config.h"
00028 
00029 #include <glib.h>
00030 #include <gtk/gtk.h>
00031 #include <gtkextra/gtksheet.h>
00032 #include "types.h"
00033 #include "menus.h"
00034 #include "field.h"
00035 #include "filein.h"
00036 #include "fileout.h"
00037 #include "edit.h"
00038 #include "main.h"
00039 #include "sort.h"
00040 #include "help.h"
00041 #include "filter.h"
00042 #include "report.h"
00043 #include "tools.h"
00044 #include "xmlmenu.h"
00045 
00046 #define _(String) String
00047 
00050 static GtkActionEntry entries[] = {
00051     /* name, stock id, label */
00052     {"FileMenuAction", NULL, _("_File"), NULL, NULL, NULL},
00053     {"RecentMenuAction", NULL, _("Re_cent"), NULL, NULL, NULL},
00054     {"EditMenuAction", NULL, _("_Edit"), NULL, NULL, NULL},
00055     {"SortMenuAction", NULL, _("_Sort"), NULL, NULL, NULL},
00056     {"FilterMenuAction", NULL, _("_Filter"), NULL, NULL, NULL},
00057     {"ReportMenuAction", NULL, _("_Report"), NULL, NULL, NULL},
00058     {"ColumnMenuAction", NULL, _("_Column"), NULL, NULL, NULL},
00059 /*  {"ToolsMenuAction", NULL, _("_Tools"), NULL, NULL, NULL},*/
00060     /* tools replaces totals and vice versa */
00061     {"TotalsMenuAction", NULL, _("_Totals"), NULL, NULL, NULL},
00062     {"ReportColumnAction", NULL, _("_Column"), NULL, NULL, NULL},
00063     {"HelpMenuAction", NULL, _("_Help"), NULL, NULL, NULL},
00064 
00065     {"NewFileAction", GTK_STOCK_NEW, _("_New"),
00066             "<Control>N", _("Create a new list"),
00067         G_CALLBACK (new_file)},
00068     {"OpenFileAction", GTK_STOCK_OPEN,
00069             _("_Open"), "<Control>O",
00070         _("Open an existing list"), G_CALLBACK (open_file)},
00071     {"OpenRecentAction", NULL, _("Re_cent"), NULL, NULL, NULL},
00072     {"CloseFileAction", GTK_STOCK_CLOSE, _("_Close"), "<Control>W",
00073         _("Close this list"), G_CALLBACK (close_file)},
00074     {"SaveFileAction", GTK_STOCK_SAVE, _("_Save"), "<Control>S",
00075         _("Save the list"), G_CALLBACK (save_file)},
00076     {"SaveAsFileAction", GTK_STOCK_SAVE_AS, _("Save _As ..."), "",
00077         _("Save the list as a new file"), G_CALLBACK (save_as)},
00078     {"ImportFileAction", NULL, _("_Import..."), "",
00079         _("Import data for this list"), G_CALLBACK (file_import)},
00080     {"ExportFileAction", GTK_STOCK_CONVERT, _("_Export ..."), "",
00081         _("Export this list"), G_CALLBACK (file_export)},
00082     {"PrintFileAction", GTK_STOCK_PRINT, _("_Print"), "<Control>P",
00083         _("Print this report"), G_CALLBACK (print_cb)},
00084     {"PreviewFileAction", GTK_STOCK_PRINT_PREVIEW, _("Print Previe_w"),
00085         "<Control><Shift>P", _("Preview the printed report"),
00086         G_CALLBACK (print_preview_cb)},
00087     {"QuitAction", GTK_STOCK_QUIT, _("Quit QuickList"),
00088             "<control>Q", _("Quit the QuickList application"),
00089         G_CALLBACK (exit_action)},
00090     {"EditCutAction", GTK_STOCK_CUT, _("C_ut"), "<Control>X",
00091             _("Cut the selected cell to the clipboard"),
00092         G_CALLBACK (edit_cut)},
00093     {"EditCopyAction", GTK_STOCK_COPY, _("_Copy"), "<Control>C",
00094             _("Copy the selected cell to the clipboard"),
00095         G_CALLBACK (edit_copy)},
00096     {"EditCopyDownAction", NULL, _("Copy _Down"), "<alt>E",
00097             _("Copy the cell above into this cell"),
00098         G_CALLBACK (edit_ditto)},
00099     {"EditPasteAction", GTK_STOCK_PASTE, _("_Paste"), "<Control>V",
00100             _("Paste the clipboard contents into this cell"),
00101         G_CALLBACK (edit_paste)},
00102     {"EditClearAction", GTK_STOCK_CLEAR, _("C_lear"), "Delete",
00103             _("Clear the contents of this cell"),
00104         G_CALLBACK (edit_clear)},
00105     {"EditFillAction", GTK_STOCK_JUSTIFY_FILL, _("_Fill down"), "<Alt>D",
00106             _("Copy the top cell into the selected cells below"),
00107         G_CALLBACK (edit_fill_down)},
00108     {"EditAllAction", NULL, _("Select _All"), "<control>A",
00109             _("Select all cells in the list"),
00110         G_CALLBACK (edit_select_all)},
00111     {"EditInsertAction", NULL, _("_Insert a row"), "<alt>I",
00112             _("Insert a row beneath the current row"),
00113         G_CALLBACK (edit_insert_rows)},
00114     {"SortColumnAction", NULL, _("_Sort column"), "<alt>Y",
00115             _("Sort by column using the current pattern"),
00116         G_CALLBACK (sort_by_column)},
00119 /*  {"SortApplyAction", GTK_STOCK_APPLY, _("_Apply"), "",
00120         _("Apply the sort pattern"), G_CALLBACK (sort_apply)},
00121     {"SortAddAction", GTK_STOCK_ADD, _("Add _Pattern"), "",
00122         _("Add a sort pattern"), G_CALLBACK (sort_add)},
00123     {"SortEditAction", GTK_STOCK_EDIT, _("_Edit"), "",
00124         _("Edit a sort pattern"), G_CALLBACK (sort_edit)},
00125     {"SortDeleteAction", GTK_STOCK_DELETE, _("_Delete"), "",
00126         _("Delete a sort pattern"), G_CALLBACK (sort_delete)},*/
00127 /*  {"FilterShowAction", NULL, _("Show _All"), "",
00128             _("Show all available filters"),
00129         G_CALLBACK (filter_show_all)},
00130     {"FilterApplyAction", GTK_STOCK_APPLY, _("Apply _Filter"), "",
00131             _("Select and apply a filter"),
00132         G_CALLBACK (filter_apply)},*/
00133 /*  {"FilterAddAction", GTK_STOCK_ADD, _("_Add"), "",
00134         _("Add a new filter"), G_CALLBACK (filter_add)},
00135     {"FilterEditAction", GTK_STOCK_EDIT, _("_Edit"), "",
00136         _("Edit a filter"), G_CALLBACK (filter_edit)},
00137     {"FilterDeleteAction", GTK_STOCK_DELETE, _("_Delete"), "",
00138         _("Delete a filter"), G_CALLBACK (filter_delete)},*/
00139     {"ReportSelectAction", NULL, _("_Select"), "",
00140         _("Select a report to view"), G_CALLBACK (report_select)},
00141 /*  {"ReportAddAction", GTK_STOCK_ADD, _("_Add"), "",
00142         _("Add a new report"), G_CALLBACK (report_add)},*/
00143     {"ColumnAddAction", GTK_STOCK_ADD, _("_Add"), "",
00144         _("Add a column to the list"), G_CALLBACK (column_add)},
00145     {"ColumnEditAction", GTK_STOCK_EDIT, _("_Edit"), "",
00146             _("Edit the type of the selected column"),
00147         G_CALLBACK (column_edit)},
00148     {"ColumnDeleteAction", GTK_STOCK_DELETE, _("_Delete"), "",
00149             _("Delete the selected column"),
00150         G_CALLBACK (column_delete)},
00152     {"ColumnLeftAction", GTK_STOCK_GO_BACK, _("Move _Left"), "",
00153             _("Move the selected column left by one slot"),
00154         G_CALLBACK (column_left)},
00155     {"ColumnRightAction", GTK_STOCK_GO_FORWARD, _("Move _Right"), "",
00156             _("Move the selected column right by one slot"),
00157         G_CALLBACK (column_right)},
00158     {"ReportColumnAddAction", GTK_STOCK_ADD, _("_Add"), "",
00159         _("Add a new column"), G_CALLBACK (report_col_add)},
00160     {"ReportColumnDeleteAction", GTK_STOCK_DELETE, _("_Delete"),
00161             "", _("Delete column from report"),
00162         G_CALLBACK (report_col_del)},
00163     {"ReportColumnLeftAction", GTK_STOCK_GO_BACK, _("Move _Left"),
00164             "", _("Move the selected column left by one slot"),
00165         G_CALLBACK (report_col_left)},
00166     {"ReportColumnRightAction", GTK_STOCK_GO_FORWARD, _("Move _Right"),
00167             "", _("Move the selected column right by one slot"),
00168         G_CALLBACK (report_col_right)},
00169     {"ToolsFindAction", GTK_STOCK_FIND, _("_Find"), "<Alt>F",
00170         _("Search the list"), G_CALLBACK (tools_find)},
00172 /*  {"ToolsMatchAction", NULL, _("_Match"), "<Alt>M",
00173         _("Match tool"), G_CALLBACK (tools_match)},*/
00174 /*  {"TotalsGroupAction", NULL, _("_Group"), "<alt>G",
00175         _("Total by group"), G_CALLBACK (report_totals_group)},
00176     {"TotalsTotalsAction", NULL, _("_Totals"), "<Alt>T",
00177         _("Totals"), G_CALLBACK (report_totals_total)},*/
00178     {"HelpManualAction", GTK_STOCK_HELP, _("Manual"), "F1",
00179         _("User Manual"), G_CALLBACK (qlhelp_manual)},
00180     {"HelpAboutAction", GTK_STOCK_ABOUT, _("_About"), NULL,
00181         _("About QuickList"), G_CALLBACK (qlhelp_credits)}
00182 
00183 };
00184 static guint n_entries = G_N_ELEMENTS (entries);
00185 
00186 static void
00187 menu_add_widget (GtkUIManager G_GNUC_UNUSED * ui, GtkWidget * widget,
00188     GtkContainer * container)
00189 {
00190     gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
00191     gtk_widget_show (widget);
00192 }
00193 
00194 GtkWidget *
00195 build_list_mb (QlContext * qlc)
00196 {
00197     GtkAccelGroup *accel_group;
00198     GtkActionGroup *action_group;
00199     GError *error;
00200     GtkWidget *menubar, *menu_box;
00201     gchar *xmlmenupath;
00202     GList * items;
00203 
00204     items = NULL;
00205     error = NULL;
00206     xmlmenupath = g_strconcat (XMLMENUDIR, "/menus.xml", NULL);
00207     action_group = gtk_action_group_new ("QLActions");
00208     gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
00209     gtk_action_group_add_actions (action_group, entries, n_entries, qlc->parent);
00210 
00211     qlc->menu_manager = gtk_ui_manager_new ();
00212     gtk_ui_manager_insert_action_group (qlc->menu_manager, action_group, 0);
00213     gtk_ui_manager_set_add_tearoffs (qlc->menu_manager, TRUE);
00214 
00215     accel_group = gtk_ui_manager_get_accel_group (qlc->menu_manager);
00216     gtk_window_add_accel_group (GTK_WINDOW (qlc->parent), accel_group);
00217 
00218     gtk_ui_manager_add_ui_from_file (qlc->menu_manager, xmlmenupath, &error);
00219 
00220     if (error)
00221     {
00222         g_message ("building menus failed: %s", error->message);
00223         g_error_free (error);
00224     }
00225     menubar = gtk_menu_bar_new ();
00226 
00227     gtk_widget_show (menubar);
00228     menu_box = gtk_vbox_new (FALSE, 0);
00229 
00230     g_signal_connect (qlc->menu_manager, "add_widget",
00231         G_CALLBACK (menu_add_widget), menu_box);
00232     g_free (xmlmenupath);
00233     return menu_box;
00234 }
00235 
00236 GtkWidget *
00237 build_report_mb (QlContext * qlc)
00238 {
00239     GtkAccelGroup *accel_group;
00240     GtkActionGroup *action_group;
00241     GError *error;
00242     GtkWidget *menubar, *menu_box;
00243     gchar *xmlmenupath;
00244 
00245     xmlmenupath = g_strconcat (XMLMENUDIR, "/reports.xml", NULL);
00246     action_group = gtk_action_group_new ("QLActions");
00247     gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
00248     gtk_action_group_add_actions (action_group, entries, n_entries, NULL);
00249     accel_group = gtk_accel_group_new ();
00250     
00251     qlc->menu_manager = gtk_ui_manager_new ();
00252     gtk_ui_manager_insert_action_group (qlc->menu_manager, action_group, 0);
00253 
00254     error = NULL;
00255     gtk_ui_manager_add_ui_from_file (qlc->menu_manager, xmlmenupath, &error);
00256 
00257     if (error)
00258     {
00259         g_message ("building menus failed: %s", error->message);
00260         g_error_free (error);
00261     }
00262     menubar = gtk_menu_bar_new ();
00263     gtk_widget_show (menubar);
00264     menu_box = gtk_vbox_new (FALSE, 0);
00265 
00266     g_signal_connect (qlc->menu_manager, "add_widget",
00267         G_CALLBACK (menu_add_widget), menu_box);
00268     g_free (xmlmenupath);
00269     return menu_box;
00270 }
00271 
00272 void
00273 menus_set_sensitive (QlContext * qlc, gchar * path, gboolean sensitive)
00274 {
00275     GtkWidget *menuitem;
00276 
00277     g_return_if_fail (qlc->menu_manager);
00278     menuitem = gtk_ui_manager_get_widget (qlc->menu_manager, path);
00279     if (menuitem)
00280         gtk_widget_set_sensitive (menuitem, sensitive);
00281     else
00282     {
00283         g_warning
00284             ("Unable to set sensitivity for a menu item "
00285             "which doesn't exist:\n%s", path);
00286     }
00287 }

Generated on Mon Jan 28 22:02:10 2008 for quicklist by  doxygen 1.5.4