mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
smart select/unselect api
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.ide;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public interface SmartSelectProvider<T> {
|
||||
ExtensionPointName<SmartSelectProvider> EP = ExtensionPointName.create("smartSelectProvider");
|
||||
|
||||
void increaseSelection(T source);
|
||||
|
||||
void decreaseSelection(T source);
|
||||
|
||||
default boolean isEnabled(DataContext context) {
|
||||
return getSource(context) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
T getSource(DataContext context);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.ide.SmartSelectProvider;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class SmartSelect extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
SmartSelectProvider provider = getProvider(e.getDataContext());
|
||||
assert provider != null;
|
||||
//noinspection unchecked
|
||||
provider.increaseSelection(provider.getSource(e.getDataContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(getProvider(e.getDataContext()) != null);
|
||||
}
|
||||
|
||||
public SmartSelectProvider getProvider(DataContext context) {
|
||||
for (SmartSelectProvider provider : SmartSelectProvider.EP.getExtensions()) {
|
||||
if (provider.isEnabled(context)) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ide.SmartSelectProvider;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class SmartUnSelect extends SmartSelect {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
SmartSelectProvider provider = getProvider(e.getDataContext());
|
||||
assert provider != null;
|
||||
//noinspection unchecked
|
||||
provider.decreaseSelection(provider.getSource(e.getDataContext()));
|
||||
}
|
||||
}
|
||||
@@ -290,6 +290,7 @@
|
||||
<extensionPoint name="reporting.sendPermission" interface="com.intellij.reporting.DataSendPermission"/>
|
||||
|
||||
<extensionPoint name="tasks.contextProvider" interface="com.intellij.tasks.context.WorkingContextProvider" area="IDEA_PROJECT"/>
|
||||
<extensionPoint name="smartSelectProvider" interface="com.intellij.openapi.ide.SmartSelectProvider"/>
|
||||
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
<keyboard-shortcut first-keystroke="shift ENTER" keymap="$default"/>
|
||||
</action>>
|
||||
<action id="SearchEverywhere" class="com.intellij.ide.actions.SearchEverywhereAction" />
|
||||
<action id="SmartSelect" class="com.intellij.ide.actions.SmartSelect" use-shortcut-of="EditorSelectWord"/>
|
||||
<action id="SmartUnSelect" class="com.intellij.ide.actions.SmartUnSelect" use-shortcut-of="EditorUnSelectWord"/>
|
||||
|
||||
<group id="TemplateParametersNavigation">
|
||||
<action id="NextTemplateParameter" class="com.intellij.codeInsight.completion.NextPrevParameterAction$Next" text="Next Parameter">
|
||||
|
||||
Reference in New Issue
Block a user