Class: Alfred::Handler::Help

Inherits:
Base
  • Object
show all
Defined in:
lib/alfred/handler/help.rb

Constant Summary

Constants inherited from Base

Base::Base_Invoke_Order

Instance Attribute Summary

Attributes inherited from Base

#order, #status

Instance Method Summary collapse

Methods inherited from Base

#<=>, #action?, #feedback, #on_close, #options, #parser, #query, #register, #status_message, #ui, #xml_builder

Constructor Details

#initialize(alfred, opts = {}) ⇒ Help

Returns a new instance of Help.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/alfred/handler/help.rb', line 30

def initialize(alfred, opts = {})
  super
  @settings = {
    :handler           => 'Help'                     ,
    :exclusive?        => true                       ,
    :with_handler_help => true                       ,
    :items             => []                         ,
    :handler_order     => ( Base_Invoke_Order / 10 )
  }.update(opts)

  @order = @settings[:handler_order]

  if @settings[:items].empty?
    @load_from_workflow_setting = true
  else
    @load_from_workflow_setting = false
  end

end

Instance Method Details

#feedback?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/alfred/handler/help.rb', line 68

def feedback?
  options.help
end

#on_action(arg) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/alfred/handler/help.rb', line 149

def on_action(arg)
  return unless action?(arg)

  case arg[:kind]
  when 'url'
    ::Alfred::Util.open_url(arg[:url])
  when 'file'
    %x{open "#{arg[:path]}"}
  end
end

#on_feedbackObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/alfred/handler/help.rb', line 72

def on_feedback
  return unless feedback?

  if @settings[:with_handler_help]
    @settings[:items].push @core.on_help
    @core.handler_controller.each do |h|
      @settings[:items].push h.on_help
    end
  end

  if @load_from_workflow_setting
    if @core.workflow_setting.has_key?(:help)
      @settings[:items].push @core.workflow_setting[:help]
    end
  end

  @settings[:items].flatten!.compact!
  @settings[:items].map! { |i| HelpItem.new(i) }.sort!

  @settings[:items].each do |item|

    case item[:kind]
    when 'file'
      item[:path] = File.expand_path(item[:path])
      # action is handled by fallback action in the main loop
      feedback.add_file_item(item[:path], item)
    when 'url'
      item[:arg] = xml_builder(
        :handler => @settings[:handler] ,
        :kind    => item[:kind]         ,
        :url     => item[:url]
      )

      feedback.add_item(
        {
          :icon => ::Alfred::Feedback.CoreServicesIcon('BookmarkIcon')
        }.merge(item)
      )

    when 'text', 'message'
      item[:arg] = xml_builder(
        {
          :handler      => @settings[:handler] ,
          :kind         => item[:kind]         ,
        }
      )

      feedback.add_item(
        {
          :valid        => 'no' ,
          :autocomplete => ''   ,
          :icon         => ::Alfred::Feedback.CoreServicesIcon('ClippingText') ,
        }.merge(item)
      )

    else
      if item.has_key? :title
        item[:arg] = xml_builder(
          {
            :handler => @settings[:handler] ,
            :kind    => item[:kind]         ,
          }.merge(item)
        )

        feedback.add_item(
          {
            :icon => ::Alfred::Feedback.CoreServicesIcon('HelpIcon'),
          }.merge(item)
        )
      end
    end
  end

  @status = :exclusive if @settings[:exclusive?]
end

#on_helpObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/alfred/handler/help.rb', line 56

def on_help
  {
    :kind         => 'text'                      ,
    :valid        => 'no'                        ,
    :autocomplete => '-h'                        ,
    :match?       => :always_match?              ,
    :order        => (HelpItem::Base_Order * 12) ,
    :title        => '-?, -h, --help [Show Workflow Usage Help]' ,
    :subtitle     => 'Other feedbacks are blocked.'              ,
  }
end

#on_parserObject



50
51
52
53
54
# File 'lib/alfred/handler/help.rb', line 50

def on_parser
  parser.on_tail('-?', '-h', '--help', 'Workflow Helper') do
    options.help = true
  end
end