Search in sources :

Example 11 with ICallback

use of org.python.pydev.shared_core.callbacks.ICallback in project Pydev by fabioz.

the class AbstractSearchIndexResultPage method fillContextMenu.

@Override
protected void fillContextMenu(IMenuManager mgr) {
    super.fillContextMenu(mgr);
    fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
    fActionGroup.fillContextMenu(mgr);
    AbstractSearchIndexQuery query = (AbstractSearchIndexQuery) getInput().getQuery();
    if (query.getSearchString().length() > 0) {
        IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
        if (!selection.isEmpty()) {
            ReplaceAction replaceSelection = new ReplaceAction(getSite().getShell(), getInput(), selection.toArray(), true);
            replaceSelection.setText(SearchMessages.ReplaceAction_label_selected);
            mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection);
        }
        ICallback<Boolean, Match> skipMatch = new ICallback<Boolean, Match>() {

            @Override
            public Boolean call(Match match) {
                StructuredViewer viewer = getViewer();
                ViewerFilter[] filters = viewer.getFilters();
                if (filters == null || filters.length == 0) {
                    return false;
                }
                for (ViewerFilter viewerFilter : filters) {
                    if (viewerFilter instanceof AbstractSearchResultsViewerFilter) {
                        AbstractSearchResultsViewerFilter searchResultsViewerFilter = (AbstractSearchResultsViewerFilter) viewerFilter;
                        if (searchResultsViewerFilter.isLeafMatch(viewer, match)) {
                            return false;
                        }
                    }
                }
                return true;
            }
        };
        ReplaceAction replaceAll = new ReplaceAction(getSite().getShell(), getInput(), null, true, skipMatch);
        replaceAll.setText(SearchMessages.ReplaceAction_label_all);
        mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);
    }
}
Also used : ICallback(org.python.pydev.shared_core.callbacks.ICallback) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ActionContext(org.eclipse.ui.actions.ActionContext) ReplaceAction(org.python.pydev.shared_ui.search.replace.ReplaceAction) Match(org.eclipse.search.ui.text.Match)

Example 12 with ICallback

use of org.python.pydev.shared_core.callbacks.ICallback in project Pydev by fabioz.

the class DebuggerReader method run.

/**
 * keep reading until we finish (that should happen when an exception is thrown, or if it is set as
 * done from outside)
 *
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    HttpProtocolUtils httpProtocol = new HttpProtocolUtils();
    ICallback<String, Object> onUnexpectedMessage = (unexpectedMessage) -> {
        String msg = "It seems an old version of the PyDev Debugger is being used (please update the pydevd package being used).\n\nFound message:\n" + unexpectedMessage;
        RunInUiThread.async(() -> {
            PyDialogHelpers.openCritical("Error", msg);
        });
        Log.log(msg);
        return null;
    };
    while (!done) {
        String contents;
        try {
            if ((contents = httpProtocol.readContents(in, onUnexpectedMessage)) == null) {
                done = true;
            } else {
                if (contents.length() > 0) {
                    processCommand(contents.toString());
                }
            }
        } catch (Exception e1) {
            done = true;
            // that's ok, it means that the client finished
            if (DEBUG) {
                e1.printStackTrace();
            }
        }
        if (done || socket == null || !socket.isConnected()) {
            AbstractDebugTarget target = remote;
            if (target != null) {
                target.terminate();
            }
            done = true;
        }
    }
}
Also used : Socket(java.net.Socket) AbstractDebugTarget(org.python.pydev.debug.model.AbstractDebugTarget) IOException(java.io.IOException) RunInUiThread(org.python.pydev.shared_ui.utils.RunInUiThread) PyDialogHelpers(org.python.pydev.ui.dialogs.PyDialogHelpers) PydevDebugPlugin(org.python.pydev.debug.core.PydevDebugPlugin) IStatus(org.eclipse.core.runtime.IStatus) AbstractDebugTargetWithTransmission(org.python.pydev.debug.model.AbstractDebugTargetWithTransmission) HttpProtocolUtils(org.python.pydev.shared_core.io.HttpProtocolUtils) ICallback(org.python.pydev.shared_core.callbacks.ICallback) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) Log(org.python.pydev.core.log.Log) InputStream(java.io.InputStream) HttpProtocolUtils(org.python.pydev.shared_core.io.HttpProtocolUtils) AbstractDebugTarget(org.python.pydev.debug.model.AbstractDebugTarget) IOException(java.io.IOException)

Example 13 with ICallback

use of org.python.pydev.shared_core.callbacks.ICallback in project Pydev by fabioz.

the class IndexApi method main.

public static void main(String[] args) throws IOException {
    File f = new File("x:\\index");
    final IndexApi indexApi = new IndexApi(f, true);
    ICallback<Object, java.nio.file.Path> onFile = new ICallback<Object, java.nio.file.Path>() {

        @Override
        public Object call(java.nio.file.Path path) {
            String string = path.toString();
            if (string.endsWith(".py")) {
                try (SeekableByteChannel sbc = Files.newByteChannel(path);
                    InputStream in = Channels.newInputStream(sbc)) {
                    Reader reader = new BufferedReader(new InputStreamReader(in));
                    IPath path2 = Path.fromOSString(string);
                    indexApi.index(path2, FileUtils.lastModified(path.toFile()), reader, IFields.GENERAL_CONTENTS);
                } catch (Exception e) {
                    Log.log("Error parsing: " + path, e);
                }
            }
            return null;
        }
    };
    Timer timer = new Timer();
    // FileUtils.visitDirectory(new File("x:\\etk"), true, onFile);
    // indexApi.commit();
    indexApi.setMaxMatches(Integer.MAX_VALUE);
    SearchResult searchResult = indexApi.searchRegexp(".*", IFields.GENERAL_CONTENTS, true);
    System.out.println("Matched: " + searchResult.getNumberOfDocumentMatches());
    timer.printDiff("Total time");
// indexApi.dispose();
// indexApi.index(filepath, modifiedTime, general);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) InputStreamReader(java.io.InputStreamReader) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) DirectoryReader(org.apache.lucene.index.DirectoryReader) Reader(java.io.Reader) IndexReader(org.apache.lucene.index.IndexReader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SeekableByteChannel(java.nio.channels.SeekableByteChannel) ICallback(org.python.pydev.shared_core.callbacks.ICallback) Timer(org.python.pydev.shared_core.utils.Timer) BufferedReader(java.io.BufferedReader) File(java.io.File)

Aggregations

ICallback (org.python.pydev.shared_core.callbacks.ICallback)13 File (java.io.File)6 IDocument (org.eclipse.jface.text.IDocument)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 MisconfigurationException (org.python.pydev.core.MisconfigurationException)3 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Document (org.eclipse.jface.text.Document)2 IPythonNature (org.python.pydev.core.IPythonNature)2 PythonNature (org.python.pydev.plugin.nature.PythonNature)2 InterpreterResponse (org.python.pydev.shared_interactive_console.console.InterpreterResponse)2