On 11/06/2010 03:16 PM, Liviu Andronic wrote:
On Sat, Nov 6, 2010 at 7:44 PM, Steve Litt<sl...@troubleshooters.com>  wrote:
Just make sure it's a choice, and hopefully not the default. I've found
single-instance to be a pain in the posterior in most situations, especially
if you use lots of desktops.

Note that even a single instance LyX would support multiple windows, via File>New Window.

Personally I'd much prefer if LyX could be configured for
single-instance use; this is where tabs are useful. At the moment
opening additional files can be a pain since you cannot simply use
your file manager for that.

If you're on Linux (or perhaps other *nices?), this is fairly easy to do. I'm attaching a simple script that looks for a running instance of LyX and tries to open the file there via the lyxpipe. If you set up for your file manager to call this script for .lyx files, then you have the best of both worlds. You can always launch a separate instance in the usual way.

Obviously, you will need to adjust some of the settings for your own use (and you may want to remove the kdialog bit). Better would be to make it more general purpose. E.g., we'd need to parse the command line for LyX's own options; use them if we find them; find the location of the lyxpipe by grepping $USERDIR/preferences; etc. Then we could even distribute it with LyX.

Richard

#!/bin/bash

LYX="/usr/local/bin/lyx";
if [ ! -f "$LYX" ]; then LYX="/usr/bin/lyx"; fi
SYSDIR="${LYX%/bin*}/share/lyx";
USERDIR="$HOME/.lyx";
LYXFULL="$LYX -sysdir $SYSDIR -userdir $USERDIR -geometry 1024x1024+100+100";
LYXPIPE="$HOME/.lyxpipe"
LYXPIPEIN="$LYXPIPE.in";
LYXPIPEOUT="$LYXPIPE.out";
CMD="file-open";

PROG=$(basename $0);
function printUsage {
cat <<EOF
#######################################################################
USAGE: $PROG [-c] [LYX-COMMANDS]
$PROG is a simple script to run LyX. Its main purpose is that it will 
open a requested file in a running instance of LyX, if it can find one.

Argument:
LYX-COMMANDS: Anything you could pass to LyX.

Options:
-c: Re-configure LyX before launching.
-h: Print this message
EOF
}


CONFIG="";
#Option processing
while getopts ":c" opt; do
        case $opt in
                c )   CONFIG="true";;
                h )   printUsage; exit 0;;
                \? )  printUsage; exit 1;;
        esac
done

shift $(($OPTIND - 1));

if [ ! -x "$LYX" ]; then
        LYX=$(which lyx);
        if [ ! -x $LYX ]; then
                echo "Can't find LyX!";
                exit 1;
        fi
fi

if [ -n "$CONFIG" ]; then
        pushd $USERDIR >/dev/null 2>&1; 
        if [ "$?" != "0" ]; then
                echo "Couldn't change to user directory $USERDIR!!";
                exit 1;
        fi
        $SYSDIR/configure.py
        popd >/dev/null 2>&1;
fi

if [ -e $LYXPIPEIN ]; then
        if [ -n "$1" ]; then 
                echo "LYXCMD:lyx-script:$CMD:$1" > $LYXPIPEIN;
                exit 0;
        fi
        kdialog --title "LyX Running" --warningcontinuecancel "LyX appears to 
be running. Click Continue to delete the lyxpipe and force a run.";
        if [ $? != 0 ]; then exit 0; fi
        rm -f $LYXPIPE
fi

$LYXFULL $1;    

Reply via email to