/[antiright]/antiright/src/arshell/file.c
ViewVC logotype

Diff of /antiright/src/arshell/file.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by jefbed, Sat Jul 23 17:10:09 2005 UTC revision 1.10 by jefbed, Sun Jul 31 16:19:50 2005 UTC
# Line 22  Line 22 
22  #include "arshell.h"  #include "arshell.h"
23    
24  void  void
25  arshell_insert_file_cb()  arshell_insert_file_cb ()
26  {  {
27    char *file=antiright_pipe_read("cat `arshell -ADf`");    char *file = antiright_pipe_read ("cat `arshell -ADf`");
28    XmTextInsert(arshell.gui.widgets.work,    XmTextInsert (arshell.gui.widgets.work,
29                 XmTextGetInsertionPosition(arshell.gui.widgets.work),                  XmTextGetInsertionPosition (arshell.gui.widgets.work), file);
30                 file);    free (file);
   free(file);  
31  }  }
32    
33  void  void
34  arshell_open_file_cb(Widget parent_widget,  arshell_open_file_cb (Widget parent_widget,
35                       XtPointer client_data,                        XtPointer client_data, XtPointer call_data)
36                       XtPointer call_data)  {
 {  
37    char *label;    char *label;
38    XmString motif_string;    XmString motif_string;
39    ARCLARG;    ARCLARG;
40    antiright_set(XmNlabelString, (XtArgVal)&motif_string);    antiright_set (XmNlabelString, (XtArgVal) & motif_string);
41    antiright_get_values(parent_widget);    antiright_get_values (parent_widget);
42    label=antiright_c_string(motif_string);    label = antiright_c_string (motif_string);
43    XmStringFree(motif_string);    XmStringFree (motif_string);
44    strncpy(arshell.edit.filename, label, ARSHELL_MAX_STRLEN);    strncpy (arshell.edit.filename, label, ARSHELL_MAX_STRLEN);
45    free(label);    free (label);
46    arshell.edit.open_is_MDI=True;    arshell.edit.open_is_MDI = True;
47    arshell_open_file();    arshell_open_file ();
48    call_data=NULL;    call_data = NULL;
49    client_data=NULL;    client_data = NULL;
50  }  }
51    
52  void  void
53  arshell_open_file()  arshell_open_file ()
54  {  {
55    char *command_string;    char *command_string;
56    char *buffer;    char *buffer;
57    antiright_get_file_type(arshell.edit.filename);    antiright_get_file_type (arshell.edit.filename);
58    asprintf(&command_string, "cat %s", arshell.edit.filename);    asprintf (&command_string, "cat %s", arshell.edit.filename);
59    buffer=antiright_pipe_read(command_string);    buffer = antiright_pipe_read (command_string);
60    free(command_string);    free (command_string);
61    XmTextSetString(arshell.gui.widgets.work, buffer);    XmTextSetString (arshell.gui.widgets.work, buffer);
62    free(buffer);    free (buffer);
63    if(!arshell.edit.open_is_MDI)    if (!arshell.edit.open_is_MDI)
64      antiright_button(arshell.gui.menubar.view_widget, arshell.edit.filename,      antiright_button (arshell.gui.menubar.view_widget, arshell.edit.filename,
65                       arshell_open_file_cb, NULL);                        arshell_open_file_cb, NULL);
66    else    else
67      arshell.edit.open_is_MDI=False;      arshell.edit.open_is_MDI = False;
68  }  }
69    
70  void  void
71  arshell_revert_file_cb()  arshell_revert_file_cb ()
72  {  {
73    arshell.edit.open_is_MDI=True;    arshell.edit.open_is_MDI = True;
74    arshell_open_file();    arshell_open_file ();
75  }  }
76    
77  void  void
78  arshell_file_select_ok_cb(Widget widget,  arshell_file_select_ok_cb (Widget widget,
79                            XtPointer client_data,                             XtPointer client_data, XtPointer call_data)
                           XtPointer call_data)  
80  {  {
81    XmFileSelectionBoxCallbackStruct *call_pointer=call_data;    XmFileSelectionBoxCallbackStruct *call_pointer = call_data;
82    char *c_string;    char *c_string;
83    
84    /*  if(arshell.flags.file_open)    /*  if(arshell.flags.file_open)
85      {       {
86        arshell_save_work_area();       arshell_save_work_area();
87        }*/       } */
88    
89    c_string=antiright_c_string(call_pointer->value);    c_string = antiright_c_string (call_pointer->value);
90    strncpy(arshell.edit.filename, c_string, ARSHELL_MAX_STRLEN);    strncpy (arshell.edit.filename, c_string, ARSHELL_MAX_STRLEN);
91    XtFree(c_string);    XtFree (c_string);
92    XtDestroyWidget(widget);    XtDestroyWidget (widget);
93    
94    if(arshell.flags.saving && !arshell.flags.opening)    if (arshell.flags.saving && !arshell.flags.opening)
95      {      {
96        arshell.flags.file_open=True;        arshell.flags.file_open = True;
97        arshell_save_work_area();        arshell_save_work_area ();
98        arshell.flags.saving=False;        arshell.flags.saving = False;
99      }      }
100    
101    if(arshell.flags.opening)    if (arshell.flags.opening)
102      {      {
103        arshell_open_file();        arshell_open_file ();
104        arshell.flags.file_open=True;        arshell.flags.file_open = True;
105        arshell.flags.opening=False;        arshell.flags.opening = False;
106      }      }
107    
108     client_data=NULL;    client_data = NULL;
109  }  }
110    
111  void  void
112  arshell_select_filename()  arshell_select_filename ()
113  {  {
114      
115    Widget file_selection_widget;    Widget file_selection_widget;
116    ARCLARG;    ARCLARG;
117    antiright_set(XmNtitle, (XtArgVal)"File Selector");    antiright_set (XmNtitle, (XtArgVal) "File Selector");
118    file_selection_widget=XmCreateFileSelectionDialog(antiright.parent_widget,    file_selection_widget =
119                                                      "file_selection_widget",      XmCreateFileSelectionDialog (antiright.parent_widget,
120                                                      antiright.arguments,                                   "file_selection_widget", antiright.arguments,
121                                                      antiright.arguments_int);                                   antiright.arguments_int);
122    antiright_set_widget_title(file_selection_widget, "File Selector");    antiright_set_widget_title (file_selection_widget, "File Selector");
123    XtManageChild(file_selection_widget);    XtManageChild (file_selection_widget);
124    XtAddCallback(file_selection_widget, XmNcancelCallback,    XtAddCallback (file_selection_widget, XmNcancelCallback,
125                  antiright_close_cb, NULL);                   antiright_close_cb, NULL);
126    XtAddCallback(file_selection_widget, XmNhelpCallback,    XtAddCallback (file_selection_widget, XmNhelpCallback,
127                  antiright_help_cb, "Use_this_dialog_to_select_a_file.");                   antiright_help_cb, "Use_this_dialog_to_select_a_file.");
128    XtAddCallback(file_selection_widget, XmNokCallback,    XtAddCallback (file_selection_widget, XmNokCallback,
129                  arshell_file_select_ok_cb, NULL);                   arshell_file_select_ok_cb, NULL);
130  }  }
131    
132  void  void
133  arshell_put_text_into_file(FILE *file)  arshell_put_text_into_file (FILE * file)
134  {  {
135    char *text_string;    char *text_string;
136    assert(arshell.gui.widgets.work != NULL);    assert (arshell.gui.widgets.work != NULL);
137    text_string=XmTextGetString(arshell.gui.widgets.work);    text_string = XmTextGetString (arshell.gui.widgets.work);
138    fprintf(file, "%s\n", text_string);    fprintf (file, "%s\n", text_string);
139    XtFree(text_string);    XtFree (text_string);
140  }  }
141    
142  void  void
143  arshell_open_file_for_writing(FILE **file_pointer)  arshell_open_file_for_writing (FILE ** file_pointer)
144  {  {
145    (*file_pointer)=fopen(arshell.edit.filename, "w");    (*file_pointer) = fopen (arshell.edit.filename, "w");
146    if((*file_pointer)==NULL)    if ((*file_pointer) == NULL)
147      {      {
148        arshell_select_filename();        arshell_select_filename ();
149      }      }
150  }  }
151    
152  void  void
153  arshell_save_work_area()  arshell_save_work_area ()
154  {  {
155    FILE* file_pointer;    FILE *file_pointer;
156    arshell.flags.saving=True;    arshell.flags.saving = True;
157    if(arshell.flags.file_open==False)    if (arshell.flags.file_open == False)
158      {      {
159        arshell_select_filename();        arshell_select_filename ();
160      }      }
161    else    else
162      {          {
163        arshell_open_file_for_writing(&file_pointer);        arshell_open_file_for_writing (&file_pointer);
164        arshell_put_text_into_file(file_pointer);        arshell_put_text_into_file (file_pointer);
165        fclose(file_pointer);        fclose (file_pointer);
166        arshell_get_rid_of_modified_status();        arshell_get_rid_of_modified_status ();
167        antiright_set_title(arshell.edit.filename);        antiright_set_title (arshell.edit.filename);
168      }      }
169  }  }
170    
171  void  void
172  arshell_save_as_cb()  arshell_save_as_cb ()
173  {  {
174    arshell.flags.saving=True;    arshell.flags.saving = True;
175    arshell_select_filename();    arshell_select_filename ();
176  }  }
177    
178  void  void
179  arshell_open_cb()  arshell_open_cb ()
180  {  {
181    arshell.flags.opening=True;    arshell.flags.opening = True;
182    arshell.flags.saving=False;    arshell.flags.saving = False;
183    arshell_select_filename();    arshell_select_filename ();
184  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26