Author Topic: button to launch external application  (Read 17039 times)

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
button to launch external application
« on: February 27, 2008, 01:45:25 PM »
Is there a way to create an extra button on the existing toolbar? I have an external checker that i want to integrate with SlickEdit the following way:

If i am currently editing a source file with slickedit and I click this button, it will launch an external application, sending as parameter to that application the current file that i am editing. The external application will perform some checks on this source file and will return an output (signalling errors and warnings).

Is is possible to capture the output of this external application and display it in the Build window of SlickEdit?

Even more, if, let's say, one of these output messages (from the external application) signals a warning at a certain line, then I would like to be able to click that message in the Build window, and, as a result, to be taken to that line in the source file (in the editing window of SlickEdit).

I would be grateful if you could get me started in these directions. Thank you.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #1 on: February 27, 2008, 03:32:34 PM »
I'm using wrapper macros like this:
Code: [Select]
_command void cat () name_info (','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   activate_build ();
   _str cmdline="D:\\Tools\\Unix\\wbin\\cat.exe" :+ " " :+ maybe_quote_filename( p_buf_name ) :+ " 2>&1";
   concur_command (cmdline, true, true, false, false);
}
which can be easily added as a new button to a button bar.
Add this macro command e.g. to your 'vusrmacs.e' module (or use the attached example).
It's a good idea to save it to your <SE-config dir> (see Help>About where your configuration directory is located).
After changing/saving you need to load the module: 'Macro>Load Module'.

In 'View>Toolbars>Customize: Categories' you can drag a default button (e.g. User Definable Tools) to a tooolbar.
After that (and closing the dialog) you can r-click this button and change the 'Properties: Command' accordingly.
You could add this command to the context menu as well by using: 'Macro>Menus...' and changing e.g. '_ext_menu_default_sel'.

If you configured error parsing properly ('Build>Configure Error Parsing') you can use the 'prev/next-error' commands or d-click in the Build window to goto the related source location.

Good luck,
HS2
« Last Edit: February 27, 2008, 03:35:00 PM by hs2 »

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #2 on: February 29, 2008, 11:43:02 AM »
Thank you for your reply. I created the button and modified the pathname to my application. However it does not execute the application but the following error is displayed:

C:\Documents and Settings\user\My Documents\src + unit test>C:\Documents and Settings\user\Desktop\MyAppliction.exe "C:\Documents and Settings\user\My Documents\src + unit test\spdh.cpp" 2>&1
'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.

where "src + unit test" is the folder where the edited file is located and MyApplication is the external application that is located on the Desktop.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #3 on: February 29, 2008, 01:40:02 PM »
Since there are SPACEs in the path to the app you need to quote the app too.
E.g.
Code: [Select]
   _str cmdline = maybe_quote_filename ( "C:\\Documents and Settings\\user\\Desktop\\MyAppliction.exe" );
HS2
PS: Try to omit SPACEs in paths/filenames - it makes live easier ... ;)

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #4 on: March 03, 2008, 09:26:26 AM »
You were right, hs2 - with no spaces, it works. It launches my application and its output is written in the build window.

As i mentioned before, the external application's output contains errors and warnings like:

"Type 1 warning at line 6672
more details about the warning on the following line"

Therefore, i see this text now in the build window. What I would like to do, is to be able to click on one of the 2 lines of this message, and as a result, to be taken to that line in the editing window. Right now, if i click on a word in these lines, a "Find File" window opens, and ti prompts me to enter the path for that word.

i.e.: If I click on "warning", the prompted message is:  Enter path for "warning"

Is there a way to be taken to line 6672 when I click on any of the 2 lines?

Thank You

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #5 on: March 03, 2008, 12:29:48 PM »
As mentioned you've to configure the error parser accordingly (see Build>Configure Error Parsing in SE v12) that the error parser is able to extract the path-to-file and line/column information from your proprietary (not covered by the built-in/default error parser config) error output to jump to. This was greatly improved with SE v12 but it's also possible to adjust the error parser for older versions, but in a slightly different way.
Which SE version are you using ?
HS2

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #6 on: March 04, 2008, 11:06:14 AM »
I use SE v12. I selected the menu option use mentioned. I am now reading the "regular expression" help intensively to try to define my own rule in the "User" section. I am still not sure about one thing: will the regular expression just try do match a pattern, or can I also specify the action I want (i.e.: go to a certain line in the current file) ?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #7 on: March 04, 2008, 11:46:13 AM »
The regex is used/'hooked' by the error parsing engine to determine the target location to jump to. No action can/needs to be specified.
BTW: It's usually a good approach to adopt an existing error parsing pattern.
Good luck,
HS2

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #8 on: March 10, 2008, 09:40:28 PM »
it was a good idea to adopt an existing error pattern - it saved me a lot of time.
I have another question: would it be possible to get the relative path to file (relative to the work environment) instead of the absolute path?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #9 on: March 10, 2008, 10:13:16 PM »
Yes, see Help>Index: relative
I hope that's what you're searching for,
HS2
PS: Thank you !

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #10 on: March 11, 2008, 02:05:57 PM »
I found it...but it was only partly satisfactory after implementing it...I think i'll stick with the absolute.

Anyway, I managed to create the button, assign it the right actions. However, the button creation was "manual" - from the menu options.

Are the new configurations of my slickedit saved somewhere? I want to be able to distribute these changes to other people too, and it would be more convenient if i just distributed the modified files instead of telling them: "go create a button, then link it to the file i'm sending, and so on".

Thanks.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #11 on: March 14, 2008, 10:39:01 PM »
You could do the following:
Check your 'vusrobjs.e' file. It contains the modified form with your added button (for example: 'Tools' button bar).
Copy and paste the '_form' to a new Slick-C module and add a few add. lines before the '_form' code:
Code: [Select]
#include 'slick.sh'

defload()
{
   tbHide ('_tbtools_form');
   tbShow ('_tbtools_form');
}

_form _tbtools_form {
...
}
You can distribute this file to others telling them to do 'Macro>Load Module: 'Tools_buttonbar_enhanced.e'

Sounds strange, but I'd recommend to 'Macro>Unload Module' after doing so.
It's not longer needed (the modified form will be saved in the other users 'vslick.sta'/'vusrobjs.e' files.

Otherwise it's now one of the user macro modules (see def_macfiles) which is not really needed.

The defload() code causes the immediate update of the 'Tools' button bar when the module is compiled into vslick.sta.
This function could be omitted, but in this case the user could either do it manually (r-click: Hide + r-click other toolbar and select 'Tools' to un-hide again) or just exit and re-start SE.

HS2
« Last Edit: March 14, 2008, 10:53:29 PM by hs2 »

newb

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: button to launch external application
« Reply #12 on: March 17, 2008, 03:42:30 PM »
I'm having a problem with the functioning of button.

The executable file (the application) called by pressing the newly created button requires some configuration files in the same directory(in its own directory). However, when I load a file into Slickedit from a different directory, and hit the button, the new pathway is the new directory- where the source file is located (not the application directory), so the application says it cannot find the config file. If I move the config file in the directory where the open source file is, then it works again...but it is not convenient, of course, to move config files to every directory where there is a file i want to open.

Is there a way to set the pathway (the environment) to the directory I have my application in? Or other suggestions?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: button to launch external application
« Reply #13 on: March 17, 2008, 04:55:36 PM »
You can either call a batch also doing the approriate 'cd' or you can try to adopt the cmdline accordingly:
Code: [Select]
_str cmdline="cd <path-to-tool> && tool.exe" ...or you could try to put it into the macro command sth. like this:
Code: [Select]
   cur_dir := getcwd ();
   cd ('-p ' "<path-to-tool>");  // maybe use env. var 'get_env ("MY_TOOL_PATH")

   // execute the tool etc.

   cd ( '-p 'cur_dir );

Good luck,
HS2