Adding one more field into the dictionary plugin by Jed Carty

130 views
Skip to first unread message

Shash

unread,
May 28, 2015, 5:42:55 AM5/28/15
to tiddl...@googlegroups.com
Hi,

I am trying to add one more field for the current dictionary plugin by Jed Carty available at http://inmysocks.tiddlyspot.com


\define thisListMacro()
<$view field=title/> - {{$:/data/Dictionary##$(thisIndex)$}}<br>
\end


\define thisEditListMacro()
<$view field=title/> - {{$:/data/Dictionary##$(thisIndex)$}} <$button>Remove<$action-deletefield $tiddler='$:/data/Dictionary' $field=$(thisIndex)$ $value=''/></$button><br>
\end


\define thisRegEx()
$
(thisSearch)$(?i)
\end


\define thisSearchMacro()
<ul>
<$list filter="[[$:/data/Dictionary]indexes[]regexp:title[(?i)$(thisSearch)$]]">
<li><<currentTiddler>> - <$transclude tiddler="$:/data/Dictionary" index=<<currentTiddler>>/></li>
</$list>
</
ul>
\end


\define thisEditMacro()
<ul>
<$list filter="[[$:/data/Dictionary]indexes[]regexp:title[(?i)$(thisSearch)$]]">
<$set name=thisItem value=<<currentTiddler>>>
<li><<thisDeleteButton>> <<currentTiddler>> - <$transclude tiddler="$:/data/Dictionary" index=<<currentTiddler>>/></li>


</$set>
</
$list>
</ul>
\end


\define thisDeleteButton()
<$button set='$:/
data/Dictionary##$(thisItem)$'>{{$:/core/images/delete-button}}</$button>
\end


Term: <$edit-text class='tc-edit-texteditor' tiddler='$:/temp/dictionary' field='name'/><br>
Meaning: <$edit-text class='tc-edit-texteditor' tiddler='$:/temp/dictionary' field='meaning'/><br>
<$reveal type='match' state='$:/temp/dictionary!!name' text=''>
<$button>Add Term</$button>
</
$reveal>
<$reveal type='nomatch' state='$:/temp/dictionary!!name' text=''>
<$button>Add Term
<$action-setfield $tiddler='$:/data/Dictionary' $index={{$:/temp/dictionary!!name}} $value={{$:/temp/dictionary!!meaning}}/>
<$action-setfield $tiddler='$:/temp/dictionary' name='' meaning=''/>
</$button>
</
$reveal>
<$reveal type='nomatch' state='$:/state/dictionary/editreveal' text='edit'>
<$button set='$:/state/dictionary/editreveal' setTo='edit'>Edit Dictionary</$button>
</
$reveal>
<$reveal type='match' state='$:/state/dictionary/editreveal' text='edit'>
<$button set='$:/state/dictionary/editreveal' setTo='noedit'>Done Editing</$button>
</
$reveal>


Search: <$edit-text tiddler='$:/temp/dictionary' field='search'/><br>
<$reveal type='nomatch' state='$:/state/dictionary/editreveal' text='edit'>
</$reveal>
<$reveal type='match' state='$:/
state/dictionary/editreveal' text='edit'>
Click on the trashcan icon to remove an item
</$reveal>
<$set name='
thisSearch' value={{$:/temp/dictionary!!search}}>
<$reveal type='
nomatch' state='$:/state/dictionary/editreveal' text='edit'>
<<thisSearchMacro>>
</$reveal>
<$reveal type='
match' state='$:/state/dictionary/editreveal' text='edit'>
<<thisEditMacro>>
</$reveal>
</$set>


I tried a lot but somehow unable to get it fixed. Is there something more I need to add for this code above to get it working.

Thanks!
Shash

Jed Carty

unread,
May 28, 2015, 10:16:48 AM5/28/15
to tiddl...@googlegroups.com
This one is very simple and uses a single data tiddler to save the entries in key-value pairs so adding a new field to an entry isn't a trivial task. There are a few ways to do it but the most straight forward way would be to create another data tiddler for each field you add. If you want to keep it all in two tiddlers you can, but that gets a bit more complex.

Here is the simplest way I to add a new field I can come up with at the moment. I am working on my tablet so I didn't do much testing. Go through and change everywhere it says 'newfield' to whatever you want to call the new field and it should work. If you want to add more fields than you can just do the same edits I did again for each new field.

\define thisListMacro()
<$view field=title/> - {{$:/data/Dictionary##$(thisIndex)$}} - {{$:/data/Dictionary/newfield##$(thisIndex)$}}<br>
\end

\define thisEditListMacro()
<$view field=title/> - {{$:/data/Dictionary##$(thisIndex)$}} - {{$:/data/Dictionary/newfield##$(thisIndex)$}} <$button>Remove<$action-deletefield $tiddler='$:/data/Dictionary' $field=$(thisIndex)$ $value=''/></$button><br>
\end

\define thisRegEx()
$(thisSearch)$(?i)
\end

\define thisSearchMacro()
<ul>
<$list filter="[[$:/data/Dictionary]indexes[]regexp:title[(?i)$(thisSearch)$]]">
<li><<currentTiddler>> - <$transclude tiddler="$:/data/Dictionary" index=<<currentTiddler>>/> - <$transclude tiddler="$:/data/Dictionary/newfield" index=<<currentTiddler>>/></li>
</$list>
</ul>
\end

\define thisEditMacro()
<ul>
<$list filter="[[$:/data/Dictionary]indexes[]regexp:title[(?i)$(thisSearch)$]]">
<$set name=thisItem value=<<currentTiddler>>>
<li><<thisDeleteButton>> <<currentTiddler>> - <$transclude tiddler="$:/data/Dictionary" index=<<currentTiddler>>/> - <$transclude tiddler="$:/data/Dictionary/newfield" index=<<currentTiddler>>/></li>

</$set>
</$list>
</ul>
\end

\define thisDeleteButton()
<$button set='$:/data/Dictionary##$(thisItem)$'>{{$:/core/images/delete-button}}</$button>
\end

Term: <$edit-text class='tc-edit-texteditor' tiddler='$:/temp/dictionary' field='name'/><br>
Meaning: <$edit-text class='tc-edit-texteditor' tiddler='$:/temp/dictionary' field='meaning'/><br>
Newfield: <$edit-text class='tc-edit-texteditor' tiddler='$:/temp/dictionary' field='newfield'/><br>
<$reveal type='match' state='$:/temp/dictionary!!name' text=''>
<$button>Add Term</$button>
</$reveal>
<$reveal type='nomatch' state='$:/temp/dictionary!!name' text=''>
<$button>Add Term
<$action-setfield $tiddler='$:/data/Dictionary' $index={{$:/temp/dictionary!!name}} $value={{$:/temp/dictionary!!meaning}}/>
<$action-setfield $tiddler='$:/data/Dictionary/newfield' $index={{$:/temp/dictionary!!name}} $value={{$:/temp/dictionary!!newfield}}/>
<$action-setfield $tiddler='$:/temp/dictionary' name='' meaning='' newfield=''/>
</$button>
</$reveal>
<$reveal type='nomatch' state='$:/state/dictionary/editreveal' text='edit'>
<$button set='$:/state/dictionary/editreveal' setTo='edit'>Edit Dictionary</$button>
</$reveal>
<$reveal type='match' state='$:/state/dictionary/editreveal' text='edit'>
<$button set='$:/state/dictionary/editreveal' setTo='noedit'>Done Editing</$button>
</$reveal>

Search: <$edit-text tiddler='$:/temp/dictionary' field='search'/><br>
<$reveal type='nomatch' state='$:/state/dictionary/editreveal' text='edit'>
Type in the search box to find specific items on the list
</$reveal>
<$reveal type='match' state='$:/state/dictionary/editreveal' text='edit'>
Click on the trashcan icon to remove an item
</$reveal>
<$set name='thisSearch' value={{$:/temp/dictionary!!search}}>
<$reveal type='nomatch' state='$:/state/dictionary/editreveal' text='edit'>
<<thisSearchMacro>>
</$reveal>
<$reveal type='match' state='$:/state/dictionary/editreveal' text='edit'>
<<thisEditMacro>>
</$reveal>
</$set>

Let me know how it works for you. I am a bit surprised anyone is using my stuff.

Shash

unread,
May 28, 2015, 10:58:29 AM5/28/15
to tiddl...@googlegroups.com
Thanks a lot. This is exactly what I was looking for. Also one more question if you don't mind. Is there any way to have a table instead of mundane way of having a " - " in between the word and the meaning?

Regards
Shash

Richard Smith

unread,
May 28, 2015, 9:16:20 PM5/28/15
to tiddl...@googlegroups.com
Hi Jed,

I want to build an English-Swahili dictionary that can test me on vocabulary, flashcard/lietner style - do you think your dictionary plugin is a good way to go? I was going to use a tiddler for each pair-entry but it might be easier to put them all into a data tiddler. Is it easy to add (and remove) entries from the table through a form?

Thanks,
Richard

Jed Carty

unread,
May 29, 2015, 10:01:21 PM5/29/15
to tiddl...@googlegroups.com
Shash,

Yes, you can change how the items are displayed. Unfortunately the list widget doesn't play well with the normal tiddlywiki table syntax so you need to use html tables. Change everywhere that has <ul> with <table> and </ul> with </table>, then change everywhere there is <li> with <tr> and </li> with </tr>. Then put <td> and </td> around what you want to be in each cell. Hopefully the two macros below will be a good enough example for how to make things work. My desktop can't get online at the moment and the mobile version of google groups doesn't let you set pieces of text as code, so I hope this displays correctly.

Change the first two macros to this:

\define thisListMacro()
<tr><td><$view field=title/></td><td>{{$:/data/Dictionary##$(thisIndex)$}}</td><td>{{$:/data/Dictionary/newfield##$(thisIndex)$}}</td></tr>
\end

\define thisEditListMacro()
<tr><td><$view field=title/></td><td>{{$:/data/Dictionary##$(thisIndex)$}}</td><td>{{$:/data/Dictionary/newfield##$(thisIndex)$}}</td><td> <$button>Remove<$action-deletefield $tiddler='$:/data/Dictionary' $field=$(thisIndex)$ $value=''/></$button></td></tr>
\end

Richard,

It is easy to add or remove entries, but it is very simple. I think that you would need more than just this plugin for what you want. I am learning French and as my attempts to learn Spanish and Japanese have taught me, I have a hard time learning vocabulary. If you have ideas for what you think would work well let me know and since it is something I will probably use I will put some work into making it.
Reply all
Reply to author
Forward
0 new messages