General
: K-Meleon Forum
General discussion about K-Meleon.
Goto:
Forum List
•
Message List
•
Search
•
Log In
Your Name:
Subject:
Help information
BBcode help
Smileys help
[quote=JamesD] The current MacroLibrary http://kmeleon.sourceforge.net/wiki/MacroLibrary is for KM versions 1.1 and later. [quote=MacroLibrary] Macros for versions of K-Meleon prior to 1.1 can be found in the old Macro Library. [/quote] Any macro using the 'if then else' statement rather than the traditional conditional statement will only run in KM version 1.5 and later. So my question is do I always use only the 'condition ? true : false;' statement for macros going into the MacroLibrary or go with the most modern code? I am preparing to add Training2.kmm into the MacroLibrary. I am going to put the version using 'if then else' there and a version for users of version 1.1 in this thread. I would like to hear from users as to whether this is the right way to do this. Should I always prepare two version of a macro? Should I move forward and only prepare a macro with the most modern code? I should point out that Training2 will be found under Training in the MacroLibrary and does require Training.kmm in order to run. [b]Training2.kmm[/b] [code] # 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.1 or later # Resources : - # Preferences : - # Version : - 0.4a 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 { $_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_E ); #-- 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. " $_Training2_Catch == "true" ? alert($_Training2_Text0,"Catch", INFO) : 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_E{ #-- Method for KM ver 1.1.x . . . . Note this also works in KM 1.5.x versions alert($_Training2_Text0,"End / Exit", "INFO"); macros(_Training2_EECode_E2) ; } _Training2_EECode_E2{ $_Training2_Result = promptforfile($_Training2_Path, "kmm files", "*.kmm"); $_Training2_Result = basename($_Training2_Result, ".kmm"); $_Training2_Result != "" ? &_Training2_EECode_NotEqual : &_Training2_EECode_E2_Cancel; } _Training2_EECode_E2_Cancel{ $_Training2_Catch == "true" ? &_Training2_CatchRun :0; } _Training2_EECode_NotEqual{ $_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_E2{ \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."Result != '' ? &_EECode_NotEqual : 0;\n"; $_Training2_Text0 = $_Training2_Text0." } \n " ; $_Training2_Text0 = $_Training2_Text0." \n _EECode_NotEqual { \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"; $_Training2_Catch == "true" ? &_Training2_EECode_NotEqualC : 0; $_Training2_Text0 = $_Training2_Text0." } " alert("Your selection was ".$_Training2_Result."\n\n".$_Training2_Text0, "Name selected"); } _Training2_EECode_NotEqualC{ $_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." CAnswer == 'NO' ? &_Training2_EECode_E2; : alert('Cancel is confirmed'); \n" ; } 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); $_Training2_CAnswer == "NO" ? &_Training2_EECode_E2 : 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); $_Training2_CAnswer == "NO" ? &_Training2_BasenameCode2 : 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 ############################### [/code][/quote]
[Please Enable JavaScript]
K-Meleon forum is powered by
Phorum
.
Home/News
Screenshots
Download
Documentation
Resources
Get Involved
Forum
Bugs
Development