Skip to content

Commit

Permalink
Core plugin: fixed a problem with menu items in the File | Reopen men…
Browse files Browse the repository at this point in the history
…u potentially appearing as disabled (#1633).
  • Loading branch information
agarny committed Apr 27, 2018
1 parent d890ecc commit acc466b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
34 changes: 24 additions & 10 deletions src/plugins/miscellaneous/Core/src/coreplugin.cpp
Expand Up @@ -43,6 +43,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QMenu>
#include <QPalette>
#include <QSettings>
#include <QTimer>

//==============================================================================

Expand Down Expand Up @@ -509,8 +510,6 @@ void CorePlugin::initializePlugin()
mFileOpenAction, &QAction::setEnabled);
connect(mCentralWidget, &CentralWidget::atLeastOneView,
mFileOpenRemoteAction, &QAction::setEnabled);
connect(mCentralWidget, &CentralWidget::atLeastOneView,
this, &CorePlugin::updateFileReopenMenu);

connect(mCentralWidget, &CentralWidget::canSave,
mFileSaveAction, &QAction::setEnabled);
Expand Down Expand Up @@ -702,7 +701,7 @@ void CorePlugin::newFile()

//==============================================================================

void CorePlugin::updateFileReopenMenu(bool pEnabled)
void CorePlugin::doUpdateFileReopenMenu()
{
// Update the contents of our Reopen sub-menu by first cleaning it

Expand All @@ -716,10 +715,12 @@ void CorePlugin::updateFileReopenMenu(bool pEnabled)

// Add the recent files to our Reopen sub-menu

bool enabled = mFileOpenAction->isEnabled();

foreach (const QString &recentFile, mRecentFileNamesOrUrls) {
QAction *action = newAction(mainWindow());

action->setEnabled(pEnabled);
action->setEnabled(enabled);
action->setText(recentFile);

connect(action, &QAction::triggered,
Expand All @@ -730,15 +731,28 @@ void CorePlugin::updateFileReopenMenu(bool pEnabled)
mRecentFileActions << action;
}

// Enable/disable our reopen sub-menu actions depending on whether we have
// recent file names
// Enable/disable our reopen sub-menu actions

enabled = enabled && !mRecentFileNamesOrUrls.isEmpty();

mFileReopenMostRecentFileAction->setEnabled(enabled);
mFileClearReopenSubMenuAction->setEnabled(enabled);

bool hasRecentFileNamesOrUrls = !mRecentFileNamesOrUrls.isEmpty();
showEnableAction(mFileReopenSubMenuSeparator2, enabled);
}

//==============================================================================

mFileReopenMostRecentFileAction->setEnabled(hasRecentFileNamesOrUrls);
mFileClearReopenSubMenuAction->setEnabled(hasRecentFileNamesOrUrls);
void CorePlugin::updateFileReopenMenu()
{
// Update the contents of our Reopen sub-menu
// Note #1: we need to do this through a single shot otherwise, on macOS,
// our menu items will look disabled (before looking enabled; see
// issue #1633)...
// Note #2: it all used to work fine before, so could it be an issue with
// Qt?...

showEnableAction(mFileReopenSubMenuSeparator2, hasRecentFileNamesOrUrls);
QTimer::singleShot(0, this, &CorePlugin::doUpdateFileReopenMenu);
}

//==============================================================================
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/miscellaneous/Core/src/coreplugin.h
Expand Up @@ -115,14 +115,16 @@ class CorePlugin : public QObject, public CoreInterface,

void reopenFile(const QString &pFileName);

void updateFileReopenMenu();

private slots:
void newFile();

void updateFileReopenMenu(bool pEnabled = true);

void reopenRecentFile();
void reopenMostRecentFile();
void clearReopenSubMenu();

void doUpdateFileReopenMenu();
};

//==============================================================================
Expand Down

0 comments on commit acc466b

Please sign in to comment.