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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6137848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:12:37  来源:igfitidea点击:

Eclipse: how to hide custom files in Project Explorer

eclipseeclipse-cdt

提问by rmflow

I have a custom builder in CDT, which adds alot of files into project directory. I want those files to be filtered out from Project Explorer, but cannot figure out how (the file mask is *.ooj).

我在 CDT 中有一个自定义构建器,它将大量文件添加到项目目录中。我希望从项目资源管理器中过滤掉这些文件,但无法弄清楚如何(文件掩码是 *.ooj)。

Is it possible to add a custom filter by file mask into Customize View? Or maybe there is anther way to hide files in Project Explorer?

是否可以通过文件掩码将自定义过滤器添加到自定义视图中?或者也许有另一种方法可以在项目资源管理器中隐藏文件?

回答by Colm Ryan

Here's how to do it on Eclipse Indigo/Luna/Neon (as of 2018-05-22):

以下是在 Eclipse Indigo/Luna/Neon 上的操作方法(截至 2018-05-22):

  • Open the "project properties"
    • pull down menu --> Project --> Properties
    • A new dialog window named "Properties" will appear
  • Create a "Resource Filter"
    • Select Resource --> Resource Filters -> Add Filter...
    • A new dialog window named "Add Resource Filter for project" will appear
    • In the new dialog select the following
      • Filter Type: Exclude All
      • Applies to: Files
      • Make sure to click the checkbox for "All children (recusive)"
      • File and Folder Attributes
        • select: Name
        • select: Matches
        • fill in: *.ooj
      • Click OK
      • Dialog closes
  • Apply the new filter
    • Click Apply
    • You should see a change in your "Navigator" View
  • Close the "Project Properties"
    • Click OK
  • Done
  • 打开“项目属性”
    • 下拉菜单 --> 项目 --> 属性
    • 将出现一个名为“属性”的新对话窗口
  • 创建“资源过滤器”
    • 选择资源 --> 资源过滤器 -> 添加过滤器...
    • 将出现一个名为“为项目添加资源过滤器”的新对话窗口
    • 在新对话框中选择以下内容
      • 过滤器类型:排除所有
      • 适用于:文件
      • 确保单击“所有孩子(递归)”复选框
      • 文件和文件夹属性
        • 选择:名称
        • 选择:匹配
        • 填写:*.ooj
      • 单击确定
      • 对话框关闭
  • 应用新过滤器
    • 点击应用
    • 您应该会在“导航器”视图中看到更改
  • 关闭“项目属性”
    • 单击确定
  • 完毕

回答by Kai

You can define a filter for that. Open the view menu in the Package Explorer and then choose "Filters..." Here you can define a pattern to hide files.

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

回答by emmzett

How to add global user defined resource filters to the Eclipse Project Explorer view:

如何将全局用户定义的资源过滤器添加到 Eclipse Project Explorer 视图:

Modifying and switching filters on a project level needs a lot of clicks and can be tedious if you have many projects in your workspace. If you need to apply or switch the same filter settings on all projects again and again you might prefer a quicker and global solution for all projects and all workspaces.

在项目级别修改和切换过滤器需要多次单击,如果您的工作区中有许多项目,则可能会很乏味。如果您需要一次又一次地在所有项目上应用或切换相同的过滤器设置,您可能更喜欢针对所有项目和所有工作区的更快的全局解决方案。

  • Modify the files plugin.xmland plugin.propertiesin 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.xmlto 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.xmlto 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

  • 修改文件plugin.xmlplugin.properties输入plugins/org.eclipse.ui.navigator.resources_{version}.jar(提取、修改和重新添加修改后的文件)。

  • 例如,plugin.xml在元素中添加一个仅文件过滤器/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>
    
  • 再举一个例子,plugin.xml在同一个元素中添加一个文件和目录过滤器:

    <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>
    
  • 为 中所有添加的过滤器提供过滤器名称和描述plugin.properties。Project Explorer 视图中的过滤器显示顺序是按此过滤器名称,而不管过滤器类型如何:

    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}"
    
  • 重新启动 Eclipse 并重置其缓存: eclipse.exe -clean

回答by omerbguclu

Firstly thanks to @emmzett Just wanna explain in a verbose mode of emmzett's answer because I didn't know anything editing plugin files and I spent 2 hours on this. Maybe I can save your time with this clarified expression.

首先感谢@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.xmlopen with an editor(notepad,Notepad++ etc) the plugin.xmlfile
  4. Find the point="org.eclipse.ui.navigator.navigatorContent"and paste code below
    <commonFilter id="org.eclipse.ui.navigator.resources.filters.SpecifyAnIdForYourFileType" 
                 name="%filters.SpecifyAnIdForYourFileType.name" 
                 description="%filters.SpecifyAnIdForYourFileType.description"
                 activeByDefault="true">
      <filterExpression>
          <and>
             <instanceof value="org.eclipse.core.resources.IFile"/>
             <test property="org.eclipse.core.resources.name" value="your specific file"/>
          </and>
       </filterExpression>
    </commonFilter>
  5. Change SpecifyAnIdForYourFileTypewith a unique name for id Change "your specific file"with your specific file suffix like *.pdfor desktop.inietc.
  6. Save the plugin.xmland exit
  7. Find the plugin.propertiesopen with an editor same as 3.step Paste this code
    filters.SpecifyAnIdForYourFileType.name=your specific file files
    filters.SpecifyAnIdForYourFileType.description=Hides files that match your specific file
  8. Save plugin.propertiesand exit
  9. Restart the eclipse and clear cache than go to Project Explorerat the left side
  10. Click the View Menuicon at the top right corner
  11. Click the Filters and Customization...
  12. Tick your new filter in the Filtersmenu.
  1. 首先进入eclipse文件然后 plugins->org.eclipse.ui.navigator.resources_(你的eclipse版本).jar
  2. 右键单击 .jar 文件并使用 winrar 打开
  3. 找到plugin.xml用编辑器(记事本、记事本++等)打开的 plugin.xml文件
  4. 找到point="org.eclipse.ui.navigator.navigatorContent"并粘贴下面的代码
    <commonFilter id="org.eclipse.ui.navigator.resources.filters.SpecifyAnIdForYourFileType" 
                 name="%filters.SpecifyAnIdForYourFileType.name" 
                 description="%filters.SpecifyAnIdForYourFileType.description"
                 activeByDefault="true">
      <filterExpression>
          <and>
             <instanceof value="org.eclipse.core.resources.IFile"/>
             <test property="org.eclipse.core.resources.name" value="your specific file"/>
          </and>
       </filterExpression>
    </commonFilter>
  5. 更改SpecifyAnIdForYourFileType为 id 的唯一名称更改"your specific file"为您的特定文件后缀,例如*.pdfdesktop.ini等。
  6. 保存plugin.xml并退出
  7. plugin.properties使用与3.step相同的编辑器找到open 粘贴此代码
    filters.SpecifyAnIdForYourFileType.name=your specific file files
    filters.SpecifyAnIdForYourFileType.description=Hides files that match your specific file
  8. 保存plugin.properties并退出
  9. 重新启动eclipse并清除缓存而不是Project Explorer在左侧
  10. 点击右上角的View Menu图标
  11. 点击 Filters and Customization...
  12. Filters菜单中勾选您的新过滤器。

That's all I want to thanks again to emmzett.

这就是我要再次感谢 emmzett 的全部内容。

Regards.

问候。