Setting value for title of NSOpenPanel does not work - swift

I want to set title for my NSOpenPanel, but it does not work! Apple says:
Gets and sets the title for the panel shown at the top of the window.
But I can not make codes works, not sure what is wrong?
let nsOpenPanel = NSOpenPanel()
nsOpenPanel.canChooseFiles = true
nsOpenPanel.title = "Hello, Choose Files"
if (nsOpenPanel.runModal() == .OK) ... // rest of codes ...

The title is something from the past when windows in macOS had title bars. To show text or an instruction on top of the NSOpenPanel object, use the message property:
nsOpenPanel.message = "Hello, Choose Files"

Related

Typo3 Content Elements missing in wizard

I have some content elements in a site package which I want to show up in the content element wizard as explained here:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/ContentElementsWizard.html
Basically I have done the same as shown in the section "Create a new tab"
Configuration\TsConfig\Page\ContentElement\All.tsconfig is looking like this:
mod.wizards.newContentElement.wizardItems.mci.header = MCI
mod.wizards.newContentElement.wizardItems.mci {
elements {
mci_home_banner {
iconIdentifier = home-banner
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
mci_home_banner_element {
iconIdentifier = home-banner-element
title = Home Banner Element
description = Element im Starseitenbanner
tt_content_defValues.CType = mci_home_banner_element
}
}
show := addToList(mci_home_banner, mci_home_banner_element)
}
I reduced the code to just 2 elements. They are not shown at all, but are available over the dropdown, so I can switch to one of them after choosing another element.
This didn't work when created in 9.5 and still does not work after switching to version 11.5.10
What am I missing?
#user414873 Did you try to add your custom elements to the "common" tab instead of your new one "mci"?
And did you try to use an existing icon identifier (e.g. "content-image" or an other one - see https://typo3.github.io/TYPO3.Icons/)? Just to make sure that there is no problem with your custom icons that prevents the elements from being displayed.
Does this minimal example work for you:
mod.wizards.newContentElement.wizardItems.common {
elements {
mci_home_banner {
iconIdentifier = content-image
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
}
show := addToList(mci_home_banner)
}
And I would doubt this:
I guess otherwise the content elements wouldn't be available at all.
I suggest you check it's correctly included by using the "Info" module in your TYPO3 main menu. Then select the page where the content element should be included and switch the dropdown on top of the content area to "View TSconfig fields content". Now you can search for "wizards" and check if your element is included.

Localize button Swift

For example I've got an app which has a textLabel and a button which are firstly set as:
mainLabel.attributedText = "labelNewText".uppercased()
mainButton.titleLabel?.attributedText = "buttonNewText".uppercased()
Then I've created a Localization file, where I set a some values for a German language:
"labelNewText" = "Etikette";
"buttonNewText" = "Taste";
And rewrote set ups for label and button like:
mainLabel.attributedText = "\(NSLocalizedString("labelNewText", comment: ""))".uppercased()
mainButton.titleLabel?.attributedText = "\(NSLocalizedString("buttonNewText", comment: ""))".uppercased()
Though, right after after I change my phone language setting to German, the translation only works for a Label but is not working for button. What am I doing wrong and how to localise button titleLabel?
You have to use UIButton's setAttributedTitle:forState: instead of trying to manipulate the text label itself. So for example:
mainButton.setAttributedTitle(myAttributeString, forState: .normal)

Swift UITest - No match found for textField with accessibility identifier

Trying to create a UITest for entering an email address/password into text fields and then hitting a login button. Using Xcode.
I watch the UITest navigate to the proper page, but it does not detect the text fields. I made sure that both text fields have the "Accessibility" box checked, and I've given them identifiers.
I'm getting this error:
UI Testing Failure - No matches found for text field
func testExample() {
let app = XCUIApplication()
//Test login page
app.buttons["loginButton"].tap()
//Here it navigates to the desired page
let emailField = app.textFields["email"]
emailField.tap()
emailField.typeText("xxx.xx.edu")
let passwordField = app.textFields["password"]
passwordField.tap()
passwordField.typeText("xxx")
app.buttons["loginButton"].tap()
// let loginAlert = app.alerts["alertVC"]
// XCTAssertEqual(loginAlert.title, "Error")
}
The accessibility indicators are "email" and "password" respectively. Logging in works fine when I run the simulator myself.
EDIT: Apparently there are no text fields at all (count = 0) even though I see them and use them on the page...
Image of storyboard with text fields:
If UITextFiled set SecureTextEntry true, you should use:
let passwordField = app.secureTextFields["password"]
I was having the same problem and I solved by unchecking the "accessibility enabled" box for the "views" of ViewControllers

What does the single | mean in swift

I found some example code when building a menu bar item in OS X. It makes use of the single | and I'm unsure what it actually means.
(What I'm trying to do is have a function called on left click of the menu item, but have it show the menu on right click)
Here's my code
//Get reference to main system status bar
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
statusItem.image = icon
statusItem.menu = menuBar
if let statusButton = statusItem.button
{
statusButton.target = self
statusButton.action = #selector(statusItemClicked)
statusButton.sendActionOn(Int(NSEventMask.RightMouseUpMask.rawValue | NSEventMask.LeftMouseUpMask.rawValue))
}
Original Answer with code Left vs Right Click Status Bar Item Mac Swift 2
Bitwise OR, just like it does in most C-like languages. In this context, it's being used to combine flags.
That must be really old code. Nowadays, in modern Swift, NSEventMask is an Option Set. You can just say [NSEventMask.rightMouseUp, NSEventMask.leftMouseUp], and you don't need the Int cast at all. (Or if you haven't updated to Swift 3 yet, the case names would start with capital letters.)

Localization the Navigation Bar Title in swift

I write navigation bar title in Attributes inspector. I would like to translate that title when I switch to other language.
self.navigationItem.title = NSLocalizedString("Login", comment: "")
I write it in override func viewDidLoad().
I took navigation item Object ID "S3Z-Mr-Qda" and translate it in Main.strings file.
/* Class = "UINavigationItem"; text = "Package History"; ObjectID = "S3Z-Mr-Qda"; */
"S3Z-Mr-Qda.text" = "Login";
However, it does not change at all and how to implement it in swift?
You can actually provide a translation to the title using that method.
The only thing that you did wrong was setting the property "text". As you can see in the code version, a navigationItem has a title property instead of text.
This would work:
"S3Z-Mr-Qda.title" = "Login";
I think you should put your translation inside a generic
Localizable.strings file instead of the storyboard translation file.
Then use your same code to load the title text:
self.navigationItem.title = NSLocalizedString("Login", comment: "")
Take a look at the official doc in order to create this kind of file:
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html