sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    One-shot toolbar buttons?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 357 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.
    • S Offline
      slbaumgartner
      last edited by

      Is there a way to create a button in a toolbar that works like the zoom extents button? That is, when you click it the underlying Tool/Command does its one-shot action and then the Toolbar button returns to un-selected? The only way I've been able to get this effect is to force the model to select the SelectionTool (which isn't necessarily what was active before). I tried things such as popping the active tool, but it didn't reset the button.

      Thanks
      Steve

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        A button should never show it is checked unless YOU set it's validation to anything other than MF_ENABLED || MF_UNCHECKED

        Answer yes, using send_action.

        IF there is a selection then this Zoom command should zoom to the selection, otherwise zoom to the model extents.

        command_proc = {
          if Sketchup.active_model.selection.empty?
            Sketchup.send_action("viewZoomExtents;")
          else
            Sketchup.send_action("viewZoomToSelection;")
          end
        }
        

        πŸ’­

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • tt_suT Offline
          tt_su
          last edited by

          @slbaumgartner said:

          Is there a way to create a button in a toolbar that works like the zoom extents button? That is, when you click it the underlying Tool/Command does its one-shot action and then the Toolbar button returns to un-selected?

          That is the default behaviour, unless you implement validation procs or make the button activate a tool. When you activate a tool the button will remain pressed for as long as that tool is active.

          1 Reply Last reply Reply Quote 0
          • S Offline
            slbaumgartner
            last edited by

            @dan you may have missed my point. I don't want to implement a zoom, I was just mentioning zoom extents as a tool whose button does what I want. I have a different tool that isn't really modal, it just performs an action and then wants control to go back to whatever was live before.

            @TT I'm puzzled. Here's what I tried:

            
            tb=UI;;Toolbar.new "Test"
            cmd = UI;;Command.new("clickme") {puts "click!"}
            tb.add_item cmd
            tb.show
            
            

            This works functionally, that is, it prints click! in the Ruby Console, but the button toggles between unselected and selected ("pressed") look with each click. I want it to reset to unselected after each click and reactivate whatever was the active tool before the click.

            Thanks
            Steve

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              Your example works fine for me on PC, in both versions that I have installed (and from memory in all versions I have ever had installed.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                You may have run into a Mac bug in a certain version.

                Try this:

                tb=UI;;Toolbar.new "Test"
                cmd = UI;;Command.new("clickme") {puts "click!"}
                cmd.set_validation_proc { MF_UNCHECKED }
                tb.add_item cmd
                tb.show
                

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • S Offline
                  slbaumgartner
                  last edited by

                  @dan rathbun said:

                  You may have run into a Mac bug in a certain version.

                  Try this:

                  tb=UI;;Toolbar.new "Test"
                  > cmd = UI;;Command.new("clickme") {puts "click!"}
                  > cmd.set_validation_proc { MF_UNCHECKED }
                  > tb.add_item cmd
                  > tb.show
                  

                  Tried that in several versions of SU and the button toggles between "unpressed" and "pressed" every time...

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    Disable all plugins, test again. If still it does not work.. log a bug report.

                    State whether the toolbar is floating, docked vertically, or on the top horizontal bar (which has always been buggy on the Mac.)

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      Also verify that MF_UNCHECKED == 0, just to be sure no plugin has messed with the global constants.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        slbaumgartner
                        last edited by

                        @dan rathbun said:

                        Disable all plugins, test again. If still it does not work.. log a bug report.

                        State whether the toolbar is floating, docked vertically, or on the top horizontal bar (which has always been buggy on the Mac.)

                        Still doesn't work, whether floating, docked, or in the top bar. Filing a bug.

                        Steve

                        1 Reply Last reply Reply Quote 0
                        • tt_suT Offline
                          tt_su
                          last edited by

                          Oh, right - yes I noticed that there's a bug under OSX. Sorry, I mostly use PC so I'd forgotten. I think there's an issue for it, but I'll check again and bump it.

                          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