NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: Lawrie Pardy on 2007-09-02 01:04 pm

Title: Inline editing of user tools
Post by: Lawrie Pardy on 2007-09-02 01:04 pm
G'day all,
it occurs to me that it might be helpful if there was a mechanism that allowed you to spawn an instance of, say, notepad - or even your editor of choice - from the edit usertools dialogue.

I'm not sure exactly how this would work but currently if you go to edit a tool invocation you get a dialogue that allows you to edit the Name and the Command.

Perhaps if the Command field were to be split into Program (E.G. php or wscript to name 2 common ones), Command (actual script file) and Parameters (passed to the command) fields then the command field might be passed to the editor to enable you to edit the actual script from within NWC2.

Would this be truly useful or is it more likely to be unnecessary "bells and whistles"?

Thoughts anyone?
Title: Re: Inline editing of user tools
Post by: NoteWorthy Online on 2007-09-02 04:45 pm
We will think about this.

For now, if you setup a text editor file associate with your scripts, you can easily engage it. Simply click Browse in the edit box, and then right click on any of the scripts.
Title: Re: Inline editing of user tools
Post by: Rick G. on 2007-09-02 04:57 pm
To expand on this, use: Tools->User Tools...->Edit...->Browse... to get an Open Dialog of all you scripts. Right Click on the one you want to edit and select: Edit

Or just create a ShortCut to you scripts folder.
Title: Re: Inline editing of user tools
Post by: Lawrie Pardy on 2007-09-02 10:26 pm
G'day Noteworthyonline,
true, I forgot about going into the browse box and invoking an editor from there.  That's probably easy enough for the needs of those with the skills to develop scripts anyway...

G'day Rick,
to add to what you suggested (Right click|Edit) I usually add a shortcut to Notepad in my "Send To" folder (C:\Documents and Settings\user name\SendTo) - this is a hidden folder so in Windows Explorer you need to go to |Tools|Folder Options|View (tab)|"Show hidden files and folders" radio button and OK

Once in the "Send To" folder, right click anywhere, "New" from the context menu, "Shortcut" from the submenu and follow the prompts.

Useful for lots of stuff.
Title: Re: Inline editing of user tools
Post by: Rick G. on 2007-09-06 03:11 pm
Here's a VBScript to do something close. It finds the script/batch file from the last User Tool run and launches whatever Edit action associated with that file. Copy the code to NotePad and save it as EditLUT.vbs
Code: [Select · Download]
Option Explicit ' Edit Last NWC2 User Tool Run
' Standalone script, not a User Tool
' by Rick G. tested on Win98, NWC2 Beta 2.19
Const exts = ".php|.vbs|.js|.py|.cmd|.bat"
Const NWC2RK = "HKCU\Software\NoteWorthy Software\NoteWorthy Composer 2\"
Dim wso: Set wso = CreateObject("WScript.Shell")
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim sho: Set sho = CreateObject("Shell.Application")
Dim ext, delimiter, lut, s

lut = wso.RegRead(NWC2RK & "Options\LastToolRun")
s = fso.BuildPath(NWC2Folder("Config"), "nwc2UserTools.ini") ' filename
s = fso.OpenTextFile(s).ReadAll ' file contents
s = Filter(Split(s, vbCr), vbLf & lut & "=")(0) ' pertinent line from file
s = Split(s, "=")(1) ' &Command:
For Each ext In Split(exts & "|", "|")
  If InStr(1, s, ext, 1) Then Exit For
Next
If ext = "" Then WScript.Quit ' no match

If Asc(s) = 39 Then s = Mid(s, 2, Len(s) - 2) ' strip single quotes
delimiter = Mid(s & " ", InStr(1, s, ext, 1) + Len(ext), 1) ' space|quote
s = Filter(Split(s, delimiter), ext, vbTrue, 1)(0) ' relative path

wso.CurrentDirectory = NWC2Folder("root")
s = fso.GetAbsolutePathName(s)
sho.Namespace(Left(s, 3)).ParseName(Mid(s, 4)).InvokeVerb("&Edit")

Function NWC2Folder(sKey)
  Select Case sKey
    Case "Songs": NWC2Folder = wso.SpecialFolders("MyDocuments")
    Case "InstrumentTrees": NWC2Folder = "itrees"
    Case "AutoSave", "Config", "Templates": NWC2Folder = sKey
    Case "PageCopy", "root"
    Case Else: Err.Raise 17, "NWC2Folder", sKey ' bad sKey
  End Select
  On Error Resume Next
  NWC2Folder = wso.RegRead(NWC2RK & sKey)
  If Err = 0 Or sKey = "Songs" Then Exit Function
  NWC2Folder = fso.BuildPath(fso.GetFile( _
    wso.RegRead("HKCR\nwcomposer\shell\nwc2\command\") _
    ).ParentFolder, NWC2Folder)
End Function

The program gets the last User Tool from the registry and scans nwc2UserTools.ini to find the corresponding line. The line is parsed to find the script filename's path which is usually relative to where nwc2.exe is. This name is fully qualified and passed to Windows' ActiveX "Shell.Application" object with instructions to invoke the "&Edit" verb on it.

A function: NWC2Folder is provided which will return the many folders used by NWC2, whether set by the user or left at their default.

This script cannot be set up as a User Tool. If it is, it will just invoke the editor on itself.  :(
Title: Re: Inline editing of user tools
Post by: Lawrie Pardy on 2007-09-06 10:16 pm
G'day Rick,
darn, couldn't get it to work :(  Then I realised I didn't have an edit verb for php extensions - added one and all is well :)

The fact that this opens the last tool used is a useful thing I reckon - that's the one most likely to need editing if one is working on developing a user tool.

Still, it would be nice to be able to execute it from within NWC2 itself...  Perhaps this is an appropriate time to request some user definable buttons in the toolbars - ones that can invoke external proggy's like this one as well as user tools.  You know, have "Global_Mod" etc. - whatever we each use most commonly - just click the button!

Hmm, on second thought, in the interest of keeping the code for NWC small and efficient, this button idea should only be considered if it would have a minimal impact - there is already toolbar code in NWC so if the ability to set customisable buttons can be a very small amount of code then fine, otherwise I'm happy to use the <Alt-F8> dialogue.
Title: Re: Inline editing of user tools
Post by: Rick G. on 2007-09-06 10:49 pm
The fact that this opens the last tool used is a useful thing I reckon - that's the one most likely to need editing if one is working on developing a user tool.
That was my thought. I also have some tools that are easier to configure by editing the source than by changing Command:
Still, it would be nice to be able to execute it from within NWC2 itself...  
It could be a user tool if NWC2 would wait until the Tool ran before updating the registry.

Some irony here. A registry key called "LastToolRun" updates before the current tool can read it, but "FileHistory" doesn't update until NWC2 is closed. Ideally, "FileHistory\Title1" would be the Active Window.

I use a Recorder macro when I need to run the same Tool on many different sections. An integral HotKey (like F11) would be much better.
Title: Re: Inline editing of user tools
Post by: Andrew Purdam on 2007-09-06 11:32 pm
When I was working on scripts a lot, I'd just have the scripts folder open.
Often I'd have the script loaded in notepad or whatever, and just keep saving it and rerunning.
(It's nice that Windows lets us run more than one program at a time...)
Not too onerous for someone who's been programming for 25 years (I started off on TI58 programmable calculators).
That's the sort of nerd I am.
Title: Re: Inline editing of user tools
Post by: Rick G. on 2007-09-06 11:59 pm
I started off on TI58 programmable calculators.
I started in 1970 with a dedicated lea$e line connecting a mainframe to one of <these> (http://bytecollector.com/images/asr-33_vcf_02.jpg). Better than punch cards :)
Title: Re: Inline editing of user tools
Post by: Lawrie Pardy on 2007-09-07 12:09 am
G'day Andrew,

When I was working on scripts a lot, I'd just have the scripts folder open.
Often I'd have the script loaded in notepad or whatever, and just keep saving it and rerunning.
<snip>

I used to do something similar donkey's years ago when I was developing in DataFlex, under DOS.  Used to run "Sidekick" and use its' editor in TSR mode.  Hotkey in and out of Sidekick and run the updated code...
Title: Re: Inline editing of user tools
Post by: Keith Mckenna on 2007-09-07 07:59 pm
Rick;
I haven't seen one of those beasts for 30 years. Was all we had connected to pdp 8's when I started at digital equipment corporation in the mid 70's. For our connections to the time sharing pdp10 we had it's big brother, the ASR35.

Keith
Title: Re: Inline editing of user tools
Post by: Rob den Heijer on 2007-09-07 10:31 pm
I started out on Data General Nova-3. Never touched a pdp-11 in my life, even though DG and Digital were very close relatives.
Later, all this MS-Dos stuff (I tried the Commodore 128, but used it for games only...) came along, and still, whenever I work on an XP machine, I have at least one cmd-window open! Can't do without it! I use TSE as my favourite editor.
The way I work is very much like the description Andrew gave.
Title: Re: Inline editing of user tools
Post by: John Ford on 2007-09-09 01:19 am
Hey, Rob -

I presume by TSE, you mean "The Semware Editor".  I've used it since it was QEdit (TSR under MS-DOS) and have upgraded ever since.  Best text editor I ever used and it's macro and repeat ability makes it a breeze to edit anything that has some sort of pattern to it.
Title: Re: Inline editing of user tools
Post by: Warren Porter on 2007-09-10 11:57 am
I presume by TSE, you mean "The Semware Editor".  I've used it since it was QEdit (TSR under MS-DOS) and have upgraded ever since.  Best text editor I ever used and it's macro and repeat ability makes it a breeze to edit anything that has some sort of pattern to it.
I've also used it since my 1st computer in 1991 and have macros to convert midi triplets to real ones, change the duration of a piece, and remove digits from text on the system clipboard.  The last one was useful in removing measure numbers from sung text but with the addition of insertion points in the text coinsiding with where it is in the score, the last one may not be needed anymore. www.wjporter.com/nwc (http://www.wjporter.com/nwc/)
Title: Re: Inline editing of user tools
Post by: Rob den Heijer on 2007-09-14 05:51 am
That is absolutely cool!
I'll find some time to compare your triplet.s to mine - and I can have a look at the other macros, too.
cheers,
Rob.
Title: Re: Inline editing of user tools
Post by: Rob den Heijer on 2007-09-14 08:10 am
A pity. Visiting the page gives me a directory, but I cannot access the files.
"HTTP Error 404 - File or directory not found." is the only reaction.

Could you post the files elsewhere please?
Or (if you can do that) change the attributes of the files. I think they now have "700" ; they need "744" at least.
Am I making sense?
Title: Re: Inline editing of user tools
Post by: NoteWorthy Online on 2007-09-14 09:01 am
In regard to Warren's site: It seems to need IE. I get the 404 error in Forefox, but not IE.
Title: Re: Inline editing of user tools
Post by: Rob den Heijer on 2007-09-14 09:41 am
Ah. It could have to do with restrictions, here at work.
Will try at home; there I have FF and IE. Thanks for the tip.
Title: Re: Inline editing of user tools
Post by: NoteWorthy Online on 2007-09-14 10:02 am
Now I get the 404 error on both IE and FF, so perhaps the server is flaky.
Title: Re: Inline editing of user tools
Post by: Warren Porter on 2007-09-14 12:44 pm
I had the same problem, I could see the files in IE but couldn't look at or save them unless I was in my FTP program.  Until I can look into it, here is the triplet.s code:

Removed by author.
Title: Re: Inline editing of user tools
Post by: Warren Porter on 2007-09-15 01:02 pm
I renamed my scripts to end in ".txt" and are visible now.  Still need to check with Ma Bell about what the problem is with nwc files. These were written to work with material from the clipboard so they might need to be modified to process a nwctxt file.

www.wjporter.com/nwc (http://www.wjporter.com/nwc).