terrine

改造easyexplore插件

easyexplore是一个eclipse的小插件,它能直接打开选中文件所在的目录,虽然只有几K的体积,却给我们带来了很大的方便。不过为了追求更高的易用性,我在dev2dev的一篇文章的基础上(这篇文章似乎漏掉了一些改动,而且易用性还是不够高:),对它进行了一点小小的改进,改进后的功能(仅适用于windows)是:

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);
        }
    }
重新编译打包之后,替换掉org.sf.easyexplore_1.0.4.jar中的easyexplore.jar和图标,搞定收工。
放了一个自己修改过的jar上来,欢迎大家从这里下载。

另外推荐一个好用的bookmark插件quickmarks,可以通过Ctrl,Alt和数字键非常快捷的创建和跳回书签,类似于JBuilder和IDEA的功能,比eclipse自带的bookmark强太多了。项目地址是http://eclipse-tools.sourceforge.net/quickmarks

posted on 2007-06-02 22:54 Jay 阅读(3172) 评论(5)  编辑  收藏

评论

# re: 改造easyexplore插件 2007-06-03 09:58 CowNew开源团队

把这个修改提交给他们呀,这样所有的人都能使用这个增强的功能了。:)。  回复  更多评论   

# re: 改造easyexplore插件 2007-06-04 09:29 Welkin Hu

我用的是从sf下载的jar包。是只有一个Easy Explorer菜单的版本。楼主所说的增强特性,在这个版本中已经是这样了。  回复  更多评论   

# re: 改造easyexplore插件 2007-06-04 16:20 hcqenjoy

Welkin Hu 我下载的怎么不是你说的版本?? 能提供下你的版本吗  回复  更多评论   

# re: 改造easyexplore插件 2007-06-04 21:07 Jay

@Welkin Hu
可以提供一个下载的链接吗,我下载的是1.0.4版本的 都没有这个功能  回复  更多评论   

# re: 改造easyexplore插件[未登录] 2008-12-29 11:43 Dennis

不错的enhancement,本来我也想改,给你抢先了,hoho  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: