Adobe flex createPopUp() opening same instances when clicked - flex4

I'm new to Adobe Flex. I have 3 different fields consisting of three pop up buttons. When I click on one of the pop up button on my web page multiple times, I can see multiple instances of popups being opened.
I want to display only once when the pop up button is clicked.
public static var myPopUp:MyPopUpClass;
public static function openClosePopUp(open:Boolean, list:ArrayCollection = null, formComponent:UIComponent = null, mouseEvent:MouseEvent = null):void {
if (open) {
myPopUp = MyPopUpClass(PopUpManager.createPopUp(FlexGlobals.topLevelApplication
as DisplayObject, MyPopUpClass, false));
}
}

To avoid opening the same popup multiple times, you could replace
if (open) {
by
if (open && !myPopUp) {

Related

MFC Change CMFCToolBar button to Toggle instead of press/release?

I found an article online that said to setup the toolbar button to be a type that stays pressed you just set a style TBBS_CHECKBOX on the button but it doesn't work for me (it still acts like a normal button). I confirmed the style is set, just after created and the SetWindowText() MFC wizard setup of CMainFrame::OnCreate(). What am I doing wrong?
for (int i=0; ; i++) {
int id=m_wndToolBar.GetItemID(i);
if (id==0) {
break;
}
if (id == ID_THE_ID) {
m_wndToolBar.SetButtonStyle(i, TBBS_CHECKBOX);
}
}
Using Command Handlers is the recommended implementation here. A command ID may be used in multiple UI items, eg a menu item and a toolbar button. A handler affects all items with the same ID, so you don't need a separate one for each item. The CCmdUI Class provides methods that can cause UI items like menus or toolbar buttons to behave as push-buttons, check-boxes or radio-buttons, in addition to enabling/disabling.
In your example, suppose that the option whether to filter is instantiated on a per document basis, ie all views of the document would be filtered or non-filtered, all at the same time. You should define a boolean variable in your document class:
BOOL m_bFilterData = FALSE;
Then the ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for the toolbar button with the Filter pic (and possibly a menu item as well):
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
.
.
ON_COMMAND(ID_VIEW_FILTERDATA, OnViewFilterData)
ON_UPDATE_COMMAND_UI(ID_VIEW_FILTERDATA, OnUpdateViewFilterData)
.
.
END_MESSAGE_MAP()
void CMyDoc::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Tell all views to refresh - You can limit this using the lHint/pHint params
UpdateAllViews(NULL, 0L, NULL);
}
void CMyDoc::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(m_nTotalItems>0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}
Now, if the filter option is instantiated per view, ie each view can indpendently be filtered or non-filtered, the above must go to your view class(-es):
void CMyView::OnViewFilterData()
{
// Toggle filtered state
m_bFilterData = !m_bFilterData;
// Refresh this view only
.
.
}
void CMyView::OnUpdateViewFilterData(CCmdUI* pCmdUI)
{
// Enable/Disable as needed
pCmdUI->Enable(GetDocument()->m_nTotalItems > 0);
// Show pressed/checked if data filtered
pCmdUI->SetCheck(m_bFilterData);
}

How to set the navigation controller to take the user to a different view in xamarin ios

My initial view has this code
if (CLLocationManager.Status == CLAuthorizationStatus.Denied ||
CLLocationManager.Status == CLAuthorizationStatus.Restricted ||
CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
{
Core.FirstLaunch = true;
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
}
else
{
NavigationController.PushViewController(new JobListViewController(), false);
}
If the location is not enabled, the location services verify controller is shown, however, the menu has a back button which is taking the user to license activation screen.
How can I change the back button to Job list and clicking it will take the user to job list controller instead?
e.g.,
Solution 1: You need to replace the backbutton and associate an action handler. You could either use text or an image for the Back Button. To do this, in your ViewDidLoad override, add this:
var _backButton = new UIBarButtonItem()
{
Title = "Back",
// Image = UIImage.FromBundle("back_navbar").OriginalRendering(), Need to add the image in Resources for this to work
TintColor = UIColor.FromRGB(0, 70, 113) // Change this to your app colours
};
_backButton.Clicked += _backButton_Clicked;
NavigationItem.SetLeftBarButtonItem(_backButton, animated: true);
And then handle the button press as shown:
void _backButton_Clicked(object sender, System.EventArgs e)
{
var controller = new JobListViewController();
this.PresentViewController(controller, true, null);
}
Solution 2: You could also just remove the unwanted LicenseActivation view controller from the navigation stack so going back won't go to that page. So when you are leaving the LicenseActivation page, in the ViewWillDisappear override, add this code:
var oldControllers = this.NavigationController.ViewControllers;
var newControllers = new UIViewController[oldControllers - 1];
int index = 0;
foreach (var item in oldControllers) {
if (item != this)
{
newControllers [index] = item;
index++;
}
}
this.NavigationController.ViewControllers = newControllers;
Solution 3:
Just use a modal for the LicenseActivation page, so that as soon as you Accept the LicenseActivation, it closes the modal and goes to the next page.
So you are pushing views on to the navigation stack, e.g.,
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
so when you press back you are popping the stack and going to the last view. If you don't want this type of navigation you could do this:
Don't push the LocationServicesVerifyViewController to the navigation controller. Rather present it modally like this:
PresentModalViewController(new LocationServicesVerifyViewController(), false);
You will need a close button on LocationServicesVerifyViewController to dismiss.
I would present the JobListViewController by pushing to the navigation controller first then check for the location inside JobListViewController then present the modal LocationServicesVerifyViewController if needed.
OR
Do you need a whole view controller for this? You could just present a popup:
var locationServiceAlertController = UIAlertController.Create("Location Services are off", "Your company... Bla", UIAlertControllerStyle.Alert);
locationServiceAlertController.AddAction(UIAlertAction.Create("Enable", UIAlertActionStyle.Default, alert => Console.WriteLine ("Do your enable stuff")));
locationServiceAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alert => Console.WriteLine ("Cancel was clicked")));
PresentViewController(locationServiceAlertController, true, null);

Firefox add-on triggers code in each open window

I have a Firefox add on that displays a pop-up when it sees a certain response header. This works fine when I have a single window. However, when I have multiple windows open, and one of the tabs in a window triggers the pop-up code in my add-on (due to the presence of said header) I get a pop-up in each of my open windows. For example, if I have 3 windows open, I get 3 different pop ups, one for each windows. Is this the default behavior, and is there an easy in-built way to fix this using their SDK.
Edit:
I have the following code:
Util.requestBlock(httpChannel) {
/*load response headers here*/
if (responseHeaders.includes("header_xyz"))
alert("show popup");
}
Util.monitor = function(w) {
this.obsService = Components.classes['#mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
this.obsService.addObserver(this, 'http-on-examine-response', false);
}
Util.monitor.prototype = {
'observe': function(subject, topic, data). {
if (topic == 'http-on-examine-response'). {
var channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
var block_response = new Util.RequestBlock(channel);
}
},
};
The Util.monitor adds an observer. Whenever a response is received, the "Observe" function is called.
var windows = require("window-utils");
for (window in windows.browserWindowIterator)
doToWindow(window);

Adding functionality to wicket palette button

I want to add some functionality to the right arrow button, the one that puts the user selection into the selected elements panel. Specifically, when the user selects an element from the avaliable choices, I don't want the element to be taken to the selected elements panel if there are elements at the right panel of another palette. So basically, what I need is to execute custom java code when the button is pressed, and alter the default behavior of the palette when a condition occurs.
I found the solution somewhere else. Just in case someone needs it, here is what you have to do.
myPalette = new Palette<MyClass>(...) {
#Override
protected Recorder newRecorderComponent() {
Recorder<MyClass> recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
// Custom code
...
if (target != null)
// Update another component
target.add(anotherComponent);
}
}
);
return recorder;
}
};

Reusing a tab in Firefox, TabOpen event, and beyond

I followed a tutorial on reusing tabs inside Firefox, and right now my extension does it well. However, I also need to reuse tabs that are opened from outside (from some application, start menu etc.). How do I do this?
I tried adding an event listener for TabOpen event, but when I log the
event.target.linkedBrowser.currentURI.spec
it's value is "about:blank". I expected the actual address that I typed into the address bar (automatically opens in a new tab), or the address that I open from some other application, so I can close that tab immediately, and the focus the right one. What am I doing wrong?
Thanks in advance.
Just in case, here's the code that reuses the tab when a new tab is requested from an extension
function openAndReuseOneTabPerURL(url) {
var wm = Components.classes["#mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserEnumerator = wm.getEnumerator("navigator:browser");
// Check each browser instance for our URL
var found = false;
while (!found && browserEnumerator.hasMoreElements()) {
var browserWin = browserEnumerator.getNext();
var tabbrowser = browserWin.getBrowser();
// Check each tab of this browser instance
var numTabs = tabbrowser.browsers.length;
for(var index=0; index<numTabs; index++) {
var currentBrowser = tabbrowser.getBrowserAtIndex(index);
if (url == currentBrowser.currentURI.spec) {
// The URL is already opened. Select this tab.
tabbrowser.selectedTab = tabbrowser.mTabs[index];
// Focus *this* browser-window
browserWin.focus();
found = true;
break;
}
}
}
// Our URL isn't open. Open it now.
if (!found) {
var recentWindow = wm.getMostRecentWindow("navigator:browser");
if (recentWindow) {
// Use an existing browser window
recentWindow.delayedOpenTab(url, null, null, null, null);
}
else {
// No browser windows are open, so open a new one.
window.open(url);
}
}
}
When you receive the TabOpen event, it's too early for the page content to be loaded still. When you receive the TabOpen event, however, you should register for load or DOMContentLoaded. When you receive that event, you should be able to access the URI.
I guess you could extract the wanted behaviour from the implementation in the Tab Mix Plus extension

Resources