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);
}
}
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;
}
}
}
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);
}
Aggregations