Code: Select all
// DelLinesContain.js V1.02
// Need RJTED V10.30 stable or greater
var searchtext = Lowercase(InputBox("Suchtext", "Suchtext: ", Document.SelText));
var iDeleted = 0, iLine = 0;
if (searchtext != "") {
Document.BeginUpdate();
while(iLine < Document.LineCount) {
sLineText = Document.Lines[iLine];
if (ScriptUtils.Pos(searchtext, Lowercase(sLineText)) != 0) {
Document.DeleteLine(iLine);
iDeleted++;
} Else {
iLine++;
}
}
Document.EndUpdate();
ShowMessage(IntToStr(iDeleted) + " Zeilen wurden entfernt.");
}
Code: Select all
// DelLinesNotContain.js V1.02
// Need RJTED V10.30 stable or greater
var searchtext = Lowercase(InputBox("Suchtext", "Suchtext: ", Document.SelText));
var iDeleted = 0, iLine = 0;
if (searchtext != "") {
Document.BeginUpdate();
while(iLine < Document.LineCount) {
sLineText = Document.Lines[iLine];
if (ScriptUtils.Pos(searchtext, Lowercase(sLineText)) == 0) {
Document.DeleteLine(iLine);
iDeleted++;
} Else {
iLine++;
}
}
Document.EndUpdate();
ShowMessage(IntToStr(iDeleted) + " Zeilen wurden entfernt.");
}
New version:
- Both contain and not contain in one script
- Configurable texts
- Change InputBox() to own modal form
- Working cancel-button
Code: Select all
// DelLines(Not)Contain.js V1.02
// Need RJ TextEd V10.40 Beta1 or newer
var sSearchtext = "", iDeleted = 0, iLine = 0;
var fInputBox, eInput, btContain, btNotContain, btCancel;
var bContain, sBtCancel, sBtContain, sBtNotContain;
var sInputBoxTitle, sEndMessage;
var sLanguage = "Ger"; // possible Values: Ger, Eng
switch (sLanguage) {
case "Eng": {
sBtCancel = "Cancel";
sBtContain = "Contain";
sBtNotContain = "Not Contain";
sInputBoxTitle = "Delete lines which text... ?";
sEndMessage = " lines were removed.";
}
case "Ger": {
sBtCancel = "Abbruch";
sBtContain = "enthalten";
sBtNotContain = "n. enthalten";
sInputBoxTitle = "Lösche Zeilen welche Text...";
sEndMessage = " Zeilen wurden entfernt.";
}
}
InputBoxForm(sInputBoxTitle, Document.SelText);
if (sSearchtext != "") {
Document.BeginUpdate();
Document.BeginUndo();
while(iLine < Document.LineCount ) {
sLineText = Lowercase(Document.Lines[iLine]);
if (ScriptUtils.Pos(sSearchtext, sLineText) != 0) {
if (bContain) {
if (Document.LineCount == 1) { // LineCount ist immer >= 1 !
iLine++;
}
Document.DeleteLine(iLine);
iDeleted++;
} else {
iLine++;
}
} else {
if (bContain) {
iLine++;
} else {
if (Document.LineCount == 1) { // LineCount ist immer >= 1 !
iLine++;
}
Document.DeleteLine(iLine);
iDeleted++;
}
}
}
Document.EndUndo();
Document.EndUpdate();
ShowMessage(IntToStr(iDeleted) + sEndMessage);
}
function ButtonClick(Sender)
{
fInputBox.ModalResult = mrOk;
if (Sender.Name == "Contain") {
if (eInput.Text != "") {
sSearchtext = Lowercase(eInput.Text);
bContain = true;
}
}
if (Sender.Name == "NotContain") {
if (eInput.Text != "") {
sSearchtext = Lowercase(eInput.Text);
bContain = false;
}
}
}
function InputBoxForm(sTitle, sDefault)
{
fInputBox = new TForm(nil);
fInputBox.Height = 120;
fInputBox.Width = 300;
fInputBox.Caption = sTitle;
fInputBox.BorderStyle = bsDialog;
fInputBox.Position = poScreenCenter;
eInput = new TEdit(fInputBox);
eInput.Parent = fInputBox;
eInput.Left = 10;
eInput.Top = 10;
eInput.Width = 275;
eInput.Text = sDefault;
btContain = new TButton(fInputBox);
btContain.Name = "Contain";
btContain.Parent = fInputBox;
btContain.SetBounds(65, 60, 70, 25);
btContain.Caption = sBtContain;
btContain.Default = true;
btContain.OnClick = &ButtonClick;
btNotContain = new TButton(fInputBox);
btNotContain.Name = "NotContain";
btNotContain.Parent = fInputBox;
btNotContain.SetBounds(140, 60, 70, 25);
btNotContain.Caption = sBtNotContain;
btNotContain.OnClick = &ButtonClick;
btCancel = new TButton(fInputBox);
btCancel.Name = "Cancel";
btCancel.Parent = fInputBox;
btCancel.SetBounds(215, 60, 70, 25);
btCancel.Caption = sBtCancel;
btCancel.OnClick = &ButtonClick;
fInputBox.ShowModal;
fInputBox.Free;
}