Skip to content

Commit 26ccf59

Browse files
committed
Rebindable hotkeys for peak/scan list.
1 parent 8f4f393 commit 26ccf59

File tree

2 files changed

+147
-21
lines changed

2 files changed

+147
-21
lines changed

chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/plugin.xml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,108 @@
751751
</description>
752752
</fontDefinition>
753753
</extension>
754+
<extension
755+
point="org.eclipse.ui.commands">
756+
<category
757+
name="Peaks/Scans"
758+
description="Related to peaks and scans in chromatography"
759+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans">
760+
</category>
761+
<command
762+
name="Query Database"
763+
description="Query against a reference database"
764+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
765+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Query">
766+
</command>
767+
<command
768+
name="Mark Unknown"
769+
description="Set as unknown and annotate with highest masses"
770+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
771+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Unknown">
772+
</command>
773+
<command
774+
name="Delete Targets"
775+
description="Clear all database query matches."
776+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
777+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.DeleteTargets">
778+
</command>
779+
<command
780+
name="Classifier"
781+
description="Edit the list of classifiers."
782+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
783+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Classifier">
784+
</command>
785+
<command
786+
name="Internal Standard"
787+
description="Set internal standards."
788+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
789+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.InternalStandard">
790+
</command>
791+
<command
792+
name="Active Analysis"
793+
description="Set as active for analysis."
794+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
795+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.ActiveAnalysis">
796+
</command>
797+
<command
798+
name="Inactivate Analysis"
799+
description="Set as inactive for analysis."
800+
categoryId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeaksScans"
801+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.InactiveAnalysis">
802+
</command>
803+
</extension>
804+
<extension
805+
point="org.eclipse.ui.contexts">
806+
<context
807+
name="Peak/Scan List"
808+
description="A list of peaks and scans"
809+
id="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
810+
parentId="org.eclipse.ui.contexts.window">
811+
</context>
812+
</extension>
813+
<extension
814+
point="org.eclipse.ui.bindings">
815+
<key
816+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Query"
817+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
818+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
819+
sequence="M1+Q">
820+
</key>
821+
<key
822+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Unknown"
823+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
824+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
825+
sequence="M1+U">
826+
</key>
827+
<key
828+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.DeleteTargets"
829+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
830+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
831+
sequence="M1+D">
832+
</key>
833+
<key
834+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.Classifier"
835+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
836+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
837+
sequence="M1+G">
838+
</key>
839+
<key
840+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.InternalStandard"
841+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
842+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
843+
sequence="M1+S">
844+
</key>
845+
<key
846+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.ActiveAnalysis"
847+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
848+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
849+
sequence="M1+I">
850+
</key>
851+
<key
852+
commandId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.InactiveAnalysis"
853+
contextId="org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList"
854+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
855+
sequence="M1+M3+I">
856+
</key>
857+
</extension>
754858
</plugin>

chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ExtendedPeakScanListUI.java

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
import org.eclipse.core.commands.ExecutionException;
8181
import org.eclipse.core.commands.operations.IOperationHistory;
8282
import org.eclipse.core.commands.operations.OperationHistoryFactory;
83+
import org.eclipse.jface.bindings.TriggerSequence;
84+
import org.eclipse.jface.bindings.keys.KeySequence;
85+
import org.eclipse.jface.bindings.keys.KeyStroke;
86+
import org.eclipse.jface.bindings.keys.SWTKeySupport;
8387
import org.eclipse.jface.viewers.IStructuredSelection;
8488
import org.eclipse.jface.viewers.StructuredSelection;
8589
import org.eclipse.jface.window.Window;
@@ -99,6 +103,8 @@
99103
import org.eclipse.swt.widgets.TableItem;
100104
import org.eclipse.swtchart.extensions.core.IKeyboardSupport;
101105
import org.eclipse.ui.PlatformUI;
106+
import org.eclipse.ui.contexts.IContextService;
107+
import org.eclipse.ui.keys.IBindingService;
102108

103109
public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI, ConfigurableUI<PeakScanListUIConfig> {
104110

@@ -108,6 +114,11 @@ public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI
108114
private static final String DESCRIPTION_PEAKS = "Number Peaks:";
109115
private static final String DESCRIPTION_SCANS = "Scans:";
110116

117+
private static final String KEY_CLASS_PREFIX = "org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList.";
118+
119+
private IContextService contextService = (IContextService)PlatformUI.getWorkbench().getService(IContextService.class);
120+
private IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
121+
111122
private AtomicReference<Composite> toolbarMain = new AtomicReference<>();
112123
private AtomicReference<Button> buttonToolbarInfo = new AtomicReference<>();
113124
private AtomicReference<InformationUI> toolbarInfoTop = new AtomicReference<>();
@@ -138,6 +149,7 @@ public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI
138149
public ExtendedPeakScanListUI(Composite parent, int style) {
139150

140151
super(parent, style);
152+
contextService.activateContext("org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList");
141153
createControl();
142154
}
143155

@@ -454,30 +466,28 @@ private void addKeyEventProcessors(Display display, ITableSettings tableSettings
454466
@Override
455467
public void handleEvent(ExtendedTableViewer extendedTableViewer, KeyEvent e) {
456468

457-
if(e.keyCode == SWT.DEL) {
469+
if(matchesKeyPress("InternalStandard", e)) {
470+
modifyInternalStandards(display);
471+
} else if(matchesKeyPress("Classifier", e)) {
472+
modifyClassifier(display);
473+
} else if(matchesKeyPress("DeleteTargets", e)) {
474+
deleteTargetsAll(e.display);
475+
} else if(matchesKeyPress("Unknown", e)) {
476+
addTargetsUnknown(e.display);
477+
} else if(matchesKeyPress("Query", e)) {
478+
scanIdentifierControl.get().runIdentification(e.display);
479+
tableViewer.get().refresh();
480+
UpdateNotifierUI.update(display, chromatogramSelection);
481+
} else if(matchesKeyPress("ActiveAnalysis", e)) {
482+
setPeaksActiveForAnalysis(true);
483+
} else if(matchesKeyPress("InactiveAnalysis", e)) {
484+
setPeaksActiveForAnalysis(false);
485+
} else if(e.keyCode == SWT.DEL) {
458486
deletePeaksOrIdentifications(display);
459487
} else if((e.stateMask & SWT.MOD1) == SWT.MOD1) {
460-
if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_I) {
461-
if((e.stateMask & SWT.MOD3) == SWT.MOD3) {
462-
setPeaksActiveForAnalysis(false); // CTRL + ALT + i
463-
} else {
464-
setPeaksActiveForAnalysis(true); // CTRL + i
465-
}
466-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_S) {
467-
modifyInternalStandards(display); // CTRL + s
468-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_G) {
469-
modifyClassifier(display); // CTRL + g
470-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_D) {
471-
deleteTargetsAll(e.display); // CTRL + d
472-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_U) {
473-
addTargetsUnknown(e.display); // CTRL + u
474-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_Q) {
475-
scanIdentifierControl.get().runIdentification(e.display); // CTRL + q
476-
tableViewer.get().refresh();
477-
UpdateNotifierUI.update(display, chromatogramSelection);
478-
} else if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_A) {
488+
if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_A) {
479489
if(showPeakProfilesSelectionAll) {
480-
propagateSelection(display);
490+
propagateSelection(display); // CTRL + A
481491
}
482492
}
483493
} else {
@@ -487,6 +497,18 @@ public void handleEvent(ExtendedTableViewer extendedTableViewer, KeyEvent e) {
487497
});
488498
}
489499

500+
private boolean matchesKeyPress(String commandSuffix, KeyEvent e) {
501+
502+
TriggerSequence triggerSequence = bindingService.getBestActiveBindingFor(KEY_CLASS_PREFIX + commandSuffix);
503+
if(triggerSequence instanceof KeySequence keySequence) {
504+
KeyStroke[] bindingStrokes = keySequence.getKeyStrokes();
505+
int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
506+
KeyStroke eventStroke = SWTKeySupport.convertAcceleratorToKeyStroke(accelerator);
507+
return bindingStrokes.length > 0 && bindingStrokes[0].equals(eventStroke);
508+
}
509+
return false;
510+
}
511+
490512
private IOperationHistory getOperationHistory() {
491513

492514
return OperationHistoryFactory.getOperationHistory();

0 commit comments

Comments
 (0)