Search in sources :

Example 1 with ModelUtilService

use of org.erlide.engine.services.search.ModelUtilService in project erlide_eclipse by erlang.

the class CreateHeaderQuickFix method run.

@Override
public void run() {
    final ModelUtilService svc = ErlangEngine.getInstance().getModelUtilService();
    final String name = getQuickFix().getArgs().get(0);
    final IErlProject project = svc.getProject(module);
    final Iterator<IPath> iterator = project.getProperties().getIncludeDirs().iterator();
    final IPath inc;
    if (!iterator.hasNext()) {
        inc = module.getResource().getParent().getProjectRelativePath();
    } else {
        inc = iterator.next();
    // if there are multiple include dirs, let user move file manually
    }
    final IProject wproject = project.getWorkspaceProject();
    final IFolder folder = wproject.getFolder(inc);
    final IFile header = folder.getFile(name);
    try (final EmptyInputStream source = new EmptyInputStream()) {
        header.create(source, true, null);
        folder.refreshLocal(IResource.DEPTH_ONE, null);
        final IFile fileToOpen = header;
        final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IDE.openEditor(page, fileToOpen);
    } catch (final CoreException e) {
        ErlLogger.error(e);
    } catch (final IOException e) {
        ErlLogger.error(e);
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ModelUtilService(org.erlide.engine.services.search.ModelUtilService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IErlProject (org.erlide.engine.model.root.IErlProject)1 ModelUtilService (org.erlide.engine.services.search.ModelUtilService)1