How to add menu items to WebKitContextMenu (javascript, gjs)? - gtk

When I try to add menuitems to a webview with this code:
my_webview.connect('context-menu', Lang.bind(this, function(webview, c_menu, event, hit_test){
var action = new Gtk.Action({name:"some_name", label:"Some Label"});
action.connect('activate', Lang.bind(this, function(){
print("Your Menu Item !");
}))
var m_item = new WebKit.ContextMenuItem(action);
c_menu.append(m_item);
m_item.show();
return false;
}));
the app exit with the error "Segmentation fault (core dumped)"
What's the correct way to add a menuitem to the context menu of a WebView ?

Small correction:
var m_item = WebKit.ContextMenuItem.new(action);
This is confusing to say the least, it's because WebKit.ContextMenuItem has a custom constructor and not the usual GObject constructor that would be invoked with new WebKit.ContextMenuItem. The segmentation fault is due to WebKit choking when its context menu item doesn't receive an action; however, it would be good if GJS at least warned you what was going on here.
I've opened a bug report for GJS here.

Related

Second browser instance in protractor can not access class' elements

I am using the protractor framework. I'd like to write a test checking if User 1 successfully sends message to User 2. Both users should be logged in at 2 different browsers. So, what i want to do is:
it("Test", () => {
let browser2 = browser.forkNewDriverInstance(true);
browser2.Chat.icon.click();
This way i want to click the element icon in the class Chat, which looks like:
export class Chat{
public static icon: p.ElementFinder = element(by.css("#popup > div > div > div > section > header > a"));
}
When i try do do that, the following error appear: Property Chat does not exist on type Protractor
How can i access the elements in the classes from browser2?
So, browser2 in your example is a completely new instance of the browser. The elements on the Chat property are still attached to the initial browser instance (browser). What worked for me is creating a module for switching browser (and element, by, etc.) contexts. The second answer here helped me greatly in creating that library: Multiple browsers and the Page Object pattern
I'm using the page object pattern, so what I had to do was re-instantiate new page objects after I forked the new driver instance. So it ended up something like this (Javascript).
var Loginpage = require('../loginPage.js);
var loginPage = new LoginPage();
it('user1 logs in, sends message to user2' () => {
loginPage.login()
//send your message
});
it('user2 logs in and looks for message' () => {
browser.forkNewDriverInstance(true);
var newBrowserLoginPage = new LoginPage();
newBrowserLoginPage.login()
var newBrowserNotificationsPage = new UserNotificationsPage();
newBrowserNotificationsPage.checkMessages();
});
So, I suggest building the small library for switching browser contexts (and therefore element, by, protractor, etc. contexts).

How to enable auto focus on SAPUI5 input suggestion field

I'm currently developing a sapui5 mobile application and am using an sap.m.Input with suggestions bound by a model like this:
new Page('page', {
showNavButton: true,
content: [
new sap.m.Input({
id: "input",
type: 'Text',
showSuggestion: true,
suggestionItemSelected: function(event) {
event.getParameters().selectedItem.mProperties.text;
},
liveChange: function() {
// some stuff
}
})
]
});
The Model is created and bound like the following:
var model = new sap.ui.model.json.JSONModel();
// model is filled
sap.ui.getCore().byId('input').setModel(model);
sap.ui.getCore().byId('input').bindAggregation('suggestionItems', '/', new sap.ui.core.Item({
text: "{someField}"
}));
When I now click into the input field on a mobile device, kind of a new screen opens with a new input field, which the user has to manually focus again, what seems like a usability flaw to me.
Is there a nice possibility to enable auto focusing the input field on this new screen, so that the user doesn't has to do it again? Or can this screen be disabled at all on mobile devices?
sap.m.input doesn't seem to have a own method for focusing, or at least I'm not finding one - I already tried using jquery's .focus() on the new input field, but without success.
edit: for clarification, the suggestion works troublefree - only the absence of the auto focus on the appearing new screen is what bothers me.
Here is a workaround to "fix" this behavior: https://jsbin.com/lukozaq
Note 1: The above snippet relies on internal implementation of how the popup works. Use it with caution as there are currently no public APIs to access the corresponding internal controls.
Note 2: I put the word fix in quotes because it seems to be the intended behavior that the user has to click on the second input field explicitly, according to the comment in the source code:
Setting focus to DOM Element, which can open the on screen keyboard on mobile device, doesn't work consistently across devices. Therefore, setting focus to those elements are disabled on mobile devices and the keyboard should be opened by the user explicitly.
That comment is from the module sap.m.Dialog. On a mobile device, when the user clicks on the source input field, a stretched Dialog opens up as a "popup" which has the second input field in its sub header.
Please check the API documentation of sap.m.Input, it has a method focus. You can call:
this.byId("input").focus()
to set the focus into the input field.
Try this:
jQuery.sap.delayedCall(0, this, function() {
this.byId("input").focus()
});
About how to detect when the user presses the input field: maybe something like this? Only problem is that I think you probably don't know the id of the new input field which is shown.
var domId = this.byId("input").getId();
$( "#"+domId ).click(function() {
jQuery.sap.delayedCall(0, this, function() {
this.byId("input").focus()
});
});
I am pretty sure that the first piece of code is how to put focus on an input. I'm not sure about the second part, but it's something to try.
in onAfterRendering() do the below..
onAfterRendering : function() {
$('document').ready(function(){
sap.ui.getCore().byId('input').focus();
});
}
I didnĀ“t have the exactly same problem, but It was similiar.
My problem was that I needed focus into suggestion input when the view had been rendered. My solution was to put following code into "hanldeRouteMatched" function:
var myInput = this.byId("inputName");
var viewName = this.getView().getId();
var selector1 = viewName + "--inputName-inner";
var selector2 = viewName + "--inputName-popup-input-inner";
jQuery.sap.delayedCall(1000, this, function() {
myInput.focus();
if($("#" + selector1)){
$("#" + selector1).click();
jQuery.sap.delayedCall(500, this, function() {
if($("#" + selector2)){
$("#" + selector2).focus();
}
});
}
});
If you see that suggestion input catch focus, but It lose it after, or It never catched it, try increasing the time in delayedCalls. The needed time depends on your connection speed.

Kendo layouts not rendering widgets without setTimeout

I upgraded the kendo library to the 2014Q1 framework which had a few nice features that they were adding, however when I did that it broke any widget (grid, tabStrip, select lists, etc.) from rendering at all. I tracked it down to the layout/view not being able to activate the widget without being wrapped in a setTimeout set to 0. Am I missing something key here or did I build this thing in an invalid way?
http://jsfiddle.net/upmFf/
The basic idea of the problem I am having is below (remove the comments and it works):
var router = new kendo.Router();
var mainLayout = new kendo.Layout($('#mainLayout').html());
var view = new kendo.View('sample', {
wrap: false,
model: kendo.observable({}),
init: function() {
// setTimeout(function(){
$("#datepicker").kendoDatePicker();
// }, 0);
}
});
mainLayout.render('#container');
router.route('/', function() {
mainLayout.showIn('#app', view);
});
router.start();
Admittedly, I don't fully understand it, but hope this helps.
Basically when you try to init the #datepicker, the view elements have not been inserted into the DOM yet. You can put a breakpoint inside the init function, when it hits, check the DOM and you will see that the #app is an empty div, and #datepicker does not exist yet (at least not on the DOM).
kendo.Layout.showIn seems to need to exit in order for the view to finish rendering, but when it initializes the view's elements, it thinks the render is done and init is triggered incorrectly ahead of time. The setTimeout works because it runs the kendoDatePicker initialization asynch, the view is able to finish rendering before the timeout function.
Workarounds...
Trigger the view rendering from the view object itself:
var view = new kendo.View('sample', {
init: function() {
$("#datepicker").kendoDatePicker();
}
});
router.route('/', function() {
view.render('#app');
});
Select and find the datepicker from the view object itself:
var view = new kendo.View('sample', {
init: function() {
view.element.find("#datepicker").kendoDatePicker();
}
});
router.route('/', function() {
mainLayout.showIn('#app', view);
});
Near the bottom of this thread is where I got the idea for the 2nd option. Maybe someone else can come around and give a better explanation of whats going on.

durandal 2.0 custom dialog master-detail

After upgrading to durandal 2.0, I found I needed to convert my master list page to use the showDialog function instead of showModal.
Previously my master model looked like this:
define(['durandal/amd/require', 'durandal/app', 'durandal/viewLocator', 'durandal/system', 'durandal/plugins/router', 'durandal/lib/tableModel', 'viewmodels/product'], function (require, app, viewLocator, system, router, table, product) {
var tm = {
tableModel: new tableModel(),
createProduct: function (data) {
app.showModal(product, data);
}
}
//...
return tm;
}
Then in my product detail view page I could close the modal easily like so
data-bind="click: $root.modal.close">Close
Now in Durandal 2.0 it is much harder to get right.
The code in the masterpage is now
define(['durandal/app', 'durandal/viewLocator', 'durandal/system', 'plugins/router', 'lib/xhrs', 'lib/tableModel'], function (app, viewLocator, system, router, xhrs, table, product) {
var tm = {
tableModel: new tableModel(),
createProduct: function (data) {
app.showDialog(product, data);
}
}
//...
return tm; }
But the way to access the close function is annoying:
Firstly I have to require the 'plugins/dialog' into the product detail viewmodel; which I would prefer not to do as I don't think the detail viewmodel needs to know that it is a dialog, only the master list viewmodel needs to know that.
then in the compositionComplete event of the product detail view model I assign:
prodedit.close = function () {
dialog.close(prodedit);
}
(prodedit is the returned as the product detail vm)
In this way the product detail dialog can be closed using this:
data-bind="click: $root.close"
OK NOW HERE IS MY ISSUE:
This will work to popup the dialog once or twice, but then fails from then onward without an error. The only thing I can see is that dialogActivator.activateItem hits its fail line: dfd.resolve(false);
Interestingly if I do pause long enough on breakpoints the issue does not occur. But once it occurs once, it never works again to open the dialog.
Is there a better way to do this?
Thankyou.

Silverlight ChildWindow not disposed using MEF and MVVM

I'm not sure if what I'm experiencing is the same as here: Silverlight ChildWindow Memory Leak
but...:
I've got a Silverlight ChildWindow with 3 radio buttons in the same group with IsChecked all set to false in XAML, I don't want any of them selected upon opening. I open up the ChildWindow from my viewmodel:
if (_NewChildWindowCommand == null)
_NewChildWindowCommand = new RelayCommand(param => _cwService.ShowDialog(_newLocation, new NewViewModel(), closed =>
{
if (_newLocation.DialogResult.HasValue && _newLocation.DialogResult.Value)
{
//do something
}
_newLocation = null;
_newLocation = _container.GetExportedValue<INewChildWindow>();
}));
I then select one of the radio buttons hit OK. It Closes, I open it up again and the ChildWindow seems to have been disposed since upon opening, none of those radio buttons are selected (the way it should be). So I select a radio button again,hit OK, It Closes...But the third time I open the ChildWindow, it has the same radio button selected as when I closed it. This is what I don't understand. I thought by setting _newLocation=null like I did and then getting INewChildWindow from the container would give me a new ChildWindow but it doesn't seem to be the case. I tried calling GC.Collect() after setting _newLocation to null but that didn't work, and I tried setting the PartCreationPolicy to NonShared on the ChildWindow, however that doesn't make a difference since the instance of the ChildWindow is being stored in _newLocation and the class containing _newLocation isn't disposed of:
[ImportingConstructor]
public HomeViewModel(IChildWindowService cwService, INewLocationChildWindow newLocationChildWindow)
{
if (!IsDesignTime)
{
_cwService = cwService;
_newLocation = newLocationChildWindow;
_catalog = new AggregateCatalog();
_catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
_container = new CompositionContainer(_catalog);
}
}
Is there something else going on here?
Set the creation policy of the ChildWindow to NonShared. Then replace _container.GetExportedValue<INewChildWindow>() with _container.GetExport<INewChildWindow>(). This will give you a Lazy<INewChildWindow>, and you can use the Value property to get the child window. Then to release the export call _container.ReleaseExport, passing in the Lazy that was returned by the call to GetExport.