Skip to content

Commit e56d01c

Browse files
author
Sergi Mansilla
committed
Merge pull request #938 from ajaxorg/ext/tab_closing
Add close all to right/left to tabs; incl. filename in Save warning
2 parents e705827 + 1b1401f commit e56d01c

File tree

4 files changed

+91
-11
lines changed

4 files changed

+91
-11
lines changed

client/ext/save/save.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = ext.register("ext/save/save", {
3737
if (!self.tabEditors) return;
3838

3939
var _self = this;
40-
40+
4141
tabEditors.addEventListener("close", this.$close = function(e) {
4242
var at = e.page.$at;
4343
if (!at.undo_ptr)
@@ -47,11 +47,17 @@ module.exports = ext.register("ext/save/save", {
4747
|| !at.undo_ptr && node.getAttribute("changed") == 1
4848
&& e.page.$doc.getValue()) {
4949
ext.initExtension(_self);
50-
50+
51+
var pages = tabEditors.getPages(),
52+
currIdx = pages.indexOf(e.page);
53+
tabEditors.set(pages[currIdx].id); //jump to file
54+
5155
winCloseConfirm.page = e.page;
5256
winCloseConfirm.all = -100;
5357
winCloseConfirm.show();
5458

59+
winCloseConfirm.childNodes[0].$ext.innerHTML = "<h3>Save " + node.getAttribute("path") + "?</h3><div>This file has unsaved changes. Your changes will be lost if you don't save them.</div>";
60+
5561
winCloseConfirm.addEventListener("hide", function(){
5662
if (winCloseConfirm.all != -100) {
5763
var f = function(resetUndo){
@@ -78,7 +84,7 @@ module.exports = ext.register("ext/save/save", {
7884

7985
winCloseConfirm.removeEventListener("hide", arguments.callee);
8086
});
81-
87+
8288
btnYesAll.hide();
8389
btnNoAll.hide();
8490

client/ext/save/save.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<a:application xmlns:a="http://ajax.org/2005/aml">
22
<a:window
33
id = "winCloseConfirm"
4-
title = "Would you like to save this file?"
4+
title = "Save this file?"
55
icon = ""
66
center = "true"
77
render = "runtime"
@@ -17,9 +17,8 @@
1717
btnSaveNo.dispatchEvent('click', {htmlEvent: {}});
1818
}
1919
">
20-
<a:vbox padding="10" edge="15 20 25 20">
21-
<h3 class="wheader">Save this file?</h3>
22-
<div>This file has unsaved changes. Would you like to save the file before closing?</div>
20+
<a:vbox id="fileTitle" padding="10" edge="15 20 25 20">
21+
2322
</a:vbox>
2423

2524
<a:hbox edge="6 10 10" pack="end" padding="8">

client/ext/tabbehaviors/tabbehaviors.js

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
7979
},
8080
disabled : "{!!!tabEditors.activepage}"
8181
})),
82+
mnuTabs.appendChild(new apf.item({
83+
caption : "Close Tabs to the Right",
84+
onclick : function() {
85+
_self.closealltotheright();
86+
},
87+
disabled : "{!!!tabEditors.activepage}"
88+
})),
89+
mnuTabs.appendChild(new apf.item({
90+
caption : "Close Tabs to the Left",
91+
onclick : function() {
92+
_self.closealltotheleft();
93+
},
94+
disabled : "{!!!tabEditors.activepage}"
95+
})),
8296
//mnuTabs.appendChild(new apf.divider()),
8397
apf.document.body.appendChild(new apf.menu({
8498
id : "mnuContextTabs",
@@ -104,18 +118,50 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
104118
onclick : function() {
105119
_self.closeallbutme(tabEditors.contextPage);
106120
}
121+
}),
122+
new apf.item({
123+
caption : "Close Tabs to the Right",
124+
onclick : function() {
125+
_self.closealltotheright();
126+
}
127+
}),
128+
new apf.item({
129+
caption : "Close Tabs to the Left",
130+
onclick : function() {
131+
_self.closealltotheleft();
132+
}
107133
})
108134
]
109135
}))
110136
);
111-
137+
112138
this.hotitems.revealtab = [this.nodes[0], mnuContextTabs.childNodes[0]];
113139
this.hotitems.closetab = [this.nodes[1], mnuContextTabs.childNodes[1]];
114140
this.hotitems.closealltabs = [this.nodes[2], mnuContextTabs.childNodes[2]];
115141
this.hotitems.closeallbutme = [this.nodes[3], mnuContextTabs.childNodes[3]];
116-
142+
this.hotitems.closealltotheright = [this.nodes[4], mnuContextTabs.childNodes[4]];
143+
this.hotitems.closealltotheleftt = [this.nodes[5], mnuContextTabs.childNodes[5]];
144+
117145
tabEditors.setAttribute("contextmenu", "mnuContextTabs");
118146

147+
mnuContextTabs.addEventListener("prop.visible", function(e) {
148+
var page = tabEditors.getPage();
149+
var pages = tabEditors.getPages();
150+
151+
// be optimistic, reset menu items to disabled
152+
mnuContextTabs.childNodes[4].setAttribute('disabled', false);
153+
mnuContextTabs.childNodes[5].setAttribute('disabled', false);
154+
155+
// if last tab, remove "close to the right"
156+
if (page.nextSibling.localName !== "page") {
157+
mnuContextTabs.childNodes[4].setAttribute('disabled', true);
158+
}
159+
// if first tab, remove "close to the left"
160+
else if (pages.indexOf(page) == 0) {
161+
mnuContextTabs.childNodes[5].setAttribute('disabled', true);
162+
}
163+
});
164+
119165
tabEditors.addEventListener("close", function(e) {
120166
if (!e || !e.htmlEvent)
121167
return;
@@ -231,8 +277,9 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
231277
for (var i = 0, l = pages.length; i < l; i++) {
232278
page = pages[i];
233279

234-
if (ignore && page == ignore)
280+
if (ignore && (page == ignore || ignore.hasOwnProperty(i))) {
235281
continue;
282+
}
236283

237284
if (page.$doc.getNode().getAttribute("changed") == "1") {
238285
page.noAnim = true; // turn off animation on closing tab
@@ -282,6 +329,34 @@ module.exports = ext.register("ext/tabbehaviors/tabbehaviors", {
282329
callback();
283330
},
284331

332+
closealltotheright : function() {
333+
var page = tabEditors.getPage();
334+
var pages = tabEditors.getPages();
335+
336+
var currIdx = pages.indexOf(page);
337+
var ignore = {};
338+
339+
for (var j = 0; j <= currIdx; j++) {
340+
ignore[j] = page;
341+
}
342+
343+
this.closeallbutme(ignore);
344+
},
345+
346+
closealltotheleft : function() {
347+
var page = tabEditors.getPage();
348+
var pages = tabEditors.getPages();
349+
350+
var currIdx = pages.indexOf(page);
351+
var ignore = {};
352+
353+
for (var j = pages.length - 1; j >= currIdx; j--) {
354+
ignore[j] = page;
355+
}
356+
357+
this.closeallbutme(ignore);
358+
},
359+
285360
nexttab : function(){
286361
var n = this.accessed.length - this.$tabAccessCycle++;
287362
if (n < 0) {

support/apf

Submodule apf updated from 7a926d5 to c4bd753

0 commit comments

Comments
 (0)