Author Topic: Open Partner File - Open the .h or .cpp corresponding file to the current file  (Read 11400 times)

ewjax

  • Community Member
  • Posts: 13
  • Hero Points: 0
From the source (see attached file):

Code: [Select]

#include "slick.sh"


//
// if this is a .h file, open the corresponding .cpp file
// if this is a .cpp file, open the corresponding .h file
//   
// original author:  Elliott W. Jackson
//
_command OpenPartnerFile()
{
   _str name;
   _str ext;
   _str partner_name;


   // get filename w/o extension
   name = strip_filename(p_buf_name, "E");

   // get extension
   ext = get_extension(p_buf_name);

   // correct filetype?
   if ( (ext == "h") || (ext == "cpp") )
   {
      // apend on new extension
      if (ext == "h")
      {
         partner_name = name".cpp";
      }

      if (ext == "cpp")
      {
         partner_name = name".h";
      }

      // edit partner file
      edit(partner_name);
   }

   message("OpenPartnerFile - Written by Elliott W. Jackson");

}

« Last Edit: July 14, 2006, 02:53:14 AM by ewjax »

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
A very similar command is built into SlickEdit -- edit_associated_file -- and it also works with C#, VB, and Ada.

sdayts

  • Community Member
  • Posts: 42
  • Hero Points: 5
I have attached a macro which toggles between .h/.cc,.cpp,c files.
This macro works off the project file to find a corresponding file to open, which is a big plus if your .h/.cpp files are not in the same directory. This macro only works for C/C++ file extensions.  It is not very pretty or elegant, but gets the job done.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
A very similar command is built into SlickEdit -- edit_associated_file -- and it also works with C#, VB, and Ada.

For a C/C++ programmer this command is so useful that in my opinion it should be added to the edit menu in slickedit so that people know it exists.  I adapted a macro written by a slickedit programmer and posted it a couple of weeks ago after looking to see if there was a built in one and deciding there wasn't.  I guess I should have looked harder through the names in the key bindings dialog.  I know there's a lot of command names in that dialog but maybe the helpfile should have a list of the most useful ones and what they do.

Graeme