Skip to content

Commit

Permalink
Unnecessary error message is printed to the header of the debug confi…
Browse files Browse the repository at this point in the history
…gurations wizard for "Chrome Debug" if URL is selected #1295

Fixes: #1295
  • Loading branch information
vrubezhny committed Aug 10, 2023
1 parent 4e536d5 commit 81a95e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Red Hat Inc. and others.
* Copyright (c) 2018, 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,6 +17,9 @@
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.pathOrEmpty;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -82,7 +85,9 @@ public void createControl(Composite parent) {
.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
decoration.setImage(fieldDecoration.getImage());
this.programPathText.addModifyListener(event -> {
setDirty(true);
validateProgramPath();
updateLaunchConfigurationDialog();
});
filePath = new Button(resComposite, SWT.PUSH);
filePath.setText(Messages.AbstractRunHTMLDebugTab_browse);
Expand Down Expand Up @@ -115,6 +120,7 @@ public void createControl(Composite parent) {
urlText.setLayoutData(urlTextGD);
urlText.addModifyListener(e -> {
setDirty(true);
validateProgramPath();
updateLaunchConfigurationDialog();
});

Expand Down Expand Up @@ -153,33 +159,43 @@ public void createControl(Composite parent) {
private void validateProgramPath() {
setDirty(true);

File file;
try {
file = new File(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programPathText.getText()));
if (!file.isFile()) {
String errorMessage = Messages.RunProgramTab_error_unknownFile;
setErrorMessage(errorMessage);
decoration.setDescriptionText(errorMessage);
decoration.show();
} else if (!shortcut.canLaunch(file)) {
String errorMessage = "Not a html file"; //$NON-NLS-1$
setErrorMessage(errorMessage);
decoration.setDescriptionText(errorMessage);
decoration.show();
} else if (!file.canRead()) {
String errorMessage = Messages.RunProgramTab_error_nonReadableFile;
setErrorMessage(errorMessage);
decoration.setDescriptionText(errorMessage);
decoration.show();
} else {
setErrorMessage(null);
decoration.hide();
String errorMessage = null;
if (fileRadio.getSelection()) {
try {
if (programPathText.getText().length() > 0) {
File file = new File(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programPathText.getText()));
if (!file.isFile()) {
errorMessage = Messages.RunProgramTab_error_unknownFile;
} else if (!shortcut.canLaunch(file)) {
errorMessage = "Not a html file"; //$NON-NLS-1$
} else if (!file.canRead()) {
errorMessage = Messages.RunProgramTab_error_nonReadableFile;
}
}
} catch (CoreException ex) {
errorMessage = ex.getMessage();
}
} catch (CoreException ex) {
setErrorMessage(ex.getMessage());
decoration.setDescriptionText(ex.getMessage());
} else if (urlRadio.getSelection()) {
if (urlText.getText().length() > 0) {
try {
new URL(urlText.getText());
} catch (MalformedURLException ex) {
errorMessage = MessageFormat.format(
Messages.RunProgramTab_error_malformedUR,
ex.getMessage());
}
}
}

if (errorMessage != null) {
setErrorMessage(errorMessage);
decoration.setDescriptionText(errorMessage);
decoration.show();
} else {
setErrorMessage(null);
decoration.hide();
}

updateLaunchConfigurationDialog();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
* Copyright (c) 2019, 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -28,6 +28,7 @@ public class Messages extends NLS {
public static String RunProgramTab_error_nonReadableFile;
public static String RunProgramTab_error_notJSFile;
public static String RunProgramTab_error_unknownFile;
public static String RunProgramTab_error_malformedUR;
public static String RunProgramTab_program;
public static String RunProgramTab_title;
public static String RunProgramTab_workingDirectory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
################################################################
# Copyright (c) 2019 Red Hat Inc. and others.
# Copyright (c) 2019, 2023 Red Hat Inc. and others.
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
Expand All @@ -22,6 +22,7 @@ RunProgramTab_argument=Arguments
RunProgramTab_error_nonReadableFile=Not allowed to read file.
RunProgramTab_error_notJSFile=File is not a JS file.
RunProgramTab_error_unknownFile=Given path doesn't reference a file.
RunProgramTab_error_malformedUR=Malformed URL: ''{0}''.
RunProgramTab_program=Program
RunProgramTab_title=\u25B6\uFE0F Program
RunProgramTab_workingDirectory=Working directory
Expand Down

0 comments on commit 81a95e4

Please sign in to comment.