Class: EditableLabel

Inherits:
Gtk::Label
  • Object
show all
Defined in:
lib/terminal_chooser.rb

Instance Method Summary collapse

Constructor Details

#initialize(term) ⇒ EditableLabel

Returns a new instance of EditableLabel.



344
345
346
347
348
349
350
351
352
# File 'lib/terminal_chooser.rb', line 344

def initialize(term)
  super(term.terminal_title)
  set_halign(:start)
  set_selectable(true)
  signal_connect "button-release-event" do |w, e|
    generate_label_popup(w, e, term)
  end
  label
end

Instance Method Details

#add_label_popup_entry_activate_signal(label, term) ⇒ Object



381
382
383
384
385
386
387
# File 'lib/terminal_chooser.rb', line 381

def add_label_popup_entry_activate_signal(label, term)
  @entry.signal_connect "activate" do |widget|
    label.text = widget.buffer.text
    term.custom_title = widget.buffer.text
    @popup.destroy
  end
end

#add_label_popup_entry_icon_release(label, term) ⇒ Object



370
371
372
373
374
375
376
377
378
379
# File 'lib/terminal_chooser.rb', line 370

def add_label_popup_entry_icon_release(label, term)
  @entry.signal_connect "icon-release" do |widget, position|
    if position == :secondary
      term.custom_title = nil
      label.text = term.window_title
      term.toplevel.current_label.text = label.text
      widget.buffer.text = label.text
    end
  end
end

#generate_label_popup(label, event, term) ⇒ Object



354
355
356
357
358
359
360
361
# File 'lib/terminal_chooser.rb', line 354

def generate_label_popup(label, event, term)
  initialize_entry_popup(label)
  @popup = Gtk::Popover.new
  add_label_popup_entry_activate_signal(label, term)
  add_label_popup_entry_icon_release(label, term)
  @popup.add(@entry)
  set_popup_position(label, event)
end

#initialize_entry_popup(label) ⇒ Object



363
364
365
366
367
368
# File 'lib/terminal_chooser.rb', line 363

def initialize_entry_popup(label)
  @entry = Gtk::Entry.new
  @entry.max_width_chars = 50
  @entry.buffer.text = label.text
  @entry.set_icon_from_icon_name(:secondary, "edit-clear-symbolic")
end

#set_popup_position(label, event) ⇒ Object



389
390
391
392
393
394
395
396
# File 'lib/terminal_chooser.rb', line 389

def set_popup_position(label, event)
  x, y = event.window.coords_to_parent(event.x, event.y)
  rect = Gdk::Rectangle.new(x - label.allocation.x, y - label.allocation.y,
                            1, 1)
  @popup.pointing_to = rect
  @popup.relative_to = label
  @popup.show_all
end