dim_list_menu.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            dim_list_menu.c
00003  *
00004  *  Fri Aug 25 14:48:06 2006
00005  *  Copyright  2006-2007  Neil Williams
00006  *  linux@codehelp.co.uk
00007  ****************************************************************************/
00013 /*
00014     This package is free software; you can redistribute it and/or modify
00015     it under the terms of the GNU General Public License as published by
00016     the Free Software Foundation; either version 3 of the License, or
00017     (at your option) any later version.
00018 
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022     GNU General Public License for more details.
00023 
00024     You should have received a copy of the GNU General Public License
00025     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00026 */
00027 
00028 #include "config.h"
00029 #include <glib.h>
00030 #include <glib/gi18n.h>
00031 #include <gtk/gtk.h>
00032 #include <gtkextra/gtksheet.h>
00033 #include "types.h"
00034 #include "dim_list_menu.h"
00035 #include "menus.h"
00036 #include "main.h"
00037 #include "filein.h"
00038 #include "dialog_initial.h"
00039 
00040 static void
00041 dim_list_empty_menu (QlContext * qlc)
00042 {
00043     menus_set_sensitive (qlc, "/menubar/FileMenu/SaveAs", FALSE);
00044     menus_set_sensitive (qlc, "/menubar/FileMenu/Close", FALSE);
00045     menus_set_sensitive (qlc, "/menubar/FileMenu/Export", FALSE);
00046     menus_set_sensitive (qlc, "/menubar/FileMenu/Print", FALSE);
00047     menus_set_sensitive (qlc, "/menubar/FileMenu/Preview", FALSE);
00048     menus_set_sensitive (qlc, "/menubar/EditMenu/Selectall", FALSE);
00049 /*  menus_set_sensitive (qlc, "/menubar/SortMenu/SortAdd", FALSE);*/
00050 /*  menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterShow", FALSE);
00051     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterAdd", FALSE);*/
00052 /*  menus_set_sensitive (qlc, "/menubar/ReportMenu/ReportAdd", FALSE);*/
00053     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnAdd", FALSE);
00054 /*  menus_set_sensitive (qlc, "/menubar/ToolsMenu/ToolsFind", FALSE);
00055     menus_set_sensitive (qlc, "/menubar/ToolsMenu/ToolsMatch", FALSE);*/
00056     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Print", FALSE);
00057     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Preview", FALSE);
00058 }
00059 
00060 void
00061 dim_list_tab_open_menu (QlContext * qlc)
00062 {
00063     menus_set_sensitive (qlc, "/menubar/FileMenu/SaveAs", TRUE);
00064     menus_set_sensitive (qlc, "/menubar/FileMenu/Close", TRUE);
00065     menus_set_sensitive (qlc, "/menubar/FileMenu/Export", TRUE);
00066     menus_set_sensitive (qlc, "/menubar/EditMenu/Selectall", TRUE);
00067 /*  menus_set_sensitive (qlc, "/menubar/SortMenu/SortAdd", TRUE);
00068     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterShow", TRUE);
00069     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterAdd", TRUE);
00070     menus_set_sensitive (qlc, "/menubar/ReportMenu/ReportAdd", TRUE);*/
00071     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnAdd", TRUE);
00072 /*  menus_set_sensitive (qlc, "/menubar/ToolsMenu/ToolsFind", TRUE);
00073     menus_set_sensitive (qlc, "/menubar/ToolsMenu/ToolsMatch", TRUE);*/
00074 }
00075 
00076 void
00077 dim_all_menus (QlContext * qlc)
00078 {
00079     QlDisplayMode mode;
00080     QlTabData * tab;
00081     GtkWidget *menuitem, * recentmenu;
00082     GtkRecentFilter * filter;
00083 
00084     tab = NULL;
00085     g_return_if_fail (qlc);
00086     tab = ql_get_tabdata (qlc);
00087     if (tab == NULL)
00088         mode = DISPLAY_EMPTY;
00089     else
00090         mode = tab->view->display_mode;
00091     switch (mode)
00092     {
00093         case DISPLAY_LIST :
00094         {
00095             dim_list_file_menu (qlc);
00096             dim_list_edit_menu (qlc);
00097             dim_list_sort_menu (qlc);
00098             dim_list_filter_menu (qlc);
00099             dim_list_report_menu (qlc);
00100             dim_list_column_menu (qlc);
00101             dim_list_tab_open_menu (qlc);
00102             break;
00103         }
00104         case DISPLAY_REPORT :
00105         case DISPLAY_EDIT : /* don't do if print on screen */
00106         {
00107             dim_report_file_menu (qlc);
00108             dim_report_column_menu (qlc);
00109             dim_report_totals_menu (qlc);
00110             dim_list_tab_open_menu (qlc);
00111             break;
00112         }
00113         case DISPLAY_EMPTY :
00114         {
00115             dim_list_file_menu (qlc);
00116             dim_list_edit_menu (qlc);
00117             dim_list_sort_menu (qlc);
00118             dim_list_filter_menu (qlc);
00119             dim_list_report_menu (qlc);
00120             dim_list_column_menu (qlc);
00121             dim_list_empty_menu (qlc);
00122             break;
00123         }
00124         case DISPLAY_PRINT : 
00125         {
00126             dim_list_tab_open_menu (qlc);
00127             break;
00128         }
00129     }
00130     menuitem = gtk_ui_manager_get_widget (qlc->menu_manager, 
00131             "/menubar/FileMenu/RecentMenu");
00133     recentmenu = gtk_recent_chooser_menu_new_for_manager (qlc->recent_manager);
00134 /*  recentmenu = gtk_recent_chooser_menu_new ();
00135 */  filter = gtk_recent_filter_new ();
00136 /*  gtk_recent_filter_add_group (filter, PACKAGE);
00137     gtk_recent_filter_set_name (filter, _("QuickList files *.qlf"));
00138     gtk_recent_filter_add_pattern (filter, "file: *.qlf");
00139 //  gtk_recent_filter_add_mime_type (filter, "application/x-quicklist");
00140 //  gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recentmenu), GTK_RECENT_SORT_MRU);
00141     gtk_recent_chooser_set_show_not_found (GTK_RECENT_CHOOSER(recentmenu), TRUE);
00142     gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER(recentmenu), TRUE);
00143     gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER(recentmenu), filter);
00144 */  if (menuitem)
00145     {
00146         gtk_menu_item_set_submenu (GTK_MENU_ITEM(menuitem), recentmenu);
00147         g_signal_connect (GTK_OBJECT(recentmenu), "item-activated",
00148             G_CALLBACK(open_recent), qlc);
00149     }
00150     else
00151         g_message ("failed to initialise recent files submenu.");
00152 }
00153 
00154 void
00155 dim_list_file_menu (QlContext * qlc)
00156 {
00157     QlTabData * tab;
00158     gboolean new = TRUE;
00159     gboolean open = TRUE;
00160     gboolean import = TRUE;
00161     gboolean changed = FALSE;
00162 
00163     tab = ql_get_tabdata (qlc);
00164     if (tab)
00165         changed = tab->file->changed;
00166     menus_set_sensitive (qlc, "/menubar/FileMenu/Newlist", new);
00167     menus_set_sensitive (qlc, "/menubar/FileMenu/Open", open);
00168     menus_set_sensitive (qlc, "/menubar/FileMenu/Save", changed);
00169     menus_set_sensitive (qlc, "/menubar/FileMenu/Import", import);
00170     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Newlist", new);
00171     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Open", open);
00172     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Save", changed);
00173 }
00174 
00175 void
00176 dim_list_edit_menu (QlContext * qlc)
00177 {
00178     QlTabData * tab;
00179     gboolean cut = FALSE;
00180     gboolean clear = FALSE;
00181     gboolean copy = FALSE;
00182     gboolean ditto = FALSE;
00183     gboolean paste = FALSE;
00184     gboolean fill = FALSE;
00185     gboolean insert = FALSE;
00186     QlSelectMode sel_type = 0;
00187 
00188     tab = ql_get_tabdata (qlc);
00189     if (tab)
00190         sel_type = tab->view->sel_type;
00191     if (sel_type)
00192     {
00193         clear = copy = cut = paste = TRUE;
00194         if (tab->view->sel_range.rowi != tab->view->sel_range.row0)
00195             fill = TRUE;
00196         if (tab->view->sel_type == SELECT_ENTRY)
00197             ditto = TRUE;
00198         if (tab->view->sel_type != SELECT_COLUMN)
00199             insert = TRUE;
00200     }
00201     menus_set_sensitive (qlc, "/menubar/EditMenu/Cut", cut);
00202     menus_set_sensitive (qlc, "/menubar/EditMenu/Copy", copy);
00203     menus_set_sensitive (qlc, "/menubar/EditMenu/Copydown", ditto);
00204     menus_set_sensitive (qlc, "/menubar/EditMenu/Clear", clear);
00205     menus_set_sensitive (qlc, "/menubar/EditMenu/Filldown", fill);
00206     menus_set_sensitive (qlc, "/menubar/EditMenu/Insertrows", insert);
00207     menus_set_sensitive (qlc, "/menubar/EditMenu/Paste", 
00208         paste_is_ok (tab));
00209 
00210     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Cut", cut);
00211     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Copy", copy);
00212     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Clear", clear);
00213     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Paste", 
00214         paste_is_ok (tab));
00215 }   /* End of list_dim_edit */
00216 
00217 void
00218 dim_list_sort_menu (QlContext * qlc)
00219 {
00220     QlTabData * tab;
00221     gboolean add = FALSE;
00222     gboolean column = FALSE;
00223     gboolean apply = FALSE;
00224     gboolean edit = FALSE;
00225     gboolean delete = FALSE;
00226 
00227     tab = ql_get_tabdata (qlc);
00228     if (tab)
00229     {
00230         if (tab->view->sel_type == SELECT_COLUMN || 
00231                 tab->view->sel_type == SELECT_ENTRY)
00232             column = TRUE;
00233     
00234         if (tab->file->sort_ct)
00235             apply = edit = delete = TRUE;
00236     
00237         if (tab->file->sort_ct < MAX_SORTS)
00238             add = TRUE;
00239     
00240         /* ie, need two real rows plus last row */
00241         if (tab->file->last_row <= 1)
00242             apply = column = FALSE;
00243     }
00244 
00245 /*  menus_set_sensitive (qlc, "/menubar/SortMenu/SortAdd", add);
00246     menus_set_sensitive (qlc, "/menubar/SortMenu/SortApply", apply);
00247     menus_set_sensitive (qlc, "/menubar/SortMenu/SortEdit", edit);
00248     menus_set_sensitive (qlc, "/menubar/SortMenu/SortDelete", delete);*/
00249     menus_set_sensitive (qlc, "/menubar/SortMenu/SortColumn", column);
00250 }   /* end of dim_list_sort_menu */
00251 
00252 void
00253 dim_list_filter_menu (QlContext * qlc)
00254 {
00255     QlTabData * tab;
00256     gboolean show = FALSE;
00257     gboolean apply = FALSE;
00258     gboolean edit = FALSE;
00259     gboolean delete = FALSE;
00260 //  gboolean add = FALSE;
00261 
00262     tab = ql_get_tabdata (qlc);
00263     show = TRUE;
00264 
00265     if (tab)
00266     {
00267         if (tab->file->filter_ct)
00268             apply = edit = delete = TRUE;
00269     }
00270 /*
00271     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterShow", show);
00272     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterApply", apply);
00273     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterEdit", edit);
00274     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterDelete", delete);
00275     menus_set_sensitive (qlc, "/menubar/FilterMenu/FilterAdd", add);*/
00276 }   /* end of dim_list_filter_menu */
00277 
00278 void
00279 dim_list_report_menu (QlContext * qlc)
00280 {
00281     QlTabData * tab;
00282     gboolean mselect = FALSE;
00283 //  gboolean add = FALSE;
00284 
00285     tab = ql_get_tabdata (qlc);
00286     if (tab)
00287     {
00288         if (tab->file->report_ct > 0)
00289         {
00290             mselect = TRUE;
00291         }
00292     }
00293     menus_set_sensitive (qlc, "/menubar/FileMenu/Print", TRUE);
00294     menus_set_sensitive (qlc, "/menubar/FileMenu/Preview", TRUE);
00295     menus_set_sensitive (qlc, "/menubar/ReportMenu/ReportSelect", mselect);
00296 /*  menus_set_sensitive (qlc, "/menubar/ReportMenu/ReportAdd", add);*/
00297 }   /* end of dim_list_report_menu */
00298 
00299 void
00300 dim_list_column_menu (QlContext * qlc)
00301 {
00302     QlTabData * tab;
00303     gboolean add = FALSE;
00304     gboolean edit = FALSE;
00305     gboolean delete = FALSE;
00306     gboolean right = FALSE;
00307     gboolean left = FALSE;
00308 
00309     tab = ql_get_tabdata (qlc);
00310     if (tab)
00311     {
00312         if (tab->view->sel_range.col0 == tab->view->sel_range.coli)
00313         {
00314             if (tab->file->last_field < MAX_FIELDS - 1)
00315                 add = TRUE;
00316             if (tab->view->sel_type == SELECT_COLUMN)
00317             {
00318                 edit = TRUE;
00319                 if (tab->file->last_field)
00320                 {                   /* ie two or more fields */
00321                     delete = TRUE;
00322                     if (tab->view->sel_range.coli < tab->file->last_field)
00323                         right = TRUE;
00324                     if (tab->view->sel_range.col0)
00325                         left = TRUE;
00326                 }
00327             }
00328         }
00329     }
00330     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnAdd", add);
00331     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnEdit", edit);
00332     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnDelete", delete);
00333     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnLeft", left);
00334     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnRight", right);
00335 }   /* end of dim_list_column_menu */
00336 
00337 void
00338 dim_report_file_menu (QlContext * qlc)
00339 {
00340     QlTabData * tab;
00341     gboolean new = FALSE;
00342     gboolean open = FALSE;
00343     gboolean import = FALSE;
00344 
00345     tab = ql_get_tabdata (qlc);
00346 
00347     menus_set_sensitive (qlc, "/menubar/FileMenu/Newlist", new);
00348     menus_set_sensitive (qlc, "/menubar/FileMenu/Open", open);
00349     menus_set_sensitive (qlc, "/menubar/FileMenu/Save", 
00350         tab->file->changed);
00351     menus_set_sensitive (qlc, "/menubar/FileMenu/Import", import);
00352     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Newlist", new);
00353     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Open", open);
00354     menus_set_sensitive (qlc, "/MainMenuBar/ToolItems/Save", 
00355         tab->file->changed);
00356 }
00357 
00358 void
00359 dim_report_column_menu (QlContext * qlc)
00360 {
00361     QlTabData * tab;
00362     gboolean rep_add = FALSE;
00363     gboolean rep_delete = FALSE;
00364     gboolean rep_right = FALSE;
00365     gboolean rep_left = FALSE;
00366 
00367     tab = ql_get_tabdata (qlc);
00368     if (tab->file->report_ptr->last_column < MAX_FIELDS - 1)
00369         rep_add = TRUE;
00370 
00371     if (tab->view->report_sel_col >= 0)
00372         if (tab->file->report_ptr->last_column)
00373         {
00374             /* ie two or more columns */
00375             rep_delete = TRUE;
00376             if (tab->view->report_sel_col < tab->file->report_ptr->last_column)
00377                 rep_right = TRUE;
00378             if (tab->view->report_sel_col)
00379                 rep_left = TRUE;
00380         }
00381     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnAdd", rep_add);
00382     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnDelete", rep_delete);
00383     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnRight", rep_right);
00384     menus_set_sensitive (qlc, "/menubar/ColumnMenu/ColumnLeft", rep_left);
00385 }   /* end of dim_report_column_menu */
00386 
00387 void
00388 dim_report_totals_menu (QlContext * qlc)
00389 {
00390     QlTabData * tab;
00391     gboolean group = FALSE;
00392     gboolean total = FALSE;
00393 
00394     tab = ql_get_tabdata (qlc);
00395     if (tab->view->report_sel_col >= 0)
00396     {
00397         QlFieldInfo * field;
00398         group = TRUE;
00399         field = ql_get_fieldinfo (tab, tab->view->report_sel_field);
00400         if (field->type == 2)
00401             total = TRUE;
00402     }
00403 /*
00404     menus_set_sensitive (qlc, "/menubar/TotalsMenu/TotalsGroup", group);
00405     menus_set_sensitive (qlc, "/menubar/TotalsMenu/TotalsTotals", total);*/
00406 }   /* end of dim_report_totals_menu */
00407 
00408 gboolean
00409 paste_is_ok (QlTabData * tab)
00410 {
00411     QlSelectMode sel_type = SELECT_NONE;
00412     if (!tab)
00413         return FALSE;
00414     if (tab)
00415         sel_type = tab->view->sel_type;
00416 /*  if (!tab->view->sel_type || !cb_sel_type)
00417         return FALSE;*/
00418     switch (sel_type)
00419     {
00420     case SELECT_ROW:
00421         if (tab->view->sel_type == SELECT_COLUMN)
00422             return FALSE;
00423 
00424     case SELECT_COLUMN:
00425         if (tab->view->sel_type != SELECT_COLUMN)
00426             return FALSE;
00427 
00428     case SELECT_BLOCK:
00429         if (tab->view->sel_type != SELECT_BLOCK && 
00430                 tab->view->sel_type != SELECT_ENTRY)
00431             return FALSE;
00432 
00433     case SELECT_ENTRY:
00434         if (tab->view->sel_type != SELECT_ENTRY)
00435             return FALSE;
00436     
00437     default :
00438         return TRUE;
00439     }
00440 }   /* end of paste_is_ok */

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