Select Home tab when it's not selected in HomeCommand

This commit is contained in:
blackmiaool 2015-05-04 10:33:33 +08:00
parent 9bf11e0b40
commit b2257752b3
3 changed files with 24 additions and 3 deletions

View File

@ -23,7 +23,8 @@ public:
~HomeCommand();
protected:
void onExecute(Context* context);
void onExecute(Context* context) override;
bool onEnabled(Context* context) override;
};
HomeCommand::HomeCommand()
@ -42,6 +43,11 @@ void HomeCommand::onExecute(Context* context)
App::instance()->getMainWindow()->showHome();
}
bool HomeCommand::onEnabled(Context* context)
{
return !App::instance()->getMainWindow()->isHomeSelected();
}
Command* CommandFactory::createHomeCommand()
{
return new HomeCommand;

View File

@ -163,7 +163,7 @@ void MainWindow::showNotification(INotificationDelegate* del)
m_notifications->getParent()->layout();
}
void MainWindow::showHome()
void MainWindow::showHomeOnOpen()
{
if (!getHomeView()->getParent()) {
TabView* selectedTab = m_tabsBar->getSelectedTab();
@ -178,6 +178,19 @@ void MainWindow::showHome()
}
}
void MainWindow::showHome()
{
if (!getHomeView()->getParent()) {
m_workspace->addView(m_homeView, 0);
}
m_tabsBar->selectTab(m_homeView);
}
bool MainWindow::isHomeSelected()
{
return (m_tabsBar->getSelectedTab() == m_homeView && m_homeView);
}
void MainWindow::showDevConsole()
{
if (!m_devConsoleView)
@ -230,7 +243,7 @@ void MainWindow::showDataRecovery(crash::DataRecovery* dataRecovery)
bool MainWindow::onProcessMessage(ui::Message* msg)
{
if (msg->type() == kOpenMessage)
showHome();
showHomeOnOpen();
return Window::onProcessMessage(msg);
}

View File

@ -67,7 +67,9 @@ namespace app {
void start();
void reloadMenus();
void showNotification(INotificationDelegate* del);
void showHomeOnOpen();
void showHome();
bool isHomeSelected();
void showDevConsole();
Mode getMode() const { return m_mode; }