use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.
the class PyEdit method openWithPathAndInnerStructure.
/**
* This function will open an editor given the passed parameters
*
* @param projectName
* @param path
* @param innerStructure
* @throws MisconfigurationException
*/
public static void openWithPathAndInnerStructure(String projectName, IPath path, List<String> innerStructure) throws MisconfigurationException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
if (project != null) {
IFile file = project.getFile(path);
if (file != null) {
IEditorPart editor = PyOpenEditor.doOpenEditor(file);
if (editor instanceof PyEdit) {
PyEdit pyEdit = (PyEdit) editor;
IPythonNature nature = pyEdit.getPythonNature();
AbstractModule mod = AbstractModule.createModuleFromDoc(nature.resolveModule(file), file.getLocation().toFile(), pyEdit.getDocument(), nature, false);
StringBuffer tok = new StringBuffer(80);
for (String s : innerStructure) {
if (tok.length() > 0) {
tok.append('.');
}
tok.append(s);
}
try {
IDefinition[] definitions = mod.findDefinition(CompletionStateFactory.getEmptyCompletionState(tok.toString(), nature, new CompletionCache()), -1, -1, nature);
List<ItemPointer> pointers = new ArrayList<ItemPointer>();
PyRefactoringFindDefinition.getAsPointers(pointers, definitions);
if (pointers.size() > 0) {
new PyOpenAction().run(pointers.get(0));
}
} catch (Exception e) {
Log.log(e);
}
}
}
}
}
use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.
the class PyOpenPythonFileAction method openFiles.
/**
* Opens the given files with the Pydev editor.
*
* @param filesSelected the files to be opened with the pydev editor.
*/
protected void openFiles(List<IFile> filesSelected) {
for (IFile f : filesSelected) {
// If a file is opened here, set it as having the Pydev editor as the default editor.
IDE.setDefaultEditor(f, PyEdit.EDITOR_ID);
new PyOpenAction().run(new ItemPointer(f));
}
}
use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.
the class PyOpenResourceAction method openFiles.
@Override
protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) {
for (PythonpathTreeNode n : pythonPathFilesSelected) {
try {
if (PythonPathHelper.isValidSourceFile(n.file.getName())) {
new PyOpenAction().run(new ItemPointer(n.file));
} else {
final IFileStore fileStore = EFS.getLocalFileSystem().getStore(n.file.toURI());
IDE.openEditorOnFileStore(page, fileStore);
}
} catch (PartInitException e) {
Log.log(e);
}
}
}
use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.
the class PyOpenResourceAction method openFiles.
@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
try {
if (PythonPathHelper.isValidSourceFile(n.zipPath)) {
new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null, n.zipPath));
} else {
IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath);
PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);
if (defaultEditor != null) {
IDE.openEditor(page, input, defaultEditor.getId());
} else {
IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
}
}
} catch (PartInitException e) {
Log.log(e);
}
}
}
use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.
the class PyOutlineSelectionDialog method open.
/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#open()
*/
@Override
public int open() {
int ret = super.open();
if (ret == OK) {
Object[] result = getResult();
if (result != null && result.length > 0) {
@SuppressWarnings("unchecked") DataAndImageTreeNode<Object> n = (DataAndImageTreeNode<Object>) result[0];
OutlineEntry outlineEntry = (OutlineEntry) n.data;
if (outlineEntry.model == null) {
Location location = new Location(NodeUtils.getNameLineDefinition(outlineEntry.node) - 1, NodeUtils.getNameColDefinition(outlineEntry.node) - 1);
EditorUtils.showInEditor(pyEdit, location, location);
} else {
PyOpenAction pyOpenAction = new PyOpenAction();
IModule m = outlineEntry.model.module;
if (m instanceof SourceModule) {
SourceModule sourceModule = (SourceModule) m;
File file = sourceModule.getFile();
if (file != null) {
ItemPointer p = new ItemPointer(file, outlineEntry.node);
pyOpenAction.run(p);
}
}
}
}
}
return ret;
}
Aggregations