mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
adding ability to undo create file/folder action
This commit is contained in:
parent
03d3ddbfa9
commit
a18ec1efdb
@ -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
|
||||
// -------------------------------------------
|
||||
{
|
||||
|
@ -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
|
||||
// -------------------------------------------
|
||||
{
|
||||
|
@ -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 = [];
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user