Eclipse:如何在项目资源管理器中隐藏自定义文件

57

我在 CDT 中有一个自定义构建器,会将很多文件添加到项目目录中。我希望这些文件被从“项目资源管理器”中过滤掉,但是无法找出方法(文件掩码是 *.ooj)。

是否可以通过文件掩码添加自定义过滤器到“自定义视图”中?或者也许有其他方法隐藏“项目资源管理器”中的文件?

4个回答

108
以下是如何在Eclipse Indigo/Luna/Neon上进行操作(截至2018年5月22日):
  • 打开项目属性
    • 下拉菜单-->项目-->属性
    • 会出现一个名为“属性”的新对话框
  • 创建“资源过滤器”
    • 选择资源-->资源过滤器->添加过滤器...
    • 会出现一个名为“为项目添加资源过滤器”的新对话框
    • 在新对话框中选择以下内容:
      • 过滤器类型:排除全部
      • 适用于:文件
      • 一定要勾选“All children (recusive)”复选框
      • 文件和文件夹属性
        • 选择:名称
        • 选择:匹配
        • 填写:*.ooj
      • 点击确定
      • 对话框关闭
  • 应用新的过滤器
    • 点击应用
    • 您应该会在“导航器”视图中看到变化
  • 关闭“项目属性”
    • 点击确定
  • 完成

1
当我这样做时,我的文件夹会隐藏,但立即又会出现。我该怎么办? - John Alexander Betts
如果您想对所有项目进行此操作,可以在包资源管理器栏中单击向下指向的三角形(在最小化图标旁边),然后从中选择“过滤器”。然后只需将筛选器(您可以使用正则表达式)添加到顶部文本区域即可。 - ceiroa
无法在Indigo上运行。似乎曾经可以运行一次,但现在不行了。 - Duck Dodgers

4
如何向Eclipse项目浏览器视图添加全局用户定义资源过滤器:
在项目级别上修改和切换过滤器需要很多点击,如果您在工作区中有许多项目,则可能会变得乏味。如果您需要一遍又一遍地在所有项目上应用或切换相同的过滤器设置,则可能更喜欢所有项目和工作区的更快速且全局的解决方案。
  • Modify the files plugin.xml and plugin.properties in plugins/org.eclipse.ui.navigator.resources_{version}.jar (extract, modify and re-add the modified files).

  • For example, add a file only filter in plugin.xml to the element /plugin/extension @point="org.eclipse.ui.navigator.navigatorContent":

    <commonFilter id="org.eclipse.ui.navigator.resources.filters.{unique-id-a}" name="%filters.{unique-id-a}.name" description="%filters.{unique-id-a}.description" activeByDefault="true|false">
       <filterExpression>
          <and>
             <instanceof value="org.eclipse.core.resources.IFile"/>
             <test property="org.eclipse.core.resources.name" value="{file-wildcard-pattern-a}"/>
          </and>
       </filterExpression>
    </commonFilter>
    
  • As another example, add a file and directory filter in plugin.xml to the same element:

    <commonFilter id="org.eclipse.ui.navigator.resources.filters.{unique-id-b}" name="%filters.{unique-id-b}.name" description="%filters.{unique-id-b}.description" activeByDefault="true|false">
       <filterExpression>
          <and>
             <adapt type="org.eclipse.core.resources.IResource">
                <test property="org.eclipse.core.resources.name" value="{file-wildcard-pattern-b}"/>
             </adapt>
          </and>
       </filterExpression>
    </commonFilter>
    
  • Provide filter names and descriptions for all added filters in plugin.properties. Filter display order in Project Explorer view is by this filter name regardless of filter type:

    filters.{unique-id-a}.name={file-wildcard-pattern-a} files
    filters.{unique-id-a}.description=Hides files that match "{file-wildcard-pattern-a}"
    
    filters.{unique-id-b}.name={file-wildcard-pattern-b} files and folders
    filters.{unique-id-b}.description=Hides files and folders that match "{file-wildcard-pattern-b}"
    
  • Restart Eclipse and reset its caches: eclipse.exe -clean


酷!这正是我想要隐藏 *.orig 文件(从 hg/git 合并)的东西:这个有效: <commonFilter id="org.eclipse.ui.navigator.resources.filters.origFiles" name="%filters.origFiles.name" description="%filters.origFiles.description" activeByDefault="false"> <filterExpression> <adapt type="org.eclipse.core.resources.IFile"> <test property="org.eclipse.core.resources.name" value="*.orig" /> </adapt> </filterExpression> </commonFilter> 对于 plugin.xml 和... - Andreas Covidiot
继续我的先前评论:filters.origFiles.name=*.orig resources filters.origFiles.description=隐藏以“.orig”结尾的资源,如版本控制系统合并(例如Mercurial/HG、GIT)生成的资源。插件属性文件 plugins.properties。在执行 eclipse -clean后,所有内容在Eclipse Kepler中都是可用的 :) - Andreas Covidiot
通过Remote Systems插件(可能已经包含在您的Eclipse发行版中),这个设置非常容易,无需额外的应用程序((解压缩器、文件导航器等):1. 转到(或Window-> Show View-> Remote Systems),2. Local->...->org.eclipse.ui.navigator.resources_<version>.jar->plugins.xml/plugins.properties->双击,3. 在两个文件中编辑/插入所需的内容,4. Remote Systems->...->plugins.xml/plugins.properties->右键单击->同步缓存 :) - Andreas Covidiot

3
您可以定义一个过滤器来实现此功能。在“包资源管理器”中打开视图菜单,然后选择“过滤器...”在这里您可以定义一个模式来隐藏文件。

3
“查看菜单”没有“筛选器”选项。我需要点击“自定义视图”才能访问“筛选器”。但是只有预定义的筛选器,例如“归档文件”,“Java文件”等,而没有添加/编辑这些筛选器的选项。 - rmflow
你使用哪个版本的Eclipse? - Kai
2
Eclipse 3.7(Indigo)在他提到的菜单中拥有一个名为“Name filter patterns”的可自定义过滤器,但是就我所知,Juno已经将其移除。不知道为什么。 - fwonce
1
@rmflowless 新版本默认使用“Project Explorer”。您需要使用“Package Explorer”进行过滤。 - lilalinux

2

首先感谢 @emmzett 只是想以详细的方式解释 emmzett 答案中的内容,因为我不知道如何编辑插件文件而且我在这上面花费了2个小时。也许我可以通过这个明确的表达来节省你的时间。

  1. Firstly go in eclipse file then plugins->org.eclipse.ui.navigator.resources_(your eclipse version).jar
  2. Right click to .jar file and open with winrar
  3. Find the plugin.xml open with an editor(notepad,Notepad++ etc) the plugin.xml file
  4. Find the point="org.eclipse.ui.navigator.navigatorContent" and paste code below
    <commonFilter id="org.eclipse.ui.navigator.resources.filters.<i>SpecifyAnIdForYourFileType</i>" 
                 name="%filters.<i>SpecifyAnIdForYourFileType</i>.name" 
                 description="%filters.<i>SpecifyAnIdForYourFileType</i>.description"
                 activeByDefault="true">
      <filterExpression>
          <and>
             <instanceof value="org.eclipse.core.resources.IFile"/>
             <test property="org.eclipse.core.resources.name" value="<i>your specific file</i>"/>
          </and>
       </filterExpression>
    </commonFilter>
  5. Change SpecifyAnIdForYourFileType with a unique name for id Change "your specific file" with your specific file suffix like *.pdf or desktop.ini etc.
  6. Save the plugin.xml and exit
  7. Find the plugin.properties open with an editor same as 3.step Paste this code
    filters.<i>SpecifyAnIdForYourFileType</i>.name=<i>your specific file</i> files
    filters.<i>SpecifyAnIdForYourFileType</i>.description=Hides files that match <i>your specific file</i>
  8. Save plugin.properties and exit
  9. Restart the eclipse and clear cache than go to Project Explorer at the left side
  10. Click the View Menu icon at the top right corner
  11. Click the Filters and Customization...
  12. Tick your new filter in the Filters menu.

我想再次感谢emmzett。这就是我想表达的全部内容。

祝好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接