Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313121 - Font dialog doesn't return selected Font (when opened after MULTI Text)
Summary: Font dialog doesn't return selected Font (when opened after MULTI Text)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.6.1   Edit
Assignee: Scott Kovatch CLA
QA Contact: Silenio Quarti CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 09:03 EDT by Lakshmi P Shanmugam CLA
Modified: 2010-06-30 12:57 EDT (History)
1 user (show)

See Also:
lshanmug: review+


Attachments
Fix (4.38 KB, patch)
2010-05-17 13:56 EDT, Scott Kovatch CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.