From c65b52d7beca14c465359f9a1aac4f1b7700d2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 19 May 2021 13:08:26 +0200 Subject: [PATCH] Add Close and Close All to the file menu. --- .../Application.e4xmi | 3 ++ .../icons/16x16/close.png | Bin 0 -> 463 bytes .../icons/16x16/close_all.png | Bin 0 -> 727 bytes .../fragment.e4xmi | 8 +++ .../ui/handlers/CloseAllHandler.java | 42 +++++++++++++++ .../extension/ui/handlers/CloseHandler.java | 48 ++++++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/close.png create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/close_all.png create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseAllHandler.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseHandler.java diff --git a/chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/Application.e4xmi b/chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/Application.e4xmi index bf8c3ef995..35d7ad37b0 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/Application.e4xmi +++ b/chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/Application.e4xmi @@ -28,7 +28,10 @@ + + + diff --git a/chemclipse/plugins/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/close.png b/chemclipse/plugins/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/close.png new file mode 100644 index 0000000000000000000000000000000000000000..38ab8a480129f52d9d71c191d89a0a521ffd40a2 GIT binary patch literal 463 zcmV;=0WkiFP)SRY0)~ z6j4@sn%#MCp2s`u^Zn=QbUF`>M&r3&uLrL2l}g1A{)wZ91Q7&|?RNWs_yH63H(#sO z6y#55p3iRg{d78|-EK#l&4yqgkW-AdVNBHT^K_?1@!lUON48u@B*yHh7w&@0U z2wp&^-kb!RCX*q+YPDKY$iU3G;LDxEhlH-{&P&uZ?FD0#0!Fjhq(mYi z;_Nkl8=N7XLsF z4n6_aw~!P9vvM)Bocwm%}wGs z2^hxnlcp_3K@g%Cpd^z?SYBSPA%t?I*lad2b~~*eA0I=ZP{92LA(cwO&dv^OY-|wC zvTv%BlaoK{@kAnlTMJwfKyR<9lFepG&xJxByk55I_xo#GTU!LQy1I&6K~UEkl;b#c zY;4R$07m1h>;3%?kk9AAYNZu}fr_#$n;ah>|Fyop4%^$?4cA~JBO@wRV@LXJguKw>yWAS<`mZT!Ufot<&jTdUOM=t*y`6+S*>!wasRWVt|5&1#4?- z4PRJT0Efd-p=sLq + + @@ -16,6 +18,8 @@ + + @@ -87,4 +91,8 @@ + + + + diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseAllHandler.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseAllHandler.java new file mode 100644 index 0000000000..aacd40efef --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseAllHandler.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.ui.handlers; + +import org.eclipse.chemclipse.ux.extension.ui.editors.IChemClipseEditor; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +public class CloseAllHandler { + + @CanExecute + boolean canExecute(EPartService partService) { + + for(MPart part : partService.getParts()) { + if(part.getObject() instanceof IChemClipseEditor) { + return true; + } + } + return false; + } + + @Execute + void execute(EPartService partService) { + + for(MPart part : partService.getParts()) { + if(part.getObject() instanceof IChemClipseEditor) { + partService.hidePart(part, true); + } + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseHandler.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseHandler.java new file mode 100644 index 0000000000..d497723812 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.ui/src/org/eclipse/chemclipse/ux/extension/ui/handlers/CloseHandler.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.ux.extension.ui.handlers; + +import javax.inject.Named; + +import org.eclipse.chemclipse.ux.extension.ui.editors.IChemClipseEditor; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +public class CloseHandler { + + @CanExecute + boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part) { + + if(part != null) { + if(part.getObject() instanceof IChemClipseEditor) { + return true; + } + } + return false; + } + + @Execute + void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) { + + if(part != null) { + Object object = part.getObject(); + if(object != null) { + if(object instanceof IChemClipseEditor) { + partService.hidePart(part, true); + } + } + } + } +}