mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
Ref T63, remember directory
This commit is contained in:
@@ -64,7 +64,7 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
QString m_widgetStyle { "Fusion" };
|
||||
int m_preferredSelection = static_cast<int>(QAbstractItemView::ExtendedSelection);
|
||||
int m_preferredSelection = static_cast<int>(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CGeneralGuiSettings,
|
||||
|
||||
39
src/blackgui/settings/viewdirectorysettings.h
Normal file
39
src/blackgui/settings/viewdirectorysettings.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 2017
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_SETTINGS_VIEWDIRECTORYSETTINGS_H
|
||||
#define BLACKGUI_SETTINGS_VIEWDIRECTORYSETTINGS_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include <QString>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Trait for directory settings
|
||||
struct TViewDirectorySettings : public BlackMisc::TSettingTrait<QString>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "guiviewdirectory/%Application%"; }
|
||||
|
||||
//! Validator function.
|
||||
static bool isValid(const QString &directory) { Q_UNUSED(directory); return true; }
|
||||
|
||||
//! Default, not consolidating
|
||||
static const QString &defaultValue() { return BlackConfig::CBuildConfig::getDocumentationDirectory(); }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -215,7 +215,7 @@ namespace BlackGui
|
||||
return this->ps_loadJson();
|
||||
}
|
||||
|
||||
CStatusMessage CViewBaseNonTemplate::showFileSaveDialog() const
|
||||
CStatusMessage CViewBaseNonTemplate::showFileSaveDialog()
|
||||
{
|
||||
return this->ps_saveJson();
|
||||
}
|
||||
@@ -514,11 +514,10 @@ namespace BlackGui
|
||||
this->settingsChanged();
|
||||
}
|
||||
|
||||
QString CViewBaseNonTemplate::getDefaultFilename(bool load) const
|
||||
QString CViewBaseNonTemplate::getSettingsFileName(bool load) const
|
||||
{
|
||||
// some logic to find a useful default name
|
||||
QString dir = CBuildConfig::getDocumentationDirectory();
|
||||
|
||||
const QString dir = m_dirSettings.get();
|
||||
if (load)
|
||||
{
|
||||
return CFileUtils::appendFilePaths(dir, CFileUtils::jsonWildcardAppendix());
|
||||
@@ -1400,7 +1399,7 @@ namespace BlackGui
|
||||
do
|
||||
{
|
||||
const QString fileName = QFileDialog::getOpenFileName(nullptr,
|
||||
tr("Load data file"), getDefaultFilename(true),
|
||||
tr("Load data file"), getSettingsFileName(true),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
@@ -1453,13 +1452,23 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_saveJson() const
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_saveJson()
|
||||
{
|
||||
const QString fileName = QFileDialog::getSaveFileName(nullptr,
|
||||
tr("Save data file"), getDefaultFilename(false),
|
||||
tr("Save data file"), getSettingsFileName(false),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityDebug, "Save canceled", true); }
|
||||
const QString json(this->toJsonString()); // save as CVariant JSON
|
||||
|
||||
// keep directory for settings
|
||||
const QFileInfo file(fileName);
|
||||
const QDir fileDir(file.absoluteDir());
|
||||
if (fileDir.exists())
|
||||
{
|
||||
this->m_dirSettings.setAndSave(fileDir.absolutePath());
|
||||
}
|
||||
|
||||
// save file
|
||||
const bool ok = CFileUtils::writeStringToFileInBackground(json, fileName);
|
||||
if (ok)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackgui/models/selectionmodel.h"
|
||||
#include "blackgui/settings/guisettings.h"
|
||||
#include "blackgui/settings/viewdirectorysettings.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/namevariantpairlist.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
@@ -256,7 +257,7 @@ namespace BlackGui
|
||||
BlackMisc::CStatusMessage showFileLoadDialog();
|
||||
|
||||
//! Show file save dialog
|
||||
BlackMisc::CStatusMessage showFileSaveDialog() const;
|
||||
BlackMisc::CStatusMessage showFileSaveDialog();
|
||||
|
||||
//! Save file name (optional)
|
||||
void setSaveFileName(const QString &saveName) { this->m_saveFileName = saveName; }
|
||||
@@ -385,7 +386,7 @@ namespace BlackGui
|
||||
void init();
|
||||
|
||||
//! Default file for load/save operations
|
||||
QString getDefaultFilename(bool load) const;
|
||||
QString getSettingsFileName(bool load) const;
|
||||
|
||||
//! Init menu actions
|
||||
BlackGui::Menus::CMenuActions initMenuActions(MenuFlag menu);
|
||||
@@ -425,6 +426,7 @@ namespace BlackGui
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if needed
|
||||
QMap<MenuFlag, BlackGui::Menus::CMenuActions> m_menuFlagActions; //!< initialized actions
|
||||
BlackMisc::CSettingReadOnly<BlackGui::Settings::TGeneralGui> m_guiSettings { this, &CViewBaseNonTemplate::settingsChanged }; //!< general GUI settings
|
||||
BlackMisc::CSetting<BlackGui::Settings::TViewDirectorySettings> m_dirSettings { this }; //!< directory for load/save
|
||||
|
||||
protected slots:
|
||||
//! Helper method with template free signature serving as callback from threaded worker
|
||||
@@ -458,7 +460,7 @@ namespace BlackGui
|
||||
void ps_loadJsonAction();
|
||||
|
||||
//! Save JSON
|
||||
virtual BlackMisc::CStatusMessage ps_saveJson() const = 0;
|
||||
virtual BlackMisc::CStatusMessage ps_saveJson() = 0;
|
||||
|
||||
//! Save JSON for action/menu, no return signatur
|
||||
void ps_saveJsonAction();
|
||||
@@ -696,7 +698,7 @@ namespace BlackGui
|
||||
virtual void ps_doubleClicked(const QModelIndex &index) override;
|
||||
virtual void ps_rowSelected(const QModelIndex &index) override;
|
||||
virtual BlackMisc::CStatusMessage ps_loadJson() override;
|
||||
virtual BlackMisc::CStatusMessage ps_saveJson() const override;
|
||||
virtual BlackMisc::CStatusMessage ps_saveJson() override;
|
||||
virtual void ps_copy() override;
|
||||
virtual void ps_cut() override;
|
||||
virtual void ps_paste() override;
|
||||
|
||||
Reference in New Issue
Block a user