/** We might just have change the diagrams modified status. * This doesn't set the status, but merely updates the display. */ void diagram_modified(Diagram *dia) { GSList *displays; gchar *dia_name = diagram_get_name(dia); gchar *extra = g_path_get_dirname (dia->filename); gchar *title = g_strdup_printf ("%s%s (%s)", diagram_is_modified(dia) ? "*" : "", dia_name, extra ? extra : " "); g_free (dia_name); g_free (extra); displays = dia->displays; while (displays!=NULL) { DDisplay *ddisp = (DDisplay *) displays->data; ddisplay_set_title(ddisp, title); displays = g_slist_next(displays); } if (diagram_is_modified(dia)) { dia->autosaved = FALSE; dia->is_default = FALSE; } /* diagram_set_modified(dia, TRUE);*/ g_free (title); }
/** Update the various areas that require updating when changing filename * This will ensure that all places that use the filename are updated: * Window titles, layer dialog, recent files, diagram tree. * @param dia The diagram whose filename has changed. */ static void diagram_update_for_filename(Diagram *dia) { GSList *l; DDisplay *ddisp; char *title; title = diagram_get_name(dia); l = dia->displays; while (l!=NULL) { ddisp = (DDisplay *) l->data; ddisplay_set_title(ddisp, title); l = g_slist_next(l); } g_free(title); layer_dialog_update_diagram_list(); /* signal about the change */ dia_diagram_change (dia, DIAGRAM_CHANGE_NAME, NULL); }
void ddisplay_set_title(DDisplay *ddisp, char *title) { if (ddisp->is_standalone_window) gtk_window_set_title (GTK_WINDOW (ddisp->shell), title); else { GtkNotebook *notebook = g_object_get_data (G_OBJECT (ddisp->shell), DIA_MAIN_NOTEBOOK); /* Find the page with ddisp then set the label on the tab */ gint num_pages = gtk_notebook_get_n_pages (notebook); gint num; GtkWidget *page; for (num = 0 ; num < num_pages ; num++) { page = gtk_notebook_get_nth_page (notebook,num); if (g_object_get_data (G_OBJECT (page), "DDisplay") == ddisp) { GtkLabel *label = g_object_get_data (G_OBJECT (page), "tab-label"); /* not using the passed in title here, because it may be too long */ gchar *name = diagram_get_name(ddisp->diagram); gtk_label_set_text(label,name); g_free(name); break; } } /* now modify the application window title */ { const gchar *pname = g_get_prgname(); gchar *fulltitle = g_strdup_printf ("%s - %s", title, pname ? pname : "Dia"); gtk_window_set_title (GTK_WINDOW (ddisp->shell), fulltitle); g_free(fulltitle); } } }
/* SORTABLE * Wrapper around the original model to allow sorting by various columns IDs */ static gint cmp_diagram (GtkTreeIter *a, GtkTreeIter *b) { DiagramData *pa = NODE_DIAGRAM(a), *pb = NODE_DIAGRAM(b); gchar *na, *nb; gint ret; if (pa == pb) return 0; na = diagram_get_name (DIA_DIAGRAM(pa)); nb = diagram_get_name (DIA_DIAGRAM(pa)); if (!na || !nb) return (na > nb) ? -1 : 1; ret = strcmp (na, nb); g_free (na); g_free (nb); return ret; }
/* * may_close_diagram: * @dialog_message: the dialog message to display to the user if the diagram * has been modified. * * When no changes have been made to the current diagram, the function * lets the caller proceed. Otherwise the user is asked for further actions. * If he chooses to save the diagram, the function will handle this action. * * Return value: %FALSE if the current action should be cancelled. * %TRUE if the caller may proceed. */ static gboolean may_close_diagram (LdWindowMain *self, const gchar *dialog_message) { GtkWidget *message_dialog; gchar *name; gint result; g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), TRUE); g_return_val_if_fail (dialog_message != NULL, TRUE); if (!ld_diagram_get_modified (self->priv->diagram)) return TRUE; name = diagram_get_name (self); /* TODO: Show the time since the diagram was last saved. * (Record the event with g_get_current_time().) */ message_dialog = gtk_message_dialog_new (GTK_WINDOW (self), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, dialog_message, name); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog), _("If you don't save, changes will be permanently lost.")); gtk_dialog_add_buttons (GTK_DIALOG (message_dialog), _("Close _without Saving"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL); result = gtk_dialog_run (GTK_DIALOG (message_dialog)); gtk_widget_destroy (message_dialog); g_free (name); switch (result) { case GTK_RESPONSE_NO: return TRUE; case GTK_RESPONSE_YES: on_action_save (NULL, self); return TRUE; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: return FALSE; default: g_assert_not_reached (); } }
/* * update_title: * * Update the title of the window. */ static void update_title (LdWindowMain *self) { gchar *title; gchar *name; g_return_if_fail (LD_IS_WINDOW_MAIN (self)); name = diagram_get_name (self); title = g_strdup_printf ("%s%s - %s", ld_diagram_get_modified (self->priv->diagram) ? "*" : "", name, PROJECT_NAME); gtk_window_set_title (GTK_WINDOW (self), title); g_free (title); g_free (name); }
/* diagram_properties_retrieve * Retrieves properties of a diagram *dia and sets the values in the * diagram properties dialog. */ static void diagram_properties_retrieve(Diagram *dia) { gchar *title; gchar *name = dia ? diagram_get_name(dia) : "?"; g_return_if_fail(dia != NULL); if (!dialog) return; /* Can we be sure that the filename is the 'proper title'? */ title = g_strdup_printf(_("Diagram Properties: %s"), name ? name : "??"); gtk_window_set_title(GTK_WINDOW(dialog), title); g_free(name); g_free(title); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dynamic_check), dia->grid.dynamic); gtk_spin_button_set_value(GTK_SPIN_BUTTON(width_x_entry), dia->grid.width_x); gtk_spin_button_set_value(GTK_SPIN_BUTTON(width_y_entry), dia->grid.width_y); gtk_spin_button_set_value(GTK_SPIN_BUTTON(visible_x_entry), dia->grid.visible_x); gtk_spin_button_set_value(GTK_SPIN_BUTTON(visible_y_entry), dia->grid.visible_y); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hex_check), dia->grid.hex); gtk_spin_button_set_value(GTK_SPIN_BUTTON(hex_size_entry), dia->grid.hex_size); dia_color_selector_set_color(bg_colour, &dia->data->bg_color); dia_color_selector_set_color(grid_colour, &dia->grid.colour); dia_color_selector_set_color(pagebreak_colour, &dia->pagebreak_color); diagram_properties_update_sensitivity(GTK_TOGGLE_BUTTON(dynamic_check), dia); }
static void _dtm_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, gint column, GValue *value) { switch (column) { case DIAGRAM_COLUMN : g_value_init (value, G_TYPE_OBJECT); g_value_set_object (value, NODE_DIAGRAM(iter)); break; case LAYER_COLUMN : g_value_init (value, G_TYPE_POINTER); g_value_set_pointer (value, NODE_LAYER(iter)); break; case OBJECT_COLUMN : g_value_init (value, G_TYPE_POINTER); g_value_set_pointer (value, NODE_OBJECT(iter)); break; case NAME_COLUMN : g_value_init (value, G_TYPE_STRING); /* deduce the requested name from the iter */ if (NODE_OBJECT(iter)) g_value_set_string (value, object_get_displayname (NODE_OBJECT (iter))); else if (NODE_LAYER(iter)) g_value_set_string (value, layer_get_name (NODE_LAYER (iter))); else if (NODE_DIAGRAM(iter)) g_value_set_string (value, diagram_get_name (DIA_DIAGRAM(NODE_DIAGRAM(iter)))); else /* warn on it? */ g_value_set_string (value, NULL); break; default : g_assert_not_reached (); } }
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; }