Search in sources :

Example 6 with CopyrightProfile

use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.

the class UpdateCopyrightProcessor method preprocessFile.

protected Runnable preprocessFile(final PsiFile file, final boolean allowReplacement) throws IncorrectOperationException {
    VirtualFile vfile = file.getVirtualFile();
    if (vfile == null)
        return EmptyRunnable.getInstance();
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null) {
        progressIndicator.setText2(vfile.getPresentableUrl());
    }
    Module mod = module;
    if (module == null) {
        mod = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vfile);
    }
    if (mod == null)
        return EmptyRunnable.getInstance();
    CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(file);
    if (opts != null && FileTypeUtil.isSupportedFile(file)) {
        logger.debug("process " + file);
        final UpdateCopyright update = UpdateCopyrightFactory.createUpdateCopyright(project, mod, file, opts);
        if (update == null)
            return EmptyRunnable.getInstance();
        update.prepare();
        if (update instanceof UpdatePsiFileCopyright && !((UpdatePsiFileCopyright) update).hasUpdates())
            return EmptyRunnable.getInstance();
        return () -> {
            try {
                if (update instanceof UpdatePsiFileCopyright) {
                    ((UpdatePsiFileCopyright) update).complete(allowReplacement);
                } else {
                    update.complete();
                }
            } catch (Exception e) {
                logger.error(e);
            }
        };
    } else {
        return EmptyRunnable.getInstance();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Module(com.intellij.openapi.module.Module) UpdateCopyright(com.maddyhome.idea.copyright.psi.UpdateCopyright) UpdatePsiFileCopyright(com.maddyhome.idea.copyright.psi.UpdatePsiFileCopyright) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 7 with CopyrightProfile

use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.

the class ExternalOptionHelper method loadOptions.

@Nullable
public static List<CopyrightProfile> loadOptions(File file) {
    try {
        List<CopyrightProfile> profiles = new ArrayList<>();
        Element root = JDOMUtil.load(file);
        if (root.getName().equals("component")) {
            final Element copyrightElement = root.getChild("copyright");
            if (copyrightElement != null)
                extractNewNoticeAndKeyword(copyrightElement, profiles);
        } else {
            for (Element component : root.getChildren("component")) {
                String name = component.getAttributeValue("name");
                if (name.equals("CopyrightManager")) {
                    for (Object o : component.getChildren("copyright")) {
                        extractNewNoticeAndKeyword((Element) o, profiles);
                    }
                } else if (name.equals("copyright")) {
                    extractNoticeAndKeyword(component, profiles);
                }
            }
        }
        return profiles;
    } catch (Exception e) {
        logger.info(e);
        Messages.showErrorDialog(e.getMessage(), "Import Failure");
        return null;
    }
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with CopyrightProfile

use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.

the class CopyrightProfilesPanel method getAllProfiles.

public Map<String, CopyrightProfile> getAllProfiles() {
    final Map<String, CopyrightProfile> profiles = new HashMap<>();
    if (!myInitialized.get()) {
        for (CopyrightProfile profile : myManager.getCopyrights()) {
            profiles.put(profile.getName(), profile);
        }
    } else {
        for (int i = 0; i < myRoot.getChildCount(); i++) {
            MyNode node = (MyNode) myRoot.getChildAt(i);
            final CopyrightProfile copyrightProfile = ((CopyrightConfigurable) node.getConfigurable()).getEditableObject();
            profiles.put(copyrightProfile.getName(), copyrightProfile);
        }
    }
    return profiles;
}
Also used : HashMap(com.intellij.util.containers.HashMap) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 9 with CopyrightProfile

use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.

the class ProjectSettingsPanel method reloadCopyrightProfiles.

public void reloadCopyrightProfiles() {
    final DefaultComboBoxModel boxModel = (DefaultComboBoxModel) myProfilesComboBox.getModel();
    boxModel.removeAllElements();
    boxModel.addElement(null);
    for (CopyrightProfile profile : myProfilesModel.getAllProfiles().values()) {
        boxModel.addElement(profile);
    }
}
Also used : CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

Example 10 with CopyrightProfile

use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.

the class AbstractFileProcessor method findFiles.

private static void findFiles(List<PsiFile> files, PsiDirectory directory, boolean subdirs) {
    final Project project = directory.getProject();
    PsiFile[] locals = directory.getFiles();
    for (PsiFile local : locals) {
        CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(local);
        if (opts != null && FileTypeUtil.isSupportedFile(local)) {
            files.add(local);
        }
    }
    if (subdirs) {
        for (PsiDirectory dir : directory.getSubdirectories()) {
            findFiles(files, dir, true);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile)

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