コード例 #1
0
ファイル: diagram.c プロジェクト: brunetton/dia
int
diagram_load_into(Diagram         *diagram,
		  const char      *filename,
		  DiaImportFilter *ifilter)
{
  /* ToDo: move context further up in the callstack and to sth useful with it's content */
  DiaContext *ctx = dia_context_new(_("Load Into"));

  gboolean was_default = diagram->is_default;
  if (!ifilter)
    ifilter = filter_guess_import_filter(filename);
  /* slightly hacked to avoid 'Not a Dia File' for .shape */
  if (!ifilter && g_str_has_suffix (filename, ".shape"))
    ifilter = filter_import_get_by_name ("dia-svg");
  if (!ifilter)  /* default to native format */
    ifilter = &dia_import_filter;

  dia_context_set_filename (ctx, filename);
  if (ifilter->import_func(filename, diagram->data, ctx, ifilter->user_data)) {
    if (ifilter != &dia_import_filter) {
      /* When loading non-Dia files, change filename to reflect that saving
       * will produce a Dia file. See bug #440093 */
      if (strcmp (diagram->filename, filename) == 0) {
	/* not a real load into but initial load */
	gchar *old_filename = g_strdup (diagram->filename);
        gchar *suffix_offset = g_utf8_strrchr(old_filename, -1, (gunichar)'.');
        gchar *new_filename;
        if (suffix_offset != NULL) {
	  new_filename = g_strndup(old_filename, suffix_offset - old_filename);
	  g_free(old_filename);
	} else {
	  new_filename = old_filename;
	}
        old_filename = g_strconcat(new_filename, ".dia", NULL);
        g_free(new_filename);
        diagram_set_filename(diagram, old_filename);
        g_free(old_filename);
        diagram->unsaved = TRUE;
	diagram_update_for_filename (diagram);
	diagram_modified(diagram);
      }
    } else {
      /* the initial diagram should have confirmed filename  */
      diagram->unsaved = 
	  strcmp(filename, diagram->filename) == 0 ? FALSE : was_default;
    }
    diagram_set_modified(diagram, TRUE);
    dia_context_release(ctx);
    return TRUE;
  } else {
    dia_context_release(ctx);
    return FALSE;
  }
}
コード例 #2
0
ファイル: diagram.c プロジェクト: brunetton/dia
Diagram *
diagram_load(const char *filename, DiaImportFilter *ifilter)
{
  Diagram *diagram = NULL;
  GList *diagrams;
  gboolean was_default = FALSE;

  for (diagrams = open_diagrams; diagrams != NULL; diagrams = g_list_next(diagrams)) {
    Diagram *old_diagram = (Diagram*)diagrams->data;
    if (old_diagram->is_default) {
      diagram = old_diagram;
      was_default = TRUE;
      break;
    }	
  }

  /* TODO: Make diagram not be initialized twice */
  if (diagram == NULL) {
    diagram = new_diagram(filename);
  }
  if (diagram == NULL) return NULL;

  if (   !diagram_init(diagram, filename)
      || !diagram_load_into (diagram, filename, ifilter)) {
    if (!was_default) /* don't kill the default diagram on import failure */
      diagram_destroy(diagram);
    diagram = NULL;
  } else {
    /* not modifying 'diagram->unsaved' the state depends on the import filter used */
    diagram_set_modified(diagram, FALSE);
    if (app_is_interactive()) {
      recent_file_history_add(filename);
      if (was_default) /* replacing it is like first remove than add */
        dia_diagram_remove(diagram);
      dia_diagram_add(diagram);
    }
  }
  
  if (diagram != NULL && was_default && app_is_interactive()) {
    diagram_update_for_filename(diagram);
    diagram->is_default = FALSE;
    if ( g_slist_length(diagram->displays) == 1 )
      display_set_active (diagram->displays->data);
  }
  
  return diagram;
}
コード例 #3
0
ファイル: dia-props.c プロジェクト: krattai/monoflow
static void
diagram_properties_respond(GtkWidget *widget,
                           gint       response_id,
                           gpointer   user_data)
{
  Diagram *active_diagram = ddisplay_active_diagram();

  if (response_id == GTK_RESPONSE_OK ||
      response_id == GTK_RESPONSE_APPLY) {
    if (active_diagram) {
      active_diagram->grid.dynamic =
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dynamic_check));
      active_diagram->grid.width_x =
        gtk_spin_button_get_value(GTK_SPIN_BUTTON(width_x_entry));
      active_diagram->grid.width_y =
        gtk_spin_button_get_value(GTK_SPIN_BUTTON(width_y_entry));
      active_diagram->grid.visible_x =
        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_x_entry));
      active_diagram->grid.visible_y =
        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_y_entry));
      active_diagram->grid.hex =
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hex_check));
      active_diagram->grid.hex_size =
        gtk_spin_button_get_value(GTK_SPIN_BUTTON(hex_size_entry));
      dia_color_selector_get_color(bg_colour,
  				 &active_diagram->data->bg_color);
      dia_color_selector_get_color(grid_colour,
  				 &active_diagram->grid.colour);
      dia_color_selector_get_color(pagebreak_colour,
  				 &active_diagram->pagebreak_color);
      diagram_add_update_all(active_diagram);
      diagram_flush(active_diagram);
      diagram_set_modified(active_diagram, TRUE);
    }
  }
  if (response_id != GTK_RESPONSE_APPLY)
    gtk_widget_hide(dialog);
}
コード例 #4
0
ファイル: app_procs.c プロジェクト: UIKit0/dia
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;
}