From 43bb22b9685a45743e92c6925fd130fefc9728cd Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 18 Dec 2011 17:59:23 +0000 Subject: Complete treeview context menu. Fix mouse trapping. Remove remaining buttons (from non-SSL trees). May return as a graphical toolbar at some point, but for now I'm glad to be rid of them. All the options are in the context menu. svn path=/trunk/netsurf/; revision=13295 --- amiga/context_menu.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++--- amiga/tree.c | 107 +++------------------------------ 2 files changed, 165 insertions(+), 107 deletions(-) diff --git a/amiga/context_menu.c b/amiga/context_menu.c index 26ff2f0c9..ec2816035 100755 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -44,6 +44,7 @@ #include "desktop/selection.h" #include "desktop/searchweb.h" #include "desktop/textinput.h" +#include "desktop/tree_url_node.h" #include "render/box.h" #include "render/form.h" #include "utils/utf8.h" @@ -943,6 +944,7 @@ void ami_context_menu_show_tree(struct tree *tree, struct Window *win, int type) struct node *root = tree_get_root(tree); struct node *sel_node = tree_get_selected_node(root); bool has_selection = tree_node_has_selection(root); + bool menu_content = false; if(ctxmenuobj) DisposeObject(ctxmenuobj); @@ -964,15 +966,61 @@ void ami_context_menu_show_tree(struct tree *tree, struct Window *win, int type) PMIA_UserData, NULL, TAG_DONE), ~0); - } + menu_content = true; + } if(type == AMI_TREE_HOTLIST) { - IDoMethod(ctxmenuobj, PM_INSERT, - NewObject(POPUPMENU_GetItemClass(), NULL, - PMIA_Title, ~0, - TAG_DONE), - ~0); + if(menu_content == true) { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + ~0); + + menu_content = false; + } + + if(has_selection && (sel_node != NULL)) { + if(tree_node_is_folder(sel_node) == true) { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_EDITFOLDER], + PMIA_ID, CMID_TREE_EDITFOLDER, + PMIA_UserData, NULL, + TAG_DONE), + ~0); + } + else + { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_EDITTITLE], + PMIA_ID, CMID_TREE_EDITTITLE, + PMIA_UserData, sel_node, + TAG_DONE), + ~0); + + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_EDITLINK], + PMIA_ID, CMID_TREE_EDITLINK, + PMIA_UserData, sel_node, + TAG_DONE), + ~0); + } + menu_content = true; + } + + if(menu_content == true) { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + ~0); + + menu_content = false; + } IDoMethod(ctxmenuobj, PM_INSERT, NewObject(POPUPMENU_GetItemClass(), NULL, @@ -989,9 +1037,84 @@ void ami_context_menu_show_tree(struct tree *tree, struct Window *win, int type) PMIA_UserData, NULL, TAG_DONE), ~0); + + if(has_selection && (sel_node != NULL) && + (tree_node_is_folder(sel_node) == true)) { + + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + ~0); + + if(tree_node_is_default(sel_node) == true) + { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_CLEARDEFAULT], + PMIA_ID, CMID_TREE_CLEARDEFAULT, + PMIA_UserData, NULL, + TAG_DONE), + ~0); + } + else + { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_SETDEFAULT], + PMIA_ID, CMID_TREE_SETDEFAULT, + PMIA_UserData, NULL, + TAG_DONE), + ~0); + } + } + + menu_content = true; + } + + if((type == AMI_TREE_HISTORY) && has_selection && + (sel_node != NULL) && (tree_node_is_folder(sel_node) == false)) { + if(menu_content == true) { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + ~0); + } + + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_ADDHOTLIST], + PMIA_ID, CMID_TREE_ADDHOTLIST, + PMIA_UserData, sel_node, + TAG_DONE), + ~0); + + menu_content = true; + } + + if(has_selection) { + if(menu_content == true) { + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + ~0); + } + + IDoMethod(ctxmenuobj, PM_INSERT, + NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_TREE_DELETE], + PMIA_ID, CMID_TREE_DELETE, + PMIA_UserData, root, + TAG_DONE), + ~0); + + menu_content = true; } - IDoMethod(ctxmenuobj, PM_OPEN, win); + if(menu_content == true) + IDoMethod(ctxmenuobj, PM_OPEN, win); } static uint32 ami_context_menu_hook_tree(struct Hook *hook, Object *item, APTR reserved) @@ -1010,6 +1133,18 @@ static uint32 ami_context_menu_hook_tree(struct Hook *hook, Object *item, APTR r tree_launch_selected(tree, true); break; + case CMID_TREE_EDITFOLDER: + hotlist_edit_selected(); + break; + + case CMID_TREE_EDITTITLE: + tree_url_node_edit_title(tree, userdata); + break; + + case CMID_TREE_EDITLINK: + tree_url_node_edit_url(tree, userdata); + break; + case CMID_TREE_NEWFOLDER: hotlist_add_folder(true); break; @@ -1017,6 +1152,22 @@ static uint32 ami_context_menu_hook_tree(struct Hook *hook, Object *item, APTR r case CMID_TREE_NEWITEM: hotlist_add_entry(true); break; + + case CMID_TREE_SETDEFAULT: + hotlist_set_default_folder(false); + break; + + case CMID_TREE_CLEARDEFAULT: + hotlist_set_default_folder(true); + break; + + case CMID_TREE_ADDHOTLIST: + hotlist_add_page(tree_url_node_get_url(userdata)); + break; + + case CMID_TREE_DELETE: + tree_delete_selected_nodes(tree, userdata); + break; } } return itemid; diff --git a/amiga/tree.c b/amiga/tree.c index a8282bb9d..86537c89c 100755 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -70,8 +70,6 @@ enum { GID_OPEN = GID_LAST, - GID_DEL, - GID_DEFAULT, GID_TREE_LAST }; @@ -467,66 +465,22 @@ void ami_tree_menu(struct treeview_window *twin) void ami_tree_update_buttons(struct treeview_window *twin) { - BOOL launch_disable = FALSE; - BOOL set_default_disable = TRUE; - if(twin->type == AMI_TREE_SSLCERT) return; if(tree_node_has_selection(tree_get_root(twin->tree))) { - struct node *selected_node = - tree_get_selected_node(tree_get_root(twin->tree)); - OnMenu(twin->win, AMI_TREE_MENU_DELETE); OnMenu(twin->win, AMI_TREE_MENU_CLEAR); - - RefreshSetGadgetAttrs((struct Gadget *)twin->objects[GID_DEL], - twin->win, NULL, - GA_Disabled, FALSE, - TAG_DONE); - - if((selected_node && (tree_node_is_folder(selected_node) == true))) - { - launch_disable = TRUE; - set_default_disable = FALSE; - } } else { OffMenu(twin->win, AMI_TREE_MENU_DELETE); OffMenu(twin->win, AMI_TREE_MENU_CLEAR); - - RefreshSetGadgetAttrs((struct Gadget *)twin->objects[GID_DEL], - twin->win, NULL, - GA_Disabled, TRUE, - TAG_DONE); - - launch_disable = TRUE; - } - - if(twin->type != AMI_TREE_COOKIES) - { - RefreshSetGadgetAttrs((struct Gadget *)twin->objects[GID_OPEN], - twin->win, NULL, - GA_Disabled, launch_disable, - TAG_DONE); - } - - if(twin->type == AMI_TREE_HOTLIST) - { - RefreshSetGadgetAttrs((struct Gadget *)twin->objects[GID_DEFAULT], - twin->win, NULL, - GA_Disabled, set_default_disable, - TAG_DONE); } } void ami_tree_open(struct treeview_window *twin,int type) { - BOOL msel = TRUE,nothl = TRUE,launchdisable=FALSE; - static WORD gen=0; - char folderclosed[100],folderopen[100],item[100]; - if(twin->win) { WindowToFront(twin->win); @@ -539,20 +493,15 @@ void ami_tree_open(struct treeview_window *twin,int type) switch(twin->type) { case AMI_TREE_HOTLIST: - nothl = FALSE; twin->wintitle = ami_utf8_easy((char *)messages_get("Hotlist")); break; case AMI_TREE_COOKIES: - nothl = TRUE; - launchdisable=TRUE; twin->wintitle = ami_utf8_easy((char *)messages_get("Cookies")); break; case AMI_TREE_HISTORY: - nothl = TRUE; twin->wintitle = ami_utf8_easy((char *)messages_get("GlobalHistory")); break; case AMI_TREE_SSLCERT: - nothl = TRUE; twin->wintitle = ami_utf8_easy((char *)messages_get("SSLCerts")); twin->sslerr = ami_utf8_easy((char *)messages_get("SSLError")); twin->sslaccept = ami_utf8_easy((char *)messages_get("Accept")); @@ -677,26 +626,6 @@ void ami_tree_open(struct treeview_window *twin,int type) SPACE_Transparent,TRUE, SPACE_BevelStyle, BVS_DISPLAY, SpaceEnd, - LAYOUT_AddChild, HGroupObject, - LAYOUT_AddChild, twin->objects[GID_OPEN] = ButtonObject, - GA_ID,GID_OPEN, - GA_Text,messages_get("TreeLaunch"), - GA_RelVerify,TRUE, - GA_Disabled,launchdisable, - ButtonEnd, - LAYOUT_AddChild, twin->objects[GID_DEL] = ButtonObject, - GA_ID,GID_DEL, - GA_Text,messages_get("TreeDelete"), - GA_RelVerify,TRUE, - ButtonEnd, - LAYOUT_AddChild, twin->objects[GID_DEFAULT] = ButtonObject, - GA_ID, GID_DEFAULT, - GA_Text, messages_get("TreeDefault"), - GA_RelVerify, TRUE, - GA_Disabled, TRUE, - ButtonEnd, - EndGroup, - CHILD_WeightedHeight,0, EndGroup, EndWindow; } @@ -800,13 +729,9 @@ BOOL ami_tree_event(struct treeview_window *twin) switch(result & WMHI_GADGETMASK) { case GID_OPEN: - if(twin->type == AMI_TREE_SSLCERT) - { - sslcert_accept(twin->ssl_data); - ami_tree_close(twin); - return TRUE; - } - else tree_launch_selected(twin->tree, true); + sslcert_accept(twin->ssl_data); + ami_tree_close(twin); + return TRUE; break; case GID_CANCEL: @@ -814,25 +739,6 @@ BOOL ami_tree_event(struct treeview_window *twin) ami_tree_close(twin); return TRUE; break; - - case GID_DEFAULT: - hotlist_set_default_folder(false); - break; - - case GID_DEL: - switch(twin->type) - { - case AMI_TREE_HISTORY: - history_global_delete_selected(); - break; - case AMI_TREE_COOKIES: - cookies_delete_selected(); - break; - case AMI_TREE_HOTLIST: - hotlist_delete_selected(); - break; - } - break; } break; @@ -847,10 +753,11 @@ BOOL ami_tree_event(struct treeview_window *twin) (twin->win->MouseY - bbox->Top >=0) && (twin->win->MouseY - bbox->Height - bbox->Top <=0)) { - if(twin->rmbtrapped == FALSE) + if((twin->type != AMI_TREE_SSLCERT) && + (twin->rmbtrapped == FALSE)) { SetWindowAttr(twin->win, WA_RMBTrap, (APTR)(BOOL)TRUE, sizeof(BOOL)); - twin->rmbtrapped = FALSE; + twin->rmbtrapped = TRUE; } } else @@ -858,7 +765,7 @@ BOOL ami_tree_event(struct treeview_window *twin) if(twin->rmbtrapped == TRUE) { SetWindowAttr(twin->win, WA_RMBTrap, (APTR)(BOOL)FALSE, sizeof(BOOL)); - twin->rmbtrapped = TRUE; + twin->rmbtrapped = FALSE; } } -- cgit v1.2.3