Project

General

Profile

Revision a998e6a0

IDa998e6a09635debf24e868706e181766bc34a941
Parent f77fd7f6
Child 197b7786

Added by Patrick Plitzner over 3 years ago

ref #6596 Replace CTRL+S keybinding with our own binding

  • this is done via model processors
  • this allows to use our SaveHandler to handle all save events

View differences:

eu.etaxonomy.taxeditor.workbench/fragment.e4xmi
87 87
    <elements xsi:type="commands:Command" xmi:id="_CYHrgB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.export" commandName="%command.label.4"/>
88 88
    <elements xsi:type="commands:Command" xmi:id="_LVTo8B62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.close" commandName="%command.label"/>
89 89
    <elements xsi:type="commands:Command" xmi:id="_MrLPsB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.closeAll" commandName="%command.label.0"/>
90
    <elements xsi:type="commands:Command" xmi:id="_PkWcQB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.save" commandName="%command.label.1"/>
91 90
    <elements xsi:type="commands:Command" xmi:id="_X-56IFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.save" commandName="%command.label.1"/>
92 91
    <elements xsi:type="commands:Command" xmi:id="_RWLmQB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.saveAll" commandName="%command.label.2"/>
93 92
    <elements xsi:type="commands:Command" xmi:id="_TvLd8B62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.exit" commandName="%command.label.5"/>
......
125 124
    <elements xsi:type="commands:Handler" xmi:id="_2fnUYCZ0EeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.workbench.OpenPartHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenPartHandler" command="_hMjgECZsEeer_rabtodzWA"/>
126 125
    <elements xsi:type="commands:Handler" xmi:id="_dBGosFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.SaveHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.SaveHandler" command="_X-56IFp0Eee4PsIXei-TMg"/>
127 126
  </fragments>
127
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Z4f0kFsaEeebk7BsM35KOg" featurename="children" parentElementId="org.eclipse.ui.contexts.dialogAndWindow">
128
    <elements xsi:type="commands:BindingContext" xmi:id="_5pEDMFsaEeebk7BsM35KOg" elementId="eu.etaxonomy.taxeditor.workbench.bindingcontext" name="Taxonomic Editor Keybinding Context"/>
129
  </fragments>
130
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_9BSjQFsaEeebk7BsM35KOg" featurename="bindingTables" parentElementId="org.eclipse.e4.legacy.ide.application">
131
    <elements xsi:type="commands:BindingTable" xmi:id="_-q2iEFsaEeebk7BsM35KOg" elementId="eu.etaxonomy.taxeditor.workbench.bindingtable" bindingContext="_5pEDMFsaEeebk7BsM35KOg">
132
      <bindings xmi:id="__6bTkFsaEeebk7BsM35KOg" elementId="eu.etaxonomy.taxeditor.workbench.keybinding.save" keySequence="M1+S" command="_X-56IFp0Eee4PsIXei-TMg"/>
133
    </elements>
134
  </fragments>
128 135
</fragment:ModelFragments>
eu.etaxonomy.taxeditor.workbench/plugin.xml
9 9
            apply="always"
10 10
            uri="fragment.e4xmi">
11 11
      </fragment>
12
      <processor
13
            apply="always"
14
            beforefragment="false"
15
            class="eu.etaxonomy.taxeditor.workbench.WorkbenchProcessor">
16
         <element
17
               id="org.eclipse.ui.contexts.window">
18
         </element>
19
         <element
20
               id="eu.etaxonomy.taxeditor.workbench.keybinding.save">
21
         </element>
22
      </processor>
12 23
   </extension>
13 24

  
14 25
</plugin>
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchProcessor.java
1
package eu.etaxonomy.taxeditor.workbench;
2

  
3
import java.util.List;
4

  
5
import javax.inject.Inject;
6
import javax.inject.Named;
7

  
8
import org.eclipse.e4.core.di.annotations.Execute;
9
import org.eclipse.e4.ui.model.application.commands.MBindingTable;
10
import org.eclipse.e4.ui.model.application.commands.MKeyBinding;
11

  
12
public class WorkbenchProcessor {
13

  
14
    @Inject
15
    @Named("org.eclipse.ui.contexts.window")
16
    private MBindingTable bindingTable;
17

  
18
    @Inject
19
    @Named("eu.etaxonomy.taxeditor.workbench.keybinding.save")
20
    private MKeyBinding saveBinding;
21

  
22

  
23
    @Execute
24
    public void execute() {
25
        //swap legacy CTRL+S with the one defined in our model fragment
26
        //to allow using our SaveHandler for all save actions
27
        List<MKeyBinding> bindings = bindingTable.getBindings();
28
        MKeyBinding legacySaveBinding = null;
29
        for (MKeyBinding mKeyBinding : bindings) {
30
            String keySequence = mKeyBinding.getKeySequence();
31
            if(keySequence.equals("CTRL+S")){
32
                legacySaveBinding = mKeyBinding;
33
                break;
34
            }
35
        }
36
        if(legacySaveBinding!=null){
37
            bindings.remove(legacySaveBinding);
38
        }
39
        bindings.add(saveBinding);
40
    }
41
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)