K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmTraining

Submitted by: JamesD



Notes:

Training provides some description and demonstration of some Macro Language statements. It is interactive, providing on screen information while the actual code for Training.kmm provides a working sample library. Training has, and will have more, extra chapters. These will be files with names in the the form of Training1[2][3]...[X].kmm. Training1.kmm is available now.

These macros require K-Meleon version 1.1.x or later.

Training includes units on promptforfolder, gensub, and $ARG.
Training1 includes units on prompt, confirm, and alert.
Updates:

2010-01-11
Minor bug fix to Training2
2009-09-20
Added Training3 with setmenu, rebuildmenu, menuchecked, setcheck, menugrayed, and setaccel
2009-01-11
Added Training2 with End/Exit, Catch, promptforfile, and basename

note: Training2 requires K-Meleon version 1.5 or later. For a 1.1 version of Training2 see here

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file(s):

Training.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
#
# Dependencies        : main.kmm,  K-Meleon ver 1.1 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.7   2008-12-24
# --------------------------------------------------------------------------------
#
####  PUBLIC MACROS ----------

Training_ArgCode{
$_Training_ArgVal = $ARG ;
$_Training_ArgVal == "menu" ? &_Training_ArgCodeA : 0 ; 
$_Training_ArgVal == "F8" ? &_Training_ArgCodeB : 0 ;
}

####  PRIVATE MACROS ---------

_Training_OverView{
$_Training_Text01 = "This 'Training' macro is provided to help users understand some statements";
$_Training_Text02 = "in the Macro Language which is a part of K-Meleon.";
$_Training_Text03 = "This macro file controls additional macro files designated as 'Training1[2][3]'.";
$_Training_Text04 = "Not all files are available yet.  They will be added as they become available. ";
alert($_Training_Text01."\n".$_Training_Text02."\n\n".$_Training_Text03."\n".$_Training_Text04, "Overview of 'Training'", "INFO");
$_Training_Text01 = "Each macro statement or concept will be reachable from the Training popup menu. ";
$_Training_Text02 = "Individual units do not follow each other.  You must choose an item from the menu. ";
$_Training_Text03 = "The additional macro files may each be made inactive via the Macro Extension  ";
$_Training_Text04 = "in preferences.  You can do this for units on which you no longer need help. ";
alert($_Training_Text01."\n".$_Training_Text02."\n\n".$_Training_Text03."\n".$_Training_Text04, "Overview of 'Training' (2)", "INFO");
$_Training_Version_Pref="general.useragent.vendorSub";
$_Training_User_Ver=getpref(STRING, $_Training_Version_Pref);
##  $_Training_User_Ver=substr(getpref(STRING, $Training_Version_Pref), 0, 3);
##  double conditional  ==> _KMVersion=="1.5"?$kSessions==true?&_Sessions_BuildMenu_15:0:0;
$_Training_Text01 = "The Macro Language has evolved through each new version of K-Meleon.";
$_Training_Text02 = "Some current language statements may not be not available to the version" ;
$_Training_Text03 = "of the browser that you are using.  Training will tell you if the version" ;
$_Training_Text04 = "you are using does not support a particular statement.";
$_Training_Text05 = "You are current using K-Meleon ";
alert($_Training_Text01."\n".$_Training_Text02."n\n".$_Training_Text03."\n".$_Training_Text04."\n\n".$_Training_Text05.$_Training_User_Ver, "Overview of 'Training' (3)", "INFO");
}

_Training_FolderCode{
$_Training_Text01 = "The promptforfolder statement is used to open a dialog with the user. \n" ;
$_Training_Text02 = "The user can select a folder from the list in the dialog.  An initial \n" ;
$_Training_Text03 = "folder may be provided.  A new folder may be created by the user.\n\n " ;
$_Training_Text04 = "  $PATH = promptforfolder( CAPTION [, INITIAL_FOLDER] ); ";
alert($_Training_Text01.$_Training_Text02.$_Training_Text03.$_Training_Text04, "promptforfolder", "INFO");
alert("Allow user to select folder. \n\n No initial folder \n No programed requirement", "Using promptforfolder") ;
$_Training_SubFolder=promptforfolder("Select a folder for use") ;
$_Training_Text01 = "$SubFolder=promptforfolder('Select a folder for use');" ;
#alert($_Training_SubFolder, "Return from promptforfolder dialog", "EXCLAIM");
$_Training_Text02 = "Some items in the default list are not actual folders. \n";
$_Training_Text03 = "'My Computer' and 'My Network Places' do not provide a value to '$SubFolder'. \n\n";
$_Training_Text04 = "Selecting 'Cancel' does not provide a value to '$SubFolder'." ;
$_Training_SubFolder == "" ? alert($_Training_Text02.$_Training_Text03.$_Training_Text04,"No value returned", "EXCLAIM") :0;
$_Training_SubFolder != "" ? alert($_Training_SubFolder. "\n\n".$_Training_Text01, "Folder user selected", "INFO") :0 ;
alert("Allow user to select folder. \n\n Set initial folder to originating folder \n No programed requirement", "Using promptforfolder") ;
$_Training_SubFolder=promptforfolder("Select a folder for use", $_Training_Path);
$_Training_Text01 = "$SubFolder=promptforfolder('Select a folder for use', $_Training_Path);";
alert( $_Training_SubFolder. "\n\n".$_Training_Text01, "Folder user selected", "INFO") ;
macros(_Training_FolderCode2) ;
}

_Training_FolderCode2{
alert("Allow user to select folder. \n\n Set initial folder to Favorites \n Require Favorites or subfolder", "Using promptforfolder") ;
####   look three places for the favorites directory
$_Training_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_Training_FavFolder==""?$_Training_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_Training_FavFolder==""?$_Training_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
####   $_Training_FavFolder should have the path for the favorites folder   c:\something\favorites
####   call _Training_RnameTrue_loop until $_Training_SubFolder is no longer a "?"
$_Training_SubFolder="?";   while($_Training_SubFolder=="?") &_Training_NameTrue_loop;
$_Training_Text01 = "Review the code in macros '_Training_FolderCode2' and '_Training_NameTrue_loop'. ";
$_Training_Text02 = "Your action was either 'cancel' or 'OK'. \n";
$_Training_Text03 = "The program is designed to default to 'Favorites' in this case. \n\n";
$_Training_SubFolder == "" ? alert($_Training_Text02.$_Training_Text03.$_Training_Text01."\n\n".$_Training_FavFolder, "The selected folder", "INFO") : alert($_Training_FavFolder."\\".$_Training_SubFolder."\n\n".$_Training_Text01, "The selected folder", "INFO") ;
}

_Training_NameTrue_loop{
$_Training_SubFolder=promptforfolder (_("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:"),$_Training_FavFolder);
$_Training_SubFolder=$_Training_SubFolder=="" ? "" : index($_Training_SubFolder,$_Training_FavFolder) == 0 ? substr($_Training_SubFolder,length($_Training_FavFolder)+1) : "?";
}

_Training_GensubCode{
$_Training_Text01 = "$SUB = gensub( r, s, h, t );" ;
$_Training_Text02 = "Searches the target string t for matches of the string r." ;
$_Training_Text03 = "If h is a string beginning with 'g' or 'G', then all matches" ; 
$_Training_Text04 = "of r are replaced with s. Otherwise, h is a number indicating" ; 
$_Training_Text05 = "which match of r to replace. The modified string is returned." ;
alert($_Training_Text01."\n".$_Training_Text02."\n".$_Training_Text03."\n".$_Training_Text04."\n".$_Training_Text05, "gensub statement", "INFO");
$_Training_Target = "copper is a color for corporate" ;
alert($_Training_Target, "The target string (t)") ;
$_Training_Match = "co" ;
$_Training_Replace = "To" ;
alert("The match string (r) is  '".$_Training_Match."'\n\n The replacement string (s) is  '".$_Training_Replace."'", "The match and replace strings", "INFO");  
$_Training_GOut = gensub($_Training_Match, $_Training_Replace, "G" ,$_Training_Target) ;
$_Training_Text01 = "$_Training_GOut = gensub($_Training_Match, $_Training_Replace, 'G' ,$_Training_Target) ;" ;
alert($_Training_GOut."\n\n".$_Training_Text01, "Global replacement", "INFO") ;
$_Training_GOut = gensub($_Training_Match, $_Training_Replace, "1" ,$_Training_Target) ;
$_Training_Text02 = "$_Training_GOut = gensub($_Training_Match, $_Training_Replace, '1' ,$_Training_Target) ;" ;
alert($_Training_GOut."\n\n".$_Training_Text02, "First replacement only", "INFO") ;
}

_Training_ArgCodeA{
$_Training_Text01 = "setmenu($_Training_Popm,'macro','$Arg','Training_ArgCode(menu)');" ;
alert("A choice was made within the Training_ArgCode macro \n based on the argument passed from the setmenu statement. \n\n The argument was 'menu'.\n\n" . $_Training_Text01 , " $ARG - argument in setmenu statement", "INFO"); 
alert("After you click OK for this message, \n\n please press the CTRL + SHIFT + F8 together.", "To test another method", "INFO");
}

_Training_ArgCodeB{
$_Training_Text01 = "setaccel( 'CTRL SHIFT VK_F8' ,'macros(Training_ArgCode(F8))');"; 
alert("A choice was made within the Training_ArgCode macro \n based on the argument passed from the setaccel statement. \n\n The argument was 'F8'.\n\n" . $_Training_Text01, " $ARG - argument in setaccel statement", "INFO"); 
alert("Training actually finished running before you pressed CTRL + SHIFT + F8. \n Your keypresses restarted Training_ArgCode and and passed 'F8' \n as an argument.", "$ARG examples finished", "INFO"); 
}

_Training_BuildMenu{
$_Training_Num = 1 ;
# add another option to Help menu
$Training_Popm = "Training" ;
#setmenu("&Help",popup,$Training_Popm,2);
setmenu("KMDocs",popup,$Training_Popm,2);
setmenu($Training_Popm,"macro","Overview","_Training_OverView");
setmenu($Training_Popm,"macro","PromptForFolder","_Training_FolderCode");
setmenu($Training_Popm,"macro","Gensub","_Training_GensubCode");
setmenu($Training_Popm,"macro","$Arg","Training_ArgCode(menu)");
macros(Training_Chapters) ;
macros(_Training_accelerators) ;
}

_Training_accelerators{
setaccel( "CTRL SHIFT VK_F8" ,"macros(Training_ArgCode(F8))"); 
}

Training_Chapters{
while($_Training_Num < 20) &_Training_Chapters_Loop ;
}
_Training_Chapters_Loop{
$_Training_File = "Training". $_Training_Num . ".kmm" ;
$_Training_ChapExist = readfile($_Training_Path."\\".$_Training_File );
$_Training_File_Menu = "Training". $_Training_Num . "_BuildMenu" ;
$_Training_ChapExist != "" ? macros($_Training_File_Menu) : 0 ;
$_Training_Num = $_Training_Num + 1 ;
}

_Training_GetPath{
## Training.kmm will be located in one of two possible locations
## If readfile finds nothing at MacroFolder then the location is UserMacroFolder
$_Training_Data=readfile(getfolder(MacroFolder)."\\Training.kmm");
$_Training_Path=getfolder($_Training_Data==""?UserMacroFolder:MacroFolder);
}

$OnInit=$OnInit."_Training_GetPath;";
$OnInit=$OnInit."_Training_BuildMenu;";
$macroModules=$macroModules."Training;";

################  END OF TRAINING.KMM  ###############################


Training1.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training1.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
# ---------- CHAPTER 1
#
# Dependencies        : main.kmm, Training.kmm, K-Meleon ver 1.1 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.3   2008-12-23
# --------------------------------------------------------------------------------

Training1_PromptCode{
#--    $VALUE = prompt( MESSAGE [, TITLE [, DEFAULT]] );
#$_Training1_Result_Bounds = 0 ;
$_Training1_Result = prompt("Select a whole number from zero to ten", "prompt example", 5);
$_Training1_Result != "" ? alert($_Training1_Result, "Your answer from prompt") : alert("Cancel", "Your answer from prompt");
macros(_Training1_PromptValid) ;
$_Training1_Text01 = "The prompt statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n The user's interaction is returned " ;
$_Training1_Text04 = "to the macro where the results \n can be acted upon. \n\n ";
$_Training1_Text05 = "$VALUE = prompt( MESSAGE [, TITLE [, DEFAULT]] ); \n\n ";
$_Training1_Text06 = "The prompt requesting a number looks like this: \n\n Result = prompt('Select a whole number between zero and ten', 'prompt example', 5);";
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05.$_Training1_Text06,"prompt example", "INFO");
}

_Training1_PromptValid{
$_Training1_Version_Pref="general.useragent.vendorSub";
$_Training1_User_Ver=substr(getpref(STRING, $_Training1_Version_Pref), 0, 3);
# choice 1.5 series = later version while other = early version
$_Training1_User_Ver == "1.5" ? &_Training1_PromptValidL : &_Training1_PromptValidE ;
}

_Training1_PromptValidL{
$_Training1_RCnt = 0 ;
$_Training1_RBI = 10 < $_Training1_Result ? 1 : 0;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = 0 > $_Training1_Result ? 1 : 0;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
## / operator produces an integer result
$_Training1_DecChek = $_Training1_Result / 1 ;
$_Training1_CrChek = $_Training1_Result == $_Training1_DecChek ? 0 : 1;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_CrChek ;
$_Training1_Text01 = "\n\n The acceptable values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10." ;
$_Training1_RCnt >= 1 ? alert($_Training1_Result.$_Training1_Text01, "Your answer was not an integer within the range.", "EXCLAIM"):0;
}

_Training1_PromptValidE{
$_Training1_RCnt = 0 ;
$_Training1_RBI = $_Training1_Result == 0 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 1 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 2 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 3 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 4 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 5 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 6 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 7 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 8 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 9 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_RBI = $_Training1_Result == 10 ? 0 : 1 ;
$_Training1_RCnt = $_Training1_RCnt + $_Training1_RBI ;
$_Training1_Text01 = "\n\n The acceptable values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10." ;
$_Training1_RCnt > 10 ? alert($_Training1_Result.$_Training1_Text01, "Your answer was not an integer within the range.", "EXCLAIM"):0;
}

Training1_ConfirmCode{
#--    $RESULT = confirm( MESSAGE [, TITLE [, BUTTONS [, ICON]]] );
#--    BUTTONS = RETRYCANCEL | YESNO | YESNOCANCEL | ABORTRETRYIGNORE
#--    ICON = EXCLAIM | INFO | STOP | QUESTION
#--    RESULT = OK | YES | NO |ABORT | RETRY | IGNORE | 0
$_Training1_Text01 = "The confirm statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n The user's interaction is returned " ;
$_Training1_Text04 = "to the macro where the results \n can be acted upon. \n\n Can you see this message?";
$_Training1_Result = confirm($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04,"confirm statement","YESNO",QUESTION) ;
$_Training1_Result == "NO" ? $_Training1_Result=confirm("You could not see prior message?", "received 'NO' from previous", "YESNO",EXCLAIM) :0 ;
$_Training1_Result == "YES" ? $_Training1_Result=confirm("Good, you did see it.", "received 'YES' from previous", "YESNO","EXCLAIM") :0 ;
$_Training1_Text01 = "are shown below.  Some shortning of text was done so they would fit \n\n" ;
$_Training1_Text02 = "Result=confirm('Bunch of text','confirm statement','YESNO','QUESTION'); \n" ;
$_Training1_Text03 = "Result=confirm('You could not see prior message?', 'received 'NO' from previous', 'YESNO','EXCLAIM'); \n" ;
$_Training1_Text04 = "Result=confirm('Good, you did see it.', 'received 'YES' from previous', 'YESNO','EXCLAIM'); \n" ;
$_Training1_Text05 = "Bye the way, your last answer was  ".$_Training1_Result. "." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05, "The previous confirm statements");
$_Training1_Text01 = "$RESULT = confirm( MESSAGE [, TITLE [, BUTTONS [, ICON]]] ); \n" ;
$_Training1_Text02 = "BUTTONS = RETRYCANCEL | YESNO | YESNOCANCEL | ABORTRETRYIGNORE \n" ;
$_Training1_Text03 = "ICON = EXCLAIM | INFO | STOP | QUESTION \n " ;
$_Training1_Text04 = "RESULT = OK | YES | NO |ABORT | RETRY | IGNORE | 0 \n\n";
$_Training1_Text05 = "Do you need to view other combinations of buttons and icons? ";
$_Training1_Result = confirm($_Training1_Text01.$_Training1_Text02.$_Training1_Text03.$_Training1_Text04.$_Training1_Text05, "confirm message box", "YESNO");
$_Training1_Result == "YES" ? macros(_Training1_ConfirmCodeA) : 0 ;
}

_Training1_ConfirmCodeA{
#alert("the user wants more");
$_Training1_Result = confirm("Choose an action", "The process stopped", "ABORTRETRYIGNORE", "STOP");
$_Training1_Text01 = "Result = confirm('Choose an action', 'The process stopped', 'ABORTRETRYIGNORE', 'STOP');";
alert("Your reply generated this answer " . $_Training1_Result. "\n\n The code was as follows \n\n". $_Training1_Text01, "confirm with buttons 'ABORTRETRYIGNORE'");
$_Training1_Result = confirm("Do you want to try another answer?", "Replay previous", "YESNOCANCEL");
$_Training1_Text01 = "Result = confirm('Do you want to try another answer?', 'Replay previous', 'YESNOCANCEL');" ;
$_Training1_Result == "YES" ? $_Training1_Text02 = "Other possible answers were  NO or 0." :0; 
$_Training1_Result == "NO" ? $_Training1_Text02 = "Other possible answers were  YES or 0." :0;
$_Training1_Result == 0 ? $_Training1_Text02 = "Other possible answers were  NO or YES." :0;
alert("Your reply generated this answer " . $_Training1_Result. "\n\n". $_Training1_Text02."\n\n The code was as follows \n\n". $_Training1_Text01, "confirm - replay previous");
$_Training1_Result == "YES" ? &_Training1_ConfirmCodeA : 0;
}

Training1_AlertCode{
#--  alert( MESSAGE [, TITLE [, ICON]] );
#--  ICON = EXCLAIM | INFO | STOP | QUESTION  
$_Training1_Text01 = "The alert statement is used to send a message to the user. \n" ;
$_Training1_Text02 = "The user must interact with the message display box in order \n" ;
$_Training1_Text03 = "for the macro to continue.  \n\n This is an alert message." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03, "alert message box", "INFO");
$_Training1_Text01 = "alert( MESSAGE [, TITLE [, ICON]] ); \n\n TITLE and ICON are optional. \n" ;
$_Training1_Text02 = "ICON can have one of the following values \n" ;
$_Training1_Text03 = "EXCLAIM | INFO | STOP | QUESTION \n\n EXCLAIM was used in this alert." ;
alert($_Training1_Text01.$_Training1_Text02.$_Training1_Text03, "form of the alert statement", "EXCLAIM");
alert("Neither TITLE nor ICON  is used in this alert");
}

Training1_BuildMenu{
# add additional lines to the training menu
setmenu($Training_Popm,"macro","[1]   Prompt","Training1_PromptCode");
setmenu($Training_Popm,"macro","[1]   Confirm","Training1_ConfirmCode");
setmenu($Training_Popm,"macro","[1]   Alert","Training1_AlertCode");
}

$macroModules=$macroModules."Training1;";
################  END OF TRAINING1.KMM  ###############################


Training2.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training2.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
# ---------- CHAPTER 2
#
# Dependencies        : main.kmm, Training.kmm, K-Meleon ver 1.5 or later
# Resources           : -
# Preferences         : -
# Version             : - 0.4   2009-01-11
# --------------------------------------------------------------------------------

Training2_EECode{
#--   How to end / cancel the execution of the macro based on a condition
$_Training2_Catch = "false" ;
macros(_Training2_EECodeRun) ;
}

_Training2_EECodeRun {
macros(_Training2_Ver);
$_Training2_Text0 = "There is neither an 'end' nor an 'exit' statement in the MacroLanguage. \n" ;
$_Training2_Text0 = $_Training2_Text0."In order to stop executing statements based upon a condition, the ending \n" ;
$_Training2_Text0 = $_Training2_Text0."brace '}' for the macro must be reached without executing statements which \n " ;
$_Training2_Text0 = $_Training2_Text0."would fail because of the condition. \n\n ";
$_Training2_Text0 = $_Training2_Text0."At the prompt which follows, please select a file of the type 'name.kmm'. ";
macros(_Training2_EECode_L ) ;
#--   There would normally not be any additional code here, but because this is training
#--   there are these additional lines
$_Training2_Text0 = "Normal execution of a macro would have stopped at the presentation of the user's \n";
$_Training2_Catch == "true" ? &_Training2_EECodeRunC : &_Training2_EECodeRunE ;
$_Training2_Text0 = $_Training2_Text0."When the end of a macro is reached, execution control returns to the \n" ;
$_Training2_Text0 = $_Training2_Text0."macro which called the macro, if any. \n\n";
$_Training2_Text1 = "_MacroFirst { \n ";
$_Training2_Text1 = $_Training2_Text1."  <code lines> ;\n ";
$_Training2_Text1 = $_Training2_Text1."  macros( _MacroSecond ) ; \n " ;
$_Training2_Text1 = $_Training2_Text1."  # control returns here from completion of _MacroSecond \n";
$_Training2_Text1 = $_Training2_Text1."  }  \n\n " ;
$_Training2_Text1 = $_Training2_Text1."_MacroSecond { \n" ;
$_Training2_Text1 = $_Training2_Text1."  <code lines> ; \n ";
$_Training2_Text1 = $_Training2_Text1."  }   " ;
alert($_Training2_Text0.$_Training2_Text1, "Execution control", INFO);
$_Training2_Text0 = "If you selected a file from the prompforfile this time, try the training \n " ;
$_Training2_Text0 = $_Training2_Text0."again and select to cancel rather than open a file. " ;
if ($_Training2_Catch == "true") alert($_Training2_Text0,"Catch", INFO); else alert($_Training2_Text0,"End / Exit", INFO);
}

_Training2_EECodeRunE{
$_Training2_Text0 = $_Training2_Text0."answer and the code example. In the case of a choice to cancel, execution would \n";
$_Training2_Text0 = $_Training2_Text0."have stopped because no code branch was provided for that case. \n\n";
}

_Training2_EECodeRunC{
$_Training2_Text0 = $_Training2_Text0."answer and the code example. In this case the to cancel is confirmed or the user \n";
$_Training2_Text0 = $_Training2_Text0."is returned to the point in the code where another attempt can be made. \n\n";
}

_Training2_EECode_L{
#-- Method for KM ver 1.5.0 or later   ( if statement )
alert($_Training2_Text0,"End / Exit", "INFO");
macros(_Training2_EECode_L2) ;
}

_Training2_EECode_L2 { 
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Result = basename($_Training2_Result, ".kmm");
if ( $_Training2_Result != "" ) {
        $_Training2_Text0 = "The creation and presentation of these lines of text occur only \n" ;
        $_Training2_Text0 = $_Training2_Text0."in the lines of code executed when the result is not missing. \n\n" ;
        $_Training2_Text0 = $_Training2_Text0."_Training2_EECode_L2{ \n ";        
        $_Training2_Text0 = $_Training2_Text0."Result = promptforfile($_Training2_Path, 'kmm files', '*.kmm'); \n" ;
        $_Training2_Text0 = $_Training2_Text0."Result = basename(Result, '.kmm'); \n";
        $_Training2_Text0 = $_Training2_Text0."if ( Result != '' ) { \n";
        $_Training2_Text0 = $_Training2_Text0."   Text0 = 'The creation and presentation of these lines . . .' \n";
        $_Training2_Text0 = $_Training2_Text0."    . \n";
        $_Training2_Text0 = $_Training2_Text0."    . \n";
        $_Training2_Text0 = $_Training2_Text0."   alert('Your selection was  '. Result.'\\n\\n'. Text0, 'Name selected') \n";
        if ( $_Training2_Catch == "true" ) {
                $_Training2_Text0 = $_Training2_Text0."   Text0 = 'You selected to cancel from the prompt for file.'; \n" ;
                $_Training2_Text0 = $_Training2_Text0."   CAnswer = confirm('Are you sure you wish to cancel?',Text0, YESNO, QUESTION); \n" ;
                $_Training2_Text0 = $_Training2_Text0."   if (CAnswer == 'NO') &_Training2_EECode_L2; else alert('Cancel is confirmed'); \n" ;
        }
        $_Training2_Text0 = $_Training2_Text0."   } ";
        alert("Your selection was  ".$_Training2_Result."\n\n".$_Training2_Text0, "Name selected");
        } 
        #-- The following statements are used only if we are training on catch        
        else { if ( $_Training2_Catch == "true" )  &_Training2_CatchRun ; }
}

Training2_CatchCode{
#--  Explain what is meant by catch in programming
$_Training2_Text0 = "The term catch means to provide an error handler within the code. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."If an error condition is encountered, there must be a way to \n" ;
$_Training2_Text0 = $_Training2_Text0."gracefully end the program or provide a way to recover from the error. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."We will use the 'End / Exit' example, but this time a method to \n" ;
$_Training2_Text0 = $_Training2_Text0."handle the condition raised by a cancel will be added. " ; 
alert($_Training2_Text0, "Catch", INFO);
$_Training2_Catch = "true" ;
macros(_Training2_EECodeRun) ;
}

_Training2_CatchRun{
$_Training2_Text0 = "You selected to cancel from the prompt for file." ;
$_Training2_CAnswer = confirm("Are you sure you wish to cancel?",$_Training2_Text0, YESNO, QUESTION); 
if ( $_Training2_CAnswer == "NO" ) &_Training2_EECode_L2; else alert("Cancel is confirmed");
}

Training2_PromptFFCode{
#--  Use of and return from promptforfile
#    $PATH = promptforfile( INITIAL_FOLDER, FILE_TYPE_DESCRIPTION, FILE_EXTENSION_PATTERN );
$_Training2_Text0 = "The promptforfile statement returns the full path, filename, and extention \n" ;
$_Training2_Text0 = $_Training2_Text0."of the selection made by the user. \n\n " ;
$_Training2_Text0 = $_Training2_Text0."$PATH = promptforfile( INITIAL_FOLDER, FILE_TYPE_DESCRIPTION, FILE_EXTENSION_PATTERN ); \n\n ";
$_Training2_Text0 = $_Training2_Text0."Required items are: \n\n " ;
$_Training2_Text0 = $_Training2_Text0." - path to initial folder \n " ;
$_Training2_Text0 = $_Training2_Text0." - file type description \n" ;
$_Training2_Text0 = $_Training2_Text0." - extention pattern -examples  *.exe  *.txt  *.kmm  *.js \n\n " ;
$_Training2_Text0 = $_Training2_Text0."Each of these must be a quoted string or a variable containing a quoted string.\n ";
alert($_Training2_Text0, "Prompt For File", INFO) ;
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Text0 = "The program generated an initial folder. \n" ;
$_Training2_Text0 = $_Training2_Text0."The file type description was 'kmm files'. \n" ;
$_Training2_Text0 = $_Training2_Text0."The extention pattern was '*.kmm'. \n\n ";
$_Training2_Text0 = $_Training2_Text0."Result = promptforfile($_Training2_Path, 'kmm files', '*.kmm');";
$_Training2_Result == "" ? $_Training2_Result = "You selected to cancel." :0; 
alert($_Training2_Result."\n\n".$_Training2_Text0, "Prompt For File", INFO) ;
}

Training2_BasenameCode{
#--  $BASE = basename( URL [, SUFFIX] ); 
#--  Returns URL with any leading directory components removed. If specified,
#--  also remove a trailing SUFFIX.
$_Training2_Text0 = "Sometimes it is not desireable to have the full path, name, and extension \n" ;
$_Training2_Text0 = $_Training2_Text0."that is received from the promptforfile statement.  We may want only \n";
$_Training2_Text0 = $_Training2_Text0."the name.  For instance, if we wanted a different path and extention for \n";
$_Training2_Text0 = $_Training2_Text0."use later in the macro. \n\n";
$_Training2_Text0 = $_Training2_Text0."$BASE = basename( URL [, SUFFIX] ); \n";
$_Training2_Text0 = $_Training2_Text0."Returns URL with any leading directory components removed. If specified, \n" ;
$_Training2_Text0 = $_Training2_Text0."also remove a trailing SUFFIX. \n\n" ;
$_Training2_Text0 = $_Training2_Text0."While meant for use with URLs, basename can strip the path and extention in \n";
$_Training2_Text0 = $_Training2_Text0."just one statement.  Notice the brackets around [, SUFFIX] in the statement?  \n";
$_Training2_Text0 = $_Training2_Text0."That means removing the suffix is optional. ";
alert($_Training2_Text0, "Basename", INFO) ;
macros(_Training2_BasenameCode2) ;
}

_Training2_BasenameCode2{
$_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm");
$_Training2_Result == "" ? &_Training2_BasenameCodeC : &_Training2_BasenameCodeNC ;
}

_Training2_BasenameCodeNC{
$_Training2_ResultNE = basename($_Training2_Result, ".kmm");
$_Training2_ResultE = basename($_Training2_Result);
$_Training2_Text1 = "Results without path and extension.  ( ResultNE )\n\n";
$_Training2_Text2 = "\n\nResults without path but retaining extension.  ( ResultE ) \n\n";
$_Training2_Text0 = "\n\nResult = promptforfile($_Training2_Path, 'kmm files', '*.kmm'); \n" ;
$_Training2_Text0 = $_Training2_Text0."ResultNE = basename(Result, '.kmm'); \n";
$_Training2_Text0 = $_Training2_Text0."ResultE = basename(Result);" ;
alert($_Training2_Text1.$_Training2_ResultNE.$_Training2_Text2.$_Training2_ResultE.$_Training2_Text0, "Basename", INFO);
$_Training2_Wiki = confirm("Would you like to view the code for an actual use of basename?","View the ChmView macro in the wiki Macrolibrary",YESNO, QUESTION); 
$_Training2_Wiki == "YES" ? open("http://kmeleon.sourceforge.net/wiki/KmmChmView") :0;
}

_Training2_BasenameCodeC{
$_Training2_Text0 = "You selected to cancel from the prompt for file." ;
$_Training2_CAnswer = confirm("Are you sure you wish to cancel?",$_Training2_Text0, YESNO, QUESTION); 
if ( $_Training2_CAnswer == "NO" ) &_Training2_BasenameCode2; else alert("Cancel is confirmed");
}

Training2_BuildMenu{
# add additional lines to the training menu
setmenu($Training_Popm,"macro","[2]   End / Exit","Training2_EECode");
setmenu($Training_Popm,"macro","[2]   Catch","Training2_CatchCode");
setmenu($Training_Popm,"macro","[2]   promptforfile","Training2_PromptFFCode");
setmenu($Training_Popm,"macro","[2]   basename","Training2_BasenameCode");
}

_Training2_GetPath{
## Training.kmm will be located in one of two possible locations
## If readfile finds nothing at MacroFolder then the location is UserMacroFolder
$__Data=readfile(getfolder(MacroFolder)."\\Training2.kmm");
$_Training2_Path=getfolder($__Data==""?UserMacroFolder:MacroFolder);
}

$OnInit=$OnInit."_Training2_GetPath;";
$macroModules=$macroModules."Training2;";
################  END OF Training2.KMM  ###############################


Training3.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Training3.kmm
# ---------- K-Meleon Macro Language Training/Example ---------------
# ---------- CHAPTER 3
#
# Dependencies        : main.kmm, Training.kmm, K-Meleon ver 1.1 or later
# Resources           : -
# Preferences         : "k-meleon_Training3_del_point"
# Version             : 0.5   2009-09-20
# --------------------------------------------------------------------------------
####  PUBLIC MACROS ----------

Training3_ArgCode{
$_Training3_ArgVal = $ARG ;
$_Training3_ArgVal == 1 ? &_Training3_SetMenuCode1 : 0 ; 
$_Training3_ArgVal == 2 ? &_Training3_SetMenuCode2 : 0 ;
$_Training3_ArgVal == 3 ? &_Training3_SetMenuCode3 : 0 ;
$_Training3_ArgVal == 4 ? &_Training3_SetMenuCode4 : 0 ;
$_Training3_ArgVal == 5 ? &_Training3_SetMenuCode5 : 0 ;
$_Training3_ArgVal == 6 ? &_Training3_SetMenuCode6 : 0 ;
$_Training3_ArgVal == 7 ? &_Training3_MenuCheckedCode2 : 0 ;
$_Training3_ArgVal == 8 ? &_Training3_SetCheckCode2 : 0 ;
$_Training3_ArgVal == 9 ? &_Training3_MenuGrayCode2 : 0 ;
}

####  PRIVATE MACROS ---------

_Training3_delPoint {
$_Training3_DP = getpref(INT,"k-meleon_Training3_del_point");
$_Training3_DP == 2 ? &_Training3_UnSetWhere : 0;
$_Training3_DP == 3 ? &_Training3_UnSetSep : 0;
$_Training3_DP == 4 ? &_Training3_UnSetAbout : 0;
$_Training3_DP == 5 ? &_Training3_UnSetPopUp : 0;
$_Training3_DP == 6 ? &_Training3_UnSetColorArg : 0;
$_Training3_DP == 7 ? &_Training3_UnSetMChecked : 0;
$_Training3_DP == 8 ? &_Training3_UnSetCMDCheck : 0;
$_Training3_DP == 9 ? &_Training3_UnSetMacroGray : 0;
$_Training3_DP == 10? &_Training3_UnSetSetAccelM : 0;
}

Training3_SetMenuCode {
#--     setmenu( MENU_NAME, ITEM_TYPE [, LABEL [, COMMAND]] [, WHERE]);
#--     ITEM_TYPE < one of the strings: inline, popup, command, macro, separator >
#--     LABEL  < string item which appears in menu - except for separator >
#--     COMMAND  < the command or macro which is to execute when selected >
#--     WHERE  < where to insert this item >
#-- LABEL must be specified for all item types except "separator". If LABEL is an empty string, this is a deletion.
#-- COMMAND must be specified for item types "command" and "macro". If COMMAND is an empty string and LABEL is not, this is a deletion.
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "The setmenu statement is used to create a menu. It has the following format.\n" ;
$_Training3_Text02 = "setmenu( MENU_NAME, ITEM_TYPE [, LABEL [, COMMAND]] [, WHERE]); \n\n" ;
$_Training3_Text03 = "MENU_NAME is a string to indentify the menu.  Any keyword may be a variable. \n";
$_Training3_Text04 = "ITEM_TYPE is one of these strings - inline, popup, command, macro, separator. \n";
$_Training3_Text05 = "LABEL is a string that is the name of the item in the menu. \n";
$_Training3_Text06 = "COMMAND is the command or macro which is to execute when selected. \n";
$_Training3_Text07 = "WHERE is the location to insert this menu item. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06.$_Training3_Text07,"The setmenu statement", "INFO");

$_Training3_Text01 = "The Demo menu has been set using variables for each part of the statement.\n" ;
$_Training3_Text02 = "The menu name is a variable called $__m set to 'The Demo'. \n" ;
$_Training3_Text03 = "ITEM_TYPE is a variable, $_Training3_Type00 set to 'macro'. \n";
$_Training3_Text04 = "LABEL is a variable, $_Training3_Label00 set to 'Explanation'. \n";
$_Training3_Text05 = "COMMAND is a variable, $_Training3_Cmd00 set to '_Training3_Explain'.\n";
$_Training3_Text06 = "WHERE is a variable, $_Training3_Whr00 set to interger 0. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"The setmenu statement", "INFO");

$_Training3_Text01 = "In order for you to be able to click on the Demo Menu,\n" ;
$_Training3_Text02 = "the currently running must be stopped. \n\n " ;
$_Training3_Text03 = "The method for you to use to re-start this macro at the \n";
$_Training3_Text04 = "point you are working is to use accelerator keys. \n\n";
$_Training3_Text05 = "After you have looked at the Demo Menu, you can press \n";
$_Training3_Text06 = "CTRL + SHIFT + T to restart the training at this point. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"The setmenu statement", "INFO");
# -- set re-entry variable
$_Training3_ReEntry = 1 ;
macros(_Training3_accelerators);
}

_Training3_SetMenuCode1 {
#--   set values into a menu line  --  SetWhere
$_Training3_Text01 = "If you look at the code for Training3.kmm you will see that there are \n" ;
$_Training3_Text02 = "additional setmenu lines in code.  We can now set some values to the \n" ;
$_Training3_Text03 = "variables for the first of those lines. \n\n " ;
$_Training3_Text04 = "We will set $_Training3_Label01 equal to 'Where', $_Training3_Cmd01 \n";
$_Training3_Text05 = "equal to '_Training3_Action01' and $_Training3_Whr01 equal to 1. \n\n";
$_Training3_Text06 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"Setmenu additional line", "INFO");
macros(_Training3_SetWhere);
$_Training3_ReEntry = 2 ;
#--    set deletion point for demo menu
setpref(INT,"k-meleon_Training3_del_point",2);
macros(_Training3_accelerators);
}

_Training3_SetMenuCode2 {
#--   set values into a menu line  --  SetSep   
$_Training3_Text01 = "Sometimes it is desireable to have a separator between items in a menu. \n\n" ;
$_Training3_Text02 = "If we set the variables for ITEM_TYPE to 'separator' and for WHERE to 'Where' \n" ;
$_Training3_Text03 = "then the separator should come before the menu item labeled 'Where'. \n\n" ;
$_Training3_Text04 = "LABEL and COMMAND do not appear in a setmenu statement for a separator. \n\n" ;
$_Training3_Text05 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05,"Separator line", "INFO");
macros(_Training3_SetSep);
$_Training3_ReEntry = 3 ;
setpref(INT,"k-meleon_Training3_del_point",3);
macros(_Training3_accelerators);
}

_Training3_SetMenuCode3 {
$_Training3_Text01 = "The setmenu statements so far have each run a macro or set a separator. \n\n" ;
$_Training3_Text02 = "You may also run a command by setting ITEM_TYPE to 'command' and setting  \n" ;
$_Training3_Text03 = "COMMAND to one of the K-Meleon Command IDs. \n\n" ;
$_Training3_Text04 = "We will do that and have a menu item for 'About KM'. \n\n" ;
$_Training3_Text05 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05,"Call command instead of macro", "INFO");
macros(_Training3_About) ;
$_Training3_ReEntry = 4 ;
setpref(INT,"k-meleon_Training3_del_point",4);
macros(_Training3_accelerators);
}

_Training3_SetMenuCode4 {
$_Training3_Text01 = "Setmenu can also create a menu within a menu.  This is called a popup menu. \n\n" ;
$_Training3_Text02 = "We will set ITEM/TYPE to 'popup' for one statement and then follow that with  \n" ;
$_Training3_Text03 = "two statements where the ITEM_TYPE is 'macro' and the MENU_NAME is the name of  \n" ;
$_Training3_Text04 = "the popup menu. The lines will then look like this:\n\n" ;
$_Training3_Text05 = "setmenu('The Demo','popup','Our Popup','macros(dummy)',5);  \n";
$_Training3_Text06 = "setmenu('Our Popup','macro','First Choice','_Training3_Choice1',0;  \n";
$_Training3_Text07 = "setmenu('Our Popup','macro','Second Choice,'_Training3_Choice2',1);  \n\n";
$_Training3_Text08 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06.$_Training3_Text07.$_Training3_Text08,"Creat a popup menu", "INFO");
macros(_Training3_PopUp) ;
$_Training3_ReEntry = 5 ;
setpref(INT,"k-meleon_Training3_del_point",5);
macros(_Training3_accelerators);
}

_Training3_SetMenuCode5 {
$_Training3_Text01 = "The first question most users have is 'Where do I get the value for MENU_NAME?' \n\n" ;
$_Training3_Text02 = "Most of the time that can be found in 'k-meleon\\defaults\\settings\\menus.cfg'.  \n" ;
$_Training3_Text03 = "Menus such as 'Tools' that can be reached by the ALT + T will have an & in the \n" ;
$_Training3_Text04 = "actual menu name. It will come before the letter in the menu which has the underscore. \n" ;
$_Training3_Text05 = "In the case of 'Tools' that means the actual MENU_NAME is &Tools. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05,"And MENU_NAME is . . .", "INFO");

$_Training3_Text01 = "Items in a menu may be deleted using the setmenu statement. \n\n" ;
$_Training3_Text02 = "LABEL must be specified for all item types except 'separator'.  \n" ;
$_Training3_Text03 = "If LABEL is an empty string, this is a deletion. \n\n" ;
$_Training3_Text04 = "COMMAND must be specified for item types 'command' and 'macro'. \n" ;
$_Training3_Text05 = "If COMMAND is an empty string and LABEL is not, this is a deletion. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05,"Delete an item from a menu", "INFO");

$_Training3_Text01 = "To delete the 'separator' in the 'Demo Menu' in this training, the WHERE field \n" ;
$_Training3_Text02 = "was set to the word 'Where', which was the menu item to follow.  When the menu item \n" ;
$_Training3_Text03 = "which had the LABEL equal to 'Where' was deleted, the separator was also. \n\n" ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03,"Delete a separator from a menu", "INFO");

$_Training3_Text01 = "A menu can be created in which a variable displays in the menu and is available to \n" ;
$_Training3_Text02 = "the executing macro as the special variable '$ARG'.  In such instances, the 'command' keyword \n" ;
$_Training3_Text03 = "is followed by open paren, the value or variable which is to become the $ARG variable, \n" ;
$_Training3_Text04 = "and a closing paren.  It might look like one of the following lines. \n\n" ;
$_Training3_Text05 = "setmenu( MENU_NAME, ITEM_TYPE, LABEL, $_CmdVar.'('.$_VarName.')', WHERE); \n  or \n" ;
$_Training3_Text06 = "setmenu( MENU_NAME, ITEM_TYPE, LABEL, '_Training3_ColorArg(Red)', WHERE); " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"Create a $ARG variable with a menu", "INFO");

$_Training3_Text01 = "In this example there are two menu items labeled 'Red' and 'Gold'. \n" ;
$_Training3_Text02 = "They both call the same macro, but pass the label as an argument. \n\n" ;
$_Training3_Text03 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03,"Create a $ARG variable with a menu", "INFO");
macros(_Training3_ColorArg) ;
$_Training3_ReEntry = 6 ;
setpref(INT,"k-meleon_Training3_del_point",6);
macros(_Training3_accelerators);
}

_Training3_SetMenuCode6 {
$_Training3_Text01 = "Everything demonstrated here can be found in the code for 'Training3. \n\n" ;
$_Training3_Text02 = "This completes the section on setmenu(). " ;
alert($_Training3_Text01.$_Training3_Text02,"Conclusion of setmenu section", "INFO");
macros(_Training3_acceleratorOff);
}

_Training3_SetWhere {
$_Training3_Label01="Where"  ;  
$_Training3_Cmd01= "_Training3_Action01" ;
$_Training3_Whr01= 1;
macros(_Training3_BuildMenuLine);
}

_Training3_UnSetWhere {
$_Training3_Label01=""  ;  
$_Training3_Cmd01= "_Training3_Action01" ;
#$_Training3_Whr01= 1;
macros(_Training3_BuildMenuLine);
}

_Training3_SetSep {
#-- point existing setmenu separator to correct menu
$_Training3_SMs = "The Demo";
macros(_Training3_BuildMenuLine);
#-- now point existing setmenu separator away from our menu
$_Training3_SMs="Dummy" ;
}

_Training3_UnSetSep {
macros(_Training3_UnSetWhere);
#-- point existing setmenu separator to missing WHERE item
$_Training3_SMs = "The Demo";
macros(_Training3_BuildMenuLine);
#-- now point existing setmenu separator away from our menu
$_Training3_SMs="Dummy" ;
}

_Training3_About {
$_Training3_Label02="About KM" ;     $_Training3_Type02="command";  
$_Training3_Cmd02= "ID_APP_ABOUT" ;  $_Training3_Whr02= 4;
macros(_Training3_BuildMenuLine);
}

_Training3_UnSetAbout {
macros(_Training3_UnSetSep);
$_Training3_Label02="" ;  $_Training3_Type02="command"; $_Training3_Cmd02= "ID_APP_ABOUT" ; 
macros(_Training3_BuildMenuLine);
}

_Training3_PopUp {
$_Mm = "Our Popup";           $_Training3_Label03=$_Mm;
$_Training3_Type03="popup";   $_Training3_Whr03= 5;
macros(_Training3_PopUp2);
$_Training3_Label03 = ""; $_Training3_Type03="macro";  $_Training3_Cmd03= "macros(dummy)" ;
}

_Training3_UnSetPopUp {
$_Mm = "Our Popup";         $_Training3_Label03="";
$_Training3_Type03="popup"; $_Training3_Whr03= 5;
macros(_Training3_UnSetAbout);
macros(_Training3_BuildMenuLine);
}
_Training3_PopUp2 {
$_Training3_Label04="First Choice" ;
$_Training3_Cmd04= "_Training3_Choice1" ;
$_Training3_Whr04= 0;
$_Training3_Label05="Second Choice" ;
$_Training3_Cmd05= "_Training3_Choice2" ;
$_Training3_Whr05= 1;
macros(_Training3_BuildMenuLine);
}

_Training3_ColorArg {
$_Training3_Label06="Red" ;
$_Training3_Cmd06= _Training3_Color."(".$_Training3_Label06.")" ;
$_Training3_Whr06= 6;
$_Training3_Label07="Gold" ;
$_Training3_Cmd07= _Training3_Color."(".$_Training3_Label07.")" ;
$_Training3_Whr07= 7;
macros(_Training3_BuildMenuLine);
}

_Training3_UnSetColorArg {
macros(_Training3_UnSetPopUp);
macros(_Training3_BuildMenuLine);
$_Training3_Label06="Red" ;
$_Training3_Cmd06= "" ;
$_Training3_Label07="Gold" ;
$_Training3_Cmd07= "" ;
macros(_Training3_BuildMenuLine);
}

_Training3_BuildMenuLine {
$_g="Demo Menu";
$__m="The Demo";
setmenu($_g,inline,$__m);
setmenu($__m,$_Training3_Type00,$_Training3_Label00,$_Training3_Cmd00,$_Training3_Whr00);
setmenu($__m,$_Training3_Type01,$_Training3_Label01,$_Training3_Cmd01,$_Training3_Whr01);
setmenu($__m,$_Training3_Type02,$_Training3_Label02,$_Training3_Cmd02,$_Training3_Whr02);
setmenu($__m,$_Training3_Type03,$_Training3_Label03,$_Training3_Cmd03,$_Training3_Whr03);
setmenu($_Mm,$_Training3_Type04,$_Training3_Label04,$_Training3_Cmd04,$_Training3_Whr04);
setmenu($_Mm,$_Training3_Type05,$_Training3_Label05,$_Training3_Cmd05,$_Training3_Whr05);
setmenu($__m,$_Training3_Type06,$_Training3_Label06,$_Training3_Cmd06,$_Training3_Whr06);
setmenu($__m,$_Training3_Type07,$_Training3_Label07,$_Training3_Cmd07,$_Training3_Whr07);
setmenu($_Training3_SMs,separator,"Where");
rebuildmenu($__m); 
}

_Training3_Action01 {
$_Training3_Text01 = "The 'WHERE' part of the setment statement specifies the \n" ;
$_Training3_Text02 = "location within the menu to insert the addressed item. \n\n" ;
$_Training3_Text03 = "Insert before an item specified either by label or by command. \n" ;
$_Training3_Text04 = "Insert at the end of the addressed menu (-1). \n";
$_Training3_Text05 = "Insert at position n of the addressed menu (1st position: 0) \n";
$_Training3_Text06 = "WHERE can be omitted for all item types except 'separator' (-1 is the default).";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06, "Where", INFO);
}

_Training3_Explain {
$_Training3_Text01 = "This menu only for use with the 'Training' item found in \n" ;
$_Training3_Text02 = "the HELP menu.  It appears when the 'Training3.kmm' macro is  \n" ;
$_Training3_Text03 = "installed and active. \n\n " ;
$_Training3_Text04 = "To make 'Training3.kmm' inactive, you may go to preferences as \n ";
$_Training3_Text05 = "EDIT - PREFERENCES - K-MELEON PLUGINS - MACRO EXTENSIONS \n";
$_Training3_Text06 = "and remove the checkmark by 'Training3'. Restart KM to take effect.";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06, "Demo Menu explanation");
}

_Training3_Choice1 {
alert("This is the macro for First Choice", "Popup menu item", INFO) ;
}

_Training3_Choice2 {
alert("This is the macro for Second Choice", "Popup menu item", INFO) ;
}

_Training3_Color {
$_Training3_ColorVal = $ARG ;
alert("The color selected is ". $_Training3_ColorVal, "Value of $ARG passed to macro", INFO);
}

Training3_RebuildMenuCode {
#--     rebuildmenu (menuName);
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "The rebuildmenu statement is used to change a menu. It has the following format.\n" ;
$_Training3_Text02 = "rebuildmenu( MENU_NAME ); \n\n" ;
$_Training3_Text03 = "Rebuildmenu is used after a change in the value of a variable in the setmenu statement. \n";
$_Training3_Text04 = "Look at the '_Training3_SetWhere' macro in the Training3.kmm file for an example. \n";
$_Training3_Text05 = "Sometimes the macro containing the rebuildmenu statement must be separate from other  \n";
$_Training3_Text06 = "setmenu statements.  Look at the code for the popup menu in Training3.kmm. \n";
$_Training3_Text07 = "_Training3_PopUp and _Training3_PopUp2 are the macros to inspect. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06.$_Training3_Text07,"The rebuildmenu statement", "INFO");
} 

Training3_MenuCheckedCode {
#--   menuchecked = boolean expression ;
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "The menuchecked statement is used to display or not display a checkmark beside a menu\n" ;
$_Training3_Text02 = "item when that menu is visible.  The format is menuchecked = boolean expression ; \n\n" ;
$_Training3_Text03 = "The menuchecked statement must be in the macro which is called by the menu item. \n";
$_Training3_Text04 = "The statement often looks like 'menuchecked = $Variable;' and the $Variable must be \n";
$_Training3_Text05 = "a global variable because local variables are out of scope in the case.  \n";
$_Training3_Text06 = "Training will create a menu item called 'Running' and display a checkmark. \n";
$_Training3_Text07 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. " ;
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06.$_Training3_Text07,"The menuchecked statement", "INFO");
#- set boolean variable for boolean expression to 'true'.
$Training3_RunningOK = true ;
macros(_Training3_SetMacroCheck);
# -- set re-entry variable
$_Training3_ReEntry = 7 ;
setpref(INT,"k-meleon_Training3_del_point",7);
macros(_Training3_accelerators);
}

_Training3_MenuCheckedCode2 {
$_Training3_Text01 = "When the value of the variable for the boolean expression is 'false' then no\n" ;
$_Training3_Text02 = "checkmark is displayed by the item in the menu. \n\n" ;
$_Training3_Text03 = "The variable preveiously set was '$Training3_RunningOK = true ;'. \n";
$_Training3_Text04 = "If that variable is set to 'false' then no checkmark will appear \n";
$_Training3_Text05 = "when the menu is displayed.  \n";
$_Training3_Text06 = "It is not required to rebuild the menu for this to happen. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"The menuchecked statement", "INFO");
#- set boolean variable for boolean expression to 'false'.
$Training3_RunningOK = false ;
macros(_Training3_acceleratorOff);
} 

_Training3_SetMacroCheck {
$_Training3_Label01="Running"  ;  
$_Training3_Cmd01= "_Training3_Action02" ;
$_Training3_Whr01= 1;
macros(_Training3_BuildMenuLine);
}

_Training3_Action02 {
menuchecked = $Training3_RunningOK ;
alert("This is action taken when 'Running' is clicked", "Running ( menuchecked )", INFO);
}

_Training3_UnSetMChecked {
$_Training3_Label01="Running"  ;  
$_Training3_Cmd01= "" ;
macros(_Training3_BuildMenuLine);
}

Training3_SetCheckCode {
#--   setcheck( COMMAND, STATE );
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "The setcheck statement is used to display or not display a checkmark beside a menu\n" ;
$_Training3_Text02 = "item which calls a COMMAND ID when that menu is visible.  \n\n" ;
$_Training3_Text03 = "The format is setcheck( COMMAND, STATE );. \n\n" ;
$_Training3_Text04 = "Training will create a menu item called 'About KM' and display a checkmark. \n";
$_Training3_Text05 = "After creating the menu item the following statement is processed. \n";
$_Training3_Text06 = "setcheck( 'ID_APP_ABOUT', true );  \n\n";
$_Training3_Text07 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06.$_Training3_Text07,"The setcheck statement", "INFO");
macros(_Training3_SetCMDCheck);
#- set boolean variable for boolean expression to 'true'.
setcheck( "ID_APP_ABOUT", true );
$_Training3_ReEntry = 8 ;
setpref(INT,"k-meleon_Training3_del_point",8);
macros(_Training3_accelerators); 
}

_Training3_SetCheckCode2 {
$_Training3_Text01 = "If we process a statement setting the STATE value to false,  \n";
$_Training3_Text02 = "the checkmark will not display. \n";
$_Training3_Text03 = "Training will process the following statement. \n\n";
$_Training3_Text04 = "setcheck( 'ID_APP_ABOUT', false ); ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04,"The setcheck statement", "INFO");
#- set boolean variable for boolean expression to 'false'.
setcheck( "ID_APP_ABOUT", false );
macros(_Training3_acceleratorOff);
}

_Training3_SetCMDCheck {
$_Training3_Label02="About KM" ;     $_Training3_Type02="command";  
$_Training3_Cmd02= "ID_APP_ABOUT" ;  $_Training3_Whr02= -1;
macros(_Training3_BuildMenuLine);
}

_Training3_UnSetCMDCheck {
$_Training3_Label02=""  ;
$_Training3_Cmd02= "ID_APP_ABOUT" ;
macros(_Training3_BuildMenuLine);
}

Training3_MenuGrayCode {
#--   menugrayed =  boolean expression ; 
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "The menugrayed statement is used to 'gray out' or 'make unavailable' a menu\n" ;
$_Training3_Text02 = "item when that menu is visible.  The format is menugrayed =  boolean expression;. \n\n" ;
$_Training3_Text03 = "Training will create a menu item called 'Downloading' but wll make it unavailable by \n";
$_Training3_Text04 = "putting the following statement into the macro which Downloading calls. \n\n";
$_Training3_Text05 = "menugrayed = $_MG_State;, where $_MG_State has the value 'false'.  \n\n";
$_Training3_Text06 = "The macro will stop so you can view/use the Demo Menu. CTRL + SHIFT + T to restart. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"The menugrayed statement", "INFO");
macros(_Training3_SetMacroGray);
$_Training3_ReEntry = 9 ;
setpref(INT,"k-meleon_Training3_del_point",9);
macros(_Training3_accelerators); 
}

_Training3_MenuGrayCode2 {
$_Training3_Text01 = "If we process a statement setting the value of $_MG_State to false,  \n";
$_Training3_Text02 = "the menu item will no longer be grayed and will be available. \n";
$_Training3_Text03 = "Training will process the following statement. \n\n";
$_Training3_Text04 = "$_MG_State = false; ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04,"The menugrayed statement", "INFO");
#- set boolean variable for boolean expression to 'false'.
$_Training3_MG_State = false;
macros(_Training3_acceleratorOff);
}

_Training3_SetMacroGray {
$_Training3_Label02="Downloading"  ;
$_Training3_Type02="macro";  
$_Training3_Cmd02= "_Training3_DownloadingSet" ;
$_Training3_Whr02= -1;
macros(_Training3_BuildMenuLine);
$_Training3_MG_State = true;
}

_Training3_DownloadingSet {
menugrayed = $_Training3_MG_State;
alert("Downloading is running \n\n ==>\n    ==>\n        ==>","Downloading available", INFO);
}

_Training3_UnSetMacroGray {
$_Training3_Label02="" ;  $_Training3_Cmd02= "_Training3_DownloadingSet" ;
macros(_Training3_BuildMenuLine);
}

Training3_SetAccelCode {
#--   setaccel( keys [,command]);
getpref(INT,"k-meleon_Training3_del_point") != 0 ? &_Training3_delPoint : 0 ;
$_Training3_Text01 = "Keyboard accelerators can be set using the setaccel statement. \n\n" ;
$_Training3_Text02 = "The format of the statement is setaccel( keys , command );. \n\n" ;
$_Training3_Text03 = "'Keys' is a space-separated list of predefined key names.  \n";
$_Training3_Text04 = "'Command' may be a Command ID, a pluginName(pluginCommand), or \n";
$_Training3_Text05 = "a call to a macro.  Example - setaccel('CTRL ALT VK_NUMPAD0', 'macros(SomeName)');.";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05,"The setaccel statement", "INFO");

$_Training3_Text01 = "The Demo Menu will be expanded to include links to more information \n" ;
$_Training3_Text02 = "on the keys that can be defined in the setaccel statement. \n\n" ;
$_Training3_Text03 = "Setaccel along with $ARG has been used in Training to set re-entry \n";
$_Training3_Text04 = "points so that you could see/use the Demo Menu.  Study the code to see \n";
$_Training3_Text05 = "how this was done. Look in _Training3_accelerators {} for that code. ";
alert($_Training3_Text01.$_Training3_Text02.$_Training3_Text03.$_Training3_Text04.$_Training3_Text05.$_Training3_Text06,"The setaccel statement", "INFO");
macros(_Training3_SetSetAccelM);
$_Training3_ReEntry = 10 ;
setpref(INT,"k-meleon_Training3_del_point",10);
macros(_Training3_accelerators); 
}

_Training3_SetSetAccelM {
$_Training3_Label06="Accelerator keys"  ;
$_Training3_Type06="macro";  
$_Training3_Cmd06= "_Training3_AccKeysExt" ;
$_Training3_Whr06= 2;
$_Training3_Label07="Default Accelerators Keys"  ;
$_Training3_Type07="macro";  
$_Training3_Cmd07= "_Training3_DefKeysExt" ;
$_Training3_Whr07= 3;
macros(_Training3_BuildMenuLine);
}

_Training3_AccKeysExt {
$_Training3_Text01 = "When you click 'OK' to end this message, a new tab or window will be \n" ;
$_Training3_Text02 = "opened and an web page with information on accelerator keys loaded. \n\n" ;
alert($_Training3_Text01.$_Training3_Text02,"Accelerator Keys Page", "INFO");
$_Training3_AK ="http://freenet-homepage.de/CoolMcKluus/software/kmeleon/project/reference/cfgfiles/accel.html#keys";
$kTabs?opentab( $_Training3_AK ):opennew( $_Training3_AK );
}

_Training3_DefKeysExt {
$_Training3_Text01 = "When you click 'OK' to end this message, a new tab or window will be \n" ;
$_Training3_Text02 = "opened and an web page about KM's default accelerator keys loaded. \n\n" ;
alert($_Training3_Text01.$_Training3_Text02,"Accelerator Keys Page", "INFO");
$_Training3_DAK ="http://two.xthost.info/kmeleon/lizard/commands.html#l_defaccel";
$kTabs?opentab( $_Training3_DAK ):opennew( $_Training3_DAK );
}

_Training3_UnSetSetAccelM {
$_Training3_Label06=""  ;
$_Training3_Type06="macro";  
$_Training3_Cmd06= "_Training3_AccKeysExt" ;
$_Training3_Label07=""  ;
$_Training3_Type07="macro";  
$_Training3_Cmd07= "_Training3_DefKeysExt" ;
macros(_Training3_BuildMenuLine);
}

_Training3_accelerators {
setaccel( "CTRL SHIFT T" ,"macros(Training3_ArgCode(".$_Training3_ReEntry."))"); 
} 

_Training3_acceleratorOff {
## "macros(dummy)" used instead of "" - bug report 1134
setaccel( "CTRL SHIFT T" ,"macros(dummy)"); 
} 

Training3_BuildMenu {
# add additional lines to the training menu
#--     setmenu( MENU_NAME, ITEM_TYPE [, LABEL [, COMMAND]] [, WHERE]);
#--     ITEM_TYPE < one of the strings: inline, popup, command, macro, separator >
#--     LABEL  < string item which appears in menu - except for separator >
#--     COMMAND  < the command or macro which is to execute when selected >
#--     WHERE  < where to insert this item >
setmenu($Training_Popm,"macro","[3]   SetMenu","Training3_SetMenuCode");
setmenu($Training_Popm,"macro","[3]   RebuildMenu","Training3_RebuildMenuCode");
setmenu($Training_Popm,"macro","[3]   MenuChecked","Training3_MenuCheckedCode");
setmenu($Training_Popm,"macro","[3]   SetCheck","Training3_SetCheckCode");
setmenu($Training_Popm,"macro","[3]   MenuGrayed","Training3_MenuGrayCode");
setmenu($Training_Popm,"macro","[3]   SetAccel","Training3_SetAccelCode");

#-- set the demo menu
#-- set initial values to the variables
$_Training3_Type00 = "macro" ;
$_Training3_Label00= "Explanation" ;
$_Training3_Cmd00 =  "_Training3_Explain" ;
$_Training3_Whr00= 0 ;

$_Training3_Type01 = "macro"  ;
$_Training3_Label01= ""  ;  
$_Training3_Cmd01 =  "macros(dummy)" ;
$_Training3_Whr01= -1;

$_Training3_Type02="macro"  ;
$_Training3_Label02=""  ;  
$_Training3_Cmd02= "macros(dummy)" ;
$_Training3_Whr02= -1;

$_Training3_Type03="macro"  ;
$_Training3_Label03=""  ;  
$_Training3_Cmd03= "macros(dummy)" ;
$_Training3_Whr03= -1;

$_Training3_Type04="macro"  ;
$_Training3_Label04=""  ;  
$_Training3_Cmd04= "macros(dummy)" ;
$_Training3_Whr04= -1;

$_Training3_Type05="macro"  ;
$_Training3_Label05=""  ;  
$_Training3_Cmd05= "macros(dummy)" ;
$_Training3_Whr05= -1;

$_Training3_Type06="macro"  ;
$_Training3_Label06=""  ;  
$_Training3_Cmd06= "macros(dummy)" ;
$_Training3_Whr06= -1;

$_Training3_Type07="macro"  ;
$_Training3_Label07=""  ;  
$_Training3_Cmd07= "macros(dummy)" ;
$_Training3_Whr07= -1;

$_Training3_SMs="Dummy" ;
$_Mm="The Demo";
#-- create the menu
$_g="Demo Menu";
setmenu(Main,popup,$_g,-1);
$__m="The Demo";
macros(_Training3_BuildMenuLine);
}

_Training3_ClearPref {
delpref("k-meleon_Training3_del_point");
}

$OnQuit=$OnQuit."_Training3_ClearPref;";
$macroModules=$macroModules."Training3;";
################  END OF Training3.kmm  ###############################

Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.