Closed ralfellner closed 8 years ago
The funny thing about load dialogs in Eclipse is that there is no equivalent (at least none I know of) that restricts to files from the workspace, and as such is based on IFile. Apart from the different looks, is there a particular misbehavior caused by this?
It doesn't cause any misbehavior. However, if you are working with a VCS like git or svn it is quite common that your projects are not physically located within your workspace folder but somewhere else on your disk. By default the dialog opens in your workspace folder and you have to click a lot to find your files.
I'm not aware of any "OpenWorkspaceFileDialog" either. The closest match would be the org.eclipse.ui.dialogs.ResourceListSelectionDialog
:
package de.fxdiagram.eclipse.actions
import de.fxdiagram.core.XRoot
import de.fxdiagram.core.model.ModelLoad
import de.fxdiagram.core.tools.actions.LoadAction
import java.io.InputStreamReader
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IResource
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.jface.window.Window
import org.eclipse.swt.widgets.Display
import org.eclipse.ui.dialogs.ResourceListSelectionDialog
class EclipseLoadAction extends LoadAction {
override perform(XRoot root) {
val dlg = new ResourceListSelectionDialog(Display.^default.activeShell, ResourcesPlugin.workspace.root,
IResource.FILE)
if (Window.OK == dlg.open() && dlg.result?.length == 1) {
val file = dlg.result.get(0) as IFile
file.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor)
if (file?.exists) {
val node = new ModelLoad().load(new InputStreamReader(file.contents, file.charset))
if (node instanceof XRoot) {
root.replaceDomainObjectProviders(node.domainObjectProviders)
root.rootDiagram = node.diagram
root.fileName = file.fullPath.toOSString
}
}
}
}
}
OK, took me a while to figure out how to set the initial filter, but I've committed a change along the lines of your solution. Thanks.
In the long run, it would be cooler if there was a mechanism to configure / replace actions, e.g. by means of dependency injection.
I'm using version 0.26.0 of Fxdiagram. With #41 the save diagram dialog has been changed to an eclipse dialog. Saving a diagram works fine. However, the load diagram dialog is still a standard file dialog. This dialog should also be changed to an eclipse dialog.