1 /*
2 ** 1998-05-25 -	Another basic GUI command, the native SWAP command handles changing of
3 **		the current dir pane. Very handy for that Opus-like feeling!
4 ** 1998-07-01 -	Expanded, generalized, and renamed this one. The commands implemented
5 **		here are now called ActivateOther (which does the same thing the old
6 **		SWAP command did), ActivateLeft, and ActivateRight.
7 ** 1999-01-30 -	Added the stack support, which is sometimes handy to have.
8 */
9 
10 #include "gentoo.h"
11 #include "dirpane.h"
12 #include "cmd_activate.h"
13 
14 /* ----------------------------------------------------------------------------------------- */
15 
16 #define	DP_STACK_SIZE	(8)
17 
18 typedef struct {
19 	guint	stack_ptr;		/* Points at next free item in stack. */
20 	guint8	stack[DP_STACK_SIZE];	/* Stack of previously active pane indices. */
21 } AcStack;
22 
23 static AcStack	the_stack = { 0 };	/* Makes sure stack pointer is initially 0 (<=> stack empty). */
24 
25 /* ----------------------------------------------------------------------------------------- */
26 
27 /* 1998-07-01 -	Activate the pane which is currently not active, i.e. the "other" one. */
cmd_activateother(MainInfo * min,DirPane * src,DirPane * dst,const CmdArg * ca)28 gint cmd_activateother(MainInfo *min, DirPane *src, DirPane *dst, const CmdArg *ca)
29 {
30 	dp_activate(dst);
31 	return 1;
32 }
33 
34 /* 1998-07-01 -	Make sure the active pane is the left one. */
cmd_activateleft(MainInfo * min,DirPane * src,DirPane * dst,const CmdArg * ca)35 gint cmd_activateleft(MainInfo *min, DirPane *src, DirPane *dst, const CmdArg *ca)
36 {
37 	dp_activate(&min->gui->pane[0]);
38 	return 1;
39 }
40 
41 /* 1998-07-01 -	Make sure the active pane is the right one. */
cmd_activateright(MainInfo * min,DirPane * src,DirPane * dst,const CmdArg * ca)42 gint cmd_activateright(MainInfo *min, DirPane *src, DirPane *dst, const CmdArg *ca)
43 {
44 	dp_activate(&min->gui->pane[1]);
45 	return 1;
46 }
47 
48 /* 1999-01-30 -	Push currently active pane onto stack. Handy if you want to
49 **		reactivate it later. Stack is finite and won't wrap; any attempt
50 **		to push more than it can hold will be (silently) ignored.
51 */
cmd_activatepush(MainInfo * min,DirPane * src,DirPane * dst,const CmdArg * ca)52 gint cmd_activatepush(MainInfo *min, DirPane *src, DirPane *dst, const CmdArg *ca)
53 {
54 	if(the_stack.stack_ptr < (sizeof the_stack.stack / sizeof the_stack.stack[0]))
55 		the_stack.stack[the_stack.stack_ptr++] = src->index;
56 	return 1;
57 }
58 
59 /* 1999-01-30 -	Activate the entry from the top of the stack. */
cmd_activatepop(MainInfo * min,DirPane * src,DirPane * dst,const CmdArg * ca)60 gint cmd_activatepop(MainInfo *min, DirPane *src, DirPane *dst, const CmdArg *ca)
61 {
62 	if(the_stack.stack_ptr > 0)
63 		dp_activate(&min->gui->pane[the_stack.stack[--the_stack.stack_ptr]]);
64 	return 1;
65 }
66