forked from Public-Mirror/Textractor
add drag'n'drop for extensions
This commit is contained in:
parent
4b82d545bf
commit
ee0a8c4887
@ -1,7 +1,10 @@
|
||||
#include "extenwindow.h"
|
||||
#include "ui_extenwindow.h"
|
||||
#include "defs.h"
|
||||
#include "types.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -19,6 +22,7 @@ namespace
|
||||
|
||||
void Load(QString extenName)
|
||||
{
|
||||
if (extenName == ITH_DLL) return;
|
||||
// Extension is dll and exports "OnNewSentence"
|
||||
HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str());
|
||||
if (!module) module = LoadLibraryW(extenName.toStdWString().c_str());
|
||||
@ -91,19 +95,25 @@ ExtenWindow::~ExtenWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ExtenWindow::on_addButton_clicked()
|
||||
void ExtenWindow::Sync()
|
||||
{
|
||||
QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)");
|
||||
if (!extenFileName.size()) return;
|
||||
QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1);
|
||||
QFile::copy(extenFileName, extenName);
|
||||
Load(extenName.left(extenName.lastIndexOf(".dll")));
|
||||
Sync();
|
||||
extenList->clear();
|
||||
extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
std::shared_lock sharedLock(extenMutex);
|
||||
for (auto extenName : extenNames)
|
||||
{
|
||||
extenList->addItem(extenName);
|
||||
extenSaveFile.write((extenName + ">").toUtf8());
|
||||
}
|
||||
extenSaveFile.close();
|
||||
}
|
||||
|
||||
void ExtenWindow::on_rmvButton_clicked()
|
||||
void ExtenWindow::Add(QString fileName)
|
||||
{
|
||||
if (auto extenName = extenList->currentItem()) Unload(extenName->text());
|
||||
if (!fileName.endsWith(".dll")) return;
|
||||
QString extenName = fileName.mid(fileName.lastIndexOf("/") + 1);
|
||||
QFile::copy(fileName, extenName);
|
||||
Load(extenName.split(".dll")[0]);
|
||||
Sync();
|
||||
}
|
||||
|
||||
@ -120,15 +130,23 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ExtenWindow::Sync()
|
||||
void ExtenWindow::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
extenList->clear();
|
||||
extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
std::shared_lock sharedLock(extenMutex);
|
||||
for (auto extenName : extenNames)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void ExtenWindow::dropEvent(QDropEvent* event)
|
||||
{
|
||||
extenList->addItem(extenName);
|
||||
extenSaveFile.write((extenName + ">").toUtf8());
|
||||
for (auto file : event->mimeData()->urls()) Add(file.toLocalFile());
|
||||
}
|
||||
extenSaveFile.close();
|
||||
|
||||
void ExtenWindow::on_addButton_clicked()
|
||||
{
|
||||
Add(QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"));
|
||||
}
|
||||
|
||||
void ExtenWindow::on_rmvButton_clicked()
|
||||
{
|
||||
if (auto extenName = extenList->currentItem()) Unload(extenName->text());
|
||||
Sync();
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "qtcommon.h"
|
||||
#include <shared_mutex>
|
||||
#include <QListWidget>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -25,8 +27,11 @@ private slots:
|
||||
void on_rmvButton_clicked();
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject* target, QEvent* event);
|
||||
void Add(QString fileName);
|
||||
void Sync();
|
||||
bool eventFilter(QObject* target, QEvent* event);
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
void dropEvent(QDropEvent* event);
|
||||
|
||||
Ui::ExtenWindow* ui;
|
||||
QFile extenSaveFile = QFile("Extensions.txt");
|
||||
|
@ -10,6 +10,9 @@
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Extensions</string>
|
||||
</property>
|
||||
|
@ -3,7 +3,7 @@
|
||||
// vnrhook/defs.h
|
||||
// 8/23/2013 jichi
|
||||
|
||||
#define ITH_DLL L"vnrhook.dll"
|
||||
#define ITH_DLL L"vnrhook"
|
||||
|
||||
// Pipes
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user