Merge branch 'development' into 'master'

v.2.9.3.3 Added context menu to editor

See merge request xevidos/codiad!24
This commit is contained in:
Isaac Brown 2019-01-19 19:22:58 -05:00
commit fd3a791ce9
5 changed files with 200 additions and 52 deletions

View file

@ -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> ?>
<input name="find" autofocus="autofocus" autocomplete="off"> <label><?php i18n("Find:"); ?></label>
<textarea style="display: none;" name="find" autofocus="autofocus" autocomplete="off"></textarea> <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> <label><?php i18n("Replace:");?></label>
<input name="replace">
<?php } ?> <textarea style="display: none;" name="replace"></textarea>
<button class="btn-left" onclick="codiad.editor.search('find');return false;"><?php i18n("Find"); ?></button> <?php
<button class="btn-mid" onclick="codiad.editor.toggleMultiLine( this );return false;"><?php i18n("Multi Line"); ?></button> }
<?php if($type=='replace'){ ?> ?>
<button class="btn-mid" onclick="codiad.editor.search('replace');return false;"><?php i18n("Replace"); ?></button> <button class="btn-left" onclick="codiad.editor.search('find');return false;"><?php i18n("Find"); ?></button>
<button class="btn-mid" onclick="codiad.editor.search('replaceAll');return false;"><?php i18n("Replace ALL"); ?></button> <button class="btn-mid" onclick="codiad.editor.toggleMultiLine( this );return false;"><?php i18n("Multi Line"); ?></button>
<?php } ?> <?php
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button> if( $type == 'replace' ) {
<?php
break; ?>
} <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
}
?>
<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> </form>
<script> <script>
$(function(){ $( function() {
<?php if($_GET['action']=='search'){ ?> <?php
if( codiad.editor.multi_line ) { if( $_GET['action'] == 'search' ) {
?>
$('textarea[name="find"]').val(codiad.active.getSelectedText()); if( codiad.editor.multi_line ) {
$('textarea[name="find"]').focus();
} else { $('textarea[name="find"]').val( codiad.active.getSelectedText() );
$('textarea[name="find"]').focus();
$('input[name="find"]').val(codiad.active.getSelectedText()); } else {
$('input[name="find"]').focus();
} $('input[name="find"]').val( codiad.active.getSelectedText() );
<?php } ?> $('input[name="find"]').focus();
}); }
<?php
} elseif( $_GET['action'] == 'sort' ) {
?>
$('textarea[name="sort"]').val( codiad.active.getSelectedText() );
$('textarea[name="sort"]').focus();
<?php
}
?>
});
</script> </script>

View file

@ -288,8 +288,22 @@
.height($(this).height()) .height($(this).height())
.trigger('v-resize'); .trigger('v-resize');
}); });
$("#root-editor-wrapper").live("contextmenu", function( e ) {
// Context Menu
e.preventDefault();
_this = codiad.editor
if( _this.getActive() ) {
let path = codiad.active.getPath();
$(e.target).attr('data-path', path);
codiad.filemanager.contextMenuShow( e, path, 'editor', 'editor');
$(this).addClass('context-menu-active');
}
});
$(window).resize(function(){ $(window).resize(function(){
$('#editor-region') $('#editor-region')
.trigger('h-resize-init') .trigger('h-resize-init')
@ -1498,6 +1512,59 @@
$('textarea[name="replace"]').hide(); $('textarea[name="replace"]').hide();
$('input[name="replace"]').val( $('textarea[name="replace"]').val() ); $('input[name="replace"]').val( $('textarea[name="replace"]').val() );
} }
},
paste: function() {
//this works only in chrome
console.log( "this works only in chrome." );
navigator.clipboard.readText().then(text => {codiad.editor.getActive().insert( text )});
},
openSort: function() {
if ( this.getActive() && codiad.active.getSelectedText() != "" ) {
codiad.modal.load( 400, 'components/editor/dialog.php?action=sort' );
codiad.modal.hideOverlay();
} else {
codiad.message.error('No text selected');
}
},
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;
} }
}; };

View file

@ -130,5 +130,47 @@
"icon": "icon-arrows-ccw", "icon": "icon-arrows-ccw",
"applies-to" : "directory-only", "applies-to" : "directory-only",
"onclick": "codiad.filemanager.rescan($('#context-menu').attr('data-path'));" "onclick": "codiad.filemanager.rescan($('#context-menu').attr('data-path'));"
},
{
"title": "Copy",
"icon": "icon-doc",
"applies-to" : "editor-only",
"onclick": "document.execCommand( 'copy' );"
},
{
"title": "Paste",
"icon": "icon-docs",
"applies-to" : "editor-only",
"onclick": "codiad.editor.paste();"
},
{
"title": "Break",
"icon": null,
"applies-to" : "editor-only",
"onclick": null
},
{
"title": "Find",
"icon": "icon-docs",
"applies-to" : "editor-only",
"onclick": "codiad.editor.openSearch('find');"
},
{
"title": "Replace",
"icon": "icon-docs",
"applies-to" : "editor-only",
"onclick": "codiad.editor.openSearch('replace');"
},
{
"title": "Break",
"icon": null,
"applies-to" : "editor-only",
"onclick": null
},
{
"title": "Sort",
"icon": "icon-docs",
"applies-to" : "editor-only",
"onclick": "codiad.editor.openSort();"
} }
] ]

View file

@ -173,9 +173,15 @@
$('#context-menu .non-root, #context-menu .file-only') $('#context-menu .non-root, #context-menu .file-only')
.hide(); .hide();
break; break;
case 'editor':
$('#context-menu a, #context-menu hr').hide();
$('#context-menu .editor-only').show();
break;
} }
if(codiad.project.isAbsPath($('#file-manager a[data-type="root"]').attr('data-path'))) { if(codiad.project.isAbsPath($('#file-manager a[data-type="root"]').attr('data-path'))) {
$('#context-menu .no-external').hide(); $('#context-menu .no-external').hide();
} else if( type == "editor" ) {
$('#context-menu .no-external').hide();
} else { } else {
$('#context-menu .no-external').show(); $('#context-menu .no-external').show();
} }

View file

@ -12,7 +12,7 @@ class Update {
// CONSTANTS // CONSTANTS
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
CONST VERSION = "v.2.9.3.2"; CONST VERSION = "v.2.9.3.3";
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// PROPERTIES // PROPERTIES