xfy リスト表示コンポーネントで Drag & Drop (その2)
- https://www.xfytec.com/community/modules/newbb/viewtopic.php?topic_id=245&forum=8
> xfy コミュニティ - Generated Link from XML file for Blog
この記事の中でこんなコードが示されていた。
<xvcd:action event="event:drop-target">
<inst:param name="event:event" />
<inst:if test="$event:event/event:drop-target/@type = 'drop'">
<inst:variable name="url" select="$event:event//lsp:url"/>
<inst:variable name="fragment" select="function:synchronous-document($url)"/>
<xvcd:insert ref="//d2l:dropped-xml" position="last-child" select="$fragment/*"/>
</inst:if>
</xvcd:action>
$event:event//lsp:url として、 Desktop や ファイルエクスプローラから File などを xfy の画面に drop したときの URL を取得できるようだ。
- https://www.xfytec.com/community/modules/mydownloads/singlefile.php?lid=184&lang=ja
> xfy コミュニティ - ImageEasy for Blog Editor
のデモ画像でも、xfy の外から image ファイルを deop して取り込んでいる様子が示されている。
down load したzip ファイルを展開して、blog-imageeasy.xvcd を眺めると、やはり
$event:event//lsp:url を利用していることがわかった。
そこで先の List での drag & drop に 外部からの drap 対応を追加してみた。
<list:list type="{xvcd:user-data('type')}">
の直後に以下のコードを追加した。
<xvcd:action event="event:drop-target">
<instruction:param name="event:event" />
<instruction:if test="$event:event/event:drop-target/@type = 'drop'">
<instruction:variable name = "url" select="function:url-decode($event:event//lsp:url)"/>
<instruction:choose>
<instruction:when test="function:ends-with($url, '/')">
<xvcd:insert ref="." position="last-child" caret-move="none">
<simple:folder name="{$url}" />
</xvcd:insert>
</instruction:when>
<instruction:otherwise>
<xvcd:insert ref="." position="last-child" caret-move="none">
<simple:file name="{$url}" />
</xvcd:insert>
</instruction:otherwise>
</instruction:choose>
</instruction:if>
</xvcd:action>
xfy 外部から File を drop したとき、その URL さえ取得できれば、その後はアプリケーションに即した様々な処理が可能だろう。
P.S.
windows や Mac でのターミナル画面でも、File/Folder をドロップするとファイルパスがコマンドライン行に追加される。
cd と打ってから、Folder を drop して、長い文字列をタイプすることなく directory 移動することができる。
最近のコメント