• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Change of style in undo stack?

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 550 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    XorUnison
    last edited by 29 Dec 2014, 09:44

    This is a smaller but somewhat annoying problem. The situation is this:

    I have a few Plug-Ins which allow the user to switch between different working modes. To do so each Plug-In with its own button does 2 things:
    1: Change the current style (between my predefined styles Construction and Display)
    2: Turn on/off certain layers

    The problem is that only the change of layers lands in the undo stack, which means that if I use one of the buttons to change the working mode, and then do a undo, I land right in between the modes where I don't want to be, the layers will be switched back like they were before, the style won't. Certain layers are only meant to be seen with certain styles though.
    (The tools do use start/commit_operation to only add one step to the undo stack.)

    Possible solutions I could imagine would be:

    1. Completely prevent the tools from putting anything onto the undo stack. That way the current layout could be handled entirely by those plug-ins. I didn't encounter any way to do this though. This would be easy and elegant, and considering the only missing changes from the undo stack are layer visibility values there couldn't be any jumbled geometry either.
    2. Use observers to modify the undo stack, or rather make sure that when the last step was one of my tools the change of style will also be reverted. As far as I'd know this would require me to keep a separate stack parallel to the undo stack, which in turn would require almost twice as much code as the plug-ins themselves require, which seems rather unnecessary and inefficient to me.
      If I could somehow access the name of the current undo/redo operations I could read and compare that value as I can freely name the operation with start_operation, which would make the separate stack unnecessary.

    Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 29 Dec 2014, 12:05

      @xorunison said:

      Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.

      That's not possible. You can make things transparent - but that doesn't make the event avoid the undo stack it's still there.

      Since the Style changes doesn't record on the undo stack, then I'd try to use observers to toggle the styles instead. It's only model changes (stuff that is recorded by the undo system) one should avoid doing in observer events.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • X Offline
        XorUnison
        last edited by 29 Dec 2014, 15:04

        @thomthom said:

        @xorunison said:

        Considering though that the undo stack shouldn't be meddled with through these observers I'd prefer to somehow go with solution #1 and just prevent these tools from adding their layer changes to the undo stack.

        That's not possible. You can make things transparent - but that doesn't make the event avoid the undo stack it's still there.

        Since the Style changes doesn't record on the undo stack, then I'd try to use observers to toggle the styles instead. It's only model changes (stuff that is recorded by the undo system) one should avoid doing in observer events.

        I feared that might be the case. What about accessing the names of the things on the undo/redo stack then, would that be possible?

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 29 Dec 2014, 20:42

          Afraid not. There is very little control over the undo stack in the API. It's an area where it needs improvement.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • X Offline
            XorUnison
            last edited by 2 Jan 2015, 07:34

            Well, that's too bad, thanks for your help though. I guess I will instead use observers to toggle the style according to which layers are visible, it'll ultimately achieve the same while saving me the trouble of writing huge chunks of code to meddle with the undo stack.

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 2 Jan 2015, 11:08

              @xorunison said:

              it'll ultimately achieve the same while saving me the trouble of writing huge chunks of code to meddle with the undo stack.

              Yea, don't fight the undo stack - it's tricky and cause of grey hairs. 😉

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 12 Jan 2015, 21:44

                @xorunison said:

                This is a smaller but somewhat annoying problem. The situation is this:

                I have a few Plug-Ins which allow the user to switch between different working modes. To do so each Plug-In with its own button does 2 things:
                1: Change the current style (between my predefined styles Construction and Display)
                2: Turn on/off certain layers

                This sounds like a perfect job for scenepages.

                One for display, one for work. Each has their own styles set, and each has their own set of off layers, and on layers.

                The button(s) could simply switch between the pages (if you did not want to waste the space for page tabs.)

                The scenes could be preset into a template model.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement