[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  A utility to bring Crimson Editor to the foreground
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

A utility to bring Crimson Editor to the foreground

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Nick Gammon   Australia  (15,394 posts)  [Biography] bio
Date Tue 23 May 2006 04:58 AM (UTC)  quote  ]

Amended on Wed 04 Jun 2008 09:31 PM (UTC) by Nick Gammon

Message
I have been playing with Crimson Editor, making it the default program for editing MUSHclient scripts. However I found to my annoyance that when I pressed Ctrl+Shift+H although Crimson Editor opened the script file, the program was not brought to the foreground, so that it was an extra step to click on it, to edit the file.

I couldn't find an easy way around this - it seems that the code used inside Crimson Editor to prevent multiple copies being active at once does not correctly bring the program to the front if it was already running.

Thus, I have written a small DLL that you can download and use with MUSHclient. It exposes a couple of handy utilities:


  • windows_utils.send_to_front - bring a program to the front

  • windows_utils.shell_execute - uses the Windows shell to run a program, open a file, print it, etc.


The DLL, and its source code, can be downloaded from:

http://www.gammon.com.au/files/mushclient/lua5.1_extras/windows_utils.zip

File size: 27 Kb.

Inside are windows_utils.dll and windows_utils.c.

Put windows_utils.dll into the same directory as MUSHclient.exe.

To make it work for me I edited the Lua "sandbox" in the Global Preferences, and added these lines *before* the call to MakeSandbox (near the top in other words):


assert (package.loadlib ("windows_utils.dll", "luaopen_windows_utils")) ()

Accelerator ("Shift+Ctrl+H", 
  [[/DoCommand "EditScriptFile"
  windows_utils.send_to_front "Crimson Editor"]])


What this does is load the DLL, and then use the Accelerator script command to change the accelerator for editing the script file (Shift+Ctrl+H) to:


  • DoCommand "EditScriptFile" -- this still edits the script file

  • windows_utils.send_to_front "Crimson Editor" -- this brings Crimson Editor to the front


If you want to use this with a different editor, just change the words "Crimson Editor" to something else (eg. UltraEdit). The match is case-sensitive on the start of the title of the window.

The other utility in the DLL is an interface to the ShellExecute operating system function. This lets you open, explore or print documents or programs. For example:


assert (windows_utils.shell_execute ("c:\\mushclient\\worlds\\SMAUG.MCL"))


Warning - this could be misused if you ran untrusted plugins or scripts. If this is likely to happen I suggest you put this line into your Lua sandbox to disable it:


windows_utils.shell_execute = nil


You would do this after the line:


assert (loadlib ("windows_utils.dll", "luaopen_windows_utils")) ()

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Rakon   USA  (116 posts)  [Biography] bio
Date Tue 23 May 2006 05:11 PM (UTC)  quote  ]
Message
Wow, thats nifty Nick. Thanks!

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
[Go to top] top

Posted by Norbert   USA  (61 posts)  [Biography] bio
Date Tue 19 Sep 2006 11:13 PM (UTC)  quote  ]
Message
Is it possible to access the ftp features of Crimson Editor with aliases and a little scripting in mushclient? What I want to do is open a file from the mud I play one for editing.

Norbert

-Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens
It's a dumb question... skip it.
[Go to top] top

Posted by Shadowfyr   USA  (1,766 posts)  [Biography] bio
Date Thu 21 Sep 2006 02:23 AM (UTC)  quote  ]
Message
One note with this.. The "FindWindow" API, which seems to be what he is using (just a guess, since I haven't looked at the code, but used the same for one of my tests), has a problem. It cannot tell the difference between different program windows with the same name and bigger issues arise when trying to deal with a window that changes its name, such as Mushclient does, when you open a new world (its looking at the Title bar for the name, since MS wasn't bright enough to make a "name" field or require that such a filed have a unique name for every program/process.

The safest solution *if* you could manage it, is to do something more complicated, you need to either find the window after creation (poor, but possibly the only solution), then remember that windows ID from then on (or) you would need to run the application with an API call that returns the unique process ID that Windows gives it when it starts, then remember that, so you can find the window when you need it again. Otherwise, the only "safe" solution is to only use it with programs that will not allow you to run more than one copy of themselves at one time, so you can't have a name conflict.

Anyway, nice utility. Its useful, but people should be aware that there are programs that it is "not" reliable to use it with, such as, for example, if you tried to use it with Internet Explorer and had 'several' such windows open. Unless you can identify what window you opened when you ran the program and remember it, you are relying on an API call that has no real idea what you are looking for, so might "find" and "bring to front" the wrong window.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (15,394 posts)  [Biography] bio
Date Thu 21 Sep 2006 02:50 AM (UTC)  quote  ]
Message
Quote:

Is it possible to access the ftp features of Crimson Editor with aliases and a little scripting in mushclient?


Not sure, depends a bit on what scripting is available in Crimson Editor, but I have my doubts. Generally programs are protected from influencing each other, for security reasons.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


5,889 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]