Enlightenment CVS committal

Author  : werkt
Project : misc
Module  : ewler

Dir     : misc/ewler/src


Modified Files:
        ewler.c form.c form.h layout.c project.c project.h selected.c 
        selected.h 


Log Message:
Projects can now be saved/opened, and tend not to destroy existing projects.

===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/ewler.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- ewler.c     10 Aug 2004 21:45:34 -0000      1.6
+++ ewler.c     12 Aug 2004 04:08:12 -0000      1.7
@@ -37,6 +37,7 @@
 static void
 __open_project( Ewl_Widget *w, void *ev_data, void *user_data )
 {
+       project_open();
 }
 
 static void
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/form.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- form.c      10 Aug 2004 22:33:15 -0000      1.13
+++ form.c      12 Aug 2004 04:08:12 -0000      1.14
@@ -533,7 +533,7 @@
                        }
                }
        } else {
-               /* do a project save */
+               project_save();
        }
 }
 
@@ -650,6 +650,27 @@
        return ecore_hash_get( form->elements, name );
 }
 
+/* do not pass go, do not collect $200, do not call this unless you MEAN IT! */
+void
+form_close( char *filename )
+{
+       Ewler_Form *form;
+
+       ecore_list_goto_first( forms );
+
+       while( (form = ecore_list_current( forms )) ) {
+               if( !strcmp( form->filename, filename ) ) {
+                       ecore_list_remove( forms );
+
+                       FREE( form->filename );
+                       ewl_widget_destroy( form->window );
+                       FREE( form );
+                       return;
+               }
+               ecore_list_next( forms );
+       }
+}
+
 void
 ewler_forms_close( void )
 {
@@ -688,6 +709,20 @@
        return 0;
 }
 
+int
+form_is_dirty( char *filename )
+{
+       Ewler_Form *form;
+
+       ecore_list_goto_first( forms );
+
+       while( (form = ecore_list_next(forms)) )
+               if( !strcmp( form->filename, filename ) )
+                       return form->dirty;
+
+       return 0;
+}
+
 void
 __form_delete( Ewler_Form *form )
 {
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/form.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- form.h      10 Aug 2004 21:45:34 -0000      1.5
+++ form.h      12 Aug 2004 04:08:12 -0000      1.6
@@ -33,6 +33,8 @@
 
 void form_save_file( Ewler_Form *form, int save_as );
 void form_open_file( char *filename );
+void form_close( char *filename );
 int form_is_open( char *filename );
+int form_is_dirty( char *filename );
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/layout.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- layout.c    9 Aug 2004 09:03:14 -0000       1.2
+++ layout.c    12 Aug 2004 04:08:12 -0000      1.3
@@ -77,9 +77,9 @@
                        sprintf( name, "Layout%d", count++ );
                        widget_name = strdup( name );
 
-                       form->layout = ewl_hbox_new();
-                       ewl_box_set_orientation( EWL_BOX(form->layout), orientation );
+                       form->layout = ewl_box_new(orientation);
                        widget_create_info( form->layout, "Ewl_Box", widget_name );
+                       ewl_box_set_orientation( EWL_BOX(form->layout), orientation );
 
                        ewl_object_request_position( EWL_OBJECT(form->layout), 0, 0 );
                        ewl_object_set_fill_policy( EWL_OBJECT(form->layout),
@@ -122,9 +122,9 @@
                sprintf( name, "Layout%d", count++ );
                widget_name = strdup( name );
 
-               box = ewl_hbox_new();
-               ewl_box_set_orientation( EWL_BOX(box), orientation );
+               box = ewl_box_new(orientation);
                widget_create_info( box, "Ewl_Box", widget_name );
+               ewl_box_set_orientation( EWL_BOX(box), orientation );
 
                s = ecore_list_goto_first( form->selected );
 
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/project.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- project.c   10 Aug 2004 21:45:34 -0000      1.3
+++ project.c   12 Aug 2004 04:08:12 -0000      1.4
@@ -1,4 +1,5 @@
 #include <Ewl.h>
+#include <errno.h>
 #include <sys/time.h>
 #include <time.h>
 
@@ -14,6 +15,49 @@
 static Ewl_Widget *options_dialog;
 static Ewl_Widget *params[3];
 
+static int
+project_close( void )
+{
+       static char buf[1024];
+       char *filename;
+
+       if( project->members ) {
+               ecore_list_goto_first( project->members );
+
+               while( (filename = ecore_list_next( project->members )) ) {
+                       if( *filename != '/' )
+                               sprintf( buf, "%s/%s", project->path, filename );
+                       else
+                               strcpy( buf, project->filename );
+
+                       if( form_is_open( buf ) && form_is_dirty( buf ) )
+                               return -1;
+               }
+       }
+
+       IF_FREE(project->path);
+       IF_FREE(project->filename);
+
+       if( project->members ) {
+               ecore_list_goto_first( project->members );
+
+               while( (filename = ecore_list_remove( project->members )) ) {
+                       if( *filename != '/' )
+                               sprintf( buf, "%s/%s", project->path, 
project->filename );
+                       else
+                               strcpy( buf, project->filename );
+
+                       form_close( buf );
+                       free( filename );
+               }
+
+               ecore_list_destroy( project->members );
+               project->members = NULL;
+       }
+
+       return 0;
+}
+
 static void
 __projects_destroy_cb( Ewl_Widget *w, void *ev_data, void *user_data )
 {
@@ -24,29 +68,26 @@
 __project_new_cb( Ewl_Widget *w, void *ev_data, void *user_data )
 {
        char *headers[2] = { NULL, NULL };
+       static char buf[256];
 
-       IF_FREE(project->name);
-       IF_FREE(project->filename);
-       IF_FREE(project->path);
-       
-       if( project->members ) {
+       if( !project_close() ) {
+               project->filename = strdup( "untitled.ewl" );
+               sprintf( buf, "%s/Untitled", getenv( "HOME" ) );
+               project->path = strdup( buf );
+               project->members = ecore_list_new();
                ecore_list_set_free_cb( project->members, free );
-               ecore_list_destroy( project->members );
-       }
 
-       project->name = strdup( "Untitled" );
-       project->filename = NULL;
-       project->path = NULL;
-       project->members = ecore_list_new();
-       ecore_list_set_free_cb( project->members, free );
-
-       project->dirty = 0;
-       project->filename_set = 0;
+               project->dirty = 0;
+               project->filename_set = 0;
 
-       headers[0] = project->name;
+               headers[0] = project->filename;
 
-       ewl_container_reset( EWL_CONTAINER(project_tree) );
-       ewl_tree_set_headers( EWL_TREE(project_tree), headers );
+               ewl_container_reset( EWL_CONTAINER(project_tree) );
+               ewl_tree_set_headers( EWL_TREE(project_tree), headers );
+       } else {
+               ewler_error_dialog( "The current project has modified forms, a new "
+                                                                                      
         "project cannot be created now." );
+       }
 }
 
 static void
@@ -127,7 +168,7 @@
        char *filename;
        int i;
 
-       headers[0] = project->name;
+       headers[0] = project->filename;
 
        ewl_container_reset( EWL_CONTAINER(project_tree) );
        ewl_tree_set_headers( EWL_TREE(project_tree), headers );
@@ -236,23 +277,85 @@
        return project->path;
 }
 
+void
+__create_path( Ewl_Widget *w, void *ev_data, void *user_data )
+{
+       char *path, *errstr = NULL;
+
+       path = ewl_entry_get_text( EWL_ENTRY(params[1]) );
+
+       mkdir( path, 0777 );
+       switch( errno ) {
+               case EPERM: errstr = "%s: cannot create directory on filesystem"; 
break;
+               case EEXIST: errstr = "%s: file exists"; break;
+               case EFAULT: errstr = "%s: bad address"; break;
+               case EACCES: errstr = "%s: permission denied"; break;
+               case ENAMETOOLONG: errstr = "%s: directory does not exist"; break;
+               case ENOENT: errstr = "%s: out of memory"; break;
+               case EROFS: errstr = "%s: read-only filesystem"; break;
+               case ENOSPC: errstr = "%s: filesystem full"; break;
+       }
+
+       if( errstr )
+               ewler_error_dialog( errstr, path );
+}
+
 static void
 __apply_changes( Ewl_Widget *w, void *ev_data, void *user_data )
 {
-       IF_FREE(project->name);
+       char *name, *path, *filename;
+       int delay = 0;
+
+       name = ewl_entry_get_text( EWL_ENTRY(params[0]) );
+       path = ewl_entry_get_text( EWL_ENTRY(params[1]) );
+       if( strlen( path ) == 0 )
+               path = NULL;
+       filename = ewl_entry_get_text( EWL_ENTRY(params[2]) );
+       if( strlen( filename ) == 0 )
+               filename = NULL;
+
+       if( path ) {
+               struct stat st_buf;
+               char *errstr = "%s: unknown error";
+
+               if( stat( path, &st_buf ) < 0 ) {
+                       switch( errno ) {
+                               case ENOENT:
+                                       ewler_yesno_dialog( __create_path, NULL, NULL,
+                                                                                      
                                 "Project directory does not exist, create it?" );
+                                       break;
+                               case ENOTDIR: errstr = "%s: no such directory in 
path"; break;
+                               case ELOOP: errstr = "%s: too many links"; break;
+                               case EFAULT: errstr = "%s: bad address"; break;
+                               case EACCES: errstr = "%s: permission denied"; break;
+                               case ENOMEM: errstr = "%s: out of memory"; break;
+                               case ENAMETOOLONG: errstr = "%s: filename too long"; 
break;
+                       }
+                       if( errno != ENOENT )
+                               ewler_error_dialog( errstr, path );
+                       delay = 1;
+               } else if( !S_ISDIR(st_buf.st_mode) ) {
+                       ewler_error_dialog( "%s: is not a directory", path );
+                       delay = 1;
+               } else {
+                       IF_FREE(project->path);
+                       project->path = ewl_entry_get_text( EWL_ENTRY(params[1]) );
+               }
+       }
+
        IF_FREE(project->filename);
-       IF_FREE(project->path);
 
-       project->name = ewl_entry_get_text( EWL_ENTRY(params[0]) );
-       project->path = ewl_entry_get_text( EWL_ENTRY(params[1]) );
-       if( strlen( project->path ) == 0 )
-               project->path = NULL;
        project->filename = ewl_entry_get_text( EWL_ENTRY(params[2]) );
        if( strlen( project->filename ) == 0 )
                project->filename = NULL;
 
        project->filename_set = 1;
 
+       if( !delay ) {
+               __destroy_dialog(options_dialog, NULL, options_dialog );
+               ewl_callback_call( options_dialog, EWL_CALLBACK_VALUE_CHANGED );
+       }
+
        project_update();
 }
 
@@ -280,16 +383,6 @@
        hbox = ewl_hbox_new();
        ewl_container_append_child( EWL_CONTAINER(vbox), hbox );
        ewl_widget_show( hbox );
-       label = ewl_text_new( "Project Name:" );
-       params[0] = ewl_entry_new( project->name ? project->name : "" );
-       ewl_container_append_child( EWL_CONTAINER(hbox), label );
-       ewl_container_append_child( EWL_CONTAINER(hbox), params[0] );
-       ewl_widget_show( label );
-       ewl_widget_show( params[0] );
-
-       hbox = ewl_hbox_new();
-       ewl_container_append_child( EWL_CONTAINER(vbox), hbox );
-       ewl_widget_show( hbox );
        label = ewl_text_new( "Project Directory:" );
        params[1] = ewl_entry_new( project->path ? project->path : "" );
        ewl_container_append_child( EWL_CONTAINER(hbox), label );
@@ -311,8 +404,6 @@
                                                                                       
                                                 EWL_STOCK_OK, EWL_RESPONSE_OK );
        ewl_callback_append( button, EWL_CALLBACK_CLICKED,
                                                                                       
  __apply_changes, NULL );
-       ewl_callback_append( button, EWL_CALLBACK_CLICKED,
-                                                                                      
  __destroy_dialog, options_dialog );
 
        button = ewl_dialog_add_button( EWL_DIALOG(options_dialog),
                                                                                       
                                                 EWL_STOCK_CANCEL, EWL_RESPONSE_CANCEL 
);
@@ -321,3 +412,186 @@
 
        ewl_widget_show( options_dialog );
 }
+
+static void
+__project_save_cb( Ewl_Widget *w, void *ev_data, void *user_data )
+{
+       char *member, *filename = user_data;
+       FILE *fptr;
+
+       fptr = fopen( filename, "w" );
+
+       if( fptr ) {
+               fprintf( fptr, "FORMS = " );
+
+               ecore_list_goto_first( project->members );
+
+               while( (member = ecore_list_next( project->members )) ) {
+                       fprintf( fptr, "%s", member );
+
+                       if( ecore_list_current( project->members ) )
+                               fprintf( fptr, " \\\n\t" );
+               }
+
+               fclose( fptr );
+       } else {
+               ewler_error_dialog( "Unable to open project file %s", filename );
+       }
+}
+
+static void
+__project_setup_save_cb( Ewl_Widget *w, void *ev_data, void *user_data )
+{
+       static char buf[1024];
+       struct stat st_buf;
+
+       sprintf( buf, "%s/%s", project->path, project->filename );
+
+       if( stat( buf, &st_buf ) < 0 ) {
+               ewler_yesno_dialog( __project_save_cb, NULL, buf,
+                                                                                      
         "Project file %s does not exist, create it?", buf );
+       } else
+               __project_save_cb( NULL, NULL, buf );
+}
+
+void
+project_save( void )
+{
+       if( !project->filename_set ) {
+               project_options_dialog();
+
+               ewl_callback_append( options_dialog, EWL_CALLBACK_VALUE_CHANGED,
+                                                                                      
          __project_setup_save_cb, NULL );
+       } else
+               __project_setup_save_cb( NULL, NULL, NULL );
+}
+
+static void
+project_setup( char *pathname )
+{
+       char *filename;
+       static char path[256];
+       int pathlen;
+
+       filename = strrchr( pathname, '/' ) + 1;
+       pathlen = filename - pathname - 1;
+       strncpy( path, pathname, pathlen );
+       path[pathlen] = '\0';
+
+       project->filename = strdup( filename );
+       project->path = strdup( path );
+
+       project->members = ecore_list_new();
+
+       project->dirty = 0;
+       project->filename_set = 1;
+}
+
+static void
+project_parse( FILE *fptr )
+{
+       static char buf[256];
+       int had_equals, item_done;
+       int word_len;
+       char *ptr;
+
+       while( !feof( fptr ) ) {
+               if( !fgets( buf, 255, fptr ) )
+                       break;
+
+               ptr = buf;
+               had_equals = 0;
+
+               if( !strncmp( buf, "FORMS", strlen( "FORMS" ) ) ) {
+                       static char file_buf[256];
+
+                       ptr += strlen( "FORMS" );
+                       while( !had_equals )
+                               if( *ptr++ == '=' )
+                                       had_equals = 1;
+
+                       item_done = 0;
+
+                       while( !item_done ) {
+                               while( *ptr == ' ' || *ptr == '\t' )
+                                       *ptr++;
+
+                               if( *ptr && *ptr != '\\' && *ptr != '\n' ) {
+                                       word_len = strcspn( ptr, " \t\\\n" );
+                                       strncpy( file_buf, ptr, word_len );
+                                       ptr += word_len;
+                                       
+                                       ecore_list_append( project->members, strdup( 
file_buf ) );
+                               } else if( *ptr == '\\' ) {
+                                       if( !fgets( buf, 255, fptr ) )
+                                               break;
+                                       ptr = buf;
+                               } else
+                                       item_done = 1;
+                       }
+               }
+       }
+}
+
+static void
+__project_open_cb( Ewl_Widget *w, void *ev_data, void *user_data )
+{
+       FILE *fptr;
+       char *filename = ev_data;
+
+       if( !ev_data ) {
+               ewl_callback_call( w, EWL_CALLBACK_DELETE_WINDOW );
+               return;
+       }
+
+       if( !(fptr = fopen( filename, "r" )) ) {
+               ewler_error_dialog( "Unable to open file: %s", filename );
+               return;
+       }
+
+       __destroy_dialog( w, NULL, w->parent );
+
+       project_setup( filename );
+       project_parse( fptr );
+
+       fclose( fptr );
+
+       project_update();
+}
+
+static void
+__project_setup_open_cb( Ewl_Widget *w, void *ev_data, void *user_data )
+{
+       Ewl_Widget *dialog, *window;
+
+       if( !project_close() ) {
+               window = ewl_window_new();
+               ewl_window_set_title( EWL_WINDOW(window), "Open New Project" );
+               ewl_object_set_minimum_size( EWL_OBJECT(window), 400, 600 );
+               ewl_widget_show( window );
+
+               dialog = ewl_filedialog_new( EWL_FILEDIALOG_TYPE_OPEN );
+
+               ewl_container_append_child( EWL_CONTAINER(window), dialog );
+               ewl_callback_append( dialog, EWL_CALLBACK_VALUE_CHANGED,
+                                                                                      
          __project_open_cb, NULL );
+               ewl_callback_append( dialog, EWL_CALLBACK_DELETE_WINDOW,
+                                                                                      
          __destroy_dialog, window );
+               ewl_widget_show( dialog );
+       } else {
+               ewler_error_dialog( "The current project has modified forms, a new "
+                                                                                      
         "project cannot be opened now." );
+       }
+}
+
+void
+project_open( void )
+{
+       if( project->dirty ) {
+               ewler_yesno_dialog( __project_setup_open_cb, NULL, NULL,
+                                                                                      
         "Current project has not been saved, do you wish "
+                                                                                      
         "to continue?" );
+       } else {
+               __project_setup_open_cb( NULL, NULL, NULL );
+       }
+}
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/project.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- project.h   10 Aug 2004 21:45:34 -0000      1.2
+++ project.h   12 Aug 2004 04:08:12 -0000      1.3
@@ -4,7 +4,6 @@
 typedef struct Ewler_Project Ewler_Project;
 
 struct Ewler_Project {
-       char *name;
        char *filename; /* filename of the project description */
        char *path; /* project dir */
        Ecore_List *members;
@@ -21,5 +20,6 @@
 void project_remove_file( char *filename );
 char *project_get_path( void );
 void project_options_dialog( void );
+void project_save( void );
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/selected.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- selected.c  9 Aug 2004 09:03:14 -0000       1.12
+++ selected.c  12 Aug 2004 04:08:12 -0000      1.13
@@ -44,7 +44,7 @@
 int
 ewler_selected_init(Ewler_Selected *s, Ewl_Widget *w)
 {
-       Ewl_Widget *sw;
+       Ewl_Widget *sw, *cw;
        Ewl_Container *parent;
        int index;
 
@@ -66,7 +66,7 @@
        ewl_theme_data_set_str(sw, "/selected/group", "selected");
        ewl_widget_set_layer( sw, 0 );
 
-       ewl_container_insert_child(parent, sw, s->index);
+       ewl_container_insert_child(parent, sw, index);
        ewl_object_request_geometry(EWL_OBJECT(s),
                                                                                       
                                 CURRENT_X(w), CURRENT_Y(w),
                                                                                       
                                 CURRENT_W(w), CURRENT_H(w));
@@ -90,12 +90,11 @@
        ewl_callback_append(sw, EWL_CALLBACK_MOUSE_UP,
                                                                                       
 ewler_selected_mouse_up_cb, NULL);
 
-       if( ewl_object_get_preferred_w(EWL_OBJECT(w)) < SELECTED_MIN_WIDTH &&
-                       ewl_object_get_preferred_h(EWL_OBJECT(w)) < 
SELECTED_MIN_HEIGHT )
+       if( ewl_object_preferred_w_sum_get(EWL_OBJECT(w)) < SELECTED_MIN_WIDTH &&
+                       ewl_object_preferred_w_sum_get(EWL_OBJECT(w)) < 
SELECTED_MIN_HEIGHT )
                ewl_object_set_preferred_size(EWL_OBJECT(w),
                                                                                       
                                                 SELECTED_MIN_WIDTH, 
SELECTED_MIN_HEIGHT);
 
-       s->index = index;
        s->selected = w;
        s->dragging = NULL;
 
@@ -129,7 +128,7 @@
        s = EWLER_SELECTED(w);
        
        /* the width comes in from the selected, the position is set by the parent */
-       ewl_object_get_preferred_size(EWL_OBJECT(s->selected), &width, &height);
+       ewl_object_preferred_size_sum_get(EWL_OBJECT(s->selected), &width, &height);
        x = CURRENT_X(s);
        y = CURRENT_Y(s);
 
@@ -227,7 +226,7 @@
 
        s = EWLER_SELECTED(user_data);
 
-       ewl_object_get_preferred_size(EWL_OBJECT(s->selected), &width, &height);
+       ewl_object_preferred_size_sum_get(EWL_OBJECT(s->selected), &width, &height);
 
        ewl_object_request_size(EWL_OBJECT(s), width, height);
        ewl_object_set_preferred_size(EWL_OBJECT(s), width, height);
===================================================================
RCS file: /cvsroot/enlightenment/misc/ewler/src/selected.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- selected.h  25 Jul 2004 01:01:49 -0000      1.6
+++ selected.h  12 Aug 2004 04:08:12 -0000      1.7
@@ -16,7 +16,6 @@
        struct {
                int x, y;
        } last_pos;
-       int index;
 };
 
 




-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to