use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PyCopyQualifiedName method run.
@Override
public void run(IAction action) {
FastStringBuffer buf = new FastStringBuffer();
try {
PyEdit pyEdit = getPyEdit();
PySelection pySelection = PySelectionFromEditor.createPySelectionFromEditor(pyEdit);
IPythonNature nature = pyEdit.getPythonNature();
File editorFile = pyEdit.getEditorFile();
if (editorFile != null) {
if (nature != null) {
String mod = nature.resolveModule(editorFile);
if (mod != null) {
buf.append(mod);
} else {
// Support for external files (not in PYTHONPATH).
buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
}
} else {
buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
}
}
List<stmtType> path = FastParser.parseToKnowGloballyAccessiblePath(pySelection.getDoc(), pySelection.getStartLineIndex());
for (stmtType stmtType : path) {
if (buf.length() > 0) {
buf.append('.');
}
buf.append(NodeUtils.getRepresentationString(stmtType));
}
} catch (MisconfigurationException e1) {
Log.log(e1);
return;
}
Transfer[] dataTypes = new Transfer[] { TextTransfer.getInstance() };
Object[] data = new Object[] { buf.toString() };
Clipboard clipboard = new Clipboard(EditorUtils.getShell().getDisplay());
try {
clipboard.setContents(data, dataTypes);
} catch (SWTError e) {
if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
throw e;
}
MessageDialog.openError(EditorUtils.getShell(), "Error copying to clipboard.", e.getMessage());
} finally {
clipboard.dispose();
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PyRemoveBlockComment method run.
/**
* Grabs the selection information and performs the action.
*/
@Override
public void run(IAction action) {
try {
if (!canModifyEditor()) {
return;
}
// Select from text editor
PyEdit pyEdit = getPyEdit();
PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(getTextEditor());
// Perform the action
Tuple<Integer, Integer> repRegion = perform(ps);
if (repRegion == null) {
return;
}
// Put cursor at the first area of the selection
pyEdit.selectAndReveal(repRegion.o1, repRegion.o2);
} catch (Exception e) {
beep(e);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PyScopeSelection method run.
@Override
public void run(IAction action) {
try {
PyEdit editor = getPyEdit();
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
new ScopeSelectionAction().perform(doc, new CoreTextSelection(doc, selection.getOffset(), selection.getLength()), editor);
} catch (Exception e) {
Log.log(e);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PySelectWord method run.
@Override
public void run(IAction action) {
PyEdit pyEdit = getPyEdit();
PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(pyEdit);
try {
Tuple<String, Integer> currToken = ps.getCurrToken();
if (currToken.o1 != null) {
int len = currToken.o1.length();
if (len > 0) {
pyEdit.selectAndReveal(currToken.o2, len);
}
}
} catch (Exception e) {
Log.log(e);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class PyToggleForceTabs method updateActionState.
private void updateActionState(IIndentPrefs indentPrefs) {
// This doesn't work! (setChecked and setImageDescriptor don't seem to update the action in the pop up menu).
// setChecked(forceTabs);
// setImageDescriptor(desc);
PyEdit pyEdit = getPyEdit();
pyEdit.updateForceTabsMessage();
}
Aggregations