forked from qt-creator/qt-creator
CPaster: Prepare delaying settings creation
Change-Id: Ie4ae3ced23f65b87d9da0841736c6d652398e286 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -60,7 +60,6 @@ public:
|
||||
|
||||
void fetchUrl();
|
||||
|
||||
Settings m_settings;
|
||||
QAction *m_postEditorAction = nullptr;
|
||||
QAction *m_fetchAction = nullptr;
|
||||
QAction *m_fetchUrlAction = nullptr;
|
||||
@@ -124,15 +123,15 @@ CodePasterPluginPrivate::CodePasterPluginPrivate()
|
||||
// Connect protocols
|
||||
if (!m_protocols.isEmpty()) {
|
||||
for (Protocol *proto : m_protocols) {
|
||||
m_settings.protocols.addOption(proto->name());
|
||||
settings().protocols.addOption(proto->name());
|
||||
connect(proto, &Protocol::pasteDone, this, &CodePasterPluginPrivate::finishPost);
|
||||
connect(proto, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
||||
}
|
||||
m_settings.protocols.setDefaultValue(m_protocols.at(0)->name());
|
||||
settings().protocols.setDefaultValue(m_protocols.at(0)->name());
|
||||
}
|
||||
|
||||
// Create the settings Page
|
||||
m_settings.readSettings();
|
||||
settings().readSettings();
|
||||
|
||||
connect(&m_urlOpen, &Protocol::fetchDone, this, &CodePasterPluginPrivate::finishFetch);
|
||||
|
||||
@@ -238,20 +237,20 @@ void CodePasterPluginPrivate::post(QString data, const QString &mimeType)
|
||||
{
|
||||
fixSpecialCharacters(data);
|
||||
|
||||
const QString username = m_settings.username.value();
|
||||
const QString username = settings().username();
|
||||
|
||||
PasteView view(m_protocols, mimeType, ICore::dialogParent());
|
||||
view.setProtocol(m_settings.protocols.stringValue());
|
||||
view.setProtocol(settings().protocols.stringValue());
|
||||
|
||||
const FileDataList diffChunks = splitDiffToFiles(data);
|
||||
const int dialogResult = diffChunks.isEmpty() ?
|
||||
view.show(username, {}, {}, m_settings.expiryDays(), data) :
|
||||
view.show(username, {}, {}, m_settings.expiryDays(), diffChunks);
|
||||
view.show(username, {}, {}, settings().expiryDays(), data) :
|
||||
view.show(username, {}, {}, settings().expiryDays(), diffChunks);
|
||||
|
||||
// Save new protocol in case user changed it.
|
||||
if (dialogResult == QDialog::Accepted && m_settings.protocols.value() != view.protocol()) {
|
||||
m_settings.protocols.setValue(view.protocol());
|
||||
m_settings.writeSettings();
|
||||
if (dialogResult == QDialog::Accepted && settings().protocols() != view.protocol()) {
|
||||
settings().protocols.setValue(view.protocol());
|
||||
settings().writeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,14 +274,14 @@ void CodePasterPluginPrivate::pasteSnippet()
|
||||
void CodePasterPluginPrivate::fetch()
|
||||
{
|
||||
PasteSelectDialog dialog(m_protocols, ICore::dialogParent());
|
||||
dialog.setProtocol(m_settings.protocols.stringValue());
|
||||
dialog.setProtocol(settings().protocols.stringValue());
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
// Save new protocol in case user changed it.
|
||||
if (m_settings.protocols.value() != dialog.protocol()) {
|
||||
m_settings.protocols.setValue(dialog.protocol());
|
||||
m_settings.writeSettings();
|
||||
if (settings().protocols() != dialog.protocol()) {
|
||||
settings().protocols.setValue(dialog.protocol());
|
||||
settings().writeSettings();
|
||||
}
|
||||
|
||||
const QString pasteID = dialog.pasteId();
|
||||
@@ -295,10 +294,10 @@ void CodePasterPluginPrivate::fetch()
|
||||
|
||||
void CodePasterPluginPrivate::finishPost(const QString &link)
|
||||
{
|
||||
if (m_settings.copyToClipboard.value())
|
||||
if (settings().copyToClipboard())
|
||||
Utils::setClipboardAndSelection(link);
|
||||
|
||||
if (m_settings.displayOutput.value())
|
||||
if (settings().displayOutput())
|
||||
MessageManager::writeDisrupting(link);
|
||||
else
|
||||
MessageManager::writeFlashing(link);
|
||||
|
@@ -34,7 +34,7 @@ FileShareProtocol::~FileShareProtocol() = default;
|
||||
|
||||
QString FileShareProtocol::name() const
|
||||
{
|
||||
return m_settings.displayName();
|
||||
return fileShareSettingsPage().displayName();
|
||||
}
|
||||
|
||||
unsigned FileShareProtocol::capabilities() const
|
||||
@@ -49,7 +49,7 @@ bool FileShareProtocol::hasSettings() const
|
||||
|
||||
const Core::IOptionsPage *FileShareProtocol::settingsPage() const
|
||||
{
|
||||
return &m_settings;
|
||||
return &fileShareSettingsPage();
|
||||
}
|
||||
|
||||
static bool parse(const QString &fileName,
|
||||
@@ -100,7 +100,7 @@ static bool parse(const QString &fileName,
|
||||
|
||||
bool FileShareProtocol::checkConfiguration(QString *errorMessage)
|
||||
{
|
||||
if (m_settings.path().isEmpty()) {
|
||||
if (fileShareSettings().path().isEmpty()) {
|
||||
if (errorMessage)
|
||||
*errorMessage = Tr::tr("Please configure a path.");
|
||||
return false;
|
||||
@@ -113,7 +113,7 @@ void FileShareProtocol::fetch(const QString &id)
|
||||
// Absolute or relative path name.
|
||||
QFileInfo fi(id);
|
||||
if (fi.isRelative())
|
||||
fi = m_settings.path().pathAppended(id).toFileInfo();
|
||||
fi = fileShareSettings().path().pathAppended(id).toFileInfo();
|
||||
QString errorMessage;
|
||||
QString text;
|
||||
if (parse(fi.absoluteFilePath(), &errorMessage, nullptr, nullptr, &text))
|
||||
@@ -125,7 +125,7 @@ void FileShareProtocol::fetch(const QString &id)
|
||||
void FileShareProtocol::list()
|
||||
{
|
||||
// Read out directory, display by date (latest first)
|
||||
QDir dir(m_settings.path().toFSPathString(), tempGlobPatternC,
|
||||
QDir dir(fileShareSettings().path().toFSPathString(), tempGlobPatternC,
|
||||
QDir::Time, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
|
||||
QStringList entries;
|
||||
QString user;
|
||||
@@ -133,7 +133,7 @@ void FileShareProtocol::list()
|
||||
QString errorMessage;
|
||||
const QChar blank = QLatin1Char(' ');
|
||||
const QFileInfoList entryInfoList = dir.entryInfoList();
|
||||
const int count = qMin(int(m_settings.displayCount()), entryInfoList.size());
|
||||
const int count = qMin(int(fileShareSettings().displayCount()), entryInfoList.size());
|
||||
for (int i = 0; i < count; i++) {
|
||||
const QFileInfo& entryFi = entryInfoList.at(i);
|
||||
if (parse(entryFi.absoluteFilePath(), &errorMessage, &user, &description)) {
|
||||
@@ -160,7 +160,7 @@ void FileShareProtocol::paste(
|
||||
)
|
||||
{
|
||||
// Write out temp XML file
|
||||
Utils::TempFileSaver saver(m_settings.path().pathAppended(tempPatternC).toFSPathString());
|
||||
Utils::TempFileSaver saver(fileShareSettings().path().pathAppended(tempPatternC).toFSPathString());
|
||||
saver.setAutoRemove(false);
|
||||
if (!saver.hasError()) {
|
||||
// Flat text sections embedded into pasterElement
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "protocol.h"
|
||||
#include "fileshareprotocolsettingspage.h"
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
@@ -30,9 +29,6 @@ public:
|
||||
const QString &username = QString(),
|
||||
const QString &comment = QString(),
|
||||
const QString &description = QString()) override;
|
||||
|
||||
private:
|
||||
FileShareProtocolSettings m_settings;
|
||||
};
|
||||
|
||||
} // CodePaster
|
||||
|
@@ -13,11 +13,15 @@ using namespace Utils;
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
FileShareProtocolSettings &fileShareSettings()
|
||||
{
|
||||
static FileShareProtocolSettings theSettings;
|
||||
return theSettings;
|
||||
}
|
||||
|
||||
FileShareProtocolSettings::FileShareProtocolSettings()
|
||||
{
|
||||
setId("X.CodePaster.FileSharePaster");
|
||||
setDisplayName(Tr::tr("Fileshare"));
|
||||
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
||||
setAutoApply(false);
|
||||
setSettingsGroup("FileSharePasterSettings");
|
||||
|
||||
path.setSettingsKey("Path");
|
||||
@@ -51,4 +55,22 @@ FileShareProtocolSettings::FileShareProtocolSettings()
|
||||
readSettings();
|
||||
}
|
||||
|
||||
class FileShareProtocolSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
FileShareProtocolSettingsPage()
|
||||
{
|
||||
setId("X.CodePaster.FileSharePaster");
|
||||
setDisplayName(Tr::tr("Fileshare"));
|
||||
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
||||
setSettingsProvider([] { return &fileShareSettings(); });
|
||||
}
|
||||
};
|
||||
|
||||
Core::IOptionsPage &fileShareSettingsPage()
|
||||
{
|
||||
static FileShareProtocolSettingsPage theSettings;
|
||||
return theSettings;
|
||||
}
|
||||
|
||||
} // namespace CodePaster
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
class FileShareProtocolSettings : public Core::PagedSettings
|
||||
class FileShareProtocolSettings final : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
FileShareProtocolSettings();
|
||||
@@ -16,4 +16,8 @@ public:
|
||||
Utils::IntegerAspect displayCount{this};
|
||||
};
|
||||
|
||||
FileShareProtocolSettings &fileShareSettings();
|
||||
|
||||
Core::IOptionsPage &fileShareSettingsPage();
|
||||
|
||||
} // CodePaster
|
||||
|
@@ -6,21 +6,24 @@
|
||||
#include "cpasterconstants.h"
|
||||
#include "cpastertr.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
Settings &settings()
|
||||
{
|
||||
static Settings theSettings;
|
||||
return theSettings;
|
||||
}
|
||||
|
||||
Settings::Settings()
|
||||
{
|
||||
setSettingsGroup("CodePaster");
|
||||
setAutoApply(false);
|
||||
setId("A.CodePaster.General");
|
||||
setDisplayName(Tr::tr("General"));
|
||||
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
||||
setDisplayCategory(Tr::tr("Code Pasting"));
|
||||
setCategoryIconPath(":/cpaster/images/settingscategory_cpaster.png");
|
||||
|
||||
username.setDisplayStyle(StringAspect::LineEditDisplay);
|
||||
username.setSettingsKey("UserName");
|
||||
@@ -64,4 +67,20 @@ Settings::Settings()
|
||||
});
|
||||
}
|
||||
|
||||
class CPasterSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
CPasterSettingsPage()
|
||||
{
|
||||
setId("A.CodePaster.General");
|
||||
setDisplayName(Tr::tr("General"));
|
||||
setCategory(Constants::CPASTER_SETTINGS_CATEGORY);
|
||||
setDisplayCategory(Tr::tr("Code Pasting"));
|
||||
setCategoryIconPath(":/cpaster/images/settingscategory_cpaster.png");
|
||||
setSettingsProvider([] { return &settings(); });
|
||||
}
|
||||
};
|
||||
|
||||
const CPasterSettingsPage settingsPage;
|
||||
|
||||
} // CodePaster
|
||||
|
@@ -3,11 +3,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <utils/aspects.h>
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
class Settings : public Core::PagedSettings
|
||||
class Settings final : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
Settings();
|
||||
@@ -19,4 +19,6 @@ public:
|
||||
Utils::BoolAspect displayOutput{this};
|
||||
};
|
||||
|
||||
Settings &settings();
|
||||
|
||||
} // CodePaster
|
||||
|
Reference in New Issue
Block a user