public void testModifyFileTypes() throws Exception { EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ((FileTypeManagerEx)FileTypeManager.getInstance()).fireBeforeFileTypesChanged(); ((FileTypeManagerEx)FileTypeManager.getInstance()).fireFileTypesChanged(); } }); String string = listener.getEventsString(); String expected = "beforePropertyChange propFileTypes\n" + "propertyChanged propFileTypes\n"; assertEquals(expected, string); }
public void testIgnoreOrder() { final FileTypeManagerEx manager = FileTypeManagerEx.getInstanceEx(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { manager.setIgnoredFilesList("a;b;"); } }); assertEquals("a;b;", manager.getIgnoredFilesList()); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { manager.setIgnoredFilesList("b;a;"); } }); assertEquals("b;a;", manager.getIgnoredFilesList()); }
private static void showUsages(@NotNull JPanel panel, @Nullable TextDescriptor exampleUsage) { String text = ""; FileType fileType = PlainTextFileType.INSTANCE; if (exampleUsage != null) { try { text = exampleUsage.getText(); String name = exampleUsage.getFileName(); FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); String extension = fileTypeManager.getExtension(name); fileType = fileTypeManager.getFileTypeByExtension(extension); } catch (IOException e) { LOG.error(e); } } ((ActionUsagePanel)panel.getComponent(0)).reset(text, fileType); panel.repaint(); }
public FileTemplatesLoader(@NotNull FileTypeManagerEx typeManager) { myTypeManager = typeManager; myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, ROOT_DIR); myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, INTERNAL_DIR, true); myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, INCLUDES_DIR); myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, CODE_TEMPLATES_DIR); myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, J2EE_TEMPLATES_DIR); myAllManagers = new FTManager[]{ myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager}; myDirToManagerMap.put("", myDefaultTemplatesManager); myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager); myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager); myDirToManagerMap.put(CODE_TEMPLATES_DIR + "/", myCodeTemplatesManager); myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager); loadDefaultTemplates(); }
@Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder .setTitle(GroovyBundle.message("newclass.dlg.title")) .addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS) .addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE); if (GroovyConfigUtils.getInstance().isVersionAtLeast(directory, GroovyConfigUtils.GROOVY2_3, true)) { builder.addKind("Trait", JetgroovyIcons.Groovy.Trait, GroovyTemplates.GROOVY_TRAIT); } builder .addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM) .addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION); for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) { builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName()); } } }
public void testModifyFileTypes() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ((FileTypeManagerEx)FileTypeManager.getInstance()).fireBeforeFileTypesChanged(); ((FileTypeManagerEx)FileTypeManager.getInstance()).fireFileTypesChanged(); } }); String string = listener.getEventsString(); String expected = "beforePropertyChange\n" + "propertyChanged\n"; assertEquals(expected, string); }
public FileTemplateManagerImpl(@NotNull FileTypeManagerEx typeManager, ProjectManager pm /*need this to ensure disposal of the service _after_ project manager*/) { myTypeManager = typeManager; myTemplateSettings = ExportableFileTemplateSettings.getInstance(); assert myTemplateSettings != null : "Can not instantiate " + ExportableFileTemplateSettings.class.getName(); myInternalTemplatesManager = myTemplateSettings.getInternalTemplatesManager(); myDefaultTemplatesManager = myTemplateSettings.getDefaultTemplatesManager(); myPatternsManager = myTemplateSettings.getPatternsManager(); myCodeTemplatesManager = myTemplateSettings.getCodeTemplatesManager(); myJ2eeTemplatesManager = myTemplateSettings.getJ2eeTemplatesManager(); myAllManagers = myTemplateSettings.getAllManagers(); if (ApplicationManager.getApplication().isUnitTestMode()) { for (String tname : Arrays.asList("Class", "AnnotationType", "Enum", "Interface")) { for (FileTemplate template : myInternalTemplatesManager.getAllTemplates(true)) { if (tname.equals(template.getName())) { myInternalTemplatesManager.removeTemplate(((FileTemplateBase)template).getQualifiedName()); break; } } final FileTemplateBase template = myInternalTemplatesManager.addTemplate(tname, "java"); template.setText(normalizeText(getTestClassTemplateText(tname))); } } }
public FileTemplatesLoader(@NotNull FileTypeManagerEx typeManager) { myTypeManager = typeManager; myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, ROOT_DIR); myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, INTERNAL_DIR, true); myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, INCLUDES_DIR); myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, CODETEMPLATES_DIR); myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, J2EE_TEMPLATES_DIR); myAllManagers = new FTManager[]{ myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager}; myDirToManagerMap.put("", myDefaultTemplatesManager); myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager); myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager); myDirToManagerMap.put(CODETEMPLATES_DIR + "/", myCodeTemplatesManager); myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager); loadDefaultTemplates(); for (FTManager child : myAllManagers) { loadCustomizedContent(child); } }
@Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder .setTitle(GroovyBundle.message("newclass.dlg.title")) .addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS) .addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE) .addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM) .addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION); for (FileTemplate template : FileTemplateManager.getInstance().getAllTemplates()) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) { builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName()); } } }
private static void showUsages(@Nonnull JPanel panel, @Nullable TextDescriptor exampleUsage) { String text = ""; FileType fileType = PlainTextFileType.INSTANCE; if (exampleUsage != null) { try { text = exampleUsage.getText(); String name = exampleUsage.getFileName(); FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); String extension = fileTypeManager.getExtension(name); fileType = fileTypeManager.getFileTypeByExtension(extension); } catch (IOException e) { LOG.error(e); } } ((ActionUsagePanel)panel.getComponent(0)).reset(text, fileType); panel.repaint(); }
public FileTemplateManagerImpl(@Nonnull FileTypeManagerEx typeManager, FileTemplateSettings projectSettings, ExportableFileTemplateSettings defaultSettings, /*need this to ensure disposal of the service _after_ project manager*/ @SuppressWarnings("UnusedParameters") ProjectManager pm, final Project project) { myTypeManager = typeManager; myProjectSettings = projectSettings; myDefaultSettings = defaultSettings; myProject = project; myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") { @Nonnull @Override public String getTemplatesDir() { return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR); } @Nonnull @Override public Project getProject() { return project; } }; }
protected FileTemplatesLoader(@Nonnull FileTypeManagerEx typeManager, @Nullable Project project) { myTypeManager = typeManager; File configDir = project == null || project.isDefault() ? new File(PathManager.getConfigPath(), TEMPLATES_DIR) : new File(UriUtil.trimTrailingSlashes(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR)); myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, configDir); myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, new File(configDir, INTERNAL_DIR), true); myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, new File(configDir, INCLUDES_DIR)); myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, new File(configDir, CODE_TEMPLATES_DIR)); myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, new File(configDir, J2EE_TEMPLATES_DIR)); myAllManagers = new FTManager[]{myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager}; myDirToManagerMap.put("", myDefaultTemplatesManager); myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager); myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager); myDirToManagerMap.put(CODE_TEMPLATES_DIR + "/", myCodeTemplatesManager); myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager); loadDefaultTemplates(); for (FTManager manager : myAllManagers) { manager.loadCustomizedContent(); } }
public void testPlainTextSubstitution() throws IOException { FileTypeManagerEx.getInstanceEx().registerFileType(MockLanguageFileType.INSTANCE, "xxx"); try { configureFromFileText("a.xxx", "aaa a<caret>"); complete(); checkResultByText("aaa aaa<caret>"); } finally { FileTypeManagerEx.getInstanceEx().unregisterFileType(MockLanguageFileType.INSTANCE); } }
public void testChangeIgnoreList() throws Exception { VirtualFile newDir = createChildDirectory(myModule1Dir, "newDir"); assertInProject(newDir); final FileTypeManagerEx fileTypeManager = (FileTypeManagerEx)FileTypeManager.getInstance(); final String list = fileTypeManager.getIgnoredFilesList(); final String list1 = list + ";" + "newDir"; try { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { fileTypeManager.setIgnoredFilesList(list1); } }); assertNotInProject(newDir); } finally { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { fileTypeManager.setIgnoredFilesList(list); } }); assertInProject(newDir); } }
@Override protected void setUp() throws Exception { super.setUp(); myFileTypeManager = (FileTypeManagerImpl)FileTypeManagerEx.getInstanceEx(); myOldIgnoredFilesList = myFileTypeManager.getIgnoredFilesList(); FileTypeManagerImpl.reDetectAsync(true); }
public void testRegexpCharsAreNotTreatedAsSeparateWords() { FileType regExpFileType = FileTypeManagerEx.getInstanceEx().findFileTypeByName("RegExp"); assertNotNull(regExpFileType); myFixture.configureByText(regExpFileType, "<caret>abc"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD); myFixture.checkResult("abc<caret>"); }
static void addAndRemoveFileType() { FileType foo = new FakeFileType() { @Override public boolean isMyFileType(@NotNull VirtualFile file) { return true; } @NotNull @Override public String getName() { return "foo"; } @NotNull @Override public String getDescription() { return ""; } }; FileTypeIndex index = new FileTypeIndex(FileTypeManager.getInstance()); int version = index.getVersion(); try { FileTypeManagerEx.getInstanceEx().registerFileType(foo); assertNotSame(version, index.getVersion()); } finally { FileTypeManagerEx.getInstanceEx().unregisterFileType(foo); } }
private static boolean isFileName(String name) { final int index = name.lastIndexOf('.'); if (index > 0) { String ext = name.substring(index + 1); if (ext.contains(":")) { ext = ext.substring(0, ext.indexOf(':')); } if (FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(ext) != UnknownFileType.INSTANCE) { return true; } } return false; }
/** * Registers the given file type with IntelliJ IDEA. * * @param fileType The file type to register. */ public static void register(final IMetaborgFileType fileType) { FileTypeManagerEx.getInstanceEx().registerFileType(fileType); // Associate the file type with its file extensions. final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (final String ext : fileType.getExtensions()) { final FileNameMatcher matcher = new ExtensionFileNameMatcher(ext); fileTypeManager.associate(fileType, matcher); } }
public void updateFileIcons() { ApplicationManager.getApplication().runWriteAction(() -> { final FileTypeManagerEx instanceEx = FileTypeManagerEx.getInstanceEx(); instanceEx.fireFileTypesChanged(); ActionToolbarImpl.updateAllToolbarsImmediately(); }); }
public void testChangeIgnoreList() throws Exception { myModule1Dir.createChildDirectory(this, "newDir"); myIndex.checkConsistency(); final FileTypeManagerEx fileTypeManager = (FileTypeManagerEx)FileTypeManager.getInstance(); final String list = fileTypeManager.getIgnoredFilesList(); final String list1 = list + ";" + "newDir"; try { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { fileTypeManager.setIgnoredFilesList(list1); } }); myIndex.checkConsistency(); } finally { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { fileTypeManager.setIgnoredFilesList(list); } }); } }
static void addAndRemoveFileType() { FileType foo = new FakeFileType() { @Override public boolean isMyFileType(VirtualFile file) { return true; } @NotNull @Override public String getName() { return "foo"; } @NotNull @Override public String getDescription() { return ""; } }; FileTypeIndex index = new FileTypeIndex(FileTypeManager.getInstance()); int version = index.getVersion(); try { FileTypeManagerEx.getInstanceEx().registerFileType(foo); assertNotSame(version, index.getVersion()); } finally { FileTypeManagerEx.getInstanceEx().unregisterFileType(foo); } }
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return; } final VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); final VirtualFile file = virtualFiles != null && virtualFiles.length == 1 ? virtualFiles[0] : null; if (file == null) { return; } Language currentLanguage = file.getUserData(FilesLanguageSubstitutor.LANGUAGE_KEY); if (currentLanguage != null && currentLanguage.getID().equals(language.getID())) { return; } Application application = ApplicationManager.getApplication(); application.runWriteAction(() -> { try { file.putUserData(FilesLanguageSubstitutor.LANGUAGE_KEY, language); FileTypeManagerEx.getInstanceEx().fireFileTypesChanged(); StatusBar statusBar = WindowManager.getInstance().getStatusBar(project); FileLanguagePanel fileLanguage = (FileLanguagePanel) (statusBar != null ? statusBar.getWidget("FileLanguage") : null); if (fileLanguage != null) { fileLanguage.doUpdate(); } } catch (Exception e1) { LOG.warn(e1); } }); }
public void testAddFileType() throws Exception { FileType foo = new FakeFileType() { @Override public boolean isMyFileType(VirtualFile file) { return true; } @Nonnull @Override public String getName() { return "foo"; } @Nonnull @Override public String getDescription() { return ""; } }; FileTypeIndex index = new FileTypeIndex(FileTypeManager.getInstance()); int version = index.getVersion(); try { FileTypeManagerEx.getInstanceEx().registerFileType(foo); assertNotSame(version, index.getVersion()); } finally { FileTypeManagerEx.getInstanceEx().unregisterFileType(foo); } }
public boolean handlesTemplate(final FileTemplate template) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); return fileType.equals(StdFileTypes.JAVA) && !FileTemplateUtil.INTERNAL_PACKAGE_INFO_TEMPLATE_NAME.equals(template.getName()); }
private static void showUsages(final JPanel panel, final TitledSeparator separator, final List<IntentionUsagePanel> usagePanels, @Nullable final TextDescriptor[] exampleUsages) throws IOException { GridBagConstraints gb = null; boolean reuse = exampleUsages != null && panel.getComponents().length == exampleUsages.length; if (!reuse) { disposeUsagePanels(usagePanels); panel.setLayout(new GridBagLayout()); panel.removeAll(); gb = new GridBagConstraints(); gb.anchor = GridBagConstraints.NORTHWEST; gb.fill = GridBagConstraints.BOTH; gb.gridheight = GridBagConstraints.REMAINDER; gb.gridwidth = 1; gb.gridx = 0; gb.gridy = 0; gb.insets = new Insets(0,0,0,0); gb.ipadx = 5; gb.ipady = 5; gb.weightx = 1; gb.weighty = 1; } if (exampleUsages != null) { for (int i = 0; i < exampleUsages.length; i++) { final TextDescriptor exampleUsage = exampleUsages[i]; final String name = exampleUsage.getFileName(); final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); final String extension = fileTypeManager.getExtension(name); final FileType fileType = fileTypeManager.getFileTypeByExtension(extension); IntentionUsagePanel usagePanel; if (reuse) { usagePanel = (IntentionUsagePanel)panel.getComponent(i); } else { usagePanel = new IntentionUsagePanel(); usagePanels.add(usagePanel); } usagePanel.reset(exampleUsage.getText(), fileType); if (!reuse) { if (i == exampleUsages.length) { gb.gridwidth = GridBagConstraints.REMAINDER; } panel.add(usagePanel, gb); gb.gridx++; } } } panel.revalidate(); panel.repaint(); }
public static boolean canCreateFromTemplate (PsiDirectory[] dirs, FileTemplate template) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); if (fileType.equals(FileTypes.UNKNOWN)) return false; CreateFromTemplateHandler handler = findHandler(template); return handler.canCreate(dirs); }
public ExportableFileTemplateSettings(@NotNull FileTypeManagerEx typeManager) { super(typeManager); }
@Override public boolean isTemplateOfType(@NotNull final FileType fType) { return fType.equals(FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(getExtension())); }
public boolean handlesTemplate(final FileTemplate template) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); return fileType.equals(StdFileTypes.GUI_DESIGNER_FORM); }
public boolean handlesTemplate(final FileTemplate template) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); return fileType.equals(StdFileTypes.JAVA); }
private SchemesManager<FileType, AbstractFileType> getSchemesManager() { return ((FileTypeManagerEx)FileTypeManager.getInstance()).getSchemesManager(); }