Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing recent file menu issue #1278 and #1279 #1281

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ void MainWindow2::readSettings()
restoreState(winState.toByteArray());

QString myPath = settings.value(LAST_PCLX_PATH, QVariant(QDir::homePath())).toString();
mRecentFileMenu->addRecentFile(myPath);

int opacity = mEditor->preference()->getInt(SETTING::WINDOW_OPACITY);

Expand Down
7 changes: 7 additions & 0 deletions core_lib/src/interface/recentfilemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ RecentFileMenu::RecentFileMenu(QString title, QWidget *parent) :
mClearSeparator->setSeparator(true);

mClearAction = new QAction(tr("Clear"), this); // share the same translation
mEmptyAction = new QAction(tr("Empty"));
mEmptyAction->setEnabled(false);
}

RecentFileMenu::~RecentFileMenu()
{
delete mClearSeparator;
delete mClearAction;
delete mEmptyAction;
}

void RecentFileMenu::clear()
Expand All @@ -47,6 +50,8 @@ void RecentFileMenu::clear()
removeAction(mClearAction);
mRecentFiles.clear();
mRecentActions.clear();
addAction(mEmptyAction);
saveToDisk();
}

void RecentFileMenu::setRecentFiles(const QStringList& filenames)
Expand All @@ -68,6 +73,7 @@ bool RecentFileMenu::loadFromDisk()
QVariant recent = settings.value("RecentFiles");
if (recent.isNull())
{
clear();
return false;
}
QStringList recentFileList = recent.toStringList();
Expand Down Expand Up @@ -104,6 +110,7 @@ void RecentFileMenu::addRecentFile(QString filename)
mRecentActions.emplace(filename, action);
if (mRecentFiles.size() == 1)
{
removeAction(mEmptyAction);
addAction(action);
addAction(mClearSeparator);
addAction(mClearAction);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/interface/recentfilemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected slots:
std::map<QString, QAction*> mRecentActions;
QAction* mClearAction = nullptr;
QAction* mClearSeparator = nullptr;
QAction* mEmptyAction = nullptr;
};

#endif // RECENTFILEMENU_H