From 2e1d7ea5596e413a2ae39c4017e87f5632b49269 Mon Sep 17 00:00:00 2001 From: xevidos Date: Sat, 19 Jan 2019 19:02:11 -0500 Subject: [PATCH] Worked on editor custom context menu, Added in basic sorting selection. --- components/editor/dialog.php | 129 ++++++++++++++--------- components/editor/init.js | 42 ++++++-- components/filemanager/context_menu.json | 2 +- 3 files changed, 117 insertions(+), 56 deletions(-) diff --git a/components/editor/dialog.php b/components/editor/dialog.php index d31c198..3544bda 100755 --- a/components/editor/dialog.php +++ b/components/editor/dialog.php @@ -16,54 +16,87 @@ checkSession(); ?>
- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ + +
diff --git a/components/editor/init.js b/components/editor/init.js index 462872d..b7cba5c 100755 --- a/components/editor/init.js +++ b/components/editor/init.js @@ -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; } }; diff --git a/components/filemanager/context_menu.json b/components/filemanager/context_menu.json index 5bcfc93..fcfe032 100755 --- a/components/filemanager/context_menu.json +++ b/components/filemanager/context_menu.json @@ -173,4 +173,4 @@ "applies-to" : "editor-only", "onclick": "codiad.editor.openSort();" } -] +] \ No newline at end of file