From 15e8ba0270fac14839fd4dda65418904bfd0c880 Mon Sep 17 00:00:00 2001 From: Adrian Lees Date: Mon, 2 Feb 2009 00:06:31 +0000 Subject: Selection menu and save/download tweaks svn path=/trunk/netsurf/; revision=6349 --- desktop/selection.c | 17 +++++++++++++++- desktop/selection.h | 1 + riscos/download.c | 10 ++++++++-- riscos/menus.c | 10 +++++++--- riscos/save.c | 56 +++++++++++++++++++++++++++++++---------------------- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/desktop/selection.c b/desktop/selection.c index 9140ebbf0..0d45f1720 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -134,7 +134,8 @@ void selection_reinit(struct selection *s, struct box *root) if (IS_INPUT(root)) { static int next_idx = 0; - root_idx = (next_idx++) << 28; + if (!++next_idx) next_idx = 1; + root_idx = next_idx << 28; } else root_idx = 0; @@ -191,6 +192,20 @@ void selection_init(struct selection *s, struct box *root) } +/** + * Indicate whether the selected text is read only, ie. cannot be modified. + * + * \param s selection object + * \return true iff the selection is read only + */ + +bool selection_read_only(struct selection *s) +{ + return !s->root || !NUMBER_SPACE(s->root->byte_offset); + +} + + /** * Label each text box in the given box subtree with its position * in a textual representation of the content. diff --git a/desktop/selection.h b/desktop/selection.h index 1fca4c383..7eafb2c7d 100644 --- a/desktop/selection.h +++ b/desktop/selection.h @@ -77,6 +77,7 @@ void selection_reinit(struct selection *s, struct box *root); /* bool selection_dragging_start(struct selection *s); */ #define selection_dragging_start(s) ((s)->drag_state == DRAG_START) +bool selection_read_only(struct selection *s); void selection_clear(struct selection *s, bool redraw); void selection_select_all(struct selection *s); diff --git a/riscos/download.c b/riscos/download.c index 55496451f..628789e6c 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -1198,7 +1198,12 @@ void ro_gui_download_remember_dir(const char *path) char *lastdot = NULL; char *p = path; while (*p >= 0x20) { - if (*p == '.') lastdot = p; + if (*p == '.') { + /* don't remember the directory if it's a temporary file */ + if (!lastdot && p == path + 12 && + !memcmp(path, "", 12)) break; + lastdot = p; + } p++; } if (lastdot) { @@ -1297,7 +1302,8 @@ bool ro_gui_download_save(struct gui_download_window *dw, dw->saved = true; strncpy(dw->path, file_name, sizeof dw->path); - ro_gui_download_remember_dir(file_name); + if (!dw->send_dataload || dw->save_message.data.data_xfer.est_size != -1) + ro_gui_download_remember_dir(file_name); /* grey out file icon */ error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON, diff --git a/riscos/menus.c b/riscos/menus.c index 0f9277d24..cc88f905e 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -2099,9 +2099,9 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, break; case BROWSER_SELECTION: - /* make menu available if there's a selection or an input field for pasting */ + /* make menu available if there's anything that /could/ be selected */ ro_gui_menu_set_entry_shaded(current_menu, action, - !(c && (bw->paste_callback || (bw->sel && selection_defined(bw->sel))))); + !c || (c->type != CONTENT_HTML && c->type != CONTENT_TEXTPLAIN)); break; case BROWSER_SELECTION_SAVE: if (c && (!bw->sel || !selection_defined(bw->sel))) c = NULL; @@ -2110,10 +2110,14 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, ro_gui_save_prepare(GUI_SAVE_TEXT_SELECTION, NULL, bw->sel, NULL, NULL); break; case BROWSER_SELECTION_COPY: - case BROWSER_SELECTION_CUT: ro_gui_menu_set_entry_shaded(current_menu, action, !(c && bw->sel && selection_defined(bw->sel))); break; + case BROWSER_SELECTION_CUT: + ro_gui_menu_set_entry_shaded(current_menu, action, + !(c && bw->sel && selection_defined(bw->sel) + && !selection_read_only(bw->sel))); + break; case BROWSER_SELECTION_PASTE: ro_gui_menu_set_entry_shaded(current_menu, action, !(c && bw->paste_callback)); break; diff --git a/riscos/save.c b/riscos/save.c index 900d6b651..d5dca1f1e 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -323,14 +323,16 @@ bool ro_gui_save_ok(wimp_w w) ro_gui_convert_save_path(path, sizeof path, name); gui_save_sourcew = w; saving_from_dialog = true; + gui_save_send_dataload = false; gui_save_close_after = xwimp_get_pointer_info(&pointer) || !(pointer.buttons & wimp_CLICK_ADJUST); - if (!ro_gui_save_content(gui_save_content, path, !option_confirm_overwrite)) { - memcpy(&gui_save_message.data.data_xfer.file_name, path, 1 + strlen(path)); - gui_save_send_dataload = false; - return false; + memcpy(&gui_save_message.data.data_xfer.file_name, path, 1 + strlen(path)); + + if (ro_gui_save_content(gui_save_content, path, !option_confirm_overwrite)) { + ro_gui_save_done(); + return true; } - return true; + return false; } @@ -941,24 +943,32 @@ void ro_gui_save_done(void) } if (saving_from_dialog) { - /* */ - char *sp = gui_save_message.data.data_xfer.file_name; - char *ep = sp + sizeof(gui_save_message.data.data_xfer.file_name); - char *lastdot = NULL; - char *p = sp; - - while (p < ep && *p >= 0x20) { - if (*p == '.') lastdot = p; - p++; - } - if (lastdot) { - /* remember the directory */ - char *new_dir = realloc(save_dir, (lastdot+1)-sp); - if (new_dir) { - save_dir_len = lastdot - sp; - memcpy(new_dir, sp, save_dir_len); - new_dir[save_dir_len] = '\0'; - save_dir = new_dir; + /* remember the save directory if saving to the Filer */ + if (!gui_save_send_dataload || + gui_save_message.data.data_xfer.est_size != -1) { + char *sp = gui_save_message.data.data_xfer.file_name; + char *ep = sp + sizeof(gui_save_message.data.data_xfer.file_name); + char *lastdot = NULL; + char *p = sp; + + while (p < ep && *p >= 0x20) { + if (*p == '.') { + /* don't remember the directory if it's a temporary file */ + if (!lastdot && p == sp + 12 && + !memcmp(sp, "", 12)) break; + lastdot = p; + } + p++; + } + if (lastdot) { + /* remember the directory */ + char *new_dir = realloc(save_dir, (lastdot+1)-sp); + if (new_dir) { + save_dir_len = lastdot - sp; + memcpy(new_dir, sp, save_dir_len); + new_dir[save_dir_len] = '\0'; + save_dir = new_dir; + } } } -- cgit v1.2.3