GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 63c3dfcc authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Only print the headers and sides


1999-07-05  Miguel de Icaza  <miguel@gnu.org>

	* src/print.c: Only print the headers and sides

	* plugins/text/text-io.c (text_cleanup_plugin): Kill probing here.
	(text_init): kill probing here as well.
	(text_parse_file): kill probing support here as well.
	(text_parse_file): Do not use first line as sheet name.

	* src/file.c (workbook_import): Added import dialog box.
	(workbook_read): Now does only probe for existing probe routines.
	(file_format_register_open): probe function being NULL now means
	that this is not an auto-probe filter, but an import filter (ie,
	the user has to manually select the file).

1999-07-04  Miguel de Icaza  <miguel@gnu.org>

	* src/file.c (file_format_register_open): Allow the probe_fn to be NULL.

	* src/workbook.c (import_file_cmd): Added import menu item.

1999-07-05  Miguel de Icaza  <miguel@gnu.org>

	* csv-io.c (csv_read_workbook): Load here now.
	(init_plugin): Do not provide a probing routine.
parent cda74447
......@@ -4,7 +4,8 @@ Miguel:
Print support (imported from the GNUMERIC_PRINT branch).
Pattern selector works again.
Imported Alan's libCSV and rewrwite ff-csv so that it actually works.
Add import feature. Drop some normal loaders and make them importers
Fixed lots of print stuff.
Jukka:
* Started the implementation of Data Analysis tools
- Implemented Correlation and Covariance tools
......
1999-07-05 Miguel de Icaza <miguel@gnu.org>
* src/print.c: Only print the headers and sides
* plugins/text/text-io.c (text_cleanup_plugin): Kill probing here.
(text_init): kill probing here as well.
(text_parse_file): kill probing support here as well.
(text_parse_file): Do not use first line as sheet name.
* src/file.c (workbook_import): Added import dialog box.
(workbook_read): Now does only probe for existing probe routines.
(file_format_register_open): probe function being NULL now means
that this is not an auto-probe filter, but an import filter (ie,
the user has to manually select the file).
1999-07-04 Miguel de Icaza <miguel@gnu.org>
* src/file.c (file_format_register_open): Allow the probe_fn to be NULL.
* src/workbook.c (import_file_cmd): Added import menu item.
1999-07-05 Michael Meeks <michael@edenproject.org>
* src/sheet.c (sheet_update_auto_expr): Removed parsing.
......
1999-07-05 Miguel de Icaza <miguel@gnu.org>
* src/print.c: Only print the headers and sides
* plugins/text/text-io.c (text_cleanup_plugin): Kill probing here.
(text_init): kill probing here as well.
(text_parse_file): kill probing support here as well.
(text_parse_file): Do not use first line as sheet name.
* src/file.c (workbook_import): Added import dialog box.
(workbook_read): Now does only probe for existing probe routines.
(file_format_register_open): probe function being NULL now means
that this is not an auto-probe filter, but an import filter (ie,
the user has to manually select the file).
1999-07-04 Miguel de Icaza <miguel@gnu.org>
* src/file.c (file_format_register_open): Allow the probe_fn to be NULL.
* src/workbook.c (import_file_cmd): Added import menu item.
1999-07-05 Michael Meeks <michael@edenproject.org>
* src/sheet.c (sheet_update_auto_expr): Removed parsing.
......
1999-07-05 Miguel de Icaza <miguel@gnu.org>
* src/print.c: Only print the headers and sides
* plugins/text/text-io.c (text_cleanup_plugin): Kill probing here.
(text_init): kill probing here as well.
(text_parse_file): kill probing support here as well.
(text_parse_file): Do not use first line as sheet name.
* src/file.c (workbook_import): Added import dialog box.
(workbook_read): Now does only probe for existing probe routines.
(file_format_register_open): probe function being NULL now means
that this is not an auto-probe filter, but an import filter (ie,
the user has to manually select the file).
1999-07-04 Miguel de Icaza <miguel@gnu.org>
* src/file.c (file_format_register_open): Allow the probe_fn to be NULL.
* src/workbook.c (import_file_cmd): Added import menu item.
1999-07-05 Michael Meeks <michael@edenproject.org>
* src/sheet.c (sheet_update_auto_expr): Removed parsing.
......
1999-07-05 Miguel de Icaza <miguel@gnu.org>
* src/print.c: Only print the headers and sides
* plugins/text/text-io.c (text_cleanup_plugin): Kill probing here.
(text_init): kill probing here as well.
(text_parse_file): kill probing support here as well.
(text_parse_file): Do not use first line as sheet name.
* src/file.c (workbook_import): Added import dialog box.
(workbook_read): Now does only probe for existing probe routines.
(file_format_register_open): probe function being NULL now means
that this is not an auto-probe filter, but an import filter (ie,
the user has to manually select the file).
1999-07-04 Miguel de Icaza <miguel@gnu.org>
* src/file.c (file_format_register_open): Allow the probe_fn to be NULL.
* src/workbook.c (import_file_cmd): Added import menu item.
1999-07-05 Michael Meeks <michael@edenproject.org>
* src/sheet.c (sheet_update_auto_expr): Removed parsing.
......
1999-07-05 Miguel de Icaza <miguel@gnu.org>
* csv-io.c (csv_read_workbook): Load here now.
(init_plugin): Do not provide a probing routine.
1999-07-02 Miguel de Icaza <miguel@nuclecu.unam.mx>
* csv-io.c (init_plugin): Do not use for now. it has a memory
......
......@@ -13,7 +13,6 @@
#include "file.h"
#include "libcsv.h"
static struct csv_table load_and_probe_table;
static void
load_table_into_sheet (struct csv_table *table, Sheet *sheet)
......@@ -24,7 +23,6 @@ load_table_into_sheet (struct csv_table *table, Sheet *sheet)
Cell *cell;
int col;
printf ("Row: %d has %d cols\n", row, CSV_WIDTH (table, row));
for (col = 0; col < CSV_WIDTH (table, row); col++){
cell = sheet_cell_new (sheet, col, row);
cell_set_text_simple (cell, CSV_ITEM (table, row, col));
......@@ -36,55 +34,40 @@ load_table_into_sheet (struct csv_table *table, Sheet *sheet)
static Workbook *
csv_read_workbook (const char* filename)
{
struct csv_table table;
Workbook *book;
Sheet *sheet;
FILE *f;
char *name;
book = workbook_new ();
if (!book)
return NULL;
f = fopen (filename, "r");
if (f == NULL)
return NULL;
if (csv_load_table (f, &table) == -1)
return NULL;
fclose (f);
name = g_strdup_printf (_("Imported %s"), g_basename (filename));
sheet = sheet_new (book, name);
g_free (name);
workbook_attach_sheet (book, sheet);
load_table_into_sheet (&load_and_probe_table, sheet);
load_table_into_sheet (&table, sheet);
/*
* Destroy and tag as invalid
*/
csv_destroy_table (&load_and_probe_table);
load_and_probe_table.row = NULL;
csv_destroy_table (&table);
return book;
}
static gboolean
csv_probe (const char *filename)
{
FILE *f;
f = fopen (filename, "r");
if (f == NULL)
return FALSE;
if (csv_load_table (f, &load_and_probe_table) == -1){
load_and_probe_table.row = NULL;
return FALSE;
}
fclose (f);
/*
* Careful:
*
* We assume that the load routine is going to be invoked inmediately
*/
return TRUE;
}
static int
csv_can_unload (PluginData *pd)
{
......@@ -95,13 +78,13 @@ csv_can_unload (PluginData *pd)
static void
csv_cleanup_plugin (PluginData *pd)
{
file_format_unregister_open (csv_probe, csv_read_workbook);
file_format_unregister_open (NULL, csv_read_workbook);
}
int
init_plugin (PluginData * pd)
{
/* file_format_register_open (1, _("Comma Separated Value (CSV) import"), csv_probe, csv_read_workbook); */
file_format_register_open (1, _("Comma Separated Value (CSV) import"), NULL, csv_read_workbook);
pd->can_unload = csv_can_unload;
pd->cleanup_plugin = csv_cleanup_plugin;
pd->title = g_strdup (_("Comma Separated Value (CSV) module"));
......
......@@ -136,7 +136,7 @@ static int smash_fields(char *ptr, char **array, int len)
}
static char * read_line(FILE *f)
char * read_line(FILE *f)
{
int n;
if(fgets(linebuf, sizeof(linebuf),f)==NULL)
......@@ -228,6 +228,7 @@ void csv_destroy_table(struct csv_table *table)
int main(int argc, char *argv)
{
struct csv_table t;
printf("Got %d\n", parse_table(stdin, &t));
printf("Got %d\n", csv_load_table(stdin, &t));
csv_destroy_table (&t);
}
#endif
......@@ -206,7 +206,7 @@ insert_cell (Sheet* sheet, char *string, int start, int end, int col, int row)
static gint
text_parse_file (gchar *file, gint flen, gint start,
Sheet *sheet, gboolean probe)
Sheet *sheet)
{
gint idx, lindex;
gint crow = 0, ccol = 0, mcol = 0; /* current/max col/row */
......@@ -237,23 +237,16 @@ text_parse_file (gchar *file, gint flen, gint start,
case '\n':
case '\f':
if (sheet_name){
if (data && !probe)
change_sheet_name (sheet, file,
lindex, idx);
sheet_name = FALSE;
} else {
if (data && !probe)
insert_cell (sheet, file,
lindex, idx,
crow, ccol);
if (ccol > mcol)
mcol = ccol;
ccol = 0;
crow ++;
}
if (data)
insert_cell (sheet, file,
lindex, idx,
crow, ccol);
if (ccol > mcol)
mcol = ccol;
ccol = 0;
crow ++;
if (file[idx] == '\f')
sheet_end = TRUE;
sheet_end = TRUE;
data = 0;
idx ++;
lindex = idx;
......@@ -261,7 +254,7 @@ text_parse_file (gchar *file, gint flen, gint start,
break;
case '\t':
if(data && !probe){ /* Non empty cell */
if(data){ /* Non empty cell */
insert_cell (sheet, file,
lindex, idx, crow, ccol);
}
......@@ -280,16 +273,14 @@ text_parse_file (gchar *file, gint flen, gint start,
}
}
if (!probe){
if (data && idx >= 0){
insert_cell (sheet, file, lindex, idx, crow, ccol);
crow ++;
}
sheet->max_col_used = mcol;
sheet->max_row_used = crow;
if (data && idx >= 0){
insert_cell (sheet, file, lindex, idx, crow, ccol);
crow ++;
}
sheet->max_col_used = mcol;
sheet->max_row_used = crow;
return idx;
}
......@@ -339,23 +330,19 @@ readTextWorkbook (const char* filename, gboolean probe)
return NULL;
}
if (!probe){
book = workbook_new ();
if (book == NULL)
return NULL;
}
book = workbook_new ();
if (book == NULL)
return NULL;
idx = 0;
while (idx >= 0 && idx < flen){
if (!probe){
sheet = sheet_new (book, _("NoName"));
if (sheet == NULL)
sheet = sheet_new (book, _("NoName"));
if (sheet == NULL)
break;
}
idx = text_parse_file (file, flen, idx, sheet, probe);
idx = text_parse_file (file, flen, idx, sheet);
if (!probe && idx >= 0){
if (idx >= 0){
sheet->modified = FALSE;
workbook_attach_sheet (book, sheet);
}
......@@ -364,12 +351,6 @@ readTextWorkbook (const char* filename, gboolean probe)
munmap (file, flen);
close (fd);
if (probe){
book = NULL;
if (idx >= 0)
book ++;
}
return book;
}
......@@ -388,12 +369,6 @@ text_read_workbook (const char* filename)
return wb;
}
static gboolean
text_probe_workbook (const char* filename)
{
return readTextWorkbook (filename, TRUE) != NULL;
}
#if 0
int
text_write_sheet (Sheet * sheet, const char *filename)
......@@ -455,7 +430,7 @@ text_init (void)
char *desc = _("Simple Text Format");
file_format_register_open (0, desc,
text_probe_workbook,
NULL,
text_read_workbook);
file_format_register_save (".txt", desc,
......@@ -465,7 +440,7 @@ text_init (void)
static void
text_cleanup_plugin (PluginData *pd)
{
file_format_unregister_open (text_probe_workbook, text_read_workbook);
file_format_unregister_open (NULL, text_read_workbook);
file_format_unregister_save (text_write_workbook);
}
......
......@@ -22,7 +22,7 @@ idldir = $(datadir)/idl
idl_DATA = Gnumeric.idl
gladedir = $(datadir)/gnumeric/glade
glade_DATA = print.glade
glade_DATA = print.glade import.glade
EXTRA_DIST = $(idl_DATA)
......
......@@ -6,6 +6,7 @@
*/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "dialogs.h"
......@@ -36,6 +37,10 @@ file_priority_sort (gconstpointer a, gconstpointer b)
* The priority is used to give it a higher precendence to a format.
* The higher the priority, the sooner it will be tried, gnumeric registers
* its XML-based format at priority 50.
*
* If the probe_fn is NULL, we consider it a format importer, so that
* it gets only listed in the "Import..." menu, and it is not auto-probed
* at file open time.
*/
void
file_format_register_open (int priority, const char *desc,
......@@ -43,7 +48,6 @@ file_format_register_open (int priority, const char *desc,
{
FileOpener *fo = g_new (FileOpener, 1);
g_return_if_fail (probe_fn != NULL);
g_return_if_fail (open_fn != NULL);
fo->priority = priority;
......@@ -138,6 +142,7 @@ workbook_read (const char *filename)
GList *l;
char *oldlocale;
Workbook *w = NULL;
char *s;
g_return_val_if_fail (filename != NULL, NULL);
......@@ -147,21 +152,102 @@ workbook_read (const char *filename)
for (l = gnumeric_file_openers; l; l = l->next){
const FileOpener *fo = l->data;
if (fo->probe == NULL)
continue;
if ((*fo->probe) (filename)){
w = (*fo->open) (filename);
if (w) {
workbook_mark_clean (w);
break;
}
}
}
}
if (w == NULL){
s = g_strdup_printf (
N_("Could not read file %s"), filename);
gnumeric_notice (
NULL,
GNOME_MESSAGE_BOX_ERROR, s);
g_free (s);
}
setlocale (LC_NUMERIC, oldlocale);
g_free (oldlocale);
return w;
}
/*
* Lets the user choose an import filter for @filename, and
* uses that to load the file
*/
Workbook *
workbook_import (Workbook *parent, const char *filename)
{
Workbook *w = NULL;
GladeXML *gui;
GtkWidget *dialog;
GtkCList *clist;
int ret, row;
GList *l;
gui = glade_xml_new (GNUMERIC_GLADEDIR "/import.glade", NULL);
if (!gui){
g_warning ("Missing import.glade file");
return NULL;
}
dialog = glade_xml_get_widget (gui, "import-dialog");
if (parent != NULL)
gnome_dialog_set_parent (GNOME_DIALOG (dialog),
GTK_WINDOW (parent->toplevel));
clist = GTK_CLIST (glade_xml_get_widget (gui, "import-clist"));
gtk_clist_set_selection_mode (clist, GTK_SELECTION_SINGLE);
for (row = 0, l = gnumeric_file_openers; l; l = l->next){
FileOpener *fo = l->data;
char *text [1];
if (fo->probe != NULL)
continue;
text [0] = fo->format_description;
gtk_clist_append (clist, text);
gtk_clist_set_row_data (clist, row, l->data);
row++;
}
gtk_widget_show (dialog);
ret = gnome_dialog_run (GNOME_DIALOG (dialog));
if (ret == 0){
char *oldlocale;
if (clist->selection){
FileOpener *fo;
int sel_row = GPOINTER_TO_INT (clist->selection->data);
/* Files are expected to be in standard C format. */
oldlocale = g_strdup (setlocale (LC_NUMERIC, "C"));
fo = gtk_clist_get_row_data (clist, sel_row);
w = fo->open (filename);
if (w != NULL)
workbook_mark_clean (w);
setlocale (LC_NUMERIC, oldlocale);
g_free (oldlocale);
return w;
}
}
gtk_object_destroy (GTK_OBJECT (gui));
gtk_object_destroy (GTK_OBJECT (dialog));
return w;
}
static void
set_ok (GtkWidget *widget, gboolean *dialog_result)
{
......
......@@ -37,4 +37,7 @@ void file_format_register_save (char *extension,
FileFormatSave save_fn);
void file_format_unregister_save (FileFormatSave save);
Workbook *workbook_import (Workbook *parent_dlg, const char *filename);
Workbook *workbook_import_with (const char *filename, FileFormatOpen open_fn);
#endif /* GNUMERIC_FILE_H */
......@@ -203,16 +203,20 @@ print_page (Sheet *sheet, int start_col, int start_row, int end_col, int end_row
/*
* Print the repeated rows and columns
*/
print_page_repeated_rows (
sheet, start_col, start_row, end_col, end_row,
x + pj->repeat_cols_used_x, y, print_width, print_height, pj);
y += pj->repeat_rows_used_y;
print_page_repeated_cols (
sheet, start_col, start_row, end_col, end_row,
x, y, print_width, print_height, pj);
if (pj->pi->repeat_left.use){
print_page_repeated_rows (
sheet, start_col, start_row, end_col, end_row,
x + pj->repeat_cols_used_x, y, print_width, print_height, pj);
y += pj->repeat_rows_used_y;
}
x += pj->repeat_cols_used_x;
if (pj->pi->repeat_top.use){
print_page_repeated_cols (
sheet, start_col, start_row, end_col, end_row,
x, y, print_width, print_height, pj);
x += pj->repeat_cols_used_x;
}
/*
* Print the body of the data
......
......@@ -46,7 +46,7 @@ new_cmd (void)
}
static void
open_cmd (GtkWidget *widget, Workbook *wb)
file_open_cmd (GtkWidget *widget, Workbook *wb)
{
char *fname = dialog_query_load_file (wb);
Workbook *new_wb;
......@@ -56,13 +56,27 @@ open_cmd (GtkWidget *widget, Workbook *wb)
}
static void
save_cmd (GtkWidget *widget, Workbook *wb)
file_import_cmd (GtkWidget *widget, Workbook *wb)
{
char *fname = dialog_query_load_file (wb);
Workbook *new_wb;
if (!fname)
return;
new_wb = workbook_import (wb, fname);
if (new_wb)
gtk_widget_show (new_wb->toplevel);
}
static void
file_save_cmd (GtkWidget *widget, Workbook *wb)
{
workbook_save (wb);
}
static void
save_as_cmd (GtkWidget *widget, Workbook *wb)
file_save_as_cmd (GtkWidget *widget, Workbook *wb)
{
workbook_save_as (wb);
}
......@@ -742,7 +756,7 @@ print_setup_cmd (GtkWidget *widget, Workbook *wb)
}
static void
print_cmd (GtkWidget *widget, Workbook *wb)
file_print_cmd (GtkWidget *widget, Workbook *wb)
{
workbook_print (wb);
}
......@@ -794,21 +808,23 @@ static GnomeUIInfo workbook_menu_file [] = {
GNOMEUIINFO_MENU_NEW_ITEM(N_("_New"), N_("Create a new spreadsheet"),
new_cmd, NULL),
GNOMEUIINFO_MENU_OPEN_ITEM(open_cmd, NULL),
GNOMEUIINFO_MENU_OPEN_ITEM(file_open_cmd, NULL),
GNOMEUIINFO_ITEM_STOCK (N_("_Import"), N_("Imports a file"),
file_import_cmd, GNOME_STOCK_PIXMAP_OPEN),
GNOMEUIINFO_MENU_SAVE_ITEM(file_save_cmd, NULL),
GNOMEUIINFO_MENU_SAVE_ITEM(save_cmd, NULL),
GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_cmd, NULL),
GNOMEUIINFO_MENU_SAVE_AS_ITEM(file_save_as_cmd, NULL),
GNOMEUIINFO_SEPARATOR,
{ GNOME_APP_UI_ITEM, N_("Plu_g-ins..."), N_("Gnumeric plugins"),
plugins_cmd },
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_PRINT_SETUP_ITEM(print_setup_cmd, NULL),
GNOMEUIINFO_MENU_PRINT_ITEM(print_cmd, NULL),
GNOMEUIINFO_MENU_PRINT_ITEM(file_print_cmd, NULL),
GNOMEUIINFO_SEPARATOR,
......@@ -985,13 +1001,13 @@ static GnomeUIInfo workbook_toolbar [] = {
new_cmd, GNOME_STOCK_PIXMAP_NEW),
GNOMEUIINFO_ITEM_STOCK (
N_("Open"), N_("Opens an existing workbook"),
open_cmd, GNOME_STOCK_PIXMAP_OPEN),
file_open_cmd, GNOME_STOCK_PIXMAP_OPEN),
GNOMEUIINFO_ITEM_STOCK (
N_("Save"), N_("Saves the workbook"),
save_cmd, GNOME_STOCK_PIXMAP_SAVE),
file_save_cmd, GNOME_STOCK_PIXMAP_SAVE),
GNOMEUIINFO_ITEM_STOCK(
N_("Print"), N_("Prints the workbook"),
print_cmd, GNOME_STOCK_PIXMAP_PRINT),
file_print_cmd, GNOME_STOCK_PIXMAP_PRINT),
GNOMEUIINFO_SEPARATOR,
......
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