Skip to content

Support message, nameFieldLabel and showsTagField for macOS dialog#8556

Merged
kevinsawicki merged 13 commits intoelectron:masterfrom
yamgent:macos-open-save-panel
Feb 9, 2017
Merged

Support message, nameFieldLabel and showsTagField for macOS dialog#8556
kevinsawicki merged 13 commits intoelectron:masterfrom
yamgent:macos-open-save-panel

Conversation

@yamgent
Copy link
Copy Markdown
Contributor

@yamgent yamgent commented Feb 1, 2017

Fixes #7783.

showSaveDialog() now supports additional attributes for setting the message, nameFieldLabel and showsTagField.

showOpenDialog() also supports message (nameFieldLabel and showsTagField doesn't seem to change the dialog box though).

  const {dialog} = require('electron');
  dialog.showSaveDialog({
    title: 'Save File',
    message: 'Select a location to save special file.',
    nameFieldLabel: 'Special Name',
    showsTagField: true
  });

screen shot 2017-02-02 at 12 05 05 am

@yamgent yamgent force-pushed the macos-open-save-panel branch from 84e21a0 to 8fa5c1d Compare February 2, 2017 12:22
Copy link
Copy Markdown
Contributor

@kevinsawicki kevinsawicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, left a few minor comments, thanks for implementing this.

}

if (showsTagField == null) {
showsTagField = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the default OS value of this is true if unset so I think this should default to true to not break backwards-compatibility.

https://developer.apple.com/reference/appkit/nssavepanel/1525589-showstagfield?language=objc

SetupDialog(dialog, title, button_label, default_path, filters);
SetupDialog(dialog, title, button_label, default_path, filters, message,
// NSOpenPanel does not support name_field_label and shows_tag_field
"", false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alignment here appear off, can you align this with the dialog argument on line 165?

SetupDialog(dialog, title, button_label, default_path, filters);
SetupDialog(dialog, title, button_label, default_path, filters, message,
// NSOpenPanel does not support name_field_label and shows_tag_field
"", false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the alignment here is off, can you align this with the dialog argument on line 142?

const file_dialog::Filters& filters,
const std::string& message,
const std::string& name_field_label,
const bool& shows_tag_field,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For primitives like bool and int, we don't use references or const, so this should just be bool show_tags_field.


let {buttonLabel, defaultPath, filters, properties, title} = options
let {buttonLabel, defaultPath, filters, properties, title,
message} = options
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine to keep on a single line, we don't enforce hard line length limits in JS.

if (message == null) {
message = ''
} else if (typeof message !== 'string') {
throw new TypeError('Message must be a string')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an assertion for this error in spec/api-dialog-spec.js?

if (nameFieldLabel == null) {
nameFieldLabel = ''
} else if (typeof nameFieldLabel !== 'string') {
throw new TypeError('Name field label must be a string')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an assertion for this error in spec/api-dialog-spec.js?

@yamgent
Copy link
Copy Markdown
Contributor Author

yamgent commented Feb 9, 2017

Thanks for your review! I will make the changes asap.

Support additional attributes available in macOS's NSSavePanel: message,
nameFieldLabel and showsTagField
Support an additional attributes available in macOS's NSOpenPanel:
message.
The default value of showsTagField in macOS's NSSavePanel is true.

Therefore, in order to follow the standard behavior and not break
backwards-compatibility, let's change the default value of
showsTagField to true.

Reference:
https://developer.apple.com/reference/appkit/nssavepanel/1525589-showstagfield?language=objc
The normal convention in the codebase is to not use references
or 'const' for primitives like 'bool' and 'int'.
@yamgent yamgent force-pushed the macos-open-save-panel branch from 49f6b70 to 347dc83 Compare February 9, 2017 13:51
@yamgent
Copy link
Copy Markdown
Contributor Author

yamgent commented Feb 9, 2017

@kevinsawicki I rebased on top of the latest master and incorporated all of your suggested changes.

@kevinsawicki
Copy link
Copy Markdown
Contributor

Thanks for this @yamgent, I merged #8623 into this branch which added a DialogSettings helper object so the method signatures in file_dialog.h no longer needed to change when we add new options and options you added could just be added to that struct and then used directly in file_dialog.mm.

Great job on this 👍 🚀

@kevinsawicki kevinsawicki merged commit 5bf60ad into electron:master Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants