Closed Bug 528379 Opened 15 years ago Closed 14 years ago

Provide Cocoa prompt for select types.

Categories

(Camino Graveyard :: General, enhancement, P3)

All
macOS
enhancement

Tracking

(Not tracked)

RESOLVED FIXED
Camino2.1

People

(Reporter: chris, Assigned: chris)

References

Details

(Whiteboard: [cm192test][camino-2.0.3])

Attachments

(1 file, 3 obsolete files)

Bug 306613 brought this to light. CocoaPromptService needs to provide an implementation of the select method so we can create a new boolean pref.

Firefox 3.5 has the options in a list box, but I'm leaning towards using an NSPopupButton.
Blocks: 306613
[6:16pm] sauron: we should get an opinion from smorgan on the UI
[6:18pm] smorgan: Popup seems like it makes the most sense
P3 on the 2.1 list.
Priority: -- → P3
Target Milestone: --- → Camino2.1
Attached patch Fix v1.0 (obsolete) — Splinter Review
Provides a select prompt using code similar to the other prompt methods.
Attachment #427518 - Flags: review?(stuart.morgan+bugzilla)
Comment on attachment 427518 [details] [diff] [review]
Fix v1.0

>+- (BOOL)select:(NSWindow*)parent title:(NSString*)title text:(NSString*)text selectList:(NSArray*)selectList selectedIndex:(unsigned int*)selectedIndex;

Needs a method-level comment (for example, the only way to know that selectedIndex is both an input and output param right now is to read the whole implementation).

>+const int kPopupButtonHeight = 26;

In my testing, sizeToFit gives you the correct height, so you shouldn't have to hard-code a standard control size. Was that not the case for you on some OS version?

>+  [selectPopup setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];

Why? If you want something other than a standard control size, you should use systemFontSizeForControlSize:, but if it's standard you should have the right size already.

>+  [selectPopup setBordered:YES];

Isn't this the default?

>+  [panel setInitialFirstResponder: selectPopup];

No space after :

>+  int result = [self runModalWindow:panel relativeToWindow:parent];
>+
>+  [panel close];

Is the close actually necessary? I would expect closing it to be the trigger for runModalWindow:relativeToWindow: to return.

>+  NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle];
>+  NSString* textStr = [NSString stringWithPRUnichars:text];

Any reason not to inline these in the call below?

>+  unsigned int selIndex = 0;

Declare this down by nsresult.
But come to think of it... why is selectedIndex an input param to your helper (instead of just output) if the API you are implementing this for doesn't need that?

>+    *_retval = (PRBool)[controller select:[browserView nativeWindow]

The baby Jesus prefers we avoid casting between bool types, as unexpected truncation bugs make him cry. Instead, assign the result to a local BOOL, and then use a ?: to assign actual PRBool values to *_retval based on that variable.
Attachment #427518 - Flags: review?(stuart.morgan+bugzilla) → review-
Attached patch Fix v1.1 (obsolete) — Splinter Review
Patch with review comments addressed. The panel won't close without telling it to, so we need to keep that line. selectedIndex is now just an output parameter.
Attachment #427518 - Attachment is obsolete: true
Attachment #427905 - Flags: review?(stuart.morgan+bugzilla)
Comment on attachment 427905 [details] [diff] [review]
Fix v1.1

r=smorgan with two nits:

>+// -select: title: text: selectList: selectedIndex:

Method signatures don't have spaces in them, so if you are going to put it here it should be without spaces.

>+  //  get panel and display it

One space after //, not two, and it should be capitalized and have a period.
Attachment #427905 - Flags: review?(stuart.morgan+bugzilla) → review+
Attached patch Fix v1.2 (obsolete) — Splinter Review
Fix with comments modified as suggested. Testing behaviour of this patch depends on the patch for Bug 306613 being landed or applied.
Attachment #427905 - Attachment is obsolete: true
Attachment #427974 - Flags: superreview?(mikepinkerton)
Attachment #427974 - Flags: review+
+  unsigned int selIndex;
+  nsresult rv = NS_OK;

I know this gets set by the function call, but I'd still rather see it initialized. In addition, when documenting -select:title:text... you should mention that the value is always set on output just in case someone wants to try to rely on it not getting clobbered in certain instances.

sr=pink
Attachment #427974 - Flags: superreview?(mikepinkerton) → superreview+
Patch with sr comments addressed, for checkin.
Attachment #427974 - Attachment is obsolete: true
Attachment #434686 - Flags: superreview+
Landed on cvs trunk and the test repo: http://hg.mozilla.org/users/alqahira_ardisson.org/camino-1.9.2-test/rev/43ec7cfeb77a
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: [cm192test]
Landed on the CAMINO_2_0_BRANCH.
Whiteboard: [cm192test] → [cm192test][camino-2.0.3]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: