feature(menu) add second menu, when click not on file

This commit is contained in:
coderaiser 2014-05-15 04:40:29 -04:00
parent da47dfe358
commit 4fcddfdaa9

View file

@ -12,7 +12,9 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
Key = CloudCmd.Key,
Events = DOM.Events,
Menu = this,
MenuShowedName,
MenuContext,
MenuContextFile,
Position = CloudCmd.MousePosition,
Images = DOM.Images;
@ -34,8 +36,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
};
this.show = function(x, y ) {
var fm, options, menuData;
if (!x || !y) {
x = (position || Position).x;
y = (position || Position).y;
@ -43,51 +43,122 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
if (!Loading) {
MenuContext.show(x, y);
MenuContextFile.show(x, y);
} else {
fm = DOM.getFM();
options = {
icon : true,
beforClose : Key.setBind,
beforShow : Key.unsetBind
};
menuData = getMenuData();
MenuContext = new MenuIO(fm, options, menuData);
MenuContext.show(x, y);
Loading = false;
position = null;
loadFileMenuData(function(menuDataFile) {
var is, menu,
NOT_FILE = true,
fm = DOM.getFM(),
menuData = getMenuData(),
options = getOptions(NOT_FILE),
optionsFile = getOptions();
MenuContext = new MenuIO(fm, options, menuData);
MenuContextFile = new MenuIO(fm, optionsFile, menuDataFile);
is = DOM.getCurrentByPosition({
x: x,
y: y
});
if (is)
menu = MenuContextFile;
else
menu = MenuContext;
menu.show(x, y);
Loading = false;
position = null;
});
}
};
function getOptions(notFile) {
var name, func, options;
if (notFile) {
name = 'context';
func = Key.unsetBind;
} else {
name = 'contextFile';
}
options = {
icon : true,
beforeClose : Key.setBind,
beforeShow : Util.bind(beforeShow, func),
beforeClick : beforeClick,
name : name
};
return options;
}
function getMenuData() {
var show = function(name) {
CloudCmd[name].show();
var menu = {
'New' : {
'File' : DOM.promptNewFile,
'Directory' : DOM.promptNewDir,
'From FilePicker' : getFromPicker
},
menuData = {
'View' : Util.bind(show, 'View'),
'Edit' : Util.bind(show, 'Edit'),
'Rename' : function() {
setTimeout(DOM.renameCurrent, 100);
},
'Delete' : DOM.promptDelete,
'(Un)Select All': DOM.toggleAllSelectedFiles,
'Zip file' : DOM.zipFile,
'Unzip file' : DOM.unzipFile,
'Upload To' : {},
'Download' : download,
'New' : {
'File' : DOM.promptNewFile,
'Directory' : DOM.promptNewDir,
'From FilePicker' : getFromPicker
}
};
'(Un)Select All': DOM.toggleAllSelectedFiles
};
return menu;
}
function loadFileMenuData(callback) {
getUploadTo(function(menuUpload) {
menuData['Upload To'] = menuUpload;
var show = function(name) {
CloudCmd[name].show();
},
menuData = getMenuData(),
menu = {
'View' : Util.bind(show, 'View'),
'Edit' : Util.bind(show, 'Edit'),
'Rename' : function() {
setTimeout(DOM.renameCurrent, 100);
},
'Delete' : DOM.promptDelete,
'Zip file' : DOM.zipFile,
'Unzip file' : DOM.unzipFile,
'Upload To' : {},
'Download' : download,
};
menu['Upload To'] = menuUpload;
Util.copyObj(menu, menuData);
Util.exec(callback, menu);
});
}
function beforeShow(callback, x, y, name) {
var notShow = DOM.getCurrentByPosition({
x: x,
y: y
});
return menuData;
if (name === 'contextFile') {
notShow = !notShow;
}
if (!notShow)
MenuShowedName = name;
Util.exec(callback);
return notShow;
}
function beforeClick(name) {
var notCall;
if (MenuShowedName !== name)
notCall = true;
return notCall;
}
function getUploadTo(callback) {