Commit f09dc013 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Take reference wb in case a URI is relative. All callers changed.

2006-03-18  Morten Welinder  <terra@gnome.org>

	* src/parse-util.c (wbref_parse): Take reference wb in case a URI
	is relative.  All callers changed.

	* src/application.c (cb_workbook_uri): Renamed from
	cb_workbook_name.
	(gnm_app_workbook_get_by_uri): Renamed from
	gnm_app_workbook_get_by_name.
	(gnm_app_workbook_get_by_name): New function that tries URI,
	absolute filename, and relative URI.
parent 04b8968f
2006-03-18 Morten Welinder <terra@gnome.org>
* src/parse-util.c (wbref_parse): Take reference wb in case a URI
is relative. All callers changed.
* src/application.c (cb_workbook_uri): Renamed from
cb_workbook_name.
(gnm_app_workbook_get_by_uri): Renamed from
gnm_app_workbook_get_by_name.
(gnm_app_workbook_get_by_name): New function that tries URI,
absolute filename, and relative URI.
2006-03-17 Morten Welinder <terra@gnome.org>
* src/application.c (gnm_app_workbook_get_by_index,
......
......@@ -111,6 +111,8 @@ Morten:
* Make CORREL, COVAR, RSQ, SLOPE, and INTERCEPT really ignore
blanks. [#334591]
* Fix DOLLARDE and DOLLARFR.
* Resurrect the ability to name external workbooks by filename,
including relative filename. (But things still expand to URIs.)
Jon Kre:
* Hand clipboard off to clipboard manager when exiting.
......
2006-03-18 Morten Welinder <terra@gnome.org>
* src/parse-util.c (wbref_parse): Take reference wb in case a URI
is relative. All callers changed.
* src/application.c (cb_workbook_uri): Renamed from
cb_workbook_name.
(gnm_app_workbook_get_by_uri): Renamed from
gnm_app_workbook_get_by_name.
(gnm_app_workbook_get_by_name): New function that tries URI,
absolute filename, and relative URI.
2006-03-17 Morten Welinder <terra@gnome.org>
* src/application.c (gnm_app_workbook_get_by_index,
......
......@@ -57,7 +57,7 @@ capp_workbook_open (PortableServer_Servant ignore,
CORBA_boolean shared_view,
CORBA_Environment *ev)
{
Workbook *wb = gnm_app_workbook_get_by_name (file_name);
Workbook *wb = gnm_app_workbook_get_by_name (file_name, NULL);
WorkbookView *wbv;
if (wb != NULL) {
......
......@@ -34,6 +34,7 @@
#include <gtk/gtkicontheme.h>
#include <glib/gi18n.h>
#include <goffice/utils/go-glib-extras.h>
#include <goffice/utils/go-file.h>
#define GNM_APP(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GNM_APP_TYPE, GnmApp))
#define GNM_APP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GNM_APP_TYPE, GnmAppClass))
......@@ -365,17 +366,56 @@ gnm_app_clipboard_area_get (void)
return NULL;
}
struct wb_name_closure {
Workbook *
gnm_app_workbook_get_by_name (char const *name,
char const *ref_uri)
{
Workbook *wb;
char *filename = NULL;
/* Try as URI. */
wb = gnm_app_workbook_get_by_uri (name);
if (wb)
goto out;
filename = g_filename_from_utf8 (name, -1, NULL, NULL, NULL);
/* Try as absolute filename. */
if (filename && g_path_is_absolute (filename)) {
char *uri = go_filename_to_uri (filename);
wb = gnm_app_workbook_get_by_uri (uri);
g_free (uri);
if (wb)
goto out;
}
if (filename && ref_uri) {
char *rel_uri = go_url_encode (filename, 1);
char *uri = go_url_resolve_relative (ref_uri, rel_uri);
g_free (rel_uri);
wb = gnm_app_workbook_get_by_uri (uri);
g_free (uri);
if (wb)
goto out;
}
out:
g_free (filename);
return wb;
}
struct wb_uri_closure {
Workbook *wb;
char const *name;
char const *uri;
};
static gboolean
cb_workbook_name (Workbook * wb, gpointer closure)
cb_workbook_uri (Workbook * wb, gpointer closure)
{
struct wb_name_closure *dat = closure;
struct wb_uri_closure *dat = closure;
const char *wb_uri = workbook_get_uri (wb);
if (wb_uri && strcmp (wb_uri, dat->name) == 0) {
if (wb_uri && strcmp (wb_uri, dat->uri) == 0) {
dat->wb = wb;
return FALSE;
}
......@@ -383,12 +423,12 @@ cb_workbook_name (Workbook * wb, gpointer closure)
}
Workbook *
gnm_app_workbook_get_by_name (char const * const name)
gnm_app_workbook_get_by_uri (char const *uri)
{
struct wb_name_closure closure;
struct wb_uri_closure closure;
closure.wb = NULL;
closure.name = name;
gnm_app_workbook_foreach (&cb_workbook_name, &closure);
closure.uri = uri;
gnm_app_workbook_foreach (&cb_workbook_uri, &closure);
return closure.wb;
}
......
......@@ -15,7 +15,9 @@ GObject *gnm_app_get_app (void);
void gnm_app_workbook_list_add (Workbook *wb);
void gnm_app_workbook_list_remove (Workbook *wb);
GList * gnm_app_workbook_list (void);
Workbook *gnm_app_workbook_get_by_name (char const *name);
Workbook *gnm_app_workbook_get_by_uri (char const *uri);
Workbook *gnm_app_workbook_get_by_name (char const *name,
char const *ref_uri);
Workbook *gnm_app_workbook_get_by_index (int i);
gboolean gnm_app_workbook_foreach (GnmWbIterFunc func, gpointer data);
......
......@@ -216,7 +216,7 @@ dhl_get_target_email (HyperlinkState *state, gboolean *success)
return g_strconcat ("mailto:", address, NULL);
}
encoded = go_url_encode ((char*)subject);
encoded = go_url_encode (subject, 0);
result = g_strconcat ("mailto:", address, "?subject=", encoded, NULL);
g_free (encoded);
......
......@@ -64,8 +64,6 @@ static GOMemChunk *expression_pool_small, *expression_pool_big;
#define CHUNK_FREE(p,v) g_free ((v))
#endif
#define GNM_EXPR_SET_OPER(e,o) ((e)->oper = (o))
/***************************************************************************/
/**
......@@ -97,7 +95,7 @@ gnm_expr_new_funcallv (GnmFunc *func, int argc, GnmExprConstPtr *argv)
ans = CHUNK_ALLOC (GnmExprFunction, expression_pool_small);
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_FUNCALL);
ans->oper = GNM_EXPR_OP_FUNCALL;
gnm_func_ref (func);
ans->func = func;
ans->argc = argc;
......@@ -166,7 +164,7 @@ gnm_expr_new_unary (GnmExprOp op, GnmExpr const *e)
if (!ans)
return NULL;
GNM_EXPR_SET_OPER (ans, op);
ans->oper = op;
ans->value = e;
return (GnmExpr *)ans;
......@@ -183,7 +181,7 @@ gnm_expr_new_binary (GnmExpr const *l, GnmExprOp op, GnmExpr const *r)
if (!ans)
return NULL;
GNM_EXPR_SET_OPER (ans, op);
ans->oper = op;
ans->value_a = l;
ans->value_b = r;
......@@ -202,7 +200,7 @@ gnm_expr_new_name (GnmNamedExpr *name,
if (!ans)
return NULL;
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_NAME);
ans->oper = GNM_EXPR_OP_NAME;
ans->name = name;
expr_name_ref (name);
......@@ -223,7 +221,7 @@ gnm_expr_new_cellref (GnmCellRef const *cr)
if (!ans)
return NULL;
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_CELLREF);
ans->oper = GNM_EXPR_OP_CELLREF;
ans->ref = *cr;
return (GnmExpr *)ans;
......@@ -248,7 +246,7 @@ gnm_expr_new_array_corner(int cols, int rows, GnmExpr const *expr)
if (ans == NULL)
return NULL;
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_ARRAY_CORNER);
ans->oper = GNM_EXPR_OP_ARRAY_CORNER;
ans->rows = rows;
ans->cols = cols;
ans->value = NULL;
......@@ -265,7 +263,7 @@ gnm_expr_new_array_elem (int x, int y)
if (ans == NULL)
return NULL;
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_ARRAY_ELEM);
ans->oper = GNM_EXPR_OP_ARRAY_ELEM;
ans->x = x;
ans->y = y;
return (GnmExpr *)ans;
......@@ -278,7 +276,7 @@ gnm_expr_new_setv (int argc, GnmExprConstPtr *argv)
{
GnmExprSet *ans = CHUNK_ALLOC (GnmExprSet, expression_pool_small);
GNM_EXPR_SET_OPER (ans, GNM_EXPR_OP_SET);
ans->oper = GNM_EXPR_OP_SET;
ans->argc = argc;
ans->argv = argv;
......
......@@ -784,7 +784,7 @@ unquote (char *dst, char const *src, int n)
* Otherwise returns @start and does not modify @wb.
* **/
static char const *
wbref_parse (char const *start, Workbook **wb)
wbref_parse (char const *start, Workbook **wb, Workbook *ref_wb)
{
/* Is this an external reference ? */
if (*start == '[') {
......@@ -810,7 +810,9 @@ wbref_parse (char const *start, Workbook **wb)
} else
unquote (name, start+2, end-start-2);
tmp_wb = gnm_app_workbook_get_by_name (name);
tmp_wb = gnm_app_workbook_get_by_name
(name,
ref_wb ? workbook_get_uri (ref_wb) : NULL);
if (tmp_wb == NULL)
return NULL;
*wb = tmp_wb;
......@@ -965,12 +967,14 @@ rangeref_parse (GnmRangeRef *res, char const *start, GnmParsePos const *pp,
{
char const *ptr = start, *start_sheet, *tmp1, *tmp2;
Workbook *wb;
Workbook *ref_wb;
g_return_val_if_fail (start != NULL, start);
g_return_val_if_fail (pp != NULL, start);
wb = pp->wb;
start_sheet = wbref_parse (start, &wb);
ref_wb = wb ? wb : pp->sheet->workbook;
start_sheet = wbref_parse (start, &wb, ref_wb);
if (start_sheet == NULL)
return start; /* TODO error unknown workbook */
ptr = sheetref_parse (start_sheet, &res->a.sheet, wb, TRUE);
......@@ -1068,7 +1072,7 @@ gnm_1_0_rangeref_parse (GnmRangeRef *res, char const *start, GnmParsePos const *
g_return_val_if_fail (pp != NULL, start);
wb = pp->wb;
ptr = wbref_parse (start, &wb);
ptr = wbref_parse (start, &wb, NULL);
if (ptr == NULL)
return start; /* TODO error unknown workbook */
......
......@@ -668,9 +668,19 @@ string_opt_quote : STRING
workbookref : '[' string_opt_quote ']' {
char const *wb_name = $2->constant.value->v_str.val->str;
Workbook *wb = gnm_app_workbook_get_by_name (wb_name);
Workbook *ref_wb = state->pos
? (state->pos->wb
? state->pos->wb
: (state->pos->sheet
? state->pos->sheet->workbook
: NULL))
: NULL;
Workbook *wb = gnm_app_workbook_get_by_name
(wb_name,
ref_wb ? workbook_get_uri (ref_wb) : NULL);
if (wb != NULL) {
g_print ("Got %s\n", workbook_get_uri (wb));
unregister_allocation ($2); gnm_expr_free ($2);
$$ = wb;
} else {
......@@ -699,8 +709,8 @@ sheetref: string_opt_quote SHEET_SEP {
}
}
| workbookref string_opt_quote SHEET_SEP {
Sheet *sheet = parser_sheet_by_name ($1, $2);
Workbook *wb = $1;
Sheet *sheet = parser_sheet_by_name (wb, $2);
if (sheet != NULL) {
unregister_allocation ($2); gnm_expr_free ($2);
$$ = sheet;
......
......@@ -897,7 +897,7 @@ wb_view_sendto (WorkbookView *wbv, GOCmdContext *context)
/* mutt does not handle urls with no destination
* so pick something to arbitrary */
GError *err = NULL;
char *url, *tmp = go_url_encode (full_name);
char *url, *tmp = go_url_encode (full_name, 0);
url = g_strdup_printf ("mailto:someone?attach=%s", tmp);
g_free (tmp);
#ifdef WITH_GNOME
......
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