Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status text suggestion #133

Open
Eneroth3 opened this issue Mar 30, 2020 · 4 comments
Open

Status text suggestion #133

Eneroth3 opened this issue Mar 30, 2020 · 4 comments

Comments

@Eneroth3
Copy link
Contributor

People often seem to forget setting the status text on tool resume, resulting in a blank status bar after having orbit, and no clue what the custom tool does. It would be nice if sketchup-rubocop had a suggestion for setting the status text on resume (and on activate if that is not already done).

@thomthom
Copy link
Member

To always suggest this, or to only suggest it if the status text can be detected to have been set at other events?

Keep in mind only simple cases can be detected. If people set up utility methods to update the status text (I do that pretty consistently) then the indirection makes it difficult to detect.

@Eneroth3
Copy link
Contributor Author

I was thinking always checking, as I can't think of any valid case when a tool shouldn't have a status text.

Can't rubocop see if a method calls another method containing some given call? I always have a separate method for setting the status text that I call both in resume and activate.

@thomthom
Copy link
Member

thomthom commented Apr 1, 2020

Can't rubocop see if a method calls another method containing some given call?

There is no simple lookup for that. It gets complex really fast. I've some times done one level of indirection checking for very common predictable patterns.

@Eneroth3
Copy link
Contributor Author

Eneroth3 commented Apr 1, 2020

Maybe this is a case where it's worth doing the complex one level check thing?

# Bad. No status text at all.
# Unsure how common.
class MyTool
  def activate
    # ...
  end
  
  def resume(view)
    # ...
  end
end

# Bad. No status text on resume.
# Surprisingly common.
class MyTool
  def activate
    Sketchup.status_text = 
      if @some_state
        "Mash some buttons and press some keys."
      else
        "Press some keys and mash some buttons."
      end
  end
  
  def resume(view)
    # ...
  end
end

# Better. Functions corerctly but code repeats itself.
# Probably quite common.
class MyTool
  def activate
    Sketchup.status_text = 
      if @some_state
        "Mash some buttons and press some keys."
      else
        "Press some keys and mash some buttons."
      end
  end
  
  def resume(view)
    Sketchup.status_text = 
      if @some_state
        "Mash some buttons and press some keys."
      else
        "Press some keys and mash some buttons."
      end
  end
end

# Good.
# My preference.
class MyTool
  def activate
    update_status_text
  end
  
  def resume(view)
    update_status_text
  end
  
  private
  
  def update_status_text
    Sketchup.status_text = 
      if @some_state
        "Mash some buttons and press some keys."
      else
        "Press some keys and mash some buttons."
      end
  end
end

# Convoluted.
# Probably uncommon.
# I wouldn't mind if this cave a false positive.
class MyTool
  def activate
    some_method
  end
  
  def resume(view)
    some_method
  end
  
  private
  
  def some_method
    update_status_text
  end
  
  def update_status_text
    Sketchup.status_text = 
      if @some_state
        "Mash some buttons and press some keys."
      else
        "Press some keys and mash some buttons."
      end
  end
end

@thomthom thomthom changed the title Status text sugegstion Status text suggestion Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants