Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot receive close event of FileDialog #374

Open
Dauto98 opened this issue Jul 8, 2022 · 2 comments
Open

Cannot receive close event of FileDialog #374

Dauto98 opened this issue Jul 8, 2022 · 2 comments

Comments

@Dauto98
Copy link

Dauto98 commented Jul 8, 2022

Describe the bug
When using FileDialog I would like to handle the event when the user close the dialog through Cancel button or Alt-F4. Basically any way that is not selecting a file. The problem is I cannot find any event that is fired when I close the dialog this way. It is needed so I can set the open state back to false.

How can I handle this use case?

To Reproduce
Sample code

const FileLoader = () => {
  const [open, setOpen] = useState(false);

  const onButtonClick = useEventHandler({
    clicked: () => {
      setOpen(true);
    }
  }, []);

  const onFileEvent = useEventHandler({
    // this one work, when the user select a file
    fileSelected: (file) => {
      setOpen(false);
      console.log(file);
    },
    // I tried all of these and none worked
    finished: (event) => {
      setOpen(false);
      console.log("close");
    },
    accept: () => {
      console.log("accept");
    },
    reject: () => {
      console.log("reject");
    },
    open: () => {
      console.log("open");
    },
    Close: () => {
      console.log("close");
    }
  }, []);

  return (
    <View>
      <Button on={onButtonClick}>Select file</Button>
      <FileDialog open={open} on={onFileEvent} />
    </View>
  );
};

Desktop (please complete the following information):

  • OS: Ubuntu 18.04
  • NodeGUI version : not directly installed, it is a dependency of React NodeGUI
  • React NodeGUI version: 0.13.0
  • React: 17.0.2
@Dauto98
Copy link
Author

Dauto98 commented Jul 8, 2022

I am debugging the issue and the problem seems to be no event is fired when I close the dialog through Cancel button (logExceptions not called in class EventWidget extends Component_1.Component in node_modules/@nodegui/nodegui/dist/lib/core/EventWidget.js).

Not sure is it related to the #373 issue (another issue of mine)

@pro100andrik
Copy link

pro100andrik commented Nov 4, 2023

I'm not sure is it actual right now, but I managed same issue like this

const [files, setFiles] = useState([]);
const chooseFileButtonHandler = useEventHandler<QPushButtonSignals>(
  {
    clicked: () => {
      const fileDialog = new QFileDialog();
      fileDialog.exec();
      const selectedFiles = fileDialog.selectedFiles();
      if (fileDialog.result() !== 0) {  // 0 = user closed the dialog, 1 = user selected file
        setFiles(selectedFiles)
      }
    }
  },
  []
);
  return (
    <View>
      <Button on={chooseFileButtonHandler} text='Chose file' />
    </View>
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants