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.



1243
1244
1245
1246
1247
1248
# File 'lib/a-core.rb', line 1243

def initialize(menu)
  # create main menu
  @menu = menu
  build
  @menu.configure(Arcadia.style('menu'))
end

Instance Method Details

#buildObject



1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
# File 'lib/a-core.rb', line 1346

def build
  menu_spec_file = [
    ['File', 0],
    ['Open', proc{Arcadia.process_event(OpenBufferEvent.new(self,'file'=>Arcadia.open_file_dialog))}, 0],
    ['New', $arcadia['main.action.new_file'], 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', $arcadia['action.on_exit'], 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],]
  @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)

#    #@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



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/a-core.rb', line 1250

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



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
# File 'lib/a-core.rb', line 1268

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



1310
1311
1312
1313
1314
1315
1316
1317
# File 'lib/a-core.rb', line 1310

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



1305
1306
1307
1308
# File 'lib/a-core.rb', line 1305

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



1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
# File 'lib/a-core.rb', line 1319

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