Author Topic: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename  (Read 526 times)

florihupf

  • Community Member
  • Posts: 54
  • Hero Points: 0
VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« on: October 31, 2023, 11:29:24 AM »
Hi there,

I have a couple custom macros that use VSEWorkspaceStateFilename() API.  Looks like I needed to change to VSEWorkspaceStateOLDFilename() to keep things working after upgrading to Slickedit 2023.

Basically I write longs strings to keep some internal state about last edited files in a way I prefer :-)

Are there any pitfalls now using the VSEWorkspaceStateOLDFilename() API? Things to look out for?

Thanks in advance!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #1 on: October 31, 2023, 01:55:58 PM »
Keep in mind that v28 will not write any data to VSEWorkspaceStateOLDFilename().  In other words, if you create a new workspace in v28, the file won't even exist unless you create it. We switched to an XML format file which is more readable, easier to store data, and less likely to have bugs due to odd characters.

florihupf

  • Community Member
  • Posts: 54
  • Hero Points: 0
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #2 on: November 01, 2023, 09:33:03 AM »
Thanks for the pointer Clark,

I am writing a long, comma separated string and it fails with the new XML format.  Do I need to escape the string somehow?  Or are there new methods to use for the new XML format?

Only reason I keep using the OLDFilename version is that writing string there works.  Thanks!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #3 on: November 01, 2023, 02:31:49 PM »
Post your old code and I can probably convert it for you.

florihupf

  • Community Member
  • Posts: 54
  • Hero Points: 0
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #4 on: November 02, 2023, 09:10:25 AM »
The code to save the LRU of the last projects used is something like this:

Code: [Select]
static void saveLastProjects()
{
   _str lastProjectsStr;
   _ini_get_value(VSEWorkspaceStateOLDFilename(), "LastProjects", "Global", lastProjectsStr);

   _str lastProjects[];
   split(lastProjectsStr, ",", lastProjects);

   int i;
   int foundAt = -1;
   for(i=0; i<lastProjects._length(); ++i) {
      if (lastProjects[i] == _project_name) {
         foundAt = i;
         break;
      }
   }

   // Bring element to front.
   if (foundAt >= 0) {
      lastProjects._deleteel(foundAt);
   }

   // Insert at front.
   lastProjects._insertel(_project_name, 0);

   // Save new (LRU'd) state.
   lastProjectsStr = join(lastProjects, ",");
   _ini_set_value(VSEWorkspaceStateOLDFilename(), "LastProjects", "Global", lastProjectsStr);
}

And I read it back via:

Code: [Select]
   _str lastProjectsStr;
   _ini_get_value(VSEWorkspaceStateOLDFilename(), "LastProjects", "Global", lastProjectsStr);
   _str lastProjects[];
   split(lastProjectsStr, ",", lastProjects);

Works with the old methods, but somehow fails (produces empty lastProjects array) with the new.

Chances are I messed something up :-)

Thanks for taking a peek!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #5 on: November 02, 2023, 02:03:55 PM »
I'm not seeing any code that initially creates the "LastProjects" section and stores a value for "Global". The old version 27. 0.2 of SlickEdit does not create this section and set this value. Do you have some code elsewhere that sets this?

florihupf

  • Community Member
  • Posts: 54
  • Hero Points: 0
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #6 on: November 05, 2023, 05:51:06 AM »
Hi Clark,

I was just looking through my code / macros and I only call the _init_set/get_value() APIs.  It is old code, but works fine :-)

Is there something else I am supposed to do?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #7 on: November 05, 2023, 02:38:01 PM »
If the only code that gets/sets the LastProjects value is the code you sent, it will definitely never work. It will always be blank. You must have some macro code somewhere else that sets this (at least that's what makes sense to me). I scanned a ton of SlickEdit macro source trees and there is no LastProjects value stored in the vpwhist file by us.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #8 on: November 06, 2023, 02:19:20 AM »
My original assessment about your code was incorrect. Your code works fine for me. There is no need to convert it because _ini_set_value() automatically creates the old INI format vpwhist file if it does not exist. Since this is a unique filename (doesn't overwrite the new XML file), I don't see a problem with using it as is. Both the old and new format vpwhist files can exist without confusing SlickEdit.

I tested your code on our SlickEdit workspace which has many projects. I called your function for different active projects and it had no probably creating the old INI format vpwhist file and ordering the project list.

florihupf

  • Community Member
  • Posts: 54
  • Hero Points: 0
Re: VSEWorkspaceStateFilename vs. VSEWorkspaceStateOLDFilename
« Reply #9 on: November 06, 2023, 07:22:43 AM »
Thanks Clark for double checking! Much appreciated!