Eclipse Search

Loading

Oct 18, 2010

New features on Mac

Windowless application:

       SWT now supports an application level menu, so now its possible for an app to have a MenuBar without any Shell

Here is the code sample:

package com.eclipse_tips.mac.sample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class WindowlessApp {

 private static int windowCount;

 public static void main(String[] args) {
  final Display display = new Display();

  Menu appMenuBar = display.getAppMenuBar();
  
  final MenuItem windowMenu = new MenuItem(appMenuBar, SWT.CASCADE);
  windowMenu.setText("Window");
  Menu windowSubMenu = new Menu(null, SWT.DROP_DOWN);
  windowMenu.setMenu(windowSubMenu);
  
  createNWMenuItem(display, windowSubMenu);
  
  while (!display.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();
 }

 private static Shell createNewWindow(final Display display) {

  windowCount++;
  Shell shell = new Shell(display);
  Menu bar = new Menu(shell, SWT.BAR);
  shell.setMenuBar(bar);
  shell.setText("Window #" + windowCount);

  MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
  fileItem.setText("&File" + windowCount);

  Menu submenu = new Menu(shell, SWT.DROP_DOWN);
  fileItem.setMenu(submenu);

  MenuItem item = new MenuItem(submenu, SWT.PUSH);
  item.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event e) {
    System.out.println("Select All");
   }
  });
  item.setText("Select All");
  
  createNWMenuItem(display, submenu);

  return shell;
 }

 private static void createNWMenuItem(final Display display, Menu submenu) {
  MenuItem newWindowItem = new MenuItem(submenu, SWT.PUSH);
  newWindowItem.addListener(SWT.Selection, new Listener() {

   public void handleEvent(Event e) {
    Shell window = createNewWindow(display);
    window.setSize(300, 200);
    window.open();
   }
  });
  newWindowItem.setText("New Window");
  
 }

}


Native ToolBar:

     The native toolBar is now supported and it looks awesome. Here is the modified SWT ToolBar snippet in action:

SWT Native Toolbar on Mac

Window menu items:

    Eclipse adds support to the standard 'Minimize', 'Zoom' & 'Bring All to Front' menu items in the Window menu:



Mac standard menu items in Window menu


Proxy Icon:

     Eclipse now supports proxy icons in the window title. You can drag those icons to other apps or Cmd+click to directly navigate any folder in the file's hierarchy:
Proxy Icon in Eclipse Workbench


Note, these are available in the latest Nightly builds of 3.7 and are subjected to change before the release :-)