mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Call external editor for dictionaries
This commit is contained in:
parent
3616665f1f
commit
e6457a1e27
|
@ -740,6 +740,9 @@ Class load() throw( exError )
|
|||
if ( !root.namedItem( "historyExportPath" ).isNull() )
|
||||
c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text();
|
||||
|
||||
if ( !root.namedItem( "editDictionaryCommandLine" ).isNull() )
|
||||
c.editDictionaryCommandLine = root.namedItem( "editDictionaryCommandLine" ).toElement().text();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -1360,6 +1363,11 @@ void save( Class const & c ) throw( exError )
|
|||
opt.appendChild( dd.createTextNode( c.historyExportPath ) );
|
||||
root.appendChild( opt );
|
||||
}
|
||||
|
||||
opt = dd.createElement( "editDictionaryCommandLine" );
|
||||
opt.appendChild( dd.createTextNode( c.editDictionaryCommandLine ) );
|
||||
root.appendChild( opt );
|
||||
|
||||
}
|
||||
|
||||
QByteArray result( dd.toByteArray() );
|
||||
|
|
|
@ -400,6 +400,8 @@ struct Class
|
|||
|
||||
unsigned short maxDictionaryRefsInContextMenu;
|
||||
|
||||
QString editDictionaryCommandLine; // Command line to call external editor for dictionary
|
||||
|
||||
Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
|
||||
pinPopupWindow( false ), showingDictBarNames( false ),
|
||||
usingSmallIconsInToolbars( false ), maxDictionaryRefsInContextMenu( 20 )
|
||||
|
|
|
@ -3,15 +3,18 @@
|
|||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QProcess>
|
||||
#include "dprintf.hh"
|
||||
#include "fsencoding.hh"
|
||||
|
||||
using std::vector;
|
||||
|
||||
DictionaryBar::DictionaryBar( QWidget * parent,
|
||||
Config::Events & events ):
|
||||
Config::Events & events, QString const & _editDictionaryCommand ):
|
||||
QToolBar( tr( "Dictionary Bar" ), parent ),
|
||||
mutedDictionaries( 0 ),
|
||||
configEvents( events ),
|
||||
editDictionaryCommand( _editDictionaryCommand ),
|
||||
use14x21( false )
|
||||
{
|
||||
setObjectName( "dictionaryBar" );
|
||||
|
@ -42,6 +45,9 @@ void DictionaryBar::setDictionaries( vector< sptr< Dictionary::Class > >
|
|||
{
|
||||
setUpdatesEnabled( false );
|
||||
|
||||
allDictionaries.clear();
|
||||
allDictionaries = dictionaries;
|
||||
|
||||
clear();
|
||||
dictActions.clear();
|
||||
|
||||
|
@ -98,6 +104,10 @@ void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
|
|||
if( dictAction )
|
||||
infoAction = menu.addAction( tr( "Dictionary info" ) );
|
||||
|
||||
QAction * editDictAction = NULL;
|
||||
if( !editDictionaryCommand.isEmpty() )
|
||||
editDictAction = menu.addAction( tr( "Edit dictionary" ) );
|
||||
|
||||
if ( !dictActions.empty() )
|
||||
menu.addSeparator();
|
||||
|
||||
|
@ -126,6 +136,29 @@ void DictionaryBar::contextMenuEvent( QContextMenuEvent * event )
|
|||
return;
|
||||
}
|
||||
|
||||
if( result && result == editDictAction )
|
||||
{
|
||||
QString id = dictAction->data().toString();
|
||||
for( unsigned i = 0; i < allDictionaries.size(); i++ )
|
||||
{
|
||||
if( id.compare( allDictionaries[ i ]->getId().c_str() ) == 0 )
|
||||
{
|
||||
QString command( editDictionaryCommand );
|
||||
QString dictName = FsEncoding::decode( allDictionaries[ i ]->getDictionaryFilenames().at( 0 ).c_str() );
|
||||
|
||||
if( dictName.endsWith( ".ifo" ) ) // Stardict dictionary
|
||||
dictName = FsEncoding::decode( allDictionaries[ i ]->getDictionaryFilenames().at( 2 ).c_str() );
|
||||
|
||||
command.replace( "%GDDICT%", "\"" + dictName + "\"" );
|
||||
|
||||
if( !QProcess::startDetached( command ) )
|
||||
QApplication::beep();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( result == editAction )
|
||||
emit editGroupRequested();
|
||||
else
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QToolBar>
|
||||
#include <QSize>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include "dictionary.hh"
|
||||
#include "config.hh"
|
||||
|
||||
|
@ -17,7 +18,7 @@ public:
|
|||
|
||||
/// Constructs an empty dictionary bar
|
||||
DictionaryBar( QWidget * parent,
|
||||
Config::Events & );
|
||||
Config::Events &, QString const & _editDictionaryCommand );
|
||||
|
||||
/// Sets dictionaries to be displayed in the bar. Their statuses (enabled/
|
||||
/// disabled) are taken from the configuration data.
|
||||
|
@ -45,7 +46,8 @@ private:
|
|||
Config::MutedDictionaries * mutedDictionaries;
|
||||
Config::Events & configEvents;
|
||||
Config::MutedDictionaries storedMutedSet;
|
||||
|
||||
QString editDictionaryCommand;
|
||||
std::vector< sptr< Dictionary::Class > > allDictionaries;
|
||||
/// All the actions we have added to the toolbar
|
||||
QList< QAction * > dictActions;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include "dictinfo.hh"
|
||||
#include "fsencoding.hh"
|
||||
#include <QProcess>
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include "lionsupport.h"
|
||||
|
@ -61,7 +63,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
addTab( this ),
|
||||
cfg( cfg_ ),
|
||||
history( History::Load(), cfg_.preferences.maxStringsInHistory ),
|
||||
dictionaryBar( this, configEvents ),
|
||||
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ),
|
||||
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle ),
|
||||
articleNetMgr( this, dictionaries, articleMaker,
|
||||
cfg.preferences.disallowContentFromOtherSites ),
|
||||
|
@ -3048,10 +3050,50 @@ void MainWindow::foundDictsContextMenuRequested( const QPoint &pos )
|
|||
QListWidgetItem *item = ui.dictsList->itemAt( pos );
|
||||
if( item )
|
||||
{
|
||||
scanPopup.get()->blockSignals( true );
|
||||
QString id = item->data( Qt::UserRole ).toString();
|
||||
showDictionaryInfo( id );
|
||||
scanPopup.get()->blockSignals( false );
|
||||
if( cfg.editDictionaryCommandLine.isEmpty() )
|
||||
{
|
||||
scanPopup.get()->blockSignals( true );
|
||||
showDictionaryInfo( id );
|
||||
scanPopup.get()->blockSignals( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
QMenu menu( ui.dictsList );
|
||||
QAction * infoAction = menu.addAction( tr( "Dictionary info" ) );
|
||||
QAction * editAction = menu.addAction( tr( "Edit dictionary" ) );
|
||||
|
||||
QAction * result = menu.exec( ui.dictsList->mapToGlobal( pos ) );
|
||||
|
||||
if( result && result == infoAction )
|
||||
{
|
||||
scanPopup.get()->blockSignals( true );
|
||||
showDictionaryInfo( id );
|
||||
scanPopup.get()->blockSignals( false );
|
||||
}
|
||||
else
|
||||
if( result && result == editAction )
|
||||
{
|
||||
for( unsigned i = 0; i < dictionaries.size(); i++ )
|
||||
{
|
||||
if( id.compare( dictionaries[ i ]->getId().c_str() ) == 0 )
|
||||
{
|
||||
QString command( cfg.editDictionaryCommandLine );
|
||||
QString dictName = FsEncoding::decode( dictionaries[ i ]->getDictionaryFilenames().at( 0 ).c_str() );
|
||||
|
||||
if( dictName.endsWith( ".ifo" ) ) // Stardict dictionary
|
||||
dictName = FsEncoding::decode( dictionaries[ i ]->getDictionaryFilenames().at( 2 ).c_str() );
|
||||
|
||||
command.replace( "%GDDICT%", "\"" + dictName + "\"" );
|
||||
|
||||
if( !QProcess::startDetached( command ) )
|
||||
QApplication::beep();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
escapeAction( this ),
|
||||
switchExpandModeAction( this ),
|
||||
wordFinder( this ),
|
||||
dictionaryBar( this, configEvents ),
|
||||
dictionaryBar( this, configEvents, cfg.editDictionaryCommandLine ),
|
||||
mouseEnteredOnce( false ),
|
||||
mouseIntercepted( false ),
|
||||
hideTimer( this )
|
||||
|
|
Loading…
Reference in a new issue