Forums » Using AMC (english) »
Adding a viewer preference to a new Export plugin
Added by Matthew Leingang almost 6 years ago
I am working on a plugin that creates an Item Analysis report as a LaTeX file. I think eventually I will add a PDF version that will compile and open the resulting PDF file. But I want to leave open the option that the user might want to edit the LaTeX file before compiling on their own.
The trouble I'm having is that in the Export panel in the AMC GUI, I have "open the file" selected as the after export action, but nothing happens after exporting to LaTeX.
Digging into AMC-gui.pl
, I think the issue is centered around this block:
if($config->get('after_export') eq 'file') { commande_parallele($config->get($type.'_viewer'),$output) if($config->get($type.'_viewer')); } elsif($config->get('after_export') eq 'dir') { view_dir($shortcuts->absolu('%PROJET/exports/')); }
I assume that $type
is tex
, although I haven't confirmed that. If so, this code looks for a preference tex_viewer
, and since one doesn't exist, stops. But there is a preference related to LaTeX; it's tex_editor
. I'd love to harness that preference in this setting.
Is it possible to set a preference tex_viewer
equal to tex_editor
, perhaps in the options_from_config
subroutine of the AMC::Export::register
child class? I've been reading through AMC::Config.pm
and can't quite grok how to do that.
Replies (2)
RE: Adding a viewer preference to a new Export plugin - Added by Alexis Bienvenüe almost 6 years ago
I assume that $type is tex
You're right. $type
is the value returned by the type
method from the AMC::Export::register::yourpluginname
class.
If not defined here, the default method is used (see https://gitlab.com/jojo_boulix/auto-multiple-choice/blob/1.4.0-rc2/AMC-perl/AMC/Export/register.pm#L37), that tries to guess the correct value from the extension
method call, removing anything until the last dot in the extension
string.
For ItemAnalysis_LaTeX
, that should end with tex
(from https://github.com/leingang/AMC-ItemAnalysis/blob/v0.3/lib/AMC/Export/register/ItemAnalysis_LaTeX.pm#L40).
Is it possible to set a preference tex_viewer equal to tex_editor
Maybe we can use
$config->get($type.'_viewer') || $config->get($type.'_editor')
in AMC-gui.pl
.
RE: Adding a viewer preference to a new Export plugin - Added by Matthew Leingang almost 6 years ago
Thanks for confirming the first question. Yes, changing that one line of AMC-gui.pl
would take care of it.
I'm still wondering if there's a way to set it on the plugin level. I kept poking around, and I noticed that AMC-gui.pl
calls the options_default
subroutine when export plugins are registered, and options_from_config
when the export command is built and executed. So options_default
seems like the place to set it. But while options_from_config
gets a config reference passed to it, options_default
doesn't.
(1-2/2)