adding ability to undo create file/folder action

This commit is contained in:
vineethvk11 2024-03-10 19:48:17 +05:30
parent 03d3ddbfa9
commit a18ec1efdb
5 changed files with 58 additions and 1 deletions

View File

@ -726,6 +726,16 @@ async function UIDesktop(options){
}
},
// -------------------------------------------
// Undo
// -------------------------------------------
{
html: "Undo",
disabled: actions_history.length > 0 ? false : true,
onClick: function(){
undo_last_action();
}
},
// -------------------------------------------
// Upload Here
// -------------------------------------------
{

View File

@ -1917,6 +1917,16 @@ async function UIWindow(options) {
}
},
// -------------------------------------------
// Undo
// -------------------------------------------
{
html: "Undo",
disabled: actions_history.length > 0 ? false : true,
onClick: function(){
undo_last_action();
}
},
// -------------------------------------------
// Upload Here
// -------------------------------------------
{

View File

@ -19,6 +19,7 @@
window.clipboard_op = '';
window.clipboard = [];
window.actions_history = [];
window.window_nav_history = {};
window.window_nav_history_current_position = {};
window.progress_tracker = [];

View File

@ -1434,9 +1434,15 @@ window.create_folder = async(basedir, appendto_element)=>{
overwrite: false,
success: function (data){
const el_created_dir = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]');
if(el_created_dir.length > 0)
if(el_created_dir.length > 0){
activate_item_name_editor(el_created_dir);
// Add action to actions_history for undo ability
actions_history.push({
operation: 'create_folder',
data: el_created_dir
});
}
clearTimeout(progwin_timeout);
// done
@ -1472,6 +1478,12 @@ window.create_file = async(options)=>{
const created_file = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]');
if(created_file.length > 0){
activate_item_name_editor(created_file);
// Add action to actions_history for undo ability
actions_history.push({
operation: 'create_file',
data: created_file
});
}
}
});
@ -3313,3 +3325,19 @@ window.unzipItem = async function(itemPath) {
}, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts)));
})
}
window.undo_last_action = async()=>{
if (actions_history.length > 0) {
const last_action = actions_history.pop();
// Undo the create file action
if (last_action.operation === 'create_file' || last_action.operation === 'create_folder') {
const lastCreatedItem = last_action.data;
undo_create_file_or_folder(lastCreatedItem);
}
}
}
window.undo_create_file_or_folder = async(item)=>{
await window.delete_item(item);
}

View File

@ -1677,6 +1677,14 @@ window.initgui = async function(){
}
return false;
}
//-----------------------------------------------------------------------------
// Undo
// ctrl/command + z, will undo last action
//-----------------------------------------------------------------------------
if((e.ctrlKey || e.metaKey) && e.which === 90){
undo_last_action();
return false;
}
});
$(document).on('click', '.remove-permission-link', async function(e){