On Sun, Nov 2, 2008 at 7:03 PM, Jesse Aldridge <[EMAIL PROTECTED]> wrote:

> Is it possible to do a "save as" with a parameter for the filename
> from a script button?

The answer to all "is it possible" questions is "yes" :-)

There are at least three ways.  All the following have been tested.

I'll present my thinking in detail:

1. Cut and paste the relevant code from c.saveAs to your script.

    w = g.app.gui.get_focus(c)
    c.mFileName = g.ensure_extension(fileName, ".leo")
    c.frame.title = c.mFileName
    c.frame.setTitle(g.computeWindowTitle(c.mFileName))
    c.frame.openDirectory = g.os_path_dirname(c.mFileName) # Bug fix in 4.4b2.
    # Calls c.setChanged(False) if no error.
    c.fileCommands.saveAs(c.mFileName)
    c.updateRecentFiles(c.mFileName)
    g.chdir(c.mFileName)
    c.redraw()
    # c.redraw_after_icons_changed(all=True)
    c.widgetWantsFocusNow(w)

2. I dimly recall a discussion about adding arguments to minibuffer
commands.  Hmm, now I see a clue.  It is c.k.givenArgs in the
saveAsCode.

    fileName = ''.join(c.k.givenArgs) or g.app.gui.runSaveFileDialog(
        initialfile = c.mFileName,
        title="Save As",
        filetypes=[("Leo files", "*.leo")],
        defaultextension=".leo")

And here is the comment in the leoKeys class:

    self.givenArgs = []
    # New in Leo 4.4.8: arguments specified after
    # the command name in k.simulateCommand.

A little experimentation shows that this works:

    fileName = r'c:\prog\test\test2.leo'
    c.k.simulateCommand('save-file-as %s' % fileName)

3. Another way would be to temporarily override
g.app.gui.runSaveFileDialog.  The safe way to do this is:

    fileName = r'c:\prog\test\test3.leo'

    def myRun(*args,**keys):
        return fileName

    old = g.app.gui.runSaveFileDialog
    try:
        g.app.gui.runSaveFileDialog = myRun
        c.saveAs()
    finally:
        g.app.gui.runSaveFileDialog = old

Edward

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to