Merge branch 'staged' into dev

This commit is contained in:
Xiao Yi Fang 2024-08-10 16:15:52 +08:00
commit d017f809d3
5 changed files with 48 additions and 17 deletions

View file

@ -282,20 +282,16 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
bool ignoreDiacritics ) const
{
if ( !dictIDs.isEmpty() ) {
QStringList ids = dictIDs;
std::vector< sptr< Dictionary::Class > > ftsDicts;
std::vector< sptr< Dictionary::Class > > dicts;
// Find dictionaries by ID's
for ( unsigned x = 0; x < dictionaries.size(); x++ ) {
for ( QStringList::Iterator it = ids.begin(); it != ids.end(); ++it ) {
if ( *it == QString::fromStdString( dictionaries[ x ]->getId() ) ) {
ftsDicts.push_back( dictionaries[ x ] );
ids.erase( it );
for ( const auto & dictId : dictIDs ) {
for ( unsigned x = 0; x < dictionaries.size(); x++ ) {
if ( dictId == QString::fromStdString( dictionaries[ x ]->getId() ) ) {
dicts.push_back( dictionaries[ x ] );
break;
}
}
if ( ids.isEmpty() )
break;
}
string header = makeHtmlHeader( word, QString(), true );
@ -303,7 +299,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
return std::make_shared< ArticleRequest >( word,
Instances::Group{ groupId, "" },
contexts,
ftsDicts,
dicts,
header,
-1,
true );

View file

@ -371,8 +371,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( pt == buffer + sizeof( buffer ) ) {
err_fatal( __func__, "too long FNAME field in dzip file \"%s\"\n", filename );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}
}
@ -393,8 +395,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( pt == buffer + sizeof( buffer ) ) {
err_fatal( __func__, "too long COMMENT field in dzip file \"%s\"\n", filename );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}
}
@ -416,8 +420,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
if ( ftell( str ) != header->headerLength + 1 ) {
err_internal( __func__, "File position (%lu) != header length + 1 (%d)\n", ftell( str ), header->headerLength + 1 );
fclose( str );
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
return DZ_ERR_INVALID_FORMAT;
}
@ -435,8 +441,11 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header
/* Compute offsets */
header->offsets = xmalloc( sizeof( header->offsets[ 0 ] ) * header->chunkCount );
if ( header->offsets == 0 ) {
if ( header->chunks )
if ( header->chunks ) {
free( header->chunks );
header->chunks = NULL;
}
fclose( str );
return DZ_ERR_NOMEMORY;
}

View file

@ -2111,10 +2111,18 @@ void ArticleView::highlightFTSResults()
webview->page()->runJavaScript( script );
auto parts = regString.split( " ", Qt::SkipEmptyParts );
if ( !parts.isEmpty() ) {
firstAvailableText = parts[ 0 ];
ftsSearchPanel->show();
if ( parts.isEmpty() ) {
return;
}
//hold the longest word
for ( auto & p : parts ) {
if ( p.size() > firstAvailableText.size() ) {
firstAvailableText = p;
}
}
ftsSearchPanel->show();
}
void ArticleView::setActiveDictIds( const ActiveDictIds & ad )

View file

@ -0,0 +1,17 @@
How to move the default index folder to other places?
## Windows
!!! note
the [`mklink`](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink#related-links) is built-in tool in Windows.
1. Open `cmd` as administrator
2. copy the index folder to another place,take `D:\gd-ng\index_new` for example.
3. Run `mklink /D "C:\Users\USERNAME\Application Data\GoldenDict\index" "D:\gd-ng\index_new"`
4. Run GoldenDict
## Linux
use `ln` to create a link.

View file

@ -46,6 +46,7 @@ nav:
- Wayland: topic_wayland.md
- Debug dictionary JS: howto/how to debug dictionary js.md
- Flatpak/FlatHub: topic_flatpak.md
- Move index folder: topic_move_index_folder.md
- Related tools:
- Anki Integration: topic_anki.md
- OCR Integration: howto/ocr.md