mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
give external programs access to translateLine via %GDSEARCH% (#417)
* give external programs access to translateLine via %GDSEARCH% * remove code smell * reformat with clang-format * update translations * don't write to stdin of an external program if GDSEARCH is set * update ui docs
This commit is contained in:
parent
75593e4487
commit
7fc2d64cd8
|
@ -26,6 +26,7 @@ public:
|
|||
bool existedInWhitelist(QString host);
|
||||
static GlobalBroadcaster * instance();
|
||||
unsigned currentGroupId;
|
||||
QString translateLineText{};
|
||||
|
||||
signals:
|
||||
void dictionaryChanges( ActiveDictIds ad );
|
||||
|
|
|
@ -4738,8 +4738,8 @@ of the appropriate groups to use them.</source>
|
|||
</message>
|
||||
<message>
|
||||
<location filename="../sources.ui" line="409"/>
|
||||
<source>Any external programs. A string %GDWORD% will be replaced with the query word. If such string is not presented, the word will be fed into standard input.</source>
|
||||
<translation>Любые внешние программы. Строка %GDWORD% будет заменена на запрашиваемое слово. Если такой строки нет, слово будет отправлено в стандартный входной поток.</translation>
|
||||
<source>Any external programs. A string %GDWORD% will be replaced with the query word. A string %GDSEARCH% will be replaced with the text in the search bar. If both of the parameters are not provided, the headword will be fed into standard input.</source>
|
||||
<translation>Любые внешние программы. Строка %GDWORD% будет заменена на запрашиваемое слово. Строка %GDSEARCH% будет заменена на текст в поисковой строке. Если обоих строк нет задано, запрашиваемое слово будет отправлено в стандартный входной поток внешней программы.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../sources.ui" line="462"/>
|
||||
|
|
|
@ -2342,6 +2342,8 @@ void MainWindow::translateInputChanged( QString const & newValue )
|
|||
{
|
||||
updateSuggestionList( newValue );
|
||||
translateBoxSuffix = QString();
|
||||
// Save translate line text. Later it can be passed to external applications.
|
||||
GlobalBroadcaster::instance()->translateLineText = newValue;
|
||||
}
|
||||
|
||||
void MainWindow::updateSuggestionList()
|
||||
|
|
14
programs.cc
14
programs.cc
|
@ -9,6 +9,7 @@
|
|||
#include "parsecmdline.hh"
|
||||
#include "iconv.hh"
|
||||
#include "utils.hh"
|
||||
#include "globalbroadcaster.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
@ -154,13 +155,18 @@ bool RunInstance::start( Config::Program const & prg, QString const & word,
|
|||
args.pop_front();
|
||||
|
||||
bool writeToStdInput = true;
|
||||
auto const & search_string = GlobalBroadcaster::instance()->translateLineText;
|
||||
|
||||
for( int x = 0; x < args.size(); ++x )
|
||||
if( args[ x ].indexOf( "%GDWORD%" ) >= 0 )
|
||||
{
|
||||
for( auto & arg : args ) {
|
||||
if( arg.indexOf( "%GDWORD%" ) >= 0 ) {
|
||||
writeToStdInput = false;
|
||||
args[ x ].replace( "%GDWORD%", word );
|
||||
arg.replace( "%GDWORD%", word );
|
||||
}
|
||||
if( arg.indexOf( "%GDSEARCH%" ) >= 0 ) {
|
||||
writeToStdInput = false;
|
||||
arg.replace( "%GDSEARCH%", search_string );
|
||||
}
|
||||
}
|
||||
|
||||
process.start( programName, args );
|
||||
if( writeToStdInput )
|
||||
|
|
|
@ -409,7 +409,7 @@ of the appropriate groups to use them.</string>
|
|||
<item>
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="text">
|
||||
<string>Any external programs. A string %GDWORD% will be replaced with the query word. If such string is not presented, the word will be fed into standard input.</string>
|
||||
<string>Any external programs. A string %GDWORD% will be replaced with the query word. A string %GDSEARCH% will be replaced with the text in the search bar. If both of the parameters are not provided, the headword will be fed into standard input.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
|
|
Loading…
Reference in a new issue