Skip to content

Commit

Permalink
Merge 3ec93a1 into fef29da
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Aug 13, 2018
2 parents fef29da + 3ec93a1 commit 6f8e37d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
86 changes: 39 additions & 47 deletions src/plugins/miscellaneous/Core/src/coreplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PLUGININFO_FUNC CorePluginInfo()
//==============================================================================

CorePlugin::CorePlugin() :
mRecentFileNamesOrUrls(QStringList()),
mRecentFiles(QStringList()),
mRecentFileActions(QList<QAction *>())
{
}
Expand Down Expand Up @@ -140,9 +140,9 @@ void CorePlugin::fileOpened(const QString &pFileName)

FileManager *fileManagerInstance = FileManager::instance();

if (fileManagerInstance->isRemote(pFileName)?
mRecentFileNamesOrUrls.removeOne(fileManagerInstance->url(pFileName)):
mRecentFileNamesOrUrls.removeOne(pFileName)) {
if (mRecentFiles.removeOne(fileManagerInstance->isRemote(pFileName)?
fileManagerInstance->url(pFileName):
pFileName)) {
updateFileReopenMenu();
}
}
Expand Down Expand Up @@ -192,10 +192,10 @@ void CorePlugin::fileRenamed(const QString &pOldFileName,
{
// Remove the new file from our list of recent files, should it be there
// Note: it's fine if the new file isn't in our list since nothing will be
// done in that case (thus avoiding us having to test for its
// done in that case (thus avoiding us from having to test for its
// presence)...

if (mRecentFileNamesOrUrls.removeOne(pNewFileName))
if (mRecentFiles.removeOne(pNewFileName))
updateFileReopenMenu();

// A file has been created or saved under a new name, so we want the old
Expand All @@ -211,21 +211,20 @@ void CorePlugin::fileClosed(const QString &pFileName)
{
// Add, if isn't new and it still exists (i.e. we are not here because the
// file has been deleted), the file to our list of recent files (making sure
// that we don't end up with more than 10 recent file names) and update our
// that we don't end up with more than 10 recent files) and update our
// Reopen sub-menu
// Note: the most recent file is to be shown first...

FileManager *fileManagerInstance = FileManager::instance();

if ( !fileManagerInstance->isNew(pFileName)
&& QFile::exists(pFileName)) {
if (fileManagerInstance->isRemote(pFileName))
mRecentFileNamesOrUrls.prepend(fileManagerInstance->url(pFileName));
else
mRecentFileNamesOrUrls.prepend(pFileName);
mRecentFiles.prepend(fileManagerInstance->isRemote(pFileName)?
fileManagerInstance->url(pFileName):
pFileName);

while (mRecentFileNamesOrUrls.count() > 10)
mRecentFileNamesOrUrls.removeLast();
while (mRecentFiles.count() > 10)
mRecentFiles.removeLast();

updateFileReopenMenu();
}
Expand Down Expand Up @@ -448,7 +447,7 @@ void CorePlugin::initializePlugin()
mainWindow());
mFileCloseAllAction = newAction(mainWindow());

// Create the separator before which we will insert our Reopen sub-menu
// Create the separator before which we will insert in our Reopen sub-menu

mFileOpenReloadSeparator = newSeparator(mainWindow());

Expand Down Expand Up @@ -528,7 +527,7 @@ void CorePlugin::initializePlugin()
connect(mCentralWidget, &CentralWidget::atLeastOneFile,
mFileCloseAllAction, &QAction::setEnabled);

// A connection related to our Reopen sub-menu
// Some connections related to our Reopen sub-menu

connect(mFileReopenMostRecentFileAction, &QAction::triggered,
this, &CorePlugin::reopenMostRecentFile);
Expand Down Expand Up @@ -619,12 +618,12 @@ void CorePlugin::loadSettings(QSettings *pSettings)
if (!mainWindow())
return;

// Retrieve the recent files
// Note: it's important to retrieve the recent files before retrieving our
// central widget settings since mRecentFileNamesOrUrls gets updated
// as a result of opening/closing a file...
// Retrieve our recent files
// Note: it's important to retrieve our recent files before retrieving our
// central widget settings since mRecentFiles gets updated as a result
// of opening/closing a file...

mRecentFileNamesOrUrls = pSettings->value(SettingsRecentFiles).toStringList();
mRecentFiles = pSettings->value(SettingsRecentFiles).toStringList();

// Update our Reopen sub-menu

Expand All @@ -647,9 +646,9 @@ void CorePlugin::saveSettings(QSettings *pSettings) const
if (!mainWindow())
return;

// Keep track of the recent files
// Keep track of our recent files

pSettings->setValue(SettingsRecentFiles, mRecentFileNamesOrUrls);
pSettings->setValue(SettingsRecentFiles, mRecentFiles);

// Keep track of the central widget settings

Expand Down Expand Up @@ -705,19 +704,19 @@ void CorePlugin::doUpdateFileReopenMenu()
{
// Update the contents of our Reopen sub-menu by first cleaning it

foreach (QAction *action, mRecentFileActions) {
mFileReopenSubMenu->removeAction(action);
foreach (QAction *recentFileAction, mRecentFileActions) {
mFileReopenSubMenu->removeAction(recentFileAction);

delete action;
delete recentFileAction;
}

mRecentFileActions.clear();

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

bool enabled = mFileOpenAction->isEnabled();

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

action->setEnabled(enabled);
Expand All @@ -731,9 +730,9 @@ void CorePlugin::doUpdateFileReopenMenu()
mRecentFileActions << action;
}

// Enable/disable our reopen sub-menu actions
// Enable/disable our Reopen sub-menu actions

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

mFileReopenMostRecentFileAction->setEnabled(enabled);
mFileClearReopenSubMenuAction->setEnabled(enabled);
Expand All @@ -759,8 +758,8 @@ void CorePlugin::updateFileReopenMenu()

void CorePlugin::updateNewModifiedSensitiveActions()
{
// Update our actions keeping in mind the fact that a file may be modified
// and even possibly new
// Update our actions, keeping in mind the fact that a file may be modified
// or even new

QString fileName = mCentralWidget->currentFileName();

Expand All @@ -783,7 +782,7 @@ void CorePlugin::updateNewModifiedSensitiveActions()

mFileLockedAction->setChecked(!FileManager::instance()->isReadableAndWritable(fileName));
// Note: we really want to call isReadableAndWritable() rather than
// isLocked() since from the GUI perspective a file should only be
// isLocked() since from a GUI perspective a file should only be
// considered unlocked if it can be both readable and writable
// (see CentralWidget::updateFileTab())...
}
Expand All @@ -795,10 +794,10 @@ void CorePlugin::reopenFile(const QString &pFileName)
// Remove the file from our list of recent files and update our Reopen
// sub-menu, if needed

if (mRecentFileNamesOrUrls.removeOne(pFileName))
if (mRecentFiles.removeOne(pFileName))
updateFileReopenMenu();

// Check that the recent file still exists
// Open the recent file after checking that it still exists, if needed

bool isLocalFile;
QString fileNameOrUrl;
Expand All @@ -807,18 +806,12 @@ void CorePlugin::reopenFile(const QString &pFileName)

if (isLocalFile) {
if (QFile::exists(fileNameOrUrl)) {
// Open the recent file

mCentralWidget->openFile(fileNameOrUrl);
} else {
// The file doesn't exist anymore, so let the user know about it

warningMessageBox(tr("Reopen File"),
tr("<strong>%1</strong> does not exist anymore.").arg(QDir::toNativeSeparators(fileNameOrUrl)));
}
} else {
// Open the recent remote file

mCentralWidget->openRemoteFile(fileNameOrUrl);
}
}
Expand All @@ -837,13 +830,12 @@ void CorePlugin::reopenRecentFile()
void CorePlugin::reopenMostRecentFile()
{
// Reopen the most recently closed file
// Note: we don't want to get a reference to mRecentFileNamesOrUrls' first
// item, hence we construct a new string from it. Indeed, reopenFile()
// is going to remove that item from mRecentFileNamesOrUrls, so if we
// were to use a reference, it would eventually become an empty
// string...
// Note: we don't want to get a reference to mRecentFiles' first item, hence
// we construct a new string from it. Indeed, reopenFile() is going to
// remove that item from mRecentFiles, so if we were to use a
// reference, it would eventually become an empty string...

reopenFile(QString(mRecentFileNamesOrUrls.first()));
reopenFile(QString(mRecentFiles.first()));
}

//==============================================================================
Expand All @@ -852,7 +844,7 @@ void CorePlugin::clearReopenSubMenu()
{
// Indirectly clear our Reopen sub-menu

mRecentFileNamesOrUrls.clear();
mRecentFiles.clear();

updateFileReopenMenu();
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/miscellaneous/Core/src/coreplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CorePlugin : public QObject, public CoreInterface,
QAction *mFileReopenSubMenuSeparator2;
QAction *mFileClearReopenSubMenuAction;

QStringList mRecentFileNamesOrUrls;
QStringList mRecentFiles;

QList<QAction *> mRecentFileActions;

Expand Down

0 comments on commit 6f8e37d

Please sign in to comment.