Worked on editor custom context menu, Added in basic sorting selection.

This commit is contained in:
xevidos 2019-01-19 19:02:11 -05:00
parent 81c3d8d4f9
commit 2e1d7ea559
3 changed files with 117 additions and 56 deletions

View file

@ -17,43 +17,69 @@ checkSession();
?>
<form onsubmit="return false;">
<?php
switch( $_GET['action'] ) {
case 'search':
//////////////////////////////////////////////////////////////////
// Find & Replace
//////////////////////////////////////////////////////////////////
case 'search':
$type = $_GET['type'];
?>
<label><?php i18n("Find:"); ?></label>
<input name="find" autofocus="autofocus" autocomplete="off">
<textarea style="display: none;" name="find" autofocus="autofocus" autocomplete="off"></textarea>
<?php
if( $type == 'replace' ) {
<?php if($type=='replace'){ ?>
?>
<label><?php i18n("Replace:");?></label>
<input name="replace">
<textarea style="display: none;" name="replace"></textarea>
<?php } ?>
<?php
}
?>
<button class="btn-left" onclick="codiad.editor.search('find');return false;"><?php i18n("Find"); ?></button>
<button class="btn-mid" onclick="codiad.editor.toggleMultiLine( this );return false;"><?php i18n("Multi Line"); ?></button>
<?php if($type=='replace'){ ?>
<?php
if( $type == 'replace' ) {
?>
<button class="btn-mid" onclick="codiad.editor.search('replace');return false;"><?php i18n("Replace"); ?></button>
<button class="btn-mid" onclick="codiad.editor.search('replaceAll');return false;"><?php i18n("Replace ALL"); ?></button>
<?php } ?>
<?php
}
?>
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button>
<?php
break;
case 'sort':
?>
<label><?php i18n("Sort:"); ?></label>
<textarea style="" name="sort" autofocus="autofocus" autocomplete="off"></textarea>
<div>
<label><input name="case_sensitive" style="display:inline-block;vertical-align: bottom;" type="checkbox"> Case Sensitive</label>
</div>
<div style="display: none;" >
<label>Delimiter:</label>
<input type="text" name="delimiter" value="">
</div>
<button class="btn-left" onclick="codiad.editor.sort( '<?php echo addcslashes( PHP_EOL, PHP_EOL );?>' );return false;"><?php i18n("Sort"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n("Cancel"); ?></button>
<?php
break;
}
?>
</form>
<script>
$( function() {
<?php if($_GET['action']=='search'){ ?>
<?php
if( $_GET['action'] == 'search' ) {
?>
if( codiad.editor.multi_line ) {
$('textarea[name="find"]').val( codiad.active.getSelectedText() );
@ -63,7 +89,14 @@ $(function(){
$('input[name="find"]').val( codiad.active.getSelectedText() );
$('input[name="find"]').focus();
}
<?php } ?>
});
<?php
} elseif( $_GET['action'] == 'sort' ) {
?>
$('textarea[name="sort"]').val( codiad.active.getSelectedText() );
$('textarea[name="sort"]').focus();
<?php
}
?>
});
</script>

View file

@ -1517,21 +1517,49 @@
openSort: function() {
if ( this.getActive() ) {
if ( this.getActive() && codiad.active.getSelectedText() != "" ) {
codiad.modal.load(400,
'components/editor/dialog.php?action=search&type=' +
type);
codiad.modal.load( 400, 'components/editor/dialog.php?action=sort' );
codiad.modal.hideOverlay();
} else {
codiad.message.error('No Open Files');
codiad.message.error('No text selected');
}
},
sort: function() {
sort: function( eol ) {
let text = $('#modal textarea[name="sort"]').val();
let array = text.split( eol );
array = array.sort( codiad.editor.sort_a );
let sorted = array.join( eol );
console.log( text, eol, array, sorted );
codiad.modal.unload();
codiad.editor.getActive().insert( sorted );
codiad.editor.getActive().focus();
},
sort_a: function( a, b ) {
let pos = 0;
let case_sensitive = $( '#modal input[name="case_sensitive"]' ).prop( 'checked' )
if( ! case_sensitive ) {
a = a.toLowerCase();
b = b.toLowerCase();
}
if( a < b ) {
pos = -1;
} else if( a > b ) {
pos = 1;
}
return pos;
}
};