How to provide custom search/find scope

Initial situation: https://plugins.jetbrains.com/plugin/9913-rollback (my plugin "rollback")

What im looking for:

I would like to use custom file scopes (generated by my plugin) as option under STRG+F to perform a search.

So you could say (for example!):

1. "Lets make a diff, compare HEAD vs master, because master its my parent branch and i want to create a pull request"

2. "Before i create my pullrequest i want to take a last look over all my changes based on my custom diff and have a look for some specific things like var_dump() "

 

Another approach:

I could add a Text-Search-Input as Filter Option under the File Tree. Already while typing the custom diff shows only these files left with a search-match....

 

Yet Another approach:

Export a XML-File and do everything else outside

0
Avatar
Permanently deleted user
正式评论

Don't know what that means: "any scope you want to create to". Anyway, in the absence of details, the generalized way to create your own scope should be:

- write your own implementation of com.intellij.psi.search.scope.packageSet.CustomScopesProvider and register it in your plugin.xml

- in that scope provider return your own implementation of com.intellij.psi.search.scope.packageSet.NamedScope where override method "contains" with your membership logic.

As an example please refer to the com.intellij.psi.search.scope.TestsScope and com.intellij.packageDependencies.TestScopeProvider sources.

Avatar
Permanently deleted user

Hi, as for file scopes try NamedScopeManager to add your own NamedScope.

0

PatternPackageSet patternPackageSet = new PatternPackageSet("*", PatternPackageSet.SCOPE_ANY, null);
NamedScope xScope = new NamedScope("xxx", patternPackageSet);
NamedScopeManager scopeManager = NamedScopeManager.getInstance(this.myToolWindowFactory.project);
scopeManager.addScope(xScope);

..Okay, so whats next? How can i add my Files?

I have:

Collection<Change> changes;


So i can do something like this with it:

for (Change change : this.changes) {
VirtualFile vFile = change.getVirtualFile();
if (vFile == null) {
continue;
}
String changePath = change.getVirtualFile().getPath();
...


How can we put these guys together :-P ?
0
Avatar
Permanently deleted user

What files your scope needs to contain? For files eligible for VCS commit there is predefined "Changed files" scope already.

 

0

any scope you want to create to. please have a look on my plugin and what it already does.

0
Avatar
Permanently deleted user

Michael, your own implementation of PackageSet should answer the 'contains' question.

0

Aaaaah.... Thank you!

0

Oh oh oh... strange bug here....

 

Left side of Screenshot: My Development Editor

Right side: Testing

 

At this moment when the porgramm do anything with Scopes with the scopeManager (2 Lines left) the user LOST the focus of the Editor and jump to "Project"-Tool-Window.

 

How can i avoid this?

0
Avatar
Permanently deleted user

Actually you cannot and it looks like a bug, pretty old one.

But why don't you reuse your scope? Do you really need to create new one again and again?

0

yeah man. why? :-) thanks...

- thats it-

0

请先登录再写评论。