The external inset uses the converters. Graphical display within LyX.

Be warned --- temporary file format.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7101 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-06-04 09:16:29 +00:00
parent e412a2a53e
commit 6a50ae699b
24 changed files with 1034 additions and 492 deletions

View File

@ -1,3 +1,7 @@
2003-06-03 Angus Leeming <leeming@lyx.org>
* external_templates: modify the templates to use the converter" mechanism.
2003-06-02 John Levon <levon@movementarian.org>
* lyx2lyx/lyxconvert_221.py: remove insetparents

View File

@ -12,29 +12,32 @@ Template RasterImage
When you export to Ascii, you can provide a
number describing how many columns the picture
should expand to.
This template uses Gimp for editing, and
ImageMagick to do conversions. It requires
Python for exporting to Ascii and DocBook,
and gifscii for exporting to Ascii.
This template uses Gimp for editing.
HelpTextEnd
InputFormat "*"
FileFilter "*.(gif|png|jpg|bmp|pbm|ppm|tga|tif|xpm|xbm)"
ViewCommand "display $$Basename.eps"
EditCommand "gimp $$FName"
AutomaticProduction true
Format LaTeX
Product "\\includegraphics{$$Basename.eps}"
UpdateCommand "convert $$Parameters $$FName $$Basename.eps"
Product "\\includegraphics{$$Basename}"
UpdateFormat eps
UpdateResult "$$Basename.eps"
Requirement "graphicx"
FormatEnd
Format PDFLaTeX
Product "\\includegraphics{$$Basename}"
UpdateFormat png
UpdateResult "$$Basename.png"
Requirement "graphicx"
FormatEnd
Format Ascii
Product "$$Contents(\"$$Basename.asc\")"
UpdateCommand "python $$Sysdir/scripts/pic2ascii.py $$FName $$Parameters"
UpdateFormat asciiimage
UpdateResult "$$Basename.asc"
FormatEnd
Format DocBook
Product "<graphic fileref=\"$$Basename.eps\"></graphic>"
UpdateCommand "python $$Sysdir/scripts/pic2png_eps.py $$FName $$Parameters"
UpdateFormat eps
UpdateResult "$$Basename.eps"
FormatEnd
Format LinuxDoc
@ -56,36 +59,32 @@ Template XFig
For DocBook export, you can provide
optional parameters for the ImageMagick
convert script.
This template uses XFig for editing, and
fig2dev and ImageMagick to do conversions.
It requires Python for exporting to Ascii
and DocBook, and gifscii for exporting to
Ascii.
This template uses XFig for editing.
HelpTextEnd
InputFormat fig
FileFilter "*.fig"
ViewCommand "xfig $$FName"
EditCommand "xfig $$FName"
AutomaticProduction true
Format LaTeX
Product "\\input{$$Basename.pstex_t}"
UpdateCommand "python $$Sysdir/scripts/fig2pstex.py $$FName $$Parameters"
UpdateFormat pstex
UpdateResult "$$Basename.pstex_t"
Requirement "graphicx"
FormatEnd
Format PDFLaTeX
Product "\\begin{picture}(0,0)\\includegraphics{$$Basename}\\end{picture}"
UpdateCommand "python $$Sysdir/scripts/fig2png.py $$FName $$Parameters"
UpdateResult "$$Basename.png"
Product "\\input{$$Basename.pdftex_t}"
UpdateFormat pdftex
UpdateResult "$$Basename.pdftex_t"
Requirement "graphicx"
FormatEnd
Format Ascii
Product "$$Contents(\"$$Basename.asc\")"
UpdateCommand "python $$Sysdir/scripts/pic2ascii.py $$FName $$Parameters"
UpdateFormat asciixfig
UpdateResult "$$Basename.asc"
FormatEnd
Format DocBook
Product "<graphic fileref=\"$$Basename.eps\"></graphic>"
UpdateCommand "python $$Sysdir/scripts/pic2png_eps.py $$FName $$Parameters"
UpdateFormat eps
UpdateResult "$$Basename.eps"
FormatEnd
Format LinuxDoc
@ -97,9 +96,8 @@ Template ChessDiagram
GuiName "[Chess: $$Basename]"
HelpText
A chess position diagram.
This template will use XBoard to view
and edit the position. Use the
'File->Save Position' in XBoard to save
This template will use XBoard to edit the position.
Use the 'File->Save Position' in XBoard to save
the position that you want to display.
Make sure to give it a '.fen' extension
and remember to type in a relative path
@ -115,8 +113,8 @@ Template ChessDiagram
that TeX will find it, and you will need
to install the skak package from CTAN.
HelpTextEnd
InputFormat fen
FileFilter "*.fen"
ViewCommand "xboard -lpf $$FName"
EditCommand "xboard -lpf $$FName -mode EditPosition"
AutomaticProduction true
Format LaTeX
@ -125,7 +123,7 @@ Template ChessDiagram
FormatEnd
Format Ascii
Product "$$Contents(\"$$Basename.asc\")"
UpdateCommand "python $$Sysdir/scripts/fen2ascii.py $$FName $$Basename.asc"
UpdateFormat asciichess
UpdateResult "$$Basename.asc"
FormatEnd
Format DocBook
@ -151,24 +149,28 @@ Template Date
Use +%T to get the time as "23:23:00"
Read 'info date' for more information.
HelpTextEnd
InputFormat date
FileFilter "*"
ViewCommand "xterm -e less $$Tempname"
AutomaticProduction true
Format LaTeX
Product "$$Contents(\"$$Tempname\")"
UpdateCommand "python $$Sysdir/scripts/general_command_wrapper.py - $$Tempname date $$Parameters"
UpdateFormat dateout
UpdateResult "$$Tempname"
FormatEnd
Format Ascii
Product "$$Contents(\"$$Tempname\")"
UpdateCommand "python $$Sysdir/scripts/general_command_wrapper.py - $$Tempname date $$Parameters"
UpdateFormat dateout
UpdateResult "$$Tempname"
FormatEnd
Format DocBook
Product "$$Contents(\"$$Tempname\")"
UpdateCommand "python $$Sysdir/scripts/general_command_wrapper.py - $$Tempname date $$Parameters"
UpdateFormat dateout
UpdateResult "$$Tempname"
FormatEnd
Format LinuxDoc
Product "$$Contents(\"$$Tempname\")"
UpdateCommand "python $$Sysdir/scripts/general_command_wrapper.py - $$Tempname date $$Parameters"
UpdateFormat dateout
UpdateResult "$$Tempname"
FormatEnd
TemplateEnd

View File

@ -1,3 +1,7 @@
2003-06-03 Angus Leeming <leeming@lyx.org>
* factory.C (createInset): small change to the way InsetExternal's params
are set.
2003-06-04 André Pönitz <poenitz@gmx.net>

View File

@ -199,7 +199,8 @@ Inset * createInset(FuncRequest const & cmd)
InsetExternal::Params iep;
InsetExternalMailer::string2params(cmd.argument, iep);
InsetExternal * inset = new InsetExternal;
inset->setFromParams(iep);
string const fpath = cmd.view()->buffer()->filePath();
inset->setParams(iep, fpath);
return inset;
} else if (name == "graphics") {

View File

@ -1,3 +1,8 @@
2003-06-03 Angus Leeming <leeming@lyx.org>
* ControlExternal.[Ch]: remove viewExternal and updateExternal.
Change the internal store from an InsetExternal to its Param struct.
2003-06-03 John Levon <levon@movementarian.org>
* ControlGraphics.C: make file path relative for the GUI,

View File

@ -18,6 +18,8 @@
#include "gettext.h"
#include "helper_funcs.h"
#include "lyxrc.h"
#include "support/LAssert.h"
#include <vector>
using std::vector;
@ -30,18 +32,15 @@ ControlExternal::ControlExternal(Dialog & parent)
bool ControlExternal::initialiseParams(string const & data)
{
inset_.reset(new InsetExternal);
InsetExternal::Params params;
InsetExternalMailer::string2params(data, params);
inset_->setFromParams(params);
inset_->setView(kernel().bufferview());
params_.reset(new InsetExternal::Params);
InsetExternalMailer::string2params(data, *params_);
return true;
}
void ControlExternal::clearParams()
{
inset_.reset();
params_.reset();
}
@ -54,28 +53,27 @@ void ControlExternal::dispatchParams()
void ControlExternal::setParams(InsetExternal::Params const & p)
{
inset_->setFromParams(p);
lyx::Assert(params_.get());
*params_ = p;
}
InsetExternal::Params const & ControlExternal::params() const
{
lyx::Assert(params_.get());
return *params_;
}
void ControlExternal::editExternal()
{
lyx::Assert(params_.get());
dialog().view().apply();
inset_->editExternal();
}
void ControlExternal::viewExternal()
{
dialog().view().apply();
inset_->viewExternal();
}
void ControlExternal::updateExternal()
{
dialog().view().apply();
inset_->updateExternal();
InsetExternal inset;
inset.setParams(*params_, kernel().buffer()->filePath());
inset.cache(kernel().bufferview());
inset.editExternal();
}

View File

@ -34,18 +34,13 @@ public:
virtual bool isBufferDependent() const { return true; }
///
InsetExternal::Params const & params() const
{ return inset_->params(); }
InsetExternal::Params const & params() const;
///
void setParams(InsetExternal::Params const &);
///
void editExternal();
///
void viewExternal();
///
void updateExternal();
///
std::vector<string> const getTemplates() const;
///
int getTemplateNumber(string const &) const;
@ -55,7 +50,7 @@ public:
string const Browse(string const &) const;
private:
///
boost::scoped_ptr<InsetExternal> inset_;
boost::scoped_ptr<InsetExternal::Params> params_;
};
#endif // CONTROLEXTERNAL_H

View File

@ -1,3 +1,16 @@
2003-06-03 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): change the External dialog button policy to
NoRepeatedApplyReadOnlyPolicy.
* QExternal.C:
* QExternalDialog.[Ch]:
* ui/QExternalDialogBase.ui:
add widgets to set the way the External dialog is
displayed within LyX.
Remove the buttons to trigger the View command and the Update command
(duplicates Apply).
2003-06-03 John Levon <levon@movementarian.org>
* lyx_gui.C: add sync_events()

View File

@ -159,7 +159,7 @@ Dialog * Dialogs::build(string const & name)
} else if (name == "external") {
dialog->setController(new ControlExternal(*dialog));
dialog->setView(new QExternal(*dialog));
dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
} else if (name == "file") {
dialog->setController(new ControlShowFile(*dialog));
dialog->setView(new QShowFile(*dialog));

View File

@ -13,9 +13,12 @@
#include "ControlExternal.h"
#include "qt_helpers.h"
#include "support/lstrings.h"
#include "support/tostr.h"
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qtextview.h>
@ -63,6 +66,23 @@ void QExternal::update_contents()
dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templ.lyxName));
dialog_->externalTV->setText(toqstr(params.templ.helpText));
int item = 0;
switch (params.display) {
case grfx::DefaultDisplay: item = 0; break;
case grfx::MonochromeDisplay: item = 1; break;
case grfx::GrayscaleDisplay: item = 2; break;
case grfx::ColorDisplay: item = 3; break;
case grfx::NoDisplay: item = 0; break;
}
dialog_->showCB->setCurrentItem(item);
dialog_->showCB->setEnabled(params.display != grfx::NoDisplay &&
!readOnly());
dialog_->displayCB->setChecked(params.display != grfx::NoDisplay);
dialog_->displayscale->setEnabled(params.display != grfx::NoDisplay &&
!readOnly());
dialog_->displayscale->setText(toqstr(tostr(params.lyxscale)));
isValid();
}
@ -84,5 +104,18 @@ void QExternal::apply()
params.templ = controller().getTemplate(dialog_->externalCO->currentItem());
switch (dialog_->showCB->currentItem()) {
case 0: params.display = grfx::DefaultDisplay; break;
case 1: params.display = grfx::MonochromeDisplay; break;
case 2: params.display = grfx::GrayscaleDisplay; break;
case 3: params.display = grfx::ColorDisplay; break;
default:;
}
if (!dialog_->displayCB->isChecked())
params.display = grfx::NoDisplay;
params.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
controller().setParams(params);
}

View File

@ -20,6 +20,7 @@
#include <qcombobox.h>
#include <qtextview.h>
#include <qlineedit.h>
#include <qvalidator.h>
#include "QExternalDialog.h"
#include "QExternal.h"
@ -35,6 +36,10 @@ QExternalDialog::QExternalDialog(QExternal * form)
form, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form, SLOT(slotClose()));
QIntValidator * validator = new QIntValidator(displayscale);
validator->setBottom(1);
displayscale->setValidator(validator);
}
@ -65,20 +70,6 @@ void QExternalDialog::editClicked()
}
void QExternalDialog::viewClicked()
{
form_->changed();
form_->controller().viewExternal();
}
void QExternalDialog::updateClicked()
{
form_->changed();
form_->controller().updateExternal();
}
void QExternalDialog::browseClicked()
{
QString file =
@ -96,7 +87,5 @@ void QExternalDialog::browseClicked()
void QExternalDialog::templateChanged()
{
externalTV->setText(toqstr(form_->helpText()));
updatePB->setEnabled(!form_->controller().params().templ.automaticProduction);
form_->changed();
}

View File

@ -26,8 +26,6 @@ public:
protected slots:
virtual void change_adaptor();
virtual void editClicked();
virtual void viewClicked();
virtual void updateClicked();
virtual void browseClicked();
virtual void templateChanged();
protected:

View File

@ -13,8 +13,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>353</width>
<height>378</height>
<width>349</width>
<height>514</height>
</rect>
</property>
<property stdset="1">
@ -34,7 +34,85 @@
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="1" rowspan="1" colspan="2" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>externalCO</cstring>
</property>
<property>
<name>toolTip</name>
<string>Available templates</string>
</property>
</widget>
<widget row="1" column="0" rowspan="1" colspan="3" >
<class>QTextView</class>
<property stdset="1">
<name>name</name>
<cstring>externalTV</cstring>
</property>
<property>
<name>toolTip</name>
<string>LaTeX error messages</string>
</property>
</widget>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>templateLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Template:</string>
</property>
<property>
<name>buddy</name>
<cstring>externalCO</cstring>
</property>
<property>
<name>toolTip</name>
<string>Available templates</string>
</property>
</widget>
<widget row="2" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>fileED</cstring>
</property>
<property>
<name>toolTip</name>
<string>Filename</string>
</property>
</widget>
<widget row="3" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>paramsED</cstring>
</property>
<property>
<name>toolTip</name>
<string>Parameters</string>
</property>
</widget>
<widget row="3" column="2" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>editPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Edit file</string>
</property>
<property>
<name>toolTip</name>
<string>Edit the file externally</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
@ -53,18 +131,272 @@
<string>Filename</string>
</property>
</widget>
<widget row="0" column="1" >
<class>QLineEdit</class>
<widget row="2" column="2" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>fileED</cstring>
<cstring>browsePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Browse...</string>
</property>
</widget>
<widget row="3" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>paramsLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Parameters:</string>
</property>
<property>
<name>buddy</name>
<cstring>paramsED</cstring>
</property>
<property>
<name>toolTip</name>
<string>Filename</string>
<string>Parameters</string>
</property>
</widget>
<widget row="4" column="0" rowspan="1" colspan="3" >
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox4</cstring>
</property>
<property stdset="1">
<name>title</name>
<string>LyX Display</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout14</cstring>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="1" column="1" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout11</cstring>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>scaleLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Scale:</string>
</property>
<property>
<name>buddy</name>
<cstring>displayscale</cstring>
</property>
<property>
<name>toolTip</name>
<string>Percentage to scale by in LyX</string>
</property>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout10</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>displayscale</cstring>
</property>
<property stdset="1">
<name>enabled</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property>
<name>toolTip</name>
<string>Percentage to scale by in LyX</string>
</property>
</widget>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>displayscaleL</cstring>
</property>
<property stdset="1">
<name>enabled</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>focusPolicy</name>
<enum>NoFocus</enum>
</property>
<property stdset="1">
<name>text</name>
<string>%</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<widget row="1" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout9</cstring>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Display:</string>
</property>
<property>
<name>buddy</name>
<cstring>showCB</cstring>
</property>
<property>
<name>toolTip</name>
<string>Screen display</string>
</property>
</widget>
<widget>
<class>QComboBox</class>
<item>
<property>
<name>text</name>
<string>Default</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Monochrome</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Grayscale</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Color</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>showCB</cstring>
</property>
<property>
<name>toolTip</name>
<string>Screen display</string>
</property>
</widget>
</vbox>
</widget>
<widget row="0" column="0" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>displayCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Show in LyX</string>
</property>
<property>
<name>toolTip</name>
<string>Display image in LyX</string>
</property>
</widget>
</grid>
</widget>
</grid>
</widget>
<widget row="5" column="0" rowspan="1" colspan="3" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout3</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
</hbox>
</widget>
<widget row="6" column="0" rowspan="1" colspan="3" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
@ -151,179 +483,9 @@
</widget>
</hbox>
</widget>
<widget row="4" column="0" rowspan="1" colspan="3" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout3</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>viewPB</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;View Result</string>
</property>
<property>
<name>toolTip</name>
<string>View the file</string>
</property>
</widget>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>updatePB</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Update Result</string>
</property>
<property>
<name>toolTip</name>
<string>Update the material</string>
</property>
</widget>
</hbox>
</widget>
<widget row="3" column="0" rowspan="1" colspan="3" >
<class>QTextView</class>
<property stdset="1">
<name>name</name>
<cstring>externalTV</cstring>
</property>
<property>
<name>toolTip</name>
<string>LaTeX error messages</string>
</property>
</widget>
<widget row="2" column="1" rowspan="1" colspan="2" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>externalCO</cstring>
</property>
<property>
<name>toolTip</name>
<string>Available templates</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>templateLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Template:</string>
</property>
<property>
<name>buddy</name>
<cstring>externalCO</cstring>
</property>
<property>
<name>toolTip</name>
<string>Available templates</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>paramsED</cstring>
</property>
<property>
<name>toolTip</name>
<string>Parameters</string>
</property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>paramsLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Parameters:</string>
</property>
<property>
<name>buddy</name>
<cstring>paramsED</cstring>
</property>
<property>
<name>toolTip</name>
<string>Parameters</string>
</property>
</widget>
<widget row="0" column="2" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>browsePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Browse...</string>
</property>
</widget>
<widget row="1" column="2" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>editPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Edit file</string>
</property>
<property>
<name>toolTip</name>
<string>Edit the file externally</string>
</property>
</widget>
</grid>
</widget>
<connections>
<connection>
<sender>updatePB</sender>
<signal>clicked()</signal>
<receiver>QExternalDialogBase</receiver>
<slot>updateClicked()</slot>
</connection>
<connection>
<sender>viewPB</sender>
<signal>clicked()</signal>
<receiver>QExternalDialogBase</receiver>
<slot>viewClicked()</slot>
</connection>
<connection>
<sender>editPB</sender>
<signal>clicked()</signal>
@ -354,6 +516,36 @@
<receiver>QExternalDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>displayCB</sender>
<signal>toggled(bool)</signal>
<receiver>showCB</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>displayCB</sender>
<signal>toggled(bool)</signal>
<receiver>displayscale</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>displayCB</sender>
<signal>stateChanged(int)</signal>
<receiver>QExternalDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>showCB</sender>
<signal>activated(const QString&amp;)</signal>
<receiver>QExternalDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>displayscale</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QExternalDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<slot access="public">browseClicked()</slot>
<slot access="public">change_adaptor()</slot>
<slot access="public">editClicked()</slot>
@ -368,8 +560,6 @@
<tabstop>editPB</tabstop>
<tabstop>externalCO</tabstop>
<tabstop>externalTV</tabstop>
<tabstop>viewPB</tabstop>
<tabstop>updatePB</tabstop>
<tabstop>okPB</tabstop>
<tabstop>applyPB</tabstop>
<tabstop>closePB</tabstop>

View File

@ -7,6 +7,18 @@
* lyx_gui.C: add sync_events()
2003-06-03 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): change the External dialog button policy to
NoRepeatedApplyReadOnlyPolicy.
* FormExternal.C:
* forms/form_external.fd:
add widgets to set the way the External dialog is
displayed within LyX.
Remove the buttons to trigger the View command and the Update command
(duplicates Apply).
2003-06-03 Angus Leeming <leeming@lyx.org>
* FormGraphics.C (build): a few comments.

View File

@ -154,7 +154,7 @@ Dialog * Dialogs::build(string const & name)
} else if (name == "external") {
dialog->setController(new ControlExternal(*dialog));
dialog->setView(new FormExternal(*dialog));
dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
} else if (name == "file") {
dialog->setController(new ControlShowFile(*dialog));
dialog->setView(new FormShowFile(*dialog));

View File

@ -12,15 +12,19 @@
#include <config.h>
#include "xformsBC.h"
#include "ControlExternal.h"
#include "FormExternal.h"
#include "forms/form_external.h"
#include "gettext.h"
#include "xforms_helpers.h"
#include "helper_funcs.h"
#include "helper_funcs.h"
#include "input_validators.h"
#include "Tooltips.h"
#include "xforms_helpers.h"
#include "gettext.h"
#include "support/tostr.h"
#include "support/lstrings.h"
#include "lyx_forms.h"
@ -41,6 +45,29 @@ void FormExternal::apply()
int const choice = fl_get_choice(dialog_->choice_template) - 1;
params.templ = controller().getTemplate(choice);
params.parameters = fl_get_input(dialog_->input_parameters);
params.lyxscale = strToInt(getString(dialog_->input_lyxscale));
if (params.lyxscale == 0)
params.lyxscale = 100;
switch (fl_get_choice(dialog_->choice_display)) {
case 5:
params.display = grfx::NoDisplay;
break;
case 4:
params.display = grfx::ColorDisplay;
break;
case 3:
params.display = grfx::GrayscaleDisplay;
break;
case 2:
params.display = grfx::MonochromeDisplay;
break;
case 1:
params.display = grfx::DefaultDisplay;
}
controller().setParams(params);
}
@ -56,16 +83,40 @@ void FormExternal::build()
fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
// Disable for read-only documents.
bcview().addReadOnly(dialog_->input_filename);
bcview().addReadOnly(dialog_->button_browse);
bcview().addReadOnly(dialog_->input_parameters);
// Trigger an input event for cut&paste with middle mouse button.
setPrehandler(dialog_->input_filename);
setPrehandler(dialog_->input_parameters);
// Activate ok/apply immediately upon input.
fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
string const display_List =
_("Default|Monochrome|Grayscale|Color|Do not display");
fl_addto_choice(dialog_->choice_display, display_List.c_str());
// Set up the tooltips.
string str = _("The file you want to insert.");
tooltips().init(dialog_->input_filename, str);
str = _("Browse the directories.");
tooltips().init(dialog_->button_browse, str);
str = _("Scale the image to inserted percentage value.");
tooltips().init(dialog_->input_lyxscale, str);
str = _("Select display mode for this image.");
tooltips().init(dialog_->choice_display, str);
// Manage the ok, apply and cancel/close buttons
bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_close);
bcview().addReadOnly(dialog_->input_filename);
bcview().addReadOnly(dialog_->button_filenamebrowse);
bcview().addReadOnly(dialog_->input_parameters);
}
@ -81,6 +132,25 @@ void FormExternal::update()
fl_set_choice(dialog_->choice_template, ID+1);
updateComboChange();
fl_set_input(dialog_->input_lyxscale, tostr(params.lyxscale).c_str());
switch (params.display) {
case grfx::NoDisplay:
fl_set_choice(dialog_->choice_display, 5);
break;
case grfx::ColorDisplay:
fl_set_choice(dialog_->choice_display, 4);
break;
case grfx::GrayscaleDisplay:
fl_set_choice(dialog_->choice_display, 3);
break;
case grfx::MonochromeDisplay:
fl_set_choice(dialog_->choice_display, 2);
break;
case grfx::DefaultDisplay:
fl_set_choice(dialog_->choice_display, 1);
}
}
@ -96,7 +166,7 @@ ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
updateComboChange();
} else if (ob == dialog_->button_filenamebrowse) {
} else if (ob == dialog_->button_browse) {
string const in_name = fl_get_input(dialog_->input_filename);
string const out_name = controller().Browse(in_name);
@ -104,12 +174,6 @@ ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
} else if (ob == dialog_->button_edit) {
controller().editExternal();
} else if (ob == dialog_->button_view) {
controller().viewExternal();
} else if (ob == dialog_->button_update) {
controller().updateExternal();
}
return ButtonPolicy::SMI_VALID;
@ -123,7 +187,4 @@ void FormExternal::updateComboChange()
fl_addto_browser(dialog_->browser_helptext,
controller().params().templ.helpText.c_str());
fl_set_browser_topline(dialog_->browser_helptext, 0);
bool const enabled = (!controller().params().templ.automaticProduction);
setEnabled(dialog_->button_update, enabled);
}

View File

@ -9,14 +9,14 @@ SnapGrid: 5
=============== FORM ===============
Name: form_external
Width: 320
Height: 355
Number of Objects: 12
Width: 395
Height: 375
Number of Objects: 14
--------------------
class: FL_BOX
type: FLAT_BOX
box: 0 0 320 355
box: 0 0 395 375
boxtype: FL_FLAT_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -31,49 +31,13 @@ name:
callback:
argument:
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 110 5 160 25
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_RIGHT_BCOL
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Template:|#t
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NorthWest FL_NorthEast
name: choice_template
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BROWSER
type: NORMAL_BROWSER
box: 5 35 310 125
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NorthWest FL_SouthEast
name: browser_helptext
callback:
argument:
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 5 220 310 25
box: 90 195 195 25
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_TOP_LEFT
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
@ -88,7 +52,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 215 245 100 25
box: 290 195 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -99,17 +63,17 @@ label: Browse...|#B
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_SouthEast FL_SouthEast
name: button_filenamebrowse
name: button_browse
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 5 290 310 25
box: 90 230 195 25
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_TOP_LEFT
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
@ -124,7 +88,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 5 165 100 25
box: 290 230 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -140,45 +104,117 @@ callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 110 165 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
class: FL_LABELFRAME
type: ENGRAVED_FRAME
box: 5 270 385 55
boxtype: FL_NO_BOX
colors: FL_BLACK FL_COL1
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: View result|#V
label: LyX View
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:
--------------------
class: FL_TEXT
type: NORMAL_TEXT
box: 155 285 25 25
boxtype: FL_FLAT_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER|FL_ALIGN_INSIDE
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: %
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_view
gravity: FL_East FL_East
name:
callback:
argument:
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 85 285 70 25
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Scale:|#S
shortcut:
resize: FL_RESIZE_X
gravity: FL_West FL_East
name: input_lyxscale
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 215 165 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
class: FL_CHOICE
type: NORMAL_CHOICE
box: 265 285 115 25
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Update result|#U
label: Display:|#D
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_update
gravity: FL_East FL_East
name: choice_display
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 140 5 160 25
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_RIGHT_BCOL
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Template:|#T
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NorthWest FL_NorthEast
name: choice_template
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BROWSER
type: NORMAL_BROWSER
box: 10 35 380 140
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NorthWest FL_SouthEast
name: browser_helptext
callback:
argument:
--------------------
class: FL_BUTTON
type: RETURN_BUTTON
box: 35 325 90 25
box: 110 340 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -196,7 +232,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 130 325 90 25
box: 205 340 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -214,7 +250,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 225 325 90 25
box: 300 340 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER

View File

@ -1,4 +1,3 @@
2003-06-04 André Pönitz <poenitz@gmx.net>
* inset.[Ch]: change owner_ from Inset * to UpdatableInset *
@ -7,6 +6,22 @@
* insettabular.C: back out tall table speed up. It was broken
2003-06-03 Angus Leeming <leeming@lyx.org>
* ExternalTemplate.[Ch]: add inputFormat and UpdateFormat variables.
Remove ViewCommand and UpdateCommand.
* graphicinset.C (update): bug fix. Set the params before calling the
loader.
* graphicinset.[Ch] (view): new method. A bit of a fudge to set the
BufferView cache to enable the InsetExternal::editCommand to be invoked
from the frontends. Would not be needed if this were dispatched properly.
(old_ascent_): variable removed.
* insetexternal.[Ch]: large clean-up to use the converter mechanism to
do any necessary conversions of external material. Also use the
new GraphicsInset to display the inset within LyX.
2003-06-03 Angus Leeming <leeming@lyx.org>
* graphicinset.[Ch]: new files. Clean up the InsetGraphics::Cache

View File

@ -31,6 +31,7 @@ extern string user_lyxdir;
// We have to have dummy default commands for security reasons!
ExternalTemplate::ExternalTemplate()
: inputFormat("*")
{}
@ -59,8 +60,8 @@ public:
<< "\tHelpText\n"
<< et.helpText
<< "\tHelpTextEnd\n"
<< "\tInputFormat " << et.inputFormat << "\n"
<< "\tFileFilter " << et.fileRegExp << "\n"
<< "\tViewCommand " << et.viewCommand << "\n"
<< "\tEditCommand " << et.editCommand << "\n"
<< "\tAutomaticProduction " << et.automaticProduction << "\n";
et.dumpFormats(ost);
@ -80,7 +81,7 @@ public:
ExternalTemplate::FormatTemplate const & ft = vt.second;
ost << "\tFormat " << vt.first << "\n"
<< "\t\tProduct " << ft.product << "\n"
<< "\t\tUpdateCommand " << ft.updateCommand << "\n"
<< "\t\tUpdateFormat " << ft.updateFormat << "\n"
<< "\t\tUpdateResult " << ft.updateResult << "\n"
<< "\t\tRequirement " << ft.requirement << "\n"
<< "\t\tPreamble\n"
@ -184,8 +185,8 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
enum TemplateOptionTags {
TO_GUINAME = 1,
TO_HELPTEXT,
TO_INPUTFORMAT,
TO_FILTER,
TO_VIEWCMD,
TO_EDITCMD,
TO_AUTOMATIC,
TO_FORMAT,
@ -199,8 +200,8 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
{ "format", TO_FORMAT },
{ "guiname", TO_GUINAME },
{ "helptext", TO_HELPTEXT },
{ "templateend", TO_END },
{ "viewcommand", TO_VIEWCMD }
{ "inputformat", TO_INPUTFORMAT },
{ "templateend", TO_END }
};
pushpophelper pph(lex, templateoptiontags, TO_END);
@ -216,16 +217,16 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
helpText = lex.getLongString("HelpTextEnd");
break;
case TO_INPUTFORMAT:
lex.next(true);
inputFormat = lex.getString();
break;
case TO_FILTER:
lex.next(true);
fileRegExp = lex.getString();
break;
case TO_VIEWCMD:
lex.next(true);
viewCommand = lex.getString();
break;
case TO_EDITCMD:
lex.next(true);
editCommand = lex.getString();
@ -258,7 +259,7 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
{
enum FormatTags {
FO_PRODUCT = 1,
FO_UPDATECMD,
FO_UPDATEFORMAT,
FO_UPDATERESULT,
FO_REQUIREMENT,
FO_PREAMBLE,
@ -270,7 +271,7 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
{ "preamble", FO_PREAMBLE },
{ "product", FO_PRODUCT },
{ "requirement", FO_REQUIREMENT },
{ "updatecommand", FO_UPDATECMD },
{ "updateformat", FO_UPDATEFORMAT },
{ "updateresult", FO_UPDATERESULT }
};
@ -283,9 +284,9 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
product = lex.getString();
break;
case FO_UPDATECMD:
case FO_UPDATEFORMAT:
lex.next(true);
updateCommand = lex.getString();
updateFormat = lex.getString();
break;
case FO_UPDATERESULT:

View File

@ -28,10 +28,12 @@ struct ExternalTemplate {
string guiName;
/// A short help text
string helpText;
/** The format of the input file. Can be "*", in which case we try and
ascertain the format from the contents of the file.
*/
string inputFormat;
/// A file extension regular expression for the file browser
string fileRegExp;
/// What command should be executed to view the file?
string viewCommand;
/// What command should be executed to edit the file?
string editCommand;
/// Should we do automatic production of the output?
@ -40,10 +42,10 @@ struct ExternalTemplate {
struct FormatTemplate {
/// The text that should be inserted into the exported file
string product;
/// The shell command to produce a resulting file
string updateCommand;
/// The filename of the resulting file
string updateResult;
/// The format of this file.
string updateFormat;
/// What features does this external inset require?
string requirement;
/// What should be inserted into the preamble
@ -64,7 +66,6 @@ struct ExternalTemplate {
/// We have to have default commands for safety reasons!
ExternalTemplate();
};

View File

@ -27,7 +27,7 @@
GraphicInset::GraphicInset()
: old_ascent_(0), checksum_(0)
: checksum_(0)
{}
@ -35,18 +35,18 @@ GraphicInset::GraphicInset(GraphicInset const & other)
: loader_(other.loader_),
params_(other.params_),
nodisplay_message_(other.nodisplay_message_),
old_ascent_(0),
checksum_(0)
{}
void GraphicInset::update(grfx::Params const & params)
{
params_ = params;
if (!params.filename.empty()) {
lyx::Assert(AbsolutePath(params.filename));
loader_.reset(params_.filename, params_);
loader_.reset(params.filename, params);
}
params_ = params;
}
@ -66,6 +66,13 @@ bool GraphicInset::hasFileChanged() const
}
void GraphicInset::view(BufferView * bv) const
{
if (bv)
view_ = bv->owner()->view();
}
BufferView * GraphicInset::view() const
{
return view_.lock().get();
@ -130,9 +137,7 @@ void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
{
DisplayType type = displayType();
old_ascent_ = (type == IMAGE) ? loader_.image()->getHeight() : 50;
dim.asc = old_ascent_;
dim.asc = (type == IMAGE) ? loader_.image()->getHeight() : 50;
dim.des = 0;
switch (type) {
@ -185,14 +190,14 @@ void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
void GraphicInset::draw(PainterInfo & pi, int x, int y) const
{
BufferView * bv = pi.base.bv;
view_ = bv->owner()->view();
// Cache the BufferView.
view(pi.base.bv);
#if 0
// MakeAbsPath returns filename_ unchanged if it is absolute
// already.
string const file_with_path =
MakeAbsPath(params_.filename, bv->buffer()->filePath());
MakeAbsPath(params_.filename, view_->buffer()->filePath());
// A 'paste' operation creates a new inset with the correct filepath,
// but then the 'old' inset stored in the 'copy' operation is actually
@ -210,14 +215,6 @@ void GraphicInset::draw(PainterInfo & pi, int x, int y) const
}
#endif
// we may have changed while someone other was drawing us so better
// to not draw anything as we surely call to redraw ourself soon.
// This is not a nice thing to do and should be fixed properly somehow.
// But I still don't know the best way to go. So let's do this like this
// for now (Jug 20020311)
if (dim_.asc != old_ascent_)
return;
if (params_.display != grfx::NoDisplay &&
loader_.status() == grfx::WaitingToLoad)
loader_.startLoading();

View File

@ -52,6 +52,8 @@ public:
/// Is the stored checksum different to that of the graphics loader?
bool hasFileChanged() const;
/// Set the cached store.
void view(BufferView *) const;
/// An accessor function to the cached store.
BufferView * view() const;
@ -61,6 +63,9 @@ public:
typedef boost::signal0<void>::slot_type slot_type;
boost::signals::connection connect(slot_type const &) const;
/// The message to display instead of the graphic itself.
string const statusMessage() const;
private:
enum DisplayType {
IMAGE,
@ -71,16 +76,12 @@ private:
/// Is the image ready to draw, or should we display a message instead?
DisplayType displayType() const;
/// The message to display instead of the graphic itself.
string const statusMessage() const;
/// The stored data.
grfx::Loader loader_;
grfx::Params params_;
string nodisplay_message_;
/// These are all cached variables.
mutable int old_ascent_;
mutable unsigned long checksum_;
mutable boost::weak_ptr<BufferView> view_;
mutable Dimension dim_;

View File

@ -11,9 +11,11 @@
#include <config.h>
#include "insetexternal.h"
#include "insets/graphicinset.h"
#include "buffer.h"
#include "BufferView.h"
#include "converter.h"
#include "debug.h"
#include "ExternalTemplate.h"
#include "funcrequest.h"
@ -22,8 +24,10 @@
#include "latexrunparams.h"
#include "lyx_main.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "Lsstream.h"
#include "frontends/lyx_gui.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
@ -31,9 +35,11 @@
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/path.h"
#include "support/systemcall.h"
#include "support/forkedcall.h"
#include "support/FileInfo.h"
#include <boost/bind.hpp>
#include <cstdio>
#include <utility>
@ -42,22 +48,47 @@ using std::endl;
InsetExternal::InsetExternal()
: view_(0)
: graphic_(new GraphicInset)
{
tempname_ = lyx::tempName(string(), "lyxext");
//ExternalTemplateManager::Templates::const_iterator i1;
graphic_->connect(boost::bind(&InsetExternal::statusChanged, this));
params_.templ = ExternalTemplateManager::get().getTemplates().begin()->second;
}
InsetExternal::InsetExternal(InsetExternal const & other)
: Inset(other),
boost::signals::trackable(),
params_(other.params_),
graphic_(new GraphicInset(*other.graphic_))
{
graphic_->connect(boost::bind(&InsetExternal::statusChanged, this));
}
Inset * InsetExternal::clone() const
{
InsetExternal * inset = new InsetExternal(*this);
return inset;
}
InsetExternal::~InsetExternal()
{
lyx::unlink(tempname_);
if (!tempname_.empty())
lyx::unlink(tempname_);
InsetExternalMailer mailer(*this);
mailer.hideDialog();
}
void InsetExternal::statusChanged()
{
BufferView * bv = graphic_->view();
if (bv)
bv->updateInset(this);
}
InsetExternal::Params const & InsetExternal::params() const
{
return params_;
@ -71,10 +102,8 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
case LFUN_INSET_MODIFY: {
InsetExternal::Params p;
InsetExternalMailer::string2params(cmd.argument, p);
if (!p.filename.empty()) {
setFromParams(p);
cmd.view()->updateInset(this);
}
setParams(p, cmd.view()->buffer()->filePath());
cmd.view()->updateInset(this);
return DISPATCHED;
}
@ -93,11 +122,65 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
}
void InsetExternal::setFromParams(Params const & p)
void InsetExternal::cache(BufferView * bv) const
{
graphic_->view(bv);
}
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
{
graphic_->metrics(mi, dim);
}
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
{
graphic_->draw(pi, x, y);
}
namespace {
grfx::Params get_grfx_params(InsetExternal::Params const & eparams,
string const & filepath)
{
grfx::Params gparams;
if (!eparams.filename.empty()) {
lyx::Assert(AbsolutePath(filepath));
gparams.filename = MakeAbsPath(eparams.filename, filepath);
}
gparams.scale = eparams.lyxscale;
gparams.display = eparams.display;
if (gparams.display == grfx::DefaultDisplay)
gparams.display = lyxrc.display_graphics;
// Override the above if we're not using a gui
if (!lyx_gui::use_gui)
gparams.display = grfx::NoDisplay;
return gparams;
}
} // namespace anon
void InsetExternal::setParams(Params const & p, string const & filepath)
{
params_.filename = p.filename;
params_.parameters = p.parameters;
params_.templ = p.templ;
params_.display = p.display;
params_.lyxscale = p.lyxscale;
// Update the display using the new parameters.
if (params_.filename.empty() || !filepath.empty())
graphic_->update(get_grfx_params(params_, filepath));
string const msg = doSubstitution(0, params_.templ.guiName);
graphic_->setNoDisplayMessage(msg);
}
@ -110,11 +193,14 @@ string const InsetExternal::editMessage() const
void InsetExternal::write(Buffer const *, ostream & os) const
{
os << "External " << params_.templ.lyxName << ",\""
<< params_.filename << "\",\"" << params_.parameters << "\"\n";
<< params_.filename << "\",\""
<< params_.parameters << "\","
<< params_.display << ','
<< params_.lyxscale << '\n';
}
void InsetExternal::read(Buffer const *, LyXLex & lex)
void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
{
string format;
string token;
@ -140,18 +226,56 @@ void InsetExternal::read(Buffer const *, LyXLex & lex)
// Parse string format...
string::size_type const pos1 = format.find(',');
params_.templ = ExternalTemplateManager::get().getTemplateByName(format.substr(0, pos1));
string::size_type const pos2 = format.find("\",\"", pos1);
params_.filename = format.substr(pos1 + 2, pos2 - (pos1 + 2));
params_.parameters = format.substr(pos2 + 3, format.length() - (pos2 + 4));
string::size_type const file_start = pos1 + 2;
string::size_type const pos2 = format.find("\",\"", file_start);
string::size_type const file_size = pos2 - file_start;
params_.filename = format.substr(file_start, file_size);
lyxerr[Debug::INFO] << "InsetExternal::Read: " << params_.templ.lyxName
<< ' ' << params_.filename
<< ' ' << params_.parameters << endl;
string::size_type const params_start = pos2 + 3;
string::size_type const pos3 = format.find("\"", params_start);
string::size_type const params_size = pos3 == pos3 - params_start;
params_.parameters = format.substr(params_start, params_size);
params_.display = grfx::NoDisplay;
params_.lyxscale = 100;
string::size_type const display_start = pos3 + 2;
if (display_start < format.size()) {
string::size_type const pos4 = format.find(',', display_start);
string::size_type const display_size = pos4 - display_start;
string const display = format.substr(display_start, display_size);
if (isStrUnsignedInt(display)) {
unsigned int const tmp = strToUnsignedInt(display);
params_.display = static_cast<grfx::DisplayType>(tmp);
}
string::size_type const scale_start = pos4 + 1;
string::size_type const scale_size = format.size() - scale_start;
string const scale = format.substr(scale_start, scale_size);
if (isStrUnsignedInt(scale)) {
params_.lyxscale = strToUnsignedInt(scale);
}
}
lyxerr[Debug::INFO] << "InsetExternal::Read: "
<< "template: '" << params_.templ.lyxName
<< "' filename: '" << params_.filename
<< "' params: '" << params_.parameters
<< "' display: '" << params_.display
<< "' scale: '" << params_.lyxscale
<< '\'' << endl;
// Update the display using the new parameters.
if (buffer)
graphic_->update(get_grfx_params(params_, buffer->filePath()));
string const msg = doSubstitution(0, params_.templ.guiName);
graphic_->setNoDisplayMessage(msg);
}
int InsetExternal::write(string const & format,
Buffer const * buf, ostream & os) const
Buffer const * buf, ostream & os,
bool external_in_tmpdir) const
{
ExternalTemplate const & et = params_.templ;
ExternalTemplate::Formats::const_iterator cit =
@ -163,7 +287,7 @@ int InsetExternal::write(string const & format,
return 0;
}
updateExternal(format, buf);
updateExternal(format, buf, external_in_tmpdir);
string const str = doSubstitution(buf, cit->second.product);
os << str;
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
@ -173,6 +297,13 @@ int InsetExternal::write(string const & format,
int InsetExternal::latex(Buffer const * buf, ostream & os,
LatexRunParams const & runparams) const
{
// "nice" means that the buffer is exported to LaTeX format but not
// run through the LaTeX compiler.
// If we're running through the LaTeX compiler, we should write the
// generated files in the bufer's temporary directory.
bool const external_in_tmpdir =
lyxrc.use_tempdir && !buf->tmppath.empty() && !runparams.nice;
// If the template has specified a PDFLaTeX output, then we try and
// use that.
if (runparams.flavor == LatexRunParams::PDFLATEX) {
@ -180,10 +311,10 @@ int InsetExternal::latex(Buffer const * buf, ostream & os,
ExternalTemplate::Formats::const_iterator cit =
et.formats.find("PDFLaTeX");
if (cit != et.formats.end())
return write("PDFLaTeX", buf, os);
return write("PDFLaTeX", buf, os, external_in_tmpdir);
}
return write("LaTeX", buf, os);
return write("LaTeX", buf, os, external_in_tmpdir);
}
@ -223,15 +354,6 @@ void InsetExternal::validate(LaTeXFeatures & features) const
}
Inset * InsetExternal::clone() const
{
InsetExternal * inset = new InsetExternal;
inset->params_ = params_;
inset->view_ = view_;
return inset;
}
string const InsetExternal::getScreenLabel(Buffer const *) const
{
ExternalTemplate const & et = params_.templ;
@ -242,27 +364,24 @@ string const InsetExternal::getScreenLabel(Buffer const *) const
}
void InsetExternal::executeCommand(string const & s,
Buffer const * buffer) const
{
Path p(buffer->filePath());
Systemcall one;
if (lyxerr.debugging()) {
lyxerr << "Executing '" << s << "' in '"
<< buffer->filePath() << '\'' << endl;
}
one.startscript(Systemcall::Wait, s);
}
string const InsetExternal::doSubstitution(Buffer const * buffer,
string const & s) const
{
string result;
string const basename = ChangeExtension(params_.filename, string());
string filepath;
bool external_in_tmpdir = false;
if (buffer && !buffer->tmppath.empty() && !buffer->niceFile) {
filepath = buffer->filePath();
if (lyxrc.use_tempdir)
external_in_tmpdir = true;
}
if (tempname_.empty()) {
string const path = external_in_tmpdir ? buffer->tmppath : string();
tempname_ = lyx::tempName(path, "lyxext");
lyx::unlink(tempname_);
// must have an extension for the converter code to work correctly.
tempname_ += ".tmp";
}
result = subst(s, "$$FName", params_.filename);
result = subst(result, "$$Basename", basename);
@ -279,9 +398,11 @@ string const InsetExternal::doSubstitution(Buffer const * buffer,
string const file = result.substr(pos + 12, end - (pos + 12));
string contents;
if (buffer) {
// Make sure we are in the directory of the buffer
Path p(buffer->filePath());
contents = GetFileContents(file);
if (!IsFileReadable(file))
Path p(buffer->tmppath);
if (IsFileReadable(file))
contents = GetFileContents(file);
} else {
contents = GetFileContents(file);
}
@ -296,49 +417,79 @@ string const InsetExternal::doSubstitution(Buffer const * buffer,
void InsetExternal::updateExternal() const
{
updateExternal("LaTeX", view_->buffer());
BufferView const * bv = graphic_->view();
Buffer const * buffer = bv ? bv->buffer() : 0;
updateExternal("LaTeX", buffer, false);
}
void InsetExternal::updateExternal(string const & format,
Buffer const * buf) const
Buffer const * buf,
bool external_in_tmpdir) const
{
ExternalTemplate const & et = params_.templ;
if (!et.automaticProduction)
return;
ExternalTemplate::Formats::const_iterator cit =
et.formats.find(format);
if (cit == et.formats.end() ||
cit->second.updateCommand.empty() ||
!et.automaticProduction)
if (cit == et.formats.end())
return;
if (!cit->second.updateResult.empty()) {
string const resultfile = doSubstitution(buf,
cit->second.updateResult);
FileInfo fi(params_.filename);
FileInfo fi2(resultfile);
if (fi2.exist() && fi.exist() &&
difftime(fi2.getModificationTime(),
fi.getModificationTime()) >= 0) {
lyxerr[Debug::FILES] << resultfile
<< " is up to date" << endl;
ExternalTemplate::FormatTemplate const & outputFormat = cit->second;
if (outputFormat.updateResult.empty())
return;
string from_format = et.inputFormat;
if (from_format.empty())
return;
string from_file = params_.filename.empty() ?
string() : MakeAbsPath(params_.filename, buf->filePath());
if (from_format == "*") {
if (from_file.empty())
return;
// Try and ascertain the file format from its contents.
from_format = getExtFromContents(from_file);
if (from_format.empty())
return;
}
}
executeCommand(doSubstitution(buf, cit->second.updateCommand), buf);
}
void InsetExternal::viewExternal() const
{
ExternalTemplate const & et = params_.templ;
if (et.viewCommand.empty())
string const to_format = outputFormat.updateFormat;
if (to_format.empty())
return;
updateExternal();
executeCommand(doSubstitution(view_->buffer(),
et.viewCommand),
view_->buffer());
if (!converters.isReachable(from_format, to_format)) {
lyxerr << "InsetExternal::updateExternal. "
"Unable to convert from "
<< from_format << " to " << to_format << endl;
return;
}
if (external_in_tmpdir && !from_file.empty()) {
// We are running stuff through LaTeX
from_file = copyFileToDir(buf->tmppath, from_file);
if (from_file.empty())
return;
}
string const to_file = doSubstitution(buf, outputFormat.updateResult);
FileInfo fi(from_file);
string abs_to_file = to_file;
if (!AbsolutePath(to_file))
abs_to_file = MakeAbsPath(to_file, OnlyPath(from_file));
FileInfo fi2(abs_to_file);
if (fi2.exist() && fi.exist() &&
difftime(fi2.getModificationTime(),
fi.getModificationTime()) >= 0) {
} else {
string const to_filebase = ChangeExtension(to_file, string());
converters.convert(buf, from_file, to_filebase,
from_format, to_format);
}
}
@ -348,10 +499,20 @@ void InsetExternal::editExternal() const
if (et.editCommand.empty())
return;
updateExternal();
executeCommand(doSubstitution(view_->buffer(),
et.editCommand),
view_->buffer());
BufferView const * bv = graphic_->view();
Buffer const * buffer = bv ? bv->buffer() : 0;
if (!buffer)
return;
string const command = doSubstitution(buffer, et.editCommand);
Path p(buffer->filePath());
Forkedcall call;
if (lyxerr.debugging()) {
lyxerr << "Executing '" << command << "' in '"
<< buffer->filePath() << '\'' << endl;
}
call.startscript(Forkedcall::DontWait, command);
}
@ -408,7 +569,7 @@ string const
InsetExternalMailer::params2string(InsetExternal::Params const & params)
{
InsetExternal inset;
inset.setFromParams(params);
inset.setParams(params, string());
ostringstream data;
data << name_ << ' ';
inset.write(0, data);

View File

@ -12,32 +12,53 @@
#ifndef INSET_EXTERNAL_H
#define INSET_EXTERNAL_H
#include "insetbutton.h"
#include "inset.h"
#include "ExternalTemplate.h"
#include "graphics/GraphicsTypes.h"
#include "LString.h"
#include <boost/scoped_ptr.hpp>
#include <boost/signals/trackable.hpp>
class GraphicInset;
///
class InsetExternal : public InsetButton {
class InsetExternal : public Inset, public boost::signals::trackable {
public:
/// hold parameters settable from the GUI
struct Params {
Params(string const & f = string(),
string const & p = string(),
ExternalTemplate const & t = ExternalTemplate())
: filename(f), parameters(p), templ(t) {}
// Params(string const & f = string(),
// string const & p = string(),
// ExternalTemplate const & t = ExternalTemplate())
Params() : display(grfx::NoDisplay), lyxscale(100) {}
/// the filename
string filename;
/// the parameters of the current choice
string parameters;
/// the current template used
ExternalTemplate templ;
/// how the inset is displayed by LyX
grfx::DisplayType display;
/// The scale of the displayed graphic (If shown).
unsigned int lyxscale;
};
InsetExternal();
///
InsetExternal(InsetExternal const &);
///
virtual ~InsetExternal();
///
virtual dispatch_result localDispatch(FuncRequest const & cmd);
/** Would not be needed if editExternal were dispatched properly from
* the frontends rather than being invoked directly.
*/
virtual void cache(BufferView *) const;
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
/// what appears in the minibuffer when opening
virtual string const editMessage() const;
///
@ -76,46 +97,50 @@ public:
// The following public members are used from the frontends code
/// set the parameters from a Params structure
virtual void setFromParams(Params const &);
/// Set the inset parameters.
virtual void setParams(Params const &, string const & filepath);
///
void updateExternal() const;
/// update the file represented by the template
void updateExternal(string const &, Buffer const *) const;
/** update the file represented by the template.
If \param external_in_tmpdir == true, then the generated file is
place in the buffer's temporary directory.
*/
void updateExternal(string const &, Buffer const *,
bool external_in_tmpdir) const;
/// edit file of this template
void editExternal() const;
/// view file of this template
void viewExternal() const;
/// return a copy of our current params
Params const & params() const;
///
void setView(BufferView * bv) { view_ = bv; }
private:
/// Write the output for a specific file format
int write(string const & format, Buffer const *,
std::ostream &) const;
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
void statusChanged();
/// Execute this command in the directory of this document
void executeCommand(string const & s, Buffer const * buf) const;
/** Write the output for a specific file format
and generate any external data files.
If \param external_in_tmpdir == true, then the generated file is
place in the buffer's temporary directory.
*/
int write(string const & format, Buffer const *, std::ostream &,
bool external_in_tmpdir = false) const;
/// Substitute meta-variables in this string
string const doSubstitution(Buffer const *, string const & s) const;
/// our owning view
BufferView * view_;
/// the current params
Params params_;
/// A temp filename
string tempname_;
mutable string tempname_;
/// The thing that actually draws the image on LyX's screen.
boost::scoped_ptr<GraphicInset> const graphic_;
};