On Fri, Feb 15, 2019 at 12:04 AM Mohammad Rahmani <
mohammad.rahm...@gmail.com> wrote:

> Stefano,
>  Could you please bruch up the procedure based on the received comments. I
> would like to add it to TW-Scripts.
>
>
Well, there isn't much to write up. As always the solution is simple once
it's been found...
But here we go:

1. How to create the panels that make up the various tabs of the plugin
page. It takes three steps:
 a - In the plugin.info file of the plugin you are writing, add a line with
"list" followed by a list of your panels in double quotes.
      In my case I wanted 6 panels: readme usage syntax example license and
config. So I added this line:
      "list": "readme usage syntax example license config"
b. Create the files corresponding to the panels in the "files" subdirectory
of your plugin, as plain text, or in wikitext, or HTML.
    I wanted them in a separate dir to keep everything uncluttered, and i
put them in a new subdir files/doc
    So I created 6 new files: files/doc/readme.txt, file/doc/usage.txt,
etc. and put some filler text in each just o be sure I could test if they
showed up in TW
c. Finally, in the tiddlywiki.files file in your files subfolder, add a
block for each one of the new file you have created, making sure the last
part of the
   "title" field is identical to what you wrote in the "list" line of your
plugin info, while the first part is the identifier of your plugin:
$:/plugins/yourName/YourPluginName/. In my case,
    I am working on a plugin called "sgfeditor", and the name I am using is
"cleinias", so the name prefix is always "$:/plugins/cleinias/sgfeditor" .
   For example, to add the content of the files/doc/readme.txt file as a
"readme" panel, you would add the following block to the tiddlywiki.files
file:

         {
            "file": "doc/readme.txt",
            "fields": {
             "type": "text/plain",
                "title": "$:/plugins/cleinias/sgfeditor/readme"
                        }
                       },

   Notice two important things: (1) the path in the "file" line is relative
to the files sub directory, NOT to the plugin directory.
   (2) The last part  of the can title (i.e. "readme") can actually be
anything you want, AS LONG AS it corresponds to one of the
    item in th e"list" line of plugin.info file. For instance, you could
have your readme info in README.txt (following usual
    conventions), and then "readme" in all lowercase and no ext in the
"title" field.

2. How to create a settings for my plugin that would either be added to the
control panel or be accessible from the plugin page
   To have the settings accessible from the config panel, you need to
create a config file and then tag it with $:/tags/ControlPanel as PMario
said. If you want it as
  a tab (panel) in the plugins page add it to the "list" line in plugin.info
.
   In either case, the basic procedure is the same as above: create a file
in the format of your choice (see point 3 below) in the "files" subdir of
your plugin, then add a block describing
   it in the tiddlywiki.files in the files subdirectory. If you go for the
config panel, you also add a line with "tags": "$:/tags/ControlPanel" . I
went the second route, and decided to put my settings  in  a "config" panel
of the plugin, and to use the json format. So I created config.json, added
"config" to the "list" line in plugin.info and added this block to
tiddlywiki.files:
            {
            "file": "config.json",
            "fields": {
                "type": "application/json",
                "title": "$:/plugins/cleinias/sgfeditor/config"
                        }
              },
   Notice that I changed the type to the correct json MIME type.

3. How to access said settings from the plugin code:
   I haven't tried to access the settings from the config panel, so I
cannot say anything about it. I only had to add two lines to read the
config tiddler from  my plugin code (I  copied them from the railroad
plugin):

// getTiddlerData reads a Json file into a javascript object:
var config = $tw.wiki.getTiddlerData(
"$:/plugins/cleinias/sgfeditor/config")

Then for every setting, I provide three options: the value in the config
panel, the value possibly present in a corresponding field of the tiddler
the plugin widget is working on, or a default value I set in code (this is
also copied from the railroad plugin). So I have an object that reads all
the config parameters:

        var options = {
            size         :  this.getAttribute("size", config.size || 19),
            panels     :  this.getAttribute("panels", config.panels ||
['control', 'names', 'comment', 'tool', 'tree', 'file'])
     ...... and do on


   That's all.

Cheers,

S.




> --
__________________________________________________
Stefano Franchi

stefano.fran...@gmail.com <stef...@tamu.edu>
http://stefano.cleinias.org

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywikidev@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/CAJODLwZWQ_HO22UuVBbhLnuvdLsp2qGX6Buy6%3DdqzyAAwRFL1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to