Skip to content
This repository
Browse code

Merge pull request #2077 from ajaxorg/fix_saveas_ctx_menu

[Dijkstra] * fix for saves window context menu
  • Loading branch information...
commit 2f6fee3a4f838c5602b9a262475ecbe8a11912f5 2 parents 10bbd69 + 8c36e34
Jan Jongboom janjongboom authored
24 plugins-client/ext.filesystem/filesystem.js
@@ -183,13 +183,19 @@ module.exports = ext.register("ext/filesystem/filesystem", {
183 183 }
184 184 },
185 185
186   - createFile: function(filename, newFile) {
  186 + createFile: function(filename, newFile, tree) {
187 187 var node;
188   -
  188 +
  189 + if (!tree) {
  190 + tree = apf.document.activeElement;
  191 + if (!tree || tree.localName != "tree")
  192 + tree = trFiles;
  193 + }
  194 +
189 195 if (!newFile) {
190   - node = trFiles.selected;
  196 + node = tree.selected;
191 197 if (!node)
192   - node = trFiles.xmlRoot.selectSingleNode("folder");
  198 + node = tree.xmlRoot.selectSingleNode("folder");
193 199 if (node.getAttribute("type") != "folder" && node.tagName != "folder")
194 200 node = node.parentNode;
195 201 }
@@ -204,7 +210,7 @@ module.exports = ext.register("ext/filesystem/filesystem", {
204 210 var prefix = filename ? filename : "Untitled";
205 211
206 212 if(!newFile)
207   - trFiles.focus();
  213 + tree.focus();
208 214
209 215 var _self = this,
210 216 path = node.getAttribute("path");
@@ -227,13 +233,13 @@ module.exports = ext.register("ext/filesystem/filesystem", {
227 233 function done(){
228 234 if (both == 2) {
229 235 file = apf.xmldb.appendChild(node, file);
230   - trFiles.select(file);
231   - trFiles.startRename();
232   - trFiles.slideOpen(null, node, true);
  236 + tree.select(file);
  237 + tree.startRename();
  238 + tree.slideOpen(null, node, true);
233 239 }
234 240 }
235 241
236   - trFiles.slideOpen(null, node, true, function(){
  242 + tree.slideOpen(null, node, true, function(){
237 243 both++;
238 244 done();
239 245 });
47 plugins-client/ext.save/save.js
@@ -231,6 +231,35 @@ module.exports = ext.register("ext/save/save", {
231 231 delete winSaveAs.page;
232 232 }
233 233 });
  234 +
  235 + trSaveAs.addEventListener("beforerename", this.$beforerename = function(e){
  236 + if (!ide.onLine && !ide.offlineFileSystemSupport) return false;
  237 +
  238 + if (trSaveAs.$model.data.firstChild == trSaveAs.selected)
  239 + return false;
  240 +
  241 + // check for a path with the same name, which is not allowed to rename to:
  242 + var path = e.args[0].getAttribute("path"),
  243 + newpath = path.replace(/^(.*\/)[^\/]+$/, "$1" + e.args[1]).toLowerCase();
  244 +
  245 + var exists, nodes = trSaveAs.getModel().queryNodes(".//node()");
  246 + for (var i = 0, len = nodes.length; i < len; i++) {
  247 + var pathLwr = nodes[i].getAttribute("path").toLowerCase();
  248 + if (nodes[i] != e.args[0] && pathLwr === newpath) {
  249 + exists = true;
  250 + break;
  251 + }
  252 + }
  253 +
  254 + if (exists) {
  255 + util.alert("Error", "Unable to Rename",
  256 + "That name is already taken. Please choose a different name.");
  257 + trSaveAs.getActionTracker().undo();
  258 + return false;
  259 + }
  260 +
  261 + fs.beforeRename(e.args[0], e.args[1]);
  262 + });
234 263 },
235 264
236 265 reverttosaved : function(){
@@ -584,7 +613,25 @@ module.exports = ext.register("ext/save/save", {
584 613 trSaveAs.addEventListener("afterload", expand);
585 614 }
586 615 },
  616 +
  617 + renameFile : function(node) {
  618 + var path = node.getAttribute("path");
  619 + var oldpath = node.getAttribute("oldpath");
  620 + davProject.rename(oldpath, path, true, false, function(data, state, extra) {
  621 + if (state !== apf.SUCCESS) {
  622 + // TODO: revert the rename!!
  623 + return;
  624 + }
587 625
  626 + ide.dispatchEvent("afterupdatefile", {
  627 + path: oldpath,
  628 + newPath: path,
  629 + xmlNode: node,
  630 + isFolder: node.getAttribute("type") === "folder"
  631 + });
  632 + });
  633 + },
  634 +
588 635 enable : function(){
589 636 this.nodes.each(function(item){
590 637 item.enable();
23 plugins-client/ext.save/save.xml
... ... @@ -1,4 +1,9 @@
1 1 <a:application xmlns:a="http://ajax.org/2005/aml">
  2 + <a:script><![CDATA[
  3 + function filesort(value, args, xmlNode) {
  4 + return (xmlNode.tagName == "folder" ? 0 : 1) + value.toLowerCase();
  5 + }
  6 + ]]></a:script>
2 7 <a:window
3 8 id = "winCloseConfirm"
4 9 title = "Save this file?"
@@ -87,10 +92,11 @@
87 92 flex = "1"
88 93 scrollbar = "sbShared 2 2 2"
89 94 model = "{require('ext/filesystem/filesystem').model}"
90   - contextmenu = "mnuCtxTree"
  95 + contextmenu = "mnuCtxSaveTree"
  96 + canrename = "true"
91 97 onafterselect = "chooseSaveAsFolder(this.selected)"
92 98 onafterchoose = "chooseSaveAsFolder(this.selected)">
93   - <a:each match="[folder|file]">
  99 + <a:each match="[project|file|folder]" sort="[@name]" sort-method="filesort">
94 100 <a:insert
95 101 match = "[folder]"
96 102 get = "{location.host &amp;&amp; davProject.readdir([@path])}" />
@@ -105,7 +111,7 @@
105 111 </a:each>
106 112 <a:add type="folder" get="{davProject.mkdir([@path], 'New Folder')}" />
107 113 <a:add type="file" get="{davProject.create([@path], 'New File.txt', '')}" />
108   - <a:rename set="{alert('boe'); davProject.rename([@name], [@path])}"/>
  114 + <a:rename match="[file|folder[not(@root)]]" set="{require('ext/save/save').renameFile(%[.])}" />
109 115 <a:copy match="[file|folder]" set="{davProject.copy([@path], [../@path])}"/>
110 116 <a:move set="{davProject.move([@path], [../@path])}"/>
111 117 <a:remove match="[file|folder]" set="{require('ext/filesystem/filesystem').remove([@path])}"/>
@@ -157,4 +163,15 @@
157 163 </a:hbox>
158 164 </a:vbox>
159 165 </a:window>
  166 + <a:menu id="mnuCtxSaveTree" disabled="{{!stServerConnected.active}}" render="runtime">
  167 + <a:item match="[file|folder[not(@root)]]" onclick="trSaveAs.startRename()">Rename</a:item>
  168 + <a:item match="[file|folder[not(@root)]]" onclick="trSaveAs.remove()">Delete</a:item>
  169 + <a:divider />
  170 + <a:item id="itemCtxTreeNewFile" match="[file|folder|project]" onclick="
  171 + require('ext/filesystem/filesystem').createFile('Untitled', null, trSaveAs);
  172 + ">New File</a:item>
  173 + <a:item match="[file|folder|project]" onclick="
  174 + require('ext/filesystem/filesystem').createFolder('New Folder', trSaveAs);
  175 + ">New Folder</a:item>
  176 + </a:menu>
160 177 </a:application>

0 comments on commit 2f6fee3

Please sign in to comment.
Something went wrong with that request. Please try again.