Skip to content

Commit

Permalink
[FIXUP] Implement requested changes adjust info text and avoid fake
Browse files Browse the repository at this point in the history
radio-button
  • Loading branch information
HannesWell committed Feb 12, 2024
1 parent a82d3df commit a62f459
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 -> {
Expand All @@ -203,13 +199,15 @@ protected Control createCustomArea(Composite parent) {
this.setReturnCode(Window.CANCEL);
this.close();
})).create(parent);

return parent;
}

@Override
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a62f459

Please sign in to comment.