diff --git a/src/config.cc b/src/config.cc
index 04203383..dff78894 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -41,6 +41,8 @@ ProxyServer::ProxyServer(): enabled( false ), type( Socks5 ), port( 3128 )
}
Preferences::Preferences():
+ newTabsOpenAfterCurrentOne( false ),
+ newTabsOpenInBackground( true ),
enableTrayIcon( true ),
startToTray( false ),
closeToTray( true ),
@@ -243,6 +245,8 @@ Class load() throw( exError )
if ( !preferences.isNull() )
{
c.preferences.interfaceLanguage = preferences.namedItem( "interfaceLanguage" ).toElement().text();
+ c.preferences.newTabsOpenAfterCurrentOne = ( preferences.namedItem( "newTabsOpenAfterCurrentOne" ).toElement().text() == "1" );
+ c.preferences.newTabsOpenInBackground = ( preferences.namedItem( "newTabsOpenInBackground" ).toElement().text() == "1" );
c.preferences.enableTrayIcon = ( preferences.namedItem( "enableTrayIcon" ).toElement().text() == "1" );
c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" );
c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).toElement().text() == "1" );
@@ -455,6 +459,14 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( c.preferences.interfaceLanguage ) );
preferences.appendChild( opt );
+ opt = dd.createElement( "newTabsOpenAfterCurrentOne" );
+ opt.appendChild( dd.createTextNode( c.preferences.newTabsOpenAfterCurrentOne ? "1":"0" ) );
+ preferences.appendChild( opt );
+
+ opt = dd.createElement( "newTabsOpenInBackground" );
+ opt.appendChild( dd.createTextNode( c.preferences.newTabsOpenInBackground ? "1":"0" ) );
+ preferences.appendChild( opt );
+
opt = dd.createElement( "enableTrayIcon" );
opt.appendChild( dd.createTextNode( c.preferences.enableTrayIcon ? "1":"0" ) );
preferences.appendChild( opt );
diff --git a/src/config.hh b/src/config.hh
index 1dc5488e..3e17ca2e 100644
--- a/src/config.hh
+++ b/src/config.hh
@@ -99,6 +99,8 @@ struct ProxyServer
struct Preferences
{
QString interfaceLanguage; // Empty value corresponds to system default
+ bool newTabsOpenAfterCurrentOne;
+ bool newTabsOpenInBackground;
bool enableTrayIcon;
bool startToTray;
bool closeToTray;
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index e60a9f31..dee3159d 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -579,6 +579,12 @@ void MainWindow::indexingDictionary( QString dictionaryName )
}
void MainWindow::addNewTab()
+{
+ createNewTab( true, tr( "(untitled)" ) );
+}
+
+ArticleView * MainWindow::createNewTab( bool switchToIt,
+ QString const & name )
{
ArticleView * view = new ArticleView( this, articleNetMgr, dictionaries,
groupInstances, false, cfg );
@@ -593,15 +599,25 @@ void MainWindow::addNewTab()
connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const & ) ),
this, SLOT( openLinkInNewTab( QUrl const &, QUrl const & ) ) );
-
+
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned ) ),
this, SLOT( showDefinitionInNewTab( QString const &, unsigned ) ) );
-
- ui.tabWidget->addTab( view, tr( "(untitled)" ) );
- ui.tabWidget->setCurrentIndex( ui.tabWidget->count() - 1 );
+ int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
+ ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
+
+ QString escaped = name;
+ escaped.replace( "&", "&&" );
+
+ ui.tabWidget->insertTab( index, view, escaped );
+
+ if ( switchToIt )
+ ui.tabWidget->setCurrentIndex( index );
+
+ return view;
}
+
void MainWindow::tabCloseRequested( int x )
{
if ( ui.tabWidget->count() < 2 )
@@ -957,23 +973,13 @@ void MainWindow::wordListSelectionChanged()
void MainWindow::openLinkInNewTab( QUrl const & url,
QUrl const & referrer )
{
- addNewTab();
-
- ArticleView & view =
- dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
-
- view.openLink( url, referrer );
+ createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->openLink( url, referrer );
}
void MainWindow::showDefinitionInNewTab( QString const & word,
unsigned group )
{
- addNewTab();
-
- ArticleView & view =
- dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) );
-
- view.showDefinition( word, group );
+ createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->showDefinition( word, group );
}
void MainWindow::showTranslationFor( QString const & inWord )
diff --git a/src/mainwindow.hh b/src/mainwindow.hh
index 82429269..8121a4e1 100644
--- a/src/mainwindow.hh
+++ b/src/mainwindow.hh
@@ -164,6 +164,10 @@ private slots:
void wordListItemActivated( QListWidgetItem * );
void wordListSelectionChanged();
+ /// Creates a new tab, which is to be populated then with some content.
+ ArticleView * createNewTab( bool switchToIt,
+ QString const & name );
+
void openLinkInNewTab( QUrl const &, QUrl const & );
void showDefinitionInNewTab( QString const & word, unsigned group );
diff --git a/src/preferences.cc b/src/preferences.cc
index bd8e0677..7fa5953e 100644
--- a/src/preferences.cc
+++ b/src/preferences.cc
@@ -47,6 +47,8 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
break;
}
+ ui.newTabsOpenAfterCurrentOne->setChecked( p.newTabsOpenAfterCurrentOne );
+ ui.newTabsOpenInBackground->setChecked( p.newTabsOpenInBackground );
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
ui.startToTray->setChecked( p.startToTray );
ui.closeToTray->setChecked( p.closeToTray );
@@ -119,6 +121,8 @@ Config::Preferences Preferences::getPreferences()
ui.interfaceLanguage->itemData(
ui.interfaceLanguage->currentIndex() ).toString();
+ p.newTabsOpenAfterCurrentOne = ui.newTabsOpenAfterCurrentOne->isChecked();
+ p.newTabsOpenInBackground = ui.newTabsOpenInBackground->isChecked();
p.enableTrayIcon = ui.enableTrayIcon->isChecked();
p.startToTray = ui.startToTray->isChecked();
p.closeToTray = ui.closeToTray->isChecked();
diff --git a/src/preferences.ui b/src/preferences.ui
index 41ad17aa..03b2ef86 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -40,6 +40,39 @@
+ -
+
+
+ Tabbed browsing
+
+
+
-
+
+
+ Normally, opening a new tab switches to it immediately.
+With this on however, new tabs will be opened without
+switching to them.
+
+
+ Open new tabs in background
+
+
+
+ -
+
+
+ With this on, new tabs are opened just after the
+current, active one. Otherwise they are added to
+be the last ones.
+
+
+ Open new tabs after the current one
+
+
+
+
+
+
-