00001 #include <glui.h>
00002 #include <glut.h>
00003 #include <iostream>
00004
00005 #include "LifeVariables.h"
00006 #include "FileDialog.h"
00007
00008 using namespace std;
00009
00010 FileDialog::FileDialog() {
00011 this->tempPath = "";
00012 this->lastElement ="";
00013 this->path = DEFAULT_PATH;
00014
00015 this->panel = GLUI_Master.create_glui("Add search path...", 0,150,200);
00016
00017 this->msgText = this->panel->add_statictext("Enter a search path.");
00018
00019 this->pathText = panel->add_edittext("Path ", GLUI_EDITTEXT_TEXT);
00020 this->pathText->set_text(path);
00021 this->pathText->set_w(300);
00022
00023 this->buttonPanel = panel->add_panel("", GLUI_PANEL_NONE);
00024 this->buttonPanel->set_alignment(GLUI_ALIGN_RIGHT);
00025
00026 this->okBtn = panel->add_button_to_panel(buttonPanel,"Ok", CONFIRMOPENFILEDLG_ID, eventListener);
00027 this->panel->add_column_to_panel(buttonPanel, false);
00028
00029 this->cancelBtn = panel->add_button_to_panel(buttonPanel,"Cancel", CANCELOPENFILEDLG_ID, eventListener);
00030 this->hide();
00031 }
00032
00033 void FileDialog::show() {
00034 this->msgText->set_text("Enter a search path.");
00035 this->panel->show();
00036 }
00037
00038 void FileDialog::show(char *errorMsg) {
00039 this->msgText->set_text(errorMsg);
00040 this->panel->show();
00041 }
00042
00043 void FileDialog::hide() {
00044 panel->hide();
00045 }
00046
00047
00048 void FileDialog::confirm() {
00049
00050
00051 this->tempPath = pathText->get_text();
00052 int pos =0;
00053
00054
00055 while((pos = tempPath.find("\\\\"))!=string::npos) {
00056 tempPath.replace(pos, 1, "\\");
00057 }
00058
00059
00060 while((pos = tempPath.find("\\"))!=string::npos) {
00061 tempPath.replace(pos, 1, "/");
00062 }
00063
00064
00065 lastElement = tempPath.substr(tempPath.size()-1, tempPath.size());
00066
00067
00068 if (lastElement.find("/")!= string::npos) {
00069 path = &tempPath[0];
00070 cout << lastElement << endl;
00071 }
00072 else {
00073 tempPath.append("/");
00074 path = &tempPath[0];
00075 }
00076 panel->hide();
00077 }