簡體   English   中英

Eclipse RCP:文件關聯(--launcher.openFile)

[英]Eclipse RCP: File association (--launcher.openFile)

我正在開發蝕產品,我需要將文件擴展名與我的編輯器關聯。 我遵循了幾個示例(如thisthis ),但似乎編輯器曾經收到過SWT OpenDocument事件。

如fileAssociation示例中所述,我創建了一個eventListener類來處理SWT.OpenDocument事件,並在調用PlatformUI.createAndRunWorkbench()方法之前將其添加到我的Application類中,以顯示在屏幕上。

public Object start(IApplicationContext context) throws Exception {
Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 
OpenDocumentEventProcessor eProc = new OpenDocumentEventProcessor();
Display display = PlatformUI.createDisplay();
display.addListener(SWT.OpenDocument, eProc);
try{
    if(!handleWorkspace(display)){
        System.exit(0);
        return IApplication.EXIT_OK;
    }
int returnCode = PlatformUI.createAndRunWorkbench(display, new XVRWorkbenchAdvisor(args, eProc));

在產品文件中,我添加了以下程序參數:

--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-name
XVR Studio Developer

如果我在一個新的空RCP項目中使用相同的代碼,它的工作原理就像一個魅力。

我不知道這可能是問題。

你能幫助我嗎?

非常感謝!!

當我剛剛為RCP應用程序完成這項工作時,我認為在此處記錄我的操作方式並提供參考將很有幫助。

  1. 我沒有用'context.getArguments()..','OpenDocumentEventProcessor'處理了所有事情。
  2. 我建議這樣做不起作用的原因是-name值與'org.eclipse.core.runtime.products'擴展點中'appName'屬性的值不匹配。 可以肯定的是,我從appName屬性和-name中刪除了空格。 然后它起作用了。

非常有用的參考資料是:

對於基本編碼: http : //help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm

有關其工作原理的說明: http : //aniefer.blogspot.co.uk/2010/05/opening-files-in-eclipse-from-command.html

使我困惑了一段時間的一個小問題是,在名稱中有空格的地方,分幾塊獲取文件的路徑。 最終,我意識到(瞬間!),我需要在文件關聯的安裝程序(InstallAware)定義中的%1參數周圍加上引號-即它變成了“%1”

這種方法對我來說是未知的,但是由於您粘貼的代碼中沒有顯式的編輯器調用,我想您仍然依靠eclipse來決定必須打開哪個編輯器。 因此,我想您仍然必須聲明性地定義內容類型和文件關聯。 為此,請為“ org.eclipse.core.contenttype.contentTypes”擴展名添加一個“文件關聯”(文件擴展名...)。 在插件xml中獲取編輯器聲明,並添加先前創建的“ contentTypeBinding” ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM