liu_shui8 发表于 2013-1-15 02:45:46

改造easyexplore插件

1.如果选中的是目录,则在资源管理器中打开这个目录(而不是在它的上级选中该目录);2.如果选中的是文件,则资源管理器中打开所在的文件夹并选中这个文件;另外,顺便把新的xp风格图标给拿了过来。

easyexplore的cvs地址是anonymous@easystruts.cvs.sourceforge.net:/cvsroot/easystruts,下载源码之后发现easyexplore已经悄悄的更新了,多了“执行外部命令”等功能,图标也改成xp风格,不过多了一层子菜单,感觉不如原来方便,而且我只对explore这个功能感兴趣,所以只取回org/sf/easyexplore/EasyExplorePlugin.java,org/sf/easyexplore/actions/EasyExploreAction.java和org/sf/easyexplore/preferences/EasyExplorePreferencePage.java三个文件的1.1版本进行修改。代码是相当的简单:

在EasyExplorePlugin.java中改变defaultTagert的值:
protected void initializeDefaultPreferences(IPreferenceStore store) {      String defaultTarget = "shell_open_command {0}";      String osName = System.getProperty("os.name");      if ( osName.indexOf("Windows") != -1 ) {            defaultTarget = "explorer.exe /e,";      }      else if ( osName.indexOf("Mac") != -1 ) {            defaultTarget = "open";                  }                store.setDefault(EasyExplorePreferencePage.P_TARGET, defaultTarget);    }
在EasyExploreAction.java中增加一个判断条件,如果选中的文件那么在资源管理器中也选中之:
public void run(IAction action) {      try {            if ( "unknown".equals(selected) ) {                MessageDialog.openInformation(new Shell(),"Easy Explore","Unable to explore " + selectedClass.getName());                EasyExplorePlugin.log("Unable to explore " + selectedClass);                return;            }            File directory = null;            if ( selected instanceof IResource ) {                directory= new File(((IResource)selected).getLocation().toOSString());            } else if ( selected instanceof File ) {                directory= (File) selected;            }             String target = EasyExplorePlugin.getDefault().getTarget();                        if (!EasyExplorePlugin.getDefault().isSupported()) {                MessageDialog.openInformation(new Shell(),"Easy Explore",                  "This platform (" +                     System.getProperty("os.name") +                     ") is currently unsupported.\n" +                     "You can try to provide the correct command to execute in the Preference dialog.\n" +                  "If you succeed, please be kind to post your discovery on EasyExplore website http://sourceforge.net/projects/easystruts,\n" +                  "or by email farialima@users.sourceforge.net. Thanks !");                return;            }            if(directory.isFile()               && System.getProperty("os.name").indexOf("Windows") != -1 ) {                target = target.trim() + "/select,";            }            if ( target.indexOf("{0}") == -1 ) {                target = target.trim() + " {0}";            }                            target = MessageFormat.format(target, new String[]{directory.toString()});                        try {               EasyExplorePlugin.log("running: "+target);                Runtime.getRuntime().exec(target);            } catch ( Throwable t ) {                MessageDialog.openInformation(new Shell(),"Easy Explore","Unable to execute " +target);                EasyExplorePlugin.log(t);            }      } catch (Throwable e) {            EasyExplorePlugin.log(e);      }    }
页: [1]
查看完整版本: 改造easyexplore插件