Dev/Mod/References.odc

MODULE DevReferences;
(**
	project	= "BlackBox"
	organization	= "www.oberon.ch"
	contributors	= "Oberon microsystems"
	version	= "System/Rsrc/About"
	copyright	= "System/Rsrc/About"
	license	= "Docu/BB-License"
	changes	= "
	- 20121106, Fyodor Tkachov, Scan uses V.IsModule, V.IsImport to correctly open documentation by module alias
	- 20111211, Fyodor Tkachov, switched from National to i21sysCharacters
	- 20091016, для поддержки русификации:
	     предложения Е.Э.Темиргалеева, вставка рукой Ткачева Ф.В.
	     ShowDocuLang добавлена Ф.В.Ткачевым.
	- YYYYMMDD, nn, ...
	"
	issues	= "
	- ...
	"

**)
	
	IMPORT
		Kernel, Files, Fonts, Models, Views, Dialog, Containers,
		StdDialog,
		TextModels, TextMappers, TextViews, TextControllers, 
		Ch := i21sysCharacters, V := i21sysVocabulary;
	
	CONST
		(* additional scanner types *)
		import = 100; module = 101; semicolon = 102; becomes  = 103; comEnd = 104;


	PROCEDURE SpecialFont (r: TextModels.Reader): BOOLEAN;
		CONST max = 14 * Fonts.point;
	BEGIN
		RETURN (r.attr.font.weight > Fonts.normal) & (r.attr.font.size <= max)
	END SpecialFont;
	
	PROCEDURE SearchIdent (
		t: TextModels.Model; ident: TextMappers.String; VAR beg, end: INTEGER; bold: BOOLEAN
	);
		VAR r: TextModels.Reader; found: BOOLEAN; ch: CHAR; len, i: INTEGER;
	BEGIN
		end := 0;
		IF ident # "" THEN
			len := 0; WHILE ident[len] # 0X DO INC(len) END;
			r := t.NewReader(NIL); found := FALSE;
			beg := 0; r.SetPos(0); r.ReadChar(ch);
			WHILE ~r.eot & ~found DO
				(* search legal start symbol *)
				WHILE ~r.eot & ~Ch.IsFirstIdentChar(ch) DO
(*				WHILE ~r.eot & ((ch < "A") OR (ch > "Z") & (ch # "_") & (ch < "a") OR (ch > "z")) DO *)
					INC(beg); r.ReadChar(ch)
				END;
				i := 0;
				WHILE ~r.eot & (~bold OR SpecialFont(r)) & (i # len) & (ch = ident[i]) DO
					r.ReadChar(ch); INC(i)
				END;
				found := (i = len) & ~Ch.IsIdentChar(ch);
(*				found := (i = len) &
								((ch < "0") OR (ch > "9") & (ch < "A") OR (ch > "Z") & (ch # "_") & (ch < "a") OR (ch > "z")); *)
				IF ~r.eot & ~found THEN	(* skip rest of identifier *)
					beg := r.Pos() - 1;
					WHILE ~r.eot & Ch.IsIdentChar(ch) DO
(*					WHILE ~r.eot &
						~((ch < "0") OR (ch > "9") & (ch < "A") OR (ch > "Z") & (ch # "_") & (ch < "a") OR (ch > "z")) DO *)
						INC(beg); r.ReadChar(ch)
					END
				END
			END;
			IF found THEN end := r.Pos() - 1 END
		END
	END SearchIdent;

	PROCEDURE ShowText* (module, ident: TextMappers.String; category: Files.Name);
		VAR title: Views.Title; loc: Files.Locator; name: Files.Name;
			v: Views.View; m: Models.Model; t: TextModels.Model; beg, end: INTEGER; c: Containers.Controller;

		PROCEDURE IsDocu ( category: Files.Name ): BOOLEAN;
		BEGIN
			category[4] := 0X;
			RETURN category = "Docu"
		END IsDocu;
		
	BEGIN
		StdDialog.GetSubLoc(module, category, loc, name); title := name$;
		Kernel.MakeFileName(name, "");
		IF IsDocu( category ) THEN
			loc.res := 77; v := Views.OldView(loc, name); loc.res := 0;
			IF v # NIL THEN
				WITH v: Containers.View DO
					c := v.ThisController();
					IF c # NIL THEN
						c.SetOpts(c.opts - {Containers.noFocus, Containers.noSelection} + {Containers.noCaret})
					END
				ELSE
				END;
				Views.OpenAux(v, title)
			END
		ELSE
			v := Views.OldView(loc, name);
			IF v # NIL THEN Views.Open(v, loc, name, NIL) END
		END;
		IF v # NIL THEN
			m := v.ThisModel();
			IF (m # NIL) & (m IS TextModels.Model) THEN
				t := m(TextModels.Model);
				SearchIdent(t, ident, beg, end, TRUE);
				IF end <= 0 THEN SearchIdent(t, ident, beg, end, FALSE) END;
				IF end > 0 THEN
					TextViews.ShowRange(t, beg, end, TextViews.any);
					TextControllers.SetSelection(t, beg, end)
				ELSIF ident # "" THEN Dialog.Beep
				END
			ELSE Dialog.ShowMsg("#System:WrongSelection")
			END
		ELSE Dialog.ShowParamMsg("#System:FileNotFound", name, "", "")
		END
	END ShowText;
	
	PROCEDURE Scan (VAR s: TextMappers.Scanner);
	BEGIN
		s.Scan;
		IF s.type = TextMappers.string THEN
			IF      V.IsImport( s.string ) THEN s.type := import
			ELSIF V.IsModule( s.string ) THEN s.type := module
			END
		ELSIF s.type = TextMappers.char THEN
			IF s.char = ";" THEN s.type := semicolon
			ELSIF s.char = ":" THEN
				IF s.rider.char = "=" THEN s.rider.Read; s.type := becomes END
			ELSIF s.char = "(" THEN
				IF s.rider.char = "*" THEN
					s.rider.Read;
					REPEAT Scan(s) UNTIL (s.type = TextMappers.eot) OR (s.type = comEnd);
					Scan(s)
				END
			ELSIF s.char = "*" THEN
				IF s.rider.char = ")" THEN s.rider.Read; s.type := comEnd END
			END
		END	
	END Scan;
	
	PROCEDURE CheckModName (VAR mod: TextMappers.String; t: TextModels.Model);
		VAR s: TextMappers.Scanner;
	BEGIN
		s.ConnectTo(t); s.SetPos(0); Scan(s);
		IF s.type = module THEN
			Scan(s);
			WHILE (s.type # TextMappers.eot) & (s.type # import) DO Scan(s) END;
			WHILE (s.type # TextMappers.eot) & (s.type # semicolon)
					& ((s.type # TextMappers.string) OR (s.string # mod)) DO Scan(s) END;
			IF s.type = TextMappers.string THEN
				Scan(s);
				IF s.type = becomes THEN
					Scan(s);
					IF s.type = TextMappers.string THEN
						mod := SHORT(s.string$)
					END
				END
			END
		END
	END CheckModName;

	PROCEDURE Show (category: Files.Name);
		VAR c: TextControllers.Controller; s: TextMappers.Scanner; beg, end: INTEGER;
			module, ident: TextMappers.String;
	BEGIN
		c := TextControllers.Focus();
		IF c # NIL THEN
			IF c.HasSelection() THEN
				c.GetSelection(beg, end);
				s.ConnectTo(c.text); s.SetOpts({7});	(* acceptUnderscores *)
				s.SetPos(beg); s.Scan;
				IF s.type = TextMappers.string THEN
					module := s.string; ident := "";
					CheckModName(module, c.text);
					s.Scan;
					IF (s.type = TextMappers.char) & (s.char = ".") THEN
						s.Scan;
						IF s.type = TextMappers.string THEN ident := s.string END
					END;
					ShowText(module, ident, category)
				ELSE Dialog.ShowMsg("#System:WrongSelection")
				END
			ELSE Dialog.ShowMsg("#System:NoSelection")
			END
		ELSE Dialog.ShowMsg("#System:NoFocus")
		END
	END Show;

	PROCEDURE ShowSource*;
	BEGIN
		Show("Mod")
	END ShowSource;

	PROCEDURE ShowDocu*;
	BEGIN
		Show("Docu")
	END ShowDocu;

	PROCEDURE ShowDocuLang* (lang: ARRAY OF CHAR); 
	(*cf. DevSearch.SearchInDocuLang*)
	BEGIN
		IF  lang = ''  THEN
			Show( "Docu" )
		ELSE
			Show( "Docu/" + lang )
		END;
	END ShowDocuLang;

END DevReferences.

 DevReferences.Show

Files.Directory

"DevReferences.ShowDocuLang('ru')"


DevReferences.ShowSource
i21sysInПримеры