代码之家  ›  专栏  ›  技术社区  ›  Real Red.

EclipseRCP:如何使默认保存按钮在编辑器中可见?

  •  2
  • Real Red.  · 技术社区  · 17 年前

    我认为在eclipsercp中有与编辑器相关联的默认保存和取消按钮。我们如何使这些按钮出现在编辑器上。

    我记得听说过这样的事。(我可能错了)

    无论如何,我们如何实现这一目标?(注:我不是在寻找一个自定义的SWT按钮,并将其命名为“SAVE”。我正在寻找一个与编辑器相关联的默认保存按钮(如果有这样的东西))。

    1 回复  |  直到 17 年前
        1
  •  3
  •   Community Mohan Dere    9 年前

    按钮与编辑器没有直接关系。
    你必须,因为 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 :

    saveAction ActionBarContributor
    加上 menuContribution ,添加 getCommandStack().markSaveLocation() 给编辑的 doSave() 方法和重写 commandStackChanged()

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