Help with saving a widget's tiddler content from external library code

39 views
Skip to first unread message

stefano franchi

unread,
Feb 22, 2019, 12:53:21 PM2/22/19
to TiddlyWikiDev
I am having some trouble understanding how to update the text and other fields of a tiddler my  widget editor works on. 

I am at the point where the editor is holding
(1) editor.widget, a ref to the widget it was called from and
(2) fieldUpdates,  an object with field/value pairs  for all the tiddler's fields I want to update. My problem is which function to use to get the task done.

I tried/looked up the following approaches in my update function (located in a loop in the external library that builds the editor object-)

a. editor.widget.parseTreeNode[field]=fieldsUpdates[field]
    Result: "Compiles" but no results, tiddler text and fields do not change.

b. editor.widget.wiki.setText(title, field, null, fieldUpdates[field])
    Didn't get to try it because it calls for the tiddler's title, And I haven't find a method to get it from the widget

c. editor.widget.wiki.setData(fieldUpdates)
   Didn't try it it either, because the code comments say it would change the tiddler's type to app/json, which is definitely not desired.

What am I missing?

Cheers,

Stefano


--
__________________________________________________
Stefano Franchi

stefano...@gmail.com
http://stefano.cleinias.org

Simon Huber

unread,
Feb 22, 2019, 3:20:15 PM2/22/19
to TiddlyWikiDev
I am having some trouble understanding how to update the text and other fields of a tiddler my  widget editor works on. 

I am at the point where the editor is holding
(1) editor.widget, a ref to the widget it was called from and
(2) fieldUpdates,  an object with field/value pairs  for all the tiddler's fields I want to update. My problem is which function to use to get the task done.

If you're editing a tiddler with your editor and you want its title, the widget calling your editor must have it (...) ?
 
what does console.log(editor.widget) say? is there no editTitle?

is your editor called the standard tw way using factory.js?

stefano franchi

unread,
Feb 22, 2019, 4:34:59 PM2/22/19
to TiddlyWikiDev
On Fri, Feb 22, 2019 at 2:20 PM Simon Huber <hypnotize...@gmail.com> wrote:
I am having some trouble understanding how to update the text and other fields of a tiddler my  widget editor works on. 

I am at the point where the editor is holding
(1) editor.widget, a ref to the widget it was called from and
(2) fieldUpdates,  an object with field/value pairs  for all the tiddler's fields I want to update. My problem is which function to use to get the task done.

If you're editing a tiddler with your editor and you want its title, the widget calling your editor must have it (...) ?
 
what does console.log(editor.widget) say? is there no editTitle?

is your editor called the standard tw way using factory.js?

No it isn't. Sorry for using a confusing terminology. Here is my scenario:

I have a widget plugin that creates a new Div element and then passes it  to  an external library. The latter builds a complete specialized editor inside the Div. I also give the library a ref to the widget that calls it. To be clearer, I have:

1. A tiddler with some specialized text format. Call it SF-Tiddler of type text/SF-type
2. A widget that reads the content of tiddlers of type text/SF-type and passes it to a specialized editor mini app
3. A specialized editor mini app, Call it SF-EditorApp, which starts out with a copy of the text content of (1) and holds on to a ref to the calling widget (2)
4. Editing operations within SF-EditorApp that need the internal copy of the text to be written back to the text of (1) as soon as they are carried out.

My problem is how to to reach (1) from a ref to (2).  SF-EditorApp has a property "widget". IO have been looking at all the methods of Widget, as well as staring at the object in the debugger, and I cannot find a ref to the tiddler the widget is open on. I was expecting either something like:

SF-EditorApp.widget.getTiddler()

or

SF-EditorApp.widget.tiddler

Instead, after many trips through  the debugger, all I could find was:

SF-EditorApp.widget.parentWidget.transcludeTitle

which indeed points to the title of my tiddler (1), but has me even more confused (to get from widget to tiddler I need to go up a level and descend to a transclusion?)

What I am looking for is the reference chain that leads from (2) to (1) or to (1)'s title.
And the fact I cannot find it after spending two hours looking at the code can only mean I ma still fundamentally confused about TW's data model.


Simon Huber

unread,
Feb 22, 2019, 4:47:47 PM2/22/19
to TiddlyWikiDev

On Fri, Feb 22, 2019 at 2:20 PM Simon Huber <hypnotize...@gmail.com> wrote:
I am having some trouble understanding how to update the text and other fields of a tiddler my  widget editor works on. 

I am at the point where the editor is holding
(1) editor.widget, a ref to the widget it was called from and
(2) fieldUpdates,  an object with field/value pairs  for all the tiddler's fields I want to update. My problem is which function to use to get the task done.

If you're editing a tiddler with your editor and you want its title, the widget calling your editor must have it (...) ?
 
what does console.log(editor.widget) say? is there no editTitle?

is your editor called the standard tw way using factory.js?

No it isn't. Sorry for using a confusing terminology. Here is my scenario:

I have a widget plugin that creates a new Div element and then passes it  to  an external library. The latter builds a complete specialized editor inside the Div. I also give the library a ref to the widget that calls it. To be clearer, I have:

1. A tiddler with some specialized text format. Call it SF-Tiddler of type text/SF-type
2. A widget that reads the content of tiddlers of type text/SF-type and passes it to a specialized editor mini app

so the widget reads the content of tiddlers, so it must know the tiddler title

somewhere there is the hidden egg

inside that widget

Simon Huber

unread,
Feb 22, 2019, 5:05:24 PM2/22/19
to TiddlyWikiDev
The easiest way of doing all this would be using the way the codemirror engine does it (have a look at tiddlywiki.com/prerelease and look at $:/plugins/tiddlywiki/codemirror/edit-codemirror.js)

* clone the edit-codemirror.js tiddler, make it export edit-sftype (for example)
* it will be used when you have a editor type mapping ($:/config/EditorTypeMappings/application/sftype) that contains sftype (in its text field ... if you export edit-sftype ... if you export edit-myengine, put myengine inside) ... that will automatically call the edit-sftype widget (or the edit-myengine widget), when editing a tiddler with type application/sftype
* then the basic handling is done by factory.js
* and you create your engine javascript tiddler with the title you defined above (your clone of edit-codemirror.js)
* for the content of your engine you can use $:/core/modules/editor/engines/simple.js as the easiest template to build on top , and you can have a look at the codemirror engine how it incorporates the codemirror library (probably too complicated for your case)
Reply all
Reply to author
Forward
0 new messages