21 |
|
|
22 |
#include "arshell.h" |
#include "arshell.h" |
23 |
#include "../bitmaps/text.xbm" |
#include "../bitmaps/text.xbm" |
|
|
|
|
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_find_at_cursor_cb() |
|
|
{ |
|
|
char *buffer=XmTextGetString(arshell.gui.widgets.work); |
|
|
char word[255]; |
|
|
int word_counter=0; |
|
|
XmTextPosition position=XmTextGetInsertionPosition(arshell.gui.widgets.work); |
|
|
XmTextPosition begin_position; |
|
|
while(buffer[position]!=' ') |
|
|
{ |
|
|
position--; |
|
|
} |
|
|
begin_position=position; |
|
|
position++; |
|
|
while(buffer[position]!=' ') |
|
|
{ |
|
|
word[word_counter]=buffer[position]; |
|
|
word_counter++; |
|
|
position++; |
|
|
} |
|
|
word[word_counter]='\0'; |
|
|
XmTextFindString(arshell.gui.widgets.work, position, word, |
|
|
XmTEXT_FORWARD, &position); |
|
|
if(position < XmTextGetLastPosition(arshell.gui.widgets.work)) |
|
|
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
|
|
XtFree(buffer); |
|
|
} |
|
|
|
|
|
void |
|
|
arshell_search_ok_cb(Widget widget, |
|
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
|
{ |
|
|
XmTextPosition position; |
|
|
XmSelectionBoxCallbackStruct *prompt_data; |
|
|
char *search_string; |
|
|
|
|
|
assert(call_data != NULL); |
|
|
|
|
|
prompt_data=call_data; |
|
|
|
|
|
XmStringGetLtoR(prompt_data->value, |
|
|
XmSTRING_DEFAULT_CHARSET, |
|
|
&search_string); |
|
|
|
|
|
assert(search_string != NULL); |
|
|
|
|
|
XmTextFindString((Widget)client_data, |
|
|
XmTextGetInsertionPosition((Widget)client_data), |
|
|
search_string, |
|
|
XmTEXT_FORWARD, |
|
|
&position); |
|
|
|
|
|
XmTextSetInsertionPosition((Widget)client_data, |
|
|
position); |
|
|
|
|
|
XtFree(search_string); |
|
|
widget=NULL; |
|
|
call_data=NULL; |
|
|
} |
|
|
|
|
|
void |
|
|
arshell_search_cb(Widget widget, |
|
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
|
{ |
|
|
Widget prompt; |
|
|
|
|
|
ARCLARG; |
|
|
antiright_set(XmNtitle, (XtArgVal)"Search"); |
|
|
|
|
|
prompt= |
|
|
XmCreatePromptDialog(antiright.parent_widget, |
|
|
"Search", |
|
|
antiright.arguments, |
|
|
antiright.arguments_int); |
|
|
XtAddCallback(prompt, |
|
|
XmNokCallback, |
|
|
arshell_search_ok_cb, |
|
|
arshell.gui.widgets.work); |
|
|
XtAddCallback(prompt, |
|
|
XmNhelpCallback, |
|
|
antiright_help_cb, |
|
|
"Enter the text that you want to find in the text field."); |
|
|
XtManageChild(prompt); |
|
|
|
|
|
widget=(Widget)NULL; |
|
|
client_data=(XtPointer)NULL; |
|
|
call_data=(XtPointer)NULL; |
|
|
} |
|
|
|
|
|
void |
|
|
arshell_replace_ok_cb(Widget widget, |
|
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
|
{ |
|
|
XmTextPosition position; |
|
|
XmTextPosition end_position; |
|
|
char *search_string; |
|
|
char *replacement_string; |
|
|
|
|
|
client_data=NULL; |
|
|
search_string=XmTextFieldGetString(arshell.edit.find_widget); |
|
|
XmTextFindString(arshell.gui.widgets.work, |
|
|
XmTextGetInsertionPosition(arshell.gui.widgets.work), |
|
|
search_string, |
|
|
XmTEXT_FORWARD, |
|
|
&position); |
|
|
XtFree(search_string); |
|
|
XmTextFindString(arshell.gui.widgets.work, |
|
|
position, |
|
|
" ", |
|
|
XmTEXT_FORWARD, |
|
|
&end_position); |
|
|
replacement_string=XmTextFieldGetString(arshell.edit.replace_widget); |
|
|
if(end_position>position) |
|
|
{ |
|
|
XmTextReplace(arshell.gui.widgets.work, position, end_position, |
|
|
replacement_string); |
|
|
} |
|
|
XtFree(replacement_string); |
|
|
XmTextSetInsertionPosition(arshell.gui.widgets.work, position); |
|
|
XtManageChild(widget); |
|
|
call_data=NULL; |
|
|
} |
|
|
void |
|
|
arshell_replace_cb(Widget widget, |
|
|
XtPointer client_data, |
|
|
XtPointer call_data) |
|
|
{ |
|
|
Widget prompt; |
|
|
Widget form; |
|
|
client_data=NULL; |
|
|
ARCLARG; |
|
|
antiright_set(XmNtitle, (XtArgVal)"Find and Replace"); |
|
|
prompt=XmCreateMessageDialog(antiright.parent_widget, |
|
|
"Find and Replace", |
|
|
antiright.arguments, |
|
|
antiright.arguments_int); |
|
|
XtManageChild(prompt); |
|
|
ARCLARG; |
|
|
form=antiright_form(prompt); |
|
|
ARCLARG; |
|
|
antiright_form_positions(0, 50, 0, 25); |
|
|
antiright_set(XmNalignment, XmALIGNMENT_END); |
|
|
antiright_label(form, "Find:"); |
|
|
ARCLARG; |
|
|
antiright_form_positions(0, 50, 25, 100); |
|
|
arshell.edit.find_widget=XmCreateTextField(form, "find_widget", |
|
|
antiright.arguments, |
|
|
antiright.arguments_int); |
|
|
antiright_set_tooltip(arshell.edit.find_widget, |
|
|
"Enter the text that is to be found here."); |
|
|
XtManageChild(arshell.edit.find_widget); |
|
|
ARCLARG; |
|
|
antiright_form_positions(50, 100, 0, 25); |
|
|
antiright_set(XmNalignment, XmALIGNMENT_END); |
|
|
antiright_label(form, "Replace:"); |
|
|
ARCLARG; |
|
|
antiright_form_positions(50, 100, 25, 100); |
|
|
arshell.edit.replace_widget=XmCreateTextField(form, "replace_widget", |
|
|
antiright.arguments, |
|
|
antiright.arguments_int); |
|
|
antiright_set_tooltip(arshell.edit.replace_widget, |
|
|
"Enter the replacement text here."); |
|
|
XtManageChild(arshell.edit.replace_widget); |
|
|
XtAddCallback(prompt, |
|
|
XmNokCallback, |
|
|
arshell_replace_ok_cb, |
|
|
NULL); |
|
|
XtAddCallback(prompt, |
|
|
XmNhelpCallback, |
|
|
antiright_help_cb, |
|
|
"Enter_the_text_that_you_want_to_find_and_replace_in_the_" |
|
|
"appropriate_text_field."); |
|
|
|
|
|
widget=(Widget)NULL; |
|
|
call_data=(XtPointer)NULL; |
|
|
} |
|
|
|
|
24 |
/* This is a simple method of printing the current file. */ |
/* This is a simple method of printing the current file. */ |
25 |
void |
void |
26 |
arshell_print_cb() |
arshell_print_cb() |
35 |
system(command); /* Print the file. */ |
system(command); /* Print the file. */ |
36 |
free(command); /* Free the unneeded memory. */ |
free(command); /* Free the unneeded memory. */ |
37 |
} |
} |
|
|
|
38 |
void |
void |
39 |
arshell_value_changed_cb() |
arshell_value_changed_cb() |
40 |
{ |
{ |
51 |
|
|
52 |
arshell.flags.modified=True; |
arshell.flags.modified=True; |
53 |
} |
} |
|
|
|
54 |
void |
void |
55 |
arshell_text_return_cb(Widget parent_widget, |
arshell_text_return_cb(Widget parent_widget, |
56 |
XtPointer client_data, |
XtPointer client_data, |
63 |
call_data=(XtPointer)NULL; |
call_data=(XtPointer)NULL; |
64 |
exit(0); |
exit(0); |
65 |
} |
} |
|
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; |
|
|
} |
|
66 |
int |
int |
67 |
arshell_line(XmTextPosition end_position) |
arshell_line(XmTextPosition end_position) |
68 |
{ |
{ |
98 |
antiright_status(status); |
antiright_status(status); |
99 |
free(status); |
free(status); |
100 |
} |
} |
|
|
|
|
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(); |
|
|
} |
|
|
} |
|
101 |
void |
void |
102 |
arshell_get_rid_of_modified_status() |
arshell_get_rid_of_modified_status() |
103 |
{ |
{ |
104 |
if(arshell.flags.modified) |
if(arshell.flags.modified) |
105 |
arshell.flags.modified=False; |
arshell.flags.modified=False; |
106 |
} |
} |
|
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); |
|
|
} |
|
|
} |
|
107 |
|
|
108 |
void |
void |
109 |
arshell_set_work_area_arguments() |
arshell_set_work_area_arguments() |
117 |
antiright_set(XmNrows, 24); |
antiright_set(XmNrows, 24); |
118 |
} |
} |
119 |
void |
void |
|
arshell_save_as_cb() |
|
|
{ |
|
|
arshell_select_filename(); |
|
|
arshell_save_work_area(); |
|
|
} |
|
|
|
|
|
void |
|
|
arshell_open_cb() |
|
|
{ |
|
|
arshell.flags.opening=True; |
|
|
arshell_select_filename(); |
|
|
} |
|
|
|
|
|
void |
|
|
arshell_setup_work_menubar() |
|
|
{ |
|
|
ARCLARG; |
|
|
if(arshell.gui.menubar.file_widget != NULL) |
|
|
{ |
|
|
antiright_button(arshell.gui.menubar.file_widget, "Save", |
|
|
arshell_save_work_area, NULL); |
|
|
antiright_button(arshell.gui.menubar.file_widget, "Save As", |
|
|
arshell_save_as_cb, NULL); |
|
|
antiright_button(arshell.gui.menubar.file_widget, "Open", |
|
|
arshell_open_cb, NULL); |
|
|
antiright_button(arshell.gui.menubar.file_widget, "Insert", |
|
|
arshell_insert_file_cb, NULL); |
|
|
antiright_button(arshell.gui.menubar.file_widget, "Print", |
|
|
arshell_print_cb, NULL); |
|
|
arshell.gui.menubar.edit_widget= |
|
|
antiright_edit_menu(arshell.gui.menubar.menubar_widget, |
|
|
arshell.gui.widgets.work); |
|
|
antiright_separator(arshell.gui.menubar.edit_widget); |
|
|
antiright_button(arshell.gui.menubar.edit_widget, "Search", |
|
|
arshell_search_cb, NULL); |
|
|
antiright_button(arshell.gui.menubar.edit_widget, "Replace", |
|
|
arshell_replace_cb, NULL); |
|
|
antiright_button(arshell.gui.menubar.edit_widget, "Find at Cursor", |
|
|
arshell_find_at_cursor_cb, NULL); |
|
|
antiright_separator(arshell.gui.menubar.view_widget); |
|
|
{ |
|
|
Widget button; |
|
|
arshell_initialize_row_manager(); |
|
|
ARCLARG; |
|
|
antiright_set(XmNmarginWidth, 0); |
|
|
antiright_set(XmNmarginHeight, 0); |
|
|
antiright_set(XmNpacking, XmPACK_TIGHT); |
|
|
antiright_set(XmNorientation, XmHORIZONTAL); |
|
|
antiright_set(XmNspacing, 0); |
|
|
arshell.edit.toolbar= |
|
|
antiright_row(arshell.gui.layout.row_manager_widget); |
|
|
{ |
|
|
char *title; |
|
|
ARCLARG; |
|
|
antiright_set(XmNtitle, (XtArgVal)&title); |
|
|
antiright_get_values(antiright.parent_widget); |
|
|
puts(title); |
|
|
if((title[0]=='S') & (title[1]=='t') & (title[2]=='i')) |
|
|
{ |
|
|
XtUnmanageChild(arshell.edit.toolbar); |
|
|
} |
|
|
ARCLARG; |
|
|
} |
|
|
|
|
|
ARCLARG; |
|
|
button=antiright_button(arshell.edit.toolbar, "Open", arshell_open_cb, |
|
|
NULL); |
|
|
antiright_set_tooltip(button, "Open a file. "); |
|
|
button=antiright_button(arshell.edit.toolbar, "Save", |
|
|
arshell_save_work_area, NULL); |
|
|
antiright_set_tooltip(button, "Save the current file. "); |
|
|
button=antiright_button(arshell.edit.toolbar, "Print", |
|
|
arshell_print_cb, NULL); |
|
|
antiright_set_tooltip(button, "Print the current file. "); |
|
|
button=antiright_button(arshell.edit.toolbar, "Cut", antiright_cut_cb, |
|
|
arshell.gui.widgets.work); |
|
|
antiright_set_tooltip(button, "Cut a selection into the clipboard."); |
|
|
button=antiright_button(arshell.edit.toolbar, "Copy", |
|
|
antiright_copy_cb, |
|
|
arshell.gui.widgets.work); |
|
|
antiright_set_tooltip(button, "Copy a selection into the clipboard"); |
|
|
button=antiright_button(arshell.edit.toolbar, "Paste", |
|
|
antiright_paste_cb, |
|
|
arshell.gui.widgets.work); |
|
|
antiright_set_tooltip(button, "Paste the contents of the clipboard."); |
|
|
button=antiright_button(arshell.edit.toolbar, "Search", |
|
|
arshell_search_cb, NULL); |
|
|
antiright_set_tooltip(button, "Search for text."); |
|
|
button=antiright_button(arshell.edit.toolbar, "Replace", |
|
|
arshell_replace_cb, NULL); |
|
|
antiright_set_tooltip(button, "Find and replace text."); |
|
|
} |
|
|
} |
|
|
} |
|
|
void |
|
120 |
arshell_modify_verify_cb(Widget widget, XtPointer client_data, |
arshell_modify_verify_cb(Widget widget, XtPointer client_data, |
121 |
XtPointer call_data) |
XtPointer call_data) |
122 |
{ |
{ |
179 |
XmTextGetInsertionPosition(arshell.gui.widgets.work), buffer); |
XmTextGetInsertionPosition(arshell.gui.widgets.work), buffer); |
180 |
XmTextSetInsertionPosition(arshell.gui.widgets.work, 0); |
XmTextSetInsertionPosition(arshell.gui.widgets.work, 0); |
181 |
} |
} |
|
|
|
|
|
|
182 |
void |
void |
183 |
arshell_create_default_text_entry(Widget widget_row_widget, |
arshell_create_default_text_entry(Widget widget_row_widget, |
184 |
int* counter_int, |
int* counter_int, |