Author Topic: saving workspace specific data  (Read 3696 times)

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
saving workspace specific data
« on: January 15, 2012, 03:54:39 pm »
You would expect to find this browsing through these forums/user's guide but no luck, forgive me if the answer is obvious.

I want to save some workspace specific data (some strings which is different in each workspace).
set_env() is no good, because when I open a new workspace without closing slickedit, the values remain

Any other way other than making my own "DB" in the config directory?

Graeme

  • Senior Community Member
  • Posts: 2533
  • Hero Points: 329
Re: saving workspace specific data
« Reply #1 on: January 15, 2012, 08:06:47 pm »
Try workspace properties -> environment.

Alternatively, in project properties, on the open tab, you can specify commands to be executed when a project is opened, including setting environment variables.  I don't know if you can specify the name of a slick macro here or not.
Alternatively, you can write your own slick macro with the macro name prefixed by _workspace_opened_ and it will get called when a new workspace is opened.  You can get the name of the current workspace with _workspace_filename

Graeme

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: saving workspace specific data
« Reply #2 on: January 17, 2012, 07:20:17 am »
Maybe I didn't explain myself properly.

I have some workspace specific data I need to use in a macro.
The data has nothing to do with the workspace name.
Lets say for example: an IP address of a special server that every workspace (project) has a different value in it
I want to store it once, and than use it on every time the workspace is opened.
Like some DB that maps a workspace to an address (again - there is no way I can deduce it from the workspace name or any other stored stuff)

Is there a build-in way to do this? or I need to make this "DB" in a file by myself?

Graeme

  • Senior Community Member
  • Posts: 2533
  • Hero Points: 329
Re: saving workspace specific data
« Reply #3 on: January 17, 2012, 11:19:35 am »
I had a feeling I didn't understand what you were asking for and unfortunately I still don't so I can only repeat that in workspace properties -> environment, you can assign the values of environment variables.  So each workspace can set the value of an environment variable called IpAddress to whatever value e.g. 127.0.0.1.

However, you might just as well write a macro that returns the value like this
Code: [Select]
_str get_something()
{
    switch(_workspace_filename)
    {
        case "c:/workspaces/workspace1.vpw" : return "127.0.0.1";
        // ...
    }
}

Maybe someone else can understand what you're asking?

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: saving workspace specific data
« Reply #4 on: January 17, 2012, 02:22:55 pm »
OK, now I got what you didn't understand... (typical programmer's problem  :))
This string is an input of a user  (in a dialog) that uses the macro and can change over time, it's not a constant

Graeme

  • Senior Community Member
  • Posts: 2533
  • Hero Points: 329
Re: saving workspace specific data
« Reply #5 on: January 17, 2012, 11:03:17 pm »
oh, ok.  You could use either an .ini or .xml file for the data.  Slick has support for both.  .ini is probably less work.  If you want an example, you could download my xretrace macro and have a look at xretrace_control_panel.e - the functions do_xretrace_load_config() and xsave_config().  So in your case, the section_name argument would be the workspace name.
http://community.slickedit.com/index.php/topic,4693.0.html

xml would give you more flexibility.


Code: [Select]
static void do_xretrace_load_config(xretrace_config * dptr, _str section_name)
{
    // set default values for all items
    call_config_funcs(CFG_FUNC_SET_DEFAULT, dptr);     

    int section_view, current_view;
    get_view_id(current_view);
    int res;
    res = _ini_get_section(_config_path() :+ 'xretrace_config.ini', section_name, section_view);
    if (res) {
        return;
    }
    activate_view(section_view);
    top();
    _insert_text(' '\r\n);  // _ini_parse_line does a down() first
    top();
    activate_view(current_view);
    _str field_name,value;
    int k = 0, maxl = 0;
    while ( k==0 ) {
        if (++maxl > 4000) {
            break;
        }
        k = _ini_parse_line(section_view,field_name,value);
        if (k==0) {
           // Set item value whose name matches the field name, to the parsed value
           call_config_funcs(CFG_FUNC_SET_ITV_TO_VAL, dptr, value, field_name);
        }
    }

boaz

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: saving workspace specific data
« Reply #6 on: January 18, 2012, 07:18:31 am »
great! thanks a lot!