Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a single tab aside #75

Open
wants to merge 2 commits into
base: major-3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
"message": "Set current tabs aside",
"description": "Save collection action name. Used in the pane, extension context menu and manifest shortcuts"
},
"setAsideSelected":
{
"message": "Set selected tabs aside",
"description": "Save collection action name, for selected tabs only. Used in the extension context menu"
},
"setMultipleTabsAsideTooltip":
{
"message": "Tip : You can set aside specific tabs by selecting them (by holding CTRL or SHIFT and clicking on the tabs) before clicking on the TabsAside extension",
Expand Down
60 changes: 38 additions & 22 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ var syncEnabled = true; //This variable controls whether to use the chrome sync
var collectionStorage = syncEnabled ? chrome.storage.sync : chrome.storage.local;

//Get the tabs to save, either all the window or the selected tabs only, and pass them through a callback.
function GetTabsToSave (callback)
function GetTabsToSave (callback, ignoreSingleTab = true)
{
chrome.tabs.query({ currentWindow: true }, (windowTabs) =>
chrome.tabs.query({currentWindow: true}, (windowTabs) =>
{
var highlightedTabs = windowTabs.filter(item => item.highlighted);
//If there are more than one selected tab in the window, we set only those aside.
// Otherwise, all the window's tabs get saved.
return callback((highlightedTabs.length > 1 ? highlightedTabs : windowTabs));
//If there are more than one selected tab in the window, or user asked for the active tab only, we set only those aside.
if (highlightedTabs.length > 1 || !ignoreSingleTab)
return callback(highlightedTabs);
else // Otherwise, all the window's tabs get saved.
return callback(windowTabs);
});

}
Expand Down Expand Up @@ -63,25 +65,32 @@ function TogglePane (tab)

function ProcessCommand (command)
{
GetTabsToSave((returnedTabs) =>
switch(command)
{
tabsToSave = returnedTabs;
switch(command)
{
case "set-aside":
case "set-aside":
GetTabsToSave((returnedTabs) =>
{
tabsToSave = returnedTabs;
SaveCollection();
break;
case "toggle-pane":
chrome.tabs.query(
{
active: true,
currentWindow: true
},
(tabs) => TogglePane(tabs[0])
)
break;
}
});
});
break;
case "set-aside-only-selected":
GetTabsToSave((returnedTabs) =>
{
tabsToSave = returnedTabs;
SaveCollection();
},false);
break;
case "toggle-pane":
chrome.tabs.query(
{
active: true,
currentWindow: true
},
(tabs) => TogglePane(tabs[0])
)
break;
}
}

chrome.browserAction.onClicked.addListener((tab) =>
Expand Down Expand Up @@ -288,6 +297,13 @@ chrome.runtime.onInstalled.addListener((updateInfo) =>
title: chrome.i18n.getMessage("setAside")
}
);
chrome.contextMenus.create(
{
id: "set-aside-only-selected",
contexts: ["browser_action"],
title: chrome.i18n.getMessage("setAsideSelected")
}
);
});

//We receive a message from the pane aside-script, which means the tabsToSave are already assigned on message reception.
Expand Down