Commit b9071979 authored by Chyla Zbigniew's avatar Chyla Zbigniew

Removed #include "xml-io.h".


* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".

* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...

* src/gnumeric-util.[ch]: ... here.

* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
parent e9a1d615
2001-05-23 Zbigniew Chyla <cyba@gnome.pl>
* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".
* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...
* src/gnumeric-util.[ch]: ... here.
* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
2001-05-22 Almer S. Tigelaar <almer@gnome.org>
* src/xml-io.c : Bump XML version number.
......
2001-05-23 Zbigniew Chyla <cyba@gnome.pl>
* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".
* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...
* src/gnumeric-util.[ch]: ... here.
* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
2001-05-22 Almer S. Tigelaar <almer@gnome.org>
* src/xml-io.c : Bump XML version number.
......
2001-05-23 Zbigniew Chyla <cyba@gnome.pl>
* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".
* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...
* src/gnumeric-util.[ch]: ... here.
* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
2001-05-22 Almer S. Tigelaar <almer@gnome.org>
* src/xml-io.c : Bump XML version number.
......
2001-05-23 Zbigniew Chyla <cyba@gnome.pl>
* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".
* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...
* src/gnumeric-util.[ch]: ... here.
* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
2001-05-22 Almer S. Tigelaar <almer@gnome.org>
* src/xml-io.c : Bump XML version number.
......
2001-05-23 Zbigniew Chyla <cyba@gnome.pl>
* src/bonobo-io.c, src/clipboard.c, src/file.c, src/plugin.c,
src/sheet-object.c, src/stf.c, src/workbook.c:
Removed #include "xml-io.h".
* src/dialogs/dialog-plugin-manager.c (gnumeric_dialog_question_yes_no):
Function moved ...
* src/gnumeric-util.[ch]: ... here.
* src/gui-file.c
(gui_file_import): Sorting file importers.
(fill_save_menu): Sorting file savers, function simplified (doesn't use
file_saver_is_default_format).
(can_try_save_to): Function simplified, uses
gnumeric_dialog_question_yes_no from gnumeric-util.h, default answer
for question about overwriting a file is configurable.
2001-05-22 Almer S. Tigelaar <almer@gnome.org>
* src/xml-io.c : Bump XML version number.
......
......@@ -27,7 +27,6 @@
#include "workbook.h"
#include "sheet.h"
#include "file.h"
#include "xml-io.h"
#include "bonobo-io.h"
static GnumFileOpener *gnumeric_bonobo_opener;
......
......@@ -27,8 +27,6 @@
#include "ranges.h"
#include "expr.h"
#include "commands.h"
#include "xml-io.h"
#include "value.h"
#include "dialog-stf.h"
......
......@@ -167,29 +167,6 @@ typedef struct {
static void update_plugin_manager_view (PluginManagerGUI *pm_gui);
static void update_plugin_details_view (PluginManagerGUI *pm_gui);
static gboolean
gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
const gchar *message,
gboolean default_answer)
{
GtkWidget *dialog, *default_button;
dialog = gnome_message_box_new (
message,
GNOME_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
if (default_answer) {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->data;
} else {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->next->data;
}
gtk_widget_grab_focus (default_button);
return gnumeric_dialog_run (wbcg, GNOME_DIALOG (dialog)) == 0;
}
static void
cb_pm_button_activate_plugin_clicked (GtkButton *button, PluginManagerGUI *pm_gui)
{
......
......@@ -12,7 +12,6 @@
#include "io-context.h"
#include "command-context.h"
#include "gnumeric.h"
#include "xml-io.h"
#include "sheet.h"
#include "application.h"
#include "workbook-control.h"
......
......@@ -22,6 +22,29 @@
# include "workbook-private.h"
#endif
gboolean
gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
const gchar *message,
gboolean default_answer)
{
GtkWidget *dialog, *default_button;
dialog = gnome_message_box_new (
message,
GNOME_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
if (default_answer) {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->data;
} else {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->next->data;
}
gtk_widget_grab_focus (default_button);
return gnumeric_dialog_run (wbcg, GNOME_DIALOG (dialog)) == 0;
}
/*
* TODO:
* Get rid of trailing newlines /whitespace.
......
......@@ -7,6 +7,9 @@
#include "error-info.h"
#include "gutils.h"
gboolean gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
const gchar *message,
gboolean default_answer);
void gnumeric_notice (WorkbookControlGUI *wbcg, const char *type, const char *str);
void gnumeric_non_modal_dialog (WorkbookControlGUI *wbcg, GtkWindow *dialog);
......
#include <config.h>
#include <errno.h>
#include <gnome.h>
#include <glade/glade.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "dialogs.h"
#include "xml-io.h"
#include "gui-file.h"
#include "sheet.h"
#include "application.h"
......@@ -15,6 +15,24 @@
#include "workbook.h"
#include <sys/stat.h>
static gint
file_opener_description_cmp (gconstpointer a, gconstpointer b)
{
const GnumFileOpener *fo_a = a, *fo_b = b;
return strcoll (gnum_file_opener_get_description (fo_a),
gnum_file_opener_get_description (fo_b));
}
static gint
file_saver_description_cmp (gconstpointer a, gconstpointer b)
{
const GnumFileSaver *fs_a = a, *fs_b = b;
return strcoll (gnum_file_saver_get_description (fs_a),
gnum_file_saver_get_description (fs_b));
}
static void
cb_select (GtkWidget *clist, gint row, gint column,
GdkEventButton *event, GtkWidget *dialog)
......@@ -38,7 +56,7 @@ gui_file_import (WorkbookControlGUI *wbcg, const char *filename)
GtkCList *clist;
GnumFileOpener *fo = NULL;
int row;
GList *l;
GList *importers, *l;
gint ret;
gui = gnumeric_glade_xml_new (wbcg, "import.glade");
......@@ -51,7 +69,9 @@ gui_file_import (WorkbookControlGUI *wbcg, const char *filename)
clist = GTK_CLIST (glade_xml_get_widget (gui, "import-clist"));
for (l = get_file_importers (), row = 0; l != NULL; l = l->next, row++) {
importers = g_list_sort (g_list_copy (get_file_importers ()),
file_opener_description_cmp);
for (l = importers, row = 0; l != NULL; l = l->next, row++) {
GnumFileOpener *fo = l->data;
char *text[1];
......@@ -62,6 +82,7 @@ gui_file_import (WorkbookControlGUI *wbcg, const char *filename)
if (row > 0) {
gtk_clist_select_row (clist, 0, 0);
}
g_list_free (importers);
gtk_signal_connect (GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC (cb_select), (gpointer) dialog);
......@@ -128,34 +149,14 @@ saver_activate (GtkMenuItem *item, GnumFileSaver *saver)
wbcg->current_saver = saver;
}
/**
* file_saver_is_default_format:
*
* Returns TRUE if @saver is the default file save format.
*/
static gboolean
file_saver_is_default_format (WorkbookControlGUI *wbcg, GnumFileSaver *saver)
{
if (wbcg->current_saver == saver)
return TRUE;
if (wbcg->current_saver == NULL) {
if (saver == get_default_file_saver ()) {
wbcg->current_saver = saver;
return TRUE;
}
}
return FALSE;
}
static void
fill_save_menu (WorkbookControlGUI *wbcg, GtkOptionMenu *omenu, GtkMenu *menu)
{
GList *l;
int i, selected=-1;
GList *savers, *l;
for (l = get_file_savers (), i = 0; l != NULL; l = l->next, i++){
savers = g_list_sort (g_list_copy (get_file_savers ()),
file_saver_description_cmp);
for (l = savers; l != NULL; l = l->next) {
GtkWidget *menu_item;
GnumFileSaver *fs = l->data;
......@@ -163,17 +164,18 @@ fill_save_menu (WorkbookControlGUI *wbcg, GtkOptionMenu *omenu, GtkMenu *menu)
gtk_object_set_data (GTK_OBJECT (menu_item), "wbcg", wbcg);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
if (file_saver_is_default_format (wbcg, fs))
selected = i;
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (saver_activate), fs);
GTK_SIGNAL_FUNC (saver_activate), fs);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), GTK_WIDGET (menu));
if (selected > 0)
gtk_option_menu_set_history (omenu, selected);
if (wbcg->current_saver == NULL) {
wbcg->current_saver = get_default_file_saver ();
}
gtk_option_menu_set_history (omenu,
g_list_index (savers, wbcg->current_saver));
g_list_free (savers);
}
static GtkWidget *
......@@ -232,33 +234,6 @@ fs_set_filename (GtkFileSelection *fsel, Workbook *wb)
g_free (name);
}
/*
* Returns true if user confirmed that existing workbook should be
* overwritten.
*
* FIXME: The dialog should really be a child of the file selector,
* not the workbook.
*/
static gboolean
wants_to_overwrite (WorkbookControlGUI *wbcg, const char *name)
{
GtkWidget *d, *button_no;
char *message = g_strdup_printf
(_("Workbook %s already exists.\nDo you want to save over it?"),
name);
d = gnome_message_box_new (
message, GNOME_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
g_free (message);
button_no = g_list_last (GNOME_DIALOG (d)->buttons)->data;
gtk_widget_grab_focus (button_no);
return (gnumeric_dialog_run (wbcg, GNOME_DIALOG (d)) == 0);
}
/*
* Check if it makes sense to try saving.
* If it's an existing file and writable for us, ask if we want to overwrite.
......@@ -271,39 +246,35 @@ wants_to_overwrite (WorkbookControlGUI *wbcg, const char *name)
static gboolean
can_try_save_to (WorkbookControlGUI *wbcg, const char *name)
{
struct stat sb;
char *err_str;
gboolean dir_entered = FALSE;
gboolean file_exists = FALSE;
if (*name == 0)
return FALSE;
else if (name [strlen (name) - 1] == '/') {
dir_entered = TRUE;
} else if ((stat (name, &sb) == 0)) {
if (S_ISDIR (sb.st_mode))
dir_entered = TRUE;
else
file_exists = TRUE;
gboolean result = TRUE;
gchar *msg;
if (name == NULL || name[0] == '\0') {
result = FALSE;
} else if (name [strlen (name) - 1] == '/' ||
g_file_test (name, G_FILE_TEST_ISDIR)) {
msg = g_strdup_printf (_("%s\nis a directory name"), name);
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);
result = FALSE;
} else if (access (name, W_OK) != 0 && errno != ENOENT) {
msg = g_strdup_printf (
_("You do not have permission to save to\n%s"),
name);
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, msg);
g_free (msg);
result = FALSE;
} else if (g_file_exists (name)) {
msg = g_strdup_printf (
_("Workbook %s already exists.\n"
"Do you want to save over it?"), name);
result = gnumeric_dialog_question_yes_no (wbcg, msg,
gnome_config_get_bool_with_default (
"Gnumeric/File/FileOverwriteDefaultAnswer=false", NULL));
g_free (msg);
}
if (dir_entered) {
err_str = g_strdup_printf (_("%s\nis a directory name"), name);
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, err_str);
g_free (err_str);
return FALSE;
}
if (file_exists) {
if (access (name, W_OK) == 0)
return wants_to_overwrite (wbcg, name);
else {
err_str = g_strdup_printf (_("You do not have permission to save to\n%s"),
name);
gnumeric_notice (wbcg, GNOME_MESSAGE_BOX_ERROR, err_str);
g_free (err_str);
return FALSE;
}
} else
return TRUE;
return result;
}
static gboolean
......
......@@ -22,6 +22,29 @@
# include "workbook-private.h"
#endif
gboolean
gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
const gchar *message,
gboolean default_answer)
{
GtkWidget *dialog, *default_button;
dialog = gnome_message_box_new (
message,
GNOME_MESSAGE_BOX_QUESTION,
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO,
NULL);
if (default_answer) {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->data;
} else {
default_button = (GtkWidget *) (GNOME_DIALOG (dialog)->buttons)->next->data;
}
gtk_widget_grab_focus (default_button);
return gnumeric_dialog_run (wbcg, GNOME_DIALOG (dialog)) == 0;
}
/*
* TODO:
* Get rid of trailing newlines /whitespace.
......
......@@ -7,6 +7,9 @@
#include "error-info.h"
#include "gutils.h"
gboolean gnumeric_dialog_question_yes_no (WorkbookControlGUI *wbcg,
const gchar *message,
gboolean default_answer);
void gnumeric_notice (WorkbookControlGUI *wbcg, const char *type, const char *str);
void gnumeric_non_modal_dialog (WorkbookControlGUI *wbcg, GtkWindow *dialog);
......
......@@ -34,7 +34,6 @@
#include "gnumeric-util.h"
#include "gutils.h"
#include "command-context.h"
#include "xml-io.h"
#include "file.h"
#include "workbook.h"
#include "workbook-view.h"
......
......@@ -20,7 +20,6 @@
#include "sheet-private.h"
#include "expr.h"
#include "ranges.h"
#include "xml-io.h"
#include "sheet-object-graphic.h"
#include "sheet-object-cell-comment.h"
......
......@@ -47,7 +47,6 @@
#include "workbook-control.h"
#include "workbook-view.h"
#include "workbook.h"
#include "xml-io.h"
#include "stf.h"
#include "dialog-stf.h"
......
......@@ -29,7 +29,6 @@
#include "ranges.h"
#include "history.h"
#include "commands.h"
#include "xml-io.h"
#include "main.h"
#include "file.h"
#include "io-context.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment