Author Topic: Is there an option to close all open files when switching workspaces?  (Read 125 times)

rowbearto

  • Senior Community Member
  • Posts: 815
  • Hero Points: 27
When I switch workspaces, I desire to have all the editor windows that are opened to be closed automatically.

This is because I have many of the same named files in these different workspaces, and I don't want to go to the old ones.

I also don't want auto-restore because some of these files are on a network drive so I don't want switching workspaces to be slow while getting files off the network drive.

Is there any setting to close all editor windows when switching workspaces?

Thanks,
Rob

Graeme

  • Senior Community Member
  • Posts: 1992
  • Hero Points: 228
Re: Is there an option to close all open files when switching workspaces?
« Reply #1 on: December 12, 2017, 12:26:13 pm »
I'm not following what you're trying to do.  If a workspace has files a,b,c open when you close it, when you next open it, files a,b,c will be the only files open.

I don't know if it helps but if you search slick macro source for call_list, you'll see in wkspace.e there is _workspace_opened_ and _wkspace_close_ so you can write a function such as _workspace_opened_abc() and it will be called automatically when a workspace is opened.  If you want to close all buffers before closing a workspace, you could try adding a call to close_all at the start of the workspace_close function in wkspace.e.

rowbearto

  • Senior Community Member
  • Posts: 815
  • Hero Points: 27
Re: Is there an option to close all open files when switching workspaces?
« Reply #2 on: December 12, 2017, 01:45:28 pm »
Quote
I'm not following what you're trying to do.  If a workspace has files a,b,c open when you close it, when you next open it, files a,b,c will be the only files open.

This is only true of "auto restore workspace" is enabled. If auto restore workspace is disabled, whatever files were opened before the new workspace was opened remain open.

Quote
I don't know if it helps but if you search slick macro source for call_list, you'll see in wkspace.e there is _workspace_opened_ and _wkspace_close_ so you can write a function such as _workspace_opened_abc() and it will be called automatically when a workspace is opened.  If you want to close all buffers before closing a workspace, you could try adding a call to close_all at the start of the workspace_close function in wkspace.e.

Thanks I will look into this.

Graeme

  • Senior Community Member
  • Posts: 1992
  • Hero Points: 228
Re: Is there an option to close all open files when switching workspaces?
« Reply #3 on: December 13, 2017, 04:31:57 am »
You can close all non C drive buffers like this.

Code: [Select]
int close_remote_files()
{
   if ( substr(p_buf_name, 1, 2) == "C:") {
      return 0;
   }
   close_buffer(); 
   return 0;
}
 
_command void abc() name_info(',')
{
   for_each_buffer('close_remote_files');
}

You can also use save_named_state and load_named_state to save and restore a set of buffers.