<commit_before>#include "../include/dialogs/MenuBar.h"

void MenuBar::buildMenu(void) {
	
	this->add("File", 0, 0, 0, FL_SUBMENU);
		this->add("File/New...", FL_CTRL + 'n', this->new_world, this);
		this->add("File/Open...", FL_CTRL + 'o', this->open_world, this);
		this->add("File/Save", FL_CTRL + 's', this->save_world, this);
		this->add("File/Save As...", 0, this->save_world_as, this);
		this->add("File/Save Selection...", 0, this->save_selection, this, FL_MENU_DIVIDER);
		this->add("File/Exit", 0, this->exit_bzwb, this);
	
	this->add("Edit", 0, 0, 0, FL_SUBMENU);
		this->add("Edit/Undo", FL_CTRL + 'z', this->undo, this);
		this->add("Edit/Redo", FL_CTRL + 'y', this->redo, this, FL_MENU_DIVIDER);
		this->add("Edit/Cut", FL_CTRL + 'x', this->cut, this);
		this->add("Edit/Copy", FL_CTRL + 'c', this->copy, this);
		this->add("Edit/Paste", FL_CTRL + 'v', this->paste, this);
		this->add("Edit/Paste Saved Selection...", 0, this->paste_saved_selection, this, FL_MENU_DIVIDER);
		this->add("Edit/Select All", FL_CTRL + 'a', this->select_all, this);
		this->add("Edit/Unselect All", FL_CTRL + FL_ALT + 'a', this->unselect_all, this);
}

// constructor
MenuBar::MenuBar( MainWindow* mw ) : Fl_Menu_Bar(0, 0, mw->w(), 30) {
	this->parent = mw;
	
	this->buildMenu();	
}

void MenuBar::new_world_real( Fl_Widget* w ) {
	
}

void MenuBar::open_world_real( Fl_Widget* w ) {
	Fl_File_Chooser* fc = new Fl_File_Chooser("share/", "*.bzw", Fl_File_Chooser::SINGLE, "Open..." );
	fc->value("*.bzw");
	fc->show();
	
	// wait for a value
	while( fc->shown() ) { Fl::wait(); }
	
	// get a value (the selected filename )
	if(fc->value() == NULL)
		return;
	
	string filename = fc->value();
	
	printf("file: %s\n", filename.c_str());
	
	// invoke BZWParser and load it
	vector<string> world = BZWParser::loadFile( filename.c_str() );
	
	// invoke the Model to build the world
	this->parent->getModel()->_build( world );
}

void MenuBar::save_world_real( Fl_Widget* w ) {
	// do a "save as..." if the world is yet unnamed
	if( this->parent->getWorldName().size() <= 0 ) {
		this->save_world_as_real( w );
		return;
	}
	
	// save the world
	string path = this->parent->getWorldName();
	
	// do a world save
	this->do_world_save( path.c_str() );
}

void MenuBar::save_world_as_real( Fl_Widget* w ) {
	Fl_File_Chooser* fc = new Fl_File_Chooser("share/", "*.bzw", Fl_File_Chooser::CREATE, "Save As..." );
	fc->show();
	
	// wait for a value
	while( fc->shown() ) { Fl::wait(); }
	
	// get a value (the file path)
	string filename = fc->value();
	
	// set the world name<commit_msg>Fixed std::runtime exception caused by clicking "cancel" from the "Save As..." dialog<commit_after>#include "../include/dialogs/MenuBar.h"

void MenuBar::buildMenu(void) {
	
	this->add("File", 0, 0, 0, FL_SUBMENU);
		this->add("File/New...", FL_CTRL + 'n', this->new_world, this);
		this->add("File/Open...", FL_CTRL + 'o', this->open_world, this);
		this->add("File/Save", FL_CTRL + 's', this->save_world, this);
		this->add("File/Save As...", 0, this->save_world_as, this);
		this->add("File/Save Selection...", 0, this->save_selection, this, FL_MENU_DIVIDER);
		this->add("File/Exit", 0, this->exit_bzwb, this);
	
	this->add("Edit", 0, 0, 0, FL_SUBMENU);
		this->add("Edit/Undo", FL_CTRL + 'z', this->undo, this);
		this->add("Edit/Redo", FL_CTRL + 'y', this->redo, this, FL_MENU_DIVIDER);
		this->add("Edit/Cut", FL_CTRL + 'x', this->cut, this);
		this->add("Edit/Copy", FL_CTRL + 'c', this->copy, this);
		this->add("Edit/Paste", FL_CTRL + 'v', this->paste, this);
		this->add("Edit/Paste Saved Selection...", 0, this->paste_saved_selection, this, FL_MENU_DIVIDER);
		this->add("Edit/Select All", FL_CTRL + 'a', this->select_all, this);
		this->add("Edit/Unselect All", FL_CTRL + FL_ALT + 'a', this->unselect_all, this);
}

// constructor
MenuBar::MenuBar( MainWindow* mw ) : Fl_Menu_Bar(0, 0, mw->w(), 30) {
	this->parent = mw;
	
	this->buildMenu();	
}

void MenuBar::new_world_real( Fl_Widget* w ) {
	
}

void MenuBar::open_world_real( Fl_Widget* w ) {
	Fl_File_Chooser* fc = new Fl_File_Chooser("share/", "*.bzw", Fl_File_Chooser::SINGLE, "Open..." );
	fc->value("*.bzw");
	fc->show();
	
	// wait for a value
	while( fc->shown() ) { Fl::wait(); }
	
	// get a value (the selected filename )
	if(fc->value() == NULL)
		return;
	
	string filename = fc->value();
	
	printf("file: %s\n", filename.c_str());
	
	// invoke BZWParser and load it
	vector<string> world = BZWParser::loadFile( filename.c_str() );
	
	// invoke the Model to build the world
	this->parent->getModel()->_build( world );
}

void MenuBar::save_world_real( Fl_Widget* w ) {
	// do a "save as..." if the world is yet unnamed
	if( this->parent->getWorldName().size() <= 0 ) {
		this->save_world_as_real( w );
		return;
	}
	
	// save the world
	string path = this->parent->getWorldName();
	
	// do a world save
	this->do_world_save( path.c_str() );
}

void MenuBar::save_world_as_real( Fl_Widget* w ) {
	Fl_File_Chooser* fc = new Fl_File_Chooser("share/", "*.bzw", Fl_File_Chooser::CREATE, "Save As..." );
	fc->show();
	
	// wait for a value
	while( fc->shown() ) { Fl::wait(); }
	
	if(fc->value() == NULL)
		return;
	
	// get a value (the file path)
	string filename = fc->value();
	
	// set the world name
{'fraction_non_alphanumeric': 0.20781696854146806, 'fraction_numerical': 0.005719733079122974, 'mean_word_length': 3.9819563152896484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 106, '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': '6675534', 'n_tokens_mistral': 2146, 'n_tokens_neox': 1992, 'n_words': 459}