How to grab a path for app.navigationBars - swift

I faced an issue that is combined with UI testing of the view.
I have an issue with an incorrect path to the element that is the text field, which is Search. I would like to achieve the state when the code for app.navigationBars will be resistant for different languages. That's why right now it looks the following way:
var airportsSearchTextField: XCUIElement { app.navigationBars["Airports"].searchFields["Search"] }
This won't work properly for another language like English. I know that it could be possible to add accessibilityIdentifier, but I'm not sure where and maybe for navigationBar is there any other way to implement a better solution to grab this element within UI tests?
func selectFlight() { airportsSearchTextField.tap() }

Related

TextKit 2 - How to create word level NSTextElements in order to tag words in text

I'm trying to create tags/labels/badges to tag certain words(actually sometimes multiple words can constitute a tag). Currently, I've added a custom NSAttributedString key that I have used to tag words with their part of speech. I want to tag these words with a rounded background coloring. I've gone through the code in this sample code, that creates tags like this:
But the example code just takes existing NSTextElements(paragraph level) and applies styling to them. When I plug into the same delegate functions from the text code all the text elements are paragraph level. For example
This is one.
This is two.
Would create two text elements: This is one. and This is two.. I'm curious how I can split these into multiple text elements. For example if I wanted to just tag EGG in EGG SANDWICH NO. 2, I'm guessing I need to split that text element into two(EGG and SANDWICH NO. 2), but I can't figure out how to do that currently, or find any examples of adding word tags to text on MacOS(The app does not need to support iOS, only MacOS).
Am I along the right track for accomplishing this? If so, what's the best way to split up the NSTextElements?
I had a similar problem and failed in a way that I really discourage to do that.
TextKit 2 is evolving. I report on trying to create a NSTextElement subclass below the NSTextParagraph level in macOS Ventana (autumn 2022).
My problem was to communicate the layout position of a text attachment, which is part of the attributed string, to the text view to position the associated subview and its exclusion path accordingly - a standard problem for text with figures.
The path to introduce a subclass of an NSTextElement into the text layout process is via delegates.
Starting at the text store:
NSTextContentStoreDelegate offers methods to introduce custom NSTextElements depending on the content of the NSAttributedString:
1. Paragraph Level:
func textContentStorage(NSTextContentStorage, textParagraphWith: NSRange) -> NSTextParagraph?
2. Arbitrary NSTextElement Level:
func textContentManager(NSTextContentManager, textElementAt: NSTextLocation) -> NSTextElement?
NSTextLayoutManagerDelegate can deliver custom NSTextLayoutFragment objects for these custom NSTextElements:
func textLayoutManager( _ textLayoutManager: NSTextLayoutManager, textLayoutFragmentFor location: NSTextLocation, in textElement: NSTextElement) -> NSTextLayoutFragment
The custom NSTextLayoutFragment objects can do what you desire.
I tried to subclass on the NSTextElement level (using method 2 of NSTextContentStoreDelegate) and used a custom NSTextLayoutFragment to execute my code. The result was that the entire layout process stopped when this custom NSTextLayoutFragment object was encountered. I overrode all methods that are in the documentation of the NSTextLayoutFragment to catch the problem and failed. Even worse, I introduced memory problems into my code that Swift as a language should guard against. At places where I and the compiler expected a model object the executing code saw the view which displays this model object.
I finally accepted that I can not go below the paragraph level and subclassed NSTextParagraph and introduced this class using the first and not the second NSTextContentStorageDelegate method. I solved the desired atomisation down to the attachment within the subclasses. That worked immediately and brought the desired functionality in a very precise and efficient way.

VerticalLayout dynamically hiding visibility

I was wondering whats the best way around dynamically hiding some menu items. At the moment I have 6 items just in a matrix layout row. I want to have 3 items aligned left and 3 items alligned right. If one of the items is set to not visible I want it to move accross. I've done something similiar in a horizontal layout and setting the visibility to hidden. I was wondering if this would work with a vertical layout? Having trouble trying to figure out exactly how I would do it as I'm quite new to UI5 xml css and javscript. Any help would be great.
Also I'm having one other issue unrelated to this, I cant seem to bind my json model to my xml fragment, if I use the same code on my normal xml view it prints out the model data. But on my fragment it just prints it like {person>/fullName} any ideas ?
Belongs to your second question.
Maybe your binding was quoted on copy and paste? Check the native XML Code.
If no data are shown (not "{person>/fullName}"), add dependent to connect the models of your view
var oFragment = sap.ui.xmlfragment(sFragment, "fragmentName", this);
oView.addDependent(oFragment);

Perl HList: Change -background for individual items

I'm trying to alert the user that some data has been changed and needs to be saved. The data is displayed in Perl's Tk::HList box. I was hoping I could do:
if ($new_item) {
$HList->add($stock_no,-background=>"red");
}
or even:
if ($new_item) {
$HList->itemCreate($stock_no,0,-text=>$stock_no,-background=>"red");
}
but both throw
Tk::Error: Bad option `-background'
I've seen the idea to use ItemStyle but there's no clear answer if that works or not or if it's the best (and only) solution. Is there another way to highlight certain rows to alert the user?
It looks like it is the best way to change the background:
use Tk::ItemStyle;
my $alert = $mw->ItemStyle('text',-background=>"red");
$HList->itemCreate($stock_no,0,-style=>$alert);
I have to include that style to each item I add, there doesn't seem to be a way to do the whole row at once.

how to switch language at runtime inside the app?

I have a requirement to switch UI language at run-time by opening and selecting a popup menu. I did some reading on cocoa's internationalization but found it not suitable for my project since it requires user to make changes in the system setting.
Post like "http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language" suggests setting the AppleLanguages would also require an app-restart.
I wonder if I can (a) create multiple NIBs and call initWithNib according to the current language or (b) use one NIB but create a plist of strings and make a function to set title string for all the texts in all my viewWillAppear. Which solution sounds better or please let me if there is a third way.
Thanks
Leo
The simplest way I can think of is reloading all your views, and updating the text property of all text components (such as UILabel, UITextField, etc.). The language specific text to be set can be returned by a method of yours, something like-
-(NSString*) localizedStringForKey: (NSString*)key andLanguage: (NSString*)lang
{
if([lang isEqualToString:#"en"])
{
if(key == #"hello")
return #"Hello";
//and so on...
}
else if([lang isEqualToString:#"fr"])
{
if(key == #"hello")
return #"Bonjour";
//and so on...
}
}
P.S: Here I am returning hard-coded values, but you can read them from language-specific plists of yours.

Dashcode - how to register and use my own filterPredicate procedurally

In my Dashcode mobile app I have a listView that is bound to a datasource. By default it shows everything in the datasource. If I add a search field the user may limit the list to just the records that match their search text.
I want to create my own preset searches attached to buttons that would be able to load a list view and show only the records from my datasource that match my custom search.
It seems like this ought to be possible, but so far I haven't figured out how to register my own filterPredicate and then use it.
I'm guessing this is what I want to do because it seems like this is what the search field part does.
Has anyone figured out how to do this?
Any help would be appreciated
According to the dashcode starter section, you could use something along the lines of:
itemDescription = Class.create(DC.ValueTransformer, {
transformedValue: function(value){
return "Page: " + value;
}
});