4cee263033
* Minimal TypeInfo header/reduce std interdependencies. TypeInfoSimple.h is a small header that can replace the use of TypeInfo.h in some cases. Signed-off-by: Nemerle <nemerle5+git@gmail.com> * Windows build fixed Removed algorithm.h from string_view.h smoke-test passed Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Resotore dynamic_pointer_cast in intrusive_ptr Requested by reviewer. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix CI build string.h - missed alogorithm.h, since it was removed from string_view NodeWrapper.h - missing smart_ptr.h Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> Co-authored-by: Nemerle <nemerle5+git@gmail.com>
98 lines
3.1 KiB
C++
98 lines
3.1 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include "RecentFiles.h"
|
|
#include "CommonSettingsConfigurations.h"
|
|
#include <AzCore/std/algorithm.h>
|
|
|
|
#include <QDir>
|
|
#include <QSettings>
|
|
|
|
#define SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_KEY (QString("Recent Files") + " " + QString::fromLocal8Bit(ScriptCanvasEditor::GetEditingGameDataFolder().c_str()) + "/")
|
|
#define SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_PATH_KEY (QString("path"))
|
|
|
|
namespace ScriptCanvasEditor
|
|
{
|
|
QStringList ReadRecentFiles()
|
|
{
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, SCRIPTCANVASEDITOR_AZ_QCOREAPPLICATION_SETTINGS_ORGANIZATION_NAME);
|
|
|
|
settings.beginGroup(SCRIPTCANVASEDITOR_NAME_SHORT);
|
|
int count = AZStd::min(settings.beginReadArray(SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_KEY),
|
|
static_cast<int>(c_scriptCanvasEditorSettingsRecentFilesCountMax));
|
|
|
|
// QSettings -> QStringList.
|
|
QStringList recentFiles;
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
settings.setArrayIndex(i);
|
|
QFile f(QDir::toNativeSeparators(settings.value(SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_PATH_KEY).toString()));
|
|
if(f.exists())
|
|
{
|
|
recentFiles.append(f.fileName());
|
|
}
|
|
}
|
|
}
|
|
|
|
settings.endArray();
|
|
settings.endGroup();
|
|
|
|
return recentFiles;
|
|
}
|
|
|
|
void WriteRecentFiles(const QStringList& recentFiles)
|
|
{
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, SCRIPTCANVASEDITOR_AZ_QCOREAPPLICATION_SETTINGS_ORGANIZATION_NAME);
|
|
|
|
settings.beginGroup(SCRIPTCANVASEDITOR_NAME_SHORT);
|
|
settings.beginWriteArray(SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_KEY);
|
|
int count = AZStd::min(recentFiles.size(),
|
|
static_cast<int>(c_scriptCanvasEditorSettingsRecentFilesCountMax));
|
|
|
|
// QSettings -> QStringList.
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
{
|
|
settings.setArrayIndex(i);
|
|
QFile f(recentFiles.at(i));
|
|
if(f.exists())
|
|
{
|
|
settings.setValue(SCRIPTCANVASEDITOR_SETTINGS_RECENT_FILES_PATH_KEY, f.fileName());
|
|
}
|
|
}
|
|
}
|
|
|
|
settings.endArray();
|
|
settings.endGroup();
|
|
}
|
|
|
|
void AddRecentFile(const QString& filename)
|
|
{
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, SCRIPTCANVASEDITOR_AZ_QCOREAPPLICATION_SETTINGS_ORGANIZATION_NAME);
|
|
|
|
// QSettings -> QStringList.
|
|
QStringList recentFiles = ReadRecentFiles();
|
|
|
|
QFile f(QDir::toNativeSeparators(filename));
|
|
if (f.exists())
|
|
{
|
|
recentFiles.prepend(f.fileName());
|
|
recentFiles.removeDuplicates();
|
|
}
|
|
|
|
WriteRecentFiles(recentFiles);
|
|
}
|
|
|
|
void ClearRecentFile()
|
|
{
|
|
QStringList empty;
|
|
WriteRecentFiles(QStringList());
|
|
}
|
|
}
|