Author Topic: New/Delete Files with *.?pp Wildcard Project  (Read 5461 times)

matthewinrandwick

  • Junior Community Member
  • Posts: 4
  • Hero Points: 1
New/Delete Files with *.?pp Wildcard Project
« on: August 24, 2006, 04:51:59 AM »
Hi,

I have a few remaining issues before our integration of SlickEdit in our organisation.  Hopefully, with a few short macros and some keyboard shortcuts they can be solved.

System setup:

* Using bjam to compile (external make command, using gcc)
* Projects are set up using recursive wildcards (*.hpp, *.cpp)

Issues:

* Not possible to right-click/add a file at the selected directory level, it must be in the project root. (Minor)

* Adding a new file to a project always requires a right-click refresh for the file to appear in the project list. Keyboard shortcut is needed given how often files are added and removed. (Critical)

* Files cannot be deleted from within the IDE. Keyboard shortcut or menu item needed. (Critical)

* Error markers don't appear in source files, but double-clicking errors in the output window jumps to the correct source location. (Minor)

I have created a flash demo showing our project setup and a demonstration of the issues described above:

http://www.zomojo.com/downloads/slick1.zip


Thanks for your assistance,

Matthew Herrmann


-----------

Matthew Herrmann

Software Architecture
Zomojo Pty Ltd


matthewinrandwick

  • Junior Community Member
  • Posts: 4
  • Hero Points: 1
Re: New/Delete Files with *.?pp Wildcard Project
« Reply #1 on: August 24, 2006, 11:32:44 PM »
Hi All,

Have made some progress on these. Here are my macros for anyone interested.

I've attached the reload to the F5 key, and the delete/rename to the right-click menu items. The error marker only engages when the full path to an error is listed in the error output, not a relative path.

The only remaining gripes are to insert files and folders under the current folder node, and then everything looks ready to go!

Something useful to newcomers would be a "hacker's guide" to macros, that explains:

* Macros need to be compiled into .ex files, then reloaded using the Load Macros command every time they are changed. This took a bit of fiddling.
* Some entry points -- _message_box, get_string(), getting current filename, project name, workspace name etc.

Regards,
Matthew Herrmann




/**
 *
 * Reloads the current project to reflect any
 * new or removed files.
 *
 */
_command reload_current_project() name_info(','VSARG2_MACRO|VSARG2_MARK)

   _str cur_project_name='';
   status=_ini_get_value(VSEWorkspaceStateFilename(_workspace_filename),"Global","CurrentProject",cur_project_name);
   cur_project_name=absolute(cur_project_name,strip_filename(_workspace_filename,'N'));
   workspace_insert(cur_project_name, true, true, true);
}

/**
 * Deletes the currently selected file in the tree view.
 */
_command delete_current_file() name_info(','VSARG2_MACRO|VSARG2_MARK)

   int ff=1;
   int currIndex;
   _str name='', fullPath='';
   int treeWid=p_window_id;
   for (;;ff=0)
   {
      int index=_TreeFindSelected(ff);
      if (index<0) break;
      if (getTreeFile(treeWid, index, name, fullPath))
      {
         continue;
      }

      if (_message_box(nls("Delete %s?", fullPath), "SlickEdit", MB_OKCANCEL|MB_ICONQUESTION) == IDOK)
      {
         edit(fullPath);
         if (close_buffer() == 0)
         {
            delete_file(fullPath);
            reload_current_project();
         }
      }
      break;
   }
   
}

/**
 * Renames the currently selected file in the tree view.
 */
_command rename_current_file() name_info(','VSARG2_MACRO|VSARG2_MARK)

   int ff=1;
   int currIndex;
   _str name='', fullPath='';
   int treeWid=p_window_id;
   for (;;ff=0)
   {
      int index=_TreeFindSelected(ff);
      if (index<0) break;
      if (getTreeFile(treeWid, index, name, fullPath))
      {
         continue;
      }

      _str new_filename;
      if (get_string(new_filename, "Enter a filename", "", fullPath) == 0)
      {
         edit(fullPath);
         if (close_buffer() == 0)
         {
            if (copy_file(fullPath, new_filename) == 0)
            {
               delete_file(fullPath);
            }
            reload_current_project();
         }
      }

      break;
   }
   
}

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: New/Delete Files with *.?pp Wildcard Project
« Reply #2 on: August 25, 2006, 01:09:14 AM »
What OS are you working on?

Quote
/**
 * Deletes the currently selected file in the tree view.
 */
_command delete_current_file() name_info(','VSARG2_MACRO|VSARG2_MARK)

On my v11/WinXP installation, when I can right-click on a filename in the Project tree there is a 'Remove' option; when I click on that, there is an option to remove the file from disk, as well as from the project.
Similarly, in the Open tab, there is a delete option on the right-click menu.

Or maybe I'm misunderstanding what you're looking for.

matthewinrandwick

  • Junior Community Member
  • Posts: 4
  • Hero Points: 1
Re: New/Delete Files with *.?pp Wildcard Project
« Reply #3 on: August 28, 2006, 10:54:18 PM »
Hi Wanderer,

Thanks for the reply -- I can see those options too, but they are greyed out, I suspect because they are wildcard project entries.

Anyway, I've got a solution to that problem now with the attached scripts.

Cheers,
Matthew

(Following is a new script to handle adding new files, to put on the right-click for project folders.)


/** Creates a new file at the current location. */
_command create_new_file() name_info(','VSARG2_MACRO|VSARG2_MARK)
{
   int ff=1;
   int currIndex;
   _str name='', fullPath='';
   int treeWid=p_window_id;

   
   for (;;ff=0)
   {
      int index=_TreeFindSelected(ff);
      if (index<0) break;

      // find the first file node, if one exists
      index = _TreeGetFirstChildIndex(index);
      int found = 0;
      while (index != -1)
      {
         if (_TreeGetFirstChildIndex(index) == -1)
         {
            found = 1;
            break;
         }

         index = _TreeGetNextSiblingIndex(index);
      }
      if (found == 0)
      {
         continue;
      }

      // try to get the full path to the filename
      if (getTreeFile(treeWid, index, name, fullPath))
      {
         continue;
      }
      fullPath = strip_filename(fullPath, 'N');
      break;
   }

   if (fullPath == '')
   {
      return 1;
   }

   // Get filename from user
   _str filename = fullPath;
   if (get_string(filename, "Enter filename : ", "", fullPath) == 0)
   { 
      edit(filename);

      _str define_text = upcase(strip_filename(filename, 'P'));
      define_text = stranslate(define_text, "_", ".");
      define_text = nls("%s_%s", define_text, random(100000000000,999999999999));

      boolean header = substr(filename, length(filename) - 3) == ".hpp";
     
      // Boilerplate
      if (header)
      {
         _insert_text(nls("#ifndef %s\n", define_text) );
         _insert_text(nls("#define %s\n\n", define_text) );
      } else
      {
         _insert_text(nls("#include \"%s.hpp\"\n\n", strip_filename(filename, 'PE')));
      }
     
      _insert_text("namespace projectname { \n");
      _insert_text("\n");
      _insert_text("} \n\n");

      if (header)
      {
         _insert_text("#endif\n");
      }

      save();
      reload_current_project();
   }

}
« Last Edit: August 28, 2006, 10:57:06 PM by matthewinrandwick »