Commit f5ef1e6e authored by Morten Welinder's avatar Morten Welinder

Export: move the single-sheet selection logic out of the savers

parent 4dc1d1af
......@@ -58,13 +58,12 @@
#include <rendered-value.h>
#include <cellspan.h>
#include <print-info.h>
#include <gutils.h>
#include <locale.h>
#include <gsf/gsf-output.h>
#include <string.h>
#define SHEET_SELECTION_KEY "sheet-selection"
typedef enum {
LATEX_NO_BORDER = 0,
LATEX_SINGLE_BORDER = 1,
......@@ -1289,10 +1288,9 @@ file_saver_sheet_get_extent (Sheet *sheet)
* to render the format and contents of the cell.
*/
void
latex_file_save (G_GNUC_UNUSED GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext *io_context,
latex_file_save (GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext *io_context,
WorkbookView const *wb_view, GsfOutput *output)
{
Workbook *wb = wb_view_get_workbook (wb_view);
GnmCell *cell;
Sheet *current_sheet;
GnmRange total_range;
......@@ -1302,13 +1300,9 @@ latex_file_save (G_GNUC_UNUSED GOFileSaver const *fs, G_GNUC_UNUSED GOIOContext
GnmStyleBorderType *clines, *this_clines;
GnmStyleBorderType *prev_vert = NULL, *next_vert = NULL, *this_vert;
gboolean needs_hline;
GPtrArray *sel;
/* Get the sheet and its range from the plugin function argument. */
sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY);
current_sheet = sel && sel->len
? g_ptr_array_index (sel, 0)
: wb_view_cur_sheet(wb_view);
current_sheet = gnm_file_saver_get_sheet (fs, wb_view);
total_range = file_saver_sheet_get_extent (current_sheet);
/* This is the preamble of the LaTeX2e file. */
......@@ -1568,23 +1562,19 @@ latex2e_table_write_file_header(GsfOutput *output)
* We try to avoid all formatting.
*/
static void
latex_table_file_save_impl (WorkbookView const *wb_view, GsfOutput *output, gboolean all)
latex_table_file_save_impl (GOFileSaver const *fs, WorkbookView const *wb_view,
GsfOutput *output, gboolean all)
{
Workbook *wb = wb_view_get_workbook (wb_view);
GnmCell *cell;
Sheet *current_sheet;
GnmRange total_range;
int row, col;
GPtrArray *sel;
/* This is the preamble of the LaTeX2e file. */
latex2e_table_write_file_header(output);
/* Get the sheet and its range from the plugin function argument. */
sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY);
current_sheet = sel && sel->len
? g_ptr_array_index (sel, 0)
: wb_view_cur_sheet(wb_view);
current_sheet = gnm_file_saver_get_sheet (fs, wb_view);
total_range = file_saver_sheet_get_extent (current_sheet);
/* Step through the sheet, writing cells as appropriate. */
......@@ -1625,11 +1615,11 @@ latex_table_file_save_impl (WorkbookView const *wb_view, GsfOutput *output, gboo
* latex table environment. We try to avoid all formatting.
*/
void
latex_table_file_save (G_GNUC_UNUSED GOFileSaver const *fs,
latex_table_file_save (GOFileSaver const *fs,
G_GNUC_UNUSED GOIOContext *io_context,
WorkbookView const *wb_view, GsfOutput *output)
{
latex_table_file_save_impl (wb_view, output, TRUE);
latex_table_file_save_impl (fs, wb_view, output, TRUE);
}
/**
......@@ -1644,9 +1634,9 @@ latex_table_file_save (G_GNUC_UNUSED GOFileSaver const *fs,
* latex table environment. We try to avoid all formatting.
*/
void
latex_table_visible_file_save (G_GNUC_UNUSED GOFileSaver const *fs,
latex_table_visible_file_save (GOFileSaver const *fs,
G_GNUC_UNUSED GOIOContext *io_context,
WorkbookView const *wb_view, GsfOutput *output)
{
latex_table_file_save_impl (wb_view, output, FALSE);
latex_table_file_save_impl (fs, wb_view, output, FALSE);
}
......@@ -16,6 +16,7 @@
#include "sheet.h"
#include "ranges.h"
#include "mathfunc.h"
#include "workbook-view.h"
#include <goffice/goffice.h>
......@@ -31,6 +32,8 @@
#include <gsf/gsf-doc-meta-data.h>
#include <gsf/gsf-timestamp.h>
#define SHEET_SELECTION_KEY "sheet-selection"
static char *gnumeric_lib_dir;
static char *gnumeric_data_dir;
static char *gnumeric_locale_dir;
......@@ -848,3 +851,34 @@ gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc **pdoc)
}
/* ------------------------------------------------------------------------- */
/**
* gnm_file_saver_get_sheet:
* @fs: #GOFileSaver
* @wbv: #WorkbookView
*
* For a single-sheet saver, this function determines what sheet to save.
*
* Returns: (transfer none): the sheet to export
*/
Sheet *
gnm_file_saver_get_sheet (GOFileSaver const *fs, WorkbookView const *wbv)
{
Workbook *wb;
GPtrArray *sel;
g_return_val_if_fail (GO_IS_FILE_SAVER (fs), NULL);
g_return_val_if_fail (go_file_saver_get_save_scope (fs) == GO_FILE_SAVE_SHEET, NULL);
g_return_val_if_fail (GNM_IS_WORKBOOK_VIEW (wbv), NULL);
wb = wb_view_get_workbook (wbv);
sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY);
if (sel) {
if (sel->len)
return g_ptr_array_index (sel, 0);
g_critical ("Someone messed up sheet selection");
}
return wb_view_cur_sheet (wbv);
}
......@@ -62,6 +62,9 @@ void gnm_hash_table_foreach_ordered (GHashTable *h,
void gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc **pdoc);
Sheet *gnm_file_saver_get_sheet (GOFileSaver const *fs,
WorkbookView const *wbv);
G_END_DECLS
#endif /* _GNM_GUTILS_H_ */
......@@ -58,8 +58,6 @@
#include <gsf/gsf-utils.h>
#include <locale.h>
#define SHEET_SELECTION_KEY "sheet-selection"
static void
stf_warning (GOIOContext *context, char const *msg)
{
......@@ -487,13 +485,11 @@ stf_read_workbook_auto_csvtab (G_GNUC_UNUSED GOFileOpener const *fo, gchar const
/***********************************************************************************/
static void
stf_write_csv (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *context,
stf_write_csv (GOFileSaver const *fs, GOIOContext *context,
GoView const *view, GsfOutput *output)
{
Sheet *sheet;
WorkbookView *wbv = GNM_WORKBOOK_VIEW (view);
Workbook *wb = wb_view_get_workbook (wbv);
GPtrArray *sel = g_object_get_data (G_OBJECT (wb), SHEET_SELECTION_KEY);
GnmStfExport *config = g_object_new
(GNM_STF_EXPORT_TYPE,
......@@ -501,11 +497,7 @@ stf_write_csv (G_GNUC_UNUSED GOFileSaver const *fs, GOIOContext *context,
"quoting-triggers", ", \t\n\"",
NULL);
if (sel)
sheet = sel->len ? g_ptr_array_index (sel, 0) : NULL;
else
sheet = wb_view_cur_sheet (wbv);
sheet = gnm_file_saver_get_sheet (fs, wbv);
if (sheet)
gnm_stf_export_options_sheet_list_add (config, sheet);
......
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