You are here: PSPad forum > English discussion forum > Re: Sorting limited to certain columns - how?

Re: Sorting limited to certain columns - how?

Goto Page: Previous1 2

#11 Re: Sorting limited to certain columns - how?

Posted by: dirks | Date: 2015-11-26 14:24 | IP: IP Logged

vbr:

Hi, you are welcome, I am glad, it helped.;
I just tried to write a javascript sorting function for this; you may try it on your input files and probably modify it to work as needed, also for possible cornercases.

Oh wow, that gives me a headstart of at least a week grinning smiley Thank you SO MUCH!

vbr:
The text is replaced for the original editor content, you may use copies, if needed.

That would be no problem.

vbr:
just save the following e.g. as a js file in ...\PSPad\script\JScript\my_pspad_javascripts.js

...

After calling Script: Reload script (or on a fresh start of PSPad) this function should be available via script-menu or directly with the shortcuts set in the Init() function (this must not be taken by any other function etc.)

Thank you again - really, having such an example works much (much, much grinning smiley) better for me than digging through info and piecing together what I don't know. smiling smiley

vbr:
Please test it to match all your requirements -especially the content of the original data - the regex should match whole lines, you are interested in.
There must not be any data in the format used for intermediate numbering, i.e. __somenumber__ ; otherwise the sorting might break and the text could be corrupted.

If I understand the JS correctly, then the first replacement is only done on lines that contain '<Meta name="' - this would be safe on the whole file, it is guaranteed for all of these lines that do not (originally) contain anything of the form __somenumber__. But I'm not sure about the next two replacements. I will do tests later.

vbr:
Another limitation of the current PSPad is the scripting support for unicode characters beyond the basic set Win-12... .
If such characters appear in the source, they would be removed with this script.

There are about 40 "Meta" lines, some values contain text which can contain German umlauts (I didn't use these lines here because they may be not privacy-safe). But it looks like the German umlauts are contained in the Win-1254 code page and the Win-1252 code page. Thanks for mentioning it anyway, I was not aware of that.

vbr:
hth,
vbr

It does help, very much, indeed! smiling smiley

I'll do some real tests in a few hours, after getting some other work done. Just wanted to tell you that I have seen it already and had a first look with my brain switched on. smiling smiley

Options: Reply | Quote | Up ^


#12 Re: Sorting limited to certain columns - how?

Posted by: dirks | Date: 2015-11-26 14:37 | IP: IP Logged

vbr:
Hi,
I'd like to add some clearer specification to the code posted above: forum.pspad.com

It changes the whole content of the editor window with the sorted text - it is probably ok for the given sample text which only contains the XML elements, that should be sorted;
however, it is likely, that a whole XML file will be loaded, with other elements, or at least with the toplevel element etc., where sorting would be harmful.

Yes, sorting the whole file would be harmful.

vbr:
It might be appropriate to work with the selected text only.

...

Of course, there can be variants to check for a possibly present selection and handle it conditionally - depending on the requirements.
hth,
vbr

Thank you very much once more, I think this modification "kills" the remaining problem smiling smiley

I owe you one or two! It would have taken me several days (maybe weeks) to get to this point. Thank you very much for all this smiling smiley

I will make some tests later on.

Later,
Dirk

Options: Reply | Quote | Up ^


#13 Re: Sorting limited to certain columns - how?

Posted by: vbr | Date: 2015-11-26 15:27 | IP: IP Logged

Hi,
you are welcome, I am glad it helped.
As for the encoding limitation, if it is German text and you are using a system which supports it within its windows-ansi codepage, such as windows 1252, it should be ok. Or better yet, if you use the version with selection, which will only contain the respective data elements with basic ascii text, it will be generally even safer with regard to encoding problems.
Another harcoded limitation is the number of lines supported for the given numbering base - currently it is 9000 (I forgot to update the comment in the code stating 900).
you can increase the starting counter value, if you need
repl_nr_counter = 1000;
e.g. 10000 ...
(After overflowing to the next order of magnitude, the string sorting will not correspond with the numerical one - e.g. "9" > "10"...)

regards,
vbr

Options: Reply | Quote | Up ^


#14 Re: Sorting limited to certain columns - how?

Posted by: dirks | Date: 2015-11-26 16:13 | IP: IP Logged

I was too curious to let it be until much later...

Bad news: The selector for the "Scripts" drop-down menu (between "Tools" and "HTML") is not shown when PSPad is running in the virtual machine, it is only shown on the host. The VM uses XP... So far I don't know what's the reason and I cannot change too much there sad smiley

Good News: PSPad remembers the values for "inserting text into lines" and sorting, so after the first time it's only 3 or 4 clicks. This is doable several times a day - and the result is exactly what I need - now that the virtual differences that were caused by moved lines are eliminated, I get only real differences (= changes within the line) and these stand out much more. Yay!

I will do some test on the host later on.

And even if I can't make the script work within the VM, I have learned a lot - so, many thanks in any case!

Dirk

Options: Reply | Quote | Up ^


#15 Re: Sorting limited to certain columns - how?

Posted by: vbr | Date: 2015-11-26 20:49 | IP: IP Logged

dirks:
I was too curious to let it be until much later...

Bad news: The selector for the "Scripts" drop-down menu (between "Tools" and "HTML") is not shown when PSPad is running in the virtual machine, it is only shown on the host. The VM uses XP... So far I don't know what's the reason and I cannot change too much there sad smiley

Good News: PSPad remembers the values for "inserting text into lines" and sorting, so after the first time it's only 3 or 4 clicks. This is doable several times a day - and the result is exactly what I need - now that the virtual differences that were caused by moved lines are eliminated, I get only real differences (= changes within the line) and these stand out much more. Yay!

I will do some test on the host later on.

And even if I can't make the script work within the VM, I have learned a lot - so, many thanks in any case!

Dirk

Hi, I don't know about possible limitations with VM mode, but other may have experiences with this.
The general setting to enable scripting in PSPad is
Settings: System integration: [x] Integrated scripting support (WSH).
After successfully activating this option (an possible new start of PSPad?) the menu entry Scripts should appear too.

regards,
vbr

Options: Reply | Quote | Up ^


#16 Re: Sorting limited to certain columns - how?

Posted by: dirks | Date: 2015-11-27 11:54 | IP: IP Logged

Hi,
life intervened suddenly, so I did not do further experiments yesterday, but I did a few minutes ago.

vbr:
Hi, I don't know about possible limitations with VM mode, but other may have experiences with this.
The general setting to enable scripting in PSPad is
Settings: System integration: [x] Integrated scripting support (WSH).
After successfully activating this option (an possible new start of PSPad?) the menu entry Scripts should appear too.

That was it - somehow I didn't find it yesterday... Not even a restart was needed. smiling smiley
I'm just astonished how I managed to make these settings different between the host and the VM. Anyway, the scripts are now available in the VM - Thank you very much once more!

And after removing the bug in the modified script:

Quote:
actEd.selText(outputText);

changed to

Quote:
actEd.selText(outputTxt);

it works like a charm smiling smiley

Problem solved. Even several problems solved! Thank you SO MUCH!

regards,
Dirk

Options: Reply | Quote | Up ^


Goto Page: Previous1 2





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR