easyexplore是一個(gè)eclipse的小插件,它能直接打開選中文件所在的目錄,雖然只有幾K的體積,卻給我們帶來(lái)了很大的方便。不過(guò)為了追求更高的易用性,我在dev2dev的一篇
文章的基礎(chǔ)上(這篇文章似乎漏掉了一些改動(dòng),而且易用性還是不夠高:),對(duì)它進(jìn)行了一點(diǎn)小小的改進(jìn),改進(jìn)后的功能(僅適用于windows)是:
1.如果選中的是目錄,則在資源管理器中打開這個(gè)目錄(而不是在它的上級(jí)選中該目錄);2.如果選中的是文件,則資源管理器中打開所在的文件夾并選中這個(gè)文件;另外,順便把新的xp風(fēng)格圖標(biāo)給拿了過(guò)來(lái)。
easyexplore的cvs地址是anonymous@easystruts.cvs.sourceforge.net:/cvsroot/easystruts,下載源碼之后發(fā)現(xiàn)easyexplore已經(jīng)悄悄的更新了,多了“執(zhí)行外部命令”等功能,圖標(biāo)也改成xp風(fēng)格,不過(guò)多了一層子菜單,感覺不如原來(lái)方便,而且我只對(duì)explore這個(gè)功能感興趣,所以只取回org/sf/easyexplore/EasyExplorePlugin.java,org/sf/easyexplore/actions/EasyExploreAction.java和org/sf/easyexplore/preferences/EasyExplorePreferencePage.java三個(gè)文件的1.1版本進(jìn)行修改。代碼是相當(dāng)?shù)暮?jiǎn)單:
在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中增加一個(gè)判斷條件,如果選中的文件那么在資源管理器中也選中之:
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和圖標(biāo),搞定收工。
放了一個(gè)自己修改過(guò)的jar上來(lái),歡迎大家從
這里下載。
另外推薦一個(gè)好用的bookmark插件quickmarks,可以通過(guò)Ctrl,Alt和數(shù)字鍵非常快捷的創(chuàng)建和跳回書簽,類似于JBuilder和IDEA的功能,比eclipse自帶的bookmark強(qiáng)太多了。項(xiàng)目地址是
http://eclipse-tools.sourceforge.net/quickmarks