mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-06-16 14:29:46 +00:00
#164: implement rw current tab prop ; improve closing ; fix various glitches
This commit is contained in:
parent
e8d21a0e8c
commit
4881c0af02
|
@ -274,7 +274,7 @@
|
||||||
-->
|
-->
|
||||||
</class>
|
</class>
|
||||||
<class name="browser window" code="BWin" description="A %MAC_APP_NAME% browser window." inherits="window" plural="browser windows">
|
<class name="browser window" code="BWin" description="A %MAC_APP_NAME% browser window." inherits="window" plural="browser windows">
|
||||||
<contents name="current tab" code="pCTb" type="tab" access="r" description="The currently selected tab in the browser window.">
|
<contents name="current tab" code="pCTb" type="tab" access="rw" description="The currently selected tab in the browser window.">
|
||||||
<cocoa key="selectedScriptTab"/>
|
<cocoa key="selectedScriptTab"/>
|
||||||
</contents>
|
</contents>
|
||||||
<cocoa class="GeckoWindow"/>
|
<cocoa class="GeckoWindow"/>
|
||||||
|
|
|
@ -907,8 +907,9 @@ BrowserGlue.prototype = {
|
||||||
createWindowAtIndex : function(index) {
|
createWindowAtIndex : function(index) {
|
||||||
var handler = Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler);
|
var handler = Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler);
|
||||||
var defaultArgs = handler.defaultArgs;
|
var defaultArgs = handler.defaultArgs;
|
||||||
var topWindow = Services.wm.getMostRecentWindow('');
|
// Use the hidden window to open in case the script closes all the things.
|
||||||
topWindow.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no,non-remote", defaultArgs);
|
Services.appShell.hiddenDOMWindow.openDialog("chrome://browser/content/",
|
||||||
|
"_blank", "chrome,all,dialog=no,non-remote", defaultArgs);
|
||||||
},
|
},
|
||||||
getWindows : function() {
|
getWindows : function() {
|
||||||
var array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
|
var array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
|
||||||
|
@ -946,6 +947,20 @@ BrowserGlue.prototype = {
|
||||||
var tab = win.gBrowser.tabs[index];
|
var tab = win.gBrowser.tabs[index];
|
||||||
win.gBrowser.removeTab(tab);
|
win.gBrowser.removeTab(tab);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
setCurrentTabInWindow : function(index, window_index) {
|
||||||
|
let win = this.getWindow(window_index);
|
||||||
|
if (win != null) {
|
||||||
|
win.gBrowser.selectedTab = win.gBrowser.tabs[index];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
closeWindowAtIndex : function(index) {
|
||||||
|
let win = this.getWindow(index);
|
||||||
|
if (win != null) {
|
||||||
|
// Use the soop3r s3kr1t don't ask when closing flag.
|
||||||
|
win.skipNextCanClose = true;
|
||||||
|
win.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,13 @@ interface nsIApplescriptService : nsISupports
|
||||||
* @param index The tab's index.
|
* @param index The tab's index.
|
||||||
*/
|
*/
|
||||||
void createWindowAtIndex(in unsigned long index);
|
void createWindowAtIndex(in unsigned long index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a window (without verification).
|
||||||
|
*
|
||||||
|
* @param index The tab's index.
|
||||||
|
*/
|
||||||
|
void closeWindowAtIndex(in unsigned long index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of nsIDOMWindows representing the tabs in
|
* Returns an array of nsIDOMWindows representing the tabs in
|
||||||
|
@ -89,6 +96,15 @@ interface nsIApplescriptService : nsISupports
|
||||||
*/
|
*/
|
||||||
nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
|
nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current tab in
|
||||||
|
* the window to the given index.
|
||||||
|
*
|
||||||
|
* @param index The window's index.
|
||||||
|
* @param window_index The window's index.
|
||||||
|
*/
|
||||||
|
void setCurrentTabInWindow(in unsigned long index, in unsigned long window_index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a tab in the window at the given index.
|
* Creates a tab in the window at the given index.
|
||||||
*
|
*
|
||||||
|
@ -121,6 +137,13 @@ interface nsIApplescriptWindowCallback : nsISupports
|
||||||
* @param index The tab's index.
|
* @param index The tab's index.
|
||||||
*/
|
*/
|
||||||
void createWindowAtIndex(in unsigned long index);
|
void createWindowAtIndex(in unsigned long index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a window (without verification).
|
||||||
|
*
|
||||||
|
* @param index The tab's index.
|
||||||
|
*/
|
||||||
|
void closeWindowAtIndex(in unsigned long index);
|
||||||
};
|
};
|
||||||
|
|
||||||
[scriptable, uuid(a433c084-ffc7-4264-90fa-82c1e0100b46)]
|
[scriptable, uuid(a433c084-ffc7-4264-90fa-82c1e0100b46)]
|
||||||
|
@ -143,6 +166,15 @@ interface nsIApplescriptTabCallback : nsISupports
|
||||||
*/
|
*/
|
||||||
nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
|
nsIDOMWindow getCurrentTabInWindow(in unsigned long index, out unsigned long tab_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current tab in
|
||||||
|
* the window to the given index.
|
||||||
|
*
|
||||||
|
* @param index The tab's index.
|
||||||
|
* @param window_index The window's index.
|
||||||
|
*/
|
||||||
|
void setCurrentTabInWindow(in unsigned long index, in unsigned long window_index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a tab in the window at the given index.
|
* Creates a tab in the window at the given index.
|
||||||
*
|
*
|
||||||
|
|
|
@ -150,6 +150,7 @@ typedef unsigned int NSUInteger;
|
||||||
- (NSArray*)scriptTabs;
|
- (NSArray*)scriptTabs;
|
||||||
- (void)insertInScriptTabs:(id)value;
|
- (void)insertInScriptTabs:(id)value;
|
||||||
- (GeckoTab*)selectedScriptTab;
|
- (GeckoTab*)selectedScriptTab;
|
||||||
|
- (void)setSelectedScriptTab:(id)value;
|
||||||
|
|
||||||
// Helper Methods
|
// Helper Methods
|
||||||
- (void)_setIndex:(NSUInteger)index;
|
- (void)_setIndex:(NSUInteger)index;
|
||||||
|
@ -183,6 +184,7 @@ typedef unsigned int NSUInteger;
|
||||||
// Helper Methods
|
// Helper Methods
|
||||||
- (void)_setWindow:(GeckoWindow*)window;
|
- (void)_setWindow:(GeckoWindow*)window;
|
||||||
- (void)_setIndex:(NSUInteger)index;
|
- (void)_setIndex:(NSUInteger)index;
|
||||||
|
- (NSUInteger)_index;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -482,6 +484,16 @@ static GeckoScriptingRoot *sharedScriptingRoot = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)handleCloseScriptCommand:(NSCloseCommand*)command {
|
- (id)handleCloseScriptCommand:(NSCloseCommand*)command {
|
||||||
|
NS_WARNING("AppleScript: window handleCloseScriptCommand");
|
||||||
|
// Try to close with the scripted handler, since it's faster. If not,
|
||||||
|
// fallback on Cocoa.
|
||||||
|
nsCOMPtr<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
|
||||||
|
if (applescriptService) {
|
||||||
|
if (NS_SUCCEEDED(applescriptService->CloseWindowAtIndex(mIndex))) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_WARNING("window close from Gecko failed; trying from NSWindow");
|
||||||
NSWindow *window = [self window];
|
NSWindow *window = [self window];
|
||||||
if (window) {
|
if (window) {
|
||||||
return [window handleCloseScriptCommand:command];
|
return [window handleCloseScriptCommand:command];
|
||||||
|
@ -536,16 +548,28 @@ static GeckoScriptingRoot *sharedScriptingRoot = nil;
|
||||||
if (!applescriptService) {
|
if (!applescriptService) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMWindow> contentWindow;
|
nsCOMPtr<nsIDOMWindow> contentWindow;
|
||||||
uint32_t tabIndex = 0;
|
uint32_t tabIndex = 0;
|
||||||
if (NS_FAILED(applescriptService->GetCurrentTabInWindow(mIndex, &tabIndex, getter_AddRefs(contentWindow))) || !contentWindow) {
|
if (NS_FAILED(applescriptService->GetCurrentTabInWindow(mIndex, &tabIndex, getter_AddRefs(contentWindow))) || !contentWindow) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [GeckoTab tabWithIndex:tabIndex andContentWindow:contentWindow andWindow:self];
|
return [GeckoTab tabWithIndex:tabIndex andContentWindow:contentWindow andWindow:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setSelectedScriptTab:(id)value {
|
||||||
|
NS_WARNING("AppleScript: window setSelectedScriptTab");
|
||||||
|
if (![(NSObject*)value isKindOfClass:[GeckoTab class]]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nsCOMPtr<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
|
||||||
|
if (!applescriptService) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(void)applescriptService->SetCurrentTabInWindow([(GeckoTab*)value _index], mIndex);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)insertObject:(NSObject*)object inScriptTabsAtIndex:(NSUInteger)index {
|
- (void)insertObject:(NSObject*)object inScriptTabsAtIndex:(NSUInteger)index {
|
||||||
NS_WARNING("AppleScript: window insertObject:inScriptTabsAtIndex");
|
NS_WARNING("AppleScript: window insertObject:inScriptTabsAtIndex");
|
||||||
if (![object isKindOfClass:[GeckoTab class]]) {
|
if (![object isKindOfClass:[GeckoTab class]]) {
|
||||||
|
@ -627,6 +651,10 @@ static GeckoScriptingRoot *sharedScriptingRoot = nil;
|
||||||
mIndex = index;
|
mIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)_index {
|
||||||
|
return mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSScriptObjectSpecifier*)objectSpecifier
|
- (NSScriptObjectSpecifier*)objectSpecifier
|
||||||
{
|
{
|
||||||
if (!mWindow) {
|
if (!mWindow) {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Scott Greenlay <scott@greenlay.net>
|
* Scott Greenlay <scott@greenlay.net>
|
||||||
|
* Cameron Kaiser <classilla@floodgap.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
@ -68,12 +69,22 @@ nsApplescriptService::GetWindows(nsIArray **windows)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsApplescriptService::CreateWindowAtIndex(uint32_t index)
|
nsApplescriptService::CreateWindowAtIndex(uint32_t index)
|
||||||
{
|
{
|
||||||
|
NS_ASSERTION(index == 0, "Not implemented for window indices other than zero");
|
||||||
if (windowCallback) {
|
if (windowCallback) {
|
||||||
return windowCallback->CreateWindowAtIndex(index);
|
return windowCallback->CreateWindowAtIndex(index);
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsApplescriptService::CloseWindowAtIndex(uint32_t index)
|
||||||
|
{
|
||||||
|
if (windowCallback) {
|
||||||
|
return windowCallback->CloseWindowAtIndex(index);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsApplescriptService::GetTabsInWindow(uint32_t index, nsIArray **tabs) {
|
nsApplescriptService::GetTabsInWindow(uint32_t index, nsIArray **tabs) {
|
||||||
if (tabCallback) {
|
if (tabCallback) {
|
||||||
|
@ -95,6 +106,14 @@ nsApplescriptService::GetCurrentTabInWindow(uint32_t index, uint32_t *tab_index,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsApplescriptService::SetCurrentTabInWindow(uint32_t index, uint32_t window_index) {
|
||||||
|
if (tabCallback) {
|
||||||
|
return tabCallback->SetCurrentTabInWindow(index, window_index);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsApplescriptService::CreateTabAtIndexInWindow(uint32_t index, uint32_t window_index) {
|
nsApplescriptService::CreateTabAtIndexInWindow(uint32_t index, uint32_t window_index) {
|
||||||
if (tabCallback) {
|
if (tabCallback) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user