Class: VMAgui

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVMAgui

Returns a new instance of VMAgui.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/vimamsa/gui.rb', line 170

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
  # imgproc = proc {
  # GLib::Idle.add(proc {
  # if !buf.images.empty?
  # vma.gui.scale_all_images

  # w = Gtk::Window.new(:toplevel)
  # w.set_default_size(1, 1)
  # w.show_all
  # Thread.new { sleep 0.1; w.destroy }
  # end

  # false
  # })
  # }
  # @delex = DelayExecutioner.new(1, imgproc)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



168
169
170
# File 'lib/vimamsa/gui.rb', line 168

def app
  @app
end

#buf1Object

Returns the value of attribute buf1.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def buf1
  @buf1
end

#buffersObject

Returns the value of attribute buffers.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def buffers
  @buffers
end

#delexObject

Returns the value of attribute delex.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def delex
  @delex
end

#overlayObject

Returns the value of attribute overlay.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def overlay
  @overlay
end

#overlay1Object

Returns the value of attribute overlay1.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def overlay1
  @overlay1
end

#overlay2Object

Returns the value of attribute overlay2.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def overlay2
  @overlay2
end

#statnfoObject

Returns the value of attribute statnfo.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def statnfo
  @statnfo
end

#subtitleObject (readonly)

Returns the value of attribute subtitle.



168
169
170
# File 'lib/vimamsa/gui.rb', line 168

def subtitle
  @subtitle
end

#swObject

Returns the value of attribute sw.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def sw
  @sw
end

#sw1Object

Returns the value of attribute sw1.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def sw1
  @sw1
end

#sw2Object

Returns the value of attribute sw2.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def sw2
  @sw2
end

#swsObject

Returns the value of attribute sws.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def sws
  @sws
end

#two_cObject

Returns the value of attribute two_c.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def two_c
  @two_c
end

#two_columnObject (readonly)

Returns the value of attribute two_column.



168
169
170
# File 'lib/vimamsa/gui.rb', line 168

def two_column
  @two_column
end

#viewObject

Returns the value of attribute view.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def view
  @view
end

#windowObject

Returns the value of attribute window.



167
168
169
# File 'lib/vimamsa/gui.rb', line 167

def window
  @window
end

#windowsObject (readonly)

Returns the value of attribute windows.



168
169
170
# File 'lib/vimamsa/gui.rb', line 168

def windows
  @windows
end

Instance Method Details

#add_to_minibuf(msg) ⇒ Object



345
346
347
348
349
350
# File 'lib/vimamsa/gui.rb', line 345

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



252
253
254
255
256
257
# File 'lib/vimamsa/gui.rb', line 252

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

#current_viewObject



832
833
834
# File 'lib/vimamsa/gui.rb', line 832

def current_view
  return @sw.child
end

#debug_idle_funcObject



467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/vimamsa/gui.rb', line 467

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("~/.vimamsa/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

#delay_scaleObject



214
215
216
217
# File 'lib/vimamsa/gui.rb', line 214

def delay_scale()
  if Time.now - @dtime > 2.0
  end
end

#end_overlay_drawObject



268
269
270
# File 'lib/vimamsa/gui.rb', line 268

def end_overlay_draw()
  @da.show
end

#ensure_cursor_drawnObject



882
883
884
885
# File 'lib/vimamsa/gui.rb', line 882

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

#handle_deltasObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/vimamsa/gui.rb', line 327

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



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/vimamsa/gui.rb', line 229

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



878
879
880
# File 'lib/vimamsa/gui.rb', line 878

def idle_ensure_cursor_drawn
  run_as_idle proc { self.ensure_cursor_drawn }
end

#idle_set_sizeObject



565
566
567
568
569
570
571
572
573
574
# File 'lib/vimamsa/gui.rb', line 565

def idle_set_size()
  # Need to wait for a while to window to be maximized to get correct @window.width
  sleep 0.1
  width = @window.width / 2
  height = @window.height - 5
  # Ripl.start :binding => binding
  @window.unmaximize
  @window.set_size_request(width, height)
  return false
end

#init_header_barObject



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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/vimamsa/gui.rb', line 382

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.pack_end(button)

  button = Gtk::Button.new
  icon = Gio::ThemedIcon.new("document-open-symbolic")
  image = Gtk::Image.new(:icon => icon, :size => :button)
  button.add(image)
  header.pack_end(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.pack_end(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.pack_end(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
  # @window.add(Gtk::TextView.new)
end

#init_menuObject



743
744
745
# File 'lib/vimamsa/gui.rb', line 743

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

#init_minibufferObject



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
# File 'lib/vimamsa/gui.rb', line 352

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)
  $sw2 = sw
  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



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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
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
# File 'lib/vimamsa/gui.rb', line 576

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"

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

    @window.maximize
    # Need to let Gtk process after maximize
    run_as_idle proc { idle_set_size }

    @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

    @sw = Gtk::ScrolledWindow.new
    @sw.set_policy(:automatic, :automatic)


    @last_adj_time = Time.now
    @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
      # puts "@sw.vadjustment"
    }

    # @sw.signal_connect("clicked") { puts "Hello World!" }
    # @sw.signal_connect("key-pressed") { puts "Hello World!" }
    @overlay = Gtk::Overlay.new
    # @overlay.add(@sw) #TODO:gtk4
    @overlay.add_overlay(@sw) #TODO:gtk4
    @overlay1 = @overlay

    # init_header_bar #TODO:gtk4

    @statnfo = Gtk::Label.new
    @subtitle = Gtk::Label.new("")
    @statbox = Gtk::Box.new(:horizontal, 2)
    @statnfo.set_size_request(150, 10)
    @statbox.pack_end(@subtitle, :expand => true, :fill => true, :padding => 0)
    @statbox.pack_end(@statnfo, :expand => false, :fill => false, :padding => 0)
    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(@overlay, 0, 2, 2, 1)
    @sw.vexpand = true
    @sw.hexpand = true

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

    @overlay.vexpand = true
    @overlay.hexpand = true

    init_minibuffer

    # p = Gtk::Popover.new

    name = "save"
    window = @window
    action = Gio::SimpleAction.new(name)
    action.signal_connect "activate" do |_simple_action, _parameter|
      dialog = Gtk::MessageDialog.new(:parent => window,
                                      :flags => :destroy_with_parent,
                                      :buttons => :close,
                                      :message => "Action FOOBAR activated.")
      dialog.signal_connect(:response) do
        dialog.destroy
      end
      dialog.show
    end

    @window.add_action(action)
    doc_actions = Gio::SimpleActionGroup.new
    doc_actions.add_action(action)

    act_quit = Gio::SimpleAction.new("quit")
    app.add_action(act_quit)
    act_quit.signal_connect "activate" do |_simple_action, _parameter|
      window.destroy
      exit!
    end

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

    @menubar = menubar

    @windows[1] = { :sw => @sw, :overlay => @overlay, :id => 1 }
    @active_window = @windows[1]

    @window.show

    press = Gtk::GestureClick.new
    press.button = Gdk::BUTTON_SECONDARY
    @window.add_controller(press)
    press.signal_connect "pressed" do |gesture, n_press, x, y|
      puts "FOOBARpressed"
      # clear_surface(surface)
      # drawing_area.queue_draw
    end
    @sw1 = @sw

    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;
    }

       ")
    @window.style_context.add_provider(prov)

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

    vma.start
  end

  # Vimamsa::Menu.new(@menubar) #TODO:gtk4
  app.run

  # @window.show_all
  # @window.show
end

#is_buffer_open(bufid) ⇒ Object



788
789
790
791
# File 'lib/vimamsa/gui.rb', line 788

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

#overlay_draw_cursor(textpos) ⇒ Object



279
280
281
282
283
284
# File 'lib/vimamsa/gui.rb', line 279

def overlay_draw_cursor(textpos)
  # return
  remove_overlay_cursor
  GLib::Idle.add(proc { self.overlay_draw_cursor_(textpos) })
  # overlay_draw_cursor_(textpos)
end

#overlay_draw_cursor_(textpos) ⇒ Object

To draw on empty lines and line-ends (where select_range doesn’t work)



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/vimamsa/gui.rb', line 303

def overlay_draw_cursor_(textpos)
  # Thread.new {
  # GLib::Idle.add(proc { p.call; false })
  # }

  # while Time.now - @last_adj_time < 0.3
  # return true
  # end

  remove_overlay_cursor
  @cursorov = Gtk::Fixed.new
  @overlay.add_overlay(@cursorov)

  (x, y) = @view.pos_to_coord(textpos)
  pp [x, y]

  # Trying to draw only background of character "I"
  label = Gtk::Label.new("<span background='#00ffaaff' foreground='#00ffaaff' weight='ultrabold'>I</span>")
  label.use_markup = true
  @cursorov.put(label, x, y)
  @cursorov.show
  return false
end

#overlay_draw_text(text, textpos) ⇒ Object



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

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

#quitObject



204
205
206
207
208
209
210
211
212
# File 'lib/vimamsa/gui.rb', line 204

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

#remove_extra_controllersObject



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/vimamsa/gui.rb', line 549

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

#remove_overlay_cursorObject



272
273
274
275
276
277
# File 'lib/vimamsa/gui.rb', line 272

def remove_overlay_cursor()
  if !@cursorov.nil?
    @overlay.remove_overlay(@cursorov)
    @cursorov = nil
  end
end

#reset_controllersObject

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



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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/vimamsa/gui.rb', line 487

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
    puts "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")
    puts "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
  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")
    puts "key released #{keyval} #{keycode} name:#{name} str:#{keystr} unicode:#{uki}"
    buf.view.handle_key_event(keyval, keystr, :key_release)
    # vma.kbd.match_key_conf(keystr, nil, :key_press)
    # buf.view.handle_deltas
    # buf.view.handle_key_event(keyval, keystr, :key_press)
    true
  end
end

#runObject



199
200
201
202
# File 'lib/vimamsa/gui.rb', line 199

def run
  init_window
  # init_rtext
end

#run_after_scrolling(p) ⇒ Object

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



287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/vimamsa/gui.rb', line 287

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



219
220
221
222
223
224
225
226
227
# File 'lib/vimamsa/gui.rb', line 219

def scale_all_images
  debug "scale all", 2
  for img in buf.images
    if !img[:obj].destroyed?
      img[:obj].scale_image
    end
  end
  false
end

#set_active_window(id) ⇒ Object



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# File 'lib/vimamsa/gui.rb', line 810

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 #TODO: remove

  @sw = @windows[id][:sw]
  @overlay = @windows[id][:overlay]

  vma.buffers.set_current_buffer_by_id(@sw.child.bufo.id)

  #TODO: set buf & view of active window??

end

#set_buffer_to_window(bufid, winid) ⇒ Object



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/vimamsa/gui.rb', line 836

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

  # @overlay = Gtk::Overlay.new
  # @overlay.add_overlay(view)

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

end

#set_current_buffer(id) ⇒ Object



855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/vimamsa/gui.rb', line 855

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

  # Check if buffer is already open in another column
  if @two_column and @active_column == 2 and id == @sw1.child.bufo.id
    toggle_active_window
  elsif @two_column && @active_column == 1 && !@sw2.child.nil? && id == @sw2.child.bufo.id
    #TODO: should not need [email protected]? here. If this happens then other column is empty.
    toggle_active_window
  else
    @sw.set_child(view)
  end
  view.grab_focus

  idle_ensure_cursor_drawn
end

#set_current_view(view) ⇒ Object

activate that window which has the given view



803
804
805
806
807
808
# File 'lib/vimamsa/gui.rb', line 803

def set_current_view(view)
  w = @windows.find { |k, v| v[:sw].child == view }
  if !w.nil?
    set_active_window(w[0])
  end
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
775
776
777
778
779
780
781
782
783
784
785
786
# File 'lib/vimamsa/gui.rb', line 747

def set_two_column
  return if @two_column
  # @window.set_default_size(800, 600) #TODO:gtk4
  # @vpaned = Gtk::Paned.new(:vertical)
  # @vbox = Gtk::Grid.new()
  # @window.add(@vbox)

  @sw2 = Gtk::ScrolledWindow.new
  @sw2.set_policy(:automatic, :automatic)
  @overlay2 = Gtk::Overlay.new
  @overlay2.add_overlay(@sw2)
  @pane = Gtk::Paned.new(:horizontal)

  @windows[2] = { :sw => @sw2, :overlay => @overlay2, :id => 2 }

  @vbox.remove(@overlay)

  # numbers: left, top, width, height
  @pane.set_start_child(@overlay2)
  @pane.set_end_child(@overlay)

  @vbox.attach(@pane, 0, 2, 2, 1)

  @sw2.vexpand = true
  @sw2.hexpand = true

  @overlay2.vexpand = true
  @overlay2.hexpand = true

  @sw2.show
  @two_column = true

  if vma.buffers.size > 1
    last = vma.buffers.get_last_visited_id
    set_buffer_to_window(last, 2)
  else
    bf = create_new_buffer "\n\n", "buff", false
    set_buffer_to_window(bf.id, 2)
  end
end

#start_overlay_drawObject



245
246
247
248
249
250
# File 'lib/vimamsa/gui.rb', line 245

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

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

#toggle_active_windowObject



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

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