Class: ArcadiaMainMenu

Inherits:
ArcadiaUserControl show all
Defined in:
lib/a-core.rb

Defined Under Namespace

Classes: UserItem

Constant Summary collapse

SUF =
'user_menu'

Instance Method Summary collapse

Methods inherited from ArcadiaUserControl

#items

Constructor Details

#initialize(menu) ⇒ ArcadiaMainMenu

Returns a new instance of ArcadiaMainMenu.



1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/a-core.rb', line 1428

def initialize(menu)
  # create main menu
  @menu = menu
  build
  begin
    @menu.configure(Arcadia.style('menu'))
  rescue RuntimeError => e
    #p "RuntimeError : #{e.message}"
    Arcadia.runtime_error(e)
  end
end

Instance Method Details

#buildObject



1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
# File 'lib/a-core.rb', line 1536

def build
  menu_spec_file = [
    ['File', 0],
    ['Open', proc{Arcadia.process_event(OpenBufferEvent.new(self,'file'=>Arcadia.open_file_dialog))}, 0],
    ['New', proc{Arcadia.process_event(NewBufferEvent.new(self))}, 0],
    #['Save', proc{EditorContract.instance.save_file_raised(self)},0],
    ['Save', proc{Arcadia.process_event(SaveBufferEvent.new(self))},0],
    ['Save as ...', proc{Arcadia.process_event(SaveAsBufferEvent.new(self))},0],
    '---',
    ['Quit', proc{Arcadia.process_event(QuitEvent.new(self))}, 0]]
    menu_spec_edit = [['Edit', 0],
    ['Cut', proc{Arcadia.process_event(CutTextEvent.new(self))}, 2],
    ['Copy', proc{Arcadia.process_event(CopyTextEvent.new(self))}, 0],
    ['Paste', proc{Arcadia.process_event(PasteTextEvent.new(self))}, 0],
    ['Undo', proc{Arcadia.process_event(UndoTextEvent.new(self))}, 0],
    ['Redo', proc{Arcadia.process_event(RedoTextEvent.new(self))}, 0],
    ['Select all', proc{Arcadia.process_event(SelectAllTextEvent.new(self))}, 0],
    ['Invert selection', proc{Arcadia.process_event(InvertSelectionTextEvent.new(self))}, 0],
    ['Uppercase', proc{Arcadia.process_event(UpperCaseTextEvent.new(self))}, 0],
    ['Lowercase', proc{Arcadia.process_event(LowerCaseTextEvent.new(self))}, 0],
    ['Prettify Current', proc{Arcadia.process_event(PrettifyTextEvent.new(self))}, 0]]
    
    menu_spec_search = [['Search', 0],
    ['Find/Replace ...', proc{Arcadia.process_event(SearchBufferEvent.new(self))}, 2],
    ['Find in files...', proc{Arcadia.process_event(SearchInFilesEvent.new(self))}, 2],
    ['Ack in files...', proc{Arcadia.process_event(AckInFilesEvent.new(self))}, 2],
    ['Go to line ...', proc{Arcadia.process_event(GoToLineBufferEvent.new(self))}, 2]]
    menu_spec_view = [['View', 0],['Show/Hide Toolbar', proc{$arcadia.show_hide_toolbar}, 2],
    ['Close current tab', proc{Arcadia.process_event(CloseCurrentTabEvent.new(self))}, 0],
    ]
    menu_spec_tools = [['Tools', 0],
    ['Keys-test', $arcadia['action.test.keys'], 2],
    ['Edit prefs', proc{Arcadia.process_event(OpenBufferEvent.new(self,'file'=>$arcadia.local_file_config))}, 0],
    ['Load from edited prefs', proc{$arcadia.load_local_config}, 0]
  ]
  menu_spec_help = [['Help', 0],
  ['About', $arcadia['action.show_about'], 2],]
  begin
    @menu.add_menu(menu_spec_file)
    @menu.add_menu(menu_spec_edit)
    @menu.add_menu(menu_spec_search)
    @menu.add_menu(menu_spec_view)
    @menu.add_menu(menu_spec_tools)
    @menu.add_menu(menu_spec_help)
  rescue RuntimeError => e
    #p "RuntimeError : #{e.message}"
    Arcadia.runtime_error(e)
  end
#    #@menu.bind_append("1", proc{
#      chs = TkWinfo.children(@menu)
#      hh = 25
#      @last_post = nil
#      chs.each{|ch|
#        ch.bind_append("Enter", proc{|x,y,rx,ry|
#          @last_post.unpost if @last_post && @last_post != ch.menu
#          ch.menu.post(x-rx,y-ry+hh)
#          @last_post=ch.menu}, "%X %Y %x %y")
#        ch.bind_append("Leave", proc{
#          @last_post.unpost if @last_post
#          @last_post=nil
#        })
#      }
#
#    #})

#      @menu.bind_append("Leave", proc{
#        if Tk.focus != @last_menu_posted 
#          @last_post.unpost if @last_post
#          @last_post=nil
#        end
#      })
#      


#      chs = TkWinfo.children(@menu)
#      hh = 25
#      @last_post = nil
#      chs.each{|ch|
#        ch.bind_append("Enter", proc{|x,y,rx,ry|
#          @last_post.unpost if @last_post && @last_post != ch.menu
#          ch.menu.post(x-rx,y-ry+hh)
#          chmenus = TkWinfo.children(ch)
#          @last_menu_posted = chmenus[0]
#          @last_menu_posted.set_focus
#          #@last_post=ch.menu
#          }, "%X %Y %x %y")
#        ch.bind_append("Leave", proc{
#          @last_post.unpost if @last_post
#          #@last_post=nil
#          @last_post=ch.menu
#        })
#      }
#      @menu.bind_append("Leave", proc{
#        if Tk.focus != @last_menu_posted 
#          @last_post.unpost if @last_post
#          @last_post=nil
#        end
#      })

   @menu.extend(TkAutoPostMenu)      
   @menu.event_posting_on
end

#get_menu_context(_menubar, _context, _underline = nil) ⇒ Object



1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
# File 'lib/a-core.rb', line 1440

def get_menu_context(_menubar, _context, _underline=nil)
  menubuttons =  _menubar[0..-1]
  # cerchiamo il context
  m_i = -1
  menubuttons.each_with_index{|mb, i|
    _t = mb[0].cget('text')
    if _t==_context
      m_i = i 
      break
    end
  }
  if m_i > -1
    _menubar[m_i][1]
  else
    _menubar.add_menu([[_context,_underline],[]])[1].delete(0)
  end
end

#get_sub_menu(menu_context, folder = nil) ⇒ Object



1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
# File 'lib/a-core.rb', line 1458

def get_sub_menu(menu_context, folder=nil)
  if folder
    s_i = -1 
    i_end = menu_context.index('end')
    if i_end
      0.upto(i_end){|j|
        type = menu_context.menutype(j)
        if type != 'separator'
          l = menu_context.entrycget(j,'label')
          if l == folder && type == 'cascade'
           s_i = j
           break
          end
        end
      }
    end
  end
  if s_i > -1 #&& menu_context.menutype(s_i) == 'cascade'
    sub = menu_context.entrycget(s_i, 'menu')
  else
    sub = TkMenu.new(
      :parent=>@pop_up,
      :tearoff=>0
    )
    sub.configure(Arcadia.style('menu'))
    sub.extend(TkAutoPostMenu)
    #update_style(sub)
    menu_context.insert('end',
      :cascade,
      :label=>folder,
      :menu=>sub,
      :hidemargin => false
    )
  end
  sub
end

#make_menu(_menu, context_path, context_underline = nil) ⇒ Object



1500
1501
1502
1503
1504
1505
1506
1507
# File 'lib/a-core.rb', line 1500

def make_menu(_menu, context_path, context_underline=nil)
  folders = context_path.split('/')
  sub = _menu
  folders.each{|folder|
    sub = get_sub_menu(sub, folder)
  }
  sub
end

#make_menu_in_menubar(_menubar, _context, context_path, context_underline = nil) ⇒ Object



1495
1496
1497
1498
# File 'lib/a-core.rb', line 1495

def make_menu_in_menubar(_menubar, _context, context_path, context_underline=nil)
  context_menu = get_menu_context(_menubar, _context, context_underline)
  make_menu(context_menu, context_path, context_underline)
end

#new_item(_sender, _args = nil) ⇒ Object



1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
# File 'lib/a-core.rb', line 1509

def new_item(_sender, _args= nil)
  return if _args.nil?
  if _args['context_caption']
    conte = _args['context_caption']
  else
    conte = _args['context']
  end
  if _args['rif'] == 'main'
    _args['menu']=make_menu_in_menubar(@menu, conte, _args['context_path'], _args['context_underline'])
  else
    if Arcadia.menu_root(_args['rif'])
      _args['menu']=make_menu(Arcadia.menu_root(_args['rif']), _args['context_path'], _args['context_underline'])
    else
      msg = "During building of menu item \"#{_args['name']}\" rif \"#{_args['rif']}\" not found!"
      Arcadia.dialog(self, 
          'type'=>'ok', 
          'title' => "(Arcadia) #{self.class::SUF}", 
          'msg'=>msg,
          'level'=>'error')

      _args['menu']=make_menu_in_menubar(@menu, conte, _args['context_path'], _args['context_underline'])
    end
  end
  super(_sender, _args)
end