0

Given a directory path and some .m files in it, I want load these packages files mannually outside notebooks, so I created Palette using code:

CreatePalette[
  Framed@Column[{(FileNameSetter[Dynamic[path], "Directory"]),
     Button[
      "LoadPackage", (SetOptions[Get, CharacterEncoding -> "UTF8"];
                      If[ Not@DirectoryQ@ToString@path,
                          Return@$Failed
                      ];
                      Get /@ FileNames["*.m", {path}];
                     ), 
      Appearance -> "Palette"]
     }], WindowTitle -> "Test"];

enter image description here

When I want load packages, I click [Browse] to choose the directory firstly, then click [LoadPackage], but it does not work, what's the problem?

Jerry
  • 2,459
  • 9
  • 15
  • Comments are not for extended discussion; this conversation has been moved to chat. – Kuba Dec 08 '18 at 14:25
  • Let me know if you disagree with closing. But from your answer and a conversation in chat I think that answer is what you need. It also shows why it is crucial to explain the problem and not say generic "it does not work". It can save people's time in future. – Kuba Dec 09 '18 at 08:26

1 Answers1

0

By using the Palette LoadPackage, functions in package files will be loaded immediately but not listed in intellisense context at once, unless one of the functions is to be used or queried i.e. Names["*"]. I have tested to fix it but not succeeded.

enter image description here

SetDirectory@$TemporaryDirectory; 
CreateDirectory["files"]; 
SetDirectory@"files"; 

Export["test.m", "BeginPackage[\"MyPackage`MyPrintTool`\"] 
myPrint::usage := \"myPrint does something\" 

Begin[\"`Private`\"] (* Begin Private Context *) 

myPrint[DateString[CurrentDate[]]<>$InputFileName] 

myPrint[message_]:=Print[message] 


End[] 

EndPackage[]", "Text"]; 


CreatePalette[ 
Framed@Column[{(FileNameSetter[Dynamic[path], "Directory"]), 
Button["LoadPackage", (Get /@ FileNames["*.m", {path}];), 
Appearance -> "Palette"]}], WindowTitle -> "Test"];
Jerry
  • 2,459
  • 9
  • 15
  • What do you mean? Is $ContextPath not up to date? – Kuba Dec 09 '18 at 07:42
  • Generally, when package files loaded, If you stike keyboards to use function, the notebook will show you a list to choose quickly(intellisense). In the upper case would not unless the new inputed funtion(s) evaluated. – Jerry Dec 09 '18 at 08:14
  • Intellisense is VS related term, I for example was not aware of what are you talking about. Please target your wording at MMA users and assume nothing else or provide clarification/links etc. – Kuba Dec 09 '18 at 08:24
  • I upload a picture upper, I think it's the Intellisense in MMA. – Jerry Dec 09 '18 at 08:36
  • My point is that Intellisense does not mean anything in MMA. No one calls autocompletion Intellisense here. If you google it it points at VS feature. – Kuba Dec 09 '18 at 08:45
  • Ok, the original question is that, click [LoadPackage], the funtions are not listed in Autocompletion List, i.e. myPrint in upper codes. – Jerry Dec 09 '18 at 08:55