[code] Menu Validation (MF_DISABLED bugged on PC?)

[code] Menu Validation (MF_DISABLED bugged on PC?)

Postby Dan Rathbun » Sun Jan 30, 2011 1:35 pm

Re: Menu and Toolbar validation.

It seems on SU 8.0M1 the validation flag MF_DISABLED has no effect. The user can still select the item, and the comand is run.

Is this a new bug?

How does this compare to Mac ?

Code: Select all
#  Valid integer values for PC:
#
# ** MF_BITMAP not used by Sketchup
#
#  0 = MF_UNCHECKED | MF_ENABLED
#  1 = MF_UNCHECKED | MF_GRAYED
#  2 = MF_UNCHECKED | MF_DISABLED
#  3 = MF_UNCHECKED | MF_GRAYED | MF_DISABLED
#
#  4 = MF_UNCHECKED | MF_BITMAP | MF_ENABLED
#  5 = MF_UNCHECKED | MF_BITMAP | MF_GRAYED
#  6 = MF_UNCHECKED | MF_BITMAP | MF_DISABLED
#  7 = MF_UNCHECKED | MF_BITMAP | MF_GRAYED | MF_DISABLED
#
#  8 = MF_CHECKED   | MF_ENABLED
#  9 = MF_CHECKED   | MF_GRAYED
# 10 = MF_CHECKED   | MF_DISABLED
# 11 = MF_CHECKED   | MF_GRAYED | MF_DISABLED
#
# 12 = MF_CHECKED   | MF_BITMAP | MF_ENABLED
# 13 = MF_CHECKED   | MF_BITMAP | MF_GRAYED
# 14 = MF_CHECKED   | MF_BITMAP | MF_DISABLED
# 15 = MF_CHECKED   | MF_BITMAP | MF_GRAYED | MF_DISABLED
#
# note 16 = MF_POPUP


If @@validation is a class var holding the validation integer for a menu item or toolbar item. You could use an instance var @validation. Or you could pass the integer in, by putting a validation argument into the () on the def method line, and changing all the @@validation to just validation:

Produce it's Bitwise OR string:
Code: Select all
def valid_string()
  
  valid
=''
  
  
# Test the 4th bit: MF_CHECKED==1
  if @@validation[3]==1
    valid 
<< 'MF_CHECKED | '
  else
    valid 
<< 'MF_UNCHECKED | '
  end
  
  
# Test the 3rd bit: MF_BITMAP==1
  #
  # valid << 'MF_BITMAP | ' if @@validation[2]==1 
  
  if 
@@validation[0]==1 or @@validation[1]==1
    
# Test the 1st bit: MF_GRAYED==1
    if @@validation[0]==1
      valid 
<< 'MF_GRAYED'    if @@validation[1]==0
      valid 
<< 'MF_GRAYED | ' if @@validation[1]==1
    end
    
# Test the 2nd bit: MF_DISABLED==1
    if @@validation[1]==1
      valid 
<< 'MF_DISABLED'
    end
  else 
#
    valid << 'MF_ENABLED'
  end
  return valid
end 
# def
  

checked?() method
Code: Select all
#  checked?()
#
#  Returns Boolean state of MF_CHECKED.
#
def self.checked?()
  #@@validation >= 8 # on PC
  (@@validation & MF_CHECKED).nonzero? ? true : false
end

enabled?() method
Code: Select all
#  enabled?()
#
#  Returns Boolean state of MF_ENABLED.
#  !! NOT EXACT same as MF_UNCHECKED !!
#
def self.enabled?()
  # [0,4,8,12].include?(@@validation) # on PC
  # on PC MF_DISABLED has no effect. Use MF_GRAYED instead.
  ((@@validation & MF_GRAYED).nonzero? ||
    (@@validation & MF_DISABLED).nonzero?) ? false : true
end

disabled?() method
Code: Select all
#  disabled?()
#
#  Returns Boolean state of MF_DISABLED.
#
def self.disabled?()
  # [2,3,6,7,10,11,14,15].include?(@@validation) # PC
  (@@validation & MF_DISABLED).nonzero? ? true : false
end

grayed?() method
Code: Select all
#  grayed?()
#
#  Returns Boolean state of MF_GRAYED.
#
def self.grayed?()
  (@@validation & MF_GRAYED).nonzero? ? true : false
end

unchecked?() method
Code: Select all
#  unchecked?()
#
#  Returns Boolean state of MF_UNCHECKED.
#  !! NOT EXACT same as MF_ENABLED !!
#
def self.unchecked?()
  #@@validation < 8 # PC
  (@@validation & MF_CHECKED).nonzero? ? false : true
end


EDIT: made Boolean methods use constants and bitwise comparison for cross-platform use, (which greatly simplifys the check for MF_GRAYED.)
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

    Postby thomthom » Sun Jan 30, 2011 2:14 pm

    This is what I always use for validation procs:
    Code: Select all
      def self.can_paste_proc
        if self.can_paste?
          MF_ENABLED
        else
          MF_DISABLED | MF_GRAYED
        end
      end


    I though MF_DISABLED prevented the action from triggering. And that MF_GRAYED where used only for the visual effect.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

    Postby thomthom » Sun Jan 30, 2011 2:20 pm

    hmm... testing in SU8M1, you're right. MF_DISABLED seem to do nothing. Only MF_GRAYED seems to affect anything.
    Though I imagine there is a reason I use MF_DISABLED | MF_GRAYED - just can't remember why. Can't find any notes on it.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

    Postby thomthom » Sun Jan 30, 2011 2:31 pm

    Same behaviour on SU6, 7.1 Windows.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

    Postby Dan Rathbun » Sun Jan 30, 2011 3:49 pm

    thomthom wrote:Though I imagine there is a reason I use MF_DISABLED | MF_GRAYED - just can't remember why. Can't find any notes on it.

    I'll bet it's a cross-platform thangie... it does not seem to matter to Windows if the DISABLED bit is set, so no harm is done.

    Need a Mac guy to test it and let us know.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

      Postby Dan Rathbun » Sun Jan 30, 2011 4:06 pm

      thomthom wrote:This is what I always use for validation procs:

      Just being clear that the methods above are not the actual validation_proc. I try not to put conditional evaluations into the menu or toolbar procs, if I can do the decision in another place in the code. In most cases, the validation state does not change until the user actually clicks on the item (or button,) so it's better to change the menu item's (or button's) valid state within the command proc, or some other method that gets called. So when the change is made I just change the value of a @@validation class var (or @validation instance var,) and let Sketchup just pick up the value of that var when it must do a UI draw.

      So creating a menu item, would look like:
      item = menu.add_item('Some Menu Label') { ..execute_code.. }
      menu.set_validation_proc(item) { @@validation }
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

        Postby thomthom » Sun Jan 30, 2011 4:11 pm

        Yea, that'd probably be better.

        IN my case I'd need an observer, but it'd still be more efficient.
        0
        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund
        User avatar
        thomthom 
        PluginStore Author
        PluginStore Author
         

        Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

        Postby thomthom » Sun Jan 30, 2011 5:55 pm

        Tested on OSX SU8.0M1 - Same behaviour, MF_DISABLED does nothing.
        0
        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund
        User avatar
        thomthom 
        PluginStore Author
        PluginStore Author
         

        Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

        Postby Dan Rathbun » Tue Feb 01, 2011 2:12 pm

        thomthom wrote:hmm... testing in SU8M1, you're right. MF_DISABLED seem to do nothing. Only MF_GRAYED seems to affect anything.

        thomthom wrote:Same behaviour on SU6, 7.1 Windows.

        thomthom wrote:Tested on OSX SU8.0M1 - Same behaviour, MF_DISABLED does nothing.


        Thanks go to ThomThom for filing a Google BugReport on this, 30 JAN 2011. :!:
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

          Postby thomthom » Tue Feb 01, 2011 2:34 pm

          I still wonder why I've been using MF_DISABLED... :?
          0
          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund
          User avatar
          thomthom 
          PluginStore Author
          PluginStore Author
           

          Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

          Postby Dan Rathbun » Tue Feb 01, 2011 2:58 pm

          Covering your butt.. just in case the API changes in the future?
          0
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: [code] Menu Validation (MF_DISABLED bugged on PC?)

            Postby thomthom » Tue Feb 01, 2011 3:00 pm

            Possibly. Maybe it was in another language where you had to gray and disable. ...Visual Basic...? Can't think of anything else where I've dealt with menus...
            0
            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund
            User avatar
            thomthom 
            PluginStore Author
            PluginStore Author
             

            SketchUcation One-Liner Adverts

            by Ad Machine » 5 minutes ago



            Ad Machine 
            Robot
             



             

            Return to Developers' Forum

            Who is online

            Users browsing this forum: No registered users and 18 guests