Analysis
Overview
The goal of this revision is to support import multiple files at once. Optionally, it should allow opening of multiple books at once.
Task requirements
- Create support for selecting multiple items in the file dialogs
- This should allow inserting a lot of images or other media at once and optionally multi book opening.
- Create a menu item in the insert menu that says "Any resource"
- The file dialog dropdown should have 1 entry - All files (*.*)
- The tooltip should say "Import any kind of supported resource, folder or zip with resources."
- When a folder is selected the button should not change to "Open" like it does in the other file dialogs. Insert should be available instead, which should allow import of a folder with resources
- zip files should be scanned for resources and they should be added to the list with the resources. This should be done carefully, because Sophie internal resources are in zips too.
- For both, folder and zip, only their supported contents should be added. But if the user has selected an unsupported file, he should be warned by a message box. If multiple files are selected and part of them are unsupported the user should be notified about them, and the supported ones should be imported
Task result
Code.
Implementation idea
- Make file dialog to support multiple selection and provide a logic that will handle it. See JFileChooser#setMultiSelectionEnabled(selected:boolean) and JFileChooser#getSelectedFiles() : File[]
- Add new file dialog that can open files and directories (JFileChooser#setFileSelectionModel(JFileChooser.FILES_AND_DIRECTORIES)). When the user select something:
1 If it is a file, try to open it
1.2 If it is a zip file, decompress it and go to 1
2 If it is a directory list its files
2.1 If there are only files go to 1
2.2 If there are directories go to 2
Related
APP_RESOURCE_LIST_IMPORT_EXPORT_R0
How to demo
- Create a book
- Go to TestResources folder or download attached zip here
- Extract the zip
- Go to insert menu, choose Image..., and select 2 images by using ctrl+click
- Click insert
- Go to page 2
- Choose insert -> Any resource
- Select the folder and click insert.
Design
- FileDialogInput and FileDialog should be changed so DialogInput#show() method returns File[]. There should be an option in FileDialogInput, indicating if multiple file selection is enabled. If multi-file selection is not active, a File[] should be returned with size 1, with the single opened file at index 0. Selection mode should be FILES_AND_DIRECTORIES if multi-select enabled, FILES_ONLY else.
- InsertResourceItem, extension of AppMenuItem, should be created. It should use multiple file selection and its filter should accept all supported by Sophie2 files.
- InsertImageItem, InsertPDFItem, InsertAudioItem, InsertVideoItem, InsertHtmlItem, PlainTextItem, InsertRtfItem should use multiple file selection. They shouldn't fire events anymore, instead they should instance the ImportFileManager class. (for example: InsertImageItem)
- File filters for Sophie2.0 should no longer be part of FileDIalogInput, they should be moved to SophieFileFilters.
- A more advanced method for determining file types should be used - MIME type utilities. They should be placed in SophieMimeTypes. File type checking in logics and in ImportFileManager should be done with SophieMimeTypes#isFromType() rather than with FileFilter#accept().
- A new class ImportFileManager should fire the corresponding for items in InsertMenu events. Instancing ImportFileManager#openFiles should do the following:
- Get selected files from FileDialog.
- Call method ImportFileManager#importFileList(File[] files). In this method, for every File in files, the following is done:
2.1. if the File is a regular file, and it's MIME type is accepted by SophieMimeTypes#isFromType(), the following event is fired: Source is the AppMenuItem extension that called ImportFileManager, the Id is ImportFileManager#Ids.OPEN_FILE, first parameter is the file itself. All Logics try to handle the event. They try to open the file, passed as first parameter as one of the files each of the Logics recognize. If some Logic succeeds, event is handled and the corresponding frame is opened. If none of the Logics succeeds, an exception dialog is shown with a message for a damaged/incorrect file.
2.2 if the File is a regular file, and it's MIME type is not accepted, user is notified for selecting an unsupported file.
- For each File in files, do:
3.1 if file is a Directory, or a zip file, a list of the files, it contains, is generated and passed as argument to ImportFileManager#importFileList. Zip files are handled by ImportFileManager#scanZipFile(File) - returns an array of files, contained in the zip file.
- Changesets:
- Implementation in 5409, tests in [5437]. Test classes - MultipleResourceImportTest.java, ResourceFilesListTest.java and ImportFileManagerTest.java.
Implementation
Implementation is done according to design. Changesets: [5409], [5437], [5449].
Merged to the trunk [5468].
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)