use of com.intellij.openapi.actionSystem.CustomShortcutSet in project intellij-community by JetBrains.
the class CopyrightProfilesPanel method createActions.
@Override
@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
ArrayList<AnAction> result = new ArrayList<>();
result.add(new DumbAwareAction("Add", "Add", IconUtil.getAddIcon()) {
{
registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}
@Override
public void actionPerformed(AnActionEvent event) {
String name = askForProfileName("Create Copyright Profile", "");
if (name != null) {
addProfileNode(new CopyrightProfile(name));
}
}
});
result.add(new MyDeleteAction());
result.add(new DumbAwareAction("Copy", "Copy", PlatformIcons.COPY_ICON) {
{
registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK)), myTree);
}
@Override
public void actionPerformed(AnActionEvent event) {
String profileName = askForProfileName("Copy Copyright Profile", "");
if (profileName == null) {
return;
}
CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom((CopyrightProfile) getSelectedObject());
clone.setName(profileName);
addProfileNode(clone);
}
@Override
public void update(AnActionEvent event) {
super.update(event);
event.getPresentation().setEnabled(getSelectedObject() != null);
}
});
result.add(new DumbAwareAction("Import", "Import", PlatformIcons.IMPORT_ICON) {
@Override
public void actionPerformed(AnActionEvent event) {
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(file -> {
final FileType fileType = file.getFileType();
return fileType != PlainTextFileType.INSTANCE && (fileType == StdFileTypes.IDEA_MODULE || fileType == StdFileTypes.XML);
}).withTitle("Choose File Containing Copyright Notice");
FileChooser.chooseFile(descriptor, myProject, null, file -> {
final List<CopyrightProfile> profiles = ExternalOptionHelper.loadOptions(VfsUtilCore.virtualToIoFile(file));
if (profiles == null)
return;
if (!profiles.isEmpty()) {
if (profiles.size() == 1) {
importProfile(profiles.get(0));
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import", profiles) {
@Override
public PopupStep onChosen(final CopyrightProfile selectedValue, boolean finalChoice) {
return doFinalStep(() -> importProfile(selectedValue));
}
@NotNull
@Override
public String getTextFor(CopyrightProfile value) {
return value.getName();
}
}).showUnderneathOf(myNorthPanel);
}
} else {
Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure");
}
});
}
private void importProfile(CopyrightProfile copyrightProfile) {
final String profileName = askForProfileName("Import copyright profile", copyrightProfile.getName());
if (profileName == null)
return;
copyrightProfile.setName(profileName);
addProfileNode(copyrightProfile);
Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.", "Import Complete");
}
});
return result;
}
use of com.intellij.openapi.actionSystem.CustomShortcutSet in project intellij-community by JetBrains.
the class SvnConfigureProxiesComponent method createActions.
protected ArrayList<AnAction> createActions(final boolean fromPopup) {
ArrayList<AnAction> result = new ArrayList<>();
result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {
{
registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}
public void actionPerformed(AnActionEvent event) {
addGroup(null);
}
});
result.add(new MyDeleteAction(forAll(o -> {
if (o instanceof MyNode) {
final MyNode node = (MyNode) o;
if (node.getConfigurable() instanceof GroupConfigurable) {
final ProxyGroup group = ((GroupConfigurable) node.getConfigurable()).getEditableObject();
return !group.isDefault();
}
}
return false;
})) {
public void actionPerformed(final AnActionEvent e) {
final TreePath path = myTree.getSelectionPath();
final MyNode node = (MyNode) path.getLastPathComponent();
final MyNode parentNode = (MyNode) node.getParent();
int idx = parentNode.getIndex(node);
super.actionPerformed(e);
idx = (idx == parentNode.getChildCount()) ? idx - 1 : idx;
if (parentNode.getChildCount() > 0) {
final TreePath newSelectedPath = new TreePath(parentNode.getPath()).pathByAddingChild(parentNode.getChildAt(idx));
myTree.setSelectionPath(newSelectedPath);
}
}
});
result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {
{
registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
}
public void actionPerformed(AnActionEvent event) {
// apply - for update of editable object
try {
getSelectedConfigurable().apply();
} catch (ConfigurationException e) {
// suppress & wait for OK
}
final ProxyGroup selectedGroup = (ProxyGroup) getSelectedObject();
if (selectedGroup != null) {
addGroup(selectedGroup);
}
}
public void update(AnActionEvent event) {
super.update(event);
event.getPresentation().setEnabled(getSelectedObject() != null);
}
});
return result;
}
use of com.intellij.openapi.actionSystem.CustomShortcutSet in project intellij-community by JetBrains.
the class IpnbFileEditor method registerHeadingActions.
private void registerHeadingActions() {
new IpnbHeading1CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 1")), myIpnbFilePanel);
new IpnbHeading2CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 2")), myIpnbFilePanel);
new IpnbHeading3CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 3")), myIpnbFilePanel);
new IpnbHeading4CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 4")), myIpnbFilePanel);
new IpnbHeading5CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 5")), myIpnbFilePanel);
new IpnbHeading6CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 6")), myIpnbFilePanel);
}
Aggregations