/* AntiRight (c) 2002-2004 Jeffrey Bedard This file is part of AntiRight. AntiRight is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. AntiRight is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with AntiRight; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "arshell.h" void arshell_insert_file_cb() { char *file=antiright_pipe_read("cat `arshell -ADf`"); XmTextInsert(arshell.gui.widgets.work, XmTextGetInsertionPosition(arshell.gui.widgets.work), file); free(file); } void arshell_open_file_cb(Widget parent_widget, XtPointer client_data, XtPointer call_data) { char *label; XmString motif_string; ARCLARG; antiright_set(XmNlabelString, (XtArgVal)&motif_string); antiright_get_values(parent_widget); label=antiright_c_string(motif_string); XmStringFree(motif_string); strncpy(arshell.edit.filename, label, ARSHELL_MAX_STRLEN); free(label); arshell.edit.open_is_MDI=True; arshell_open_file(); call_data=NULL; client_data=NULL; } void arshell_open_file() { char *command_string; char *buffer; asprintf(&command_string, "cat %s", arshell.edit.filename); buffer=antiright_pipe_read(command_string); free(command_string); XmTextSetString(arshell.gui.widgets.work, buffer); free(buffer); if(!arshell.edit.open_is_MDI) antiright_button(arshell.gui.menubar.view_widget, arshell.edit.filename, arshell_open_file_cb, NULL); else arshell.edit.open_is_MDI=False; } void arshell_file_select_ok_cb(Widget widget, XtPointer client_data, XtPointer call_data) { XmFileSelectionBoxCallbackStruct *call_pointer=call_data; char *c_string; if(arshell.flags.file_open) { arshell_save_work_area(); } c_string=antiright_c_string(call_pointer->value); strncpy(arshell.edit.filename, c_string, ARSHELL_MAX_STRLEN); XtFree(c_string); XtDestroyWidget(widget); if(arshell.flags.saving) { arshell.flags.file_open=True; arshell_save_work_area(); arshell.flags.saving=False; } if(arshell.flags.opening) { arshell.flags.file_open=True; arshell_open_file(); arshell.flags.opening=False; } client_data=NULL; } void arshell_select_filename() { Widget file_selection_widget; ARCLARG; antiright_set(XmNtitle, (XtArgVal)"File Selector"); file_selection_widget=XmCreateFileSelectionDialog(antiright.parent_widget, "file_selection_widget", antiright.arguments, antiright.arguments_int); antiright_set_widget_title(file_selection_widget, "File Selector"); XtManageChild(file_selection_widget); XtAddCallback(file_selection_widget, XmNcancelCallback, antiright_close_cb, NULL); XtAddCallback(file_selection_widget, XmNhelpCallback, antiright_help_cb, "Use_this_dialog_to_select_a_file."); XtAddCallback(file_selection_widget, XmNokCallback, arshell_file_select_ok_cb, NULL); } void arshell_put_text_into_file(FILE *file) { char *text_string; assert(arshell.gui.widgets.work != NULL); text_string=XmTextGetString(arshell.gui.widgets.work); fprintf(file, "%s\n", text_string); XtFree(text_string); } void arshell_open_file_for_writing(FILE **file_pointer) { (*file_pointer)=fopen(arshell.edit.filename, "w"); if((*file_pointer)==NULL) { arshell_select_filename(); } } void arshell_save_work_area() { FILE* file_pointer; arshell.flags.saving=True; if(arshell.flags.file_open==False) { arshell_select_filename(); } else { arshell_open_file_for_writing(&file_pointer); arshell_put_text_into_file(file_pointer); fclose(file_pointer); arshell_get_rid_of_modified_status(); antiright_set_title(arshell.edit.filename); } } void arshell_save_as_cb() { arshell_select_filename(); arshell_save_work_area(); } void arshell_open_cb() { arshell.flags.opening=True; arshell_select_filename(); }