Re: [twdev] Re: How to build a settings panel for a plugin

2019-02-14 Thread Mohammad Rahmani
Thank you!
Added to TW-Scripts

On Friday, February 15, 2019 at 10:32:28 AM UTC+3:30, stefano franchi wrote:
>
>
>
> On Fri, Feb 15, 2019 at 12:04 AM Mohammad Rahmani  > 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', 

Re: [twdev] Re: How to build a settings panel for a plugin

2019-02-14 Thread stefano franchi
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 
http://stefano.cleinias.org

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this 

Re: [twdev] Re: How to build a settings panel for a plugin

2019-02-14 Thread Mohammad Rahmani
Stefano,
 Could you please bruch up the procedure based on the received comments. I 
would like to add it to TW-Scripts.

Cheers
Mohammad

On Friday, February 15, 2019 at 1:42:32 AM UTC+3:30, stefano franchi wrote:
>
>
>
> On Thu, Feb 14, 2019 at 2:49 PM Matthew Lauber  > wrote:
>
>> That should be correct.  Keep in mind, in the list field, the file will 
>> be named "readme" but the shadow tiddler needs to be named 
>> "$:/plugins/yourName/yourPlugin/readme"
>>
>>
> My bad. I was using an overly complicated naming scheme and had made a 
> mistake. Thanks for pointing out my understanding was correct and directing 
> me to the real problem.
>
> Cheers,
>
> S.
>
>  
> -- 
> __
> Stefano Franchi
>
> stefano...@gmail.com 
> 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/b153edaf-6b9c-4242-893c-25f9520382aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [twdev] Re: How to build a settings panel for a plugin

2019-02-14 Thread stefano franchi
On Thu, Feb 14, 2019 at 2:49 PM Matthew Lauber  wrote:

> That should be correct.  Keep in mind, in the list field, the file will be
> named "readme" but the shadow tiddler needs to be named
> "$:/plugins/yourName/yourPlugin/readme"
>
>
My bad. I was using an overly complicated naming scheme and had made a
mistake. Thanks for pointing out my understanding was correct and directing
me to the real problem.

Cheers,

S.


-- 
__
Stefano Franchi

stefano.fran...@gmail.com 
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/CAJODLwYD_1WAbwmPYkjcq7F%3DR340wNjWG0RWfpzUtzckcTWpnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.