use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel in project intellij-community by JetBrains.
the class IpnbPyReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
final List<Object> variants = Lists.newArrayList();
Collections.addAll(variants, super.getVariants());
PsiFile file = myElement.getContainingFile();
if (file instanceof IpnbPyFragment) {
final IpnbFilePanel panel = ((IpnbPyFragment) file).getFilePanel();
final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
for (IpnbEditablePanel editablePanel : panels) {
if (!(editablePanel instanceof IpnbCodePanel))
continue;
final Editor editor = ((IpnbCodePanel) editablePanel).getEditor();
final IpnbPyFragment psiFile = (IpnbPyFragment) PsiDocumentManager.getInstance(myElement.getProject()).getPsiFile(editor.getDocument());
if (psiFile == null)
continue;
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(myElement);
PyResolveUtil.scopeCrawlUp(processor, psiFile, null, null);
variants.addAll(getOriginalElements(processor));
}
}
return variants.toArray();
}
use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel in project intellij-community by JetBrains.
the class IpnbCodeCellAction method changeTypeToCode.
public void changeTypeToCode(@NotNull final IpnbFileEditor editor) {
final IpnbFilePanel filePanel = editor.getIpnbFilePanel();
final IpnbEditablePanel selectedCellPanel = filePanel.getSelectedCellPanel();
if (selectedCellPanel == null)
return;
final IpnbEditableCell cell = selectedCellPanel.getCell();
final List<IpnbCell> cells = filePanel.getIpnbFile().getCells();
final int index = cells.indexOf(selectedCellPanel.getCell());
final IpnbCodeCell codeCell = new IpnbCodeCell("python", cell.getSource(), null, Lists.newArrayList(), cell.getMetadata());
if (index >= 0) {
cells.set(index, codeCell);
}
filePanel.replaceComponent(selectedCellPanel, codeCell);
}
use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel in project intellij-community by JetBrains.
the class IpnbHeadingCellActionBase method changeTypeToHeading.
public void changeTypeToHeading(@NotNull final IpnbFileEditor editor) {
final IpnbFilePanel filePanel = editor.getIpnbFilePanel();
final IpnbEditablePanel selectedCellPanel = filePanel.getSelectedCellPanel();
if (selectedCellPanel == null)
return;
final IpnbEditableCell cell = selectedCellPanel.getCell();
final List<IpnbCell> cells = filePanel.getIpnbFile().getCells();
final int index = cells.indexOf(selectedCellPanel.getCell());
final IpnbHeadingCell heading = new IpnbHeadingCell(cell.getSource(), myLevel, cell.getMetadata());
if (index >= 0) {
cells.set(index, heading);
}
filePanel.replaceComponent(selectedCellPanel, heading);
}
use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel in project intellij-community by JetBrains.
the class IpnbParser method newDocumentText.
@Nullable
public static String newDocumentText(@NotNull final IpnbFilePanel ipnbPanel) {
final IpnbFile ipnbFile = ipnbPanel.getIpnbFile();
if (ipnbFile == null)
return null;
for (IpnbEditablePanel panel : ipnbPanel.getIpnbPanels()) {
if (panel.isModified()) {
panel.updateCellSource();
}
}
final IpnbFileRaw fileRaw = new IpnbFileRaw();
fileRaw.metadata = ipnbFile.getMetadata();
if (ipnbFile.getNbformat() == 4) {
for (IpnbCell cell : ipnbFile.getCells()) {
fileRaw.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat()));
}
} else {
final IpnbWorksheet worksheet = new IpnbWorksheet();
worksheet.cells.clear();
for (IpnbCell cell : ipnbFile.getCells()) {
worksheet.cells.add(IpnbCellRaw.fromCell(cell, ipnbFile.getNbformat()));
}
fileRaw.worksheets = new IpnbWorksheet[] { worksheet };
}
final StringWriter stringWriter = new StringWriter();
final JsonWriter writer = new JsonWriter(stringWriter);
writer.setIndent(" ");
gson.toJson(fileRaw, fileRaw.getClass(), writer);
return stringWriter.toString();
}
use of org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel in project intellij-community by JetBrains.
the class IpnbPyReference method multiResolve.
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
ResolveResult[] results = super.multiResolve(incompleteCode);
if (results.length == 0) {
PsiFile file = myElement.getContainingFile();
if (file instanceof IpnbPyFragment) {
final IpnbFilePanel panel = ((IpnbPyFragment) file).getFilePanel();
final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
final String referencedName = myElement.getReferencedName();
if (referencedName == null)
return ResolveResult.EMPTY_ARRAY;
for (IpnbEditablePanel editablePanel : panels) {
if (!(editablePanel instanceof IpnbCodePanel))
continue;
final Editor editor = ((IpnbCodePanel) editablePanel).getEditor();
final IpnbPyFragment psiFile = (IpnbPyFragment) PsiDocumentManager.getInstance(myElement.getProject()).getPsiFile(editor.getDocument());
if (psiFile == null)
continue;
final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
PyResolveUtil.scopeCrawlUp(processor, psiFile, referencedName, psiFile);
final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, psiFile, psiFile);
if (resultList.size() > 0) {
List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
return ret.toArray(new RatedResolveResult[ret.size()]);
}
}
}
}
return results;
}
Aggregations