static gint properties_apply(GtkWidget *canvas, gpointer data) { ObjectChange *obj_change = NULL; if ( (current_obj == NULL) || (current_dia == NULL) ) return 0; object_add_updates(current_obj, current_dia); obj_change = current_obj->ops->apply_properties(current_obj); object_add_updates(current_obj, current_dia); diagram_update_connections_object(current_dia, current_obj, TRUE); if (obj_change != NULL) { undo_object_change(current_dia, current_obj, obj_change); } diagram_modified(current_dia); diagram_update_extents(current_dia); if (obj_change != NULL) { undo_set_transactionpoint(current_dia->undo); } else { message_warning(_("This object doesn't support Undo/Redo.\n" "Undo information erased.")); undo_clear(current_dia->undo); } diagram_flush(current_dia); return 0; }
/* Match and replace property values. */ static gboolean _replace (DiaObject *obj, const SearchData *sd, const char *replacement) { ObjectChange *obj_change; GPtrArray *plist = NULL; plist = _match_props (obj, sd, replacement); if (!plist) return FALSE; /* Refresh screen and free the list of modified properties. */ obj_change = object_apply_props (obj, plist); prop_list_free (plist); if (obj_change) undo_object_change(sd->diagram, obj, obj_change); object_add_updates(obj, sd->diagram); diagram_update_connections_object(sd->diagram, obj, TRUE); diagram_modified(sd->diagram); diagram_object_modified(sd->diagram, obj); diagram_update_extents(sd->diagram); diagram_flush(sd->diagram); return TRUE; }
static PyObject * PyDiaDiagram_UpdateExtents(PyDiaDiagram *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":Diagram.update_extents")) return NULL; diagram_update_extents(self->dia); Py_INCREF(Py_None); return Py_None; }
static gint properties_respond(GtkWidget *widget, gint response_id, gpointer data) { ObjectChange *obj_change = NULL; gboolean set_tp = TRUE; GList *tmp; if ( response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK) { if ((current_objects != NULL) && (current_dia != NULL)) { object_add_updates_list(current_objects, current_dia); for (tmp = current_objects; tmp != NULL; tmp = tmp->next) { DiaObject *current_obj = (DiaObject*)tmp->data; obj_change = current_obj->ops->apply_properties_from_dialog(current_obj, object_part); object_add_updates(current_obj, current_dia); diagram_update_connections_object(current_dia, current_obj, TRUE); if (obj_change != NULL) { undo_object_change(current_dia, current_obj, obj_change); set_tp = set_tp && TRUE; } else set_tp = FALSE; diagram_object_modified(current_dia, current_obj); } diagram_modified(current_dia); diagram_update_extents(current_dia); if (set_tp) { undo_set_transactionpoint(current_dia->undo); } else { message_warning(_("This object doesn't support Undo/Redo.\n" "Undo information erased.")); undo_clear(current_dia->undo); } diagram_flush(current_dia); } } if (response_id != GTK_RESPONSE_APPLY) { #ifdef G_OS_WIN32 /* on windows we are not hiding the dialog, because shrinking when hidden does * not work (the dialog shows up with the same size as before, bug #333751) */ gtk_widget_destroy (dialog); #else properties_dialog_hide(); #endif } return 0; }
static void plugin_callback (GtkWidget *widget, gpointer data) { DiaCallbackFilter *cbf = data; /* check if the callback filter is still available */ if (!g_list_find (filter_get_callbacks (), cbf)) { message_error (_("The function is not available anymore.")); return; } /* and finally invoke it */ if (cbf->callback) { DDisplay *ddisp = NULL; DiagramData* diadata = NULL; ObjectChange *change; /* stuff from the toolbox menu should never get a diagram to modify */ if (strncmp (cbf->menupath, TOOLBOX_MENU, strlen (TOOLBOX_MENU)) != 0) { ddisp = ddisplay_active(); diadata = ddisp ? ddisp->diagram->data : NULL; } change = cbf->callback (diadata, ddisp ? ddisp->diagram->filename : NULL, 0, cbf->user_data); if (change != NULL) { if (ddisp) { undo_object_change(ddisp->diagram, NULL, change); /* * - can not call object_add_update() w/o object * - could call object_add_updates_list() with the selected objects, * but that would just be an educated guess (layout working on selection) */ diagram_add_update_all(ddisp->diagram); diagram_modified(ddisp->diagram); diagram_update_extents(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); } else { /* no diagram to keep the change, throw it away */ if (change->free) change->free(change); g_free(change); } } } }
/** * Respond to the user finishing the Open Dialog either accept or cancel/destroy */ static void file_open_response_callback(GtkWidget *fs, gint response, gpointer user_data) { char *filename; Diagram *diagram = NULL; if (response == GTK_RESPONSE_ACCEPT) { gint index = gtk_combo_box_get_active (GTK_COMBO_BOX(user_data)); if (index >= 0) /* remember it */ persistence_set_integer ("import-filter", index); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)); diagram = diagram_load(filename, ifilter_by_index (index - 1, filename)); g_free (filename); if (diagram != NULL) { diagram_update_extents(diagram); layer_dialog_set_diagram(diagram); if (diagram->displays == NULL) { /* GSList *displays = diagram->displays; GSList *displays_head = displays; diagram->displays = NULL; for (; displays != NULL; displays = g_slist_next(displays)) { DDisplay *loaded_display = (DDisplay *)displays->data; copy_display(loaded_display); g_free(loaded_display); } g_slist_free(displays_head); } else { */ new_display(diagram); } } } gtk_widget_destroy(opendlg); }
static void dia_layer_select_callback(GtkWidget *widget, gpointer data) { DiaLayerWidget *lw; lw = DIA_LAYER_WIDGET(widget); /* Don't deselect if we're selected the active layer. This can happen * if the window has been defocused. */ if (lw->dia->data->active_layer != lw->layer) { diagram_remove_all_selected(lw->dia, TRUE); } diagram_update_extents(lw->dia); data_set_active_layer(lw->dia->data, lw->layer); diagram_add_update_all(lw->dia); diagram_flush(lw->dia); internal_call = TRUE; if (lw->connect_off) { /* If the user wants this off, it becomes so */ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), FALSE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), TRUE); } internal_call = FALSE; }
static void create_object_button_press(CreateObjectTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point clickedpoint, origpoint; Handle *handle1; Handle *handle2; DiaObject *obj; real click_distance; ddisplay_untransform_coords(ddisp, (int)event->x, (int)event->y, &clickedpoint.x, &clickedpoint.y); origpoint = clickedpoint; snap_to_grid(ddisp, &clickedpoint.x, &clickedpoint.y); click_distance = ddisplay_untransform_length(ddisp, 3.0); obj = dia_object_default_create (tool->objtype, &clickedpoint, tool->user_data, &handle1, &handle2); tool->obj = obj; /* ensure that tool->obj is initialised in case we return early. */ if (!obj) { tool->moving = FALSE; tool->handle = NULL; message_error(_("'%s' creation failed"), tool->objtype ? tool->objtype->name : "NULL"); return; } diagram_add_object(ddisp->diagram, obj); /* Try a connect */ if (handle1 != NULL && handle1->connect_type != HANDLE_NONCONNECTABLE) { ConnectionPoint *connectionpoint; connectionpoint = object_find_connectpoint_display(ddisp, &origpoint, obj, TRUE); if (connectionpoint != NULL) { (obj->ops->move)(obj, &origpoint); } } if (!(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => remove current selection */ diagram_remove_all_selected(ddisp->diagram, TRUE); } diagram_select(ddisp->diagram, obj); /* Connect first handle if possible: */ if ((handle1!= NULL) && (handle1->connect_type != HANDLE_NONCONNECTABLE)) { object_connect_display(ddisp, obj, handle1, TRUE); } object_add_updates(obj, ddisp->diagram); ddisplay_do_update_menu_sensitivity(ddisp); diagram_flush(ddisp->diagram); if (handle2 != NULL) { tool->handle = handle2; tool->moving = TRUE; tool->last_to = handle2->pos; gdk_pointer_grab (gtk_widget_get_window(ddisp->canvas), FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); ddisplay_set_all_cursor(get_cursor(CURSOR_SCROLL)); } else { diagram_update_extents(ddisp->diagram); tool->moving = FALSE; } }
static void modify_button_release(ModifyTool *tool, GdkEventButton *event, DDisplay *ddisp) { Point *dest_pos, to; GList *list; int i; ObjectChange *objchange; tool->break_connections = FALSE; ddisplay_set_all_cursor(default_cursor); /* remove position from status bar */ { GtkStatusbar *statusbar = GTK_STATUSBAR (ddisp->modified_status); guint context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); gtk_statusbar_pop (statusbar, context_id); } switch (tool->state) { case STATE_MOVE_OBJECT: /* Return to normal state */ gdk_pointer_ungrab (event->time); ddisplay_untransform_coords(ddisp, event->x, event->y, &to.x, &to.y); if (!modify_move_already(tool, ddisp, &to)) { tool->orig_pos = NULL; tool->state = STATE_NONE; return; } diagram_update_connections_selection(ddisp->diagram); if (tool->orig_pos != NULL) { /* consider the non-selected children affected */ list = parent_list_affected(ddisp->diagram->data->selected); dest_pos = g_new(Point, g_list_length(list)); i=0; while (list != NULL) { DiaObject *obj = (DiaObject *) list->data; dest_pos[i] = obj->position; list = g_list_next(list); i++; } undo_move_objects(ddisp->diagram, tool->orig_pos, dest_pos, parent_list_affected(ddisp->diagram->data->selected)); } ddisplay_connect_selected(ddisp); /* pushes UNDO info */ diagram_update_extents(ddisp->diagram); diagram_modified(ddisp->diagram); diagram_flush(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); tool->orig_pos = NULL; tool->state = STATE_NONE; break; case STATE_MOVE_HANDLE: gdk_pointer_ungrab (event->time); tool->state = STATE_NONE; if (tool->orig_pos != NULL) { undo_move_handle(ddisp->diagram, tool->handle, tool->object, *tool->orig_pos, tool->last_to, gdk_event_to_dia_ModifierKeys(event->state)); } /* Final move: */ object_add_updates(tool->object, ddisp->diagram); objchange = tool->object->ops->move_handle(tool->object, tool->handle, &tool->last_to, NULL, HANDLE_MOVE_USER_FINAL,gdk_event_to_dia_ModifierKeys(event->state)); if (objchange != NULL) { undo_object_change(ddisp->diagram, tool->object, objchange); } object_add_updates(tool->object, ddisp->diagram); /* Connect if possible: */ if (tool->handle->connect_type != HANDLE_NONCONNECTABLE) { object_connect_display(ddisp, tool->object, tool->handle, TRUE); /* pushes UNDO info */ diagram_update_connections_selection(ddisp->diagram); } highlight_reset_all(ddisp->diagram); diagram_flush(ddisp->diagram); diagram_modified(ddisp->diagram); diagram_update_extents(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); if (tool->orig_pos != NULL) { g_free(tool->orig_pos); tool->orig_pos = NULL; } break; case STATE_BOX_SELECT: gdk_pointer_ungrab (event->time); /* Remove last box: */ dia_interactive_renderer_set_selection (ddisp->renderer, FALSE, 0, 0, 0, 0); { GList *list, *list_to_free; list = list_to_free = find_selected_objects(ddisp, tool); if (selection_style == SELECT_REPLACE && !(event->state & GDK_SHIFT_MASK)) { /* Not Multi-select => Remove all selected */ diagram_remove_all_selected(ddisp->diagram, TRUE); } if (selection_style == SELECT_INTERSECTION) { GList *intersection = NULL; while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; if (diagram_is_selected(ddisp->diagram, obj)) { intersection = g_list_append(intersection, obj); } list = g_list_next(list); } list = intersection; diagram_remove_all_selected(ddisp->diagram, TRUE); while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; diagram_select(ddisp->diagram, obj); list = g_list_next(list); } g_list_free(intersection); } else { while (list != NULL) { DiaObject *obj = (DiaObject *)list->data; if (selection_style == SELECT_REMOVE) { if (diagram_is_selected(ddisp->diagram, obj)) diagram_unselect_object(ddisp->diagram, obj); } else if (selection_style == SELECT_INVERT) { if (diagram_is_selected(ddisp->diagram, obj)) diagram_unselect_object(ddisp->diagram, obj); else diagram_select(ddisp->diagram, obj); } else { if (!diagram_is_selected(ddisp->diagram, obj)) diagram_select(ddisp->diagram, obj); } list = g_list_next(list); } } g_list_free(list_to_free); } ddisplay_do_update_menu_sensitivity(ddisp); ddisplay_flush(ddisp); tool->state = STATE_NONE; break; case STATE_NONE: break; default: message_error("Internal error: Strange state in modify_tool\n"); } }
void app_init (int argc, char **argv) { static gboolean nosplash = FALSE; static gboolean nonew = FALSE; static gboolean use_integrated_ui = TRUE; static gboolean credits = FALSE; static gboolean version = FALSE; static gboolean verbose = FALSE; static gboolean log_to_stderr = FALSE; #ifdef HAVE_GNOME GnomeClient *client; #endif static char *export_file_name = NULL; static char *export_file_format = NULL; static char *size = NULL; static char *show_layers = NULL; gboolean made_conversions = FALSE; GSList *files = NULL; static const gchar **filenames = NULL; int i = 0; gchar *export_format_string = /* Translators: The argument is a list of options, not to be translated */ g_strdup_printf(_("Select the filter/format out of: %s"), "cgm, dia, dxf, eps, eps-builtin, " EPS_PANGO "fig, mp, plt, hpgl, png (" # if defined(HAVE_LIBPNG) && defined(HAVE_LIBART) "png-libart, " # endif # ifdef HAVE_CAIRO "cairo-png, cairo-alpha-png, " # endif /* we always have pixbuf but don't know exactly all it's *few* save formats */ "pixbuf-png), jpg, " "shape, svg, tex (pgf-tex, pstricks-tex), " WMF "wpg"); GOptionContext *context = NULL; static GOptionEntry options[] = { {"export", 'e', 0, G_OPTION_ARG_FILENAME, NULL /* &export_file_name */, N_("Export loaded file and exit"), N_("OUTPUT")}, {"filter",'t', 0, G_OPTION_ARG_STRING, NULL /* &export_file_format */, NULL /* &export_format_string */, N_("TYPE") }, {"size", 's', 0, G_OPTION_ARG_STRING, NULL, N_("Export graphics size"), N_("WxH")}, {"show-layers", 'L', 0, G_OPTION_ARG_STRING, NULL, N_("Show only specified layers (e.g. when exporting). Can be either the layer name or a range of layer numbers (X-Y)"), N_("LAYER,LAYER,...")}, {"nosplash", 'n', 0, G_OPTION_ARG_NONE, &nosplash, N_("Don't show the splash screen"), NULL }, {"nonew", 'n', 0, G_OPTION_ARG_NONE, &nonew, N_("Don't create an empty diagram"), NULL }, {"classic", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_integrated_ui, N_("Start classic user interface (no diagrams in tabs)"), NULL }, {"log-to-stderr", 'l', 0, G_OPTION_ARG_NONE, &log_to_stderr, N_("Send error messages to stderr instead of showing dialogs."), NULL }, {"input-directory", 'I', 0, G_OPTION_ARG_CALLBACK, _check_option_input_directory, N_("Directory containing input files"), N_("DIRECTORY")}, {"output-directory", 'O', 0, G_OPTION_ARG_CALLBACK, _check_option_output_directory, N_("Directory containing output files"), N_("DIRECTORY")}, {"credits", 'c', 0, G_OPTION_ARG_NONE, &credits, N_("Display credits list and exit"), NULL }, {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Generate verbose output"), NULL }, {"version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Display version and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL /* &filenames */, NULL, NULL }, { NULL } }; /* for users of app_init() the default is interactive */ dia_is_interactive = TRUE; options[0].arg_data = &export_file_name; options[1].arg_data = &export_file_format; options[1].description = export_format_string; options[2].arg_data = &size; options[3].arg_data = &show_layers; g_assert (strcmp (options[13].long_name, G_OPTION_REMAINING) == 0); options[13].arg_data = (void*)&filenames; argv0 = (argc > 0) ? argv[0] : "(none)"; #if GTK_CHECK_VERSION(2,24,0) /* ... use setlocale directly? */ #else gtk_set_locale(); #endif setlocale(LC_NUMERIC, "C"); _setup_textdomains (); context = g_option_context_new(_("[FILE...]")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); #ifndef HAVE_GNOME /* avoid to add it a second time */ g_option_context_add_group (context, gtk_get_option_group (FALSE)); #endif if (argv) { GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { /* IMO !error here is a bug upstream, triggered e.g. with --gdk-debug=updates */ g_print ("%s", error->message); g_error_free (error); } else { g_print (_("Invalid option?")); } g_option_context_free(context); exit(1); } /* second level check of command line options, existance of input files etc. */ if (filenames) { while (filenames[i] != NULL) { gchar *filename; gchar *testpath; if (g_str_has_prefix (filenames[i], "file://")) { filename = g_filename_from_uri (filenames[i], NULL, NULL); if (!g_utf8_validate(filename, -1, NULL)) { gchar *tfn = filename; filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); g_free(tfn); } } else filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL); if (!filename) { g_print (_("Filename conversion failed: %s\n"), filenames[i]); continue; } if (g_path_is_absolute(filename)) testpath = filename; else testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL); /* we still have a problem here, if GLib's file name encoding would not be utf-8 */ if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR)) files = g_slist_append(files, filename); else { g_print (_("Missing input: %s\n"), filename); g_free (filename); } if (filename != testpath) g_free (testpath); ++i; } } /* given some files to output, we are not starting up the UI */ if (export_file_name || export_file_format || size) dia_is_interactive = FALSE; } if (argv && dia_is_interactive && !version) { #ifdef HAVE_GNOME GnomeProgram *program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, /* haven't found a quick way to pass GOption here */ GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_NONE); client = gnome_master_client(); if(client == NULL) { g_warning(_("Can't connect to session manager!\n")); } else { g_signal_connect(G_OBJECT (client), "save_yourself", G_CALLBACK (save_state), NULL); g_signal_connect(G_OBJECT (client), "die", G_CALLBACK (session_die), NULL); } /* This smaller icon is 48x48, standard Gnome size */ /* gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/dia_gnome_icon.png");*/ #else # ifdef G_THREADS_ENABLED g_thread_init (NULL); # endif gtk_init(&argc, &argv); #endif } else { #ifdef G_THREADS_ENABLED g_thread_init (NULL); #endif g_type_init(); /* * On Windows there is no command line without display so that gtk_init is harmless. * On X11 we need gtk_init_check() to avoid exit() just because there is no display * running outside of X11. */ if (!gtk_init_check(&argc, &argv)) dia_log_message ("Running without display"); } /* done with option parsing, don't leak */ g_free(export_format_string); if (version) { gchar *ver_utf8; gchar *ver_locale; #if (defined __TIME__) && (defined __DATE__) /* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */ ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__); #else ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION); #endif ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL); printf("%s\n", ver_locale); g_free(ver_locale); g_free(ver_utf8); if (verbose) dump_dependencies(); exit(0); } if (!dia_is_interactive) log_to_stderr = TRUE; libdia_init ( (dia_is_interactive ? DIA_INTERACTIVE : 0) | (log_to_stderr ? DIA_MESSAGE_STDERR : 0) | (verbose ? DIA_VERBOSE : 0) ); print_credits(credits); if (dia_is_interactive) { create_user_dirs(); if (!nosplash) app_splash_init(""); /* Init cursors: */ default_cursor = gdk_cursor_new(GDK_LEFT_PTR); ddisplay_set_all_cursor(default_cursor); } dia_register_plugins(); dia_register_builtin_plugin(internal_plugin_init); load_all_sheets(); /* new mechanism */ dia_log_message ("object defaults"); { DiaContext *ctx = dia_context_new (_("Object Defaults")); dia_object_defaults_load (NULL, TRUE /* prefs.object_defaults_create_lazy */, ctx); dia_context_release (ctx); } debug_break(); if (object_get_type("Standard - Box") == NULL) { message_error(_("Couldn't find standard objects when looking for " "object-libs; exiting...\n")); g_critical( _("Couldn't find standard objects when looking for " "object-libs in '%s'; exiting...\n"), dia_get_lib_directory("dia")); exit(1); } persistence_load(); /** Must load prefs after persistence */ prefs_init(); if (dia_is_interactive) { /* further initialization *before* reading files */ active_tool = create_modify_tool(); dia_log_message ("ui creation"); if (use_integrated_ui) { create_integrated_ui(); } else { create_toolbox(); /* for the integrated ui case it is integrated */ persistence_register_window_create("layer_window", (NullaryFunc*)&layer_dialog_create); } /*fill recent file menu */ recent_file_history_init(); /* Set up autosave to check every 5 minutes */ g_timeout_add_seconds(5*60, autosave_check_autosave, NULL); #if 0 /* do we really open these automatically in the next session? */ persistence_register_window_create("diagram_tree", &diagram_tree_show); #endif persistence_register_window_create("sheets_main_dialog", (NullaryFunc*)&sheets_dialog_create); /* In current setup, we can't find the autosaved files. */ /*autosave_restore_documents();*/ } dia_log_message ("diagrams"); made_conversions = handle_all_diagrams(files, export_file_name, export_file_format, size, show_layers, input_directory, output_directory); if (dia_is_interactive && files == NULL && !nonew) { if (use_integrated_ui) { GList * list; file_new_callback(NULL); list = dia_open_diagrams(); if (list) { Diagram * diagram = list->data; diagram_update_extents(diagram); diagram->is_default = TRUE; } } else { gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); Diagram *diagram = new_diagram (filename); g_free(filename); if (diagram != NULL) { diagram_update_extents(diagram); diagram->is_default = TRUE; /* I think this is done in diagram_init() with a call to * layer_dialog_update_diagram_list() */ layer_dialog_set_diagram(diagram); new_display(diagram); } } } g_slist_free(files); if (made_conversions) exit(0); dynobj_refresh_init(); dia_log_message ("initialized"); }
/** Handle loading of diagrams given on command line, including conversions. * Returns TRUE if any automatic conversions were performed. * Note to future hackers: 'size' is currently the only argument that can be * sent to exporters. If more arguments are desired, please don't just add * even more arguments, but create a more general system. */ static gboolean handle_initial_diagram(const char *in_file_name, const char *out_file_name, const char *export_file_format, const char *size, char* show_layers, const char *outdir) { Diagram *diagram = NULL; gboolean made_conversions = FALSE; if (export_file_format) { char *export_file_name = NULL; DiaExportFilter *ef = NULL; /* First try guessing based on extension */ export_file_name = build_output_file_name(in_file_name, export_file_format, outdir); /* to make the --size hack even uglier but work again for the only filter supporting it */ if ( size && strcmp(export_file_format, "png") == 0) ef = filter_export_get_by_name ("png-libart"); if (!ef) ef = filter_guess_export_filter(export_file_name); if (ef == NULL) { ef = filter_export_get_by_name(export_file_format); if (ef == NULL) { g_critical(_("Can't find output format/filter %s\n"), export_file_format); return FALSE; } g_free (export_file_name); export_file_name = build_output_file_name(in_file_name, ef->extensions[0], outdir); } made_conversions |= do_convert(in_file_name, (out_file_name != NULL?out_file_name:export_file_name), ef, size, show_layers); g_free(export_file_name); } else if (out_file_name) { DiaExportFilter *ef = NULL; /* if this looks like an ugly hack to you, agreed ;) */ if (size && strstr(out_file_name, ".png")) ef = filter_export_get_by_name ("png-libart"); made_conversions |= do_convert(in_file_name, out_file_name, ef, size, show_layers); } else { if (g_file_test(in_file_name, G_FILE_TEST_EXISTS)) { diagram = diagram_load (in_file_name, NULL); } else { diagram = new_diagram (in_file_name); } if (diagram != NULL) { diagram_update_extents(diagram); if (app_is_interactive()) { layer_dialog_set_diagram(diagram); /* the display initial diagram holds two references */ new_display(diagram); } else { g_object_unref(diagram); } } } return made_conversions; }
gboolean app_exit(void) { GList *list; GSList *slist; /* * The following "solves" a crash related to a second call of app_exit, * after gtk_main_quit was called. It may be a win32 gtk-1.3.x bug only * but the check shouldn't hurt on *ix either. --hb */ static gboolean app_exit_once = FALSE; if (app_exit_once) { g_error(_("This shouldn't happen. Please file a bug report at bugzilla.gnome.org\n" "describing how you caused this message to appear.\n")); return FALSE; } if (diagram_modified_exists()) { if (is_integrated_ui ()) { GtkWidget *dialog; int result; exit_dialog_item_array_t *items = NULL; GList * list; Diagram * diagram; dialog = exit_dialog_make (GTK_WINDOW (interface_get_toolbox_shell ()), _("Exiting Dia")); list = dia_open_diagrams(); while (list) { diagram = list->data; if (diagram_is_modified (diagram)) { const gchar * name = diagram_get_name (diagram); const gchar * path = diagram->filename; exit_dialog_add_item (dialog, name, path, diagram); } list = g_list_next (list); } result = exit_dialog_run (dialog, &items); gtk_widget_destroy (dialog); if (result == EXIT_DIALOG_EXIT_CANCEL) { return FALSE; } else if (result == EXIT_DIALOG_EXIT_SAVE_SELECTED) { DiaContext *ctx = dia_context_new(_("Save")); int i; for (i = 0 ; i < items->array_size ; i++) { gchar *filename; diagram = items->array[i].data; filename = g_filename_from_utf8 (diagram->filename, -1, NULL, NULL, NULL); diagram_update_extents (diagram); dia_context_set_filename (ctx, filename); if (!diagram_save (diagram, filename, ctx)) { exit_dialog_free_items (items); dia_context_release (ctx); return FALSE; } else { dia_context_reset (ctx); } g_free (filename); } dia_context_release (ctx); exit_dialog_free_items (items); } else if (result == EXIT_DIALOG_EXIT_NO_SAVE) { list = dia_open_diagrams(); while (list) { diagram = list->data; /* slight hack: don't ask again */ diagram_set_modified (diagram, FALSE); undo_clear(diagram->undo); list = g_list_next (list); } } } else { GtkWidget *dialog; GtkWidget *button; dialog = gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, /* no standard buttons */ _("Quitting without saving modified diagrams")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), _("Modified diagrams exist. " "Are you sure you want to quit Dia " "without saving them?")); gtk_window_set_title (GTK_WINDOW(dialog), _("Quit Dia")); button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); gtk_dialog_add_action_widget (GTK_DIALOG(dialog), button, GTK_RESPONSE_CANCEL); #if GTK_CHECK_VERSION(2,18,0) gtk_widget_set_can_default (GTK_WIDGET (button), TRUE); #else GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); #endif gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL); button = gtk_button_new_from_stock (GTK_STOCK_QUIT); gtk_dialog_add_action_widget (GTK_DIALOG(dialog), button, GTK_RESPONSE_OK); gtk_widget_show_all (dialog); if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) { gtk_widget_destroy(dialog); return FALSE; } gtk_widget_destroy(dialog); } } prefs_save(); persistence_save(); dynobj_refresh_finish(); { DiaContext *ctx = dia_context_new (_("Exit")); dia_object_defaults_save (NULL, ctx); dia_context_release (ctx); } /* Free loads of stuff (toolbox) */ list = dia_open_diagrams(); while (list!=NULL) { Diagram *dia = (Diagram *)list->data; list = g_list_next(list); slist = dia->displays; while (slist!=NULL) { DDisplay *ddisp = (DDisplay *)slist->data; slist = g_slist_next(slist); gtk_widget_destroy(ddisp->shell); } /* The diagram is freed when the last display is destroyed */ } /* save pluginrc */ if (dia_is_interactive) dia_pluginrc_write(); gtk_main_quit(); /* This printf seems to prevent a race condition with unrefs. */ /* Yuck. -Lars */ /* Trying to live without it. -Lars 10/8/07*/ /* g_print(_("Thank you for using Dia.\n")); */ app_exit_once = TRUE; return TRUE; }
static void dia_dnd_file_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, DDisplay *ddisp) { #if GTK_CHECK_VERSION(2,22,0) switch (gdk_drag_context_get_selected_action(context)) #else switch (context->action) #endif { case GDK_ACTION_DEFAULT: case GDK_ACTION_COPY: case GDK_ACTION_MOVE: case GDK_ACTION_LINK: case GDK_ACTION_ASK: default: { Diagram *diagram = NULL; gchar *sPath = NULL, *pFrom, *pTo; pFrom = strstr((gchar *) gtk_selection_data_get_data(data), "file:"); while (pFrom) { GError *error = NULL; pTo = pFrom; while (*pTo != 0 && *pTo != 0xd && *pTo != 0xa) pTo ++; sPath = g_strndup(pFrom, pTo - pFrom); /* format changed with Gtk+2.0, use conversion */ pFrom = g_filename_from_uri (sPath, NULL, &error); if (!ddisp) diagram = diagram_load (pFrom, NULL); else { diagram = ddisp->diagram; if (!diagram_load_into (diagram, pFrom, NULL)) { /* the import filter is supposed to show the error message */ gtk_drag_finish (context, TRUE, FALSE, time); break; } } g_free (pFrom); g_free(sPath); if (diagram != NULL) { diagram_update_extents(diagram); layer_dialog_set_diagram(diagram); if (diagram->displays == NULL) { new_display(diagram); } } pFrom = strstr(pTo, "file:"); } /* while */ gtk_drag_finish (context, TRUE, FALSE, time); } break; } return; }
static void create_object_button_release(CreateObjectTool *tool, GdkEventButton *event, DDisplay *ddisp) { GList *list = NULL; DiaObject *obj = tool->obj; gboolean reset; GList *parent_candidates; g_return_if_fail (obj != NULL); if (!obj) /* not sure if this isn't enough */ return; /* could be a legal invariant */ if (tool->moving) { gdk_pointer_ungrab (event->time); object_add_updates(tool->obj, ddisp->diagram); tool->obj->ops->move_handle(tool->obj, tool->handle, &tool->last_to, NULL, HANDLE_MOVE_CREATE_FINAL, 0); object_add_updates(tool->obj, ddisp->diagram); } parent_candidates = layer_find_objects_containing_rectangle(obj->parent_layer, &obj->bounding_box); /* whole object must be within another object to parent it */ for (; parent_candidates != NULL; parent_candidates = g_list_next(parent_candidates)) { DiaObject *parent_obj = (DiaObject *) parent_candidates->data; if (obj != parent_obj && object_within_parent(obj, parent_obj)) { Change *change = undo_parenting(ddisp->diagram, parent_obj, obj, TRUE); (change->apply)(change, ddisp->diagram); break; /* obj->parent = parent_obj; parent_obj->children = g_list_append(parent_obj->children, obj); */ } } g_list_free(parent_candidates); list = g_list_prepend(list, tool->obj); undo_insert_objects(ddisp->diagram, list, 1); if (tool->moving) { if (tool->handle->connect_type != HANDLE_NONCONNECTABLE) { object_connect_display(ddisp, tool->obj, tool->handle, TRUE); diagram_update_connections_selection(ddisp->diagram); diagram_flush(ddisp->diagram); } tool->moving = FALSE; tool->handle = NULL; tool->obj = NULL; } { /* remove position from status bar */ GtkStatusbar *statusbar = GTK_STATUSBAR (ddisp->modified_status); guint context_id = gtk_statusbar_get_context_id (statusbar, "ObjectPos"); gtk_statusbar_pop (statusbar, context_id); } highlight_reset_all(ddisp->diagram); reset = prefs.reset_tools_after_create != tool->invert_persistence; /* kind of backward: first starting editing to see if it is possible at all, than GUI reflection */ if (textedit_activate_object(ddisp, obj, NULL) && reset) { gtk_action_activate (menus_get_action ("ToolsTextedit")); reset = FALSE; /* don't switch off textedit below */ } diagram_update_extents(ddisp->diagram); diagram_modified(ddisp->diagram); undo_set_transactionpoint(ddisp->diagram->undo); if (reset) tool_reset(); ddisplay_set_all_cursor(default_cursor); ddisplay_do_update_menu_sensitivity(ddisp); }
/** * A button hit in the Export Dialog */ static void file_export_response_callback(GtkWidget *fs, gint response, gpointer user_data) { char *filename; Diagram *dia; DiaExportFilter *ef; struct stat statbuf; dia = g_object_get_data (G_OBJECT (fs), "user_data"); g_assert (dia); if (response == GTK_RESPONSE_ACCEPT) { gint index; diagram_update_extents(dia); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)); if (g_stat(filename, &statbuf) == 0) { GtkWidget *dialog = NULL; dialog = gtk_message_dialog_new (GTK_WINDOW(fs), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("File already exists")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), _("The file '%s' already exists.\n" "Do you want to overwrite it?"), dia_message_filename(filename)); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) { /* if not overwrite allow to select another filename */ gtk_widget_destroy(dialog); g_free (filename); return; } gtk_widget_destroy(dialog); } index = gtk_combo_box_get_active (GTK_COMBO_BOX(user_data)); if (index >= 0) persistence_set_integer ("export-filter", index); ef = efilter_by_index (index - 1, NULL); if (!ef) ef = filter_guess_export_filter(filename); if (ef) { DiaContext *ctx = dia_context_new (_("Export")); g_object_ref(dia->data); dia_context_set_filename (ctx, filename); ef->export_func(dia->data, ctx, filename, dia->filename, ef->user_data); g_object_unref(dia->data); dia_context_release (ctx); } else message_error(_("Could not determine which export filter\n" "to use to save '%s'"), dia_message_filename(filename)); g_free (filename); } g_object_unref (dia); /* drop our diagram reference */ gtk_widget_destroy(exportdlg); }
static GtkWidget * file_save_as_dialog_prepare (Diagram *dia, DDisplay *ddisp) { gchar *filename = NULL; if (!savedlg) { GtkWidget *compressbutton; savedlg = gtk_file_chooser_dialog_new(_("Save Diagram"), GTK_WINDOW(ddisp->shell), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); /* vfs saving is as easy - if you see 'bad file descriptor' there is * something wrong with the permissions of the share ;) */ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER(savedlg), FALSE); gtk_dialog_set_default_response(GTK_DIALOG(savedlg), GTK_RESPONSE_ACCEPT); gtk_window_set_role(GTK_WINDOW(savedlg), "save_diagram"); /* Need better way to make it a reasonable size. Isn't there some*/ /* standard look for them (or is that just Gnome?)*/ compressbutton = gtk_check_button_new_with_label(_("Compress diagram files")); gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(savedlg), compressbutton); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compressbutton), dia->data->is_compressed); g_signal_connect(G_OBJECT(compressbutton), "toggled", G_CALLBACK(toggle_compress_callback), NULL); gtk_widget_show(compressbutton); gtk_widget_set_tooltip_text (compressbutton, _("Compression reduces file size to less than 1/10th " "size and speeds up loading and saving. Some text " "programs cannot manipulate compressed files.")); g_signal_connect (GTK_FILE_CHOOSER(savedlg), "response", G_CALLBACK(file_save_as_response_callback), compressbutton); g_signal_connect(G_OBJECT(savedlg), "destroy", G_CALLBACK(gtk_widget_destroyed), &savedlg); } else { GtkWidget *compressbutton = gtk_file_chooser_get_extra_widget(GTK_FILE_CHOOSER(savedlg)); gtk_widget_set_sensitive(savedlg, TRUE); g_signal_handlers_block_by_func(G_OBJECT(compressbutton), toggle_compress_callback, NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compressbutton), dia->data->is_compressed); g_signal_handlers_unblock_by_func(G_OBJECT(compressbutton), toggle_compress_callback, NULL); if (g_object_get_data (G_OBJECT (savedlg), "user_data") != NULL) g_object_unref (g_object_get_data (G_OBJECT (savedlg), "user_data")); #if GTK_CHECK_VERSION(2,20,0) if (gtk_widget_get_visible(savedlg)) { #else if (GTK_WIDGET_VISIBLE(savedlg)) { #endif /* keep a refernce to the diagram */ g_object_ref(dia); g_object_set_data (G_OBJECT (savedlg), "user_data", dia); gtk_window_present (GTK_WINDOW(savedlg)); return savedlg; } } if (dia && dia->filename) filename = g_filename_from_utf8(dia->filename, -1, NULL, NULL, NULL); if (filename != NULL) { char* fnabs = dia_get_absolute_filename (filename); if (fnabs) { gchar *base = g_path_get_basename(dia->filename); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(savedlg), fnabs); /* FileChooser api insist on exiting files for set_filename */ /* ... and does not use filename encoding on this one. */ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(savedlg), base); g_free(base); } g_free(fnabs); g_free(filename); } g_object_ref(dia); g_object_set_data (G_OBJECT (savedlg), "user_data", dia); return savedlg; } /** * Respond to the File/Save menu entry. * * Delegates to Save As if there is no filename set yet. */ void file_save_callback(GtkAction *action) { Diagram *diagram; diagram = ddisplay_active_diagram(); if (!diagram) return; if (diagram->unsaved) { file_save_as_callback(action); } else { gchar *filename = g_filename_from_utf8(diagram->filename, -1, NULL, NULL, NULL); DiaContext *ctx = dia_context_new (_("Save")); diagram_update_extents(diagram); if (diagram_save(diagram, filename, ctx)) recent_file_history_add(filename); g_free (filename); dia_context_release (ctx); } }
/** * Respond to a button press (also destroy) in the save as dialog. */ static void file_save_as_response_callback(GtkWidget *fs, gint response, gpointer user_data) { char *filename; Diagram *dia; struct stat stat_struct; if (response == GTK_RESPONSE_ACCEPT) { dia = g_object_get_data (G_OBJECT(fs), "user_data"); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)); if (!filename) { /* Not getting a filename looks like a contract violation in Gtk+ to me. * Still Dia would be crashing (bug #651949) - instead simply go back to the dialog. */ gtk_window_present (GTK_WINDOW (fs)); return; } if (g_stat(filename, &stat_struct) == 0) { GtkWidget *dialog = NULL; char *utf8filename = NULL; if (!g_utf8_validate(filename, -1, NULL)) { utf8filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); if (utf8filename == NULL) { message_warning(_("Some characters in the filename are neither UTF-8\n" "nor your local encoding.\nSome things will break.")); } } if (utf8filename == NULL) utf8filename = g_strdup(filename); dialog = gtk_message_dialog_new (GTK_WINDOW(fs), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("File already exists")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), _("The file '%s' already exists.\n" "Do you want to overwrite it?"), utf8filename); g_free(utf8filename); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) { /* don't hide/destroy the dialog, but simply go back to it */ gtk_window_present (GTK_WINDOW (fs)); gtk_widget_destroy(dialog); g_free (filename); return; } gtk_widget_destroy(dialog); } dia->data->is_compressed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(user_data)); diagram_update_extents(dia); { DiaContext *ctx = dia_context_new (_("Save as")); diagram_set_filename(dia, filename); dia_context_set_filename (ctx, filename); if (diagram_save(dia, filename, ctx)) recent_file_history_add(filename); dia_context_release (ctx); } g_free (filename); } /* if we have our own reference, drop it before destroy */ if ((dia = g_object_get_data (G_OBJECT(fs), "user_data")) != NULL) { g_object_set_data (G_OBJECT(fs), "user_data", NULL); g_object_unref (dia); } /* if we destroy it gtk_dialog_run wont give the response */ if (!g_object_get_data (G_OBJECT(fs), "dont-destroy")) gtk_widget_destroy(GTK_WIDGET(fs)); }