Class: VMAgui

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/gui.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVMAgui



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/vimamsa/gui.rb', line 196

def initialize()
  @two_column = false
  @active_column = 1
  @show_overlay = true
  @da = nil
  @sws = []
  @buffers = {}
  @view = nil
  @buf1 = nil
  @img_resizer_active = false
  @windows = {}
  @app = nil
end

Instance Attribute Details

#active_windowObject (readonly)

Returns the value of attribute active_window.



194
195
196
# File 'lib/vimamsa/gui.rb', line 194

def active_window
  @active_window
end

#appObject (readonly)

Returns the value of attribute app.



194
195
196
# File 'lib/vimamsa/gui.rb', line 194

def app
  @app
end

#buf1Object

Returns the value of attribute buf1.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def buf1
  @buf1
end

#buffersObject

Returns the value of attribute buffers.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def buffers
  @buffers
end

#delexObject

Returns the value of attribute delex.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def delex
  @delex
end

#overlayObject

Returns the value of attribute overlay.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def overlay
  @overlay
end

#statnfoObject

Returns the value of attribute statnfo.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def statnfo
  @statnfo
end

#subtitleObject (readonly)

Returns the value of attribute subtitle.



194
195
196
# File 'lib/vimamsa/gui.rb', line 194

def subtitle
  @subtitle
end

#sw1Object

Returns the value of attribute sw1.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def sw1
  @sw1
end

#sw2Object

Returns the value of attribute sw2.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def sw2
  @sw2
end

#swsObject

Returns the value of attribute sws.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def sws
  @sws
end

#two_cObject

Returns the value of attribute two_c.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def two_c
  @two_c
end

#two_columnObject (readonly)

Returns the value of attribute two_column.



194
195
196
# File 'lib/vimamsa/gui.rb', line 194

def two_column
  @two_column
end

#viewObject

Returns the value of attribute view.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def view
  @view
end

#windowObject

Returns the value of attribute window.



193
194
195
# File 'lib/vimamsa/gui.rb', line 193

def window
  @window
end

#windowsObject (readonly)

Returns the value of attribute windows.



194
195
196
# File 'lib/vimamsa/gui.rb', line 194

def windows
  @windows
end

Instance Method Details

#add_to_minibuf(msg) ⇒ Object



315
316
317
318
319
320
# File 'lib/vimamsa/gui.rb', line 315

def add_to_minibuf(msg)
  # return #TODO:gtk4
  startiter = @minibuf.buffer.get_iter_at(:offset => 0)
  @minibuf.buffer.insert(startiter, "#{msg}\n")
  @minibuf.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES), -1, false)
end

#clear_overlayObject



261
262
263
264
265
266
# File 'lib/vimamsa/gui.rb', line 261

def clear_overlay()
  if @da != nil
    # @overlay.remove(@da)
    @active_window[:overlay].remove_overlay(@da)
  end
end

#current_viewObject



828
829
830
# File 'lib/vimamsa/gui.rb', line 828

def current_view
  return @active_window[:sw].child
end

#debug_idle_funcObject



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/vimamsa/gui.rb', line 436

def debug_idle_func
  return false if @shutdown == true
  if Time.now - @last_debug_idle > 1
    @last_debug_idle = Time.now
    # puts "DEBUG IDLE #{Time.now}"
    # @view.check_controllers
  end

  ctrl_fn = File.expand_path(get_dot_path("ripl_ctrl"))
  # Allows to debug in case keyboard handling is lost
  if File.exist?(ctrl_fn)
    File.delete(ctrl_fn)
    start_ripl
  end

  sleep 0.02
  return true
end

#end_overlay_drawObject



277
278
279
# File 'lib/vimamsa/gui.rb', line 277

def end_overlay_draw()
  @da.show
end

#ensure_cursor_drawnObject



914
915
916
917
# File 'lib/vimamsa/gui.rb', line 914

def ensure_cursor_drawn
  # view.place_cursor_onscreen #TODO: needed?
  view.draw_cursor
end

#handle_deltasObject



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/vimamsa/gui.rb', line 297

def handle_deltas()
  view.delete_cursor_char
  while d = buf.deltas.shift
    pos = d[0]
    op = d[1]
    num = d[2]
    txt = d[3]
    if op == DELETE
      startiter = @buf1.get_iter_at(:offset => pos)
      enditer = @buf1.get_iter_at(:offset => pos + num)
      @buf1.delete(startiter, enditer)
    elsif op == INSERT
      startiter = @buf1.get_iter_at(:offset => pos)
      @buf1.insert(startiter, txt)
    end
  end
end

#handle_image_resizeObject

TODO:gtk4



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/vimamsa/gui.rb', line 238

def handle_image_resize #TODO:gtk4
  return if @img_resizer_active == true
  @dtime = Time.now

  $gcrw = 0
  vma.gui.window.signal_connect "configure-event" do |widget, cr|
    if $gcrw != cr.width
      @delex.run
    end
    $gcrw = cr.width
    false
  end

  @img_resizer_active = true
end

#idle_ensure_cursor_drawnObject



910
911
912
# File 'lib/vimamsa/gui.rb', line 910

def idle_ensure_cursor_drawn
  run_as_idle proc { self.ensure_cursor_drawn }
end

#idle_set_sizeObject



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/vimamsa/gui.rb', line 531

def idle_set_size()
  # Need to wait for a while to window to be maximized to get correct @window.width
  @window.maximize
  wait_for_resize(@window)
  # Set new size as half of the screeen
  width = @window.width / 2
  height = @window.height - 5
  width = 600 if width < 600
  height = 600 if height < 600

  #Minimum size:
  @window.set_size_request(600, 600)
  @window.set_default_size(width, height)
  debug "size #{[width, height]}", 2
  @window.unmaximize

  #set_default_size doesn't always have effect if run immediately
  wait_for_resize(@window)
  @window.set_default_size(width, height)

  return false
end

#init_header_barObject

TODO: implement in gtk4



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/vimamsa/gui.rb', line 352

def init_header_bar()
  header = Gtk::HeaderBar.new
  @header = header
  header.show_close_button = true
  # header.title = ""#TODO:gtk4
  # header.has_subtitle = true#TODO:gtk4
  header.subtitle = ""

  # icon = Gio::ThemedIcon.new("mail-send-receive-symbolic")
  # icon = Gio::ThemedIcon.new("document-open-symbolic")
  # icon = Gio::ThemedIcon.new("dialog-password")

  #edit-redo edit-paste edit-find-replace edit-undo edit-find edit-cut edit-copy
  #document-open document-save document-save-as document-properties document-new
  # document-revert-symbolic
  #

  #TODO:
  # button = Gtk::Button.new
  # icon = Gio::ThemedIcon.new("open-menu-symbolic")
  # image = Gtk::Image.new(:icon => icon, :size => :button)
  # button.add(image)
  # header.append(button)

  button = Gtk::Button.new
  icon = Gio::ThemedIcon.new("document-open-symbolic")
  image = Gtk::Image.new(:icon => icon, :size => :button)
  button.add(image)
  header.append(button)

  button.signal_connect "clicked" do |_widget|
    open_file_dialog
  end

  button = Gtk::Button.new
  icon = Gio::ThemedIcon.new("document-save-symbolic")
  image = Gtk::Image.new(:icon => icon, :size => :button)
  button.add(image)
  header.append(button)
  button.signal_connect "clicked" do |_widget|
    buf.save
  end

  button = Gtk::Button.new
  icon = Gio::ThemedIcon.new("document-new-symbolic")
  image = Gtk::Image.new(:icon => icon, :size => :button)
  button.add(image)
  header.append(button)
  button.signal_connect "clicked" do |_widget|
    create_new_file
  end

  box = Gtk::Box.new(:horizontal, 0)
  box.style_context.add_class("linked")

  button = Gtk::Button.new
  image = Gtk::Image.new(:icon_name => "pan-start-symbolic", :size => :button)
  button.add(image)
  box.add(button)
  button.signal_connect "clicked" do |_widget|
    history_switch_backwards
  end

  button = Gtk::Button.new
  image = Gtk::Image.new(:icon_name => "pan-end-symbolic", :size => :button)
  button.add(image)
  box.add(button)
  button.signal_connect "clicked" do |_widget|
    history_switch_forwards
  end

  button = Gtk::Button.new
  icon = Gio::ThemedIcon.new("window-close-symbolic")
  image = Gtk::Image.new(:icon => icon, :size => :button)
  button.add(image)
  box.add(button)
  button.signal_connect "clicked" do |_widget|
    bufs.close_current_buffer
  end

  header.pack_start(box)
  @window.titlebar = header
end

#init_menuObject



677
678
679
# File 'lib/vimamsa/gui.rb', line 677

def init_menu
  Vimamsa::Menu.new(@menubar, @app)
end

#init_minibufferObject



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/vimamsa/gui.rb', line 322

def init_minibuffer()
  # Init minibuffer
  sw = Gtk::ScrolledWindow.new
  sw.set_policy(:automatic, :automatic)
  overlay = Gtk::Overlay.new
  overlay.set_child(sw)
  @vbox.attach(overlay, 0, 3, 2, 1)
  sw.set_size_request(-1, 12)

  view = VSourceView.new(nil, nil)
  view.set_highlight_current_line(false)
  view.set_show_line_numbers(false)
  # view.set_buffer(buf1)
  ssm = GtkSource::StyleSchemeManager.new
  ssm.set_search_path(ssm.search_path << ppath("styles/"))
  sty = ssm.get_scheme("molokai_edit")
  view.buffer.highlight_matching_brackets = false #TODO
  view.buffer.style_scheme = sty
  provider = Gtk::CssProvider.new
  # provider.load(data: "textview { font-family: Monospace; font-size: 11pt; }")
  provider.load(data: "textview { font-family: Arial; font-size: 10pt; color:#eeeeee}")
  view.style_context.add_provider(provider)
  view.wrap_mode = :char
  @minibuf = view
  # startiter = view.buffer.get_iter_at(:offset => 0)
  message("STARTUP")
  sw.set_child(view)
end

#init_windowObject



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/vimamsa/gui.rb', line 554

def init_window
  @last_debug_idle = Time.now
  app = Gtk::Application.new("net.samiddhi.vimamsa.r#{rand(1000)}", :flags_none)
  @app = app

  Gtk::Settings.default.gtk_application_prefer_dark_theme = true
  Gtk::Settings.default.gtk_theme_name = "Adwaita"
  Gtk::Settings.default.gtk_cursor_blink = false
  Gtk::Settings.default.gtk_cursor_blink_time = 4000

  app.signal_connect "activate" do
    @window = Gtk::ApplicationWindow.new(app)
    @window.set_application(app)

    @window.title = "Multiple Views"
    @vpaned = Gtk::Paned.new(:vertical)

    @vbox = Gtk::Grid.new()
    @window.add(@vbox)

    Thread.new {
      GLib::Idle.add(proc { debug_idle_func })
    }

    reset_controllers

    @windows[1] = new_window(1)

    @last_adj_time = Time.now


    # To show keyboard key binding state
    @statnfo = Gtk::Label.new
    
    # To show e.g. current folder
    @subtitle = Gtk::Label.new("")
    
    @statbox = Gtk::Box.new(:horizontal, 2)
    @statnfo.set_size_request(150, 10)
    @statbox.append(@subtitle)
    @subtitle.hexpand = true
    @statbox.append(@statnfo)
    provider = Gtk::CssProvider.new
    @statnfo.add_css_class("statnfo")
    provider.load(data: "label.statnfo {   background-color:#353535; font-size: 10pt; margin-top:2px; margin-bottom:2px; align:right;}")

    provider = Gtk::CssProvider.new
    @statnfo.style_context.add_provider(provider)

    # numbers: left, top, width, height
    @vbox.attach(@windows[1][:overlay], 0, 2, 2, 1)

    # column, row, width height
    @vbox.attach(@statbox, 1, 1, 1, 1)

    init_minibuffer

    menubar = Gio::Menu.new
    app.menubar = menubar
    @window.show_menubar = true

    @menubar = menubar

    @active_window = @windows[1]

    @window.show

    run_as_idle proc { idle_set_size }

    prov = Gtk::CssProvider.new
    # See gtk-4.9.4/gtk/theme/Default/_common.scss  on how to theme
    # gtksourceview/gtksourcestyleschemepreview.c
    # gtksourceview/gtksourcestylescheme.c
    prov.load(data: " headerbar { padding: 0 0px; min-height: 16px; border-width: 0 0 0px; border-style: solid; }
    
    textview border.left gutter { color: #8aa; font-size:8pt; }     
    
    textview border.left gutter { padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; color: #8aa; font-size:9pt; }     
    
       headerbar .title {
    font-weight: bold;
    font-size: 11pt;
    color: #cdffee;
}

 headerbar > windowhandle > box .start {
    border-spacing: 6px;
}
 
 headerbar windowcontrols button {
      min-height: 15px;
      min-width: 15px;
    }

 popover background > contents { padding: 8px; border-radius: 20px; } 
       ")
    @window.style_context.add_provider(prov)

    sc = Gtk::StyleContext.add_provider_for_display(Gdk::Display.default, prov)

    vma.start
  end

  GLib::Idle.add(proc { self.monitor })

  app.run
end

#is_buffer_open(bufid) ⇒ Object



776
777
778
779
# File 'lib/vimamsa/gui.rb', line 776

def is_buffer_open(bufid)
  openbufids = @windows.keys.collect { |x| @windows[x][:sw].child.bufo.id }
  return openbufids.include?(bufid)
end

#monitorObject



662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/vimamsa/gui.rb', line 662

def monitor
  swa = @windows[1][:sw]
  @monitor_time ||= Time.now
  @sw_width ||= swa.width
  return true if Time.now - @monitor_time < 0.2
  # Detect element resize
  if swa.width != @sw_width
    # puts "@sw.width=#{@sw.width}"
    @sw_width = swa.width
    DelayExecutioner.exec(id: :scale_images, wait: 0.7, callable: proc { vma.gui.scale_all_images })
  end
  @monitor_time = Time.now
  return true
end

#new_scrolled_windowObject



882
883
884
885
886
887
888
889
890
891
# File 'lib/vimamsa/gui.rb', line 882

def new_scrolled_window
  sw = Gtk::ScrolledWindow.new
  sw.set_policy(:automatic, :automatic)
  @last_adj_time = Time.now
  sw.vadjustment.signal_connect("value-changed") { |x|
    @last_adj_time = Time.now
    debug "@sw.vadjustment #{x.value}", 2
  }
  return sw
end

#new_window(win_id) ⇒ Object



708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# File 'lib/vimamsa/gui.rb', line 708

def new_window(win_id)
  n_sw = Gtk::ScrolledWindow.new
  n_sw.set_policy(:automatic, :automatic)
  n_overlay = Gtk::Overlay.new
  n_overlay.add_overlay(n_sw)
  # @pane = Gtk::Paned.new(:horizontal)

  win = { :sw => n_sw, :overlay => n_overlay, :id => win_id }
  # @windows[2] = { :sw => @sw2, :overlay => @overlay2, :id => 2 }

  # @vbox.remove(@overlay)

  # @pane.set_start_child(@overlay2)
  # @pane.set_end_child(@overlay)

  # numbers: left, top, width, height
  # @vbox.attach(@pane, 0, 2, 2, 1)

  n_sw.vexpand = true
  n_sw.hexpand = true

  n_overlay.vexpand = true
  n_overlay.hexpand = true

  # TODO: remove??
  n_sw.vadjustment.signal_connect("value-changed") { |x|
 # pp x.page_increment
         # pp x.page_size
         # pp x.step_increment
         # pp x.upper
         # pp x.value
         # pp x
         # @last_adj_time = Time.now
    }

  # @sw2.show
  return win
end

#overlay_draw_text(text, textpos) ⇒ Object



268
269
270
271
272
273
274
275
# File 'lib/vimamsa/gui.rb', line 268

def overlay_draw_text(text, textpos)
  # debug "overlay_draw_text #{[x,y]}"
  (x, y) = @view.pos_to_coord(textpos)
  # debug "overlay_draw_text #{[x,y]}"
  label = Gtk::Label.new("<span background='#000000ff' foreground='#ff0000' weight='ultrabold'>#{text}</span>")
  label.use_markup = true
  @da.put(label, x, y)
end

#page_down(multip: 1.0) ⇒ Object



893
894
895
896
897
898
899
# File 'lib/vimamsa/gui.rb', line 893

def page_down(multip: 1.0)
  sw = @active_window[:sw]
  va = sw.vadjustment
  newval = va.value + va.page_increment * multip
  va.value = newval
  sw.child.set_cursor_to_top
end

#page_up(multip: 1.0) ⇒ Object



901
902
903
904
905
906
907
908
# File 'lib/vimamsa/gui.rb', line 901

def page_up(multip: 1.0)
  sw = @active_window[:sw]
  va = sw.vadjustment
  newval = va.value - va.page_increment * multip
  newval = 0 if newval < 0
  va.value = newval
  sw.child.set_cursor_to_top
end

#quitObject



215
216
217
218
219
220
221
222
223
224
# File 'lib/vimamsa/gui.rb', line 215

def quit
  @window.destroy
  @shutdown = true
  for t in Thread.list
    if t != Thread.current
      t.exit
    end
  end
  @app.quit
end

#remove_extra_controllersObject



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/vimamsa/gui.rb', line 515

def remove_extra_controllers
  clist = vma.gui.window.observe_controllers
  to_remove = []
  (0..(clist.n_items - 1)).each { |x|
    ctr = clist.get_item(x)
    if ctr.class == Gtk::EventControllerKey and ctr != @press
      to_remove << ctr
    end
  }
  if to_remove.size > 0
    # puts "Removing controllers:"
    # pp to_remove
    to_remove.each { |x| vma.gui.window.remove_controller(x) }
  end
end

#reset_controllersObject

Remove widget event controllers added by gtk, and add our own.



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/vimamsa/gui.rb', line 456

def reset_controllers
  clist = @window.observe_controllers
  to_remove = []
  (0..(clist.n_items - 1)).each { |x|
    ctr = clist.get_item(x)
    if ctr.class == Gtk::EventControllerKey
      to_remove << ctr
    end
  }
  if to_remove.size > 0
    # debug "Removing controllers:"
    # pp to_remove
    to_remove.each { |x| @window.remove_controller(x) }
  end

  press = Gtk::EventControllerKey.new
  @press = press
  # to prevent SourceView key handler capturing any keypresses
  press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
  @window.add_controller(press)

  press.signal_connect "key-pressed" do |gesture, keyval, keycode, y|
    name = Gdk::Keyval.to_name(keyval)
    uki = Gdk::Keyval.to_unicode(keyval)
    keystr = uki.chr("UTF-8")
    debug "key pressed #{keyval} #{keycode} name:#{name} str:#{keystr} unicode:#{uki}"
    buf.view.handle_key_event(keyval, keystr, :key_press)
    true
  end

  press.signal_connect "modifiers" do |eventctr, modtype|
    # eventctr: Gtk::EventControllerKey
    # modtype: Gdk::ModifierType
    debug "modifier change"
    vma.kbd.modifiers[:ctrl] = modtype.control_mask?
    vma.kbd.modifiers[:alt] = modtype.alt_mask?
    vma.kbd.modifiers[:hyper] = modtype.hyper_mask?
    vma.kbd.modifiers[:lock] = modtype.lock_mask?
    vma.kbd.modifiers[:meta] = modtype.meta_mask?
    vma.kbd.modifiers[:shift] = modtype.shift_mask?
    vma.kbd.modifiers[:super] = modtype.super_mask?

    #TODO:?
    # button1_mask?
    # ...
    # button5_mask?
    true # = handled, do not propagate further
  end

  press.signal_connect "key-released" do |gesture, keyval, keycode, y|
    name = Gdk::Keyval.to_name(keyval)
    uki = Gdk::Keyval.to_unicode(keyval)
    keystr = uki.chr("UTF-8")
    debug "key released #{keyval} #{keycode} name:#{name} str:#{keystr} unicode:#{uki}"
    buf.view.handle_key_event(keyval, keystr, :key_release)
    true # = handled, do not propagate further
  end
end

#runObject



210
211
212
213
# File 'lib/vimamsa/gui.rb', line 210

def run
  init_window
  # init_rtext
end

#run_after_scrolling(p) ⇒ Object

Run proc after animated scrolling has stopped (e.g. after page down)



282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/vimamsa/gui.rb', line 282

def run_after_scrolling(p)
  Thread.new {
    # After running
    #   view.signal_emit("move-cursor", Gtk::MovementStep.new(:PAGES)
    # have to wait for animated page down scrolling to actually start
    # Then have to wait determine that it has stopped if scrolling adjustment stops changing. There should be a better way to do this.
    sleep 0.1
    while Time.now - @last_adj_time < 0.1
      sleep 0.1
    end
    debug "SCROLLING ENDED", 2
    run_as_idle p
  }
end

#scale_all_imagesObject



226
227
228
229
230
231
232
233
234
235
236
# File 'lib/vimamsa/gui.rb', line 226

def scale_all_images
  for k, window in @windows
    bu = window[:sw].child.bufo
    for img in bu.images
      if !img[:obj].destroyed?
        img[:obj].scale_image
      end
    end
  end
  false
end

#set_active_window(id) ⇒ Object



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
# File 'lib/vimamsa/gui.rb', line 804

def set_active_window(id)
  return if !@two_column
  return if id == @active_column
  return if id == @active_window[:id]

  if @windows[id].nil?
    debug "No such window #{id}", 2
    return
  end

  @active_window = @windows[id]
  @active_column = id

  @active_window[:sw].child.focus_in()
  for k, w in @windows
    if w != @active_window
      fochild = w[:sw].child
      run_as_idle proc { fochild.focus_out() }
    end
  end

  vma.buffers.set_current_buffer_by_id(@active_window[:sw].child.bufo.id)
end

#set_buffer_to_window(bufid, winid) ⇒ Object



832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/vimamsa/gui.rb', line 832

def set_buffer_to_window(bufid, winid)
  view = @buffers[bufid]
  debug "vma.gui.set_buffer_to_window(#{bufid}), winid=#{winid}"
  buf1 = view.buffer

  @windows[winid][:sw].set_child(view)
  idle_ensure_cursor_drawn

  #TODO:???
  # @view = view
  # @buf1 = buf1
  # $view = view ???
  # $vbuf = buf1

end

#set_current_buffer(id) ⇒ Object



848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# File 'lib/vimamsa/gui.rb', line 848

def set_current_buffer(id)
  view2 = @buffers[id]
  debug "vma.gui.set_current_buffer(#{id}), view=#{view}"
  buf1 = view2.buffer
  @view = view2
  @buf1 = buf1
  $view = view
  $vbuf = buf1

  # Check if buffer is already open in another column
  if @two_column and @active_column == 2 and id == @windows[1][:sw].child.bufo.id
    toggle_active_window
  elsif @two_column && @active_column == 1 && !@windows[2][:sw].child.nil? && id == @windows[2][:sw].child.bufo.id
    #TODO: should not need [email protected]? here. If this happens then other column is empty.
    toggle_active_window
  else
    #TODO: improve
    swa = @active_window[:sw]
    ol = @active_window[:overlay]
    ol.remove_overlay(swa)
    swa.set_child(nil)
    # Creating a new ScrolledWindow every time to avoid a layout bug
    # https://gitlab.gnome.org/GNOME/gtk/-/issues/6189
    swb = new_scrolled_window
    swb.set_child(view2)
    ol.add_overlay(swb)
    @active_window[:view] = view
    @active_window[:sw] = swb
  end
  view.grab_focus

  idle_ensure_cursor_drawn
end

#set_current_view(view) ⇒ Object

Activate that window which has the given view



791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/vimamsa/gui.rb', line 791

def set_current_view(view)
  # Window of current view:
  w = @windows.find { |k, v| v[:sw].child == view }
  # All other windows:
  otherw = @windows.find_all { |k, v| v[:sw].child != view }
  if !w.nil?
    set_active_window(w[0])
    for k, x in otherw
      x[:sw].child.focus_out()
    end
  end
end

#set_one_columnObject



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/vimamsa/gui.rb', line 689

def set_one_column
  return if !@two_column
  #This always closes the leftmost column/window
  #TODO: close rightmost column if left active
  set_active_window(1)

  @windows[2][:sw].set_child(nil)
  @windows.delete(2)
  w1 = @windows[1]

  @pane.set_start_child(nil)
  @pane.set_end_child(nil)

  @vbox.remove(@pane)
  @vbox.attach(w1[:overlay], 0, 2, 2, 1)
  # @vbox.attach(@statbox, 1, 1, 1, 1)
  @two_column = false
end

#set_two_columnObject



747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/vimamsa/gui.rb', line 747

def set_two_column
  return if @two_column
  @windows[2] = new_window(2)

  w1 = @windows[1]
  w2 = @windows[2]

  # Remove overlay from @vbox and add the Gtk::Paned instead
  @pane = Gtk::Paned.new(:horizontal)
  @vbox.remove(w1[:overlay])
  @pane.set_start_child(w2[:overlay])
  @pane.set_end_child(w1[:overlay])

  # numbers: left, top, width, height
  @vbox.attach(@pane, 0, 2, 2, 1)

  w2[:sw].show
  @two_column = true

  last = vma.buffers.get_last_visited_id
  if !last.nil?
    set_buffer_to_window(last, 2)
  else
    # If there is only one buffer, create a new one and add to the new window/column
    bf = create_new_buffer "\n\n", "buff", false
    set_buffer_to_window(bf.id, 2)
  end
end

#start_overlay_drawObject



254
255
256
257
258
259
# File 'lib/vimamsa/gui.rb', line 254

def start_overlay_draw()
  @da = Gtk::Fixed.new
  @active_window[:overlay].add_overlay(@da)

  # @overlay.set_overlay_pass_through(@da, true) #TODO:gtk4
end

#toggle_active_windowObject



781
782
783
784
785
786
787
788
# File 'lib/vimamsa/gui.rb', line 781

def toggle_active_window()
  return if !@two_column
  if @active_column == 1
    set_active_window(2)
  else
    set_active_window(1)
  end
end

#toggle_two_columnObject



681
682
683
684
685
686
687
# File 'lib/vimamsa/gui.rb', line 681

def toggle_two_column
  if @two_column
    set_one_column
  else
    set_two_column
  end
end