# data file for the Fltk User Interface Designer (fluid)
version 1.0110 
header_name {.h} 
code_name {.cc}
decl {\#include <FL/fl_ask.H>} {selected public
} 

decl {\#include <cstdio>} {public
} 

decl {\#include <cstdlib>} {public
} 

decl {\#include <string>} {public
} 

decl {\#include "Osc_ListModel.h"} {public
} 

decl {\#include "Osc_DataModel.h"} {public
} 

class PresetsUI_ {} {
    Function {refresh()} {open return_type {virtual void}
    } {
        code {;} {}
    }
    Function {~PresetsUI_()} {open return_type virtual
    } {
        code {;} {}
    }
} 

class PresetsUI {} {
    Function {PresetsUI(Fl_Osc_Interface *osc_):listmodel(osc_), datamodel(osc_)} {} {
        code {osc = osc_;
            arraymode = false;
            make_window();
            listmodel.callback = [this](Osc_ListModel::list_t list) {
                copybrowse->clear();
                pastebrowse->clear();
                files.clear();
                printf("adding entries<%s>...\\n", datamodel.value.c_str());
                if(datamodel.value.empty())
                    return; 
                for(unsigned i=0;i<list.size();++i){
                    std::string type = std::get<2>(list[i]);
                    std::string comp = datamodel.value.substr(1);
                    if(arraymode)
                        comp += "n";
                    bool same = comp == type;
                    same |= strstr(type.c_str(), "Plfo") && strstr(comp.c_str(), "Plfo");
                    if(!same)
                        continue;
                    files.push_back(std::get<0>(list[i]));
                    copybrowse->add(std::get<1>(list[i]).c_str());
                    pastebrowse->add(std::get<1>(list[i]).c_str());
            }};
            datamodel.callback = [this](Osc_DataModel::value_t val) {
                printf("Value = %s\\n", val.c_str());
                copytypetext->label(val.c_str());
                pastetypetext->label(val.c_str());
                listmodel.doUpdate("/presets/scan-for-presets");
            };
        
        } {}
    }
    Function {~PresetsUI()} {} {
        code {copywin->hide();delete(copywin);
            pastewin->hide();delete(pastewin);} {}
    }
    Function {make_window()} {} {
        Fl_Window copywin {
            label {Copy to Clipboard/Preset}
            xywh {190 173 265 430} type Double box THIN_UP_BOX color 238 hide modal
        } {
            Fl_Browser copybrowse {
                callback {int val=o->value();
                    if (val!=0){
                        presetname->cut(0,presetname->maximum_size());
                        presetname->insert(o->text(val));
                    };}
                xywh {10 25 245 320} type Select
            }
            Fl_Button copypbutton {
                label {Copy to Preset}
                callback {const char *tmp=presetname->value();
                    if (tmp!=NULL) {
                        if (strlen(tmp)>0){
                            if(arraymode)
                                osc->write("/presets/copy", "ssi", url.c_str(), tmp, arrayidx);
                            else
                                osc->write("/presets/copy", "ss", url.c_str(), tmp);
                            copywin->hide();
                        };
                    };}
                xywh {145 355 110 20} box THIN_UP_BOX
            }
            Fl_Button copybutton {
                label {Copy to Clipboard}
                callback {
                    if(arraymode)
                        osc->write("/presets/copy", "si", url.c_str(), arrayidx);
                    else
                        osc->write("/presets/copy", "s", url.c_str());
                    copywin->hide();}
                xywh {25 385 90 35} box THIN_UP_BOX align 192
            }
            Fl_Button {} {
                label Cancel
                    callback {copywin->hide();}
                xywh {160 385 80 35} box THIN_UP_BOX align 192
            }
            Fl_Box {} {
                label {Type:}
                xywh {10 5 40 15} labelsize 11 align 20
            }
            Fl_Box copytypetext {
                xywh {50 5 205 15} box FLAT_BOX color 238 labelfont 1 labelsize 11 align 20
            }
            Fl_Input presetname {
                callback {const char *tmp=o->value();
                    if (tmp==NULL) tmp="";
                    if (strlen(tmp)>0) {
                        copybutton->deactivate();
                        copypbutton->activate();
                    } else {
                        copybutton->activate();
                        copypbutton->deactivate();
                    };}
                xywh {10 355 130 20} when 1
            }
        }
        Fl_Window pastewin {
            label {Paste from Clipboard/Preset}
            xywh {463 173 265 430} type Double box THIN_UP_BOX color 238 hide modal
        } {
            Fl_Browser pastebrowse {
                callback {if (o->value()==0) {
                    pastepbutton->deactivate();
                    deletepbutton->deactivate();
                }else{
                    pastepbutton->activate();
                    deletepbutton->activate();
                };}
                xywh {10 25 245 320} type Hold
            }
            Fl_Button pastepbutton {
                label {Paste from Preset}
                callback {int n=pastebrowse->value()-1;
                    if (n>=0){
                        if(arraymode)
                            osc->write("/presets/paste", "ssi", url.c_str(), files[n].c_str(), arrayidx);
                        else
                            osc->write("/presets/paste", "ss", url.c_str(), files[n].c_str());
                    }
                    pastewin->hide();
                    pui->refresh();}
                xywh {10 355 160 20} box THIN_UP_BOX
            }
            Fl_Button pastebutton {
                label {Paste from Clipboard}
                callback {
                    if(arraymode)
                        osc->write("/presets/paste", "si", url.c_str(), arrayidx);
                    else
                        osc->write("/presets/paste", "s", url.c_str());
                    pastewin->hide();
                    pui->refresh();}
                xywh {25 385 90 35} box THIN_UP_BOX align 192
            }
            Fl_Button {} {
                label Cancel
                    callback {pastewin->hide();}
                xywh {160 385 80 35} box THIN_UP_BOX align 192
            }
            Fl_Box pastetypetext {
                xywh {55 5 200 15} box FLAT_BOX color 238 labelfont 1 labelsize 11 align 20
            }
            Fl_Box {} {
                label {Type:}
                xywh {15 5 40 15} labelsize 11 align 20
            }
            Fl_Button deletepbutton {
                label Delete
                    callback {int n=pastebrowse->value()-1;

                        if (n>=0) {
                            osc->write("/presets/delete", "s", files[n].c_str());
                        }
                        rescan(url);
                    } selected
                xywh {180 355 75 20} box THIN_UP_BOX
            }
        }
    }
    Function {paste(std::string url_, PresetsUI_ *pui, int idx)} {} {code {
    url = url_;
    this->pui=pui;
    bool but=(Fl::event_button()!=FL_LEFT_MOUSE);
    pastepbutton->deactivate();
    deletepbutton->deactivate();
    arraymode = true;
    arrayidx  = idx;

    if(but) {
        osc->write("/presets/paste", "si", url.c_str(), idx);
        pui->refresh();
    } else {
        rescan(url_);
        pastewin->show();
    }
    } {}}
    Function {copy(std::string url_, int idx)} {} {code {
        copybutton->activate();
        copypbutton->deactivate();
        arraymode = true;
        arrayidx  = idx;
        url = url_;
        this->pui=NULL;
        bool but=(Fl::event_button()!=FL_LEFT_MOUSE);
        presetname->cut(0,presetname->maximum_size());

        if(but) {
            osc->write("/presets/copy", "si", url_.c_str(), idx);
        } else {
            rescan(url_);
            copywin->show();
        }
    } {}}
    Function {copy(std::string url_)} {} {
        code {
            copybutton->activate();
            copypbutton->deactivate();
            arraymode = false;

            url = url_;
            this->pui=NULL;
            bool but=(Fl::event_button()!=FL_LEFT_MOUSE);
            presetname->cut(0,presetname->maximum_size());

            if(but) {
                osc->write("/presets/copy", "s", url_.c_str());
            } else {
                rescan(url_);
                copywin->show();
            };} {}
    }
    Function {paste(std::string url_, PresetsUI_ *pui)} {} {
        code {
            url = url_;
            this->pui=pui;
            bool but=(Fl::event_button()!=FL_LEFT_MOUSE);
            pastepbutton->deactivate();
            deletepbutton->deactivate();
            arraymode = false;

            if(but) {
                osc->write("/presets/paste", "s", url.c_str());
                pui->refresh();
            } else {
                rescan(url_);
                pastewin->show();
            };} {}
    }
    Function {rescan(std::string url)} {} {
        code {copybrowse->clear();
            pastebrowse->clear();

            printf("Datamodel Update...");
            datamodel.doUpdate(url+"preset-type");
            } {}
    }
    decl {std::string url;} {public local
    }
    decl {Fl_Osc_Interface *osc;} {public local
    }
    decl {Osc_ListModel listmodel;} {public local
    }
    decl {Osc_DataModel datamodel;} {public local
    }
    decl {std::vector<std::string> files;} {public local
    }
    decl {bool arraymode;} {public local
    }
    decl {int arrayidx;} {public local
    }
    decl {PresetsUI_ *pui;} {public local
    }
} 

decl {PresetsUI *presetsui;} {public
}
