~ubuntu-branches/debian/sid/genius/sid

« back to all changes in this revision

Viewing changes to src/gnome-genius.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-02-06 09:45:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070206094534-02k3egxuiyuswl7c
Tags: 0.7.7-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GENIUS Calculator
2
 
 * Copyright (C) 1997-2006 Jiri (George) Lebl
 
2
 * Copyright (C) 1997-2007 Jiri (George) Lebl
3
3
 *
4
4
 * Author: Jiri (George) Lebl
5
5
 *
87
87
static GtkWidget *term = NULL;
88
88
static GtkWidget *appbar = NULL;
89
89
static GtkWidget *notebook = NULL;
 
90
static GtkTooltips *tips;
90
91
static GString *errors=NULL;
91
92
static GString *infos=NULL;
92
93
 
98
99
 
99
100
static char *last_dir = NULL;
100
101
 
 
102
static GList *prog_menu_items = NULL;
 
103
 
101
104
GeniusSetup genius_setup = {
102
105
        FALSE /* error_box */,
103
106
        TRUE /* info_box */,
104
107
        TRUE /* blinking_cursor */,
105
108
        1000 /* scrollback */,
106
109
        NULL /* font */,
107
 
        FALSE /* black on white */
 
110
        FALSE /* black on white */,
 
111
        FALSE /* output_remember */,
 
112
        FALSE /* precision_remember */
108
113
};
109
114
 
110
115
typedef struct {
182
187
static void load_cb (GtkWidget *w);
183
188
static void reload_cb (GtkWidget *w);
184
189
static void quitapp (GtkWidget * widget, gpointer data);
 
190
#ifdef HAVE_GTKSOURCEVIEW
 
191
static void setup_undo_redo (void);
 
192
static void undo_callback (GtkWidget *menu_item, gpointer data);
 
193
static void redo_callback (GtkWidget *menu_item, gpointer data);
 
194
#endif
185
195
static void cut_callback (GtkWidget *menu_item, gpointer data);
186
196
static void copy_callback (GtkWidget *menu_item, gpointer data);
187
197
static void paste_callback (GtkWidget *menu_item, gpointer data);
193
203
static void copy_as_latex (GtkWidget *menu_item, gpointer data);
194
204
static void copy_as_troff (GtkWidget *menu_item, gpointer data);
195
205
static void copy_as_mathml (GtkWidget *menu_item, gpointer data);
 
206
static void next_tab (GtkWidget *menu_item, gpointer data);
 
207
static void prev_tab (GtkWidget *menu_item, gpointer data);
 
208
static void prog_menu_activated (GtkWidget *item, gpointer data);
196
209
static void setup_calc (GtkWidget *widget, gpointer data);
197
210
static void run_program (GtkWidget *menu_item, gpointer data);
 
211
static void full_answer (GtkWidget *menu_item, gpointer data);
198
212
static void warranty_call (GtkWidget *widget, gpointer data);
199
213
static void aboutcb (GtkWidget * widget, gpointer data);
200
214
static void help_on_function (GtkWidget *menuitem, gpointer data);
220
234
};
221
235
 
222
236
static GnomeUIInfo edit_menu[] = {  
 
237
#ifdef HAVE_GTKSOURCEVIEW
 
238
#define EDIT_UNDO_ITEM 0
 
239
        GNOMEUIINFO_MENU_UNDO_ITEM(undo_callback,NULL),
 
240
#define EDIT_REDO_ITEM 1
 
241
        GNOMEUIINFO_MENU_REDO_ITEM(redo_callback,NULL),
 
242
        GNOMEUIINFO_SEPARATOR,
 
243
#define EDIT_CUT_ITEM 3
 
244
        GNOMEUIINFO_MENU_CUT_ITEM(cut_callback,NULL),
 
245
#define EDIT_COPY_ITEM 4
 
246
        GNOMEUIINFO_MENU_COPY_ITEM(copy_callback,NULL),
 
247
#else
223
248
#define EDIT_CUT_ITEM 0
224
249
        GNOMEUIINFO_MENU_CUT_ITEM(cut_callback,NULL),
225
250
#define EDIT_COPY_ITEM 1
226
251
        GNOMEUIINFO_MENU_COPY_ITEM(copy_callback,NULL),
 
252
#endif
227
253
        GNOMEUIINFO_MENU_PASTE_ITEM(paste_callback,NULL),
228
254
        GNOMEUIINFO_SEPARATOR,
229
255
        GNOMEUIINFO_ITEM_STOCK(N_("Copy Answer As Plain _Text"),
255
281
        GNOMEUIINFO_ITEM_STOCK(N_("_Run"),N_("Run current program"),run_program, GTK_STOCK_EXECUTE),
256
282
        GNOMEUIINFO_ITEM_STOCK(N_("_Interrupt"),N_("Interrupt current calculation"),genius_interrupt_calc,GTK_STOCK_STOP),
257
283
        GNOMEUIINFO_SEPARATOR,
 
284
        GNOMEUIINFO_ITEM_STOCK (N_("Show _Full Answer"), N_("Show the full text of last answer"), full_answer, GTK_STOCK_INFO),
 
285
        GNOMEUIINFO_SEPARATOR,
258
286
        GNOMEUIINFO_ITEM_STOCK (N_("_Plot"), N_("Plot a function"), genius_plot_dialog, GNOME_STOCK_BOOK_OPEN),
259
287
        GNOMEUIINFO_END,
260
288
};
278
306
};
279
307
 
280
308
static GnomeUIInfo programs_menu[] = {
 
309
        { GNOME_APP_UI_ITEM, N_("_Next Tab"), N_("Go to next tab"),
 
310
                (gpointer)next_tab, NULL, NULL, \
 
311
                GNOME_APP_PIXMAP_STOCK, GTK_STOCK_GO_FORWARD, 
 
312
                GDK_Page_Down, (GdkModifierType) GDK_CONTROL_MASK, NULL },
 
313
        { GNOME_APP_UI_ITEM, N_("_Previous Tab"), N_("Go to previous tab"),
 
314
                (gpointer)prev_tab, NULL, NULL, \
 
315
                GNOME_APP_PIXMAP_STOCK, GTK_STOCK_GO_BACK, 
 
316
                GDK_Page_Up, (GdkModifierType) GDK_CONTROL_MASK, NULL },
 
317
 
 
318
        GNOMEUIINFO_SEPARATOR,
 
319
 
 
320
        GNOMEUIINFO_ITEM (N_("_Console"),
 
321
                          N_("Go to the console tab"),
 
322
                          prog_menu_activated,
 
323
                          NULL),
 
324
 
281
325
        GNOMEUIINFO_END,
282
326
};
283
327
  
457
501
/*display a message in a messagebox*/
458
502
static GtkWidget *
459
503
geniusbox (gboolean error,
 
504
           gboolean always_textbox,
 
505
           const char *textbox_title,
460
506
           gboolean bind_response,
461
507
           const char *s)
462
508
{
463
509
        GtkWidget *mb;
464
510
        /* if less than 10 lines */
465
 
        if (count_char (s, '\n') <= 10) {
 
511
        if (count_char (ve_sure_string (s), '\n') <= 10 &&
 
512
            ! always_textbox) {
466
513
                GtkMessageType type = GTK_MESSAGE_INFO;
467
514
                if (error)
468
515
                        type = GTK_MESSAGE_ERROR;
471
518
                                             type,
472
519
                                             GTK_BUTTONS_OK,
473
520
                                             "%s",
474
 
                                             s);
 
521
                                             ve_sure_string (s));
475
522
        } else {
476
523
                GtkWidget *sw;
477
524
                GtkWidget *tv;
478
525
                GtkTextBuffer *buffer;
479
526
                GtkTextIter iter;
 
527
                const char *title;
 
528
 
 
529
                if (textbox_title != NULL)
 
530
                        title = textbox_title;
 
531
                else if (error)
 
532
                        title = _("Error");
 
533
                else
 
534
                        title = _("Information");
480
535
 
481
536
                mb = gtk_dialog_new_with_buttons
482
 
                        (error?_("Error"):_("Information"),
 
537
                        (title,
483
538
                         GTK_WINDOW (genius_window) /* parent */,
484
539
                         0 /* flags */,
485
540
                         GTK_STOCK_OK, GTK_RESPONSE_OK,
504
559
                gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
505
560
 
506
561
                gtk_text_buffer_insert_with_tags_by_name
507
 
                        (buffer, &iter, s, -1, "foo", NULL);
 
562
                        (buffer, &iter, ve_sure_string (s), -1, "foo", NULL);
508
563
 
509
564
                gtk_container_add (GTK_CONTAINER (sw), tv);
510
565
 
528
583
 
529
584
 
530
585
static void
 
586
full_answer (GtkWidget *menu_item, gpointer data)
 
587
{
 
588
        GelOutput *out;
 
589
        char *s;
 
590
 
 
591
        /* perhaps a bit ugly */
 
592
        out = gel_output_new ();
 
593
        gboolean last_info = genius_setup.info_box;
 
594
        gboolean last_error = genius_setup.error_box;
 
595
        genius_setup.info_box = TRUE;
 
596
        genius_setup.error_box = TRUE;
 
597
        gel_output_setup_string (out, 0, NULL);
 
598
        gel_evalexp ("ans", NULL, out, NULL, TRUE, NULL);
 
599
        gel_printout_infos ();
 
600
        genius_setup.info_box = last_info;
 
601
        genius_setup.error_box = last_error;
 
602
 
 
603
        s = gel_output_snarf_string (out);
 
604
        gel_output_unref (out);
 
605
 
 
606
        geniusbox (FALSE /*error*/,
 
607
                   TRUE /*always textbox*/,
 
608
                   _("Full Answer") /*textbox_title*/,
 
609
                   TRUE /*bind_response*/,
 
610
                   s);
 
611
}
 
612
 
 
613
 
 
614
static void
531
615
printout_error_num_and_reset(void)
532
616
{
533
617
        if(genius_setup.error_box) {
537
621
                                                        _("\nToo many errors! (%d followed)"),
538
622
                                                        errors_printed - curstate.max_errors);
539
623
                        }
540
 
                        geniusbox (TRUE, TRUE, errors->str);
 
624
                        geniusbox (TRUE /*error*/,
 
625
                                   FALSE /*always textbox*/,
 
626
                                   NULL /*textbox_title*/,
 
627
                                   TRUE /*bind_response*/,
 
628
                                   errors->str);
541
629
                        g_string_free(errors,TRUE);
542
630
                        errors=NULL;
543
631
                }
607
695
{
608
696
        /* Print out the infos */
609
697
        if (infos != NULL) {
610
 
                geniusbox (FALSE, TRUE, infos->str);
 
698
                geniusbox (FALSE /*error*/,
 
699
                           FALSE /*always textbox*/,
 
700
                           NULL /*textbox_title*/,
 
701
                           TRUE /*bind_response*/,
 
702
                           infos->str);
611
703
                g_string_free (infos, TRUE);
612
704
                infos = NULL;
613
705
        }
681
773
{
682
774
        static GtkWidget *about;
683
775
        static const char *authors[] = {
684
 
                "Jiri (George) Lebl (jirka@5z.com)",
 
776
                "Jiří (George) Lebl (jirka@5z.com)",
685
777
                NULL
686
778
        };
687
779
        static const char *documenters[] = {
688
 
                "Jiri (George) Lebl (jirka@5z.com)",
 
780
                "Jiří (George) Lebl",
 
781
                "Kai Willadsen",
689
782
                NULL
690
783
        };
691
784
        const char *translators;
752
845
                              genius_setup.info_box);
753
846
        gnome_config_set_bool("/genius/properties/blinking_cursor",
754
847
                              genius_setup.blinking_cursor);
755
 
        gnome_config_set_int("/genius/properties/max_digits", 
756
 
                              curstate.max_digits);
757
 
        gnome_config_set_bool("/genius/properties/results_as_floats",
758
 
                              curstate.results_as_floats);
759
 
        gnome_config_set_bool("/genius/properties/scientific_notation",
760
 
                              curstate.scientific_notation);
761
 
        gnome_config_set_bool("/genius/properties/full_expressions",
762
 
                              curstate.full_expressions);
 
848
        gnome_config_set_bool("/genius/properties/output_remember",
 
849
                              genius_setup.output_remember);
 
850
        if (genius_setup.output_remember) {
 
851
                gnome_config_set_int("/genius/properties/max_digits", 
 
852
                                      curstate.max_digits);
 
853
                gnome_config_set_bool("/genius/properties/results_as_floats",
 
854
                                      curstate.results_as_floats);
 
855
                gnome_config_set_bool("/genius/properties/scientific_notation",
 
856
                                      curstate.scientific_notation);
 
857
                gnome_config_set_bool("/genius/properties/full_expressions",
 
858
                                      curstate.full_expressions);
 
859
                gnome_config_set_bool("/genius/properties/mixed_fractions",
 
860
                                      curstate.mixed_fractions);
 
861
        }
763
862
        gnome_config_set_int("/genius/properties/max_errors",
764
863
                             curstate.max_errors);
765
 
        gnome_config_set_int("/genius/properties/float_prec",
766
 
                             curstate.float_prec);
 
864
        gnome_config_set_bool("/genius/properties/precision_remember",
 
865
                              genius_setup.precision_remember);
 
866
        if (genius_setup.precision_remember) {
 
867
                gnome_config_set_int("/genius/properties/float_prec",
 
868
                                     curstate.float_prec);
 
869
        }
767
870
        
768
871
        gnome_config_sync();
769
872
}
951
1054
static void
952
1055
setup_response (GtkWidget *widget, gint resp, gpointer data)
953
1056
{
 
1057
        if (resp == GTK_RESPONSE_HELP) {
 
1058
                gnome_help_display ("genius", "genius-prefs", NULL /* error */);
 
1059
                return;
 
1060
        }
 
1061
 
954
1062
        if (resp == GTK_RESPONSE_CANCEL ||
955
1063
            resp == GTK_RESPONSE_OK ||
956
1064
            resp == GTK_RESPONSE_APPLY) {
1018
1126
                (_("Genius Setup"),
1019
1127
                 GTK_WINDOW (genius_window) /* parent */,
1020
1128
                 0 /* flags */,
 
1129
                 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1021
1130
                 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
1022
1131
                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1023
1132
                 GTK_STOCK_OK, GTK_RESPONSE_OK,
1089
1198
                          G_CALLBACK (optioncb),
1090
1199
                          (gpointer)&tmpstate.full_expressions);
1091
1200
 
 
1201
        w=gtk_check_button_new_with_label(_("Use mixed fractions"));
 
1202
        gtk_box_pack_start(GTK_BOX(box),w,FALSE,FALSE,0);
 
1203
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), 
 
1204
                                      tmpstate.mixed_fractions);
 
1205
        g_signal_connect (G_OBJECT (w), "toggled",
 
1206
                          G_CALLBACK (optioncb),
 
1207
                          (gpointer)&tmpstate.mixed_fractions);
 
1208
 
 
1209
        w=gtk_check_button_new_with_label(_("Remember output settings across sessions"));
 
1210
        gtk_box_pack_start(GTK_BOX(box),w,FALSE,FALSE,0);
 
1211
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), 
 
1212
                                      tmpsetup.output_remember);
 
1213
        g_signal_connect (G_OBJECT(w), "toggled",
 
1214
                          G_CALLBACK (optioncb),
 
1215
                          (gpointer)&tmpsetup.output_remember);
 
1216
 
 
1217
        gtk_tooltips_set_tip (tips, w,
 
1218
                              _("Should the output settings in the "
 
1219
                               "\"Number/Expression output options\" frame "
 
1220
                               "be remembered for next session.  Does not apply "
 
1221
                               "to the \"Error/Info output options\" frame."),
 
1222
                              NULL);
1092
1223
 
1093
1224
        frame=gtk_frame_new(_("Error/Info output options"));
1094
1225
        gtk_box_pack_start(GTK_BOX(mainbox),frame,FALSE,FALSE,0);
1179
1310
        g_signal_connect (G_OBJECT (adj), "value_changed",
1180
1311
                          G_CALLBACK (intspincb), &tmpstate.float_prec);
1181
1312
 
 
1313
        w=gtk_check_button_new_with_label(_("Remember precision setting across sessions"));
 
1314
        gtk_box_pack_start(GTK_BOX(box),w,FALSE,FALSE,0);
 
1315
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), 
 
1316
                                      tmpsetup.precision_remember);
 
1317
        g_signal_connect (G_OBJECT(w), "toggled",
 
1318
                          G_CALLBACK (optioncb),
 
1319
                          (gpointer)&tmpsetup.precision_remember);
 
1320
 
 
1321
        gtk_tooltips_set_tip (tips, w,
 
1322
                              _("Should the precision setting "
 
1323
                               "be remembered for next session."),
 
1324
                              NULL);
 
1325
 
1182
1326
 
1183
1327
        mainbox = gtk_vbox_new(FALSE, GNOME_PAD);
1184
1328
        gtk_container_set_border_width(GTK_CONTAINER(mainbox),GNOME_PAD);
1185
1329
        gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
1186
1330
                                  mainbox,
1187
1331
                                  gtk_label_new(_("Terminal")));
1188
 
 
1189
1332
        
1190
1333
        frame=gtk_frame_new(_("Terminal options"));
1191
1334
        gtk_box_pack_start(GTK_BOX(mainbox),frame,FALSE,FALSE,0);
1304
1447
                last_dir = NULL;
1305
1448
                return;
1306
1449
        }
1307
 
        if (strcmp(s, "/") == 0) {
 
1450
        if (strcmp(s, G_DIR_SEPARATOR_S) == 0) {
1308
1451
                last_dir = s;
1309
1452
                return;
1310
1453
        }
1311
 
        last_dir = g_strconcat (s, "/", NULL);
 
1454
        last_dir = g_strconcat (s, G_DIR_SEPARATOR_S, NULL);
1312
1455
        g_free (s);
1313
1456
}
1314
1457
#endif
1373
1516
 
1374
1517
        gtk_widget_destroy (GTK_WIDGET (fs));
1375
1518
 
 
1519
        vte_terminal_feed (VTE_TERMINAL (term),
 
1520
                           "\r\n\e[0mOutput from \e[0;32m", -1);
 
1521
        vte_terminal_feed (VTE_TERMINAL (term), s, -1);
 
1522
        vte_terminal_feed (VTE_TERMINAL (term),
 
1523
                           "\e[0m (((\r\n", -1);
 
1524
        gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
 
1525
 
 
1526
        calc_running ++;
1376
1527
        gel_load_guess_file (NULL, s, TRUE);
 
1528
        calc_running --;
1377
1529
 
1378
1530
        gel_printout_infos ();
 
1531
 
 
1532
        vte_terminal_feed (VTE_TERMINAL (term),
 
1533
                           "\e[0m)))End", -1);
 
1534
 
 
1535
        /* interrupt the current command line */
 
1536
        interrupted = TRUE;
 
1537
        vte_terminal_feed_child (VTE_TERMINAL (term), "\n", 1);
1379
1538
}
1380
1539
 
1381
1540
static void
1429
1588
        gtk_widget_show (fs);
1430
1589
}
1431
1590
 
 
1591
#ifdef HAVE_GTKSOURCEVIEW
 
1592
 
 
1593
static guint ur_idle_id = 0;
 
1594
 
 
1595
static gboolean
 
1596
setup_undo_redo_idle (gpointer data)
 
1597
{
 
1598
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1599
 
 
1600
        ur_idle_id = 0;
 
1601
 
 
1602
        if (page < 0)
 
1603
                return FALSE;
 
1604
        if (page == 0) {
 
1605
                gtk_widget_set_sensitive (edit_menu[EDIT_UNDO_ITEM].widget,
 
1606
                                          FALSE);
 
1607
                gtk_widget_set_sensitive (edit_menu[EDIT_REDO_ITEM].widget,
 
1608
                                          FALSE);
 
1609
        } else {
 
1610
                GtkWidget *w = gtk_notebook_get_nth_page
 
1611
                        (GTK_NOTEBOOK (notebook), page);
 
1612
                Program *p = g_object_get_data (G_OBJECT (w), "program");
 
1613
                gtk_widget_set_sensitive
 
1614
                        (edit_menu[EDIT_UNDO_ITEM].widget,
 
1615
                         gtk_source_buffer_can_undo
 
1616
                           (GTK_SOURCE_BUFFER (p->buffer)));
 
1617
                gtk_widget_set_sensitive
 
1618
                        (edit_menu[EDIT_REDO_ITEM].widget,
 
1619
                         gtk_source_buffer_can_redo
 
1620
                           (GTK_SOURCE_BUFFER (p->buffer)));
 
1621
        }
 
1622
 
 
1623
        return FALSE;
 
1624
}
 
1625
 
 
1626
static void
 
1627
setup_undo_redo (void)
 
1628
{
 
1629
        if (ur_idle_id == 0) {
 
1630
                ur_idle_id = gtk_idle_add (setup_undo_redo_idle, NULL);
 
1631
        }
 
1632
}
 
1633
 
 
1634
 
 
1635
static void
 
1636
undo_callback (GtkWidget *menu_item, gpointer data)
 
1637
{
 
1638
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1639
        if (page < 0)
 
1640
                return;
 
1641
        if (page == 0) {
 
1642
                /* undo from a terminal? what are you talking about */
 
1643
                return;
 
1644
        } else {
 
1645
                GtkWidget *w = gtk_notebook_get_nth_page
 
1646
                        (GTK_NOTEBOOK (notebook), page);
 
1647
                Program *p = g_object_get_data (G_OBJECT (w), "program");
 
1648
                if (gtk_source_buffer_can_undo
 
1649
                        (GTK_SOURCE_BUFFER (p->buffer)))
 
1650
                        gtk_source_buffer_undo
 
1651
                                (GTK_SOURCE_BUFFER (p->buffer));
 
1652
        }
 
1653
}
 
1654
 
 
1655
static void
 
1656
redo_callback (GtkWidget *menu_item, gpointer data)
 
1657
{
 
1658
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1659
        if (page < 0)
 
1660
                return;
 
1661
        if (page == 0) {
 
1662
                /* redo from a terminal? what are you talking about */
 
1663
                return;
 
1664
        } else {
 
1665
                GtkWidget *w = gtk_notebook_get_nth_page
 
1666
                        (GTK_NOTEBOOK (notebook), page);
 
1667
                Program *p = g_object_get_data (G_OBJECT (w), "program");
 
1668
                if (gtk_source_buffer_can_redo
 
1669
                        (GTK_SOURCE_BUFFER (p->buffer)))
 
1670
                        gtk_source_buffer_redo
 
1671
                                (GTK_SOURCE_BUFFER (p->buffer));
 
1672
        }
 
1673
}
 
1674
#endif
 
1675
 
1432
1676
static void
1433
1677
cut_callback (GtkWidget *menu_item, gpointer data)
1434
1678
{
1435
1679
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1680
        if (page < 0)
 
1681
                return;
1436
1682
        if (page == 0) {
1437
1683
                /* cut from a terminal? what are you talking about */
1438
1684
                return;
1452
1698
copy_callback (GtkWidget *menu_item, gpointer data)
1453
1699
{
1454
1700
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1701
        if (page < 0)
 
1702
                return;
1455
1703
        if (page == 0) {
1456
1704
                vte_terminal_copy_clipboard (VTE_TERMINAL (term));
1457
1705
        } else {
1468
1716
paste_callback (GtkWidget *menu_item, gpointer data)
1469
1717
{
1470
1718
        int page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
 
1719
        if (page < 0)
 
1720
                return;
1471
1721
        if (page == 0) {
1472
1722
                vte_terminal_paste_clipboard (VTE_TERMINAL (term));
1473
1723
        } else {
1650
1900
}
1651
1901
 
1652
1902
static void
 
1903
next_tab (GtkWidget *menu_item, gpointer data)
 
1904
{
 
1905
        gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
 
1906
}
 
1907
 
 
1908
static void
 
1909
prev_tab (GtkWidget *menu_item, gpointer data)
 
1910
{
 
1911
        gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
 
1912
}
 
1913
 
 
1914
static void
1653
1915
prog_menu_activated (GtkWidget *item, gpointer data)
1654
1916
{
1655
1917
        GtkWidget *w = data;
1656
 
        int num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), w);
 
1918
        int num;
 
1919
       
 
1920
        if (w == NULL)
 
1921
                num = 0;
 
1922
        else
 
1923
                num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), w);
1657
1924
        gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), num);
1658
1925
}
1659
1926
 
1663
1930
        int n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
1664
1931
        int i;
1665
1932
        GtkWidget *menu;
 
1933
        GtkWidget *item;
 
1934
        GtkWidget *w;
1666
1935
 
1667
 
        if (n <= 1) {
1668
 
                /* No programs in the menu */
1669
 
                gtk_widget_hide (genius_menu[PROGRAMS_MENU].widget);
1670
 
                return;
 
1936
        while (prog_menu_items != NULL) {
 
1937
                gtk_widget_destroy (prog_menu_items->data);
 
1938
                prog_menu_items = g_list_remove_link (prog_menu_items, prog_menu_items);
1671
1939
        }
1672
1940
 
1673
 
        menu = gtk_menu_new ();
1674
 
        gtk_widget_show (menu);
 
1941
        menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (genius_menu[PROGRAMS_MENU].widget));
 
1942
 
1675
1943
        for (i = 1; i < n; i++) {
1676
1944
                GtkWidget *item;
1677
1945
                GtkWidget *w = gtk_notebook_get_nth_page
1684
1952
                g_signal_connect (G_OBJECT (item), "activate",
1685
1953
                                  G_CALLBACK (prog_menu_activated), w);
1686
1954
                gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
1955
 
 
1956
                prog_menu_items = g_list_prepend (prog_menu_items, item);
1687
1957
        }
1688
 
 
1689
 
        gtk_menu_item_set_submenu
1690
 
                (GTK_MENU_ITEM (genius_menu[PROGRAMS_MENU].widget), menu);
1691
 
        gtk_widget_show (genius_menu[PROGRAMS_MENU].widget);
1692
1958
}
1693
1959
 
1694
1960
static void
1894
2160
                gtk_source_buffer_set_language
1895
2161
                        (GTK_SOURCE_BUFFER (buffer), lang);
1896
2162
        }
 
2163
        g_signal_connect (G_OBJECT (buffer), "can-undo",
 
2164
                          G_CALLBACK (setup_undo_redo), NULL);
 
2165
        g_signal_connect (G_OBJECT (buffer), "can-redo",
 
2166
                          G_CALLBACK (setup_undo_redo), NULL);
1897
2167
#else
1898
2168
        tv = gtk_text_view_new ();
1899
2169
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
1916
2186
        p->curline = 0;
1917
2187
        g_object_set_data (G_OBJECT (sw), "program", p);
1918
2188
 
 
2189
#ifdef HAVE_GTKSOURCEVIEW
 
2190
        g_signal_connect (G_OBJECT (buffer), "can-undo",
 
2191
                          G_CALLBACK (setup_undo_redo), NULL);
 
2192
        g_signal_connect (G_OBJECT (buffer), "can-redo",
 
2193
                          G_CALLBACK (setup_undo_redo), NULL);
 
2194
#endif
 
2195
 
1919
2196
        g_signal_connect_after (G_OBJECT (p->buffer), "mark_set",
1920
2197
                                G_CALLBACK (move_cursor),
1921
2198
                                p);
1924
2201
                char *d = g_get_current_dir ();
1925
2202
                char *n = g_strdup_printf (_("Program_%d.gel"), cnt);
1926
2203
                /* the file name will have an underscore */
1927
 
                p->name = g_strconcat (d, "/", n, NULL);
 
2204
                p->name = g_build_filename (d, n, NULL);
1928
2205
                g_free (d);
1929
2206
                g_free (n);
1930
2207
                p->vname = g_strdup_printf (_("Program %d"), cnt);
1935
2212
                contents = get_contents_vfs (filename);
1936
2213
                if (contents != NULL) {
1937
2214
                        GtkTextIter iter;
 
2215
#ifdef HAVE_GTKSOURCEVIEW
 
2216
                        gtk_source_buffer_begin_not_undoable_action
 
2217
                                (GTK_SOURCE_BUFFER (buffer));
 
2218
#endif
1938
2219
                        gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
1939
2220
                        gtk_text_buffer_insert_with_tags_by_name
1940
2221
                                (buffer, &iter, contents, -1, "foo", NULL);
 
2222
#ifdef HAVE_GTKSOURCEVIEW
 
2223
                        gtk_source_buffer_end_not_undoable_action
 
2224
                                (GTK_SOURCE_BUFFER (buffer));
 
2225
#endif
1941
2226
                        g_free (contents);
1942
2227
                } else {
1943
2228
                        char *s = g_strdup_printf (_("Cannot open %s"), filename);
1956
2241
                          G_CALLBACK (changed_cb), sw);
1957
2242
 
1958
2243
        build_program_menu ();
 
2244
 
 
2245
#ifdef HAVE_GTKSOURCEVIEW
 
2246
        setup_undo_redo ();
 
2247
#endif
1959
2248
}
1960
2249
 
1961
2250
static void
2293
2582
        GtkWidget *w;
2294
2583
        Program *p;
2295
2584
        int current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
2296
 
        if (current == 0) /* if the console */
 
2585
        if (current <= 0) /* if the console */
2297
2586
                return;
2298
2587
        w = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current);
2299
2588
        p = g_object_get_data (G_OBJECT (w), "program");
2477
2766
                   curstate.full_expressions?"true":"false");
2478
2767
        curstate.full_expressions = gnome_config_get_bool(buf);
2479
2768
 
 
2769
        g_snprintf(buf,256,"/genius/properties/mixed_fractions=%s",
 
2770
                   curstate.mixed_fractions?"true":"false");
 
2771
        curstate.mixed_fractions = gnome_config_get_bool(buf);
 
2772
 
 
2773
        g_snprintf(buf,256,"/genius/properties/output_remember=%s",
 
2774
                   genius_setup.output_remember?"true":"false");
 
2775
        genius_setup.output_remember = gnome_config_get_bool(buf);
 
2776
 
2480
2777
        g_snprintf(buf,256,"/genius/properties/max_errors=%d",
2481
2778
                   curstate.max_errors);
2482
2779
        curstate.max_errors = gnome_config_get_int(buf);
2490
2787
                curstate.float_prec = 60;
2491
2788
        else if (curstate.float_prec > 16384)
2492
2789
                curstate.float_prec = 16384;
 
2790
 
 
2791
        g_snprintf(buf,256,"/genius/properties/precision_remember=%s",
 
2792
                   genius_setup.precision_remember?"true":"false");
 
2793
        genius_setup.precision_remember = gnome_config_get_bool(buf);
2493
2794
}
2494
2795
 
2495
2796
static void
2612
2913
                        foo = NULL;
2613
2914
                }
2614
2915
                if (foo == NULL) {
2615
 
                        foo = g_strconcat
2616
 
                                (dir, "/genius-readline-helper-fifo", NULL);
 
2916
                        foo = g_build_filename
 
2917
                                (dir, "genius-readline-helper-fifo", NULL);
2617
2918
                        if (access (foo, X_OK) != 0) {
2618
2919
                                g_free (foo);
2619
2920
                                foo = NULL;
2626
2927
                foo = g_find_program_in_path ("genius-readline-helper-fifo");
2627
2928
 
2628
2929
        if (foo == NULL) {
2629
 
                GtkWidget *d = geniusbox (TRUE /* error */,
2630
 
                                          FALSE,
 
2930
                GtkWidget *d = geniusbox (TRUE /*error*/,
 
2931
                                          FALSE /*always textbox*/,
 
2932
                                          NULL /*textbox_title*/,
 
2933
                                          FALSE /*bind_response*/,
2631
2934
                                          _("Can't execute genius-readline-helper-fifo!\n"));
2632
2935
 
2633
2936
                gtk_dialog_run (GTK_DIALOG (d));
2798
3101
                selection_changed ();
2799
3102
                gtk_widget_set_sensitive (edit_menu[EDIT_CUT_ITEM].widget,
2800
3103
                                          FALSE);
 
3104
                setup_undo_redo ();
2801
3105
                gnome_appbar_pop (GNOME_APPBAR (appbar));
2802
3106
        } else {
2803
3107
                char *s;
2838
3142
                                     selected_program->curline + 1);
2839
3143
                gnome_appbar_push (GNOME_APPBAR (appbar), s);
2840
3144
                g_free (s);
 
3145
 
 
3146
                setup_undo_redo ();
2841
3147
        }
2842
3148
}
2843
3149
 
2937
3243
{
2938
3244
        GtkWidget *hbox;
2939
3245
        GtkWidget *w;
2940
 
        GtkTooltips *tips;
2941
3246
        char *file;
2942
3247
        GnomeUIInfo *plugins;
2943
3248
        int plugin_count = 0;
3070
3375
                gtk_widget_hide (genius_menu[PLUGINS_MENU].widget);
3071
3376
        }
3072
3377
 
3073
 
        /* No programs in the menu */
3074
 
        gtk_widget_hide (genius_menu[PROGRAMS_MENU].widget);
3075
 
 
3076
3378
        /*setup appbar*/
3077
3379
        appbar = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER);
3078
3380
        gnome_app_set_statusbar(GNOME_APP(genius_window), appbar);
3186
3488
                /*try the library file in the current/../lib directory*/
3187
3489
                gel_load_compiled_file (NULL, "../lib/lib.cgel", FALSE);
3188
3490
        } else {
3189
 
                gel_load_compiled_file (NULL, LIBRARY_DIR "/gel/lib.cgel",
 
3491
                gel_load_compiled_file (NULL,
 
3492
                                        LIBRARY_DIR G_DIR_SEPARATOR_S
 
3493
                                        "gel" G_DIR_SEPARATOR_S "lib.cgel",
3190
3494
                                        FALSE);
3191
3495
        }
3192
3496
 
3193
3497
        /*
3194
3498
         * Read init files
3195
3499
         */
3196
 
        file = g_strconcat(g_getenv("HOME"),"/.geniusinit",NULL);
 
3500
        file = g_build_filename (g_get_home_dir (), ".geniusinit",NULL);
3197
3501
        if(file)
3198
3502
                gel_load_file(NULL, file, FALSE);
3199
3503
        g_free(file);