use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class PythonPlatformProvider method projectNameChanged.
void projectNameChanged(Project project, final String newName) {
final String projectDir = project.getProjectDirectory().getNameExt();
PythonSupport pythonSupport = PythonSupport.forProject(project);
final PythonPreferences preferences = pythonSupport.getPreferences();
if (!preferences.isEnabled()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, python not enabled", projectDir);
return;
}
if (!preferences.isSyncEnabled()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, sync not enabled", projectDir);
return;
}
final PythonPackage packageJson = pythonSupport.getPythonPackage();
if (!packageJson.exists()) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, package.json not exist", projectDir);
return;
}
LOGGER.log(Level.FINE, "Processing project name change in project {0}", projectDir);
Map<String, Object> content = packageJson.getContent();
if (content == null) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, package.json has no or invalid content", projectDir);
return;
}
if (!StringUtils.hasText(newName)) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, new name is empty", projectDir);
return;
}
String name = (String) content.get(PythonPackage.FIELD_NAME);
if (Objects.equals(name, newName)) {
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, new name same as current name in package.json", projectDir);
return;
}
final String projectName = PythonUtils.getProjectDisplayName(project);
if (preferences.isAskSyncEnabled()) {
Notifications.askSyncChanges(project, new Runnable() {
@Override
public void run() {
RP.post(new Runnable() {
@Override
public void run() {
changeProjectName(packageJson, newName, projectName, projectDir);
}
});
}
}, new Runnable() {
@Override
public void run() {
preferences.setSyncEnabled(false);
LOGGER.log(Level.FINE, "Project name change ignored in project {0}, cancelled by user", projectDir);
}
});
} else {
changeProjectName(packageJson, newName, projectName, projectDir);
}
}
use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class Notifications method notifyPythonDetected.
@NbBundle.Messages({ "Notifications.detection.title=Python detected", "# {0} - project name", "Notifications.detection.description=Enable Python support in project {0}?", "# {0} - project name", "Notifications.detection.done=Python support enabled in project {0}.", "# {0} - project name", "Notifications.detection.noop=Python support already enabled in project {0}." })
public static void notifyPythonDetected(final Project project) {
final String projectName = PythonUtils.getProjectDisplayName(project);
final PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
assert !preferences.isEnabled() : "Python support should not be enabled in project " + projectName;
NotificationDisplayer.getDefault().notify(Bundle.Notifications_detection_title(), NotificationDisplayer.Priority.LOW.getIcon(), Bundle.Notifications_detection_description(projectName), new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text;
if (preferences.isEnabled()) {
// already done
text = Bundle.Notifications_detection_noop(projectName);
} else {
preferences.setEnabled(true);
text = Bundle.Notifications_detection_done(projectName);
}
StatusDisplayer.getDefault().setStatusText(text);
}
}, NotificationDisplayer.Priority.LOW);
}
use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class Notifications method notifyRunConfiguration.
// @NbBundle.Messages({
// "Notifications.graalvm.detection.title=GraalVM detected",
// "Notifications.graalvm.detection.description=Set proper node and npm paths?",
// "Notifications.graalvm.detection.done=Proper node and npm paths set.",
// "Notifications.graalvm.detection.noop=Proper node and npm paths already set.",
// })
// public static void notifyGraalVmDetected() {
// NotificationDisplayer.getDefault().notify(
// Bundle.Notifications_graalvm_detection_title(),
// NotificationDisplayer.Priority.LOW.getIcon(),
// Bundle.Notifications_graalvm_detection_description(),
// new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String text;
// if (GraalVmUtils.properPathsSet()) {
// // already done
// text = Bundle.Notifications_graalvm_detection_noop();
// } else {
// PythonOptions.getInstance().setPython(GraalVmUtils.getPython());
// PythonOptions.getInstance().setNpm(GraalVmUtils.getNpm(true));
// text = Bundle.Notifications_graalvm_detection_done();
// }
// StatusDisplayer.getDefault().setStatusText(text);
// }
// },
// NotificationDisplayer.Priority.LOW);
// }
@NbBundle.Messages({ "Notifications.enabled.title=Python support enabled", "# {0} - project name", "Notifications.enabled.description=Enable running project {0} as Python application?", "# {0} - project name", "Notifications.enabled.done=Project {0} will be run as Python application.", "# {0} - project name", "Notifications.enabled.noop=Project {0} already runs as Python application.", "# {0} - project name", "Notifications.enabled.invalid=Python support not enabled in project {0}." })
public static void notifyRunConfiguration(Project project) {
final String projectName = PythonUtils.getProjectDisplayName(project);
final PythonSupport pythonSupport = PythonSupport.forProject(project);
final PythonPreferences preferences = pythonSupport.getPreferences();
assert !preferences.isRunEnabled() : "Python run should not be enabled in " + projectName;
NotificationDisplayer.getDefault().notify(Bundle.Notifications_enabled_title(), NotificationDisplayer.Priority.LOW.getIcon(), Bundle.Notifications_enabled_description(projectName), new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text;
if (!preferences.isEnabled()) {
// not enabled at all (happens if one clicks in notifications window later)
text = Bundle.Notifications_enabled_invalid(projectName);
} else if (preferences.isRunEnabled()) {
// already done
text = Bundle.Notifications_enabled_noop(projectName);
} else {
pythonSupport.firePropertyChanged(PythonPlatformProvider.PROP_RUN_CONFIGURATION, null, PythonRunPanel.IDENTIFIER);
text = Bundle.Notifications_enabled_done(projectName);
}
StatusDisplayer.getDefault().setStatusText(text);
}
}, NotificationDisplayer.Priority.LOW);
}
use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class PythonExecutable method forProjectInternal.
@CheckForNull
private static PythonExecutable forProjectInternal(@NullAllowed Project project, boolean showCustomizer) {
if (project == null) {
return getDefault(null, showCustomizer);
}
PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
if (preferences.isDefaultPython()) {
return getDefault(project, showCustomizer);
}
String node = preferences.getPython();
ValidationResult result = new PythonPreferencesValidator().validateNode(node).getResult();
if (validateResult(result) != null) {
if (showCustomizer) {
PythonCustomizerProvider.openCustomizer(project, result);
}
return null;
}
assert node != null;
return createExecutable(node, project);
}
use of org.apache.netbeans.modules.python4nb.preferences.PythonPreferences in project python4nb by ebresie.
the class PythonPlatformProvider method detectPython.
private void detectPython(Project project) {
PythonSupport pythonSupport = PythonSupport.forProject(project);
PythonPreferences preferences = pythonSupport.getPreferences();
if (preferences.isEnabled()) {
// already enabled => noop
return;
}
PythonPackage packageJson = pythonSupport.getPythonPackage();
if (!packageJson.exists()) {
return;
}
Map<String, Object> content = packageJson.getContent();
if (content == null) {
// some error
return;
}
Object engines = content.get(PythonPackage.FIELD_ENGINES);
if (engines instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Object> engines2 = (Map<String, Object>) engines;
if (engines2.containsKey(PythonPackage.FIELD_NODE)) {
Notifications.notifyPythonDetected(project);
}
}
}
Aggregations