Class: FileTreePanel
- Inherits:
-
Object
- Object
- FileTreePanel
- Defined in:
- lib/vimamsa/gui_file_panel.rb
Constant Summary collapse
- COL_LABEL =
0- COL_BUF_ID =
0 = folder row (not selectable)
1
Instance Method Summary collapse
- #init_context_menu ⇒ Object
-
#initialize ⇒ FileTreePanel
constructor
A new instance of FileTreePanel.
- #refresh ⇒ Object
- #show_context_menu(x, y) ⇒ Object
- #widget ⇒ Object
Constructor Details
#initialize ⇒ FileTreePanel
Returns a new instance of FileTreePanel.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vimamsa/gui_file_panel.rb', line 5 def initialize @store = Gtk::TreeStore.new(String, Integer) @tree = Gtk::TreeView.new(@store) @tree.headers_visible = false @tree.activate_on_single_click = true @tree.level_indentation = 7 renderer = Gtk::CellRendererText.new renderer.ellipsize = Pango::EllipsizeMode::START col = Gtk::TreeViewColumn.new("", renderer, text: COL_LABEL) col. = true @tree.append_column(col) @tree.signal_connect("row-activated") do |tv, path, _col| iter = @store.get_iter(path) next if iter.nil? buf_id = iter[COL_BUF_ID] next if buf_id.nil? || buf_id == 0 vma.buffers.set_current_buffer(buf_id) end @context_menu = nil rightclick = Gtk::GestureClick.new rightclick. = 3 @tree.add_controller(rightclick) rightclick.signal_connect("pressed") do |gesture, n_press, x, y| result = @tree.get_path_at_pos(x.to_i, y.to_i) next unless result iter = @store.get_iter(result[0]) next unless iter buf_id = iter[COL_BUF_ID] next unless buf_id && buf_id != 0 @context_buf_id = buf_id (x, y) end @sw = Gtk::ScrolledWindow.new @sw.set_policy(:never, :automatic) @sw.set_child(@tree) @sw.set_size_request(180, -1) @sw. = true end |
Instance Method Details
#init_context_menu ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/vimamsa/gui_file_panel.rb', line 52 def act = Gio::SimpleAction.new("fp_close_buffer") vma.gui.app.add_action(act) act.signal_connect("activate") { vma.buffers.close_buffer(@context_buf_id) if @context_buf_id } @context_menu = Gtk::PopoverMenu.new @context_menu.set_parent(@tree) @context_menu.has_arrow = false end |
#refresh ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vimamsa/gui_file_panel.rb', line 70 def refresh @store.clear bh = {} vma.buffers.list.each do |b| dname = b.fname ? File.dirname(b.fname) : "*" bname = b.fname ? File.basename(b.fname) : (b.list_str || "(untitled)") bh[dname] ||= [] bh[dname] << { bname: bname, buf: b } end bh.keys.sort.each do |dname| dir_iter = @store.append(nil) dir_iter[COL_LABEL] = "📂 #{tilde_path(dname)}" dir_iter[COL_BUF_ID] = 0 bh[dname].sort_by { |x| x[:bname] }.each do |bnfo| active_mark = bnfo[:buf].is_active? ? "● " : " " file_iter = @store.append(dir_iter) file_iter[COL_LABEL] = "#{active_mark}#{bnfo[:bname]}" file_iter[COL_BUF_ID] = bnfo[:buf].id end end @tree. end |
#show_context_menu(x, y) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/vimamsa/gui_file_panel.rb', line 61 def (x, y) if @context_menu.nil? = Gio::Menu.new .append("Close file", "app.fp_close_buffer") @context_menu.() @context_menu.set_pointing_to(Gdk::Rectangle.new(x.to_i, y.to_i, 1, 1)) @context_menu.popup end |
#widget ⇒ Object
48 49 50 |
# File 'lib/vimamsa/gui_file_panel.rb', line 48 def @sw end |