alert window in my firefox addon - firefox

I'm fresh to firefox addons development, so pls excuse me if it's too dumb. I just couldnt find the answer here in the Stack.
I try to launch an alert window from my addon:
alert('This is an alert');
However, it won't recognize 'alert'. What component should I include (Require)?
Thanks!

For a modal alert, as the question asks, better to use prompt-service, not alerts-service:
var prompts = Cc["#mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
prompts.alert(null, "AlertTitle", "AlertMessage");

Perhaps this could help you?
https://developer.mozilla.org/en-US/docs/XUL/School_tutorial/User_Notifications_and_Alerts?redirectlocale=en-US&redirectslug=XUL_School%2FUser_Notifications_and_Alerts
Since links occasionally die I'll save you some scrolling and post the code that might be most useful:
let alertsService =
Cc["#mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
let title = this._bundle.getString("xulschoolhello.greeting.title");
let message = this._bundle.getString("xulschoolhello.greeting.label");
alertsService.showAlertNotification(
"chrome://xulschoolhello/skin/hello-notification.png",
title, message, true, "", this, "XULSchool Hello Message");

Related

What is the correct way to send suggestions to the user with the [Suggestions] response type?

I have tried for what feels like hours to get the Composer to send a suggestion back to the user. I want the suggestion, if clicked, to open another website.
First, I created a template:
# urlCard(title, value)
[CardAction
Type = openUrl
Title = ${title}
Value = ${value}
]
This works fine if I use it from a hero card, for example:
[HeroCard
title = Click that button
text = This is a test hero card
buttons = ${urlCard( 'Google', 'https://google.com/' )}
]
But I cannot get suggestions to work with [Suggestions:
[Suggestions
SuggestionActions = ${urlCard( 'Google', 'https://google.com/' )}
]
This is what I see in the Bot Framework Emulator:
How can I send suggestions to the user, without being in a hero card?
I have no experience with the Composer but I can tell you how the Python API works and maybe it can help you to figure this out.
In Python (JS is very similar) you would do something like:
CardAction(title="Yes?", type=ActionTypes.im_back, value='yes')
CardAction(title="No?", type=ActionTypes.im_back, value='no')
The suggested actions disappear after the user makes a selection and the bot will receive a message with the action value. I don't think you can embed a URL however, so maybe this is the actual issue you have.
This worked for me:
[Activity
SuggestedActions = ${openUrl( 'Google', 'https://google.com/' )}
]

Switch to another window in Cypress

I want to switch to to a new window on pressing a button, and the new window has dynamic URL, How do we handle this. Is there any workaround. I searched through many articles
Click the add button
cy.get('a[href*="javascript:xxxSearch();"]').click()
It opens a new window
I want to access(search/add the elements in new window and then switch back to previous main window
May be a good idea if you could share the full html of that page. As I understood from the question, may be grab the href and then get the attribute of href to a const and visit to that link as below. Just give a try and let me know if this is working for you.
it('Open a new window',function(){
cy.visit('some_url')
//test code continues....
cy.get('a[href="/some/link"]').then(($href)=>{
const hrefLink = $href.attr('href');
cy.visit(hrefLink);
// rest of you test to grab the search button
})
})

Avoid panel to autoHide in Firefox extension

I am actually trying to develop a Firefox extension using the high level apis, and specifically trying to avoid a panel to autohide when you pick a file or when you click outside of the panel itself.
Does somebody has an idea of how to do this?
I know that it is possible using XUL, so why is this not easy using the apis?
Thank you in advance for your answers.
This is the offical sdk method of doing it:
let myPanel = Panel({.....})
let { getActiveView }=require("sdk/view/core");
getActiveView(myPanel).setAttribute("noautohide", true);
Idea from
this
var toolbarbuttonPanel = doc.createElement('panel');
toolbarbuttonPanel.setAttribute('id', 'toolbarbutton-panel');
toolbarbuttonPanel.setAttribute('type', 'arrow');
toolbarbuttonPanel.setAttribute('noautohide', 'true'); // This is important
var toolbarbuttonLabel = doc.createElement('label');
toolbarbuttonLabel.setAttribute('value', 'toolbarbutton panel');
toolbarbuttonPanel.appendChild(toolbarbuttonLabel);
var mainPopupSet = document.querySelector('#mainPopupSet');
mainPopupSet.appendChild(toolbarbuttonPanel);
Then add this on sdk action/toggle button click:
toolbarbuttonPanel.openPopup(btn);
And Noitidart's comment

How Do I Prevent the KendoGrid's RemoveRow Function from Prompting?

I'm using a Kendo Grid's removeRow function. It works, but it always prompts "Are you sure you want to delete this record?" whenever I programmatically remove a row. I've already done the decision-making as to whether or not the row should be removed, so I don't want this message to show up. Googling didn't help and I couldn't find any similar question on StackOverflow or Kendo's forum. I know I could change the code, but I was wondering if there's a way to configure the grid to just not show it? Another solution would maybe be to temporarily block confirm prompts, possibly? Not sure if that's possible.
Setting editable.confirmation to false should do the trick:
kendoGrid( {
editable: {
confirmation: false
}
})
I have a workaround that I just figured out, in the meantime. It works fine, but it's a bit hacky:
var oldConfirm = window.confirm;
window.confirm = function() { return true; };
grid.getKendoGrid().removeRow(selectedRow);
window.confirm = oldConfirm;
I'd still be interested in hearing about any disabling of the confirmation, however, and I'll accept that as the answer if it comes along.

How Do You Change the Title of a Page in wx.aui.AuiNotebook?

So I'm working on a text editor to better learn wxPython (and to make a text editor that I really like :P). I have been having trouble finding much info on the wx.aui.AuiNotebook class. One thing I would like to know is how to interact with its pages. For example, I would really like to know how to change the title of a page (so that I can update the page title when a user saves or to mark it when there is unsaved changes). Any assistance on this matter would be most appreciated!
The method is called SetPageText, so you would do something like:
current_page = notebook.GetCurrentPage()
current_page_index = notebook.GetPageIndex(current_page)
current_label = notebook.GetPageText(current_page_index)
if not current_label.endswith(' (*)':
notebook.SetPageText(current_page_index, current_label + ' (*)')
Apparently, in wxPython version 2.8 does not include wx.aui.AuiNotebook.GetCurrentPage(). What I apparently didn't realize is that a "page" in the wx.aui.AuiNotebook is equivalent to the panel that is being added to it. Thus the following code will work,
self.panelBox = []
newPanel = wx.Panel(self, wx.ID_ANY)
#YADA YADA STUFF!
self.nb.AddPage(newPanel, "Untitled Document "+str(self.untitledDocCount))
currPageIndex = self.nb.GetPageIndex(newPanel)
currLabel = self.nb.GetPageText(currPageIndex)
if not currLabel.endswith(' (*)'):
self.nb.SetPageText(currPageIndex, currLabel+' (*)')
self.panelBox.append(newPanel)
It's up to the programmer to ensure that the pages (panels) are accessible. I do this by storing the panel references in a "panel box" and then switching between them accordingly in conditions such as a "change tab" event. I don't know if this is the best way to do this, but it appears to work so far.

Resources