-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
299 additions
and
35 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
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
36 changes: 36 additions & 0 deletions
36
bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/ToolsSystemWrapper.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,36 @@ | ||
/******************************************************************************* | ||
* Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
* Use is subject to license terms. | ||
*******************************************************************************/ | ||
package com.espressif.idf.core.tools; | ||
|
||
import com.espressif.idf.core.SystemWrapper; | ||
|
||
/** | ||
* Tools System wrapper to make sure to avoid the | ||
* system path when verifying for validation after tools installation | ||
* @author Ali Azam Rana | ||
* | ||
*/ | ||
public class ToolsSystemWrapper implements SystemWrapper | ||
{ | ||
private String path; | ||
|
||
public ToolsSystemWrapper(String path) | ||
{ | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
public String getPathEnv() | ||
{ | ||
return path; | ||
} | ||
|
||
@Override | ||
public String getEnvExecutables() | ||
{ | ||
return System.getenv(PATHEXT); | ||
} | ||
|
||
} |
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
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
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
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
85 changes: 85 additions & 0 deletions
85
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/URLDialog.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,85 @@ | ||
/******************************************************************************* | ||
* Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
* Use is subject to license terms. | ||
*******************************************************************************/ | ||
package com.espressif.idf.ui.dialogs; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.eclipse.jface.dialogs.Dialog; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.program.Program; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Link; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
import com.espressif.idf.core.logging.Logger; | ||
|
||
/** | ||
* URL Dialog class that can show multiple external web URLs in the text and | ||
* make them click able and launches the default program to open them | ||
* @author Ali Azam Rana | ||
* | ||
*/ | ||
public class URLDialog extends Dialog | ||
{ | ||
private static final String URL_REGEX = "\\b((http|https)://)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)"; //$NON-NLS-1$ | ||
|
||
private String text; | ||
private String title; | ||
|
||
public URLDialog(Shell parentShell, String title, String text) | ||
{ | ||
super(parentShell); | ||
this.text = text; | ||
this.title = title; | ||
} | ||
|
||
@Override | ||
protected Control createDialogArea(Composite parent) | ||
{ | ||
Composite container = new Composite((Composite) super.createDialogArea(parent), SWT.NONE); | ||
container.setLayout(new GridLayout()); | ||
Link link = new Link(container, SWT.NONE); | ||
link.setText(getTextForLinkControl()); | ||
link.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true)); | ||
link.addListener(SWT.Selection, e -> Program.launch(e.text)); | ||
return container; | ||
} | ||
|
||
@Override | ||
protected void configureShell(Shell newShell) | ||
{ | ||
super.configureShell(newShell); | ||
newShell.setText(title); | ||
} | ||
|
||
private String getTextForLinkControl() | ||
{ | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
Pattern pattern = Pattern.compile(URL_REGEX); | ||
Matcher matcher = pattern.matcher(text); | ||
int startIndex = 0, endIndex = text.length(); | ||
while (matcher.find()) | ||
{ | ||
String url = matcher.group(); | ||
Logger.log("URL Found: " + url); | ||
endIndex = text.indexOf(url); | ||
stringBuilder.append(text.substring(startIndex, endIndex)); | ||
stringBuilder.append("<a>"); //$NON-NLS-1$ | ||
stringBuilder.append(url); | ||
stringBuilder.append("</a>"); //$NON-NLS-1$ | ||
startIndex = endIndex + url.length(); | ||
endIndex = text.length(); | ||
} | ||
if (stringBuilder.toString().isEmpty()) | ||
{ | ||
stringBuilder.append(text); | ||
} | ||
return stringBuilder.toString(); | ||
} | ||
} |
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
Oops, something went wrong.