mirror of
https://github.com/august-alt/gpui.git
synced 2025-03-14 12:58:39 +03:00
wip: implement messages for InputMessageNotifier
This commit is contained in:
parent
0ac2ac45f5
commit
3e5b5a347a
@ -764,6 +764,44 @@ context (user policy option)</translation>
|
||||
<translation>Common</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>preferences::InputMessageNotifier</name>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="27"/>
|
||||
<source>The input field has a space at the beginning or at the end</source>
|
||||
<translation>The input field has a space at the beginning or at the end</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="31"/>
|
||||
<source>There is a folder '.'/'..' in the path input field</source>
|
||||
<translation>There is a folder '.'/'..' in the path input field</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="35"/>
|
||||
<source>The path input field contains the path to the folder</source>
|
||||
<translation>The path input field contains the path to the folder</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="39"/>
|
||||
<source>The path input field contains a path that is not compatible with windows</source>
|
||||
<translation>The path input field contains a path that is not compatible with windows</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="43"/>
|
||||
<source>The path input field contains a relative path</source>
|
||||
<translation>The path input field contains a relative path</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="47"/>
|
||||
<source>The path input field contains a path from root</source>
|
||||
<translation>The path input field contains a path from root</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="51"/>
|
||||
<source>The path input field contains a network path</source>
|
||||
<translation>The path input field contains a network path</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>preferences::PreferencesTreeView</name>
|
||||
<message>
|
||||
|
@ -765,6 +765,44 @@ context (user policy option)</source>
|
||||
<translation>Общие</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>preferences::InputMessageNotifier</name>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="27"/>
|
||||
<source>The input field has a space at the beginning or at the end</source>
|
||||
<translation>Поле ввода содержит пробел в начале или в конце</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="31"/>
|
||||
<source>There is a folder '.'/'..' in the path input field</source>
|
||||
<translation>В поле ввода пути есть папка "."/".."</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="35"/>
|
||||
<source>The path input field contains the path to the folder</source>
|
||||
<translation>Поле ввода пути содержит путь к папке</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="39"/>
|
||||
<source>The path input field contains a path that is not compatible with windows</source>
|
||||
<translation>Поле ввода path содержит путь, который несовместим с Windows</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="43"/>
|
||||
<source>The path input field contains a relative path</source>
|
||||
<translation>Поле ввода path содержит относительный путь</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="47"/>
|
||||
<source>The path input field contains a path from root</source>
|
||||
<translation>Поле ввода path содержит путь от корня</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../inputmessagenotifier.cpp" line="51"/>
|
||||
<source>The path input field contains a network path</source>
|
||||
<translation>Поле ввода path содержит сетевой путь</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>preferences::PreferencesTreeView</name>
|
||||
<message>
|
||||
|
@ -20,13 +20,142 @@
|
||||
|
||||
#include "inputmessagenotifier.h"
|
||||
|
||||
namespace preferences
|
||||
{
|
||||
namespace preferences {
|
||||
|
||||
InputMessageNotifier::InputMessageNotifier(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
QString InputMessageNotifier::invisibleSpaceMessage()
|
||||
{
|
||||
|
||||
return tr("The input field has a space at the beginning or at the end");
|
||||
}
|
||||
QString InputMessageNotifier::dotsMessage()
|
||||
{
|
||||
return tr("There is a folder '.'/'..' in the path input field");
|
||||
}
|
||||
QString InputMessageNotifier::folderPathMessage()
|
||||
{
|
||||
return tr("The path input field contains the path to the folder");
|
||||
}
|
||||
QString InputMessageNotifier::windowsCompatibilityMessage()
|
||||
{
|
||||
return tr("The path input field contains a path that is not compatible with windows");
|
||||
}
|
||||
QString InputMessageNotifier::relativePathMessage()
|
||||
{
|
||||
return tr("The path input field contains a relative path");
|
||||
}
|
||||
QString InputMessageNotifier::rootPathMessage()
|
||||
{
|
||||
return tr("The path input field contains a path from root");
|
||||
}
|
||||
QString InputMessageNotifier::networkPathMessage()
|
||||
{
|
||||
return tr("The path input field contains a network path");
|
||||
}
|
||||
|
||||
bool InputMessageNotifier::checkInvisibleSpace(const QString &str)
|
||||
{
|
||||
return str.trimmed() != str;
|
||||
}
|
||||
bool InputMessageNotifier::checkDots(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
bool InputMessageNotifier::checkFolderPath(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
bool InputMessageNotifier::checkWindowsCompatibility(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
bool InputMessageNotifier::checkRelativePath(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
bool InputMessageNotifier::checkRootPath(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
bool InputMessageNotifier::checkNetworkPath(const QString &str)
|
||||
{
|
||||
// TODO: Write regex
|
||||
return false;
|
||||
}
|
||||
|
||||
InputMessageNotifier::InputMessageNotifier(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
this->m_layout = new QVBoxLayout;
|
||||
this->setLayout(this->m_layout);
|
||||
|
||||
for (size_t i = 0; i < static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH); ++i) {
|
||||
this->m_messages[i] = new QLabel(this);
|
||||
|
||||
this->m_messages[i]->setText(this->m_getMessages[i]());
|
||||
this->m_messages[i]->hide();
|
||||
this->m_messages[i]->setStyleSheet("background-color: rgb(249, 240, 107);\n"
|
||||
"border-radius: 10px;\n"
|
||||
"padding: 10px;");
|
||||
|
||||
this->m_layout->addWidget(this->m_messages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void InputMessageNotifier::addInstance(const QString& name)
|
||||
{
|
||||
this->m_instances[name] = {};
|
||||
}
|
||||
|
||||
void InputMessageNotifier::setInstanceDetection(const QString& name, MessageNotifierType type,
|
||||
bool detection)
|
||||
{
|
||||
this->m_instances[name].trigger[static_cast<size_t>(type)] = detection;
|
||||
updateState();
|
||||
}
|
||||
|
||||
void InputMessageNotifier::eraseInstance(const QString& name)
|
||||
{
|
||||
this->m_instances.remove(name);
|
||||
updateState();
|
||||
}
|
||||
|
||||
void InputMessageNotifier::updateInstance(const QString& name, const QString& content)
|
||||
{
|
||||
auto &instance = this->m_instances[name];
|
||||
|
||||
for (size_t i = 0; i < static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH); ++i) {
|
||||
instance.detected[i] = instance.trigger[i] && this->m_checkMessage[i](content);
|
||||
}
|
||||
|
||||
instance.content = std::move(content);
|
||||
updateState();
|
||||
}
|
||||
|
||||
void InputMessageNotifier::updateState()
|
||||
{
|
||||
std::bitset<32> res{ 0 };
|
||||
|
||||
for (const auto &instance : this->m_instances) {
|
||||
res |= instance.detected;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH); ++i) {
|
||||
if (res[i]) {
|
||||
this->m_messages[i]->show();
|
||||
} else {
|
||||
this->m_messages[i]->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputMessageNotifier::retranslateUi()
|
||||
{
|
||||
for (size_t i = 0; i < static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH); ++i) {
|
||||
this->m_messages[i]->setText(this->m_getMessages[i]());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace preferences
|
||||
|
@ -21,59 +21,104 @@
|
||||
#ifndef GPUI_INPUTMESSAGENOTIFIER_H
|
||||
#define GPUI_INPUTMESSAGENOTIFIER_H
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QtCore>
|
||||
#include <QtWidgets>
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class InputMessageNotifier; }
|
||||
namespace Ui {
|
||||
class InputMessageNotifier;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace preferences
|
||||
{
|
||||
namespace preferences {
|
||||
|
||||
class InputMessageNotifier : public QWidget
|
||||
{
|
||||
public:
|
||||
Q_OBJECT
|
||||
private:
|
||||
typedef struct MessageNotifierInfoFields
|
||||
{
|
||||
bool invisibleSpace : 1; // example: ` /var/hello`
|
||||
bool dots : 1; // example: `/var/./hello` | `/var/../hello`
|
||||
bool folderPath : 1; // example: `/var/hello/`
|
||||
bool windowsCompatibility : 1; // any path, that can't be Windows path or UNC path.
|
||||
bool localPath : 1; // any path, that can't be local: `var/hello`
|
||||
bool rootPath : 1; // any path, that can't be root: `/var/hello`
|
||||
bool networkPath : 1; // any path, that can't be network: `smb://SMB.DOMAIN.TEST/Test/path`
|
||||
} MessageNotifierInfoFields;
|
||||
|
||||
public:
|
||||
typedef union MessageNotifierInfo
|
||||
{
|
||||
MessageNotifierInfoFields fields;
|
||||
uint32_t mask{0};
|
||||
} MessageNotifierInfo;
|
||||
typedef enum class MessageNotifierType {
|
||||
// Warns if one of the following regular expressions is executed for the entire string
|
||||
INVISIBLE_SPACE = 0, // " .*|.* |.+ {2}.+"
|
||||
DOTS = 1, // ".+\.{1,2}.*"
|
||||
FOLDER_PATH = 2, // "*./"
|
||||
WINDOWS_COMPATIBILITY = 3, // TODO: write regex
|
||||
RELATIVE_PATH = 4, // TODO: write regex (for linux and windows)
|
||||
ROOT_PATH = 5, // TODO: write regex (for linux and windows)
|
||||
NETWORK_PATH = 6, // TODO: write regex (for linux and windows)
|
||||
MESSAGE_NOTIFIER_LENGTH,
|
||||
} MessageNotifierType;
|
||||
|
||||
typedef struct MessageInstance
|
||||
private:
|
||||
typedef std::bitset<32> MessageNotifierInfo;
|
||||
|
||||
typedef struct MessageInstance
|
||||
{
|
||||
MessageNotifierInfo trigger;
|
||||
MessageNotifierInfo detected;
|
||||
MessageNotifierInfo trigger{0};
|
||||
MessageNotifierInfo detected{0};
|
||||
QString content{};
|
||||
} MessageInstance;
|
||||
|
||||
public:
|
||||
explicit InputMessageNotifier(QWidget* parent = nullptr);
|
||||
typedef QString (*MessageStringFunc)();
|
||||
typedef bool (*CheckStringFunc)(const QString &str);
|
||||
|
||||
private:
|
||||
InputMessageNotifier(const InputMessageNotifier&) = delete; // copy ctor
|
||||
InputMessageNotifier(InputMessageNotifier&&) = delete; // move ctor
|
||||
InputMessageNotifier& operator=(const InputMessageNotifier&) = delete; // copy assignment
|
||||
InputMessageNotifier& operator=(InputMessageNotifier&&) = delete; // move assignment
|
||||
static QString invisibleSpaceMessage();
|
||||
static QString dotsMessage();
|
||||
static QString folderPathMessage();
|
||||
static QString windowsCompatibilityMessage();
|
||||
static QString relativePathMessage();
|
||||
static QString rootPathMessage();
|
||||
static QString networkPathMessage();
|
||||
|
||||
static bool checkInvisibleSpace(const QString &str);
|
||||
static bool checkDots(const QString &str);
|
||||
static bool checkFolderPath(const QString &str);
|
||||
static bool checkWindowsCompatibility(const QString &str);
|
||||
static bool checkRelativePath(const QString &str);
|
||||
static bool checkRootPath(const QString &str);
|
||||
static bool checkNetworkPath(const QString &str);
|
||||
|
||||
void updateState();
|
||||
|
||||
private:
|
||||
static constexpr std::array<MessageStringFunc,
|
||||
static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH)>
|
||||
m_getMessages = { &invisibleSpaceMessage, &dotsMessage,
|
||||
&folderPathMessage, &windowsCompatibilityMessage,
|
||||
&relativePathMessage, &rootPathMessage,
|
||||
&networkPathMessage };
|
||||
static constexpr std::array<CheckStringFunc,
|
||||
static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH)>
|
||||
m_checkMessage = { &checkInvisibleSpace, &checkDots, &checkFolderPath,
|
||||
&checkWindowsCompatibility, &checkRelativePath, &checkRootPath,
|
||||
&checkNetworkPath };
|
||||
|
||||
public:
|
||||
explicit InputMessageNotifier(QWidget *parent = nullptr);
|
||||
|
||||
void addInstance(const QString& name);
|
||||
void setInstanceDetection(const QString& name, MessageNotifierType type, bool detection = true);
|
||||
void eraseInstance(const QString& name);
|
||||
void updateInstance(const QString& name, const QString &content);
|
||||
|
||||
void retranslateUi();
|
||||
|
||||
private:
|
||||
InputMessageNotifier(const InputMessageNotifier &) = delete; // copy ctor
|
||||
InputMessageNotifier(InputMessageNotifier &&) = delete; // move ctor
|
||||
InputMessageNotifier &operator=(const InputMessageNotifier &) = delete; // copy assignment
|
||||
InputMessageNotifier &operator=(InputMessageNotifier &&) = delete; // move assignment
|
||||
|
||||
private:
|
||||
QMap<QString, MessageInstance> m_instances{};
|
||||
QStaticArrayData<QWidget*, 7> m_messages{};
|
||||
};
|
||||
QVBoxLayout* m_layout{ nullptr };
|
||||
std::array<QLabel *, static_cast<size_t>(MessageNotifierType::MESSAGE_NOTIFIER_LENGTH)>
|
||||
m_messages{ nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace preferences
|
||||
|
||||
#endif //GPUI_INPUTMESSAGENOTIFIER_H
|
||||
#endif // GPUI_INPUTMESSAGENOTIFIER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user