mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
+ Implement saving and restoring of the last chosen groups.
This commit is contained in:
parent
8e43a81592
commit
abc6d30d7c
|
@ -135,6 +135,9 @@ Class load() throw( exError )
|
||||||
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
|
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.lastMainGroup = root.namedItem( "lastMainGroup" ).toElement().text();
|
||||||
|
c.lastPopupGroup = root.namedItem( "lastPopupGroup" ).toElement().text();
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +234,16 @@ void save( Class const & c ) throw( exError )
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QDomElement opt = dd.createElement( "lastMainGroup" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.lastMainGroup ) );
|
||||||
|
root.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "lastPopupGroup" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.lastPopupGroup ) );
|
||||||
|
root.appendChild( opt );
|
||||||
|
}
|
||||||
|
|
||||||
configFile.write( dd.toByteArray() );
|
configFile.write( dd.toByteArray() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ struct Class
|
||||||
Paths paths;
|
Paths paths;
|
||||||
Groups groups;
|
Groups groups;
|
||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
|
|
||||||
|
QString lastMainGroup; // Last used group in main window
|
||||||
|
QString lastPopupGroup; // Last used group in popup window
|
||||||
};
|
};
|
||||||
|
|
||||||
DEF_EX( exError, "Error with the program's configuration", std::exception )
|
DEF_EX( exError, "Error with the program's configuration", std::exception )
|
||||||
|
|
|
@ -26,3 +26,15 @@ void GroupComboBox::fill( Instances::Groups const & groups )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GroupComboBox::setCurrentGroup( QString const & gr )
|
||||||
|
{
|
||||||
|
for( int x = 0; x < count(); ++x )
|
||||||
|
{
|
||||||
|
if ( itemText( x ) == gr )
|
||||||
|
{
|
||||||
|
setCurrentIndex( x );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ public:
|
||||||
|
|
||||||
/// Fills combo-box with the given groups
|
/// Fills combo-box with the given groups
|
||||||
void fill( Instances::Groups const & );
|
void fill( Instances::Groups const & );
|
||||||
|
|
||||||
|
/// Chooses the given group in the combobox. If there's no such group,
|
||||||
|
/// does nothing.
|
||||||
|
void setCurrentGroup( QString const & );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -81,6 +81,9 @@ MainWindow::MainWindow():
|
||||||
connect( ui.preferences, SIGNAL( activated() ),
|
connect( ui.preferences, SIGNAL( activated() ),
|
||||||
this, SLOT( editPreferences() ) );
|
this, SLOT( editPreferences() ) );
|
||||||
|
|
||||||
|
connect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
||||||
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
||||||
|
|
||||||
connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
|
connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
|
||||||
this, SLOT( translateInputChanged( QString const & ) ) );
|
this, SLOT( translateInputChanged( QString const & ) ) );
|
||||||
|
|
||||||
|
@ -103,6 +106,12 @@ MainWindow::MainWindow():
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
// Save any changes in last chosen groups etc
|
||||||
|
Config::save( cfg );
|
||||||
|
}
|
||||||
|
|
||||||
LoadDictionaries::LoadDictionaries( vector< string > const & allFiles_ ):
|
LoadDictionaries::LoadDictionaries( vector< string > const & allFiles_ ):
|
||||||
allFiles( allFiles_ )
|
allFiles( allFiles_ )
|
||||||
{
|
{
|
||||||
|
@ -295,6 +304,11 @@ void MainWindow::updateGroupList()
|
||||||
|
|
||||||
ui.groupLabel->setText( haveGroups ? tr( "Look up in:" ) : tr( "Look up:" ) );
|
ui.groupLabel->setText( haveGroups ? tr( "Look up in:" ) : tr( "Look up:" ) );
|
||||||
|
|
||||||
|
// currentIndexChanged() signal is very trigger-happy. To avoid triggering
|
||||||
|
// it, we disconnect it while we're clearing and filling back groups.
|
||||||
|
disconnect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
||||||
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
||||||
|
|
||||||
{
|
{
|
||||||
DictLock _;
|
DictLock _;
|
||||||
|
|
||||||
|
@ -305,6 +319,10 @@ void MainWindow::updateGroupList()
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.groupList->fill( groupInstances );
|
ui.groupList->fill( groupInstances );
|
||||||
|
ui.groupList->setCurrentGroup( cfg.lastMainGroup );
|
||||||
|
|
||||||
|
connect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
|
||||||
|
this, SLOT( currentGroupChanged( QString const & ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::makeScanPopup()
|
void MainWindow::makeScanPopup()
|
||||||
|
@ -449,6 +467,15 @@ void MainWindow::editPreferences()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::currentGroupChanged( QString const & gr )
|
||||||
|
{
|
||||||
|
cfg.lastMainGroup = gr;
|
||||||
|
|
||||||
|
// Update word search results
|
||||||
|
|
||||||
|
translateInputChanged( ui.translateLine->text() );
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::translateInputChanged( QString const & newValue )
|
void MainWindow::translateInputChanged( QString const & newValue )
|
||||||
{
|
{
|
||||||
QString req = newValue.trimmed();
|
QString req = newValue.trimmed();
|
||||||
|
@ -500,7 +527,10 @@ void MainWindow::prefixMatchComplete( WordFinderResults r )
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ui.wordList->count() )
|
if ( ui.wordList->count() )
|
||||||
|
{
|
||||||
ui.wordList->scrollToItem( ui.wordList->item( 0 ), QAbstractItemView::PositionAtTop );
|
ui.wordList->scrollToItem( ui.wordList->item( 0 ), QAbstractItemView::PositionAtTop );
|
||||||
|
ui.wordList->setCurrentItem( 0, QItemSelectionModel::Clear );
|
||||||
|
}
|
||||||
|
|
||||||
ui.wordList->setUpdatesEnabled( true );
|
ui.wordList->setUpdatesEnabled( true );
|
||||||
ui.wordList->unsetCursor();
|
ui.wordList->unsetCursor();
|
||||||
|
@ -614,6 +644,12 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason )
|
||||||
{
|
{
|
||||||
if ( !isVisible() )
|
if ( !isVisible() )
|
||||||
show();
|
show();
|
||||||
|
else
|
||||||
|
if ( isMinimized() )
|
||||||
|
{
|
||||||
|
showNormal();
|
||||||
|
activateWindow();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ class MainWindow: public QMainWindow
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MainWindow();
|
MainWindow();
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ private slots:
|
||||||
void editPreferences();
|
void editPreferences();
|
||||||
void indexingDictionary( QString dictionaryName );
|
void indexingDictionary( QString dictionaryName );
|
||||||
|
|
||||||
|
void currentGroupChanged( QString const & );
|
||||||
void translateInputChanged( QString const & );
|
void translateInputChanged( QString const & );
|
||||||
void prefixMatchComplete( WordFinderResults );
|
void prefixMatchComplete( WordFinderResults );
|
||||||
void wordListItemActivated( QListWidgetItem * );
|
void wordListItemActivated( QListWidgetItem * );
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
|
|
||||||
ScanPopup::ScanPopup( QWidget * parent,
|
ScanPopup::ScanPopup( QWidget * parent,
|
||||||
Config::Class const & cfg_,
|
Config::Class & cfg_,
|
||||||
ArticleNetworkAccessManager & articleNetMgr,
|
ArticleNetworkAccessManager & articleNetMgr,
|
||||||
std::vector< sptr< Dictionary::Class > > const & allDictionaries_,
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries_,
|
||||||
Instances::Groups const & groups_ ):
|
Instances::Groups const & groups_ ):
|
||||||
|
@ -33,6 +33,8 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
ui.prefixButton->hide();
|
ui.prefixButton->hide();
|
||||||
|
|
||||||
ui.groupList->fill( groups );
|
ui.groupList->fill( groups );
|
||||||
|
ui.groupList->setCurrentGroup( cfg.lastPopupGroup );
|
||||||
|
|
||||||
setWindowFlags( Qt::Popup );
|
setWindowFlags( Qt::Popup );
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
|
@ -131,10 +133,12 @@ QString ScanPopup::elideInputWord()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScanPopup::currentGroupChanged( QString const & )
|
void ScanPopup::currentGroupChanged( QString const & gr )
|
||||||
{
|
{
|
||||||
if ( isVisible() )
|
if ( isVisible() )
|
||||||
initiateTranslation();
|
initiateTranslation();
|
||||||
|
|
||||||
|
cfg.lastPopupGroup = gr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::initiateTranslation()
|
void ScanPopup::initiateTranslation()
|
||||||
|
|
|
@ -22,14 +22,14 @@ class ScanPopup: public QDialog, KeyboardState
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScanPopup( QWidget * parent,
|
ScanPopup( QWidget * parent,
|
||||||
Config::Class const & cfg,
|
Config::Class & cfg,
|
||||||
ArticleNetworkAccessManager &,
|
ArticleNetworkAccessManager &,
|
||||||
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
||||||
Instances::Groups const & );
|
Instances::Groups const & );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Config::Class const & cfg;
|
Config::Class & cfg;
|
||||||
std::vector< sptr< Dictionary::Class > > const & allDictionaries;
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries;
|
||||||
Instances::Groups const & groups;
|
Instances::Groups const & groups;
|
||||||
Ui::ScanPopup ui;
|
Ui::ScanPopup ui;
|
||||||
|
|
Loading…
Reference in a new issue