Skip to content

Commit 4b9e63d

Browse files
author
jantje
committed
decorator code now mostly in sloeberproject
1 parent f5aa2c5 commit 4b9e63d

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java

+35-26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.eclipse.cdt.core.envvar.IContributedEnvironment;
1212
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
1313
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
14+
import org.eclipse.cdt.core.model.CoreModel;
1415
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1516
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
1617
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@@ -203,7 +204,6 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
203204
return root.getProject(realProjectName);
204205
}
205206

206-
207207
@SuppressWarnings("nls")
208208
private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc) {
209209
IProject project = confDesc.getProjectDescription().getProject();
@@ -237,10 +237,8 @@ private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc)
237237
+ pathDelimiter + systemroot + pathDelimiter + systemroot + "\\system32\\Wbem"
238238
+ pathDelimiter + makeEnvironmentVar("sloeber_path_extension"));
239239
} else {
240-
allVars.put("PATH",
241-
makeEnvironmentVar(ENV_KEY_COMPILER_PATH) + pathDelimiter
242-
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter
243-
+ makeEnvironmentVar("PATH"));
240+
allVars.put("PATH", makeEnvironmentVar(ENV_KEY_COMPILER_PATH) + pathDelimiter
241+
+ makeEnvironmentVar(ENV_KEY_BUILD_GENERIC_PATH) + pathDelimiter + makeEnvironmentVar("PATH"));
244242
}
245243

246244
// Set the codeAnalyzer compile commands
@@ -477,7 +475,6 @@ private static void setEnvVars(ICConfigurationDescription confDesc, Map<String,
477475
}
478476
}
479477

480-
481478
/**
482479
* get the Arduino project description based on a project description
483480
*
@@ -548,43 +545,55 @@ public void setOtherDescription(ICConfigurationDescription confDesc, OtherDescri
548545
*/
549546
public BoardDescription getBoardDescription(ICConfigurationDescription confDesc, boolean allowNull) {
550547
if (!allowNull) {
551-
configureProject();
548+
configureProject();
552549
}
553550
return myBoardDescriptions.get(confDesc.getId());
554551
}
555552

556553
public CompileDescription getCompileDescription(ICConfigurationDescription confDesc, boolean allowNull) {
557554
if (!allowNull) {
558-
configureProject();
555+
configureProject();
559556
}
560557
return myCompileDescriptions.get(confDesc.getId());
561558
}
562559

563-
564560
public OtherDescription getOtherDescription(ICConfigurationDescription confDesc, boolean allowNull) {
565561
if (!allowNull) {
566-
configureProject();
562+
configureProject();
567563
}
568564
return myOtherDescriptions.get(confDesc.getId());
569565
}
570566

571-
public String getDecoratedText(ICConfigurationDescription confDesc, String text) {
572-
// do not use getBoardDescriptor below as this will cause a infinite loop at
573-
// project creation
574-
BoardDescription boardDescriptor = myBoardDescriptions.get(confDesc.getId());
575-
if (boardDescriptor == null) {
576-
return text + " Project not configured"; //$NON-NLS-1$
577-
}
578-
String boardName = boardDescriptor.getBoardName();
579-
String portName = boardDescriptor.getActualUploadPort();
580-
if (portName.isEmpty()) {
581-
portName = Messages.decorator_no_port;
582-
}
583-
if (boardName.isEmpty()) {
584-
boardName = Messages.decorator_no_platform;
585-
}
586-
return text + ' ' + boardName + ' ' + ':' + portName;
567+
/**
568+
* get the text for the decorator
569+
*
570+
* @param text
571+
* @return
572+
*/
573+
public String getDecoratedText(String text) {
574+
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(myProject);
575+
if (prjDesc != null) {
576+
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
577+
if (confDesc != null) {
578+
// do not use getBoardDescriptor below as this will cause a infinite loop at
579+
// project creation
580+
BoardDescription boardDescriptor = myBoardDescriptions.get(confDesc.getId());
581+
if (boardDescriptor == null) {
582+
return text + " Project not configured"; //$NON-NLS-1$
583+
}
584+
String boardName = boardDescriptor.getBoardName();
585+
String portName = boardDescriptor.getActualUploadPort();
586+
if (portName.isEmpty()) {
587+
portName = Messages.decorator_no_port;
588+
}
589+
if (boardName.isEmpty()) {
590+
boardName = Messages.decorator_no_platform;
591+
}
587592

593+
return text + ' ' + boardName + ' ' + ':' + portName;
594+
}
595+
}
596+
return text;
588597
}
589598

590599
private static String getBoardPrefix(ICConfigurationDescription confDesc) {

io.sloeber.ui/src/io/sloeber/ui/ExplorerLabelDecorator.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.sloeber.ui;
22

3-
import org.eclipse.cdt.core.model.CoreModel;
4-
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
5-
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
63
import org.eclipse.core.resources.IProject;
74
import org.eclipse.jface.viewers.ILabelDecorator;
85
import org.eclipse.jface.viewers.ILabelProviderListener;
@@ -44,16 +41,9 @@ public Image decorateImage(Image image, Object element) {
4441
public String decorateText(String text, Object element) {
4542
IProject proj = (IProject) element;
4643
if (proj != null) {
47-
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj);
48-
if (prjDesc != null) {
49-
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
50-
if (confDesc != null) {
51-
SloeberProject arduinoProject = SloeberProject
52-
.getSloeberProject(proj, true);
53-
if (arduinoProject != null) {
54-
return arduinoProject.getDecoratedText(confDesc, text);
55-
}
56-
}
44+
SloeberProject arduinoProject = SloeberProject.getSloeberProject(proj, true);
45+
if (arduinoProject != null) {
46+
return arduinoProject.getDecoratedText(text);
5747
}
5848
}
5949
return text;

0 commit comments

Comments
 (0)