mirror of
https://github.com/xevidos/codiad.git
synced 2024-12-23 06:12:16 +01:00
Changed duplicate to copy to somewhat mach filesystem commands for familiarity, Added search back into filemanager, Updated find and replace to use new modal promise format
This commit is contained in:
parent
57f39ec8bf
commit
e17abc1bb2
6 changed files with 163 additions and 153 deletions
|
@ -1368,7 +1368,8 @@
|
||||||
400,
|
400,
|
||||||
'components/editor/dialog.php?action=search&type=' + type,
|
'components/editor/dialog.php?action=search&type=' + type,
|
||||||
{},
|
{},
|
||||||
function( c ) {
|
)
|
||||||
|
.then( function( c ) {
|
||||||
|
|
||||||
let input = c.find( 'input:first' );
|
let input = c.find( 'input:first' );
|
||||||
let textarea = c.find( 'textarea:first' );
|
let textarea = c.find( 'textarea:first' );
|
||||||
|
|
|
@ -68,6 +68,63 @@ class Filemanager extends Common {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// DUPLICATE (Creates a duplicate of the object - (cut/copy/paste)
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public function copy( $source, $destination, $replace = false ) {
|
||||||
|
|
||||||
|
$response = array(
|
||||||
|
"status" => "none",
|
||||||
|
"message" => null,
|
||||||
|
);
|
||||||
|
|
||||||
|
$source = self::formatPath( $source );
|
||||||
|
$destination = self::formatPath( $destination );
|
||||||
|
$new_destination = $destination;
|
||||||
|
$path_parts = pathinfo( $destination );
|
||||||
|
$i = 1;
|
||||||
|
|
||||||
|
if( ! $replace ) {
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
if( is_dir( $new_destination ) ) {
|
||||||
|
|
||||||
|
$new_destination = rtrim( $destination, "/" ) . " $i/";
|
||||||
|
} elseif( is_file( $new_destination ) ) {
|
||||||
|
|
||||||
|
if( isset( $path_parts["extension"] ) ) {
|
||||||
|
|
||||||
|
$new_destination = str_replace( ".{$path_parts["extension"]}", " {$i}.{$path_parts["extension"]}", $destination );
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$new_destination = $destination . " $i";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
} while( ( is_file( $new_destination ) || is_dir( $new_destination ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( file_exists( $source ) ) {
|
||||||
|
|
||||||
|
if( is_file( $source ) ) {
|
||||||
|
|
||||||
|
copy( $source, $new_destination );
|
||||||
|
$response["status"] = "success";
|
||||||
|
} else {
|
||||||
|
|
||||||
|
self::recursive_copy( $source, $new_destination );
|
||||||
|
$response["status"] = "success";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$response["status"] = "error";
|
||||||
|
$response["message"] = "Invalid Source";
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// CREATE (Creates a new file or directory)
|
// CREATE (Creates a new file or directory)
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
@ -159,60 +216,6 @@ class Filemanager extends Common {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// DUPLICATE (Creates a duplicate of the object - (cut/copy/paste)
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public function duplicate( $source, $destination ) {
|
|
||||||
|
|
||||||
$response = array(
|
|
||||||
"status" => "none",
|
|
||||||
"message" => null,
|
|
||||||
);
|
|
||||||
|
|
||||||
$source = self::formatPath( $source );
|
|
||||||
$destination = self::formatPath( $destination );
|
|
||||||
$new_destination = $destination;
|
|
||||||
$path_parts = pathinfo( $destination );
|
|
||||||
$i = 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
|
|
||||||
if( is_dir( $new_destination ) ) {
|
|
||||||
|
|
||||||
$new_destination = rtrim( $destination, "/" ) . " $i/";
|
|
||||||
} elseif( is_file( $new_destination ) ) {
|
|
||||||
|
|
||||||
if( isset( $path_parts["extension"] ) ) {
|
|
||||||
|
|
||||||
$new_destination = str_replace( ".{$path_parts["extension"]}", " {$i}.{$path_parts["extension"]}", $destination );
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$new_destination = $destination . " $i";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
} while( ( is_file( $new_destination ) || is_dir( $new_destination ) ) );
|
|
||||||
|
|
||||||
if( file_exists( $source ) ) {
|
|
||||||
|
|
||||||
if( is_file( $source ) ) {
|
|
||||||
|
|
||||||
copy( $source, $new_destination );
|
|
||||||
$response["status"] = "success";
|
|
||||||
} else {
|
|
||||||
|
|
||||||
self::recursive_copy( $source, $new_destination );
|
|
||||||
$response["status"] = "success";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$response["status"] = "error";
|
|
||||||
$response["message"] = "Invalid Source";
|
|
||||||
}
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find( $path, $query, $options = array() ) {
|
public function find( $path, $query, $options = array() ) {
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
|
@ -634,7 +637,7 @@ class Filemanager extends Common {
|
||||||
|
|
||||||
if ( is_dir( $source . '/' . $file ) ) {
|
if ( is_dir( $source . '/' . $file ) ) {
|
||||||
|
|
||||||
self::recurse_copy( $source . '/' . $file, $destination . '/' . $file );
|
self::recursive_copy( $source . '/' . $file, $destination . '/' . $file );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
copy( $source . '/' . $file, $destination . '/' . $file );
|
copy( $source . '/' . $file, $destination . '/' . $file );
|
||||||
|
@ -729,6 +732,9 @@ class Filemanager extends Common {
|
||||||
$response["status"] = "success";
|
$response["status"] = "success";
|
||||||
$response["data"] = array();
|
$response["data"] = array();
|
||||||
$response["data"]["index"] = $return;
|
$response["data"]["index"] = $return;
|
||||||
|
$response["data"]["cmd"] = $cmd;
|
||||||
|
$response["data"]["output"] = $output;
|
||||||
|
$response["data"]["output_array"] = $output_arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
|
|
|
@ -81,7 +81,7 @@
|
||||||
"title": "Paste",
|
"title": "Paste",
|
||||||
"icon": "icon-docs",
|
"icon": "icon-docs",
|
||||||
"applies-to" : "directory-only",
|
"applies-to" : "directory-only",
|
||||||
"onclick": "codiad.filemanager.pasteNode($('#context-menu').attr('data-path'));"
|
"onclick": "codiad.filemanager.paste_node($('#context-menu').attr('data-path'));"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Break",
|
"title": "Break",
|
||||||
|
|
|
@ -118,6 +118,19 @@ switch( $action ) {
|
||||||
exit( $response );
|
exit( $response );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case( 'copy' ):
|
||||||
|
|
||||||
|
if( isset( $_POST["replace"] ) ) {
|
||||||
|
|
||||||
|
$replace = $_POST["replace"];
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$replace = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $Filemanager->copy( $path, $destination, $replace );
|
||||||
|
break;
|
||||||
|
|
||||||
case 'create':
|
case 'create':
|
||||||
|
|
||||||
if( isset( $_GET["type"] ) ) {
|
if( isset( $_GET["type"] ) ) {
|
||||||
|
@ -141,11 +154,6 @@ switch( $action ) {
|
||||||
$response = $Filemanager->delete( $path, true, true );
|
$response = $Filemanager->delete( $path, true, true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'duplicate':
|
|
||||||
|
|
||||||
$response = $Filemanager->duplicate( $path, $destination );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'find':
|
case 'find':
|
||||||
|
|
||||||
if( ! isset( $_GET["query"] ) ) {
|
if( ! isset( $_GET["query"] ) ) {
|
||||||
|
|
|
@ -101,12 +101,12 @@ switch( $_GET['action'] ) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Overwrite
|
// replace
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
case 'overwrite':
|
case 'replace':
|
||||||
?>
|
?>
|
||||||
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
|
<input type="hidden" name="path" value="<?php echo($_GET['path']); ?>">
|
||||||
<label><?php i18n("Would you like to overwrite or duplicate the following:"); ?></label>
|
<label><?php i18n("Would you like to replace or duplicate the following:"); ?></label>
|
||||||
<pre>
|
<pre>
|
||||||
<?php
|
<?php
|
||||||
if( ! FileManager::isAbsPath( $_GET['path'] ) ) {
|
if( ! FileManager::isAbsPath( $_GET['path'] ) ) {
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
},
|
},
|
||||||
opened_folders: [],
|
opened_folders: [],
|
||||||
post_max_size: ( 1024*1024 ),
|
post_max_size: ( 1024*1024 ),
|
||||||
preview: null,
|
preview_window: null,
|
||||||
refresh_interval: null,
|
refresh_interval: null,
|
||||||
selected: [],
|
selected: [],
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@
|
||||||
|
|
||||||
if( _this.auto_reload && editor !== null ) {
|
if( _this.auto_reload && editor !== null ) {
|
||||||
|
|
||||||
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
|
codiad.editor.getActive().addEventListener( "change", _this.refresh_preview );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -671,6 +671,9 @@
|
||||||
if( rescan || total_saved == 0 || ! children ) {
|
if( rescan || total_saved == 0 || ! children ) {
|
||||||
|
|
||||||
let data = await _this.get_indexes( path );
|
let data = await _this.get_indexes( path );
|
||||||
|
|
||||||
|
console.log( data );
|
||||||
|
|
||||||
let response = codiad.jsend.parse( data );
|
let response = codiad.jsend.parse( data );
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
|
@ -716,7 +719,7 @@
|
||||||
index_directory_callback: function( entry, container, i, files ) {
|
index_directory_callback: function( entry, container, i, files ) {
|
||||||
|
|
||||||
let _this = codiad.filemanager;
|
let _this = codiad.filemanager;
|
||||||
entry.droppable({
|
entry.children( 'a' ).droppable({
|
||||||
accept: _this.node.accept,
|
accept: _this.node.accept,
|
||||||
drop: _this.node.drop,
|
drop: _this.node.drop,
|
||||||
over: _this.node.over,
|
over: _this.node.over,
|
||||||
|
@ -725,6 +728,13 @@
|
||||||
start: _this.node.start,
|
start: _this.node.start,
|
||||||
stop: _this.node.stop,
|
stop: _this.node.stop,
|
||||||
});
|
});
|
||||||
|
entry.draggable({
|
||||||
|
opacity: 0.85,
|
||||||
|
revert: true,
|
||||||
|
start: _this.node.start,
|
||||||
|
stop: _this.node.stop,
|
||||||
|
zIndex: 100,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
index_file_callback: function( entry, container, i, files ) {
|
index_file_callback: function( entry, container, i, files ) {
|
||||||
|
@ -881,7 +891,7 @@
|
||||||
_this.toggle_directory( $( this ).parent().children( "a" ) );
|
_this.toggle_directory( $( this ).parent().children( "a" ) );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
_this.openFile( $( this ).parent().children( "a" ).attr( 'data-path' ) );
|
_this.open_file( $( this ).parent().children( "a" ).attr( 'data-path' ) );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on( "contextmenu", 'a', function( e ) {
|
.on( "contextmenu", 'a', function( e ) {
|
||||||
|
@ -1084,26 +1094,33 @@
|
||||||
paste_node: function( path ) {
|
paste_node: function( path ) {
|
||||||
|
|
||||||
let _this = this;
|
let _this = this;
|
||||||
let overwrite = false;
|
let replace = false;
|
||||||
|
let clipboard = this.clipboard;
|
||||||
|
console.log( path, clipboard )
|
||||||
|
|
||||||
if( this.clipboard == '' ) {
|
if( clipboard == '' ) {
|
||||||
|
|
||||||
codiad.message.error( i18n( 'Nothing in Your Clipboard' ) );
|
codiad.message.error( i18n( 'Nothing in Your Clipboard' ) );
|
||||||
} else if( path == this.clipboard ) {
|
} else if( path == clipboard ) {
|
||||||
|
|
||||||
codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) );
|
codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let short_name = _this.get_short_name( _this.clipboard );
|
let short_name = _this.get_short_name( clipboard );
|
||||||
let new_path = path + '/' + short_name
|
let new_path = path + '/' + short_name
|
||||||
|
let existing_node = $( '#file-manager a[data-path="' + new_path + '"]' );
|
||||||
|
|
||||||
if( $( '#file-manager a[data-path="' + new_path + '"]' ).length ) {
|
console.log( existing_node );
|
||||||
|
|
||||||
// Confirm overwrite?
|
if( existing_node.length ) {
|
||||||
|
|
||||||
|
// Confirm replace?
|
||||||
codiad.modal.load( 400, this.dialog, {
|
codiad.modal.load( 400, this.dialog, {
|
||||||
action: 'overwrite',
|
action: 'replace',
|
||||||
path: new_path
|
path: new_path
|
||||||
});
|
})
|
||||||
|
.then( function( container ) {
|
||||||
|
|
||||||
$( '#modal-content form' )
|
$( '#modal-content form' )
|
||||||
.on( 'submit', function( e ) {
|
.on( 'submit', function( e ) {
|
||||||
|
|
||||||
|
@ -1112,7 +1129,7 @@
|
||||||
|
|
||||||
if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) {
|
if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) {
|
||||||
|
|
||||||
overwrite = true;
|
replace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -1120,9 +1137,9 @@
|
||||||
url: _this.controller + '?action=copy',
|
url: _this.controller + '?action=copy',
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
path: path,
|
path: clipboard,
|
||||||
destination: new_path,
|
destination: new_path,
|
||||||
overwrite: overwrite,
|
replace: replace,
|
||||||
},
|
},
|
||||||
success: async function( data ) {
|
success: async function( data ) {
|
||||||
|
|
||||||
|
@ -1154,6 +1171,7 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -1161,9 +1179,9 @@
|
||||||
url: _this.controller + '?action=copy',
|
url: _this.controller + '?action=copy',
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
path: path,
|
path: clipboard,
|
||||||
destination: new_path,
|
destination: new_path,
|
||||||
overwrite: overwrite,
|
replace: replace,
|
||||||
},
|
},
|
||||||
success: async function( data ) {
|
success: async function( data ) {
|
||||||
|
|
||||||
|
@ -1216,28 +1234,28 @@
|
||||||
}
|
}
|
||||||
_this.refresh_interval = setTimeout( function() {
|
_this.refresh_interval = setTimeout( function() {
|
||||||
|
|
||||||
if( _this.preview == null ) {
|
if( _this.preview_window == null ) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if( ( typeof _this.preview.location.reload ) == "undefined" ) {
|
if( ( typeof _this.preview_window.location.reload ) == "undefined" ) {
|
||||||
|
|
||||||
_this.preview = null;
|
_this.preview_window = null;
|
||||||
codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
|
codiad.editor.getActive().removeEventListener( "change", _this.refresh_preview );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_this.preview.location.reload( true );
|
_this.preview_window.location.reload( true );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
|
|
||||||
console.log( e );
|
console.log( e );
|
||||||
codiad.message.error( 'Please close your previously opened preview window.' );
|
codiad.message.error( 'Please close your previously opened preview window.' );
|
||||||
_this.preview = null;
|
_this.preview_window = null;
|
||||||
codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
|
codiad.editor.getActive().removeEventListener( "change", _this.refresh_preview );
|
||||||
}
|
}
|
||||||
}, 500 );
|
}, 1000 );
|
||||||
},
|
},
|
||||||
|
|
||||||
rename: function( path, new_path ) {
|
rename: function( path, new_path ) {
|
||||||
|
@ -1326,7 +1344,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
preview_path: function( path ) {
|
preview: function( path ) {
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -1406,20 +1424,8 @@
|
||||||
path: path
|
path: path
|
||||||
});
|
});
|
||||||
codiad.modal.hideOverlay();
|
codiad.modal.hideOverlay();
|
||||||
let last_searched = JSON.parse( await codiad.settings.get_option( "lastSearched" ) );
|
|
||||||
if( last_searched ) {
|
|
||||||
|
|
||||||
$( '#modal-content form input[name="search_string"]' ).val( lastSearched.searchText );
|
|
||||||
$( '#modal-content form input[name="search_file_type"]' ).val( lastSearched.fileExtension );
|
|
||||||
$( '#modal-content form select[name="search_type"]' ).val( lastSearched.searchType );
|
|
||||||
if( lastSearched.searchResults != '' ) {
|
|
||||||
$( '#filemanager-search-results' ).slideDown().html( lastSearched.searchResults );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$( '#modal-content form' )
|
$( '#modal-content form' )
|
||||||
.on( 'submit', function( e ) {
|
.on( 'submit', function( e ) {
|
||||||
|
|
||||||
$( '#filemanager-search-processing' ).show();
|
$( '#filemanager-search-processing' ).show();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
searchString = $( '#modal-content form input[name="search_string"]' ).val();
|
searchString = $( '#modal-content form input[name="search_string"]' ).val();
|
||||||
|
@ -1463,17 +1469,6 @@
|
||||||
$( '#filemanager-search-results' )
|
$( '#filemanager-search-results' )
|
||||||
.slideUp();
|
.slideUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
codiad.settings.update_option(
|
|
||||||
"lastSearched",
|
|
||||||
JSON.stringify({
|
|
||||||
searchText: searchText,
|
|
||||||
searchType: searchType,
|
|
||||||
fileExtension: fileExtensions,
|
|
||||||
searchResults: searchResults
|
|
||||||
})
|
|
||||||
)
|
|
||||||
_this.saveSearchResults( searchString, searchType, fileExtensions, results );
|
|
||||||
$( '#filemanager-search-processing' )
|
$( '#filemanager-search-processing' )
|
||||||
.hide();
|
.hide();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue