mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
feature: enhance clipboard data processing
when copied text from some applications such as Kindle PC, the copied text will have extra informations added by the application . This option used to strip the added text away
This commit is contained in:
parent
e107350b51
commit
41d05cb27a
24
config.cc
24
config.cc
|
@ -182,14 +182,24 @@ InputPhrase Preferences::sanitizeInputPhrase( QString const & inputPhrase ) cons
|
|||
{
|
||||
InputPhrase result;
|
||||
|
||||
if( limitInputPhraseLength && inputPhrase.size() > inputPhraseLengthLimit )
|
||||
QString _phase = inputPhrase;
|
||||
if( stripClipboard )
|
||||
{
|
||||
auto parts = inputPhrase.split( QChar::LineFeed, Qt::SkipEmptyParts );
|
||||
if( !parts.empty() )
|
||||
{
|
||||
_phase = parts[ 0 ];
|
||||
}
|
||||
}
|
||||
|
||||
if( limitInputPhraseLength && _phase.size() > inputPhraseLengthLimit )
|
||||
{
|
||||
gdDebug( "Ignoring an input phrase %d symbols long. The configured maximum input phrase length is %d symbols.",
|
||||
inputPhrase.size(), inputPhraseLengthLimit );
|
||||
_phase.size(), inputPhraseLengthLimit );
|
||||
return result;
|
||||
}
|
||||
|
||||
const QString withPunct = inputPhrase.simplified();
|
||||
const QString withPunct = _phase.simplified();
|
||||
result.phrase = gd::toQString( Folding::trimWhitespaceOrPunct( gd::toWString( withPunct ) ) );
|
||||
if ( !result.isValid() )
|
||||
return result; // The suffix of an invalid input phrase must be empty.
|
||||
|
@ -267,6 +277,7 @@ Preferences::Preferences():
|
|||
, inputPhraseLengthLimit( 1000 )
|
||||
, maxDictionaryRefsInContextMenu ( 20 )
|
||||
, synonymSearchEnabled( true )
|
||||
, stripClipboard( false )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1005,6 +1016,9 @@ Class load()
|
|||
if ( !preferences.namedItem( "synonymSearchEnabled" ).isNull() )
|
||||
c.preferences.synonymSearchEnabled = ( preferences.namedItem( "synonymSearchEnabled" ).toElement().text() == "1" );
|
||||
|
||||
if ( !preferences.namedItem( "stripClipboard" ).isNull() )
|
||||
c.preferences.stripClipboard = ( preferences.namedItem( "stripClipboard" ).toElement().text() == "1" );
|
||||
|
||||
QDomNode fts = preferences.namedItem( "fullTextSearch" );
|
||||
|
||||
if ( !fts.isNull() )
|
||||
|
@ -1960,6 +1974,10 @@ void save( Class const & c )
|
|||
opt.appendChild( dd.createTextNode( c.preferences.synonymSearchEnabled ? "1" : "0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "stripClipboard" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.stripClipboard ? "1" : "0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
{
|
||||
QDomNode hd = dd.createElement( "fullTextSearch" );
|
||||
preferences.appendChild( hd );
|
||||
|
|
|
@ -372,6 +372,7 @@ struct Preferences
|
|||
unsigned short maxDictionaryRefsInContextMenu;
|
||||
|
||||
bool synonymSearchEnabled;
|
||||
bool stripClipboard;
|
||||
|
||||
QString addonStyle;
|
||||
|
||||
|
|
|
@ -227,6 +227,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
|
||||
ui.synonymSearchEnabled->setChecked( p.synonymSearchEnabled );
|
||||
|
||||
ui.stripClipboard->setChecked( p.stripClipboard );
|
||||
|
||||
ui.maxDictsInContextMenu->setValue( p.maxDictionaryRefsInContextMenu );
|
||||
|
||||
// Different platforms have different keys available
|
||||
|
@ -443,6 +445,7 @@ Config::Preferences Preferences::getPreferences()
|
|||
p.inputPhraseLengthLimit = ui.inputPhraseLengthLimit->value();
|
||||
p.ignoreDiacritics = ui.ignoreDiacritics->isChecked();
|
||||
p.ignorePunctuation = ui.ignorePunctuation->isChecked();
|
||||
p.stripClipboard = ui.stripClipboard->isChecked();
|
||||
|
||||
p.synonymSearchEnabled = ui.synonymSearchEnabled->isChecked();
|
||||
|
||||
|
|
|
@ -1743,6 +1743,13 @@ from Stardict, Babylon and GLS dictionaries</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="stripClipboard">
|
||||
<property name="text">
|
||||
<string>When using clipboard,strip everything after newline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_17">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in a new issue