Form S_172FSO - Manage details of a snippet

LANSA

Form S_172FSO - Manage details of a snippet
* ===================================================================;
*;
* Component : S172FSO;
* Type : Form;
* Ancestor : PRIM_FORM (Primitive Form);
* ;
* Description : Maintains details of a snippet ;
*;
* Disclaimer : The following material is supplied as sample material ;
* only. No warranty concerning this material or its use ;
* in any way whatsoever is expressed or implied. ;
* ;
* ===================================================================;
;
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM FORMPOSITION(ScreenCenter) FORMSTYLE(Owned) HEIGHT(487) LAYOUTMANAGER(#ATLM_1) LEFT(421) TOP(152) VISUALSTYLE(#VS_NORM) WIDTH(362);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1);
DEFINE_COM CLASS(#STD_TEXTS.Visual) NAME(#STD_TEXTS) CAPTION('Snippet Group ') DISPLAYPOSITION(1) HEIGHT(19) LABELTYPE(Caption) LEFT(2) MARGINLEFT(70) PARENT(#COM_OWNER) TABPOSITION(1) TOP(392) WIDTH(350);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_2) ATTACHMENT(Bottom) MANAGE(#STD_TEXTS) MARGINBOTTOM(2) MARGINLEFT(2) MARGINRIGHT(2) MARGINTOP(2) PARENT(#ATLM_1);
DEFINE_COM CLASS(#STD_TEXT.Visual) NAME(#STD_TEXT) CAPTION('Snippet Name') DISPLAYPOSITION(2) HEIGHT(19) LABELTYPE(Caption) LEFT(2) MARGINLEFT(70) PARENT(#COM_OWNER) TABPOSITION(3) TOP(415) WIDTH(350);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_3) ATTACHMENT(Bottom) MANAGE(#STD_TEXT) MARGINBOTTOM(2) MARGINLEFT(2) MARGINRIGHT(2) MARGINTOP(2) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#SAVE_SNIPPET) CAPTION('Save Snippet') DISPLAYPOSITION(3) HEIGHT(20) LEFT(2) PARENT(#COM_OWNER) TABPOSITION(2) TOP(438) WIDTH(350);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_4) ATTACHMENT(Bottom) MANAGE(#SAVE_SNIPPET) MARGINBOTTOM(2) MARGINLEFT(2) MARGINRIGHT(2) MARGINTOP(2) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_MEMO) NAME(#MEMO) CURRENTLINE(1) DISPLAYPOSITION(4) HEIGHT(390) LEFT(0) MAXIMUMLINELENGTH(256) PARENT(#COM_OWNER) TABPOSITION(4) TOP(0) VISUALSTYLE(#S_172VFF) WIDTH(354);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_5) ATTACHMENT(Center) MANAGE(#MEMO) PARENT(#ATLM_1);
DEFINE_COM CLASS(#PRIM_MECL) NAME(#MECL_1) COLUMNROLE(Data) DISPLAYPOSITION(1) PARENT(#MEMO) SOURCE(#SYSVAR$AV) WIDTH(20) WIDTHTYPE(Remainder);
;
Define #String *char 256;
Define #S_172Hi *char 1;
Define #S_172Grp RefFld(#Std_TextS);
Define #S_172Nam RefFld(#Std_Text);
;
Define #S_172Pos *dec 3 0;
Define #S_172End RefFld(#S_172Pos);
Define #S_172Len RefFld(#S_172Pos);
Define #S_172File RefFld(#SysVar$av);
;
Define #MaxStrLen RefFld(#Std_Num) Default(256);
;
DEF_ARRAY NAME(#STR) INDEXES(#II) OVERLAYING(#STRING) TYPE(*CHAR) TOT_ENTRY(256) ENTRY_LEN(1);
;
Define_Evt SnippetFound;
Define_Map *Input #std_textS #SnippetGroup ;
Define_Map *Input #std_text #SnippetName;
;
Define_Evt SnippetModified;
;
Def_Cond *OkToSave '(#Std_Texts *ne *blanks) *and (#Std_Text *ne *Blanks)';
;
EVTROUTINE handling(#com_owner.CreateInstance);
Change #S_172Hi *Hival;
SET #Com_Owner Caption(*component_desc);
ENDROUTINE;
;
* Make a file name from a snippet name;
;
MthRoutine MakeFileName;
Define_Map *Input #std_textS #SnippetGroup ;
Define_Map *Input #std_text #SnippetName;
Define_Map *Output #SysVar$av #FileName ;
;
Invoke #Com_Owner.AddUnderScores ToString(#SnippetGroup.Value) ToGetString(#S_172Grp) ;
Invoke #Com_Owner.AddUnderScores ToString(#SnippetName.Value) ToGetString(#S_172Nam) ;
;
Use TConcat (*Part_Dir_Source 'S_SNIPPET_SXS_' #S_172Grp '_SXS_' #S_172Nam) (#SysVar$Av);
Use TConcat (#SysVar$Av '.snp') (#SysVar$av);
;
Set #FileName Value(#SysVar$Av) ;
;
EndRoutine;
;
* UnMake a file name into a snippet name;
;
MthRoutine UnMakeFileName;
Define_Map *Output #std_textS #SnippetGroup ;
Define_Map *Output #std_text #SnippetName;
Define_Map *Input #SysVar$av #FileName ;
;
Change #SysVar$Av #FileName.Value;
;
Change #S_172Pos 1;
USE ScanString WITH_ARGS(#SysVar$Av '_SXS_' #S_172Pos) TO_GET(#S_172Pos);
;
Change #S_172Pos '#S_172Pos + 5';
USE ScanString WITH_ARGS(#SysVar$Av '_SXS_' #S_172Pos) TO_GET(#S_172End);
;
Change #S_172Len '#S_172End - #S_172Pos' ;
Substring (#SysVar$av #S_172Pos #S_172Len) (#S_172Grp);
;
Change #S_172End '#S_172End + 5';
Substring (#SysVar$av #S_172End) (#S_172Nam);
;
Invoke #Com_Owner.RemoveUnderScores FromString(#S_172Grp) ToGetString(#SnippetGroup.Value) ;
;
Invoke #Com_Owner.RemoveUnderScores FromString(#S_172Nam) ToGetString(#SnippetName.Value) ;
;
EndRoutine;
;
* Replace blanks in a string with underscores;
;
MthRoutine AddUnderScores ;
Define_map *Input #SysVar$av #ToString;
Define_map *Output #SysVar$av #ToGetString;
;
Change #String #ToString.Value ;
;
Begin_Loop from(#MaxStrLen) to(1) Using(#ii) step(-1);
Leave if('#Str#ii *ne *Blanks');
Change #str#ii *Hival;
End_loop;
Begin_Loop from(1) to(#MaxStrLen) Using(#ii);
Leave if('#Str#ii = #S_172Hi');
Continue if('#Str#ii *ne *Blanks');
Change #str#ii '_';
End_loop;
Begin_Loop from(#MaxStrLen) to(1) Using(#ii) step(-1);
Leave if('#Str#ii *ne #S_172Hi');
Change #str#ii *blanks;
End_loop;
;
Set #ToGetString Value(#String);
;
EndRoutine;
;
* Remove underscores;
;
MthRoutine RemoveUnderScores;
Define_map *Input #SysVar$av #FromString;
Define_map *Output #SysVar$av #ToGetString;
;
Change #String #FromString.Value ;
;
Begin_Loop from(1) to(#MaxStrLen) Using(#ii);
Continue if('#Str#ii *ne ''_''');
Change #Str#ii *blanks;
End_loop;
;
Set #ToGetString Value(#String);
;
EndRoutine;
;
* Enumerate all snippet files ;
;
MthRoutine EnumerateSnippets;
define field(#ov_name) type(*char) length(10);
define field(#ov_prefix) type(*char) length(200);
define field(#ov_suffix) type(*char) length(3);
define field(#ov_retc) type(*char) length(2);
define field(#ov_errn) type(*dec) length(15) decimals(0);
;
Def_list name(#S_172List) fields(#ov_name #ov_prefix #ov_suffix) type(*working) entrys(9999);
;
Clr_List #S_172List;
;
use builtin(ov_file_service) with_args(get_dir *Part_Dir_Source 'snp' ) to_get(#ov_retc #ov_errn #S_172List);
;
selectlist #S_172List;
;
Define #S_172C14 *char 14 ;
;
Change #S_172C14 #OV_Prefix;
;
Continue If('#S_172C14 *ne ''S_SNIPPET_SXS_''');
;
Invoke #Com_Owner.UnMakeFileName SnippetGroup(#S_172Grp) SnippetName(#S_172Nam) FileName(#ov_prefix);
;
Signal SnippetFound SnippetGroup(#S_172Grp) SnippetName(#S_172Nam);
;
endselect;
;
EndRoutine;
;
* Edit a Snippet;
;
MthRoutine EditSnippet;
Define_Map *Input #std_textS #SnippetGroup ;
Define_Map *Input #std_text #SnippetName;
;
Clr_List #Memo;
;
Invoke #Com_Owner.MakeFileName SnippetGroup(#SnippetGroup.Value) SnippetName(#SnippetName.Value) FileName(#S_172File);
;
USE BUILTIN(TRANSFORM_FILE) WITH_ARGS(#Memo #S_172FILE T B Y) TO_GET(#OV_RETC);
;
Change #Std_TextS #SnippetGroup.Value;
Change #Std_Text #SnippetName.Value;
;
Set #Save_Snippet Enabled(False);
;
Invoke #Com_Owner.RestoreForm;
Invoke #Com_Owner.ShowModalForm;
;
EndRoutine;
;
* New Snippet;
;
MthRoutine NewSnippet;
Define_Map *Input #std_textS #SnippetGroup ;
;
Clr_List #Memo;
;
Change #Std_TextS #SnippetGroup.Value;
Change #Std_Text *Null;
;
Set #Save_Snippet Enabled(False);
;
Invoke #Com_Owner.RestoreForm;
;
If_Null #Std_Texts;
Invoke #Std_Texts.SetFocus ;
else;
Invoke #Std_Text.SetFocus ;
Endif;
;
Invoke #Com_Owner.ShowModalForm;
;
EndRoutine;
;
* Delete a Snippet;
;
MthRoutine DeleteSnippet;
Define_Map *Input #std_textS #SnippetGroup ;
Define_Map *Input #std_text #SnippetName;
;
Invoke #Com_Owner.MakeFileName SnippetGroup(#SnippetGroup.Value) SnippetName(#SnippetName.Value) FileName(#S_172File);
;
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(REMOVE_FILE #S_172File) TO_GET(#OV_RETC);
;
Signal SnippetModified;
;
EndRoutine;
* Enable / Disable save button;
;
EVTROUTINE HANDLING(#MEMO.Changed #Std_Text.Changed #Std_Texts.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
Set #Save_Snippet Enabled(*OkToSave);
ENDROUTINE;
;
* Handle save request ;
;
EVTROUTINE HANDLING(#SAVE_SNIPPET.Click);
Invoke #Com_Owner.MakeFileName SnippetGroup(#Std_Texts) SnippetName(#Std_Text) FileName(#S_172File);
USE TRANSFORM_LIST WITH_ARGS(#Memo #S_172FILE T B Y) TO_GET(#OV_RETC);
Signal SnippetModified;
Invoke #Com_Owner.CloseForm;
ENDROUTINE;
;
END_COM;