Skip to content

Commit

Permalink
Bring Zeal window up on another instance start (fixes #187)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Jan 22, 2015
1 parent fd170cc commit 73e7d91
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Application::Application(const QString &query, QObject *parent) :
// Wait a little while the other side writes the bytes
connection->waitForReadyRead();
if (connection->bytesAvailable())
m_mainWindow->bringToFrontAndSearch(QString::fromLocal8Bit(connection->readAll()));
m_mainWindow->bringToFront(QString::fromLocal8Bit(connection->readAll()));
else
m_mainWindow->bringToFront();
});
/// TODO: Verify if removeServer() is needed
QLocalServer::removeServer(LocalServerName); // remove in case previous instance crashed
Expand All @@ -55,7 +57,7 @@ Application::Application(const QString &query, QObject *parent) :
applySettings();

if (!query.isEmpty())
m_mainWindow->bringToFrontAndSearch(query);
m_mainWindow->bringToFront(query);
else if (!m_settings->startMinimized)
m_mainWindow->show();
}
Expand Down
9 changes: 2 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,8 @@ int main(int argc, char *argv[])
socket->connectToServer(Zeal::Core::Application::localServerName());

if (socket->waitForConnected(500)) {
if (!clParams.query.isEmpty()) {
socket->write(clParams.query.toLocal8Bit());
socket->flush();
} else {
QTextStream(stdout) << QObject::tr("Already running. Terminating.") << endl;
}

socket->write(clParams.query.toLocal8Bit());
socket->flush();
return 0;
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,22 +619,20 @@ void MainWindow::createTrayIcon()
#endif
}

void MainWindow::bringToFront()
void MainWindow::bringToFront(const QString &query)
{
show();
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
raise();
activateWindow();
ui->lineEdit->setFocus();
}

void MainWindow::bringToFrontAndSearch(const QString &query)
{
bringToFront();
m_searchState->zealSearch.setQuery(query);
ui->lineEdit->setText(query);
ui->treeView->setFocus();
ui->treeView->activated(ui->treeView->currentIndex());
if (!query.isEmpty()) {
m_searchState->zealSearch.setQuery(query);
ui->lineEdit->setText(query);
ui->treeView->setFocus();
ui->treeView->activated(ui->treeView->currentIndex());
}
}

void MainWindow::closeEvent(QCloseEvent *event)
Expand Down
3 changes: 1 addition & 2 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MainWindow : public QMainWindow
explicit MainWindow(Zeal::Core::Application *app, QWidget *parent = 0);
~MainWindow();

void bringToFrontAndSearch(const QString &query);
void bringToFront(const QString &query = QString());
void createTab();

protected:
Expand All @@ -97,7 +97,6 @@ private slots:
void applyWebPageStyle();

private:
void bringToFront();
void displayViewActions();
void loadSections(const QString &docsetName, const QUrl &url);
void setupSearchBoxCompletions();
Expand Down

0 comments on commit 73e7d91

Please sign in to comment.