/*; Copyright (c) 2003, Shiv Sikand, All rights reserved.
;
; This file is part of the cdsp4-concept interface
; Redistribution and use in source and binary forms, with or
; without modification, are permitted provided that the following
; conditions are met:
;
; Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
;
; Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; Neither name of Perforce Software nor SGI nor the names of its
; contributors may be used to endorse or promote products derived from
; this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE
; SOFTWARE, INC, SGI, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
; OF THE POSSIBILITY OF SUCH DAMAGE.*/
#include "gui.h"
// Global utils
GSList *free_list_gstring(GSList *list,Fl_Hold_Browser *browswer);
// Module definitions
Fl_Hold_Browser *mbrowse=(Fl_Hold_Browser *)0;
GSList *mbrowse_list=NULL;
// Module utils
int addmodules();
int read_dir();
// Module callbacks
void mbrowse_callback(Fl_Widget *w, void *data);
void mod_editcb(Fl_Widget *w, void *data);
void mod_readcb(Fl_Widget *w, void *data);
// View definitions
Fl_Hold_Browser *vbrowse=(Fl_Hold_Browser *)0;
GSList *vbrowse_list=NULL;
// View utils
int addviews(gchar *module);
// View callbacks
void vbrowse_callback(Fl_Widget *w, void *data);
void view_editcb(Fl_Widget *w, void *data);
void view_readcb(Fl_Widget *w, void *data);
// Menu definitions
Fl_Menu_Item menu_Proj[] = {
{"&Edit", FL_ALT+'e', mod_editcb, 0},
{"&Read", FL_ALT+'r', mod_readcb, 0},
{0}
};
Fl_Menu_Item menu_Mod[] = {
{"&Edit", FL_ALT+'e', mod_editcb, 0},
{"&Read", FL_ALT+'r', mod_readcb, 0},
{0}
};
Fl_Menu_Item menu_View[] = {
{"&Edit", FL_ALT+'e', view_editcb, 0},
{"&Read", FL_ALT+'r', view_readcb, 0},
{0}
};
// Main Concept Browser Definition
Fl_Window* make_window() {
const char *text="Monkey";
Fl_Window* w;
// Main Window
{ Fl_Window* o = new Fl_Window(367, 566, "cdsp4 Concept Browser");
w = o;
o->color(46);
o->labelcolor(90);
o->align(FL_ALIGN_TOP|FL_ALIGN_INSIDE);
// Project commands
{ Fl_Menu_Button* o = new Fl_Menu_Button(20,5,180,25, "Project Commands ");
o->down_box(FL_BORDER_BOX);
o->menu(menu_Proj);
o->labelcolor(120);
o->labelfont(1);
}
// Text boxes
{ Fl_Text_Display* o = new Fl_Text_Display(20, 50, 325, 25, "Active project");
o->align(FL_ALIGN_TOP_LEFT);
o->labelfont(1);
//Text buffer
Fl_Text_Buffer *ap_buff= new Fl_Text_Buffer(128);
o->buffer(ap_buff);
ap_buff->append("dog");
}
{ Fl_Text_Display* o = new Fl_Text_Display(20, 100, 325, 25, "Branch client");
o->align(FL_ALIGN_TOP_LEFT);
o->labelfont(1);
//Text buffer
Fl_Text_Buffer *bc_buff= new Fl_Text_Buffer(128);
o->buffer(bc_buff);
bc_buff->append("dog");
}
// Module browser
{ Fl_Hold_Browser* o = mbrowse = new Fl_Hold_Browser(20, 180, 325, 230);
o->textcolor(4);
// Read the current directory for modules and add it to the object
addmodules();
o->callback(mbrowse_callback,o);
}
// Module commands
{ Fl_Menu_Button* o = new Fl_Menu_Button(20,140,180,25, "Module Commands ");
o->down_box(FL_BORDER_BOX);
o->menu(menu_Mod);
o->labelcolor(120);
o->labelfont(1);
}
// View section
{ Fl_Menu_Button* o = new Fl_Menu_Button(20,425,180,25, "View Commands ");
o->down_box(FL_BORDER_BOX);
o->menu(menu_View);
o->labelcolor(120);
o->labelfont(1);
//o->callback(vchoice_callback,o);
}
// View browser
{ Fl_Hold_Browser* o = vbrowse = new Fl_Hold_Browser(20, 460,325,75);
o->textcolor(99);
o->callback(vbrowse_callback, o);
}
o->end();
}
return w;
}
void mbrowse_callback(Fl_Widget *w, void *userData) {
int currentsel;
GString *data;
currentsel=mbrowse->value();
data=(GString *)g_slist_nth_data(mbrowse_list,currentsel-1);
printf("Value is %s\n", data->str);
// Populate the view browse window
addviews(data->str);
}
void vbrowse_callback(Fl_Widget *w, void *data) {
int currentsel;
currentsel=vbrowse->value();
printf("Sel is %d\n", currentsel);
printf("Changed %d\n", vbrowse->changed());
}
void view_editcb(Fl_Widget *w, void *data) {
printf("Edit cb\n");
printf("Data is %d\n", vbrowse->value());
}
void view_readcb(Fl_Widget *w, void *data) {
printf("Read cb\n");
}
void mod_editcb(Fl_Widget *w, void *data) {
printf("Edit cb\n");
printf("Data is %d\n", mbrowse->value());
}
void mod_readcb(Fl_Widget *w, void *data) {
printf("Read cb\n");
}
int addmodules() {
DIR *dirp;
dirent *dp;
struct stat buf;
dirp= opendir(".");
GString *dname;
// Add directories to the modules list
// And to the module browser
if(mbrowse_list != NULL) {
mbrowse_list=free_list_gstring(mbrowse_list,mbrowse);
}
while(dirp) {
if((dp = readdir(dirp)) != NULL) {
stat(dp->d_name, &buf);
if(S_ISDIR(buf.st_mode)) {
if((strcmp(".", dp->d_name)) && (strcmp("..", dp->d_name))) {
// add it to the list
dname=g_string_new(dp->d_name);
mbrowse_list= g_slist_append(mbrowse_list, dname);
// add it to the browser
mbrowse->add(dp->d_name,0);
}
}
} else {
closedir(dirp);
return 0;
}
}
return 1;
}
int addviews(gchar *module) {
DIR *dirp;
dirent *dp;
struct stat buf;
GString *dname;
if(vbrowse_list != NULL) {
vbrowse_list=free_list_gstring(vbrowse_list,vbrowse);
}
dirp= opendir(module);
while(dirp) {
if((dp = readdir(dirp)) != NULL) {
stat(dp->d_name, &buf);
if(S_ISDIR(buf.st_mode)) {
if((strcmp(".", dp->d_name)) && (strcmp("..", dp->d_name))) {
// add view filtering here
// add it to the list
dname=g_string_new(dp->d_name);
vbrowse_list= g_slist_append(vbrowse_list, dname);
// add it to the browser
vbrowse->add(dp->d_name,0);
}
}
} else {
closedir(dirp);
return 0;
}
}
return 1;
}
GSList *free_list_gstring(GSList *list,Fl_Hold_Browser *browser) {
GString *data;
int i;
// Free all the GStrings in a list
for(i=0; i < g_slist_length(list); i++) {
data=(GString *)g_slist_nth_data(list,i);
// pop it off
list=g_slist_remove(list,data);
// free the Gstring
g_string_free(data, TRUE);
}
browser->clear();
return list;
}