<commit_before>#include "ofxSourcesEditor.h"

ofxSourcesEditor::ofxSourcesEditor()
{
    defImgDir = DEFAULT_IMAGES_DIR;
    registerAppEvents();
}

ofxSourcesEditor::~ofxSourcesEditor()
{
    unregisterAppEvents();
    delete gui;
    while ( images.size() ) {
        delete images.back();
        images.pop_back();
    }
}

void ofxSourcesEditor::registerAppEvents()
{
    ofAddListener(ofEvents().setup, this, &ofxSourcesEditor::setup);
}

void ofxSourcesEditor::unregisterAppEvents()
{
    ofRemoveListener(ofEvents().setup, this, &ofxSourcesEditor::setup);
}

void ofxSourcesEditor::setup(ofEventArgs& args)
{
    gui = new ofxRadioList();
    
    // read directory contents
    ofDirectory imgDir;
    imgDir.listDir(defImgDir);
    imgDir.sort();
    
    vector<string> vnames;
    
    for(int i = 0; i < (int)imgDir.size(); i++){
		//images[i].loadImage(imgDir.getPath(i));
        vnames.push_back(imgDir.getName(i));
	}
    
    gui->setup("Images", vnames);
    ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent);
    
    
    //gui->addLabel(defImgDir, OFX_UI_FONT_SMALL);
    //ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL);
    //radio->activateToggle("image0.png");
    
    //ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent);
}

void ofxSourcesEditor::draw()
{
    gui->draw();
}

void ofxSourcesEditor::loadImage( string name, string path )
{
    images.push_back(new ofImage());
    images.back()->loadImage(path);
    
    imageNames.push_back(name);
    
    ofSendMessage("imageLoaded");
}

void ofxSourcesEditor::disable()
{
    gui->disable();
}

void ofxSourcesEditor::enable()
{<commit_msg>Not showing source list if there is no surface selected<commit_after>#include "ofxSourcesEditor.h"

ofxSourcesEditor::ofxSourcesEditor()
{
    defImgDir = DEFAULT_IMAGES_DIR;
    registerAppEvents();
}

ofxSourcesEditor::~ofxSourcesEditor()
{
    unregisterAppEvents();
    delete gui;
    while ( images.size() ) {
        delete images.back();
        images.pop_back();
    }
}

void ofxSourcesEditor::registerAppEvents()
{
    ofAddListener(ofEvents().setup, this, &ofxSourcesEditor::setup);
}

void ofxSourcesEditor::unregisterAppEvents()
{
    ofRemoveListener(ofEvents().setup, this, &ofxSourcesEditor::setup);
}

void ofxSourcesEditor::setup(ofEventArgs& args)
{
    gui = new ofxRadioList();
    
    // read directory contents
    ofDirectory imgDir;
    imgDir.listDir(defImgDir);
    imgDir.sort();
    
    vector<string> vnames;
    
    for(int i = 0; i < (int)imgDir.size(); i++){
		//images[i].loadImage(imgDir.getPath(i));
        vnames.push_back(imgDir.getName(i));
	}
    
    gui->setup("Images", vnames);
    ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent);
}

void ofxSourcesEditor::draw()
{
    // Don't draw if there is no source selected
    if ( surfaceManager->getSelectedSurface() == NULL ) {
        return;
    }
    
    gui->draw();
}

void ofxSourcesEditor::loadImage( string name, string path )
{
    images.push_back(new ofImage());
    images.back()->loadImage(path);
    
    imageNames.push_back(name);
    
    ofSendMessage("imageLoaded");
}

void ofxSourcesEditor::disable()
{
    gui->disable();
}

void ofxSourcesEditor::enable()
{
    // Don't enable if there is no surface selected
    if ( surfaceManager->getSelectedSurface() == NULL ) {
        cout << "No surface selected. Not enable()ing source list." << endl;
        return;
    }
    
{'fraction_non_alphanumeric': 0.14354884648248362, 'fraction_numerical': 0.000854457419538593, 'mean_word_length': 3.739541160593792, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '6854045', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1151, 'n_words': 195}