mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-21 23:48:08 +00:00
commit
4c786fbd8d
2 changed files with 56 additions and 0 deletions
10
sort-lines/info.json
Normal file
10
sort-lines/info.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "Sort lines",
|
||||
"identifier": "sort-lines-script",
|
||||
"script": "sort-lines.qml",
|
||||
"authors": ["@wiktor2200"],
|
||||
"platforms": ["linux", "macos", "windows"],
|
||||
"version": "0.0.1",
|
||||
"minAppVersion": "17.06.2",
|
||||
"description" : "This script sort selected lines in note text edit. \n\nIt creates an array from selected lines, sorts array and joins it again to output string."
|
||||
}
|
46
sort-lines/sort-lines.qml
Normal file
46
sort-lines/sort-lines.qml
Normal file
|
@ -0,0 +1,46 @@
|
|||
import QtQml 2.0
|
||||
import QOwnNotesTypes 1.0
|
||||
|
||||
/**
|
||||
* This script sort selected lines in note text edit. It creates an array from selected lines,
|
||||
* sorts array and joins it again to output string.
|
||||
*/
|
||||
|
||||
Script {
|
||||
/**
|
||||
* Initializes the custom actions
|
||||
*/
|
||||
function init() {
|
||||
script.registerCustomAction("sortLinesAsc", "Sort lines ascending", "SortAsc", "view-sort-ascending", true, true);
|
||||
script.registerCustomAction("sortLinesDesc", "Sort lines descending", "SortDesc", "view-sort-descending", true, true);
|
||||
}
|
||||
|
||||
function customActionInvoked(identifier) {
|
||||
|
||||
// getting selected text from the note text edit
|
||||
var text = script.noteTextEditSelectedText();
|
||||
|
||||
switch (identifier) {
|
||||
// sort lines ascending
|
||||
case "sortLinesAsc":
|
||||
text = text.split("\n").sort(function(a, b) {
|
||||
return a.localeCompare(b, {
|
||||
'sensitivity': 'base'
|
||||
});
|
||||
}).join("\n");
|
||||
break;
|
||||
|
||||
// sort lines descending
|
||||
case "sortLinesDesc":
|
||||
text = text.split("\n").sort(function(a, b) {
|
||||
return a.localeCompare(b, {
|
||||
'sensitivity': 'base'
|
||||
});
|
||||
}).reverse().join("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// put the result to the current cursor position in the note text edit
|
||||
script.noteTextEditWrite(text);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue