Skip to content

Commit dcef517

Browse files
author
Chris White
committed
Implemented deletion of open tabs (#93)
Deletion of closed tabs is not yet implemented.
1 parent efc1155 commit dcef517

File tree

2 files changed

+72
-14
lines changed

2 files changed

+72
-14
lines changed

tabfern/src/view/tree.css

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,20 @@ div.jstree-wholerow-hovered > .tf-action-group {
213213
z-index: 5;
214214
}
215215

216-
/* The buttons are in order Rename, Close, Delete. Add some space to the right
216+
/* Windows:
217+
* The buttons are in order Rename, Close, Delete. Add some space to the right
217218
* of Close to move the "delete" button farther from the others.
218-
* Use padding-right on Close rather than margin-left on Delete so there isn't
219-
* a gap between buttons. If there is such a gap, clicking it hits the node.
219+
* Tabs:
220+
* The buttons are Edit, Delete. Add space to the right of Edit.
221+
*
222+
* Use padding-right on Close/Edit rather than margin-left on Delete so there
223+
* isn't a gap between buttons. If there is such a gap, clicking it hits the
224+
* node.
220225
* TODO replace this with an invisible, narrow action button that just calls
221226
* select_node().
222227
*/
223-
.tf-action-group .fff-picture-delete {
228+
.tf-window > div > .tf-action-group .fff-picture-delete,
229+
.tf-tab > div > .tf-action-group .fff-pencil {
224230
padding-right: 0.5em;
225231
}
226232

tabfern/src/view/tree.js

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,23 +651,57 @@ function actionEditBullet(node_id, node, unused_action_id, unused_action_el)
651651
/// @param evt {Event} (optional) If truthy, the event that triggered the action
652652
/// @param is_internal {Boolean} (optional) If truthy, this is an internal
653653
/// action, so don't prompt for confirmation.
654+
/// ** Not yet used. **
654655
function actionDeleteTab(node_id, node, unused_action_id, unused_action_el,
655-
evt, is_internal)
656+
evt, is_internal_unimplemented)
656657
{
657658
let tab_val = D.tabs.by_node_id(node_id);
658-
if(!tab_val || !tab_val.tab_id) return;
659+
if(!tab_val) return;
660+
if(tab_val.tab_id !== K.NONE) { // Remove open tabs
661+
chrome.tabs.remove(tab_val.tab_id, K.ignore_chrome_error);
662+
} else { // Remove closed tabs
663+
// TODO implement this
664+
}
665+
666+
// TODO? implement if necessary. At the moment, it doesn't appear
667+
// that I need this.
668+
// // We had a click --- hover the node that is now under the mouse.
669+
// // That is the node that was the next-sibling node before.
670+
// // This fixes a bug in which clicking the delete button removes the row,
671+
// // and the row that had been below moves up, but the wholerow hover and the
672+
// // action buttons don't appear for that row.
673+
// //
674+
// // TODO update this when adding full hierarchy (#34).
675+
//
676+
// let next_node = T.treeobj.get_next_dom(node, true);
677+
// if(evt && evt.type === 'click' && next_node) {
678+
// T.treeobj.hover_node(next_node);
679+
// }
659680

660-
// TODO RESUME HERE
661-
// ASQH.NowCCTry((cc)=>{
681+
682+
// If it actually disappears, let tabOnRemoved() handle it.
683+
684+
// let seq = ASQH.NowCCTry((cc)=>{
662685
// chrome.tabs.remove(tab_val.tab_id, cc)
663-
// })
664-
// .then((done_or_err)=>{
686+
// });
687+
//
688+
// seq.try((done, maybe_err)=>{
689+
// if(ASQH.is_asq_try_err(maybe_err)) { return done(); }
690+
// // If the tab-removal failed, just bail.
691+
//
665692
// // Check if the tab still exists. If it had a beforeunload and
666693
// // the user hit "Stay", it will still be there.
667694
// // Even if there is a beforeunload popup, it appears that
668695
// // chrome.runtime.lastError does not show any error. Therefore,
669696
// // we cannot rely on the error state to tell us whether the tab
670697
// // is actually closed.
698+
// chrome.tabs.get(tab_val.tab_id, ASQH.CC(done));
699+
// // We hope this will fail; if so, the tab is gone.
700+
//
701+
// seq.val( (info_or_err) => {
702+
// if(!ASQH.is_asq_try_err(maybe_err)) return;
703+
// // If the tab is still there, don't remove it from the tree
704+
// });
671705
// });
672706

673707
} //actionDeleteTab
@@ -693,6 +727,16 @@ function addTabNodeActions(win_node_id)
693727
callback: actionEditBullet,
694728
dataset: { action: 'editBullet' }
695729
});
730+
731+
T.treeobj.add_action(win_node_id, {
732+
id: 'deleteTab',
733+
class: 'fff-cross ' + K.ACTION_BUTTON_WIN_CLASS,
734+
text: ' ',
735+
grouped: true,
736+
callback: actionDeleteTab,
737+
dataset: { action: 'deleteTab' }
738+
});
739+
696740
} //addTabNodeActions
697741

698742
/// Create a tree node for an open tab.
@@ -1127,17 +1171,25 @@ function treeOnSelect(_evt_unused, evt_data)
11271171
log.info({'Actually, button press':elem, action, evt_data});
11281172

11291173
switch(action) {
1174+
// Windows
11301175
case 'renameWindow':
11311176
actionRenameWindow(node.id, node, null, null); break;
11321177
case 'closeWindow':
11331178
actionCloseWindowAndSave(node.id, node, null, null); break;
11341179
case 'deleteWindow':
1135-
actionDeleteWindow(node.id, node, null, null, evt_data.event);
1136-
// Pass the event so actionDeleteWindow will treat it as
1137-
// a click and refresh the hover state.
1180+
actionDeleteWindow(node.id,node, null,null, evt_data.event);
1181+
// Pass the event so actionDeleteWindow will treat it
1182+
// as a click and refresh the hover state.
11381183
break;
1184+
1185+
// Tabs
11391186
case 'editBullet':
11401187
actionEditBullet(node.id, node, null, null); break;
1188+
case 'deleteTab':
1189+
actionDeleteTab(node.id, node, null, null, evt_data.event);
1190+
// as deleteWindow, above.
1191+
break;
1192+
11411193
default: break; //no-op if unknown
11421194
}
11431195

@@ -1829,7 +1881,7 @@ function tabOnRemoved(tabid, removeinfo)
18291881

18301882
// See if it's a tab we have already marked as removed. If so,
18311883
// whichever code marked it is responsible, and we're off the hook.
1832-
if(!tab_val || !tab_val.tab_id) return;
1884+
if(!tab_val || tab_val.tab_id === K.NONE) return;
18331885

18341886
D.tabs.remove_value(tab_val);
18351887
// So any events that are triggered won't try to look for a

0 commit comments

Comments
 (0)