script to open help map for addon

script to open help map for addon

Postby jokro » Fri Aug 02, 2013 9:34 am

I need a script to open a Help map for an add-on, which is loaded to <userdirectory>scripts/help/Smarltocker_Help.mm.
Is there an easy way for this ?
Regards
Jodi
jokro
 
Posts: 486
Joined: Sun Jul 24, 2011 2:56 pm

Re: script to open help map for addon

Postby seb4stien » Sat Aug 03, 2013 10:29 am

Maybe you could try :
def file = yourfile
def uri = file.toURI()
loadUri(uri)
seb4stien
 
Posts: 32
Joined: Sat Jun 08, 2013 8:28 am

Re: script to open help map for addon

Postby dpolivaev » Sat Aug 03, 2013 10:32 pm

org.freeplane.features.mapio.mindmapmode.MMapIO.newDocumentationMap(URL)
User avatar
dpolivaev
Site Admin
 
Posts: 667
Joined: Sat Jul 23, 2011 1:21 pm

Re: script to open help map for addon

Postby jokro » Fri Sep 13, 2013 2:10 pm

Dimitry,
Your proposal works fine with litteral path names. I would like to switch automatically to the current language setting of freeplane. Say if the help file is smartlocker.mm and I have a translation in smartlocker_nl.mm that it loads the latter. From the source I understand that it should switch automatically ?

Here is my present code:

Code: Select all
import org.freeplane.features.map.mindmapmode.MMapController;
import org.freeplane.core.resources.ResourceController;
import org.freeplane.features.mode.Controller;
class Help {
   static void action(){
      String userDir= ResourceController.getResourceController().getFreeplaneUserDirectory()
      String path="file:///"+userDir+"\\"+"doc\\smartlocker.mm"
      URL url=path.toURL()
      Controller.getCurrentModeController().getMapController().newDocumentationMap(url)
   }
}


Regards
Jodi
jokro
 
Posts: 486
Joined: Sun Jul 24, 2011 2:56 pm

Re: script to open help map for addon

Postby jokro » Wed Sep 18, 2013 9:35 pm

Hi,
If you are interested, I developed the following solution assuming
1. the help files are in <USERDIR>/doc
2. myName.mm is the default help map
3. myName_lc.mm is the translation for languge code lc

Code: Select all
static void action(){
      openHelp("smartlocker")
   }
   
   static void openHelp(String helpFile){//in userdir/doc; name without .mm
      final ResourceController resourceController = ResourceController.getResourceController()
      final String languageCode = resourceController.getLanguageCode()
      String userDir= ResourceController.getResourceController().getFreeplaneUserDirectory()
      String path
      def p1=userDir+"\\"+"doc\\"+helpFile+"_"+languageCode+".mm"
      def p2=userDir+"\\"+"doc\\"+helpFile+".mm"
      if (new File(p1).isFile()) path="file:///"+p1
      else if(new File(p2).isFile()) path="file:///"+p2
      if (path!=""){
         URL url=path.toURL()
         Controller.getCurrentModeController().getMapController().newDocumentationMap(url)
      }
      else Message.warning("Help file missing: $helpFile")
   }


Regards
Jodi
jokro
 
Posts: 486
Joined: Sun Jul 24, 2011 2:56 pm

Re: script to open help map for addon

Postby jokro » Sat Sep 21, 2013 9:02 pm

To make the code not only work for Windows, my backslashes should be replaced by "File.separator":
Code: Select all
static void openHelp(String helpFile){//in userdir/doc; name without .mm
      final ResourceController resourceController = ResourceController.getResourceController()
      final String languageCode = resourceController.getLanguageCode()
      String userDir= ResourceController.getResourceController().getFreeplaneUserDirectory()
      String path
      def p1=userDir+File.separator+"doc"+File.separator+helpFile+"_"+languageCode+".mm"
      def p2=userDir+File.separator+"doc"+File.separator+helpFile+".mm"
      if (new File(p1).isFile()) path="file:///"+p1
      else if(new File(p2).isFile()) path="file:///"+p2
      if (path!=""){
         URL url=path.toURL()
         Controller.getCurrentModeController().getMapController().newDocumentationMap(url)
      }
      //else Message.warning("Help file missing: $helpFile")
                else println "Help file missing: $helpFile"
}
   }
jokro
 
Posts: 486
Joined: Sun Jul 24, 2011 2:56 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 1 guest

cron