use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonConsoleLineTracker method checkMapFilenameToHyperlink.
private boolean checkMapFilenameToHyperlink(final int lineOffset, final int matchStartCol, final int matchEndCol, final String filename, final int lineNumberInt) {
File realFile = new File(filename);
if (fileExists(realFile)) {
// Simple case (absolute file match).
createLinkToFile(lineOffset, matchStartCol, matchEndCol, lineNumberInt, realFile);
return true;
}
// Not a direct match, let's try some heuristics to get a match based on the working dir.
final IPath path = Path.fromOSString(filename);
if (path.isAbsolute()) {
// Not much we can't do if the path is already absolute.
return false;
}
IProject project = getProject();
try {
if (project != null) {
if (createLinkFromContainerAndPath(lineOffset, matchStartCol, matchEndCol, lineNumberInt, path, project)) {
return true;
}
}
} catch (IllegalArgumentException e1) {
// ignore
} catch (Exception e1) {
Log.log(e1);
}
IPath workingDir = getWorkingDirectory();
if (workingDir != null && project != null) {
if (!workingDir.equals(project.getLocation())) {
IPath full = workingDir.append(path);
File file = full.toFile();
if (fileExists(file)) {
createLinkToFile(lineOffset, matchStartCol, matchEndCol, lineNumberInt, file);
return true;
}
}
}
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
try {
Set<IResource> projectSourcePathFolderSet = nature.getPythonPathNature().getProjectSourcePathFolderSet();
for (IResource iResource : projectSourcePathFolderSet) {
if (iResource instanceof IContainer) {
IContainer iContainer = (IContainer) iResource;
if (iContainer.equals(project)) {
// We already checked this.
continue;
}
if (workingDir != null && iContainer.getLocation().equals(workingDir)) {
// We already checked this.
continue;
}
if (createLinkFromContainerAndPath(lineOffset, matchStartCol, matchEndCol, lineNumberInt, path, iContainer)) {
return true;
}
}
}
} catch (CoreException e) {
}
}
return false;
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PyGlobalsBrowser method doSelect.
/**
* @param pythonNatures the natures from were we can get info
* @param additionalInfo the additional informations
* @param selectedText the text that should be initially set as a filter
*/
public static void doSelect(List<IPythonNature> pythonNatures, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) {
SelectionDialog dialog = GlobalsDialogFactory.create(EditorUtils.getShell(), additionalInfo, selectedText);
dialog.open();
Object[] result = dialog.getResult();
if (result != null && result.length > 0) {
for (Object obj : result) {
IInfo entry;
if (obj instanceof AdditionalInfoAndIInfo) {
AdditionalInfoAndIInfo additional = (AdditionalInfoAndIInfo) obj;
try {
// all of the input natures).
if (additional.additionalInfo instanceof AdditionalProjectInterpreterInfo) {
AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additional.additionalInfo;
IProject project = projectInterpreterInfo.getProject();
PythonNature pythonNature = PythonNature.getPythonNature(project);
if (pythonNature != null) {
pythonNatures = new ArrayList<IPythonNature>();
pythonNatures.add(pythonNature);
}
} else if (additional.additionalInfo instanceof AdditionalSystemInterpreterInfo) {
AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additional.additionalInfo;
SystemPythonNature pythonNature = new SystemPythonNature(systemInterpreterInfo.getManager());
pythonNatures = new ArrayList<IPythonNature>();
pythonNatures.add(pythonNature);
}
} catch (Throwable e) {
Log.log(e);
}
entry = additional.info;
} else {
entry = (IInfo) obj;
}
List<ItemPointer> pointers = new ArrayList<ItemPointer>();
ICompletionState completionCache = new CompletionState();
for (IPythonNature pythonNature : pythonNatures) {
// try to find in one of the natures...
ICodeCompletionASTManager astManager = pythonNature.getAstManager();
if (astManager == null) {
continue;
}
AnalysisPlugin.getDefinitionFromIInfo(pointers, astManager, pythonNature, entry, completionCache, false, true);
if (pointers.size() > 0) {
new PyOpenAction().run(pointers.get(0));
// don't check the other natures
break;
}
}
}
}
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PySearchIndexPage method checkSelectedResource.
@Override
protected void checkSelectedResource(Collection<String> projectNames, Collection<String> moduleNames, IResource resource) {
if (resource != null && resource.isAccessible()) {
IProject project = resource.getProject();
projectNames.add(project.getName());
PythonNature nature = PythonNature.getPythonNature(project);
if (nature == null) {
return;
}
String moduleName;
try {
moduleName = nature.resolveModule(resource);
} catch (MisconfigurationException e) {
Log.log(e);
return;
}
if (moduleName != null) {
for (String s : moduleNames) {
if (s.endsWith(".*")) {
if (moduleName.startsWith(s.substring(0, s.length() - 1))) {
// There's already another one which includes what we're about to add.
return;
}
}
}
if (resource instanceof IContainer) {
moduleNames.add(moduleName + ".*");
} else {
moduleNames.add(moduleName);
}
}
}
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class ProjectsGroup method calculateChildren.
@Override
protected void calculateChildren() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
for (IProject iProject : projects) {
PythonNature nature = PythonNature.getPythonNature(iProject);
if (nature != null) {
addChild(new NatureGroup(this, nature));
}
}
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PydevPlugin method stop.
/**
* This is called when the plugin is being stopped.
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
DefaultSyncSystemModulesManagerScheduler.get().stop();
IPath stateLocation = getStateLocation();
File file = stateLocation.toFile();
for (String prefix : erasePrefixes) {
FileUtils.clearTempFilesAt(file, prefix);
}
this.isAlive = false;
try {
// stop the running shells
AbstractShell.shutdownAllShells();
// (no point in getting the ones not initialized)
for (PythonNature nature : PythonNature.getInitializedPythonNatures()) {
try {
nature.saveAstManager();
} catch (Exception e) {
Log.log(e);
}
}
} finally {
super.stop(context);
}
}
Aggregations