mirror of
https://github.com/xevidos/codiad.git
synced 2025-01-03 11:42:12 +01:00
Worked on editor custom context menu, Added in basic sorting selection.
This commit is contained in:
parent
81c3d8d4f9
commit
2e1d7ea559
3 changed files with 117 additions and 56 deletions
|
@ -16,54 +16,87 @@ checkSession();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<form onsubmit="return false;">
|
<form onsubmit="return false;">
|
||||||
<?php
|
<?php
|
||||||
|
switch( $_GET['action'] ) {
|
||||||
|
|
||||||
switch($_GET['action']){
|
case 'search':
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Find & Replace
|
// Find & Replace
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
case 'search':
|
|
||||||
$type = $_GET['type'];
|
$type = $_GET['type'];
|
||||||
?>
|
?>
|
||||||
<label><?php i18n("Find:"); ?></label>
|
<label><?php i18n("Find:"); ?></label>
|
||||||
<input name="find" autofocus="autofocus" autocomplete="off">
|
<input name="find" autofocus="autofocus" autocomplete="off">
|
||||||
<textarea style="display: none;" name="find" autofocus="autofocus" autocomplete="off"></textarea>
|
<textarea style="display: none;" name="find" autofocus="autofocus" autocomplete="off"></textarea>
|
||||||
|
<?php
|
||||||
|
if( $type == 'replace' ) {
|
||||||
|
|
||||||
<?php if($type=='replace'){ ?>
|
?>
|
||||||
|
<label><?php i18n("Replace:");?></label>
|
||||||
<label><?php i18n("Replace:"); ?></label>
|
|
||||||
<input name="replace">
|
<input name="replace">
|
||||||
<textarea style="display: none;" name="replace"></textarea>
|
<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-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>
|
<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('replace');return false;"><?php i18n("Replace"); ?></button>
|
||||||
<button class="btn-mid" onclick="codiad.editor.search('replaceAll');return false;"><?php i18n("Replace ALL"); ?></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>
|
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button>
|
||||||
<?php
|
<?php
|
||||||
break;
|
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>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$( function() {
|
||||||
<?php if($_GET['action']=='search'){ ?>
|
<?php
|
||||||
|
if( $_GET['action'] == 'search' ) {
|
||||||
|
?>
|
||||||
if( codiad.editor.multi_line ) {
|
if( codiad.editor.multi_line ) {
|
||||||
|
|
||||||
$('textarea[name="find"]').val(codiad.active.getSelectedText());
|
$('textarea[name="find"]').val( codiad.active.getSelectedText() );
|
||||||
$('textarea[name="find"]').focus();
|
$('textarea[name="find"]').focus();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$('input[name="find"]').val(codiad.active.getSelectedText());
|
$('input[name="find"]').val( codiad.active.getSelectedText() );
|
||||||
$('input[name="find"]').focus();
|
$('input[name="find"]').focus();
|
||||||
}
|
}
|
||||||
<?php } ?>
|
<?php
|
||||||
});
|
} elseif( $_GET['action'] == 'sort' ) {
|
||||||
|
|
||||||
|
?>
|
||||||
|
$('textarea[name="sort"]').val( codiad.active.getSelectedText() );
|
||||||
|
$('textarea[name="sort"]').focus();
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1517,21 +1517,49 @@
|
||||||
|
|
||||||
openSort: function() {
|
openSort: function() {
|
||||||
|
|
||||||
if ( this.getActive() ) {
|
if ( this.getActive() && codiad.active.getSelectedText() != "" ) {
|
||||||
|
|
||||||
codiad.modal.load(400,
|
codiad.modal.load( 400, 'components/editor/dialog.php?action=sort' );
|
||||||
'components/editor/dialog.php?action=search&type=' +
|
|
||||||
type);
|
|
||||||
codiad.modal.hideOverlay();
|
codiad.modal.hideOverlay();
|
||||||
} else {
|
} 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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue