Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 239485 - [Workbench] Better handling of ws/os specific code
Summary: [Workbench] Better handling of ws/os specific code
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 239141
Blocks:
  Show dependency tree
 
Reported: 2008-07-03 12:56 EDT by Kim Horne CLA
Modified: 2008-10-28 13:20 EDT (History)
4 users (show)

See Also:


Attachments
Centralize window system platform queries (53.20 KB, patch)
2008-09-15 12:09 EDT, Paul Webster CLA
no flags Details | Diff
take 2 (63.30 KB, patch)
2008-09-26 08:24 EDT, Paul Webster CLA
no flags Details | Diff
Cocoa support v03 (57.30 KB, patch)
2008-09-26 15:18 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kim Horne CLA 2008-07-03 12:56:05 EDT
Now that we have to contend with Cocoa and WPF SWT ports our platform-specific story is getting complicated.  We have duplicate conditional logic peppered throughout our codebase and we should address this in 3.5.
Comment 1 Grant Gayed CLA 2008-09-12 13:02:14 EDT
Eclipse-on-Cocoa is now being built nightly, and will be an early-access platform for 3.5M2.

Comment 2 Paul Webster CLA 2008-09-15 10:06:36 EDT
I had a look through our uses of SWT.getPlatform() and Platform.getOS()/Platform.getWS().

We use it firstly for "platform specific" setup (sizes that are different on windows/gtk/mac) and secondly for gtk event differences :-)  JFace restricts itself ot SWT.getPlatform() but at the workbench level we try both options.

Themes makes use of Platform because it tries to take into account both OS and WS.

One option that I'm considering is to write a JFace utility class that gathers our common questions (we shouldn't have "win32".equals(*) throughout our code).

For those that aren't tied to a specific windowing system (most of my gtk ones are) I think providing isWindows() and isMac() might generalize those 2 questions to what JFace and the workbench need.

PW
Comment 3 Paul Webster CLA 2008-09-15 10:08:16 EDT
That being said, should I push through at least the cocoa change for M2?  That would align most of the carbon changes to also be supported, but may introduce some problems on cocoa as the org.eclipse.ui.cocoa fragment has not been completed yet (i.e. no preferences menu entry :-)

PW
Comment 4 Grant Gayed CLA 2008-09-15 10:35:45 EDT
I was going to say yes until you gave the example of the missing preferences menu.  For now it's more important to be stable/more complete than to be Mac-like, so if this could introduce strangeness then I'd suggest pushing it to a future milestone.
Comment 5 Paul Webster CLA 2008-09-15 12:09:16 EDT
Created attachment 112555 [details]
Centralize window system platform queries

Start off by centralizing the platform queries.  It looks like all of the carbon queries really are "mac" queries, so I think they can all be replaced with isMac() for now (M3) and we'll keep our eye out for any that need to be changed back.

PW
Comment 6 Paul Webster CLA 2008-09-15 13:32:04 EDT
And a reminder to look at SWTKeyLookup before this goes in.

PW
Comment 7 Paul Webster CLA 2008-09-22 14:32:48 EDT
And native key formatter
PW
Comment 8 Paul Webster CLA 2008-09-26 08:24:03 EDT
Created attachment 113584 [details]
take 2

work in progress
PW
Comment 9 Paul Webster CLA 2008-09-26 15:18:27 EDT
Created attachment 113622 [details]
Cocoa support v03

This implements the helper methods on org.eclipse.jface.util.Util, and I've replaced all SWT.getPlatform() related occurrences of win32, carbon, cocoa, gtk, motif, and photon in the Platform UI and JFace.

For carbon|cocoa, I changed them to call Util.isMac().  That's in most places that involve keybindings.

For carbon that I found by itself:
I changed it to Util.isMac() for items like "on mac use 4 pixels, on gtk use 8 pixels".
I changed it to Util.isCarbon() for event related work arounds.

For win32 that I found by itself:
I changed it to Util.isWindows() for items like "on windows use *.exe, *.com" or pixel widths.
I changed it to Util.isWin32() for paint related events and event workarounds.

I have added an Util.isMacNow() method for use in the WorkbenchActionBuilder, that can be replaced when the cocoa fragment (or equivalent) is available.

PW
Comment 10 Paul Webster CLA 2008-10-01 11:38:40 EDT
Released >20081001
PW
Comment 11 Markus Kuppe CLA 2008-10-07 02:27:14 EDT
Why hasn't this API been pushed down to the SWT layer. Don't the String constants come from SWT anyway?
Comment 12 Paul Webster CLA 2008-10-07 08:44:34 EDT
(In reply to comment #11)
> Why hasn't this API been pushed down to the SWT layer. Don't the String
> constants come from SWT anyway?
> 

Sorta ... it looks like the fragment defines this:
org.eclipse.swt.internal.Platform.PLATFORM = "gtk"; //$NON-NLS-1$

So SWT is not currently providing a list of known platforms.  We could make an API request for constants for all known platforms, although that wouldn't cover other ports that don't come from SWT.

SWT wouldn't be providing the convenience methods, those are for UI.

org.eclipse.core.runtime.Platform.getWS() also defines constants for the windowing system ... but JFace can't see the runtime, and the runtime can't see the UI.

PW
Comment 13 Paul Webster CLA 2008-10-28 13:20:18 EDT
In I20081027-1800
PW