Closed mahsashadi closed 3 years ago
A VFS file object contains isDirectory
. Can't you use that ?
Indeed I just pass an extension to handleCreateFile function (odt, odp,...), and then I want It to open save as dialog to create the file with my extension, with path and name set in SaveDialog
To clarify more, the project is about making new file for office. I have different buttons for making new word/ powerpoint/ excel files, which all calls handleCreateFile function in their onclick event.
You could probably create a proxy type event handler for this:
function handleCreateFile(fileType) {
basic.off('save-file') // Just to ensure no duplicate events
basic.once('save-file', result => basic.emit('my-save-file', result, fileType)
basic.createSaveDialog()
}
useEffect(() => {
basic.on('my-save-file', (file, fileType) => {
})
}, [])
Thanks.
And how can I filter the files on saveDialog to only show files with my fileType
?
What's the value of a fileType
?
It can be an array of strings
For example [“docx”, “odt”] for openjng new file in Office Word, and [“ppt”, “odp”] for Office Powerpoint
Currently it's only possible to filter with the mime
option, so you'd have to map your fileType to MIME(s).
By mime
, you mean I should define basic like below to work as I need?
const myBasic = core.make('osjs/basic-application', proc, win, {
mimeTypes: fileType //['docx', 'odt', 'txt']
})
No. MIMEs are formatted like this foo/bar
.
Ex a docx
file extension is usually the application/vnd.openxmlformats-officedocument.wordprocessingml.document
MIME type.
So I did not understand how and where I can use them in savedialog senario!
The basic application usually takes the mime definitions from the metadata file, but you can define these yourself like you demonstrated:
const fileTypes = {
docx: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
}
const mimeTypes = Object.values(fileTypes).flat()
const myBasic = core.make('osjs/basic-application', proc, win, {
mimeTypes
})
But since you mention that you want to have different behavior based on what button is clicked, then you probably wanna override the basic application mime types in your dialog. The mimeTypes
parameter for the basic application is designed to make the dialog accept multiple different MIME types, i.e.text/plain
+text/html
+application/vnd.openxmlformats-officedocument.wordprocessingml.document
files, not separately. I hope that makes sense...
const fileTypes = {
docx: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
}
function something(fileType) {
const mimeTypes = fileTypes[fileType] || []
basic.createSaveDialog({
mime: mimeTypes
})
}
So if you need to go for an approach like above here, then you can probably just drop using basic application, because all that it really does is just to handle the session and dialogs anyway.
Thank a lot for your great explanation :+1 I think the code above works, I will examine more tomorrow.
Just it has problem with one of my drives (loaded by my own adapter) which only has directories (no file) at first level, none of directories are shown.
So if you need to go for an approach like above here, then you can probably just drop using basic application, because all that it really does is just to handle the session and dialogs anyway.
Since I need a dialog with save-as dialog options I use basic, so why it is better not to use basic in this case?!
Since I need a dialog with save-as dialog options I use basic, so why it is better not to use basic in this case?!
Sure, you can just keep using this if it works for you. I just think that maybe once you start to override functionality, maybe it would be best to write it yourself -- if you look at the basic-application source you'll see that there isn't that much going on :) But don't fix what ain't broke, I suppose.
maybe it would be best to write it yourself
you are right, I will rewrite this code part again later, thanks a lot.
Just another question , I use defaultFilename
in below code:
const newBasic = core.make('osjs/basic-application', proc, win, {
defaultFilename: ' '
})
But from the second time later that I opened it in my app, I have previous used filename. How can I always have empty filename?
Hm. Sounds like a bug. Can you show screenshots on how to reproduce ?
Sounds like a bug
Oh, or maybe not. I'm not 100% sure what you're refering to.
The default behavior of the "basic application" is to store the last used file into the session. So maybe this is what you're getting ?
You can probably override that by doing proc.args.file = undefined
before basic.init()
.
BTW, there is a bug that when I close the save-as dialog by close button (not by cancel button), if the filename textbox has some value, the confirm dialog for overwriting is triggered! For example It happenes in your textpad application.
Could you please file an issue about it here https://github.com/os-js/osjs-dialogs/issues ? :)
Could you please file an issue about it here https://github.com/os-js/osjs-dialogs/issues ? :)
Sure. It issued here.
Please close this issue if you have solved what was asked in OP
Hi, How can I access
fileType
parameter insave-file
event in below code?