From a62f45944a15a5e38bfec0e1af58caf76539c826 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Mon, 12 Feb 2024 20:38:07 +0100 Subject: [PATCH] [FIXUP] Implement requested changes adjust info text and avoid fake radio-button --- .../internal/WindowsDefenderConfigurator.java | 12 +++-- .../dialogs/StartupPreferencePage.java | 45 +++++++++---------- .../eclipse/ui/internal/messages.properties | 6 +-- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java index c4f304f0c9a..d387d4371b8 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java @@ -170,15 +170,15 @@ private static HandlingOption askForDefenderHandlingDecision() { protected Control createCustomArea(Composite parent) { ButtonFactory radioButtonFactory = WidgetFactory.button(SWT.RADIO | SWT.WRAP); - Button exclude = radioButtonFactory + Button performExclusion = radioButtonFactory .text(bindProductName(WorkbenchMessages.WindowsDefenderConfigurator_performExclusionChoice)) .onSelect(e -> { choice[0] = HandlingOption.EXECUTE_EXCLUSION; getButton(0).setEnabled(true); }).create(parent); - Point size = exclude.computeSize(SWT.DEFAULT, SWT.DEFAULT); + Point size = performExclusion.computeSize(SWT.DEFAULT, SWT.DEFAULT); GridDataFactory.swtDefaults().hint((int) (size.x * 0.6), (int) (size.y * 2.3)).indent(0, 5) - .applyTo(exclude); + .applyTo(performExclusion); Button keepScanning = radioButtonFactory .text(bindProductName( @@ -189,10 +189,6 @@ protected Control createCustomArea(Composite parent) { }).create(parent); GridDataFactory.swtDefaults().indent(0, 5).applyTo(keepScanning); - Button fakeDefaultSelection = radioButtonFactory.text("").create(parent); //$NON-NLS-1$ - GridDataFactory.swtDefaults().hint(SWT.DEFAULT, 1).applyTo(fakeDefaultSelection); - fakeDefaultSelection.setSelection(true); - LinkFactory.newLink(SWT.WRAP) .text(WorkbenchMessages.WindowsDefenderConfigurator_detailsAndOptionsLinkText) .onSelect((e -> { @@ -203,6 +199,7 @@ protected Control createCustomArea(Composite parent) { this.setReturnCode(Window.CANCEL); this.close(); })).create(parent); + return parent; } @@ -210,6 +207,7 @@ protected Control createCustomArea(Composite parent) { protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); getButton(0).setEnabled(false); + getButton(1).forceFocus(); // prevents auto-focusing one of the radio-buttons which selects them } }; int open = dialog.open(); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java index 7a026f2facc..e9958be6c56 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java @@ -39,11 +39,12 @@ import org.eclipse.jface.widgets.TableFactory; import org.eclipse.jface.widgets.WidgetFactory; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ExpandBar; +import org.eclipse.swt.widgets.ExpandItem; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; @@ -95,16 +96,17 @@ protected void createExtraContent(Composite composite) { if (WindowsDefenderConfigurator.isRelevant()) { new Label(composite, SWT.NONE); // add spacer + GridDataFactory grapHorizontalSpace = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING) + .grab(true, false); + Group group = GroupFactory.newGroup(SWT.SHADOW_NONE | SWT.H_SCROLL) .text(WorkbenchMessages.WindowsDefenderConfigurator_statusCheck) - .layoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)).create(composite); + .layoutData(grapHorizontalSpace.create()).create(composite); GridLayoutFactory.swtDefaults().spacing(5, 10).applyTo(group); - Label info = LabelFactory.newLabel(SWT.WRAP) - .text(WindowsDefenderConfigurator - .bindProductName(WorkbenchMessages.WindowsDefenderConfigurator_exclusionInformation)) - .layoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)).create(group); - GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(info); + String infoText = WindowsDefenderConfigurator + .bindProductName(WorkbenchMessages.WindowsDefenderConfigurator_exclusionInformation); + LabelFactory.newLabel(SWT.WRAP).text(infoText).layoutData(grapHorizontalSpace.create()).create(group); Button ignoreAllInstall = createCheckBox(WorkbenchMessages.WindowsDefenderConfigurator_ignoreAllChoice, false, group); @@ -131,32 +133,27 @@ protected void createExtraContent(Composite composite) { } }).create(group); - Button showScriptButton = WidgetFactory.button(SWT.PUSH).create(group); + ExpandBar bar = new ExpandBar(group, SWT.NONE); + bar.setForeground(bar.getDisplay().getSystemColor(SWT.COLOR_BLACK)); + grapHorizontalSpace.applyTo(bar); + bar.addListener(SWT.Expand, e -> bar.requestLayout()); + bar.addListener(SWT.Collapse, e -> bar.requestLayout()); + // Use back-tick characters to split a command over multiple lines: // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.4#line-continuation - Text scriptText = WidgetFactory.text(SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.READ_ONLY) + Text scriptText = WidgetFactory.text(SWT.BORDER | SWT.H_SCROLL | SWT.READ_ONLY) .text(WindowsDefenderConfigurator.createAddExclusionsPowershellCommand(" `\n ")) //$NON-NLS-1$ - .create(group); - GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(scriptText); + .layoutData(grapHorizontalSpace.create()).create(bar); - setScriptBlockVisible(scriptText, showScriptButton, false); - showScriptButton.addSelectionListener(SelectionListener.widgetSelectedAdapter( - e -> setScriptBlockVisible(scriptText, showScriptButton, !scriptText.getVisible()))); + ExpandItem item = new ExpandItem(bar, SWT.NONE); + item.setText(WorkbenchMessages.WindowsDefenderConfigurator_scriptButtonLabel); + item.setControl(scriptText); + item.setHeight(scriptText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); updateWindowsDefenderHandlingOptions(); } } - private void setScriptBlockVisible(Text text, Button button, boolean visible) { - button.setText(WorkbenchMessages.WindowsDefenderConfigurator_scriptButtonLabel + (visible ? " <<" : " >>")); //$NON-NLS-1$//$NON-NLS-2$ - text.setVisible(visible); - ((GridData) text.getLayoutData()).exclude = !visible; - text.requestLayout(); - text.getParent().requestLayout(); - text.getParent().getParent().requestLayout(); - text.getParent().getParent().pack(); - } - protected static Button createCheckBox(String text, boolean checked, Composite composite) { Button button = ButtonFactory.newButton(SWT.CHECK).text(text).font(composite.getFont()).create(composite); button.setSelection(checked); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties index 733ef9025a6..6d9fe69c8cd 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties @@ -568,12 +568,12 @@ CheckedTreeSelectionDialog_nothing_available=No entries available. CheckedTreeSelectionDialog_select_all=Select &All CheckedTreeSelectionDialog_deselect_all=&Deselect All -WindowsDefenderConfigurator_statusCheck=Windows Defender exclusion check +WindowsDefenderConfigurator_statusCheck=Windows Defender Exclusion Check WindowsDefenderConfigurator_exclusionCheckMessage=Microsoft's Windows Defender is active and could significantly decrease the application's start-up and overall performance.\n\ Select how this installation should be handled by Windows Defender: WindowsDefenderConfigurator_exclusionInformation=If Windows Defender is active and scans this application it can significantly slow down its start-up and overall performance.\n\ -To avoid a performance decrease {0} can exclude itself from being scanned by Windows Defender.\n\ -But be aware that in general adding exclusions could affect this computer's security and adding them requires Administrator privileges. +To prevent a decrease in performance {0} can exclude itself and all files opened from real-time scanning by Windows Defender.\n\ +Be aware that in general adding exclusions could affect this computer's security and adding them requires Administrator privileges. WindowsDefenderConfigurator_scriptButtonLabel=Powershell script (execution requires Administrator privileges) WindowsDefenderConfigurator_performExclusionChoice=Exclude {0} from being scanned to improve performance.\n\ (In general adding exclusions may affect the security level of this computer)