2009-07-20 144 views
2

我認爲在Eclipse RCP中有與編輯器相關的默認SAVE和CANCEL按鈕。我們如何讓這些按鈕出現在編輯器上。Eclipse RCP:如何在編輯器中顯示默認SAVE按鈕?

我認爲這些按鈕在默認情況下是不可見的,可能有一些超類方法需要被覆蓋以使SAVE CANCEL按鈕出現在編輯器上。我記得聽說過這樣的事情。 (雖然我可能是錯的)

無論如何,我們該如何實現? (PS:我不是在尋找一個自定義的SWT按鈕並將其命名爲'SAVE'。我正在尋找一個與編輯器相關的默認保存按鈕(如果有的話))。

回答

3

這些按鈕與您的編輯沒有直接關係。
你必須像described there)

  • 添加菜單貢獻與commandId設置爲標準命令ID可以在IWorkbenchActionDefinitionIds如發現org.eclipse.ui.file.save

  • ApplicationActionBarAdvisor.makeActions中創建一個命令並進行註冊。

protected void makeActions(final IWorkbenchWindow window) { 
    // Creates the actions and registers them. 
    // Registering is needed to ensure that key bindings work. 
    // The corresponding commands keybindings are defined in the plugin.xml 
    // file. 
    // Registering also provides automatic disposal of the actions when 
    // the window is closed. 
    saveAction = ActionFactory.SAVE.create(window); 
    register(saveAction); 
} 
  • 添加髒標誌Editor部分和實施isDirty()setDirty()clean()方法。

更新2013年2月,從user s-d

注:添加在ActionBarContributorsaveAction是在垃圾站不再需要基於靛藍R2(3.7.2)。
這足以添加menuContribution,加到編輯器的doSave()方法,並覆蓋commandStackChanged()如下

public void commandStackChanged(EventObject event) { 
    firePropertyChange(PROP_DIRTY); 
    super.commandStackChanged(event); 
} 
+0

@ S-d,謝謝你的建議的修改。 – VonC 2013-02-28 16:12:34

相關問題