Shotcut improved

Post Reply
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Shotcut improved

Post by luowy »

I have completed the fully functional shortcut keys, which can use all the keys as shotcuts.
currently, some keys can't be used by shortcut:
e.g "ctrl+/" "ctrl+-" "ctrl+ Insert" ...

I made some improvements to this;

StdDialog.Item

Code: Select all

		Item* = POINTER TO EXTENSIBLE RECORD
			next*: Item;
			item-, string-, filter-: POINTER TO ARRAY OF CHAR;
			shortcut-: ARRAY 16 (*8*) OF CHAR;
			privateFilter-, failed, trapped: BOOLEAN;	(* filter call failed, caused a trap *)
			res: INTEGER	(* result code of failed filter *)
		END;
		
HostMenus.SetShortcut;

Code: Select all

 	PROCEDURE SetShortcut (VAR i: Item; VAR name: Dialog.String);
		VAR j, n, k: INTEGER; ch, nch: CHAR; 
			buf: ARRAY 16 OF CHAR; 
	BEGIN
		i.shift := FALSE; 
		i.ctrl := FALSE; 
		i.code := 0; (* i.code  is  virtual  key*)
		
		j := 0; ch := i.shortcut[0];
		WHILE (ch = '^') OR (ch = '*') OR (ch = 20X) OR (ch = 09X)DO
			IF ch = '^' THEN i.ctrl := TRUE;
			ELSIF ch = '*' THEN i.shift := TRUE;
			END;
			INC(j); ch := i.shortcut[j];
		END;
		k := 0;
		WHILE ch # 0X DO
			IF (ch >= "a") & (ch <= "z") THEN ch := CAP(ch) END;
			IF (ch # 20X) & (ch # 09X) THEN buf[k] := ch; INC(k); END;
			INC(j); ch := i.shortcut[j];
		END; 
		buf[k] := 0X;
		IF buf = '' THEN i.ctrl := FALSE; i.shift := FALSE; RETURN END;

		ch := buf[0];
		IF (LEN(buf$) = 1) THEN
			CASE ch OF 
			| '0'..'9', 'A'..'Z': i.code := ORD(buf[0]); 
			| '~', '`': i.code := 0C0H; buf := ' ~';
			| '-', '_': i.code := 0BDH; buf := ' -';
			| '+', '=': i.code := 0BBH; buf := ' +';
			| '[', '{': i.code := 0DBH; buf := ' [';
			| ']', '}': i.code := 0DDH; buf := ' ]';
			| '\', '|': i.code := 0DCH; buf := ' \';
			| ';', ':': i.code := 0BAH; buf := ' ;';
			| 27X, 22X: i.code := 0DEH; buf := ' "';
			| ',': i.code := 0BCH; buf := ' ,';
			| '.': i.code := 0BEH; buf := ' .';
			| '/': i.code := 0BFH; buf := ' /';
			ELSE
			END;
			i.ctrl := TRUE;
		ELSE
			CASE ch OF
			| 'B': 
				IF buf = 'BACKSPACE' THEN i.code := 08H; buf := 'BackSpace'; i.ctrl := TRUE;
				ELSIF buf = 'BREAK' THEN i.code := 13H; buf := 'Break'; i.ctrl := TRUE;
				END;
				
			| 'D':
				IF buf = 'DELETE' THEN i.code := 2EH; buf := 'Delete'; i.ctrl := TRUE;
				ELSIF buf = 'DOWN' THEN i.code := 28H; buf := 'Down'; i.ctrl := TRUE;
				END;
				
			| 'E':
				IF buf = 'ENTER' THEN i.code := 0DH; buf := 'Enter';(* i.ctrl := TRUE;*)
				ELSIF buf = 'ESC' THEN i.code := 1BH; buf := 'Esc'; i.ctrl := TRUE;
				ELSIF buf = 'END' THEN i.code := 23H; buf := 'End'; i.ctrl := TRUE;
				END;
				
			| 'F': (* F1 .. F16,maybe ctrl = FALSE  *)
				n := 0; k := 1; ch := buf[k];
				WHILE (ch >= "0") & (ch <= "9") DO
					n := 10 * n + ORD(ch) - ORD("0"); 
					INC(k); ch := buf[k];
				END;
				IF (n >= 1) & (n <= 16) THEN 
					i.code := 70H - 1 + n;
					buf := buf$;
				END
			| 'H':
				IF buf = 'HOME' THEN i.code := 24H; buf := 'Home'; i.ctrl := TRUE;
				END;
				
			| 'I':
				IF buf = 'INSERT' THEN i.code := 2DH; buf := 'Insert';
				END;
			| 'L':
				IF buf = 'LEFT' THEN i.code := 25H; buf := 'Left'; i.ctrl := TRUE;
				END;
				
			| 'N':
				IF (buf[1] = 'U') & (buf[2] = 'M') THEN
					IF (buf[3] >= '0') & (buf[3] <= '9') & (buf[4] = 0X)THEN
						i.code := 60H + ORD(buf[3]) - ORD('0');
						buf[1] := 'u'; buf[2] := 'm'; i.ctrl := TRUE;
					ELSIF (buf = 'NUM*') THEN
						i.code := 6AH; buf := 'Num*'; i.ctrl := TRUE;
					ELSIF (buf = 'NUM+') THEN
						i.code := 6BH; buf := 'Num+'; i.ctrl := TRUE;
					ELSIF (buf = 'NUMENTER') THEN
						i.code := 6CH; buf := 'NumEnter'; i.ctrl := TRUE;
					ELSIF (buf = 'NUM-') THEN
						i.code := 6DH; buf := 'Num-'; i.ctrl := TRUE;
					ELSIF (buf = 'NUM.') THEN
						i.code := 6EH; buf := 'Num.'; i.ctrl := TRUE;
					ELSIF (buf = 'NUM/') THEN
						i.code := 6FH; buf := 'Num/'; i.ctrl := TRUE;
					END;
				END; 
				
			| 'P':
				IF (buf = 'PAGEUP')THEN i.code := 21H; buf := 'PageUP';
				ELSIF (buf = 'PAGEDOWN') THEN i.code := 22H; buf := 'PageDown';
				END;
				i.ctrl := TRUE;
			| 'R': IF buf = 'RIGHT' THEN i.code := 27H; buf := 'Right'; i.ctrl := TRUE;
				END;
			| 'S': IF buf = 'SPACE' THEN i.code := 20H; buf := 'Space';(* i.ctrl := TRUE;*)
				END;
			| 'T':
				IF buf = 'TAB' THEN i.code := 09H; buf := 'Tab'; i.ctrl := TRUE;
				END;
			| 'U':
				IF buf = 'UP' THEN i.code := 26H; name := 'Up'; i.ctrl := TRUE;
				END;			
			ELSE
			END;
		END;
		IF i.code # 0 THEN
			name := name$ + 09X;(* Tab *)
			IF i.ctrl THEN name := name$ + 'Ctrl+'; END;
			IF i.shift THEN name := name$ + 'Shift+'; END;
			name := name$ + buf;
		END;
		
	END SetShortcut; 
	
after patching, rebuild the whole framework needed;
luowy
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Shotcut improved

Post by Josef Templ »

looks good to me.

Can there be any reason why those shortcuts were not supported originally?
I mean, for example, conflicts with shortcuts used by Windows or similar aspects.

- Josef
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: Shotcut improved

Post by luowy »

Sorry, StdMenuTool.Item must be patched:

Code: Select all

				...
				IF s.type = string THEN
					IF s.len < 16(*8*) THEN shortcut := s.string$
					ELSE Error(s, "string too long")
					END
				ELSE Error(s, "string expected")
				END;
				...
luowy
Post Reply