Fix bug in QDialog (#485)
QDialog should return DialogCode either Rejected or Accepted.
This commit is contained in:
parent
cca5baa447
commit
7836aadd71
@ -34,8 +34,8 @@
|
||||
Napi::Value exec(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->exec(); \
|
||||
return env.Null(); \
|
||||
int value = static_cast<int>(this->instance->exec()); \
|
||||
return Napi::Number::From(env, value); \
|
||||
} \
|
||||
Napi::Value open(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
|
||||
40
src/demo.ts
40
src/demo.ts
@ -1,33 +1,13 @@
|
||||
import { QMainWindow, QLabel, WidgetEventTypes, QMouseEvent } from './index';
|
||||
import { QPoint } from './lib/QtCore/QPoint';
|
||||
import { ContextMenuPolicy } from './lib/QtEnums';
|
||||
import { QMenu } from './lib/QtWidgets/QMenu';
|
||||
import { QAction } from './lib/QtWidgets/QAction';
|
||||
import { QFileDialog, DialogCode, FileMode } from './index';
|
||||
|
||||
const win = new QMainWindow();
|
||||
|
||||
const label = new QLabel();
|
||||
label.setText('Move your mouse here');
|
||||
label.setMouseTracking(true);
|
||||
label.setContextMenuPolicy(ContextMenuPolicy.CustomContextMenu);
|
||||
const fileDialog = new QFileDialog();
|
||||
fileDialog.setFileMode(FileMode.AnyFile);
|
||||
fileDialog.setNameFilter('All files (*.*)');
|
||||
|
||||
label.addEventListener(WidgetEventTypes.MouseMove, (nativeEvt) => {
|
||||
const mouseEvt = new QMouseEvent(nativeEvt as any);
|
||||
console.log('mouseMoved at: ', { x: mouseEvt.x(), y: mouseEvt.y() });
|
||||
});
|
||||
|
||||
label.addEventListener('customContextMenuRequested', (pos: { x: number; y: number }): void => {
|
||||
console.log(pos);
|
||||
const position = new QPoint(pos.x, pos.y);
|
||||
const menu = new QMenu();
|
||||
const action = new QAction();
|
||||
|
||||
action.setText(`Hello World`);
|
||||
menu.addAction(action);
|
||||
const ptGlobal = label.mapToGlobal(position);
|
||||
menu.exec(ptGlobal);
|
||||
});
|
||||
|
||||
win.setCentralWidget(label);
|
||||
win.show();
|
||||
(global as any).win = win;
|
||||
if (fileDialog.exec() === DialogCode.Accepted) {
|
||||
const selectedFiles = fileDialog.selectedFiles();
|
||||
console.log(selectedFiles);
|
||||
} else {
|
||||
console.log('User canceled');
|
||||
}
|
||||
|
||||
4
src/lib/QtEnums/DialogCode/index.ts
Normal file
4
src/lib/QtEnums/DialogCode/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum DialogCode {
|
||||
Rejected = 0,
|
||||
Accepted = 1,
|
||||
}
|
||||
@ -88,3 +88,4 @@ export { WindowModality } from './WindowModality';
|
||||
export { WindowState } from './WindowState';
|
||||
export { WindowType } from './WindowType';
|
||||
export { PenStyle } from './PenStyle';
|
||||
export { DialogCode } from './DialogCode';
|
||||
@ -3,6 +3,7 @@ import { NativeElement } from '../core/Component';
|
||||
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { NodeWidget, QWidgetSignals } from './QWidget';
|
||||
import { DialogCode } from '../QtEnums';
|
||||
|
||||
// All Dialogs should extend from NodeDialog
|
||||
// Implement all native QDialog methods here so that all dialogs get access to those aswell
|
||||
@ -22,7 +23,7 @@ export abstract class NodeDialog<Signals extends QDialogSignals> extends NodeWid
|
||||
isSizeGripEnabled(): boolean {
|
||||
return this.property('sizeGripEnabled').toBool();
|
||||
}
|
||||
exec(): number {
|
||||
exec(): DialogCode {
|
||||
return this.native.exec();
|
||||
}
|
||||
open(): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user