Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313121

Summary: Font dialog doesn't return selected Font (when opened after MULTI Text)
Product: [Eclipse Project] Platform Reporter: Lakshmi P Shanmugam <lshanmug>
Component: SWTAssignee: Scott Kovatch <skovatch>
Status: RESOLVED FIXED QA Contact: Silenio Quarti <Silenio_Quarti>
Severity: normal    
Priority: P3 CC: skovatch
Version: 3.6Flags: lshanmug: review+
Target Milestone: 3.6.1   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Fix none

Description Lakshmi P Shanmugam CLA 2010-05-17 09:03:38 EDT
The Font Dialog doesn't return the selected Font.

public class FontDialogBug {
public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new RowLayout());
	
	final Text t = new Text(shell, SWT.MULTI|SWT.BORDER);
	t.setText("Hello");
	
	Button button = new Button(shell, SWT.PUSH);
	button.setText("set font");
	button.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			FontDialog d = new FontDialog(shell);
			FontData data = d.open();
			System.out.println(data);
			if (data != null) t.setFont(new Font(display, data));
		}
	});

	shell.pack();
	shell.open();
	
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}

Happens when we create the Text with SWT.MULTI style. Doesn't happen with SWT.SINGLE.
Comment 1 Scott Kovatch CLA 2010-05-17 13:03:26 EDT
This is only an issue when the multi-line Text has focus. If you move focus to the Button first and then set the font it will work.
Comment 2 Scott Kovatch CLA 2010-05-17 13:56:40 EDT
Created attachment 168780 [details]
Fix

Found it. Active NSTextViews normally respond to changes in the font panel. Any selected text is updated to the new font selection, but if the NSTextView is not set to use rich text nothing happens. I'm not entirely sure why, but the font in the font panel is then re-set to the current font of the NSTextView. This has the effect of vetoing the font selection. Fix is to tell the NSTextView used for Text to not listen to NSFontPanel changes.
Comment 3 Scott Kovatch CLA 2010-06-02 17:50:02 EDT
One-liner; for 3.6.1.
Comment 4 Scott Kovatch CLA 2010-06-28 13:07:00 EDT
Lakshmi, please review. You can send it to Silenio if you're not comfortable reviewing.
Comment 5 Lakshmi P Shanmugam CLA 2010-06-30 09:30:28 EDT
Hi Scott, I think the patch is good.
Comment 6 Scott Kovatch CLA 2010-06-30 12:57:32 EDT
Fixed > 20100630 in 3.6.1 and HEAD.