Author Topic: how to show list of buffers not in workspace files  (Read 3206 times)

ehab

  • Senior Community Member
  • Posts: 285
  • Hero Points: 15
  • coding with SE is like playing music
how to show list of buffers not in workspace files
« on: March 31, 2010, 07:38:05 pm »
hello all,

often i open files not related to workspace files and using list_buffers will show the open buffers off course.

what i would like to do is

list_buffers_nonworkspace

i will benefit by quickly navigating to open files not related to current project or workspace.

anyone came across such need and find a solution would help : )

comments are also welcome.

Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330
Re: how to show list of buffers not in workspace files
« Reply #1 on: April 01, 2010, 11:08:21 pm »
Hi ehab

Here's some code adapted from here that might help
http://community.slickedit.com/index.php?topic=5154.msg21426#msg21426


Code: [Select]
static _str ofiles[];

int generate_ofiles()
{
   _str attrs = file_list_field(p_buf_name, DIR_ATTR_COL, DIR_ATTR_WIDTH);

   if (!_FileExistsInCurrentWorkspace(p_buf_name)) {
      ofiles[ofiles._length()] = attrs :+ '  ' :+ strip_filename(p_buf_name,'p') :+
                              '  ' :+ strip_filename(p_buf_name,'n');
   }
   return 0;
}
   
_command void list_ofiles() name_info(',')
{
   ofiles._makeempty();
   for_each_buffer('generate_ofiles');

   typeless result=show("-modal -xy _sellist_form","Open buffers",SL_COMBO|SL_SIZABLE,ofiles,'','','','','',
                        'list_ofiles','','','',7);

   ofiles._makeempty();
}

ehab

  • Senior Community Member
  • Posts: 285
  • Hero Points: 15
  • coding with SE is like playing music
Re: how to show list of buffers not in workspace files
« Reply #2 on: April 01, 2010, 11:39:20 pm »
Graeme, nice to hear from you

the solution is excellent, as usual : )

one extra request if i may.

how do i add a call back function or so that when i select a file and press enter will will switch to the buffer i have selected?

ehab

  • Senior Community Member
  • Posts: 285
  • Hero Points: 15
  • coding with SE is like playing music
Re: how to show list of buffers not in workspace files
« Reply #3 on: April 02, 2010, 12:03:56 am »
i just used

Code: [Select]
edit_file(result);
with some change in ofiles off course. If you passed by with some time then i'd love to learn how to use callback functions just for this example.

thanks Graeme and my regards

« Last Edit: April 02, 2010, 12:28:08 am by ehab »

Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330
Re: how to show list of buffers not in workspace files
« Reply #4 on: April 03, 2010, 08:53:39 am »
oops, I forgot the most important bit.  Oh well, you figured it out.  Here's an example of how the callback thing works.

Also, if you type
list-buffers 1
on the slick cmd line you'll see the old list buffers dialog and if you type fp old-list-buffers you'll get taken to the code where you can also see callbacks being used.

Code: [Select]
static _str ofiles[];

int generate_ofiles()
{
   _str attrs = file_list_field(p_buf_name, DIR_ATTR_COL, DIR_ATTR_WIDTH);

   if (!_FileExistsInCurrentWorkspace(p_buf_name)) {
      // ofiles[ofiles._length()] = attrs :+ '  ' :+ strip_filename(p_buf_name,'p') :+
         //                     '  ' :+ strip_filename(p_buf_name,'n');
      ofiles[ofiles._length()] = p_buf_name;
   }
   return 0;
}
   
_str list_ofiles_callback(int reason,_str & result,_str key)
{
   _nocheck _control _sellistcombo;
   _nocheck _control _sellist;
   _nocheck _control _sellistok;
   _str fn;
   if (reason==SL_ONDEFAULT) {  // Enter key
      return 1;
   }
   if (reason == SL_ONUSERBUTTON) {
      if (key == 3) {
         // close buffer button
         int orig_wid = p_window_id;
         start_again :
         while(1) {
            if (_sellist._lbfind_selected(1))
               break;
            fn = _sellist._lbget_text();
            _sellist._delete_line();
            _save_non_active(fn, true);
            continue start_again;
            //status=_sellist._lbfind_selected(0);
         }
         p_window_id = orig_wid;
      }
   }
   return '';
}



_command void list_ofiles() name_info(',')
{
   ofiles._makeempty();
   for_each_buffer('generate_ofiles');

   _str buttons = 'b1,Close buffer,b3';
   typeless result=show("-modal -xy _sellist_form",
                        "Open buffers",
                        SL_COMBO|SL_SIZABLE|SL_DEFAULTCALLBACK|SL_ALLOWMULTISELECT,
                        ofiles,
                        buttons,
                        '',
                        '',
                        'list_ofiles_callback',
                        '',
                        'list_ofiles',
                        '','','',0);

   ofiles._makeempty();
   message(result);
}