forked from Public-Mirror/Textractor
improve extension UI
This commit is contained in:
parent
1bab6956a8
commit
20f35a02ed
@ -10,6 +10,7 @@
|
||||
|
||||
extern const char* EXTENSIONS;
|
||||
extern const char* ADD_EXTENSION;
|
||||
extern const char* REMOVE_EXTENSION;
|
||||
extern const char* INVALID_EXTENSION;
|
||||
extern const char* CONFIRM_EXTENSION_OVERWRITE;
|
||||
extern const char* EXTENSION_WRITE_ERROR;
|
||||
@ -95,11 +96,21 @@ namespace
|
||||
QMessageBox::information(This, EXTENSIONS, QString(INVALID_EXTENSION).arg(extenFile.fileName()));
|
||||
}
|
||||
|
||||
void OpenMenu(QPoint point)
|
||||
void Delete()
|
||||
{
|
||||
QAction addExtension(ADD_EXTENSION);
|
||||
if (QMenu::exec({ &addExtension }, ui.extenList->mapToGlobal(point), nullptr, This))
|
||||
if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.xdll)\nLibraries (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
|
||||
if (ui.extenList->currentItem())
|
||||
{
|
||||
Unload(ui.extenList->currentIndex().row());
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
|
||||
void ContextMenu(QPoint point)
|
||||
{
|
||||
QAction addExtension(ADD_EXTENSION), removeExtension(REMOVE_EXTENSION);
|
||||
if (auto action = QMenu::exec({ &addExtension, &removeExtension }, ui.extenList->mapToGlobal(point), nullptr, This))
|
||||
if (action == &removeExtension) Delete();
|
||||
else if (QString extenFile = QFileDialog::getOpenFileName(This, ADD_EXTENSION, ".", EXTENSIONS + QString(" (*.xdll)\nLibraries (*.dll)")); !extenFile.isEmpty()) Add(extenFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +120,7 @@ bool DispatchSentenceToExtensions(std::wstring& sentence, const InfoForExtension
|
||||
wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str());
|
||||
concurrency::reader_writer_lock::scoped_lock_read readLock(extenMutex);
|
||||
for (const auto& extension : extensions)
|
||||
if (*(sentenceBuffer = extension.callback(sentenceBuffer, sentenceInfo)) == L'\0') break;
|
||||
if (!*(sentenceBuffer = extension.callback(sentenceBuffer, sentenceInfo))) break;
|
||||
sentence = sentenceBuffer;
|
||||
HeapFree(GetProcessHeap(), 0, sentenceBuffer);
|
||||
return !sentence.empty();
|
||||
@ -129,7 +140,7 @@ ExtenWindow::ExtenWindow(QWidget* parent) : QMainWindow(parent, Qt::WindowCloseB
|
||||
ui.vboxLayout->addWidget(new QLabel(EXTEN_WINDOW_INSTRUCTIONS, this));
|
||||
setWindowTitle(EXTENSIONS);
|
||||
|
||||
connect(ui.extenList, &QListWidget::customContextMenuRequested, OpenMenu);
|
||||
connect(ui.extenList, &QListWidget::customContextMenuRequested, ContextMenu);
|
||||
ui.extenList->installEventFilter(this);
|
||||
|
||||
if (!QFile::exists(EXTEN_SAVE_FILE)) QTextFile(EXTEN_SAVE_FILE, QIODevice::WriteOnly).write(DEFAULT_EXTENSIONS);
|
||||
@ -139,7 +150,7 @@ ExtenWindow::ExtenWindow(QWidget* parent) : QMainWindow(parent, Qt::WindowCloseB
|
||||
|
||||
bool ExtenWindow::eventFilter(QObject* target, QEvent* event)
|
||||
{
|
||||
// See https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget/1528215
|
||||
// https://stackoverflow.com/questions/1224432/how-do-i-respond-to-an-internal-drag-and-drop-operation-using-a-qlistwidget/1528215
|
||||
if (event->type() == QEvent::ChildRemoved)
|
||||
{
|
||||
QStringList extenNames;
|
||||
@ -152,11 +163,7 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event)
|
||||
|
||||
void ExtenWindow::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Delete && ui.extenList->currentItem())
|
||||
{
|
||||
Unload(ui.extenList->currentIndex().row());
|
||||
Sync();
|
||||
}
|
||||
if (event->key() == Qt::Key_Delete) Delete();
|
||||
}
|
||||
|
||||
void ExtenWindow::dragEnterEvent(QDragEnterEvent* event)
|
||||
|
9
text.cpp
9
text.cpp
@ -57,12 +57,11 @@ Negatives for data_offset/split_offset refer to registers
|
||||
-C for RAX, -14 for RBX, -1C for RCX, -24 for RDX, and so on for RSP, RBP, RSI, RDI, R8-R15
|
||||
* means dereference pointer+deref_offset)";
|
||||
const char* SAVE_SETTINGS = u8"Save settings";
|
||||
const char* EXTEN_WINDOW_INSTRUCTIONS = u8R"(To add an extension, right click the extension list
|
||||
Alternatively, drag and drop the extension file from your computer
|
||||
To reorder extensions, drag and drop them within the list
|
||||
(Extensions are used from top to bottom: order DOES matter)
|
||||
To remove an extension, select it and press delete)";
|
||||
const char* EXTEN_WINDOW_INSTRUCTIONS = u8R"(Right click the list to add/remove extensions
|
||||
Drag and drop extensions within the list to reorder them
|
||||
(Extensions are used from top to bottom: order DOES matter))";
|
||||
const char* ADD_EXTENSION = u8"Add extension";
|
||||
const char* REMOVE_EXTENSION = u8"Remove extension";
|
||||
const char* INVALID_EXTENSION = u8"%1 is an invalid extension";
|
||||
const char* CONFIRM_EXTENSION_OVERWRITE = u8"Another version of this extension already exists, do you want to delete and overwrite it?";
|
||||
const char* EXTENSION_WRITE_ERROR = u8"Failed to save extension";
|
||||
|
Loading…
x
Reference in New Issue
Block a user