Author Topic: No auto-restore workspace  (Read 8824 times)

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
No auto-restore workspace
« on: March 13, 2008, 03:53:01 pm »
I'm trying to figure out how to achieve a behavior I'm looking for:

(a)  By default Slick launch with no files open (i.e. do not restore the previous workspace).
(b)  If Slick is opened from a particular working directory, open a workspace associated with that working directory.

I'm figuring I will write a macro to do (b), but I'm not sure how to accomplish (a).  I want workspaces to save/load the list of open buffers, etc, but I merely don't want Slick to reopen the last workspace I had open.  Or is there an invocation option that causes it to not open the last workspace?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6209
  • Hero Points: 482
Re: No auto-restore workspace
« Reply #1 on: March 13, 2008, 04:07:53 pm »
There is no existing feature to do this.  You would have to modify main.e (defmain()) to make this change.  Roughly, you need to set "Auto restore files" to on and change the command line arguments to myworkspace.vpw at start up (defmain()).  In the other case, you turn "Auto restore files" off at start up.  That should get you close to what you want.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: No auto-restore workspace
« Reply #2 on: March 14, 2008, 02:44:49 am »
Thanks, I see now how to do (b) by munging the cmdline within defmain to produce arbitrary behaviors including opening workspaces.

The hard part was indeed (a) though, and it took me a few hours but I finally understand enough of how main.e and restore.e interact to make a couple minor tweaks so that Slick avoids restoring the previous project/workspace on startup, but still saves the project/workspace info on exit.  It's only a few lines changed, but in some large files -- what's the preferred way to post these type of tweaks?  I used unified diffs below.  Note, it is only logic to avoid restoring workspaces on invocation -- I didn't share logic for choosing which workspace to load based on cwd, as that is in flux in a personal module).

I suspect I could speed up exit/startup slightly if I can figure out where to close the workspace on exit such that the workspace settings are saved but such that Slick doesn't try to restore the workspace on the next invocation.  But if Slick auto-saves the state (e.g. for crash recovery) then I would still need to prevent restoring on startup, so I figured the brute force approach will suffice for now.

Code: [Select]
==== //depot/SlickEdit/Custom/macros/main.e#1 - c:\Slick\macros\main.e ====
@@ -1854,6 +1854,7 @@
   _str restore_options;
   if (def_auto_restore) {
      restore_options="I";
+     restore_options=restore_options:+"~";  // chrisant: The ~ avoids restoring workspaces.
   } else {
      restore_options="IN";
   }
==== //depot/SlickEdit/Custom/macros/restore.e#1 - c:\Slick\macros\restore.e ===
=
@@ -220,11 +220,19 @@
    typeless mdi_state="";
    boolean JustRestoreGlobalInfo=false;
    boolean RestoringFromInvocation=false;
+   boolean SkipWorkspaceRestore=false;
    restore_options=upcase(restore_options);
    if (pos("I",restore_options)) {
       restore_options=stranslate(restore_options,"","I");
       RestoringFromInvocation=true;
    }
+   // The ~ flag behaves like the N flag except that it avoids restoring
+   // workspaces and projects.
+   if (pos("~",restore_options)) {
+      restore_options=stranslate(restore_options,"","~");
+      SkipWorkspaceRestore=true;
+      restore_options=restore_options:+"N";
+   }
    // IF we already restored from project and just want to restore
    //    global auto restore info.
    if (pos("G",restore_options)) {
@@ -361,15 +369,17 @@
          int index=find_index(name,PROC_TYPE);
          // IF there is a callable function
          if ( index_callable(index)) {
             if (rtype=='WORKSPACE:' && !gHitToolbarsSection) {
                //4:52pm 2/10/2000
                //We do not want to run the workspace restore until after the
                //toolbar restore has run.
                //This is because a SCC version control system being initialized
                //may cause output to the Output toolbar, which would show the
                //output toolbar.  Restore would then show another copy.
-               WorkspaceCallbackIndex=index;
-               WorkspaceLine=p_line;
+               if (!SkipWorkspaceRestore) {
+                  WorkspaceCallbackIndex=index;
+                  WorkspaceLine=p_line;
+               }
                parse line with count .;
                down(count);
             }else{
@@ -399,7 +409,7 @@
       }
    }
    activate_window(window_config_id);
-   if (WorkspaceCallbackIndex) {
+   if (WorkspaceCallbackIndex && !SkipWorkspaceRestore) {
       //4:54pm 2/10/2000
       //Deferred calling the workspace callback earlier.
       //4:52pm 2/10/2000
« Last Edit: March 14, 2008, 08:10:54 pm by chrisant »

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: No auto-restore workspace
« Reply #3 on: March 14, 2008, 10:38:32 am »
Cool chrisant, my 'skip workspace' option is 'W' instead of '~', but the patch is quite similar :)
My intention was/is a bit different. I want to quick-edit files w/o restoring a workspace and avoid saving any settings/state on exit.
I do not use this part :
Quote
if (rtype=='WORKSPACE:' && (!gHitToolbarsSection || SkipWorkspaceRestore)) {
...
b/c I want to get the window/toolbar layout of the last workspace which almost the same for all my workspaces.
'restore workspace' is set.

When posting patches referring to line numbers, you should add the version information e.g. 'SE v12.0.3 r35'. 'r35: hotfix rev. 35.
HS2

FYI: This is the hack to avoid state file saving on exit. I fact just a reduced exit sequence is used.
window.e - safe_exit() [line 949]: SE v12.0.3 r35
Code: [Select]
   // HS2-ADD: hack to avoid state saving when quick-editing files w/o workspace
   // messageNwait ("_workspace_filename:" _workspace_filename);
   if ( _workspace_filename == '' )
   {
     sav_restore_flags := def_restore_flags;
     def_restore_flags = 0;

     if (_workspace_filename != '') workspace_close();

     def_restore_flags = sav_restore_flags;

     if (!bInEclipseMode) {
        int status=list_modified(nls('Exiting with Modified Buffers'),true);
        if (status) {
           return(status);
        }
     }

     stop_search('quiet');
     p_window_id=_mdi.p_child;
     if ( _process_info() ) {  /* is a process running ? */
        if ( def_exit_process ) {
           exit_process();
        } else {
           message(nls('Please exit build window.'));
           return(1);
        }
     }

     quit_error_file();
     exit_list(endingSession==true);

     if (doNotExit=='') {
        exit(0);
     }
     return(0);
   }

pitfall: Any config change has to de done with an opened workspace to get saved.
« Last Edit: March 14, 2008, 11:04:16 am by hs2 »

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: No auto-restore workspace
« Reply #4 on: March 14, 2008, 08:09:13 pm »
Yes, the part you quoted is wrong, and I've removed it.  It was experimental from before I moved the SkipWorkspaceRestore check inside that block, it should have been removed.

The reason for my patch is similar to yours:  I want to be able to quickly edit random files without restoring an unrelated workspace and I don't want the random files to get saved into the settings for an unrelated workspace.  Personally, in that situation I would like it to save any settings that are not workspace settings.

Here is a subtle potential difference in our approaches:  When my Slick opens without a workspace and then closes, it saves that there are no workspaces open.  So next time I open Slick with a workspace, Slick has forgotten about all the other workspaces that were previously open-but-not-active (i.e. they don't appear at the bottom of the Project menu anymore).  But when your Slick opens without a workspace and then closes, it does not save any state.  Thus the next time you open Slick with a workspace, Slick still remembers about all the other workspaces.

Ideally I'd like the Project menu to still list the recent workspaces, but I'm still working on figuring out how Slick saves/restores that part of the state.

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: No auto-restore workspace
« Reply #5 on: March 14, 2008, 09:09:24 pm »
Quote
Thus the next time you open Slick with a workspace, Slick still remembers about all the other workspaces.
Yes, that's by intention. SE also loads my last workspace that I can continue my 'real' work exactly where I left it.
Edit: I'm starting a new SE instance (+new arg) when I'm just quick-editing files to avoid any interference with a possible running instance with a workspace loaded.

But it would be nice if you keep me informed about the results of your investigation.
Thanks in advance and good luck, HS2
« Last Edit: March 14, 2008, 10:04:04 pm by hs2 »

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: No auto-restore workspace
« Reply #6 on: March 16, 2008, 10:26:25 pm »
Update:  I found in _srg_workspace in wkspace.e where it loads the history list on the Project menu and where it opens the most recent workspace/project.  Now it restores the history list of recent workspaces, but does not actually open the most recent one.  Perfect, for my purposes -- I wanted the history list to be preserved, but I wanted workspaces to only be opened either explicitly or by inference based on the directory from which I launched Slick (which is a larger patch and currently lives in my personal macro, which includes quite a bit of other custom stuff so far).

If there is interest in polishing up the inference logic I can push it into its own module and post the updated patch and the inference logic together (I can't imagine the former is useful without the latter).