How can you dynamically add a new tab to a tab-panel in Red - red

Let's say you have a tab-panel like so :
editor: layout [
below
t: tab-panel 350x350 [
"tab 1" [
below
b: button 75x25 "Interpret" on-click [do a/text ]
a: area 320x250
]
]
]
view editor
How could I dynamically add a new tab to it so that has the contents of the current tab?

They are several ways to add a new tab dynamically, but in all cases, it boils down to adding:
A tab label as a string! to t/data block.
A corresponding panel face object! to t/pane block.
Here is a fully working example code:
tab1: [
below
button 75x25 "Interpret" on-click [do face/parent/pane/2/text ]
area 320x250
]
editor: layout compose/deep/only [
below
button "add tab" [
append t/data "tab 2"
append t/pane make face! [type: 'panel pane: layout/only tab1]
]
t: tab-panel 350x350 ["tab 1" (tab1)]
]
view editor
Some remarks:
tab1 definition has been externalized, so its definition can be reused for another tab content (as per your request).
a: word has been removed as it cannot be duplicated, access to the current area face in current tab panel is now done by walking up the face tree. b: definition has been dropped for same reason (and it's not used anyway).
Examples of dynamic behaviors and dynamic face construction (without VID dialect) are available here. tab-panel face type is described there.

Related

How can I set the vscode extension custom icon in activity bar to the first?

I added one icon to the activity bar, and it works well.
I need to put it at the top of the activity bar (at the top for Resource Management), how can I reach the requirement?
Now the code like this: Is there any option can change the order?
"viewsContainers": {
"activitybar": [
{
"id": "thingio_sidebar",
"title": "ThingIO Options",
"icon": "media/dep.svg"
}
]
}

How to highlight the selected tab in sap.m.IconTabBar?

Dear SAPUI5 developers,
I have a sap.m.IconTabBar and I set the active tab by the code when the user switch between pages. I used the following code:
sap.ui.getCore().byId(this.createId("iconTabBar")).setSelectedKey("1");
The problem is that it switch the selected tab correctly to the first tab. But it does not show the blue line under the tab that shows it is selected.
Please look at the following images:
What shows when I select the first tab by code:
But what it shows when I press the tab by the mouse it shows a blue line under the icon like the following:
As #Ash said in the comments you need to call fireSelect but this works just if user the second tab at first. If the user is on the first tab and switches between the pages then fireSelect does not act properly. Thus you need to select the second tab at first then it will works almost all times.
sap.ui.getCore().byId(this.createId("iconTabBar")).setSelectedKey("2");
sap.ui.getCore().byId(this.createId("iconTabBar")).setSelectedKey("1");
sap.ui.getCore().byId(this.createId("iconTabBar")).fireSelect();
Ok I had a look into the IconTabBar source Code and theres something I dont really get why but here is how it proceeds :
when you call IconTabBar.setSelectedKey(key), it calls IconTabHeader.setSelectedKey(key)
then internally the IconTabBarHeader calls setSelectedItem(item, true)
the 'true' here is important, the parameter is named 'bAPIchange' in the setSelectedItem function, and it is used as condition for the fireSelect() :
if (!bAPIchange) {
// fire event on iconTabBar
if (bIsParentIconTabBar) {
oParent.fireSelect({
selectedItem: this.oSelectedItem,
selectedKey: sSelectedKey,
item: this.oSelectedItem,
key: sSelectedKey
});
} else {
// fire event on header
this.fireSelect({
selectedItem: this.oSelectedItem,
selectedKey: sSelectedKey,
item: this.oSelectedItem,
key: sSelectedKey
});
}
}
Which explains why the event is not fired in your case

How can I get the label for a scroll view in a Xcode 7.2 XCTestCase?

In XCode 7.2, if I can get XCUIApplication().scrollViews["Foo"].otherElements.otherElements["Page Title"], what's the way to say, "Give me the page title for this scrollView named "Foo"?"
I have tried asking for the accessibilityLabel and staticTexts.
I have tried adding XCUIApplication().scrollViews["Foo"], XCUIApplication().scrollViews["Foo"].otherElements, etc to my watch list but I don't see any useful information.
When I do a po on XCUIApplication().scrollViews["Foo"].otherElements, I get:
<snip>
↪︎Find: Descendants matching type Other
Output: {
Other 0x7f904b60e910: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}}, label: 'PDF article'
Other 0x7f9049efb6e0: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}}
}
(Page title in this case is 'PDF article')
So I feel like I should be able to access it with staticTexts at least.
It looks like your page title is a custom view that doesn't inherit from UILabel (UILabel descendants are marked as StaticTexts).
You need to set an accessibility identifier (not label) on your page title in the app's code.
pageTitle.accessibilityIdentifier = "Page Title"
This should make your code work and would be the best practice.
Alternatively, if you change your search chain to use the value of the label instead of "Page Title", that should work too. However, if you open a different page with a different title, this won't work.
XCUIApplication().scrollViews["Foo"].otherElements["PDF article"]

summernote: how to add a "italic" button show it stay next to the bold and underline buttons?

I am new to summernote. I hope to add a "italic" button next to the bold and underline buttons because it is such a common edit operation. I am unable to find examples of how to do it.
Thanks for any help!
I think that's by default. But you can of course customize your own toolbar.
$('.summernote').summernote({
toolbar: [
//[groupname, [button list]]
['style', ['bold', 'italic', 'underline', 'clear']]
]
});
You can read more about custom toolbar here.
By Design:
As stated here you can just configure summernote's toolbar by passing in a custom structure like this:
$('#summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
]
});
NB: When overriding the toolbar structure you need to pass the whole toolbar and you cannot just override a single group (e.g. by initializing the array with just ['style', ['bold', 'italic', 'underline', 'clear']]) as it would remove all the other actions
Quick n dirty:
look for ['bold', 'underline' .... in summernote.js
add 'italic' between them
NB: it will be gone when you update. Surely it's better to copy the whole toolbar setting and replicate in your init options, adding whatever you see fit. But technically, it's there and it's gonna work. Line 9789 in my version. (Don't trust line numbers, look for the string.)

SAPUI5- Hide button in a listitem when it is clicked

Is it possible to hide a button of a particular item on the list? Lets say I have a list with swipedContent which contains a button with id: "actionButton". I want to hide "actionButton" when it is clicked.
Code:
new sap.m.List("list", {
backgroundDesign : "Transparent",
mode : sap.ui.Device.system.phone ? sap.m.ListMode.None
: sap.m.ListMode.SingleSelectMaster,
itemPress : [ oController.handleListSelect, oController ],
swipeContent : new sap.m.Button({
id: "actionButton",
text : "Actions",
type : "Accept",
press : [ oController.onPress, oController ]
})
})
EDIT:
onPress: function(e){
var list = this.getView().byId("list");
var swipedItem = list.getSwipedItem();
//Below code destroys swipeContent from ALL THE ITEMS in the list which I don't want
list.destroySwipeContent();
//And this doesnot work
swipedItem.destroySwipeContent();
}
If I use:
sap.ui.getCore().byId("actionButton").setVisible(false);
It will hide the buttons from all the items. But I want it to hide for that particular item. Is there a way?
Please help. Thank you.
From what you've written, I understand that you want the action button to disappear once you've pressed it. This happens automatically already - see the Explored example for the Sample: List - Swipe (you can set Chrome to emulate a phone so you can test the swipe; I'd also suggest you modify the sample List.controller.js on the fly so that it doesn't remove the item (the default action for this sample):
handleReject: function (evt) {
var oList = evt.getSource().getParent();
// Next line commented out on purpose, for testing
// oList.removeAggregation("items", oList.getSwipedItem());
oList.swipeOut();
}
so you can see the result.