forked from eclipse-cdt/cdt-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-cdt#159] Add C file image descriptor
fixes eclipse-cdt#159
- Loading branch information
1 parent
81c2687
commit b805668
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
bundles/org.eclipse.cdt.lsp/src/org/eclipse/cdt/lsp/editor/LspEditorFileImageDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* See git history | ||
*******************************************************************************/ | ||
package org.eclipse.cdt.lsp.editor; | ||
|
||
import java.net.URL; | ||
import java.util.HashMap; | ||
|
||
import org.eclipse.cdt.lsp.LspPlugin; | ||
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider; | ||
import org.eclipse.cdt.ui.lsp.ICFileImageDescriptor; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.FileLocator; | ||
import org.eclipse.core.runtime.Path; | ||
import org.eclipse.core.runtime.Platform; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.osgi.framework.Bundle; | ||
|
||
public class LspEditorFileImageDescriptor implements ICFileImageDescriptor { | ||
private final ICLanguageServerProvider cLanguageServerProvider; | ||
private static HashMap<String, ImageDescriptor> imageRegistry = new HashMap<>(2); | ||
private static final String ICONS_PATH = "$nl$/icons/"; //$NON-NLS-1$ | ||
public static final String IMG_CFILE = "IMG_CFILE"; //$NON-NLS-1$ | ||
public static final String IMG_CXXFILE = "IMG_CXXFILE"; //$NON-NLS-1$ | ||
|
||
public LspEditorFileImageDescriptor() { | ||
cLanguageServerProvider = LspPlugin.getDefault().getCLanguageServerProvider(); | ||
declareRegistryImage(IMG_CFILE, ICONS_PATH + "c.png"); //$NON-NLS-1$ | ||
declareRegistryImage(IMG_CXXFILE, ICONS_PATH + "cpp.png"); //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public ImageDescriptor getCImageDescriptor() { | ||
return imageRegistry.get(IMG_CFILE); | ||
} | ||
|
||
@Override | ||
public ImageDescriptor getCXXImageDescriptor() { | ||
return imageRegistry.get(IMG_CXXFILE); | ||
} | ||
|
||
@Override | ||
public ImageDescriptor getHeaderImageDescriptor() { | ||
return imageRegistry.get(IMG_CFILE); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(IProject project) { | ||
return cLanguageServerProvider.isEnabledFor(project); | ||
} | ||
|
||
private final void declareRegistryImage(String key, String path) { | ||
ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); | ||
Bundle bundle = Platform.getBundle(LspPlugin.PLUGIN_ID); | ||
URL url = null; | ||
if (bundle != null) { | ||
url = FileLocator.find(bundle, new Path(path), null); | ||
if (url != null) { | ||
desc = ImageDescriptor.createFromURL(url); | ||
} | ||
} | ||
imageRegistry.put(key, desc); | ||
} | ||
} |