| 
		
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Hi all
 after identifying the desired tab with Firefox4GetTabs function, what is the more efficient way to switch to it
 by using its name or position? Upposing i'm currently on 2nd tab, i want to switch to 4th one, or to a tab named
 "thetabiwanttogoto"?
 
 Thanks
 
	
	
	
		
	Posts: 1,769Threads: 410
 Joined: Feb 2003
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Thanks for the input Ken, but you point the link to the macro i refer in my post to actually find a tab, it's name and row place.
 What i'd like is the way to switch to the desired tab, knowing it's name or postion.
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		Updated 2014-04-30. 
If does not work with portable Firefox: FireFox portable and FireFox functions (FirefoxGetTabs, ..) 
This version gets accessible objects of tab buttons. 
Also changed: 
1. Renamed from Firefox4GetTabs to FirefoxGetTabs. 
2. Error if does not find window or something fails. 
3. names is optional, can be 0.
 
Function FirefoxGetTabs ;/function# [hwndFF] [ARRAY(str)&names] [ARRAY(str)&urls] [ARRAY(Acc)&docObjects] [ARRAY(Acc)&buttonObjects]
 
 ;Gets names of Firefox tabs. Optionally gets their URL and accessible objects.
 ;Returns 0-based index of the selected tab.
 ;Error if fails.
 
 ;hwndFF - Firefox window handle. If 0, finds.
 ;names - variable for tab names. Can be 0 if don't need.
 ;urls - variable for addresses. Can be 0 if don't need.
 ;docObjects - variable for DOCUMENT accessible objects that represent web pages. Can be 0 if don't need.
 ;buttonObjects - variable for PAGETAB accessible objects that represent tab buttons. Can be 0 if don't need.
 
 ;REMARKS
 ;Requires QM 2.3.3 or later.
 ;Elements of urls and docObjects of non-loaded tabs will be empty. Firefox does not load pages in invisible tabs at startup.
 
 ;EXAMPLE
 ;ARRAY(str) names urls
 ;int selectedTab=FirefoxGetTabs(0 names urls)
 ;out selectedTab
 ;int i
 ;for i 0 names.len
 ,;out "--------[]%s[]%s" names[i] urls[i]
 
 
 ARRAY(str) _names; if(!&names) &names=_names
 names=0
 if(&urls) urls=0
 if(&docObjects) docObjects=0
 if(&buttonObjects) buttonObjects=0
 
 if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) end ERR_WINDOW
 
 int i r=-1
 FFNode fn
 ARRAY(str) ap
 
 ;enum tabs
 Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004 1) ;;note: added 1 s waiting because fails when called first time after launching FF
 rep
 ,if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
 ,
 ,names[]=a.Name
 ,if(&buttonObjects) buttonObjects[]=a
 ,
 ,;get selected tab
 ,if(r<0 and a.State&STATE_SYSTEM_SELECTED) r=i
 ,
 ,if &urls
 ,,;get id of associated pane and store in ap. Because the order of tabs and panes may be different.
 ,,fn.FromAcc(a)
 ,,ap[]=fn.Attribute("linkedpanel")
 ,
 ,;next
 ,a.Navigate("n"); err break
 ,i+1
 
 if(r<0) end ERR_FAILED
 if(!&urls and !&docObjects) ret r
 
 ;enum panes
 if(&urls) urls.create(names.len)
 if(&docObjects) docObjects.create(names.len)
 #if QMVER<0x2030400
 a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
 err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
 #else
 a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
 #endif
 rep
 ,;get id of this pane, and find in ap
 ,fn.FromAcc(a); _s=fn.Attribute("id")
 ,for(i 0 ap.len) if(ap[i]=_s) break
 ,if(i=names.len) goto next2 ;;should never happen
 ,;get DOCUMENT object and url
 ,Acc aa; a.Navigate("fi2" aa); err goto next2
 ,if(&urls) urls[i]=aa.Value
 ,if(&docObjects) docObjects[i]=aa
 ,
 ,;next2
 ,a.Navigate("n"); err break
 
 ret r
 
 err+ end _error
Function FirefoxSelectTab ;/function hwndFF $name [flags] ;;flags: 1 name is URL, 2 wildcard, 4 beginning, 8 end, 16 anywhere, 32 rx
 
 ;Finds and select Firefox tab.
 ;Error if not found.
 
 ;hwndFF - Firefox window handle. If 0, finds.
 ;name - tab name. If flag 1 - URL.
 ;flags:
 ;;;1 - name is URL.
 ;;;2-32 - how to compare name. Default: exact match. Always case insensitive.
 ;;;
 
 ARRAY(str) names urls; ARRAY(Acc) a
 int selectedTab=FirefoxGetTabs(hwndFF names iif(flags&1 &urls 0) 0 a)
 int i
 ARRAY(str)& as=iif(flags&1 urls names)
 for i 0 names.len
 ,if SelStr(flags|1 as[i] name)
 ,,if i!=selectedTab
 ,,,a[i].DoDefaultAction
 ,,ret 1
 
 end "tab not found"
 err+ end _error
Or simply find and click tab button accessible object. 
Acc a.Find(... "PAGETAB" ...) 
a.DoDefaultAction
	 
	
	
	
		
	Posts: 1,769Threads: 410
 Joined: Feb 2003
 
	
	
		GAHHHH!!!!  I need to start drinking coffee! 
sorry about that.  here's a skeleton that'll do that.  you should be able to change the "Inbox * - Gmail" string to be a variable that you pull out of the array after using the Firefox4GetTabs.
 
Macro Macro int w1=win("* - Mozilla Firefox" "Mozilla*WindowClass" "" 0x805)Acc a1.Find(w1 "PAGETAB" "Inbox * - Gmail" "class=MozillaWindowClass" 0x1005)
 a1.Mouse(1)
 
	
	
	
		
	Posts: 1,769Threads: 410
 Joined: Feb 2003
 
	
	
		yeah...ok, I guess you could do that thing G just wrote up too....I guess... :lol:
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Hmmm, no way of doing that...simpler????
 I managed to do Acc.mouse(1), but not very effective because two tabs with same name does mess.
 
 Let's cook your code Gintaras.
 
 Aren't tabs able to be selected or activated, or focused to bring them to front?
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		What can be simpler than this?
 FirefoxSelectTab 0 "name"
 or
 FirefoxSelectTab 0 "url" 1
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Sometimes, i want understand what is in my code, to reuse it suited for my needs, and yours is so advanced that ihardly can get the meaning.
 
 It's simple for you, not necessarily for end user.
 
 When Federer plays tennis, i feel like it is simple 'til i try to hit a ball myself.......
 
	
	
	
		
	Posts: 1,769Threads: 410
 Joined: Feb 2003
 
	
	
		I think your supposed to use it like this 
Macro Macro FirefoxSelectTab(0 "Inbox" 16)
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Well, for once the way Gintaras took was not appropriate, even if i used piece of code in another macro yet.....
 The trick i was looking for was the dodefaultaction thing, baffled i did not find it by myself.
 
 I just had then to tweak the original Firefox4GetTabs function, and off we go.
 
 here what i did:
 
 ARRAY(str) names urls
 int selectedTab=Firefox4GetTabs(0 names urls)
 
 int i
 
 int w=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804)
 Acc a.Find(w "PAGETAB" names[2] "class=MozillaWindowClass" 0x1005) => find by name
 Acc a.Find(w "PAGETAB" "" "class=MozillaWindowClass" 0x1005 0 2) =>find by index
 a.DoDefaultAction
 
 Thanks again G & Ken for leading me the right way.
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		a little follow up : what is the way to go for triggering an action on tab change : new tab creation, tab destroy, tab name change, lost/gain focus, change selected tab etc?
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		For some events will work "window name changed" trigger.For some should work accessible object trigger.
 
 Or run a macro (function) that repeatedly gets tabs with FirefoxGetTabs and using that info decides what is changed.
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Hi Gintaras
 seems it does not work anymore. Don't know if it's my setup or common to all firefox users (28-29 versions).
 
 No more linkedpanel attribute in Acc dialog selection box.
 
 Confirm?
 
 TY
 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		Does work for finding tabs, but fails to find panel and urls here... 
Function FirefoxGetTabs ,fn.FromAcc(a); _s=fn.Attribute("id"),for(i 0 ap.len) if(ap[i]=_s) break
tweaked
 
Function FirefoxGetTabs ,fn.FromAcc(a); _s=fn.Attribute("id"),out _s
 ,for(i 0 ap.len) if(ap[i]=_s) break
_s is always empty...
	 
	
	
	
		
	Posts: 12,239Threads: 144
 Joined: Dec 2002
 
	
	
		In dialog 'Find accessible object', in 'Other properties', are there some items that begin with "a:"? Test with tab buttons. Also test with some links, should be "a:href". If all "a:" are missing, try to run macro "Firefox portable install registry values for QM functions" from the above link, and restart Firefox.
	 
	
	
	
		
	Posts: 795Threads: 136
 Joined: Feb 2009
 
	
	
		regular firefox not portable mode.
 used to work til version 27 t last..
 |