Class: Ruber::SyntaxChecker::Plugin

Inherits:
Plugin show all
Defined in:
plugins/syntax_checker/syntax_checker.rb,
plugins/syntax_checker/syntax_checker.rb

Overview

Plugin object for the syntax_checker feature

Defined Under Namespace

Classes: Led

Constant Summary

COLORS =
{
  :correct => Qt::Color.new(Qt.green),
  :unknown => Qt::Color.new(Qt.gray),
  :incorrect => Qt::Color.new(Qt.red)
}
MESSAGES =
{
  :correct => 'No syntax errors',
  :unknown => 'Unknown document type',
  :incorrect => 'There are syntax errors'
}

Constants inherited from Plugin

LICENSES

Instance Attribute Summary (collapse)

Attributes included from PluginLike

plugin_description

Instance Method Summary (collapse)

Methods inherited from Plugin

#about_data

Methods included from PluginLike

#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #delayed_initialize, #initialize_plugin, #plugin_name, #query_close, #register_options, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #save_settings, #session_data, #setup_action, #setup_actions, #shutdown, #update_project

Signal Summary

API for class SyntaxChecker::SyntaxCheckerPlugin

Methods API

Constructor Details

- (Plugin) initialize(psf)

A new instance of Plugin



124
125
126
127
128
129
130
131
132
133
134
135
# File 'plugins/syntax_checker/syntax_checker.rb', line 124

def initialize psf
  super
  self.connect(SIGNAL('extension_added(QString, QObject*)')) do |name, prj|
    connect prj.extension(name.to_sym), SIGNAL('syntax_checked(QObject*)'), self, SLOT('document_checked(QObject*)')
  end
  @syntax_checkers = {}
  @led = Led.new
  connect @led, SIGNAL('context_menu_requested(QPoint)'), self, SLOT('display_context_menu(QPoint)')
  connect @led, SIGNAL(:left_clicked), self, SLOT(:jump_to_first_error)
  Ruber[:main_window].status_bar.add_permanent_widget @led
  set_current_status :unknown
end

Instance Attribute Details

- (Object) current_errors (readonly)

Returns the value of attribute current_errors



92
93
94
# File 'plugins/syntax_checker/syntax_checker.rb', line 92

def current_errors
  @current_errors
end

- (Object) current_status (readonly)

Returns the value of attribute current_status



90
91
92
# File 'plugins/syntax_checker/syntax_checker.rb', line 90

def current_status
  @current_status
end

Instance Method Details

- (Object) display_context_menu(pt) (private)



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'plugins/syntax_checker/syntax_checker.rb', line 184

def display_context_menu pt
  return if @current_status == :unknown
  if !@current_errors || @current_errors.empty?
    actions = [KDE::Action.new(i18n(MESSAGES[@current_status]), @led)]
  else actions = @current_errors.map{|e| KDE::Action.new format_error(e), @led}
  end
  choice = Qt::Menu.exec actions, pt
  return if !choice or !@current_errors or @current_errors.empty?
  error = @current_errors[actions.index(choice)]
  line = error.line
  col = error.column || 0
  Ruber[:world].active_environment.active_editor.go_to line, col if line
end

Slot Signature:

display_context_menu(QPoint)

- (Object) document_checked(doc) (private)



209
210
211
212
213
# File 'plugins/syntax_checker/syntax_checker.rb', line 209

def document_checked doc
  return unless doc.active?
  ext = doc.extension(:syntax_checker)
  set_current_status ext.status, ext.errors
end

Slot Signature:

document_checked(QObject*)

- (Object) format_error(error)



150
151
152
153
154
155
156
157
158
# File 'plugins/syntax_checker/syntax_checker.rb', line 150

def format_error error
  msg = ''
  if error.line
    msg << KDE.i18n("Line %d") % (error.line + 1)
    msg << (error.column ? (KDE.i18n(", column %d: ")) % (error.column + 1) : ': ')
  end
  msg << KDE.i18n(error.formatted_message || error.message || 'UNKNOWN ERROR')
  msg
end

- (Object) jump_to_first_error (private)



199
200
201
202
203
204
205
206
# File 'plugins/syntax_checker/syntax_checker.rb', line 199

def jump_to_first_error
  return unless @current_errors and !@current_errors.empty?
  e = @current_errors[0]
  col = e.column || 0
  if e.line
    Ruber[:world].active_environment.active_editor.go_to e.line, col
  end
end

Slot Signature:

jump_to_first_error()

- (Object) load_settings



178
179
180
# File 'plugins/syntax_checker/syntax_checker.rb', line 178

def load_settings
  emit settings_changed
end

- (Object) register_syntax_checker(cls, mimetypes, patterns = [])



159
160
161
162
163
164
165
# File 'plugins/syntax_checker/syntax_checker.rb', line 159

def register_syntax_checker cls, mimetypes, patterns = []
  if @syntax_checkers.include? cls
    raise ArgumentError, "#{cls} has already been registered as syntax checker"
  end
  @syntax_checkers[cls] = [mimetypes, patterns]
  emit syntax_checker_added
end

- (Object) remove_syntax_checker(cls)



166
167
168
# File 'plugins/syntax_checker/syntax_checker.rb', line 166

def remove_syntax_checker cls
  emit syntax_checker_removed if @syntax_checkers.delete cls
end

- (Object) set_current_status(status, errors = [])



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'plugins/syntax_checker/syntax_checker.rb', line 143

def set_current_status status, errors = []
  @led.color = COLORS[status]
  if status == :incorrect and !errors.empty?
    tool_tip = errors.map do |e|
      format_error e
    end.join "\n"
    @led.tool_tip = tool_tip
  else @led.tool_tip = i18n(MESSAGES[status])
  end
  @current_status = status
  if @current_status == :incorrect
    @current_errors = errors.dup
  else @current_errors = nil
  end
end

- (Object) syntax_checker_for(doc)



170
171
172
173
174
175
176
# File 'plugins/syntax_checker/syntax_checker.rb', line 170

def syntax_checker_for doc
  cls = @syntax_checkers.find do |_, rules| 
    doc.file_type_match?(rules[0], rules[1])
  end
  return unless cls
  cls[0]
end

- (Object) unload



137
138
139
140
141
# File 'plugins/syntax_checker/syntax_checker.rb', line 137

def unload
  Ruber[:main_window].status_bar.remove_widget @led
  super
  self
end

Signal Details

- settings_changed

- syntax_checker_added

- syntax_checker_removed