Search in sources :

Example 1 with HelpBook

use of org.eclipse.linuxtools.cdt.libhover.HelpBook in project linuxtools by eclipse.

the class LibHover method getCachedLibraries.

private static void getCachedLibraries(IFileStore dir, String type) {
    try {
        // $NON-NLS-1$
        boolean isCPP = type.equals("C++");
        IFileStore[] files = dir.childStores(EFS.NONE, null);
        for (int i = 0; i < files.length; ++i) {
            IFileStore file = files[i];
            String fileName = file.fetchInfo().getName();
            if (fileName.endsWith(".libhover")) {
                // $NON-NLS-1$
                File f = file.toLocalFile(EFS.NONE, null);
                if (f != null) {
                    String name = getCleanName(fileName.substring(0, fileName.length() - 9));
                    HelpBook h = new HelpBook(name, type);
                    helpBooks.add(h);
                    helpBooksMap.put(name, h);
                    String location = file.toURI().toString();
                    LibHoverLibrary l = new LibHoverLibrary(name, location, null, null, isCPP);
                    libraries.put(h, l);
                }
            }
        }
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) HelpBook(org.eclipse.linuxtools.cdt.libhover.HelpBook) ICHelpBook(org.eclipse.cdt.ui.ICHelpBook) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File)

Example 2 with HelpBook

use of org.eclipse.linuxtools.cdt.libhover.HelpBook in project linuxtools by eclipse.

the class LibHover method getLibHoverDocs.

public static synchronized void getLibHoverDocs() {
    if (docsFetched) {
        return;
    }
    libraries.clear();
    helpBooks.clear();
    helpBooksMap.clear();
    // Check if caching of library info is enabled and if so, get any
    // cached library hover info.
    IPreferenceStore ps = LibhoverPlugin.getDefault().getPreferenceStore();
    if (ps.getBoolean(PreferenceConstants.CACHE_EXT_LIBHOVER)) {
        // Look for cached libhover files in the plugin state location
        IPath stateLocation = LibhoverPlugin.getDefault().getStateLocation();
        IFileSystem fs = EFS.getLocalFileSystem();
        // $NON-NLS-1$
        IPath CLibraryLocation = stateLocation.append("C");
        // $NON-NLS-1$
        IPath CPPLibraryLocation = stateLocation.append("CPP");
        IFileStore cDir = fs.getStore(CLibraryLocation);
        if (cDir.fetchInfo().exists()) {
            // $NON-NLS-1$
            getCachedLibraries(cDir, "C");
        }
        IFileStore cppDir = fs.getStore(CPPLibraryLocation);
        if (cppDir.fetchInfo().exists()) {
            // $NON-NLS-1$
            getCachedLibraries(cppDir, "C++");
        }
    }
    IExtensionRegistry x = RegistryFactory.getRegistry();
    IConfigurationElement[] ces = x.getConfigurationElementsFor(LIBHOVER_DOC_EXTENSION);
    for (int i = 0; i < ces.length; ++i) {
        IConfigurationElement ce = ces[i];
        if (ce.getName().equals("library")) {
            // $NON-NLS-1$
            // see comment in initialize()
            // Use the FileLocator class to open the magic hover doc file
            // in the plugin's jar.
            // Either open the html file or file system file depending
            // on what has been specified.
            // $NON-NLS-1$
            String location = ce.getAttribute("location");
            // $NON-NLS-1$
            String name = ce.getAttribute("name");
            // $NON-NLS-1$
            String helpdocs = ce.getAttribute("docs");
            // $NON-NLS-1$
            String type = ce.getAttribute("type");
            String nameSpace = ce.getContributor().getName();
            // If library not already cached, create it
            ICHelpBook book = helpBooksMap.get(name);
            if (book == null) {
                HelpBook h = new HelpBook(name, type);
                helpBooks.add(h);
                helpBooksMap.put(name, h);
                LibHoverLibrary l = new LibHoverLibrary(name, location, helpdocs, nameSpace, // $NON-NLS-1$
                "C++".equals(type));
                libraries.put(h, l);
            } else {
                LibHoverLibrary l = libraries.get(book);
                if (l != null) {
                    l.setDocs(helpdocs);
                }
            }
            docsFetched = true;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HelpBook(org.eclipse.linuxtools.cdt.libhover.HelpBook) ICHelpBook(org.eclipse.cdt.ui.ICHelpBook) IFileSystem(org.eclipse.core.filesystem.IFileSystem) IFileStore(org.eclipse.core.filesystem.IFileStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ICHelpBook(org.eclipse.cdt.ui.ICHelpBook) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

ICHelpBook (org.eclipse.cdt.ui.ICHelpBook)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 HelpBook (org.eclipse.linuxtools.cdt.libhover.HelpBook)2 File (java.io.File)1 IFileSystem (org.eclipse.core.filesystem.IFileSystem)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 IPath (org.eclipse.core.runtime.IPath)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1