Skip to content

Commit

Permalink
macosx
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Apr 19, 2024
1 parent 8ee0ab2 commit f8b469d
Showing 1 changed file with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -108,32 +105,11 @@ public void openPMDRuleConfiguration() {
}

private void openPreferences() {
String osname = System.getProperty("os.name").toLowerCase(Locale.ROOT);
if (osname.contains("mac")) {
// https://www.eclipse.org/forums/index.php/t/854280/
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().execute(new Runnable() {
@Override
public void run() {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
Menu appMenu = workbench.getDisplay().getSystemMenu();
for (MenuItem item : appMenu.getItems()) {
if (item.getText().startsWith("Preferences")) {
Event event = new Event();
event.time = (int) System.currentTimeMillis();
event.widget = item;
event.display = workbench.getDisplay();
item.setSelection(true);
item.notifyListeners(SWT.Selection, event);
break;
}
}
}
}
});
} else {
bot.menu().menu("Window", "Preferences").click();
}
// due to macosx, where the Preferences is not part of the Window menu but the application
// menu, we programmatically open the preferences dialog and not try to find it via the menu.
bot.getDisplay().execute(() -> {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(bot.shell().widget, null, null, errors);
dialog.open();
});
}
}

0 comments on commit f8b469d

Please sign in to comment.