Menu

[r121]: / actions.cpp  Maximize  Restore  History

Download this file

733 lines (604 with data), 20.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/*
The actions.cpp file is to define the interaction action funcitons when the user does something.
*/
//includes for prototypes
#include "actions.h"
//double checks to makes sure the user didn't forget to save
void save_checker(int key)
{
g_print("Checking for none saved files...\n");
//for when the tab is closed by it's lonesome
if (key!=0)
{
if (gtk_text_buffer_get_modified(GTK_TEXT_BUFFER(tab[key].buffer)))
{
g_print("Running Save Dialog...\n");
do
{
//holds the file selection widget proccess (file_sel)
gtk_dialog_run(GTK_DIALOG(save_check));
}
while (GTK_WIDGET_VISIBLE(save_check));
}
//since it's only one tab, we can return
return;
}
//goes through all the tabs to make sure their saved
for (int i=0; i<maxtabs && tmpall!=1 && canpass!=1;)
{
g_print("Checking Page...\n");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), i);
if (gtk_text_buffer_get_modified(GTK_TEXT_BUFFER(tab[i+1].buffer)))
{
g_print("Running Save Dialog...\n");
do
{
//holds the file selection widget proccess (file_sel)
gtk_dialog_run(GTK_DIALOG(save_check));
}
while (GTK_WIDGET_VISIBLE(save_check) && tmpall!=1 && canpass!=1);
g_print("Save Dialog Closed\n");
}
i++;
}
//reset tmp holder
tmpall=0;
return;
}
//main quit app
gint destroyapp(GtkWidget *widget, gpointer gdata)
{
save_checker(0);
//checks to see if cancled was not clicked
if (canpass==0)
{
g_print("Quitting...\n");
gtk_main_quit();
}
else
{
canpass=0;
return 1;
}
return 0;
}
//file paramters checker
gint fileprmp()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
g_print("Checking Paramters...\n");
if (fileprmt)
{
g_print("Paramter Found\n");
g_print("Opening Paramter File...\n");
tab[curtab].filename=fileprmt;
gtk_notebook_set_tab_label(GTK_NOTEBOOK(notebook), tab[curtab].scroller, gtk_label_new(g_path_get_basename(tab[curtab].filename)));
g_file_get_contents(tab[curtab].filename, &tab[curtab].contents, &tab[curtab].length, &tab[curtab].err);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(tab[curtab].buffer), tab[curtab].contents, -1);
gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(tab[curtab].buffer), FALSE);
g_print("Paramter File Opened\n");
}
else
{
g_print("No Paramter Found\n");
}
g_print("Paramter Checking Done\n");
return 0;
}
//To close the save_check, when a button is selected.
gint check_x()
{
//hide the widget for later open actions
g_print("Checking for Save_Check...\n");
if (GTK_WIDGET_VISIBLE(save_check))
{
g_print("Save_Check Visable\n");
gtk_widget_hide(save_check);
g_print("Save_Check Hidden\n");
}
return 0;
}
//event when "Canceled" button is clicked on the file selection widget
gint file_sel_x(GtkWidget *w, GtkFileSelection *fs)
{
//hide the widget for later open actions
gtk_widget_hide(filesel);
g_print("Hid File Selection\n");
//close the tab that was created
if (openpass==1)
{
on_tab_x();
openpass=0;
}
return 0;
}
//event when "Ok" button is clicked on the file selection widget
gint file_sel(GtkWidget *w, GtkFileSelection *fs)
{
//get filename from slection widget and hide the widget for later open actions
g_print("Retriving File Information...\n");
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
tab[curtab].filename=(gchar*)gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs));
gtk_widget_hide(filesel);
gtk_notebook_set_tab_label(GTK_NOTEBOOK(notebook), tab[curtab].scroller, gtk_label_new(g_path_get_basename(tab[curtab].filename)));
return 0;
}
//new event
gint on_new()
{
if (tabcount==maxtabs+1)
{
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), tabcount-2);
return 1;
}
g_print("Opening New Tab...\n");
newup=1;
tab[tabcount].buffer=gtk_source_buffer_new(NULL);
tab[tabcount].textview=gtk_source_view_new_with_buffer(tab[tabcount].buffer);
tab[tabcount].scroller=gtk_scrolled_window_new(NULL, NULL);
gtk_source_buffer_begin_not_undoable_action(tab[tabcount].buffer);
gtk_source_buffer_end_not_undoable_action(tab[tabcount].buffer);
gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(tab[tabcount].buffer), FALSE);
//syntax highlighting
on_syntax(tabcount);
//sets scrollers and editability for text_view
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tab[tabcount].scroller), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(tab[tabcount].scroller), GTK_SHADOW_IN);
gtk_text_view_set_editable(GTK_TEXT_VIEW(tab[tabcount].textview), TRUE);
gtk_container_add(GTK_CONTAINER(tab[tabcount].scroller), tab[tabcount].textview);
//checks for first time for plus
if (tabcount==0)
{
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), tab[tabcount].scroller, gtk_label_new("+"), maxtabs);
newup=1;
}
else
{
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), tab[tabcount].scroller, gtk_label_new("..."), tabcount-1);
}
//programming environment
gtk_source_view_set_auto_indent(GTK_SOURCE_VIEW(tab[tabcount].textview), true);
gtk_source_view_set_highlight_current_line(GTK_SOURCE_VIEW(tab[tabcount].textview), true);
//show
gtk_widget_show(tab[tabcount].scroller);
gtk_widget_show(tab[tabcount].textview);
on_linen();
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), tabcount-1);
//switch to keep from looping
if (tabcount==0)
{
newup=1;
}
tabcount++;
return 0;
}
//function to check if the plus tab was clicked
gint on_tab_plus()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
if (curtab==tabcount && newup!=1)
{
on_new();
}
newup=0;
return 0;
}
//open file event
gint on_open()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks to see if the content has already been edited
g_print("Checking Modified Buffer...\n");
if (gtk_text_buffer_get_char_count(GTK_TEXT_BUFFER(tab[curtab].buffer)))
{
if (on_new()==1)
{
return 0;
}
}
openpass=1;
//checks if a file was previously opened and sets the default directory to it's location
g_print("Retriving Old Path...\n");
if (tab[curtab].filename)
{
gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), tab[curtab].filename);
}
//loops and waits for the widget to close
g_print("Starting File Selection...\n");
do
{
//holds the file selection widget proccess (file_sel)
gtk_dialog_run(GTK_DIALOG(filesel));
}
while (GTK_WIDGET_VISIBLE(filesel));
g_print("File Selection Done\n");
//get file information and set file contents to the buffer
g_file_get_contents(tab[curtab].filename, &tab[curtab].contents, &tab[curtab].length, &tab[curtab].err);
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(tab[curtab].buffer), tab[curtab].contents, -1);
gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(tab[curtab].buffer), FALSE);
gtk_source_buffer_begin_not_undoable_action(tab[tabcount].buffer);
gtk_source_buffer_end_not_undoable_action(tab[tabcount].buffer);
//syntax highlighting
on_syntax(tabcount);
g_print("Wrote Content\n");
return 0;
}
//save file event
gint on_save()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks for save_check
check_x();
//checks to see if the filename isn't specified and opens the file selection process
g_print("Checking Old Filename...\n");
if (!tab[curtab].filename)
{
g_print("Old Path Not Found\n");
//loops and waits for the widget to close
g_print("Starting File Selection...\n");
do
{
//holds the file selection widget proccess (file_sel)
gtk_dialog_run(GTK_DIALOG(filesel));
}
while (GTK_WIDGET_VISIBLE(filesel));
g_print("File Selection Done\n");
//checks to see if the Canceled button was pressed instead of ok
if (!tab[curtab].filename)
{
return 0;
}
}
//delcare some temp vars
g_print("Retriving File...\n");
gchar *text;
gsize rbytes, wbytes;
GError *err = NULL;
FILE *fp;
//finds the iters
gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tab[curtab].buffer), &start);
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(tab[curtab].buffer), &end);
//temp stores the content of the buffer
text=gtk_text_buffer_get_text(GTK_TEXT_BUFFER(tab[curtab].buffer), &start, &end, FALSE);
//converts the content to UTF-8
text=g_convert(text, -1, &tab[curtab].charset, "UTF-8", &rbytes, &wbytes, &err);
//open the file to be stored and puts the content in
fp=fopen(tab[curtab].filename, "w");
fputs(text, fp);
//set variations off, close the file, free up room
gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(tab[curtab].buffer), FALSE);
fclose(fp);
g_free(text);
//syntax_open();
return 0;
}
//save as event
gint on_save_as()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks for save_check
check_x();
//checks if a file was previously opened and sets the default directory to it's location
g_print("Checking Old Path...\n");
if (tab[curtab].filename)
{
g_print("Defining Old File Path...\n");
gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), tab[curtab].filename);
}
//loops and waits for the widget to close
g_print("Running File Selection...\n");
do
{
//holds the file selection widget proccess (file_sel)
gtk_dialog_run(GTK_DIALOG(filesel));
}
while (GTK_WIDGET_VISIBLE(filesel));
g_print("File Selection Done\n");
//checks to see if the Canceled button was pressed instead of ok
if (!tab[curtab].filename)
{
return 0;
}
//triggers the save event
on_save();
return 0;
}
//event when "Don't Save Any" button is clicked on the save_check
gint on_save_none()
{
//set to tell that this button was clicked
tmpall=1;
//hide the widget for later open actions
if (GTK_WIDGET_VISIBLE(save_check))
{
gtk_widget_hide(save_check);
g_print("Save_Check Hidden\n");
}
return 0;
}
//event when "Save All" button is clicked on the save_check
gint on_save_all()
{
//checks for save_check
check_x();
//goes through all the tabs to sve
for (int i=0; i<maxtabs;)
{
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), i);
if (gtk_text_buffer_get_modified(GTK_TEXT_BUFFER(tab[i].buffer)))
{
on_save();
}
i++;
}
//destroy app
g_print("Quitting...\n");
gtk_main_quit();
return 0;
}
//Save All for menu
gint on_save_all_menu()
{
//goes through all the tabs to sve
for (int i=0; i<maxtabs;)
{
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), i);
if (gtk_text_buffer_get_modified(GTK_TEXT_BUFFER(tab[i].buffer)))
{
on_save();
}
i++;
}
return 0;
}
//event when "Cancel" button is clicked on the save_check
gint on_save_cancel()
{
//sets the passing variable and returns
g_print("Canceling Quit");
//hide the widget for later open actions
if (GTK_WIDGET_VISIBLE(save_check))
{
gtk_widget_hide(save_check);
g_print("Save_Check Hidden\n");
}
canpass=1;
return 0;
}
//close tab event
gint on_tab_x()
{
curtab=gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
save_checker(curtab+1);
//checks for cancle
if (canpass!=1)
{
gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), curtab);
g_print("Page Removed\n");
//moves all the tab data to match up
g_print("Moving Tab Data...\n");
for (int i=curtab; i<maxtabs-1;)
{
tab[i]=tab[i+1];
i++;
}
tabcount--;
//checks to see if all that is left is the plus
if (tabcount==1)
{
on_new();
}
//checks to see if the last tab before the plus was closed
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
if (curtab==tabcount)
{
on_prevp();
}
}
else
{
canpass=0;
}
return 0;
}
//search box event
gint on_search()
{
//loops and waits for the widget to close
g_print("Starting Search Box...\n");
do
{
//holds the file selection widget proccess (search_box)
gtk_dialog_run(GTK_DIALOG(search_box));
}
while (GTK_WIDGET_VISIBLE(search_box));
g_print("Search Box Done\n");
return 0;
}
//copy event
gint on_copy()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(tab[curtab].buffer), gtk_clipboard_get(GDK_NONE));
g_print("Copied\n");
return 0;
}
//paste event
gint on_paste()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(tab[curtab].buffer), gtk_clipboard_get(GDK_NONE), NULL, TRUE);
g_print("Pasted\n");
return 0;
}
//cut event
gint on_cut()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(tab[curtab].buffer), gtk_clipboard_get(GDK_NONE), TRUE);
g_print("Cut\n");
return 0;
}
//delete event
gint on_del()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
gtk_text_buffer_delete_selection(GTK_TEXT_BUFFER(tab[curtab].buffer), TRUE, TRUE);
g_print("Deleted\n");
return 0;
}
//select all event
gint on_sel_all()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//finds iters
gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(tab[curtab].buffer), &start);
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(tab[curtab].buffer), &end);
//place the cursor at the end
gtk_text_buffer_place_cursor(GTK_TEXT_BUFFER(tab[curtab].buffer), &end);
//moves the selection bound from the end through the start
gtk_text_buffer_move_mark_by_name(GTK_TEXT_BUFFER(tab[curtab].buffer), "selection_bound", &start);
g_print("Selected All\n");
return 0;
}
//undo event
gint on_undo()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//undoes
gtk_source_buffer_undo(tab[curtab].buffer);
return 0;
}
//uredo event
gint on_redo()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//redoes
gtk_source_buffer_redo(tab[curtab].buffer);
return 0;
}
//next tab
gint on_nextp()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks to make sure the plus wasn't hit
if (curtab==tabcount-1)
{
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 0);
}
else
{
gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
}
g_print("Next Tab\n");
return 0;
}
//previous tab
gint on_prevp()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks to see if it's at the begining
if (curtab==1)
{
gtk_notebook_set_page(GTK_NOTEBOOK(notebook), tabcount-2);
}
else
{
gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
}
g_print("Previous Tab\n");
return 0;
}
//fullscreen event switch
gint on_fullscn()
{
//temp vars
GtkItemFactory *ifactory;
gboolean state;
//checks for the checkmark sets the wordwrap accordingly
ifactory=gtk_item_factory_from_widget(menubar);
state=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/View/Full Screen")));
if (!state)
{
gtk_window_unfullscreen(GTK_WINDOW(window));
}
else
{
gtk_window_fullscreen(GTK_WINDOW(window));
}
return 0;
}
//word wrap check box trigger
gint on_wrap()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//temp vars
GtkItemFactory *ifactory;
gboolean state;
//checks for the checkmark sets the wordwrap accordingly
ifactory=gtk_item_factory_from_widget(menubar);
state=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/View/Word Wrap")));
for (int i=0; i<maxtabs;)
{
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tab[i+1].textview), state ? GTK_WRAP_WORD : GTK_WRAP_NONE);
i++;
}
g_print("Word Wrap Switched\n");
return 0;
}
//line number check box trigger
gint on_linen()
{
curtab=1+gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
//checks for the checkmark sets the line numbering accordingly
ifactory=gtk_item_factory_from_widget(menubar);
state=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/View/Line Numbers")));
for (int i=0; i<maxtabs;)
{
gtk_source_view_set_show_line_numbers(GTK_SOURCE_VIEW(tab[i+1].textview), state);
//gtk_source_view_set_show_line_marks(GTK_SOURCE_VIEW(tab[i+1].textview), state);
i++;
}
g_print("Line Numbering Switched\n");
return 0;
}
//about diolog event
gint on_about()
{
//holds the information needed
g_print("Defining About Information...\n");
const gchar *name="Devchekio";
const gchar *version="v0.9.5";
const GdkPixbuf *logo=gdk_pixbuf_new_from_file("images/icon_256.png", tmppixbuf);
const gchar *website="http://www.blahertech.org/projects/devchekio/";
const gchar *copyright="Copyright Blahertech 2007-2008 Benjamin Jay Young";
const gchar *comments="GTK+ Check in/out code editor";
//authors
const gchar *authors[]=
{
"Ben Young (Project Leader) <Blaher>",
"Zach Serafini (Developer)",
"Harry Rickards (Linux Packages) <L33tmyst>",
"Thulasi R (Mac OSX Porter) <Travinan>",
NULL
};
//artists
const gchar *artists[]=
{
"James Nicholls (Logo Designer) <Niknaks1993>",
NULL
};
//sends the info to setup the about diolog box widget
g_print("Showing About Dialog...\n");
gtk_show_about_dialog(GTK_WINDOW(window),
"name", name,
"version", version,
"logo", logo,
"website", website,
"copyright", copyright,
"comments", comments,
"authors", authors,
"artists", artists,
NULL);
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.