refactor regex filter, add guide, and make it a default

This commit is contained in:
Akash Mozumdar 2019-06-03 19:29:37 -04:00
parent 7cdbd93dcb
commit 3a36dbca1d
3 changed files with 60 additions and 17 deletions

View File

@ -1,8 +1,5 @@
#include "extension.h" #include "extension.h"
#include <QMainWindow> #include "ui_regexfilter.h"
#include <QLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTimer> #include <QTimer>
extern const char* REGEX_FILTER; extern const char* REGEX_FILTER;
@ -16,25 +13,19 @@ struct : QMainWindow
{ {
void launch() void launch()
{ {
auto centralWidget = new QWidget(this); ui.setupUi(this);
auto layout = new QVBoxLayout(centralWidget); connect(ui.input, &QLineEdit::textEdited, [=](QString newRegex)
auto input = new QLineEdit(centralWidget);
auto output = new QLabel(centralWidget);
output->setAlignment(Qt::AlignCenter);
layout->addWidget(input);
layout->addWidget(output);
connect(input, &QLineEdit::textEdited, [=](QString newRegex)
{ {
std::lock_guard l(m); std::lock_guard l(m);
try { regex = newRegex.toStdWString(); } try { regex = newRegex.toStdWString(); }
catch (...) { return output->setText(INVALID_REGEX); } catch (...) { return ui.output->setText(INVALID_REGEX); }
output->setText(QString(CURRENT_FILTER).arg(newRegex)); ui.output->setText(QString(CURRENT_FILTER).arg(newRegex));
}); });
resize(350, 60);
setCentralWidget(centralWidget);
setWindowTitle(REGEX_FILTER); setWindowTitle(REGEX_FILTER);
show(); show();
} }
Ui::FilterWindow ui;
}*window = nullptr; }*window = nullptr;
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

52
extensions/regexfilter.ui Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FilterWindow</class>
<widget class="QMainWindow" name="FilterWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>76</height>
</rect>
</property>
<widget class="QWidget">
<layout class="QVBoxLayout">
<item>
<widget class="QLineEdit" name="input"/>
</item>
<item>
<widget class="QLabel" name="output">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel">
<property name="text">
<string>&lt;a href=&quot;https://regexr.com&quot;&gt;regexr.com&lt;/a&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -28,7 +28,7 @@ constexpr auto CONFIG_FILE = u8"Textractor.ini";
// Misc // Misc
constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repetition>Lua>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines"; constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repetition>Regex Filter>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines";
constexpr auto WINDOW = u8"Window"; constexpr auto WINDOW = u8"Window";
// EOF // EOF