Enlightenment CVS committal Author : andreas99 Project : e16 Module : tools
Dir : e16/tools/e16menuedit2/src Modified Files: Makefile.am callbacks.c callbacks.h e16menuedit2.c e16menuedit2.h file.c file.h Added Files: e16menu.c e16menu.h icon_chooser.c icon_chooser.h toolbar.c toolbar.h treeview.c treeview.h Log Message: - splited in more files for easier maintain - prepared source for menu and pop-up menu =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- Makefile.am 25 Jul 2004 17:21:51 -0000 1.1 +++ Makefile.am 28 Jul 2004 22:12:28 -0000 1.2 @@ -20,7 +20,15 @@ e16menuedit2.h\ file.c\ file.h\ - nls.h + nls.h\ + icon_chooser.c\ + icon_chooser.h\ + e16menu.c\ + e16menu.h\ + treeview.c\ + treeview.h\ + toolbar.c\ + toolbar.h e16menuedit2_LDFLAGS = =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/callbacks.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- callbacks.c 28 Jul 2004 12:33:22 -0000 1.5 +++ callbacks.c 28 Jul 2004 22:12:28 -0000 1.6 @@ -1,3 +1,29 @@ +/* Copyright (C) 2004 Andreas Volz and various contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * File: callbacks.c + * Created by: Andreas Volz <[EMAIL PROTECTED]> + * + */ + #ifdef HAVE_CONFIG_H # include <config.h> #endif @@ -8,349 +34,52 @@ #include "callbacks.h" #include "e16menuedit2.h" #include "file.h" +#include "icon_chooser.h" +#include "e16menu.h" +#include "treeview.h" -void on_file1_activate (GtkMenuItem *menuitem, +void on_menu_save_activate (GtkMenuItem *menuitem, gpointer user_data) { + GtkWidget *treeview_menu; + treeview_menu = (GtkWidget*) user_data; + save_table_to_menu (treeview_menu); } -void on_save1_activate (GtkMenuItem *menuitem, +void on_menu_quit_activate (GtkMenuItem *menuitem, gpointer user_data) { - g_print ("menu save not yet available!\n"); + gtk_main_quit (); } void on_new_button (GtkButton *button, gpointer user_data) { GtkWidget *treeview_menu; - GtkTreeModel *model; - GtkTreeSelection *select; - GtkTreeIter sibling; - GtkTreeIter new_iter; - GtkTreeIter root_iter; - gchar *empty_desc, *empty_icon; - gchar *tree_string; treeview_menu = (GtkWidget*) user_data; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_menu)); - - select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_menu)); - - if (gtk_tree_selection_get_selected (select, &model, &sibling)) - { - empty_desc = g_strdup (_("New Entry")); - empty_icon = g_strdup (""); - - tree_string = gtk_tree_model_get_string_from_iter ( - GTK_TREE_MODEL(model), &sibling); - - if (!strcmp (tree_string, "0")) - { - gtk_tree_model_get_iter_first (GTK_TREE_MODEL(model), &root_iter); - gtk_tree_store_append (GTK_TREE_STORE (model), &new_iter, &root_iter); - } - else - { - gtk_tree_store_insert_after (GTK_TREE_STORE (model), - &new_iter, - NULL, - &sibling); - } - - gtk_tree_store_set (GTK_TREE_STORE (model), &new_iter, - COL_DESCRIPTION, empty_desc, - COL_ICONNAME, empty_icon, - -1); - g_free (empty_desc); - g_free (empty_icon); - } + new_table_row (treeview_menu); } void on_change_icon_button (GtkButton *button, gpointer user_data) { - GtkWidget *main_window; - GtkWidget *dialog; - GtkWidget *filechooser; - GtkWidget *preview; - GtkWidget *treeview_menu; - GtkTreeModel *model; - GtkTreeSelection *select; - GdkPixbuf *icon_pixbuf; - GtkTreeIter iter; - GtkWidget *resize_combo; - GtkWidget *resize_hbox; - GtkWidget *dialog_vbox; - GtkWidget *resize_label; - GList *glist = NULL; - gint dialog_response; - - main_window = gtk_widget_get_toplevel (GTK_WIDGET(button)); - treeview_menu = (GtkWidget*) user_data; - preview = gtk_image_new (); - filechooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN); - gtk_widget_set_size_request (filechooser, 600, 400); - - dialog = gtk_dialog_new (); - gtk_window_set_title (GTK_WINDOW (dialog), _("Select Icon...")); - dialog_vbox = GTK_DIALOG(dialog)->vbox; - - gtk_dialog_add_button (GTK_DIALOG(dialog), - GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT); - gtk_dialog_add_button (GTK_DIALOG(dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG(dialog), - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT); - - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gtk_window_resize (GTK_WINDOW (dialog), 700, 500); - gtk_dialog_set_has_separator (GTK_DIALOG(dialog), TRUE); - - gtk_box_set_homogeneous (GTK_BOX (dialog_vbox), FALSE); - gtk_container_add (GTK_CONTAINER (dialog_vbox), - filechooser); - - gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (filechooser), - preview); - - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filechooser), - "/usr/share/pixmaps"); - - gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (filechooser), - TRUE); - - g_signal_connect (filechooser, "update-preview", - G_CALLBACK (update_preview_cb), preview); - - /* combo box */ - resize_hbox = gtk_hbox_new (FALSE, 0); - dialog_vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), - resize_hbox); - resize_combo = gtk_combo_new (); - resize_label = gtk_label_new (_("Icon size:")); - glist = g_list_append (glist, ICON_SIZE_AUTO_STRING); - glist = g_list_append (glist, ICON_SIZE1_STRING); - glist = g_list_append (glist, ICON_SIZE2_STRING); - glist = g_list_append (glist, ICON_SIZE3_STRING); - glist = g_list_append (glist, ICON_SIZE4_STRING); - glist = g_list_append (glist, ICON_SIZE5_STRING); - glist = g_list_append (glist, ICON_SIZE6_STRING); - glist = g_list_append (glist, ICON_SIZE7_STRING); - gtk_combo_set_popdown_strings (GTK_COMBO (resize_combo), glist); - gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (resize_combo)->entry), - "auto (64x64 limit)"); - gtk_box_pack_start (GTK_BOX (resize_hbox), resize_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (resize_hbox), resize_combo, FALSE, FALSE, 0); - - gtk_widget_show_all (dialog); - - dialog_response = gtk_dialog_run (GTK_DIALOG (dialog)); - - switch (dialog_response) - { - /* select new icon */ - case GTK_RESPONSE_ACCEPT: - { - gchar *filename; - - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_menu)); - select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_menu)); - - if (gtk_tree_selection_get_selected (select, &model, &iter)) - { - const gchar *entry_select; - gint width, height; - gint width_new, height_new; - gchar filename_resized[PATH_MAX]; - gchar *right; - - entry_select = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO ( - resize_combo)->entry)); - - /* temporary fix for probability broken librsvg function. - * it should autodetect librsvg version... - */ - right = g_malloc (3); - strsplit (filename, &right, g_utf8_strlen (filename, -1) - 3); - if (strcmp (right, "svg")) - { - gdk_pixbuf_get_file_info (filename, - &width, - &height); - } - else - { - width = ICON_SIZE_AUTO; - height = ICON_SIZE_AUTO; - } - g_free (right); - - if (width <= 0) - width = 1; - if (height <= 0) - height = 1; - - if (!strcmp (entry_select, ICON_SIZE_AUTO_STRING)) - { - if ((width > ICON_SIZE_AUTO) || (height > ICON_SIZE_AUTO)) - { - width_new = ICON_SIZE_AUTO; - height_new = ICON_SIZE_AUTO; - } - else - { - width_new = width; - height_new = height; - } - } - else if (!strcmp (entry_select, ICON_SIZE1_STRING)) - { - width_new = ICON_SIZE1; - height_new = ICON_SIZE1; - } - else if (!strcmp (entry_select, ICON_SIZE2_STRING)) - { - width_new = ICON_SIZE2; - height_new = ICON_SIZE2; - } - else if (!strcmp (entry_select, ICON_SIZE3_STRING)) - { - width_new = ICON_SIZE3; - height_new = ICON_SIZE3; - } - else if (!strcmp (entry_select, ICON_SIZE4_STRING)) - { - width_new = ICON_SIZE4; - height_new = ICON_SIZE4; - } - else if (!strcmp (entry_select, ICON_SIZE5_STRING)) - { - width_new = ICON_SIZE5; - height_new = ICON_SIZE5; - } - else if (!strcmp (entry_select, ICON_SIZE6_STRING)) - { - width_new = ICON_SIZE6; - height_new = ICON_SIZE6; - } - else if (!strcmp (entry_select, ICON_SIZE7_STRING)) - { - width_new = ICON_SIZE7; - height_new = ICON_SIZE7; - } - - if ((width == width_new) && (height == height_new)) - { - icon_pixbuf = gdk_pixbuf_new_from_file (filename, NULL); - } - else - { - icon_pixbuf = gdk_pixbuf_new_from_file_at_size (filename, - width_new, - height_new, - NULL); - - sprintf (filename_resized, "%s/%s/%s/%s_%dx%d.png", homedir (getuid ()), - APP_HOME, ICON_DIR, g_path_get_basename (filename), - width_new, height_new); - - g_free (filename); - filename = strdup (filename_resized); - - /*printf ("%s\n", filename);*/ - - gdk_pixbuf_save (icon_pixbuf, filename, "png", NULL, NULL); - } - - if (icon_pixbuf != NULL) - { - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COL_ICON, icon_pixbuf, - COL_ICONNAME, filename, - -1); - } - } - - g_free (filename); - break; - } - - /* delete current icon */ - case GTK_RESPONSE_REJECT: - { - gchar *filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_menu)); - select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_menu)); - - if (gtk_tree_selection_get_selected (select, &model, &iter)) - { - gtk_tree_model_get (model, &iter, - COL_ICON, &icon_pixbuf, - -1); - - if (icon_pixbuf != NULL) - { - g_object_unref (icon_pixbuf); - } - - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COL_ICON, NULL, - COL_ICONNAME, "", - -1); - - } - - g_free (filename); - break; - } - } - - gtk_widget_destroy (dialog); + open_icon_chooser ((GtkWidget *) user_data); } void on_save_button (GtkButton *button, gpointer user_data) { GtkWidget *treeview_menu; - GtkTreeModel *model; - int i = 0; treeview_menu = (GtkWidget*) user_data; - model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_menu)); - gtk_tree_model_foreach (GTK_TREE_MODEL(model), table_save_func, NULL); - - printf ("Menu saved!\n"); - - /* free allocated menu files */ - while (menu_file[i] != NULL) - { - g_free (menu_file[i]); - i++; - } + save_table_to_menu (treeview_menu); } void on_delete_button (GtkButton *button, gpointer user_data) { - GtkTreeIter iter; GtkWidget *treeview_menu; - GtkTreeModel *model; - GtkTreeSelection *select; treeview_menu = (GtkWidget*) user_data; - model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_menu)); - select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_menu)); - - if (gtk_tree_selection_get_selected (select, &model, &iter)) - { - gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); - } + delete_table_row (treeview_menu); } void on_descrenderer_edited (GtkCellRendererText *celltext, @@ -369,8 +98,6 @@ -1); g_free (desc); - - g_print ("edited\n"); } void on_paramsrenderer_edited (GtkCellRendererText *celltext, @@ -389,68 +116,10 @@ -1); g_free (params); - - g_print ("edited\n"); } void on_iconcolumn_clicked (GtkTreeViewColumn *treeviewcolumn, gpointer user_data) { - printf ("change icon\n"); -} - -void update_preview_cb (GtkFileChooser *file_chooser, gpointer data) -{ - GtkWidget *preview; - char *filename; - GdkPixbuf *pixbuf; - gboolean have_preview; - gint width, height; - - preview = GTK_WIDGET (data); - filename = gtk_file_chooser_get_preview_filename (file_chooser); - - if (filename != NULL) - { - gchar *right; - - /* temporary fix for probability broken librsvg function - * it should autodetect librsvg version... - */ - right = g_malloc (3); - strsplit (filename, &right, g_utf8_strlen (filename, -1) - 3); - - if (strcmp (right, "svg")) - { - gdk_pixbuf_get_file_info (filename, &width, &height); - } - else - { - width = ICON_SIZE_AUTO; - height = ICON_SIZE_AUTO; - } - g_free (right); - - if ((width > ICON_SIZE_AUTO) || (height > ICON_SIZE_AUTO)) - { - width = ICON_SIZE_AUTO; - height = ICON_SIZE_AUTO; - } - - if (width <= 0) - width = 1; - if (height <= 0) - height = 1; - - pixbuf = gdk_pixbuf_new_from_file_at_size (filename, width, height, NULL); - have_preview = (pixbuf != NULL); - g_free (filename); - - gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); - if (pixbuf) - gdk_pixbuf_unref (pixbuf); - - gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); - } } =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/callbacks.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- callbacks.h 27 Jul 2004 11:21:18 -0000 1.2 +++ callbacks.h 28 Jul 2004 22:12:28 -0000 1.3 @@ -1,12 +1,38 @@ +/* Copyright (C) 2004 Andreas Volz and various contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * File: callbacks.h + * Created by: Andreas Volz <[EMAIL PROTECTED]> + * + */ + #ifndef _CALLBACKS_H #define _CALLBACKS_H #include <gtk/gtk.h> -void on_file1_activate (GtkMenuItem *menuitem, +void on_menu_save_activate (GtkMenuItem *menuitem, gpointer user_data); -void on_save1_activate (GtkMenuItem *menuitem, - gpointer user_data); +void on_menu_quit_activate (GtkMenuItem *menuitem, + gpointer user_data); void on_new_button (GtkButton *button, gpointer user_data); void on_change_icon_button (GtkButton *button, gpointer user_data); void on_save_button (GtkButton *button, gpointer user_data); @@ -21,7 +47,6 @@ gpointer data); void on_iconcolumn_clicked (GtkTreeViewColumn *treeviewcolumn, gpointer user_data); -void update_preview_cb (GtkFileChooser *file_chooser, gpointer data); #define ICON_SIZE_AUTO_STRING "auto (64x64 limit)" #define ICON_SIZE1_STRING "64x64" =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- e16menuedit2.c 28 Jul 2004 12:33:22 -0000 1.3 +++ e16menuedit2.c 28 Jul 2004 22:12:28 -0000 1.4 @@ -1,5 +1,28 @@ -/* Created by Anjuta version 1.2.2 */ -/* This file will not be overwritten */ +/* Copyright (C) 2004 Andreas Volz and various contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * File: e16menuedit2.c + * Created by: Andreas Volz <[EMAIL PROTECTED]> + * + */ #include <unistd.h> #include <sys/types.h> @@ -7,11 +30,9 @@ #include "e16menuedit2.h" #include "file.h" #include "callbacks.h" - -static GtkTargetEntry row_targets[] = { - { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_APP, - TARGET_GTK_TREE_MODEL_ROW } -}; +#include "e16menu.h" +#include "treeview.h" +#include "toolbar.h" int main (int argc, char *argv[]) { @@ -19,7 +40,6 @@ GtkWidget *treeview_menu; GladeXML *main_xml; GtkWidget *toolbar1; - GtkToolItem *toolitem1; int i; char app_dir[PATH_MAX]; @@ -39,7 +59,6 @@ main_xml = glade_xml_new (PACKAGE_SOURCE_DIR"/e16menuedit2.glade", "main_window", NULL); - /* This is important */ glade_xml_signal_autoconnect (main_xml); main_window = glade_xml_get_widget (main_xml, "main_window"); @@ -53,59 +72,11 @@ treeview_menu = glade_xml_get_widget (main_xml, "treeview_menu"); create_tree_model (treeview_menu); - /* new entry toolbar button */ - toolbar1 = glade_xml_get_widget (main_xml, "toolbar1"); - toolitem1 = gtk_tool_button_new_from_stock (GTK_STOCK_NEW); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar1), toolitem1, TB_NEW); - gtk_widget_show (GTK_WIDGET (toolitem1)); - gtk_tool_item_set_tooltip (toolitem1, GTK_TOOLBAR (toolbar1)->tooltips, - _("New Entry"), ""); - g_signal_connect (toolitem1, "clicked", - G_CALLBACK (on_new_button), treeview_menu); - - /* change icon toolbar button */ - toolbar1 = glade_xml_get_widget (main_xml, "toolbar1"); - toolitem1 = gtk_tool_button_new_from_stock (GTK_STOCK_SELECT_COLOR); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar1), toolitem1, TB_CHANGE_ICON); - gtk_widget_show (GTK_WIDGET (toolitem1)); - gtk_tool_item_set_tooltip (toolitem1, GTK_TOOLBAR (toolbar1)->tooltips, - _("Change Icon"), ""); - g_signal_connect (toolitem1, "clicked", - G_CALLBACK (on_change_icon_button), treeview_menu); - - /* save toolbar button */ toolbar1 = glade_xml_get_widget (main_xml, "toolbar1"); - toolitem1 = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar1), toolitem1, TB_SAVE); - gtk_widget_show (GTK_WIDGET (toolitem1)); - gtk_tool_item_set_tooltip (toolitem1, GTK_TOOLBAR (toolbar1)->tooltips, - _("Save Menu"), ""); - g_signal_connect (toolitem1, "clicked", - G_CALLBACK (on_save_button), treeview_menu); - - /* delete toolbar button */ - toolitem1 = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar1), toolitem1, TB_DELETE); - gtk_widget_show (GTK_WIDGET (toolitem1)); - gtk_tool_item_set_tooltip (toolitem1, GTK_TOOLBAR (toolbar1)->tooltips, - _("Delete Entry or Submenu"), ""); - g_signal_connect (toolitem1, "clicked", - G_CALLBACK (on_delete_button), treeview_menu); - - /* quit toolbar button */ - toolitem1 = gtk_tool_button_new_from_stock (GTK_STOCK_QUIT); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar1), toolitem1, TB_QUIT); - gtk_widget_show (GTK_WIDGET (toolitem1)); - gtk_tool_item_set_tooltip (toolitem1, GTK_TOOLBAR (toolbar1)->tooltips, - _("Quit Menu Editor"), ""); - g_signal_connect (toolitem1, "clicked", - G_CALLBACK (gtk_main_quit), NULL); - + create_toolbar (toolbar1, treeview_menu); /* create initial directories */ - sprintf (app_dir, "%s/%s/%s", homedir (getuid ()), APP_HOME, ICON_DIR); - mkdir_with_parent (app_dir, 0755); gtk_widget_show (main_window); @@ -113,393 +84,3 @@ gtk_main (); return 0; } - -void create_tree_model (GtkWidget *treeview_menu) -{ - GtkCellRenderer *renderer_desc, *renderer_icon; - GtkCellRenderer *renderer_iconname, *renderer_params; - GtkTreeViewColumn *iconname_column, *icon_column; - GtkTreeModel *model; - - renderer_desc = gtk_cell_renderer_text_new (); - g_object_set (renderer_desc, "editable", TRUE, NULL); - gtk_tree_view_insert_column_with_attributes ( - GTK_TREE_VIEW (treeview_menu), - -1, - "Description", - renderer_desc, - "text", COL_DESCRIPTION, - NULL); - - renderer_icon = gtk_cell_renderer_pixbuf_new (); - icon_column = gtk_tree_view_column_new_with_attributes ( - "Icon", - renderer_icon, - "pixbuf", COL_ICON, - NULL); - gtk_tree_view_insert_column (GTK_TREE_VIEW (treeview_menu), - icon_column, -1); - - renderer_iconname = gtk_cell_renderer_text_new (); - iconname_column = gtk_tree_view_column_new_with_attributes ( - "Icon Name", - renderer_iconname, - "text", COL_ICONNAME, - NULL); - g_object_set (iconname_column, "visible", FALSE, NULL); - gtk_tree_view_insert_column (GTK_TREE_VIEW (treeview_menu), - iconname_column, -1); - - - renderer_params = gtk_cell_renderer_text_new (); - g_object_set (renderer_params, "editable", TRUE, NULL); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview_menu), - -1, - "Parameters", - renderer_params, - "text", COL_PARAMS, - NULL); - - model = load_menus_from_disk (); - - /* connect signals - to edit cell */ - g_signal_connect (renderer_desc, "edited", - G_CALLBACK (on_descrenderer_edited), model); - g_signal_connect (renderer_params, "edited", - G_CALLBACK (on_paramsrenderer_edited), model); - //g_signal_connect (icon_column, "clicked", - // G_CALLBACK (on_iconcolumn_clicked), model); - - gtk_tree_view_set_model (GTK_TREE_VIEW (treeview_menu), model); - - gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview_menu), - GDK_BUTTON1_MASK, - row_targets, - G_N_ELEMENTS (row_targets), - GDK_ACTION_MOVE | GDK_ACTION_COPY); - - gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview_menu), - row_targets, - G_N_ELEMENTS (row_targets), - GDK_ACTION_MOVE | GDK_ACTION_COPY); - - g_object_unref (model); /* destroy model automatically with view */ - - return; -} - -GtkTreeModel *load_menus_from_disk (void) -{ - - FILE *menufile; - char buf[1024]; - char first = 1; - char s[4096]; - GtkTreeStore *store; - GtkTreeIter iter, sub_iter; - - store = gtk_tree_store_new (TREE_COLUMNS_SIZE, - G_TYPE_STRING, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_STRING); - - /* currently hardcoded, but not a big issue to change later */ - sprintf (buf, "%s/.enlightenment/file.menu", homedir (getuid ())); - menufile = fopen (buf, "r"); - if (!menufile) - { - printf ("hmm. looks like you have some \"issues\" as you don't have\n" - "a %s file.\n", buf); - gtk_exit (1); - } - - while (fgets (s, 4096, menufile)) - { - s[strlen (s) - 1] = 0; - if ((s[0] && s[0] != '#')) - { - if (first) - { - gchar *text[3]; - char *txt = NULL; - char *txt2 = NULL; - char *txt3 = NULL; - - txt = field (s, 0); - text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL); - txt2 = g_strdup (""); - text[1] = g_locale_to_utf8 (txt2, -1, NULL, NULL, NULL); - txt3 = g_strdup (buf); - text[2] = g_locale_to_utf8 (txt3, -1, NULL, NULL, NULL); - - gtk_tree_store_append (store, &iter, NULL); - gtk_tree_store_set (store, &iter, - COL_DESCRIPTION, text[0], - COL_ICON, gdk_pixbuf_new_from_file (text[1], NULL), - COL_ICONNAME, text[1], - COL_PARAMS, text[2], - -1); - - //printf("mainitem: %s, %s, %s\n",txt,txt2,txt3); - - if (txt) - g_free (txt); - if (txt2) - g_free (txt2); - if (txt3) - g_free (txt3); - - first = 0; - } - else - { - char *txt = NULL, *icon = NULL, *act = NULL, *params = NULL; - gchar *text[3]; - - txt = field (s, 0); - icon = field (s, 1); - act = field (s, 2); - params = field (s, 3); - - text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL); - if (!icon) - icon = g_strdup (""); - text[1] = g_locale_to_utf8 (icon, -1, NULL, NULL, NULL); - if (!params) - params = g_strdup (""); - text[2] = g_locale_to_utf8 (params, -1, NULL, NULL, NULL); - - //printf("subitem: %s, %s, %s, %s\n",txt,icon,act,params); - - gtk_tree_store_append (store, &sub_iter, &iter); - gtk_tree_store_set (store, &sub_iter, - COL_DESCRIPTION, text[0], - COL_ICON, gdk_pixbuf_new_from_file (icon, NULL), - COL_ICONNAME, text[1], - COL_PARAMS, text[2], - -1); - - if (!strcasecmp (act, "menu")) - load_sub_menu_from_disk (params, store, &sub_iter); - - if (txt) - g_free (txt); - if (icon) - g_free (icon); - if (act) - g_free (act); - if (params) - g_free (params); - - } - } - } - - fclose (menufile); - - return GTK_TREE_MODEL (store); -} - -/* load submenu from disk */ -void load_sub_menu_from_disk (char *file_to_load, GtkTreeStore *store, - GtkTreeIter *iter) -{ - - FILE *menufile; - char buf[1024]; - char first = 1; - char s[4096]; - GtkTreeIter sub_iter; - - if (!file_to_load) - return; - if (file_to_load[0] != '/') - sprintf (buf, "%s/.enlightenment/%s", homedir (getuid ()), file_to_load); - else - sprintf (buf, "%s", file_to_load); - - menufile = fopen (buf, "r"); - - if (!menufile) - return; - - while (fgets (s, 4096, menufile)) - { - s[strlen (s) - 1] = 0; - if ((s[0] && s[0] != '#')) - { - if (first) - first = 0; - else - { - char *txt = NULL, *icon = NULL, *act = NULL, *params = NULL; - gchar *text[3]; - - txt = field (s, 0); - icon = field (s, 1); - act = field (s, 2); - params = field (s, 3); - - text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL); - if (!icon) - icon = g_strdup (""); - text[1] = g_locale_to_utf8 (icon, -1, NULL, NULL, NULL); - if (!params) - params = g_strdup (""); - text[2] = g_locale_to_utf8 (params, -1, NULL, NULL, NULL); - - /* printf("subitem: %s, %s, %s, %s\n",txt,icon,act,params); */ - - gtk_tree_store_append (store, &sub_iter, iter); - gtk_tree_store_set (store, &sub_iter, - COL_DESCRIPTION, text[0], - COL_ICON, gdk_pixbuf_new_from_file (icon, NULL), - COL_ICONNAME, text[1], - COL_PARAMS, text[2], - -1); - - - if (!strcasecmp (act, "menu")) - load_sub_menu_from_disk (params, store, &sub_iter); - - if (txt) - g_free (txt); - if (icon) - g_free (icon); - if (act) - g_free (act); - if (params) - g_free (params); - } - } - } - - fclose (menufile); - - return; -} - -gboolean table_save_func (GtkTreeModel *model, GtkTreePath *path, - GtkTreeIter *iter, gpointer user_data) -{ - gchar *description, *icon, *params; - gchar *tree_path_str; - gboolean has_child; - gint depth; - gchar *realfile; - gchar *dirname; - FILE *menu_ptr, *menu_ptr2; - gchar buffer[128]; - - gtk_tree_model_get (model, iter, - COL_DESCRIPTION, &description, - COL_ICONNAME, &icon, - COL_PARAMS, ¶ms, - -1); - - tree_path_str = gtk_tree_path_to_string(path); - - has_child = gtk_tree_model_iter_has_child (model, iter); - depth = gtk_tree_path_get_depth (path) - 1; - -#define WRITE_FILE /* undef this for debugging */ -#ifdef WRITE_FILE - if (depth + 1 >= MAX_RECURSION) - { - g_print ("maximum menu recursion reached! -> %d\n", MAX_RECURSION); - return TRUE; - } - - if (!g_path_is_absolute (params)) - { - /* Tarnation! A relative path */ - realfile = g_strjoin ("/", homedir (getuid ()), - ".enlightenment", params, NULL); - } - else - { - realfile = params; - } - - menu_file[depth] = g_strdup (realfile); - - /* create recursiv new menu subdirectory */ - dirname = g_path_get_dirname (realfile); - mkdir_with_parent (dirname, 0755); - g_free (dirname); - - if (depth > 0) - { - menu_ptr = fopen (menu_file[depth-1], "a+"); - if (menu_ptr == NULL) - { - printf ("Couldn't save menu to: %s\n", menu_file[depth-1]); - } - - if (has_child) - { - menu_ptr2 = fopen (menu_file[depth], "w"); - if (menu_ptr2 == NULL) - { - printf ("Couldn't save menu to: %s\n", menu_file[depth]); - } - //g_print ("write header to \"%s\":\n", menu_file[depth]); - sprintf (buffer, "\"%s\"\n", description); - fprintf (menu_ptr2, "%s", g_locale_from_utf8 (buffer, - -1, NULL, NULL, NULL)); - fclose (menu_ptr2); - - //g_print ("write menu to \"%s\":\n", menu_file[depth-1]); - sprintf (buffer, "\"%s\"\t%s\tmenu\t\"%s\"\n", - description[0] == '\0' ? "NULL" : description, - icon[0] == '\0' ? "NULL" : icon, - params[0] == '\0' ? "" : params); - fprintf (menu_ptr, "%s", g_locale_from_utf8 (buffer, - -1, NULL, NULL, NULL)); - } - else - { - //g_print ("write exec to \"%s\":\n", menu_file[depth-1]); - sprintf (buffer, "\"%s\"\t%s\texec\t\"%s\"\n", - description[0] == '\0' ? "NULL" : description, - icon[0] == '\0' ? "NULL" : icon, - params[0] == '\0' ? "" : params); - - fprintf (menu_ptr, "%s", g_locale_from_utf8 (buffer, - -1, NULL, NULL, NULL)); - } - fclose (menu_ptr); - } - else - { - menu_ptr2 = fopen (menu_file[depth], "w"); - if (menu_ptr2 == NULL) - { - printf ("Couldn't save menu to: %s\n", menu_file[depth]); - } - //g_print ("write first header to \"%s\":\n", menu_file[depth]); - sprintf (buffer, "\"%s\"\n", description); - fprintf (menu_ptr2, "%s", g_locale_from_utf8 (buffer, - -1, NULL, NULL, NULL)); - fclose (menu_ptr2); - } -#endif /* WRITE_FILE */ - -#ifndef WRITE_FILE - g_print ("%s | ", tree_path_str); - g_print ("%s %s %s\n", description, icon, params); -#endif /* WRITE_FILE */ - - /* end of filelist to free it later */ - menu_file[depth+1] = NULL; - - g_free(tree_path_str); - - g_free(description); - g_free(icon); - g_free(params); - - return FALSE; -} =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e16menuedit2.h 27 Jul 2004 10:25:21 -0000 1.2 +++ e16menuedit2.h 28 Jul 2004 22:12:28 -0000 1.3 @@ -1,10 +1,28 @@ -/*************************************************************************** - * e16menuedit.h +/* Copyright (C) 2004 Andreas Volz and various contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - * Tue Jun 1 13:51:01 2004 - * Copyright 2004 Andreas Volz - * [EMAIL PROTECTED] - ****************************************************************************/ + * File: e16menuedit2.h + * Created by: Andreas Volz <[EMAIL PROTECTED]> + * + */ #ifndef _E16MENUEDIT_H #define _E16MENUEDIT_H @@ -12,48 +30,15 @@ #include <gtk/gtk.h> #include <glade/glade.h> #include <stdio.h> +#ifdef HAVE_CONFIG_H #include <config.h> +#endif #include "nls.h" #define to_utf8(String) g_locale_to_utf8(String,-1,0,0,0) #define from_utf8(String) g_locale_from_utf8(String,-1,0,0,0) -#define MAX_RECURSION 128 - -void create_tree_model (GtkWidget *treeview_menu); -GtkTreeModel *create_and_fill_model (void); -GtkTreeModel *load_menus_from_disk (void); -void load_sub_menu_from_disk (char *file_to_load, GtkTreeStore *store, - GtkTreeIter *iter); -gboolean table_save_func (GtkTreeModel *model, GtkTreePath *path, - GtkTreeIter *iter, gpointer user_data); - #define APP_HOME ".e16menuedit2" #define ICON_DIR "icons" -enum tree_columns -{ - COL_DESCRIPTION, - COL_ICON, - COL_ICONNAME, - COL_PARAMS, - TREE_COLUMNS_SIZE -}; - -enum toolbar_buttons -{ - TB_NEW, - TB_CHANGE_ICON, - TB_SAVE, - TB_DELETE, - TB_QUIT -}; - -enum -{ - TARGET_GTK_TREE_MODEL_ROW -}; - -gchar *menu_file[MAX_RECURSION]; - #endif /* _E16MENUEDIT_H */ =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/file.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- file.c 27 Jul 2004 13:27:16 -0000 1.2 +++ file.c 28 Jul 2004 22:12:28 -0000 1.3 @@ -1,11 +1,3 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <pwd.h> -#include <sys/types.h> -#include <glib.h> #include "file.h" char *homedir (int uid) =================================================================== RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/file.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- file.h 25 Jul 2004 17:21:51 -0000 1.1 +++ file.h 28 Jul 2004 22:12:28 -0000 1.2 @@ -1,6 +1,14 @@ #ifndef _FILE_H #define _FILE_H +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <ctype.h> +#include <pwd.h> +#include <sys/types.h> +#include <glib.h> #include <sys/stat.h> #include <sys/types.h> ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs