mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +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);
|
bool existedInWhitelist(QString host);
|
||||||
static GlobalBroadcaster * instance();
|
static GlobalBroadcaster * instance();
|
||||||
unsigned currentGroupId;
|
unsigned currentGroupId;
|
||||||
|
QString translateLineText{};
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dictionaryChanges( ActiveDictIds ad );
|
void dictionaryChanges( ActiveDictIds ad );
|
||||||
|
|
|
@ -4738,8 +4738,8 @@ of the appropriate groups to use them.</source>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../sources.ui" line="409"/>
|
<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>
|
<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% будет заменена на запрашиваемое слово. Если такой строки нет, слово будет отправлено в стандартный входной поток.</translation>
|
<translation>Любые внешние программы. Строка %GDWORD% будет заменена на запрашиваемое слово. Строка %GDSEARCH% будет заменена на текст в поисковой строке. Если обоих строк нет задано, запрашиваемое слово будет отправлено в стандартный входной поток внешней программы.</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../sources.ui" line="462"/>
|
<location filename="../sources.ui" line="462"/>
|
||||||
|
|
|
@ -2342,6 +2342,8 @@ void MainWindow::translateInputChanged( QString const & newValue )
|
||||||
{
|
{
|
||||||
updateSuggestionList( newValue );
|
updateSuggestionList( newValue );
|
||||||
translateBoxSuffix = QString();
|
translateBoxSuffix = QString();
|
||||||
|
// Save translate line text. Later it can be passed to external applications.
|
||||||
|
GlobalBroadcaster::instance()->translateLineText = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateSuggestionList()
|
void MainWindow::updateSuggestionList()
|
||||||
|
|
14
programs.cc
14
programs.cc
|
@ -9,6 +9,7 @@
|
||||||
#include "parsecmdline.hh"
|
#include "parsecmdline.hh"
|
||||||
#include "iconv.hh"
|
#include "iconv.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
#include "globalbroadcaster.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
@ -154,12 +155,17 @@ bool RunInstance::start( Config::Program const & prg, QString const & word,
|
||||||
args.pop_front();
|
args.pop_front();
|
||||||
|
|
||||||
bool writeToStdInput = true;
|
bool writeToStdInput = true;
|
||||||
|
auto const & search_string = GlobalBroadcaster::instance()->translateLineText;
|
||||||
|
|
||||||
for( int x = 0; x < args.size(); ++x )
|
for( auto & arg : args ) {
|
||||||
if( args[ x ].indexOf( "%GDWORD%" ) >= 0 )
|
if( arg.indexOf( "%GDWORD%" ) >= 0 ) {
|
||||||
{
|
|
||||||
writeToStdInput = false;
|
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 );
|
process.start( programName, args );
|
||||||
|
|
|
@ -409,7 +409,7 @@ of the appropriate groups to use them.</string>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_16">
|
<widget class="QLabel" name="label_16">
|
||||||
<property name="text">
|
<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>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
Loading…
Reference in a new issue