Skip to content

Commit 64794d0

Browse files
authored
Merge pull request #2757 from eselmeister/TargetsClipboardTransfer
Enable to set a target in the scan/peak list via the clipboard.
2 parents 7c41b22 + feb4004 commit 64794d0

File tree

1 file changed

+33
-3
lines changed
  • chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt

1 file changed

+33
-3
lines changed

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
import org.eclipse.jface.viewers.StructuredSelection;
8686
import org.eclipse.jface.window.Window;
8787
import org.eclipse.swt.SWT;
88+
import org.eclipse.swt.dnd.Clipboard;
89+
import org.eclipse.swt.dnd.TextTransfer;
8890
import org.eclipse.swt.events.KeyEvent;
8991
import org.eclipse.swt.events.MouseAdapter;
9092
import org.eclipse.swt.events.MouseEvent;
@@ -146,7 +148,6 @@ public class ExtendedPeakScanListUI extends Composite implements IExtendedPartUI
146148
public ExtendedPeakScanListUI(Composite parent, int style) {
147149

148150
super(parent, style);
149-
contextService.activateContext("org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList");
150151
createControl();
151152
}
152153

@@ -243,6 +244,8 @@ private void createControl() {
243244

244245
private void initialize() {
245246

247+
contextService.activateContext("org.eclipse.chemclipse.ux.extension.xxd.ui.PeakScanList");
248+
246249
enableToolbar(toolbarInfoTop, buttonToolbarInfo.get(), IApplicationImage.IMAGE_INFO, TOOLTIP_INFO, true);
247250
enableToolbar(toolbarSearch, buttonToolbarSearch.get(), IMAGE_SEARCH, TOOLTIP_SEARCH, false);
248251
enableToolbar(toolbarInfoBottom, buttonToolbarInfo.get(), IApplicationImage.IMAGE_INFO, TOOLTIP_INFO, true);
@@ -343,13 +346,11 @@ public void mouseDown(MouseEvent e) {
343346
*/
344347
Display display = peakScanListUI.getTable().getDisplay();
345348
ITableSettings tableSettings = peakScanListUI.getTableSettings();
346-
347349
addDeleteMenuItem(display, tableSettings, "Peak/Scan (Delete Identifications)");
348350
addAnalysisActiveMenuItem(tableSettings, "Peaks (Activate for Analysis)", true);
349351
addAnalysisActiveMenuItem(tableSettings, "Peaks (Deactivate for Analysis)", false);
350352
addInternalStandardsMenuItem(display, tableSettings, "Peaks (Edit Internal Standard)");
351353
addClassifierMenuItem(display, tableSettings, "Peaks (Edit Classifier)");
352-
353354
addKeyEventProcessors(display, tableSettings);
354355
peakScanListUI.applySettings(tableSettings);
355356

@@ -474,6 +475,17 @@ private void addKeyEventProcessors(Display display, ITableSettings tableSettings
474475
setPeaksActiveForAnalysis(false);
475476
} else if(e.keyCode == SWT.DEL) {
476477
deletePeaksOrIdentifications(display);
478+
} else if(e.stateMask == SWT.MOD1 && e.keyCode == 'v') {
479+
/*
480+
* Copy Target
481+
*/
482+
Clipboard clipboard = new Clipboard(e.display);
483+
TextTransfer transfer = TextTransfer.getInstance();
484+
if(clipboard.getContents(transfer) instanceof String content) {
485+
if(!content.isBlank()) {
486+
addTargetsUnknown(content.trim());
487+
}
488+
}
477489
} else if((e.stateMask & SWT.MOD1) == SWT.MOD1) {
478490
if(e.keyCode == IKeyboardSupport.KEY_CODE_LC_A) {
479491
if(showPeakProfilesSelectionAll) {
@@ -674,11 +686,24 @@ private IScan getScan(Object object) {
674686

675687
private void addTargetsUnknown() {
676688

689+
addTargetsUnknown("");
690+
}
691+
692+
private void addTargetsUnknown(String name) {
693+
677694
for(Object object : tableViewer.get().getStructuredSelection().toList()) {
678695
IScan scan = getScan(object);
679696
if(scan instanceof ITargetSupplier targetSupplier) {
680697
IIdentificationTarget identificationTarget = IdentificationTargetSupport.getTargetUnknown(scan);
681698
if(identificationTarget != null) {
699+
/*
700+
* Modify the identification target.
701+
* Set a specific name instead of the default unknown label on demand.
702+
*/
703+
if(isModifyIdentificationTarget(name)) {
704+
targetSupplier.getTargets().clear();
705+
identificationTarget.getLibraryInformation().setName(name);
706+
}
682707
targetSupplier.getTargets().add(identificationTarget);
683708
}
684709
}
@@ -694,6 +719,11 @@ private void addTargetsUnknown() {
694719
UpdateNotifierUI.update(getDisplay(), IChemClipseEvents.TOPIC_EDITOR_CHROMATOGRAM_UPDATE, "Peaks/Scans unknown targets have been set.");
695720
}
696721

722+
private boolean isModifyIdentificationTarget(String name) {
723+
724+
return name != null && !name.isBlank();
725+
}
726+
697727
private void propagateSelection(Display display) {
698728

699729
if(interactionMode != InteractionMode.SOURCE && interactionMode != InteractionMode.BIDIRECTIONAL) {

0 commit comments

Comments
 (0)