Thanks, Hussein.
I ended up writing something similar, except that it takes you back to
the original map file. In the process, I found that your XXE commands
handle recursion quite nicely ;-) By the way, in your example, it looks
like there's a new macro variable, %C, in v3.2. I assume that's the path
to the current config directory?
<command name="createNewFile">
<macro>
<sequence>
<set variable="mapFile" expression="%d" plainString="true"/>
<set variable="mapPath" expression="%p" plainString="true"/>
<command name="pick" parameter="'Choose the type of DITA file
to create' true 'Concept' 'dita_concept_template.xml' 'Reference'
'dita_reference_template.xml' 'Task' 'dita_task_template.xml' 'Wrapper
(multi-topic) ' 'ditabase_template.xml'"/>
<set variable="templateFile" expression="c:%Sprogram
files%Sxmlmind_xml_editor%Saddon%Sconfig%Sdita%Stemplate%S%_"
plainString="true"/>
<get expression="$templateFile"/>
<command name="XXE.openCopy" parameter="%_"/>
<get expression="$mapPath"/>
<command name="selectFile" parameter="saveFile
%_/Untitled.xml"/>
<set variable="savedFile" expression="%_" plainString="true"/>
<get expression="$savedFile"/>
<set variable="copyTemplateParams"
expression="concat('"',$templateFile,'"
"',$savedFile,'"')"/>
<get expression="$copyTemplateParams"/>
<command name="copyTemplate" parameter="%_"/>
<command name="XXE.close"/>
<get expression="$savedFile"/>
<command name="XXE.open" parameter="%_"/>
<get expression="$savedFile"/>
<command name="fileNameOnly" parameter="%_"/>
<set variable="hrefAttribute" expression="%_"
plainString="true"/>
<get expression="$mapFile"/>
<command name="XXE.edit" parameter="%_"/>
<get expression="$hrefAttribute"/>
<command name="putAttribute" parameter="[implicitElement]
'href' '%_'"/>
</sequence>
</macro>
</command>
<command name="copyTemplate">
<process>
<copy files='%0' to='%1'/>
</process>
</command>
<command name="fileNameOnly">
<macro>
<sequence>
<set variable="theParam" expression="%*" plainString="true"/>
<set variable="sep" expression="%S" plainString="true"/>
<set variable="substringAfter"
expression="substring-after($theParam,$sep)"/>
<choice>
<sequence>
<test expression="not($substringAfter)"/>
<get expression="$theParam"/>
</sequence>
<sequence>
<get expression="$substringAfter"/>
<command name="fileNameOnly" parameter="%_"/>
</sequence>
</choice>
</sequence>
</macro>
</command>
-----Original Message-----
From: Hussein Shafie [mailto:[email protected]]
Sent: Wednesday, March 29, 2006 2:29 AM
To: Mark Fletcher
Cc: xmleditor-support at xmlmind.com
Subject: Re: [XXE] Problem with XXE.saveAs
Mark Fletcher wrote:
> Hmm. Well, here's what I'm trying to do. Maybe you can suggest another
> way.
>
> I'm working on a CSS for ditamap. Topicref hrefs are displayed
onscreen.
> If an href is unassigned, I display it as "[unassigned]" and want to
> put a command button behind the text that will allow the user to
> create a new concept/task/reference dita file and update the href
> attribute automatically. I haven't seen a programmatic way to show the
> user the File,New dialog. Is there one?
Here's a command which does what you want (I think):
---
<binding>
<keyPressed code="F3" />
<command name="initTopicRef" />
</binding>
<command name="initTopicRef">
<macro>
<sequence>
<pass><command name="putAttribute" parameter="href" /></pass>
<command name="pick"
parameter="'Please choose the type of topic you want to create:'
true
Topic template%Stopic.dita
Concept template%Sconcept.dita
Reference template%Sreference.dita
Task template%Stask.dita " />
<set variable="templateFilename" expression="%_"
plainString="true" />
<command name="selectConvertedFile"
parameter="saveFileWithExtension=dita" />
<set variable="newFileName" expression="%_"
plainString="true" />
<get expression="concat('"',
$templateFilename,
'" "',
$newFileName, '"')" />
<command name="copyTopicTemplate" parameter="%_" />
<get context="$selectedElement"
expression="relativize-uri(uri-or-file-name($newFileName))"
/>
<command name="putAttribute" parameter="href '%_'" />
<get expression="$newFileName" />
<command name="XXE.open" parameter="%_" />
</sequence>
</macro>
</command>
<command name="copyTopicTemplate">
<process showProgress="false">
<copy files="%C%S%0" to="%1" />
</process>
</command>
---
Just one problem with XXE V3.1. uri-or-file-name() is a new XPath
extension function which has been added in V3.2.
Replace:
expression="relativize-uri(uri-or-file-name($newFileName))"
by just:
expression="$newFileName"
if you want to play with this macro.
> Also, is there a way to change the "context" from the map file to the
> new Untitled file?
The above macro does this because it *ends* with an XXE.open.
> What if I write a command that only exists in a config file for dita
> topics and not dita maps, and call that command when I want to save
> the file?
Commands are global to XXE: e.g. a command defined the DocBook
configuration file could invoke a command defined in the XHTML
configuration file.