Class: Cosmos::RubyEditor
Defined Under Namespace
Classes: LineNumberArea, RubySyntax
Constant Summary
collapse
- CHAR_57 =
Qt::Char.new(57)
CompletionTextEdit::SELECTION_DETAILS_POOL, CompletionTextEdit::TRUE_VARIANT
Qt::PlainTextEdit::AMP, Qt::PlainTextEdit::BLANK, Qt::PlainTextEdit::BREAK, Qt::PlainTextEdit::GT, Qt::PlainTextEdit::LT, Qt::PlainTextEdit::NBSP
Instance Attribute Summary collapse
Instance Method Summary
collapse
#highlight_line, #indent_selection, #keyPressCallback=, #keyPressEvent, #rehighlight, #stop_highlight, #unindent_selection
#addText, #add_formatted_text, #appendText, #flush, #selected_lines, #selection_end_line, #selection_start_line
Constructor Details
#initialize(parent) ⇒ RubyEditor
Returns a new instance of RubyEditor.
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 157
def initialize(parent)
super(parent)
font = Cosmos.get_default_font
setFont(font)
@fontMetrics = Cosmos.getFontMetrics(font)
setStyleSheet("selection-background-color: lightblue; selection-color: black;")
@breakpoints = []
@enable_breakpoints = false
@syntax = RubySyntax.new(document())
@lineNumberArea = LineNumberArea.new(self)
connect(self, SIGNAL('blockCountChanged(int)'), self, SLOT('line_count_changed()'))
connect(self, SIGNAL('updateRequest(const QRect &, int)'), self, SLOT('update_line_number_area(const QRect &, int)'))
line_count_changed()
end
|
Instance Attribute Details
#enable_breakpoints ⇒ Object
Returns the value of attribute enable_breakpoints.
28
29
30
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 28
def enable_breakpoints
@enable_breakpoints
end
|
Instance Method Details
#add_breakpoint(line) ⇒ Object
197
198
199
200
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 197
def add_breakpoint(line)
@breakpoints << line
@lineNumberArea.repaint
end
|
#clear_breakpoint(line) ⇒ Object
202
203
204
205
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 202
def clear_breakpoint(line)
@breakpoints.delete(line)
@lineNumberArea.repaint
end
|
#clear_breakpoints ⇒ Object
207
208
209
210
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 207
def clear_breakpoints
@breakpoints = []
@lineNumberArea.repaint
end
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 212
def
cursor = textCursor
no_selection = cursor.hasSelection ? false : true
cursor.beginEditBlock
selection_end = cursor.selectionEnd
cursor.setPosition(textCursor.selectionStart)
cursor.movePosition(Qt::TextCursor::StartOfLine)
result = true
while (cursor.position < selection_end && result == true) || (no_selection)
if cursor.block.text =~ /^\S*#~/
cursor.deleteChar
cursor.deleteChar
selection_end -= 2
else
cursor.insertText("#~")
selection_end += 2
end
cursor.movePosition(Qt::TextCursor::StartOfLine)
result = cursor.movePosition(Qt::TextCursor::Down)
break if no_selection
end
cursor.endEditBlock
end
|
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 186
def (point)
= createStandardContextMenu()
return unless @enable_breakpoints
.addSeparator()
.addAction(create_add_breakpoint_action(point))
.addAction(create_clear_breakpoint_action(point))
.addAction(create_clear_all_breakpoints_action())
end
|
180
181
182
183
184
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 180
def dispose
super()
@syntax.dispose
@lineNumberArea.dispose
end
|
#line_number_area_paint_event(event) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 258
def line_number_area_paint_event(event)
painter = Qt::Painter.new(@lineNumberArea)
if painter.isActive and not painter.paintEngine.nil?
event_rect = event.rect()
painter.fillRect(event_rect, Qt::lightGray)
block = firstVisibleBlock()
blockNumber = block.blockNumber()
top, bottom = block_top_and_bottom(block)
width = @lineNumberArea.width()
height = @fontMetrics.height()
ellipse_width = @fontMetrics.width(CHAR_57)
painter.setPen(Cosmos::BLACK)
while (block.isValid() and top <= event_rect.bottom())
if (block.isVisible() and bottom >= event_rect.top())
number = blockNumber + 1
painter.drawText(0, top, width, height, Qt::AlignRight, number.to_s)
if @enable_breakpoints and @breakpoints.include?(number)
painter.setBrush(Cosmos::RED)
painter.drawEllipse(2,
top+2,
ellipse_width,
ellipse_width)
end
end
next_block = block.next()
block.dispose
block = next_block
top = bottom
rect = blockBoundingRect(block)
bottom = top + rect.height()
rect.dispose
blockNumber += 1
end
block.dispose
block = nil
event_rect.dispose
event_rect = nil
end
painter.dispose
painter = nil
end
|
#resizeEvent(e) ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 246
def resizeEvent(e)
super(e)
cr = self.contentsRect()
rect = Qt::Rect.new(cr.left(),
cr.top(),
line_number_area_width(),
cr.height())
@lineNumberArea.setGeometry(rect)
cr.dispose
rect.dispose
end
|