summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2010-08-28 22:44:35 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2010-08-28 22:44:35 +0000
commit890e7b2b466451528f7cfd64b88a16275ae5c2d0 (patch)
tree63efa83b7374e21b23906dc2abb48abf36d8e96e
parentfe750bd0082d455d0be688793e2d5dbdb3b37a42 (diff)
downloadnetsurf-890e7b2b466451528f7cfd64b88a16275ae5c2d0.tar.gz
netsurf-890e7b2b466451528f7cfd64b88a16275ae5c2d0.tar.bz2
Add ARexx commands CLOSE (close window/tab) and ACTIVE (current window/tab number to
pass to other ARexx commands) Add CloseTabs.nsrx script to close all tabs in the current window except the active one svn path=/trunk/netsurf/; revision=10718
-rwxr-xr-xamiga/arexx.c91
-rwxr-xr-xamiga/dist/NetSurf.guide8
-rw-r--r--amiga/dist/Rexx/CloseTabs.nsrx47
3 files changed, 144 insertions, 2 deletions
diff --git a/amiga/arexx.c b/amiga/arexx.c
index 59e9b1035..296178317 100755
--- a/amiga/arexx.c
+++ b/amiga/arexx.c
@@ -52,7 +52,9 @@ enum
RX_FORWARD,
RX_HOME,
RX_RELOAD,
- RX_WINDOWS
+ RX_WINDOWS,
+ RX_ACTIVE,
+ RX_CLOSE
};
STATIC char result[100];
@@ -70,6 +72,8 @@ STATIC VOID rx_forward(struct ARexxCmd *, struct RexxMsg *);
STATIC VOID rx_home(struct ARexxCmd *, struct RexxMsg *);
STATIC VOID rx_reload(struct ARexxCmd *, struct RexxMsg *);
STATIC VOID rx_windows(struct ARexxCmd *, struct RexxMsg *);
+STATIC VOID rx_active(struct ARexxCmd *, struct RexxMsg *);
+STATIC VOID rx_close(struct ARexxCmd *, struct RexxMsg *);
STATIC struct ARexxCmd Commands[] =
{
@@ -86,6 +90,8 @@ STATIC struct ARexxCmd Commands[] =
{"HOME", RX_HOME, rx_home, "WINDOW/K/N,TAB/K/N", 0, NULL, 0, 0, NULL },
{"RELOAD", RX_RELOAD, rx_reload, "FORCE/S,WINDOW/K/N,TAB/K/N", 0, NULL, 0, 0, NULL },
{"WINDOWS", RX_WINDOWS, rx_windows, "WINDOW/K/N", 0, NULL, 0, 0, NULL },
+ {"ACTIVE", RX_ACTIVE, rx_active, "TAB/S", 0, NULL, 0, 0, NULL },
+ {"CLOSE", RX_CLOSE, rx_close, "WINDOW/K/N,TAB/K/N", 0, NULL, 0, 0, NULL },
{ NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL }
};
@@ -156,6 +162,30 @@ struct browser_window *ami_find_tab_gwin(struct gui_window_2 *gwin, int tab)
return NULL;
}
+int ami_find_tab_bw(struct gui_window_2 *gwin, struct browser_window *bw)
+{
+ int tabs = 0;
+ struct Node *ctab;
+ struct Node *ntab;
+ struct browser_window *tbw = NULL;
+
+ if((bw == NULL) || (gwin->tabs == 0)) return 1;
+
+ ctab = GetHead(&gwin->tab_list);
+
+ do
+ {
+ tabs++;
+ ntab=GetSucc(ctab);
+ GetClickTabNodeAttrs(ctab,
+ TNA_UserData, &tbw,
+ TAG_DONE);
+ if(tbw == bw) return tabs;
+ } while(ctab=ntab);
+
+ return NULL;
+}
+
struct browser_window *ami_find_tab(int window, int tab)
{
int windows = 0, tabs = 0;
@@ -490,3 +520,62 @@ STATIC VOID rx_windows(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((
else sprintf(result, "%ld", windows);
cmd->ac_Result = result;
}
+
+STATIC VOID rx_active(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused)))
+{
+ int windows = 0, tabs = 0;
+ int window = 0, tab = 0;
+ struct browser_window *bw = curbw;
+ struct nsObject *node, *nnode;
+ struct gui_window_2 *gwin;
+
+ cmd->ac_RC = 0;
+
+ if(!IsMinListEmpty(window_list))
+ {
+ node = (struct nsObject *)GetHead((struct List *)window_list);
+
+ do
+ {
+ nnode=(struct nsObject *)GetSucc((struct Node *)node);
+
+ gwin = node->objstruct;
+
+ if(node->Type == AMINS_WINDOW)
+ {
+ windows++;
+ if(gwin->bw == bw)
+ {
+ window = windows;
+ break;
+ }
+ }
+ } while(node = nnode);
+ }
+
+ if(cmd->ac_ArgList[0])
+ {
+ tab = ami_find_tab_bw(gwin, bw);
+ }
+
+ if(cmd->ac_ArgList[0]) sprintf(result, "%ld", tab);
+ else sprintf(result, "%ld", window);
+ cmd->ac_Result = result;
+}
+
+STATIC VOID rx_close(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused)))
+{
+ struct browser_window *bw = curbw;
+
+ cmd->ac_RC = 0;
+
+ if((cmd->ac_ArgList[0]) && (cmd->ac_ArgList[1]))
+ bw = ami_find_tab(*(ULONG *)cmd->ac_ArgList[0], *(ULONG *)cmd->ac_ArgList[1]);
+ else if(cmd->ac_ArgList[0])
+ {
+ ami_close_all_tabs(bw->window->shared);
+ return;
+ }
+
+ if(bw) browser_window_destroy(bw);
+}
diff --git a/amiga/dist/NetSurf.guide b/amiga/dist/NetSurf.guide
index 378cf23ad..5abf13946 100755
--- a/amiga/dist/NetSurf.guide
+++ b/amiga/dist/NetSurf.guide
@@ -114,13 +114,19 @@ Move back to the home page.
@{b}RELOAD FORCE/S,WINDOW/K/N,TAB/K/N@{ub} (2.10626)
Reload the current page, FORCE will do a full reload.
+@{b}CLOSE WINDOW/K/N,TAB/K/N@{ub} (2.10718)
+Close the current page. A window or window and tab can be specified. Note that when a tab is closed, the tab number of tabs to the right of it will change, and the currently active tab may also change. If the last tab or window is closed, NetSurf will usually exit. Make sure you account for these situations in your code.
+
@{b}VERSION VERSION/N REVISION/N RELEASE/S@{ub}
Returns the current version of NetSurf in RESULT. You can also do version checking by supplying a VERSION and optional REVISION to check against. If the version of NetSurf is the same or higher 1 will be returned, if it is older 0. If RELEASE is specified, the command operates on the release version rather than the internal version number.
+@{b}ACTIVE TAB/S@{ub} (2.10718)
+Returns the active window (or tab if TAB is specified). Commands automatically operate on the active window/tab so you do not normally need to use this.
+
@{b}WINDOWS WINDOW/K/N@{ub} (2.10656)
Puts the number of windows into RESULT. If the WINDOW keyword is specified, will put the number of tabs in that window into RESULT.
-The WINDOW/K/N,TAB/K/N parameters were added in 2.10656 and allow targetting a window other than the current one. Both WINDOW and TAB must be specified (TAB=1 for tabless window)
+The WINDOW/K/N,TAB/K/N parameters were added in 2.10656 and allow targetting a window other than the current one. Both WINDOW and TAB must be specified (TAB=1 for tabless window) except in the special case of the CLOSE command.
The ARexx menu will be populated with scripts named #?.nsrx in @{"arexx_dir" link options 9}, up to a maximum of 20 entries. The titles of these entries will be the comments field of the file (or the filename if comments field is empty).
@endnode
diff --git a/amiga/dist/Rexx/CloseTabs.nsrx b/amiga/dist/Rexx/CloseTabs.nsrx
new file mode 100644
index 000000000..276ae11a3
--- /dev/null
+++ b/amiga/dist/Rexx/CloseTabs.nsrx
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* This script closes all tabs other than the current one */
+
+options results
+address netsurf
+
+/* Find the currently active window and tab */
+active
+awin = result
+active tab
+atab = result
+
+/* Find out how many tabs are in the active window */
+windows window awin
+tabs = result
+
+if tabs=1 then exit
+
+/* Close all tabs above the current one */
+do t=tabs to atab+1 by -1
+ close window awin tab t
+end
+
+/* Close all tabs below the current one
+ * NB: The active tab number will change when lower-numbered tabs are closed!
+ */
+
+do t=1 to atab-1
+ close window awin tab 1
+end