/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "sabbu.h" extern struct sabbu app; enum { PROP_NAME_COLUMN, PROP_VALUE_COLUMN, PROP_DISPLAY_COLUMN, PROP_EDITABLE_COLUMN, PROP_ALIGN_COLUMN, PROP_N_COLUMNS }; #define PROPERTY_NONE 1 << 0 #define PROPERTY_STRING 1 << 1 #define PROPERTY_INT 1 << 2 #define PROPERTY_DOUBLE 1 << 3 #define PROPERTY_READONLY 1 << 4 struct property { char *name_internal; char *name_display; int type; }; struct property properties[] = { {"", _("Property|Read-only Info"), PROPERTY_NONE}, {"ScriptType", _("Property|Script Type:"), PROPERTY_STRING | PROPERTY_READONLY}, {"Sync Point Time", _("Property|Sync Point Time:"), PROPERTY_STRING | PROPERTY_READONLY}, {"", _("Property|Basic"), PROPERTY_NONE}, {"Title", _("Property|Title:"), PROPERTY_STRING}, {"Original Script", _("Property|Original Script:"), PROPERTY_STRING}, {"Original Translation", _("Property|Original Translation:"), PROPERTY_STRING}, {"Original Editing", _("Property|Original Editing:"), PROPERTY_STRING}, {"Original Timing", _("Property|Original Timing:"), PROPERTY_STRING}, {"Sync Point", _("Property|Sync Point:"), PROPERTY_STRING}, {"Script Updated By", _("Property|Script Updated By:"), PROPERTY_STRING}, {"Update Details", _("Property|Update Details:"), PROPERTY_STRING}, {"Video", _("Property|Video"), PROPERTY_NONE}, {"PlayResX", _("Property|PlayResX:"), PROPERTY_INT}, {"PlayResY", _("Property|PlayResY:"), PROPERTY_INT}, {"PlayDepth", _("Property|PlayDepth:"), PROPERTY_INT}, {"Behaviour", _("Property|Behaviour:"), PROPERTY_NONE}, {"Collisions", _("Property|Collisions:"), PROPERTY_STRING}, {"Wrap Style", _("Property|Wrap Style:"), PROPERTY_INT}, {"", _("Property|Miscellaneous"), PROPERTY_NONE}, {"Timer", _("Property|Timer:"), PROPERTY_DOUBLE}, {NULL, NULL, 0} }; void gui_properties_display_value_cb(GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { GtkTreePath *path = gtk_tree_model_get_path(model, iter); char *text; char *name; if(app.script) { gtk_tree_model_get(model, iter, PROP_NAME_COLUMN, &name, -1); name = KRY_TS(name); text = app.script->GetProperty(name); if(!text) text = ""; g_object_set(renderer, "text", text, NULL); kry_free(name); } gtk_tree_path_free(path); } void gui_properties_edit_cb(GtkCellRendererText *renderer, gchar *path_string, gchar *text, GtkTreeModel *model) { GtkTreeIter iter; GtkTreePath *path = gtk_tree_path_new_from_string(path_string); struct property *property; int i = 0; char *name; gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, PROP_NAME_COLUMN, &name, -1); for(;;) { property = &properties[i]; if(!property->name_internal) break; if(!strcmp(property->name_internal, name)) break; i++; } // if the value is set to empty, we delete that property char *val = app.script->GetProperty(name); if(!strcmp(text, "")) { if(val) app.script->SetProperty(name, NULL); return; } if(property->type & PROPERTY_INT) { char *lastchar; strtol(text, &lastchar, 10); if(lastchar[0] != 0) { gui_error(_("This property must be a number")); return; } } if(val && !strcmp(val, text)) return; char *name_copy = kry_strdup(name); char *text_copy = kry_strdup(text); app.script->SetProperty(name_copy, text_copy); } gboolean gui_properties_delete_cb(GtkWidget *widget, gpointer data) { gui_main_enable(); gui_main_focus(); return FALSE; } void gui_properties_close_cb(GtkWidget *button, GtkWidget *window) { gui_main_enable(); gui_main_focus(); gtk_widget_destroy(window); } void gui_properties_show() { GtkCellRendererText *renderer_name = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); GtkCellRendererText *renderer_value = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); GtkTreeStore *store = gtk_tree_store_new(PROP_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_DOUBLE); GtkTreeView *treeview = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store))); GtkTreeViewColumn *column_name = gtk_tree_view_column_new_with_attributes(__("PropertyList|Name"), GTK_CELL_RENDERER(renderer_name), "text", PROP_DISPLAY_COLUMN, "xalign", PROP_ALIGN_COLUMN, NULL); GtkTreeViewColumn *column_value = gtk_tree_view_column_new_with_attributes(__("PropertyList|Value"), GTK_CELL_RENDERER(renderer_value), "editable", PROP_EDITABLE_COLUMN, NULL); GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); GtkTreeIter iter; GtkTreeIter parent; struct property *property; int i = 0; g_signal_connect(renderer_value, "edited", G_CALLBACK(gui_properties_edit_cb), store); gtk_tree_view_column_set_cell_data_func(column_value, GTK_CELL_RENDERER(renderer_value), gui_properties_display_value_cb, NULL, NULL); gtk_tree_view_append_column(treeview, column_name); gtk_tree_view_append_column(treeview, column_value); //gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), PROP_NAME_COLUMN, GTK_SORT_ASCENDING); for(;;) { property = &properties[i]; if(!property->name_internal) break; if(property->type == PROPERTY_NONE) { gtk_tree_store_append(store, &iter, NULL); parent = iter; } else { gtk_tree_store_append(store, &iter, &parent); } gtk_tree_store_set(store, &iter, PROP_NAME_COLUMN, sgettext_strip(property->name_internal), PROP_DISPLAY_COLUMN, __(property->name_display), PROP_EDITABLE_COLUMN, !(property->type & PROPERTY_READONLY), PROP_ALIGN_COLUMN, (property->type != PROPERTY_NONE ? 1.0 : 0.0), -1); i++; } gtk_tree_view_expand_all(treeview); gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(treeview)); gtk_scrolled_window_set_policy(sw, GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); GtkHBox *hbox_button = GTK_HBOX(gtk_hbox_new(FALSE, 0)); GtkHButtonBox *bbox = GTK_HBUTTON_BOX(gtk_hbutton_box_new()); GtkButton *button_close = GTK_BUTTON(gtk_button_new_from_stock("gtk-close")); gtk_box_pack_start(GTK_BOX(bbox), GTK_WIDGET(button_close), FALSE, TRUE, 0); gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); gtk_box_pack_start(GTK_BOX(hbox_button), GTK_WIDGET(bbox), TRUE, TRUE, 10); GtkVBox *vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0)); GtkFrame *frame = GTK_FRAME(gtk_frame_new(NULL)); gtk_frame_set_shadow_type(frame, GTK_SHADOW_ETCHED_IN); GtkWindow *window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); gtk_window_set_title(window, _("Properties")); g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(gui_properties_delete_cb), NULL); g_signal_connect(G_OBJECT(button_close), "clicked", G_CALLBACK(gui_properties_close_cb), window); gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(sw)); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(frame), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox_button), FALSE, TRUE, 3); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox)); gtk_widget_set_size_request(GTK_WIDGET(window), 500, -1); gui_main_disable(); gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_transient_for(window, app.ui.window); gtk_widget_show_all(GTK_WIDGET(window)); }