use of org.rstudio.studio.client.projects.model.OpenProjectParams in project rstudio by rstudio.
the class ProjectOpener method showOpenProjectDialog.
public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
initialize();
// use the default dialog on desktop mode or single-session mode
FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(FileSystemItem input, final ProgressIndicator indicator) {
final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {
@Override
public void execute(FileSystemItem item) {
onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
}
};
// null return values here imply a cancellation
if (input == null)
return;
if (input.isDirectory()) {
final String rprojPath = input.completePath(input.getName() + ".Rproj");
final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {
@Override
public void onResponseReceived(Boolean success) {
onProjectFileReady.execute(rprojFile);
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onProjectFileReady.execute(rprojFile);
}
});
} else {
onProjectFileReady.execute(input);
}
}
});
} else {
// in multi-session mode, we have a special dialog for opening projects
WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
}
}
Aggregations