<commit_before>var Path = nodeRequire('path');
var $ = require('jquery');
var _ = require('underscore');
var menubar = new gui.Menu({ type: 'menubar' });
menubar.createMacBuiltin("p5");
var fileMenu = new gui.Menu();
var help = new gui.Menu();
var win = gui.Window.get();
var recentFilesMenu = new gui.Menu();
var exampleCategoryMenu = new gui.Menu();
var openRecent, examples;
var fs = nodeRequire('fs');


module.exports.setup = function(app) {
  fileMenu.append(new gui.MenuItem({ label: 'New Project', modifiers: 'shift-cmd', key: 'n', click: function(){
    app.newWindow(app.windowURL);
  }}));
  
  fileMenu.append(new gui.MenuItem({ label: 'New File', modifiers: 'cmd', key: 'n', click: function(){
    app.newFile();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'New Folder', click: function(){
    app.newFolder();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Open', modifiers: 'cmd', key: 'o', click: function(){
    $('#openFile').trigger('click');
  }}));

  openRecent = new gui.MenuItem({label: 'Open Recent'});
  openRecent.submenu = recentFilesMenu;
  fileMenu.append(openRecent);

  fileMenu.append(new gui.MenuItem({ label: 'Close', modifiers: 'cmd', key: 'w', click: function(){
    app.closeProject();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save', modifiers: 'cmd', key: 's', click: function(){
    app.saveFile();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save File As...', modifiers: 'shift-cmd', key: 's', click: function(){
    app.saveFileAs(app.currentFile.path);
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save Project As...', modifiers: 'alt-shift-cmd', key: 's', click: function(){
    $('#saveProject').trigger('click');
    
  }}));

  makeExampleSubmenu();
  examples.submenu = exampleCategoryMenu;
  fileMenu.append(examples);

  fileMenu.append(new gui.MenuItem({ type: 'separator' }));

  //fileMenu.append(new gui.MenuItem({ label: 'Export \t\t\t\u2318E', click: function(){
    //app.export();
  //}}));

  fileMenu.append(new gui.MenuItem({ label: 'Run', modifiers: 'cmd', key: 'r', click: function(){
    app.run();
  }}));

  help.append(new gui.MenuItem({ label: 'Reference', click: function(){
    app.showHelp();
  }}));

  menubar.insert(new gui.MenuItem({ label: 'File', submenu: fileMenu}),1);
  menubar.append(new gui.MenuItem({ label: 'Help', submenu: help}));
  win.menu = menubar;

};

module.exports.resetMenu = function() {
  win.menu = menubar;
};

module.exports.updateRecentFiles = function(app, path) {
  var recentFiles = JSON.parse(localStorage.recentFiles || '[]');

  if (typeof path !== 'undefined' && !app.temp) {
    recentFiles.unshift(path);
  }

  recentFiles = _.unique(recentFiles);

  if (recentFiles.length > 10) recentFiles.pop();

  localStorage.recentFiles = JSON.stringify(recentFiles);

  // clear the recentFilesMenu because we're going to repopulate it
  recentFilesMenu = new gui.Menu();
  openRecent.submenu = recentFilesMenu;

  // iterate through the recentFiles and append to the openRecent submenu
  recentFiles.forEach(function(p) {
    var m = new gui.MenuItem({ label: Path.basename(p), click: function() {
      app.openProject(p);
    }});
    recentFilesMenu.append(m);
  });
  if (recentFiles.length > 0) {
    recentFilesMenu.append(new gui.MenuItem({type: 'separator'}));
    recentFilesMenu.append(new gui.MenuItem({label: 'Clear Recent Projects', click: function(){
      localStorage.recentFiles = [];
      module.exports.updateRecentFiles(app);
    }}));
  }

  openRecent.enabled = (recentFiles.length !== 0);
};


function makeExampleSubmenu() {
  // example sketches
  examples = new gui.MenuItem({label: 'Examples'});
  var files = fs.readdirSync('mode_assets/examples');
  files.forEach(function(category) {
    exampleCategoryMenu.append(new gui.MenuItem({label: category}));
  })
}<commit_msg>category labels have empty submenus<commit_after>var Path = nodeRequire('path');
var $ = require('jquery');
var _ = require('underscore');
var menubar = new gui.Menu({ type: 'menubar' });
menubar.createMacBuiltin("p5");
var fileMenu = new gui.Menu();
var help = new gui.Menu();
var win = gui.Window.get();
var recentFilesMenu = new gui.Menu();
var exampleCategoryMenu = new gui.Menu();
var openRecent, examples;
var fs = nodeRequire('fs');


module.exports.setup = function(app) {
  fileMenu.append(new gui.MenuItem({ label: 'New Project', modifiers: 'shift-cmd', key: 'n', click: function(){
    app.newWindow(app.windowURL);
  }}));
  
  fileMenu.append(new gui.MenuItem({ label: 'New File', modifiers: 'cmd', key: 'n', click: function(){
    app.newFile();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'New Folder', click: function(){
    app.newFolder();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Open', modifiers: 'cmd', key: 'o', click: function(){
    $('#openFile').trigger('click');
  }}));

  openRecent = new gui.MenuItem({label: 'Open Recent'});
  openRecent.submenu = recentFilesMenu;
  fileMenu.append(openRecent);

  fileMenu.append(new gui.MenuItem({ label: 'Close', modifiers: 'cmd', key: 'w', click: function(){
    app.closeProject();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save', modifiers: 'cmd', key: 's', click: function(){
    app.saveFile();
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save File As...', modifiers: 'shift-cmd', key: 's', click: function(){
    app.saveFileAs(app.currentFile.path);
  }}));

  fileMenu.append(new gui.MenuItem({ label: 'Save Project As...', modifiers: 'alt-shift-cmd', key: 's', click: function(){
    $('#saveProject').trigger('click');
    
  }}));

  // ??
  examples = new gui.MenuItem({label: 'Examples'});
  makeExampleSubmenu();
  examples.submenu = exampleCategoryMenu;
  fileMenu.append(examples);

  fileMenu.append(new gui.MenuItem({ type: 'separator' }));

  //fileMenu.append(new gui.MenuItem({ label: 'Export \t\t\t\u2318E', click: function(){
    //app.export();
  //}}));

  fileMenu.append(new gui.MenuItem({ label: 'Run', modifiers: 'cmd', key: 'r', click: function(){
    app.run();
  }}));

  help.append(new gui.MenuItem({ label: 'Reference', click: function(){
    app.showHelp();
  }}));

  menubar.insert(new gui.MenuItem({ label: 'File', submenu: fileMenu}),1);
  menubar.append(new gui.MenuItem({ label: 'Help', submenu: help}));
  win.menu = menubar;

};

module.exports.resetMenu = function() {
  win.menu = menubar;
};

module.exports.updateRecentFiles = function(app, path) {
  var recentFiles = JSON.parse(localStorage.recentFiles || '[]');

  if (typeof path !== 'undefined' && !app.temp) {
    recentFiles.unshift(path);
  }

  recentFiles = _.unique(recentFiles);

  if (recentFiles.length > 10) recentFiles.pop();

  localStorage.recentFiles = JSON.stringify(recentFiles);

  // clear the recentFilesMenu because we're going to repopulate it
  recentFilesMenu = new gui.Menu();
  openRecent.submenu = recentFilesMenu;

  // iterate through the recentFiles and append to the openRecent submenu
  recentFiles.forEach(function(p) {
    var m = new gui.MenuItem({ label: Path.basename(p), click: function() {
      app.openProject(p);
    }});
    recentFilesMenu.append(m);
  });
  if (recentFiles.length > 0) {
    recentFilesMenu.append(new gui.MenuItem({type: 'separator'}));
    recentFilesMenu.append(new gui.MenuItem({label: 'Clear Recent Projects', click: function(){
      localStorage.recentFiles = [];
      module.exports.updateRecentFiles(app);
    }}));
  }

  openRecent.enabled = (recentFiles.length !== 0);
};


function makeExampleSubmenu() {
  var exampleDir = 'mode_assets/examples';
  // example sketches
  var files = fs.readdirSync(exampleDir);
  files.forEach(function(category) {
    var sketchMenu = new gui.Menu();
    var categoryLabel = new gui.MenuItem({label: category});
    //...
    categoryLabel.submenu = sketchMenu;
    exampleCategoryMenu.append(categoryLabel);
    /*
    var sketches = fs.readdirSync(exampleDir.concat('/').concat(category));
    sketches.forEach(function(fileName) {
      console.log(fileName);
      // add option to submenu labeled with file name
      sketchMenu.append(new gui.MenuItem({label: fileName}));
    });
    */
  });
}
{'fraction_non_alphanumeric': 0.1804621591881648, 'fraction_numerical': 0.002445286709866732, 'mean_word_length': 4.308241401687216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3454324', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2629, 'n_words': 592}