00001
00002 #include <gtk/gtk.h>
00003 #include <stdio.h>
00004 #include <errno.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007
00008 extern GtkWidget *view;
00009 GtkWidget *text_view;
00011 GtkWidget *search_entry;
00012
00014 GtkWidget *replace_entry;
00015
00019 void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter)
00020 {
00021 GtkTextIter mstart, mend;
00022 GtkTextBuffer *buffer;
00023 gboolean found;
00024
00025 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view));
00026 found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);
00027
00028 if (found)
00029 {
00030 gtk_text_buffer_select_range (buffer, &mstart, &mend);
00031 gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE);
00032 }
00033 }
00037 void win_destroy (void)
00038 {
00039 gtk_main_quit();
00040 }
00041
00045 void next_button_clicked (GtkWidget *next_button)
00046 {
00047 const gchar *text;
00048 GtkTextBuffer *buffer;
00049 GtkTextMark *last_pos;
00050 GtkTextIter iter;
00051
00052 text = gtk_entry_get_text (GTK_ENTRY (search_entry));
00053 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view));
00054 last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
00055
00056 if (last_pos == NULL)
00057 {
00058 GtkWidget *window1;
00059 GtkWidget *label;
00060
00061 window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00062 gtk_window_set_title (GTK_WINDOW (window1), "Search");
00063 gtk_window_set_default_size(GTK_WINDOW(window1), 50, 300);
00064
00065
00066 label = gtk_label_new ("End of Search!!!! \n\n");
00067
00068 gtk_container_add (GTK_CONTAINER (window1), label);
00069
00070 gtk_widget_show_all (window1);
00071
00072 return;
00073
00074 }
00075
00076 gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos);
00077 find (GTK_TEXT_VIEW (text_view),(gchar *)gtk_entry_get_text((GtkEntry *)search_entry), &iter);
00078 }
00079
00083 void search_button_clicked (GtkWidget *search_button)
00084 {
00085
00086 GtkTextBuffer *buffer;
00087 GtkTextIter iter;
00088
00089 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view));;
00090 gtk_text_buffer_get_start_iter(buffer, &iter);
00091
00092 find (GTK_TEXT_VIEW(text_view),(gchar *)gtk_entry_get_text((GtkEntry *)search_entry),&iter);
00093 }
00094
00098 void textfind(void)
00099 {
00100 GtkWidget *win;
00101 GtkWidget *vbox;
00102 GtkWidget *hbox;
00103 GtkWidget *search_button;
00104 GtkWidget *next_button;
00105
00106
00107 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00108
00109 vbox = gtk_vbox_new (FALSE, 2);
00110 gtk_container_add (GTK_CONTAINER (win), vbox);
00111
00112 hbox = gtk_hbox_new (FALSE, 2);
00113
00114 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00115
00116 text_view = view;
00117 search_entry = gtk_entry_new();
00118
00119 gtk_box_pack_start (GTK_BOX (hbox),search_entry, TRUE, TRUE, 0);
00120
00121 search_button = gtk_button_new_with_label ("Search");
00122 gtk_box_pack_start (GTK_BOX (hbox), search_button, FALSE, FALSE, 0);
00123 g_signal_connect(G_OBJECT (search_button), "clicked",G_CALLBACK (search_button_clicked), NULL);
00124
00125 next_button = gtk_button_new_with_label ("Next");
00126 gtk_box_pack_start (GTK_BOX (hbox), next_button, FALSE, FALSE, 0);
00127 g_signal_connect (G_OBJECT (next_button), "clicked",G_CALLBACK (next_button_clicked), NULL);
00128
00129
00130
00131 gtk_widget_show_all(win);
00132 }
00133
00134
00135
00139 void replace (GtkTextView *text_view, const gchar *text,const gchar *text1, GtkTextIter *iter)
00140 {
00141 GtkTextIter mstart, mend;
00142 GtkTextBuffer *buffer;
00143 gboolean found;
00144
00145 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(text_view));
00146 found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);
00147 if (found)
00148 {
00149 gtk_text_buffer_select_range (buffer, &mstart, &mend);
00150 gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE);
00151
00152 int len=strlen(text1);
00153 gtk_text_buffer_delete(buffer,&mstart,&mend);
00154 gtk_text_buffer_insert(buffer,&mstart,text1,len);
00155 }
00156 }
00160 void replace_button_clicked(GtkWidget *replace_button)
00161 {
00162 GtkTextBuffer *buffer;
00163 GtkTextIter iter;
00164
00165 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
00166 gtk_text_buffer_get_start_iter(buffer, &iter);
00167
00168 replace (GTK_TEXT_VIEW(text_view),(gchar *)gtk_entry_get_text((GtkEntry *)search_entry),(gchar *)gtk_entry_get_text((GtkEntry *)replace_entry),&iter);
00169 }
00170
00174 void text_find_replace(void)
00175 {
00176 GtkWidget *win;
00177 GtkWidget *vbox;
00178 GtkWidget *hbox;
00179 GtkWidget *search_button;
00180 GtkWidget *replace_button;
00181
00182 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00183
00184 vbox = gtk_vbox_new (FALSE, 2);
00185 gtk_container_add (GTK_CONTAINER (win), vbox);
00186
00187 hbox = gtk_hbox_new (FALSE, 2);
00188 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00189
00190 text_view = view;
00191
00192 search_entry = gtk_entry_new();
00193 replace_entry = gtk_entry_new();
00194
00195 gtk_box_pack_start (GTK_BOX (hbox),search_entry, TRUE, TRUE, 0);
00196 gtk_box_pack_start (GTK_BOX (hbox),replace_entry, TRUE, TRUE, 0);
00197
00198 search_button = gtk_button_new_with_label ("Search");
00199 gtk_box_pack_start (GTK_BOX (hbox), search_button, FALSE, FALSE, 0);
00200 g_signal_connect(G_OBJECT (search_button), "clicked",G_CALLBACK (search_button_clicked), NULL);
00201
00202 replace_button = gtk_button_new_with_label ("Replace");
00203 gtk_box_pack_start (GTK_BOX (hbox), replace_button, FALSE, FALSE, 0);
00204 g_signal_connect (G_OBJECT (replace_button),"clicked",G_CALLBACK (replace_button_clicked), NULL);
00205
00206 gtk_widget_show_all(win);
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00219 void show_about(void)
00220 {
00221
00222 GtkWidget *window1;
00223 GtkWidget *label;
00224 char about[300];
00225 window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00226 gtk_window_set_title (GTK_WINDOW (window1), "About Text Editor for C");
00227 gtk_window_set_default_size(GTK_WINDOW(window1), 300, 300);
00228
00229
00230 strcpy(about,"This is C editor used for compilation of C programs.\n\n This has features for syntax highlighting and highlights the"
00231 "lines that contains errors.\n ");
00232
00233 strcat(about,"\0");
00234 label = gtk_label_new (about);
00235 gtk_container_add (GTK_CONTAINER (window1), label);
00236
00237 gtk_widget_show_all (window1);
00238 }
00239
00245 void show_help(void)
00246 {
00247
00248 GtkWidget *window1;
00249 GtkWidget *label;
00250 char help[5000];
00251 window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00252 gtk_window_set_title (GTK_WINDOW (window1), "Help");
00253 gtk_window_set_default_size(GTK_WINDOW(window1), 300, 300);
00254
00255
00256 strcpy(help,"\nTo Create a New C file, choose file -> New. The application displays a new file in the C editor.\n\nTo Save a File\n - To save changes in an existing file, choose File -> Save.\n - To save a new file or to save an existing file under a new filename, choose File -> Save As. Enter a name for the file in the Save As dialog, then click Save.\n\nTo Edit text\n\n - To copy the selected text to a buffer, choose Edit -> Copy.\n - To delete the selected text from the file and move the selected text to a buffer, choose Edit -> Cut.\n - To insert the contents of the buffer at the cursor position, choose Edit -> Paste.You must cut or copy text before you can paste text into the file.\n - To select all of the text in the file, choose Edit -> Select All.\n\nTo Find Text\n\n - Choose Search -> Find to display the Find dialog.\n-Type the string that you want to find, in the text box.\n- Click Find to search the file for the first occurence of the string.\n If the editor finds the string, application moves the cursor position to the string, and selects the string.\n- To find the next occurence of the string, click Next\n\nTo Find and Replace Text\n\nChoose Search -> Replace to display the Replace dialog.\n-Type the string that you want to find, in the Search For field.\n-Click Find to search the file for the first occurence of the string.\n If the editor finds the string, application moves the cursor position to the string, and selects the string.\n- Click Replace to replace the occurences of the string with the text in the Replace with field. \n- To find the next occurence of the string,click Next.\n\nTo Compile:-\n Select the file to be complied. \nThe file gets displayed on the window1 with all the keywords highlighted.\n Now click on gcc button to compile the code.\n If any errors , they would be displayed in the bottom window and would be highlighted in gray in the main program.\n To view the error at a particular line, click on the error in the window2 and it gets highlighted in the program in yellow.\n. If no errors then the .o file would be created in the current folder.");
00257
00258
00259 strcat(help,"\0");
00260 label = gtk_label_new (help);
00261 gtk_container_add (GTK_CONTAINER (window1), label);
00262 gtk_widget_show_all (window1);
00263
00264 }