use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class CopyrightProfilesPanel method reloadTree.
private void reloadTree() {
myRoot.removeAllChildren();
Collection<CopyrightProfile> collection = myManager.getCopyrights();
for (CopyrightProfile profile : collection) {
CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom(profile);
addNode(new MyNode(new CopyrightConfigurable(myProject, clone, TREE_UPDATER)), myRoot);
}
myInitialized.set(true);
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class ProjectSettingsPanel method isModified.
public boolean isModified() {
CopyrightProfile defaultCopyright = myManager.getDefaultCopyright();
final Object selected = myProfilesComboBox.getSelectedItem();
if (defaultCopyright != selected && (selected == null || defaultCopyright == null || !defaultCopyright.equals(selected))) {
return true;
}
final Map<String, String> map = myManager.getScopeToCopyright();
if (map.size() != myScopeMappingModel.getItems().size())
return true;
final Iterator<String> iterator = map.keySet().iterator();
for (ScopeSetting setting : myScopeMappingModel.getItems()) {
final NamedScope scope = setting.getScope();
if (!iterator.hasNext())
return true;
final String scopeName = iterator.next();
if (scope == null || !Comparing.strEqual(scopeName, scope.getName()))
return true;
final String profileName = map.get(scope.getName());
if (profileName == null)
return true;
if (!profileName.equals(setting.getProfileName()))
return true;
}
return false;
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class ExternalOptionHelper method extractNewNoticeAndKeyword.
public static void extractNewNoticeAndKeyword(Element valueElement, List<CopyrightProfile> profiles) {
CopyrightProfile profile = new CopyrightProfile();
boolean extract = false;
for (Object l : valueElement.getChildren("option")) {
extract |= extract(profile, (Element) l);
}
if (extract)
profiles.add(profile);
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class ExternalOptionHelper method extractNoticeAndKeyword.
public static void extractNoticeAndKeyword(Element valueElement, List<CopyrightProfile> profiles) {
CopyrightProfile profile = new CopyrightProfile();
boolean extract = false;
for (Object l : valueElement.getChildren("LanguageOptions")) {
if (((Element) l).getAttributeValue("name").equals("__TEMPLATE__")) {
for (Object o1 : ((Element) l).getChildren("option")) {
extract |= extract(profile, (Element) o1);
}
break;
}
}
if (extract)
profiles.add(profile);
}
use of com.maddyhome.idea.copyright.CopyrightProfile 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;
}
Aggregations