Search in sources :

Example 1 with CopyrightProfile

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);
}
Also used : CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 2 with CopyrightProfile

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;
}
Also used : NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 3 with CopyrightProfile

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);
}
Also used : Element(org.jdom.Element) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 4 with CopyrightProfile

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);
}
Also used : Element(org.jdom.Element) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 5 with CopyrightProfile

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;
}
Also used : InputEvent(java.awt.event.InputEvent) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) java.util(java.util) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) HashMap(com.intellij.util.containers.HashMap) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CopyrightManager(com.intellij.copyright.CopyrightManager) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) PlatformIcons(com.intellij.util.PlatformIcons) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) TreePath(javax.swing.tree.TreePath) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) AnAction(com.intellij.openapi.actionSystem.AnAction) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) ExternalOptionHelper(com.maddyhome.idea.copyright.options.ExternalOptionHelper) FileType(com.intellij.openapi.fileTypes.FileType) KeyEvent(java.awt.event.KeyEvent) MasterDetailsStateService(com.intellij.openapi.ui.MasterDetailsStateService) Nullable(org.jetbrains.annotations.Nullable) CommonShortcuts(com.intellij.openapi.actionSystem.CommonShortcuts) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) InputValidator(com.intellij.openapi.ui.InputValidator) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CopyrightProfile (com.maddyhome.idea.copyright.CopyrightProfile)10 Project (com.intellij.openapi.project.Project)2 HashMap (com.intellij.util.containers.HashMap)2 Element (org.jdom.Element)2 Nullable (org.jetbrains.annotations.Nullable)2 CopyrightManager (com.intellij.copyright.CopyrightManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonShortcuts (com.intellij.openapi.actionSystem.CommonShortcuts)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)1 FileType (com.intellij.openapi.fileTypes.FileType)1 PlainTextFileType (com.intellij.openapi.fileTypes.PlainTextFileType)1 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)1 Module (com.intellij.openapi.module.Module)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1