ui: recent projects menu fix
recent projects updates now when a projects is loaded
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
QtMainView::QtMainView()
|
||||
: m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
|
||||
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
|
||||
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
|
||||
{
|
||||
m_window = std::make_shared<QtMainWindow>();
|
||||
m_window->show();
|
||||
@@ -80,6 +81,16 @@ void QtMainView::activateWindow()
|
||||
m_activateWindowFunctor();
|
||||
}
|
||||
|
||||
void QtMainView::updateRecentProjectMenu()
|
||||
{
|
||||
m_updateRecentProjectMenuFunctor();
|
||||
}
|
||||
|
||||
void QtMainView::doUpdateRecentProjectMenu()
|
||||
{
|
||||
m_window->updateRecentProjectMenu();
|
||||
}
|
||||
|
||||
void QtMainView::doSetTitle(const std::string& title)
|
||||
{
|
||||
m_window->setWindowTitle(QString::fromStdString(title));
|
||||
|
||||
@@ -36,16 +36,19 @@ public:
|
||||
virtual void hideStartScreen();
|
||||
virtual void setTitle(const std::string& title);
|
||||
virtual void activateWindow();
|
||||
virtual void updateRecentProjectMenu();
|
||||
|
||||
private:
|
||||
void doSetTitle(const std::string& title);
|
||||
void doActivateWindow();
|
||||
void doUpdateRecentProjectMenu();
|
||||
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
|
||||
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
|
||||
QtThreadedFunctor<> m_activateWindowFunctor;
|
||||
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_VIEW_H
|
||||
|
||||
@@ -89,6 +89,10 @@ void QtMainWindow::init()
|
||||
|
||||
QtMainWindow::~QtMainWindow()
|
||||
{
|
||||
if(m_recentProjectAction)
|
||||
{
|
||||
delete [] m_recentProjectAction;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::addView(View* view)
|
||||
@@ -431,7 +435,7 @@ void QtMainWindow::setupProjectMenu()
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
QMenu *recentProjectMenu = new QMenu(tr("Recent Project"));
|
||||
QMenu *recentProjectMenu = new QMenu(tr("Recent Projects"));
|
||||
menu->addMenu(recentProjectMenu);
|
||||
|
||||
for (int i = 0; i < ApplicationSettings::MaximalAmountOfRecentProjects; ++i)
|
||||
@@ -466,19 +470,12 @@ void QtMainWindow::updateRecentProjectMenu()
|
||||
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
|
||||
for (size_t i = 0; i < ApplicationSettings::MaximalAmountOfRecentProjects; i++)
|
||||
{
|
||||
if(i < recentProjects.size()-1)
|
||||
if(i < recentProjects.size())
|
||||
{
|
||||
FilePath project = recentProjects[i];
|
||||
m_recentProjectAction[i]->setVisible(true);
|
||||
if (project.exists())
|
||||
{
|
||||
m_recentProjectAction[i]->setText(FileSystem::fileName(project.str()).c_str());
|
||||
m_recentProjectAction[i]->setData(project.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_recentProjectAction[i]->setDisabled(true);
|
||||
}
|
||||
m_recentProjectAction[i]->setText(FileSystem::fileName(project.str()).c_str());
|
||||
m_recentProjectAction[i]->setData(project.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -87,6 +87,7 @@ public slots:
|
||||
void toggleView(View* view, bool fromMenu);
|
||||
|
||||
void handleEscapeShortcut();
|
||||
void updateRecentProjectMenu();
|
||||
|
||||
private:
|
||||
struct DockWidget
|
||||
@@ -100,7 +101,6 @@ private:
|
||||
|
||||
void setupEditMenu();
|
||||
void setupProjectMenu();
|
||||
void updateRecentProjectMenu();
|
||||
void setupViewMenu();
|
||||
void setupHelpMenu();
|
||||
|
||||
|
||||
@@ -60,22 +60,19 @@ void QtStartScreen::setup()
|
||||
int position = 290;
|
||||
QIcon cpp_icon("data/gui/startscreen/icon_cpp.png");
|
||||
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
|
||||
for (size_t i = 0; i < recentProjects.size() && i < ApplicationSettings::MaximalAmountOfRecentProjects; i++)
|
||||
for (int i = 0; i < recentProjects.size() && i < ApplicationSettings::MaximalAmountOfRecentProjects; i++)
|
||||
{
|
||||
FilePath project = recentProjects[i];
|
||||
if (project.exists())
|
||||
{
|
||||
QtRecentProjectButton* button = new QtRecentProjectButton(project.str().c_str(), this);
|
||||
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
button->setIcon(cpp_icon);
|
||||
button->setIconSize(QSize(25, 25));
|
||||
button->setObjectName("recentButton");
|
||||
button->minimumSizeHint(); // force font loading
|
||||
button->setGeometry(292, position, button->fontMetrics().width(button->text()) + 45, 40);
|
||||
connect(button, SIGNAL(clicked()), button, SLOT(handleButtonClick()));
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(handleRecentButton()));
|
||||
position += 40;
|
||||
}
|
||||
QtRecentProjectButton* button = new QtRecentProjectButton(project.str().c_str(), this);
|
||||
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
button->setIcon(cpp_icon);
|
||||
button->setIconSize(QSize(25, 25));
|
||||
button->setObjectName("recentButton");
|
||||
button->minimumSizeHint(); // force font loading
|
||||
button->setGeometry(292, position, button->fontMetrics().width(button->text()) + 45, 40);
|
||||
connect(button, SIGNAL(clicked()), button, SLOT(handleButtonClick()));
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(handleRecentButton()));
|
||||
position += 40;
|
||||
}
|
||||
|
||||
resize(600, 600);
|
||||
|
||||
@@ -87,6 +87,8 @@ void Application::loadProject(const FilePath& projectSettingsFilePath)
|
||||
m_project = Project::create(m_storageCache.get());
|
||||
m_project->loadProjectSettings(projectSettingsFilePath);
|
||||
m_project->loadStorage();
|
||||
|
||||
m_mainView->updateRecentProjectMenu();
|
||||
}
|
||||
|
||||
void Application::refreshProject()
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
virtual void hideStartScreen() = 0;
|
||||
virtual void setTitle(const std::string& title) = 0;
|
||||
virtual void activateWindow() = 0;
|
||||
virtual void updateRecentProjectMenu() = 0;
|
||||
};
|
||||
|
||||
#endif // MAIN_VIEW_H
|
||||
|
||||
@@ -113,7 +113,16 @@ ApplicationSettings::ApplicationSettings()
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getRecentProjects() const
|
||||
{
|
||||
return getPathValues("user/recent_projects/recent_project");
|
||||
std::vector<FilePath> recentProjects = getPathValues("user/recent_projects/recent_project");
|
||||
std::vector<FilePath>::iterator iter = recentProjects.end();
|
||||
for( ; iter != recentProjects.begin(); iter--)
|
||||
{
|
||||
if(!(*iter).exists())
|
||||
{
|
||||
recentProjects.erase(iter);
|
||||
}
|
||||
}
|
||||
return recentProjects;
|
||||
}
|
||||
|
||||
bool ApplicationSettings::setRecentProjects(const std::vector<FilePath> &recentProjects)
|
||||
|
||||
Reference in New Issue
Block a user