Search in sources :

Example 11 with PyOpenAction

use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.

the class PyEdit method createActions.

/*
     * (non-Javadoc)
     *
     * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
     *
     * TODO: Fix content assist to work in emacs mode:
     * http://wiki.eclipse.org/index.php/FAQ_How_do_I_add_Content_Assist_to_my_editor%3F
     * http://www.eclipse.org/newsportal/article.php?id=61744&group=eclipse.platform#61744
     */
@Override
protected void createActions() {
    super.createActions();
    try {
        MyResources resources = new MyResources();
        IAction action;
        // Quick-Assist: it's added to the platform as of Eclipse 3.2, so, we do not have to put the binding here
        // -------------------------------------------------------------------------------------
        // This action will fire a CONTENTASSIST_PROPOSALS operation
        // when executed
        action = new ContentAssistAction(resources, "ContentAssistProposal.", this);
        action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
        setAction("ContentAssistProposal", action);
        markAsStateDependentAction("ContentAssistProposal", true);
        // -------------------------------------------------------------------------------------
        // open action
        IAction openAction = new PyOpenAction();
        setAction(ACTION_OPEN, openAction);
        // -------------------------------------------------------------------------------------
        // Offline action
        action = new OfflineAction(resources, "Pyedit.ScriptEngine.", this);
        action.setActionDefinitionId("org.python.pydev.editor.actions.scriptEngine");
        action.setId("org.python.pydev.editor.actions.scriptEngine");
        setAction("PyDevScriptEngine", action);
        // move lines
        if (this.getIndentPrefs().getSmartLineMove()) {
            // Don't even bind the action if the smart line move is not set.
            // This means 2 things:
            // - Uses the default action when asked
            // - An editor restart will be needed to have it applied
            action = new PyMoveLineUpAction(resources, "Pyedit.MoveLinesUp.", this);
            action.setActionDefinitionId(ITextEditorActionDefinitionIds.MOVE_LINES_UP);
            action.setId("org.python.pydev.editor.actions.moveLineUp");
            setAction(ITextEditorActionConstants.MOVE_LINE_UP, action);
            action = new PyMoveLineDownAction(resources, "Pyedit.MoveLinesDown.", this);
            action.setActionDefinitionId(ITextEditorActionDefinitionIds.MOVE_LINES_DOWN);
            action.setId("org.python.pydev.editor.actions.moveLineDown");
            setAction(ITextEditorActionConstants.MOVE_LINE_DOWN, action);
        }
        notifier.notifyOnCreateActions(resources);
        onCreateActions.call(this);
    } catch (Throwable e) {
        Log.log(e);
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) PyMoveLineUpAction(org.python.pydev.editor.actions.PyMoveLineUpAction) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) OfflineAction(org.python.pydev.editor.actions.OfflineAction) PyMoveLineDownAction(org.python.pydev.editor.actions.PyMoveLineDownAction) ContentAssistAction(org.eclipse.ui.texteditor.ContentAssistAction)

Example 12 with PyOpenAction

use of org.python.pydev.editor.actions.PyOpenAction in project Pydev by fabioz.

the class HierarchyViewer method createPartControl.

public void createPartControl(Composite parent) {
    this.fParent = parent;
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 2;
    parent.setLayout(layout);
    sash = new SashForm(parent, SWT.VERTICAL);
    GridData layoutData = new GridData();
    layoutData.grabExcessHorizontalSpace = true;
    layoutData.grabExcessVerticalSpace = true;
    layoutData.horizontalAlignment = GridData.FILL;
    layoutData.verticalAlignment = GridData.FILL;
    sash.setLayoutData(layoutData);
    parent = sash;
    treeClassesViewer = new TreeViewer(parent);
    treeClassesViewer.setContentProvider(new DataAndImageTreeNodeContentProvider());
    treeClassesViewer.setLabelProvider(createLabelProvider());
    treeClassesViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            handleSelection(selection, 2);
        }
    });
    treeClassesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            handleSelection(selection, 1);
        }
    });
    treeMembers = new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    treeMembers.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            TreeItem[] selection = treeMembers.getSelection();
            if (selection.length > 0) {
                Object data = selection[0].getData();
                ItemPointer p = (ItemPointer) data;
                if (p != null) {
                    new PyOpenAction().run(p);
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DataAndImageTreeNodeContentProvider(org.python.pydev.shared_ui.quick_outline.DataAndImageTreeNodeContentProvider) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 13 with PyOpenAction

use of org.python.pydev.editor.actions.PyOpenAction 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;
                }
            }
        }
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IPythonNature(org.python.pydev.core.IPythonNature) ArrayList(java.util.ArrayList) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) ICompletionState(org.python.pydev.core.ICompletionState) CompletionState(org.python.pydev.ast.codecompletion.revisited.CompletionState) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) ICompletionState(org.python.pydev.core.ICompletionState) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Aggregations

PyOpenAction (org.python.pydev.editor.actions.PyOpenAction)13 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)11 IFile (org.eclipse.core.resources.IFile)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3 PartInitException (org.eclipse.ui.PartInitException)3 CoreException (org.eclipse.core.runtime.CoreException)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Point (org.eclipse.swt.graphics.Point)2 IModule (org.python.pydev.core.IModule)2 IPythonNature (org.python.pydev.core.IPythonNature)2 PyEdit (org.python.pydev.editor.PyEdit)2 AdditionalInfoAndIInfo (com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo)1 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)1 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1