Author Topic: set_active_project  (Read 10505 times)

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
set_active_project
« on: July 26, 2007, 07:12:39 PM »
This macro command allows you to quickly set active the project you specify, by giving the name of the project to the command.  I haven't found any similar built-in commands, so I decided to write one myself.  I hope it's also useful to someone. :)

You can give the project name as the command line argument, or just execute the command, and it'll ask you the project name via input dialog.

Code: [Select]
/**
 * Set active the specified project by its name, without the
 * .vpj extension.  So, to activate 'foo.vpj', this command
 * expects 'foo' as the input.  If there are multiple projects
 * with the same name, it activates the first project it finds.
 *
 * @param name name of the project to activate
 */
_command void set_active_project(_str name='') name_info(COMMAND_ARG',')
{
   if (name == '') {
      int res = textBoxDialog("Project Name", 0, 0, "", "", "set_active_project", "project name");
      if (res == COMMAND_CANCELLED_RC) {
         // Dialog cancelled.  Abort.
         message("command cancelled");
         return;
      }
      name = _param1;
      if (name == '') {
         // Name is still empty.  Abort.
         message("specified project name is empty");
         return;
      }
   }

   // Load the workspace XML file of the current workspace.
   int status = 0;
   int handle = _xmlcfg_open(_workspace_filename, status);
   if (status < 0) {
      message("failed to load workspace file");
      return;
   }

   // Go through all project names.
   _str projFiles[];
   _WorkspaceGet_ProjectFiles(handle, projFiles);
   int i, n = projFiles._length();
   for (i = 0; i < n; ++i) {
      _str projName = stranslate(projFiles[i], '', "?*/", "r");
      projName = stranslate(projName, '', "\\.vpj$", "r");
      if (name == projName) {
         // Matching project name found.  Set this project active.
         workspace_set_active(projFiles[i]);
         return;
      }
   }

   message("no project named '"name"' found");
}
« Last Edit: July 26, 2007, 07:16:43 PM by Kohei »

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #1 on: July 26, 2007, 09:56:43 PM »
Nice macro Kohei - thanks for sharing [HP++] !

HS2

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: set_active_project
« Reply #2 on: July 27, 2007, 03:57:03 PM »
Thanks for the hero point HS2! :)

What would be nice, though, is to extend this code to allow auto-completion within the input box.  The needed information - the list of projects in the current workspace - is known beforehand, so it would be nice to use that information to add some polish.

Maybe something to do when I get more spare time. :)

Kohei
« Last Edit: July 27, 2007, 04:01:55 PM by Kohei »

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #3 on: July 27, 2007, 05:14:03 PM »
Completion would be nice !
As an alternative sth. like the old 'project-load' command (sellist w/ combobox) would also be helpful.
Maybe it's easier to do ...

Good luck,
HS2

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #4 on: August 01, 2007, 10:01:44 AM »
Hi Kohei,

it's easily overlooked but there is sth. useful already built-in: 'workspace-properties' command (or Project>Workspace Props).
The tree control also supports i-searching so it's almost useful for fast-switching projects.
I've made a keybinding to it and added these event handlers to my macro toolbox and now I'm pretty happy with it :)
Code: [Select]
// HS2-ADD: @see wkspace.e      -  Set Active an bail out on ALT-ENTER wherever the focus is
defeventtab _workspace_properties_form
void _workspace_properties_form.A_ENTER()
{
   ctlset_active.call_event (ctlset_active,lbutton_up);
   ctlclose.call_event(ctlclose,LBUTTON_UP);
}
// HS2-ADD: @see wkspace.e      -  Flip back to tree on BACKSPACE
void _workspace_properties_form.BACKSPACE()
{
   ctltree1._set_focus;
}

HS2

Kohei

  • Senior Community Member
  • Posts: 192
  • Hero Points: 25
Re: set_active_project
« Reply #5 on: August 01, 2007, 01:07:21 PM »
Ah, nice!  I was sure there was something like that. :)

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #6 on: September 02, 2007, 03:20:32 PM »
@Kohei: BTW: 'workspace_properties' can be abused for switching projects much better if you change the form so that the 'Set Active' button is the default one. With that you can just use <ENTER>...

However, I've made another macro command 'qproj' for switching projects quickly.
I discarded the idea of adding a new completion arg b/c a workspace could contain projects with the same name but in different directories so completion would need to complete the full path to a vpj-file to allow unique selections. That's not applicable.
But 'qproj' behaves quite similar - except you've to use <ENTER> instead of <TAB>.

Usage on cmdline - the filter arg (wildcard) is optional:
qproj <filter>
or
qproj <|filter> resp. <FiLtEr> for CaSe sens. filtering.

If there is a uniq. match w/ a filter set no selection list is shown and the project is activated immediately (or the full path to it is inserted).
The selection list also supports i-search. The curr. project is the initially selected line and is marked with a '>'.
A 'Properties' button is also implemented.

I think it's a quite handy command also if bound to a key...

HS2

Edit: Added (default) sorting.
« Last Edit: September 23, 2007, 12:21:31 AM by hs2 »

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #7 on: March 16, 2008, 04:25:26 PM »
Sorry - there was a bug in '_qproj_callback -> SL_ONINIT'.
Code: [Select]
   _sellist._lbsort();
   _sellist._lbtop();  // goto the beginning of the list after sorting
HS2

hensz

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: set_active_project
« Reply #8 on: July 27, 2011, 01:29:41 PM »
@hs2: Great macro, thank you for sharing!

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: set_active_project
« Reply #9 on: April 15, 2012, 01:31:09 PM »
This is a reworked version of qproj.e supporting SE >= 12 incl. V17 beta2:
There are 2 known issues:
1) when invoked with cmdline activated (by keybinding) the focus to cmdline is not restored although the selected text is inserted properly
2) the column alignment of the dialog is broken in V17 beta 2.

HS2