diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/history-entry.ui | 83 | ||||
-rw-r--r-- | src/mate-calc.c | 4 | ||||
-rw-r--r-- | src/math-equation.c | 18 | ||||
-rw-r--r-- | src/math-history-entry.c | 129 | ||||
-rw-r--r-- | src/math-history-entry.h | 49 | ||||
-rw-r--r-- | src/math-history.c | 117 | ||||
-rw-r--r-- | src/math-history.h | 50 | ||||
-rw-r--r-- | src/math-window.c | 94 | ||||
-rw-r--r-- | src/math-window.h | 4 | ||||
-rw-r--r-- | src/org.mate.calculator.gresource.xml | 1 |
11 files changed, 548 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index df5fccd..0555049 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,10 @@ mate_calc_SOURCES = \ math-buttons.h \ math-converter.c \ math-converter.h \ + math-history.c \ + math-history.h \ + math-history-entry.c \ + math-history-entry.h \ math-display.c \ math-display.h \ math-equation.c \ @@ -194,6 +198,7 @@ EXTRA_DIST = \ mp-enums.c.template \ mp-enums.h.template \ org.mate.calculator.gresource.xml \ + history-entry.ui \ preferences.ui DISTCLEANFILES = \ diff --git a/src/history-entry.ui b/src/history-entry.ui new file mode 100644 index 0000000..e8335d8 --- /dev/null +++ b/src/history-entry.ui @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface> + <requires lib="gtk+" version="3.22"/> + <object class="GtkGrid" id="grid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">12</property> + <property name="margin_right">16</property> + <property name="margin_start">12</property> + <property name="margin_end">16</property> + <property name="column_homogeneous">True</property> + <child> + <object class="GtkEventBox" id="equation_eventbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <signal name="button-press-event" handler="equation_clicked_cb" swapped="no"/> + <child> + <object class="GtkLabel" id="equation_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="ellipsize">end</property> + <property name="max_width_chars">1</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <attributes> + <attribute name="size" value="14000"/> + </attributes> + </object> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">4</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="equation_symbol"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label">=</property> + <property name="max_width_chars">1</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <attributes> + <attribute name="weight" value="light"/> + <attribute name="size" value="12000"/> + </attributes> + </object> + <packing> + <property name="left_attach">4</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkEventBox" id="answer_eventbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <signal name="button-press-event" handler="answer_clicked_cb" swapped="no"/> + <child> + <object class="GtkLabel" id="answer_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="ellipsize">end</property> + <property name="max_width_chars">12</property> + <property name="xalign">1</property> + <property name="yalign">0.5</property> + <attributes> + <attribute name="weight" value="bold"/> + <attribute name="size" value="14000"/> + </attributes> + </object> + </child> + </object> + <packing> + <property name="left_attach">5</property> + <property name="top_attach">0</property> + <property name="width">2</property> + </packing> + </child> + </object> +</interface> diff --git a/src/mate-calc.c b/src/mate-calc.c index 05e40dd..0c2645c 100644 --- a/src/mate-calc.c +++ b/src/mate-calc.c @@ -190,7 +190,7 @@ int main(int argc, char **argv) MathEquation *equation; MathButtons *buttons; int accuracy = 9, word_size = 64, base = 10; - gboolean show_tsep = FALSE, show_zeroes = FALSE; + gboolean show_tsep = FALSE, show_zeroes = FALSE, show_hist = FALSE; MpDisplayFormat number_format; MPAngleUnit angle_units; ButtonMode button_mode; @@ -213,6 +213,7 @@ int main(int argc, char **argv) base = g_settings_get_int(g_settings_var, "base"); show_tsep = g_settings_get_boolean(g_settings_var, "show-thousands"); show_zeroes = g_settings_get_boolean(g_settings_var, "show-zeroes"); + show_hist = g_settings_get_boolean(g_settings_var, "show-history"); number_format = g_settings_get_enum(g_settings_var, "number-format"); angle_units = g_settings_get_enum(g_settings_var, "angle-units"); button_mode = g_settings_get_enum(g_settings_var, "button-mode"); @@ -244,6 +245,7 @@ int main(int argc, char **argv) window = math_window_new(equation); buttons = math_window_get_buttons(window); g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL); + math_window_set_show_history(window, show_hist); math_buttons_set_programming_base(buttons, base); math_buttons_set_mode(buttons, button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type diff --git a/src/math-equation.c b/src/math-equation.c index 3b0e4d8..1d349e2 100644 --- a/src/math-equation.c +++ b/src/math-equation.c @@ -975,10 +975,15 @@ math_equation_set_number(MathEquation *equation, const MPNumber *x) { char *text; GtkTextIter start, end; + MathEquationState *state; g_return_if_fail(equation != NULL); g_return_if_fail(x != NULL); + /* Notify history */ + state = get_current_state(equation); + g_signal_emit_by_name(equation, "history", state->expression, x, mp_serializer_get_base(equation->priv->serializer)); + /* Show the number in the user chosen format */ text = mp_serializer_to_string(equation->priv->serializer, x); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(equation), text, -1); @@ -1788,8 +1793,19 @@ math_equation_class_init(MathEquationClass *klass) "Serializer", MP_TYPE_SERIALIZER, G_PARAM_READABLE)); -} + GType param_types[3] = {G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT}; + g_signal_newv("history", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 3, + param_types); +} static void pre_insert_text_cb(MathEquation *equation, diff --git a/src/math-history-entry.c b/src/math-history-entry.c new file mode 100644 index 0000000..baf3a7c --- /dev/null +++ b/src/math-history-entry.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2020 MATE developers + * + * This program 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. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + * + * + */ + +#include <string.h> +#include <glib/gi18n.h> +#include <gdk/gdkkeysyms.h> + +#include "math-history-entry.h" + +struct MathHistoryEntryPrivate +{ + MathEquation *equation; + + MPNumber *answer; /* Stores answer in MPNumber object */ + char *equation_string; /* Stores equation to be entered in history-entry */ + char *answer_string; /* Stores answer to be entered in history-entry */ + GtkWidget *equation_label; + GtkWidget *answer_label; + GtkWidget *equation_eventbox; + GtkWidget *answer_eventbox; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (MathHistoryEntry, math_history_entry, GTK_TYPE_LIST_BOX_ROW); + +#define UI_HISTORY_ENTRY_RESOURCE_PATH "/org/mate/calculator/ui/history-entry.ui" +#define GET_WIDGET(ui, name) \ + GTK_WIDGET(gtk_builder_get_object(ui, name)) + +MathHistoryEntry * +math_history_entry_new(MathEquation *equation) +{ + MathHistoryEntry *history_entry = g_object_new(math_history_entry_get_type(), NULL); + history_entry->priv->equation = g_object_ref(equation); + return history_entry; +} + +void answer_clicked_cb(GtkWidget *widget, GdkEventButton *eventbutton, gpointer data); +G_MODULE_EXPORT +void +answer_clicked_cb (GtkWidget *widget, GdkEventButton *eventbutton, gpointer data) +{ /* Callback function for button-press-event on answer_eventbox */ + GtkEventBox *event = (GtkEventBox*) widget; + MathHistoryEntry *history_entry = MATH_HISTORY_ENTRY(data); + if (event != NULL) + { + if (GTK_IS_BIN(event)) + { + GtkWidget *answer_label = gtk_bin_get_child(GTK_BIN(event)); + char *answer = gtk_widget_get_tooltip_text(answer_label); + if (answer != NULL) + math_equation_insert(history_entry->priv->equation, answer); + } + } +} +void equation_clicked_cb(GtkWidget *widget, GdkEventButton *eventbutton, gpointer data); +G_MODULE_EXPORT +void +equation_clicked_cb (GtkWidget *widget, GdkEventButton *eventbutton, gpointer data) +{ /* Callback function for button-press-event on equation_eventbox */ + GtkEventBox *event = (GtkEventBox*) widget; + MathHistoryEntry *history_entry = MATH_HISTORY_ENTRY(data); + if (event != NULL) + { + if (GTK_IS_BIN(event)) + { + GtkLabel *equation_label = (GtkLabel*) gtk_bin_get_child(GTK_BIN(event)); + const char *equation = gtk_label_get_text(equation_label); + if (equation != NULL) + math_equation_set(history_entry->priv->equation, equation); + } + } +} + +void +math_history_entry_insert_entry(MathHistoryEntry *history_entry, char *equation, MPNumber *number, int number_base) +{ + GtkBuilder *builder = NULL; + GtkWidget *grid; + GError *error = NULL; + char *final_answer; + MpSerializer *serializer_nine = mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, number_base, 9); + MpSerializer *serializer_four = mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, number_base, 4); + + history_entry->priv->answer = number; + history_entry->priv->equation_string = equation; + history_entry->priv->answer_string = mp_serializer_to_string(serializer_nine, history_entry->priv->answer); + final_answer = mp_serializer_to_string(serializer_four, history_entry->priv->answer); + + builder = gtk_builder_new(); + if(gtk_builder_add_from_resource (builder, UI_HISTORY_ENTRY_RESOURCE_PATH, &error) == 0) + { + g_print("gtk_builder_add_from_resource FAILED\n"); + g_print("%s\n",error->message); + return; + } + grid = GET_WIDGET(builder, "grid"); + gtk_container_add(GTK_CONTAINER(history_entry), grid); + history_entry->priv->equation_label = GET_WIDGET(builder, "equation_label"); + history_entry->priv->answer_label = GET_WIDGET(builder, "answer_label"); + history_entry->priv->equation_eventbox = GET_WIDGET(builder, "equation_eventbox"); + history_entry->priv->answer_eventbox = GET_WIDGET(builder, "answer_eventbox"); + gtk_widget_set_tooltip_text(history_entry->priv->equation_label, history_entry->priv->equation_string); + gtk_widget_set_tooltip_text(history_entry->priv->answer_label, history_entry->priv->answer_string); + gtk_label_set_text(GTK_LABEL(history_entry->priv->equation_label), history_entry->priv->equation_string); + gtk_label_set_text(GTK_LABEL(history_entry->priv->answer_label), final_answer); + gtk_builder_connect_signals(builder, history_entry); +} + +static void +math_history_entry_class_init(MathHistoryEntryClass *klass) +{ +} + +static void +math_history_entry_init(MathHistoryEntry *history_entry) +{ + history_entry->priv = math_history_entry_get_instance_private(history_entry); + history_entry->priv->equation_string = ""; + history_entry->priv->answer_string = ""; +} diff --git a/src/math-history-entry.h b/src/math-history-entry.h new file mode 100644 index 0000000..512b551 --- /dev/null +++ b/src/math-history-entry.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020 MATE developers + * + * This program 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. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + * + * + */ + +#ifndef MATH_HISTORY_ENTRY_VIEW_H +#define MATH_HISTORY_ENTRY_VIEW_H + +#include <glib-object.h> +#include <gtk/gtk.h> + +#include "math-display.h" +#include "math-history.h" + +G_BEGIN_DECLS + +#define MATH_HISTORY_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), math_history_entry_get_type(), MathHistoryEntry)) + +typedef struct MathHistoryEntryPrivate MathHistoryEntryPrivate; + +typedef struct +{ + GtkListBoxRow parent_instance; + MathHistoryEntryPrivate *priv; +} MathHistoryEntry; + +typedef struct +{ + GtkListBoxRowClass parent_class; +} MathHistoryEntryClass; + +GType math_history_entry_get_type(void); + +MathHistoryEntry * +math_history_entry_new(MathEquation *equation); + +void +math_history_entry_insert_entry(MathHistoryEntry *history_entry, char *equation, MPNumber *number, int number_base); + +G_END_DECLS + +#endif /* MATH_HISTORY_ENTRY_VIEW_H */ diff --git a/src/math-history.c b/src/math-history.c new file mode 100644 index 0000000..18b9bda --- /dev/null +++ b/src/math-history.c @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2020 MATE developers + * + * This program 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. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + * + * + */ + +#include <string.h> +#include <glib/gi18n.h> +#include <gdk/gdkkeysyms.h> + +#include "math-history.h" + +struct MathHistoryPrivate +{ + MathEquation *equation; + + MathHistoryEntry *entry; + char *prev_equation; + int items_count; /* Number of entries in history listbox */ + GtkWidget *listbox; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(MathHistory, math_history, GTK_TYPE_SCROLLED_WINDOW); + +MathHistory * +math_history_new(MathEquation *equation) +{ + MathHistory *history = g_object_new(math_history_get_type(), NULL); + history->priv->equation = g_object_ref(equation); + return history; +} + +static void +scroll_bottom_cb(MathHistory *history, gpointer data) +{ + GtkAdjustment *adjustment; + // TODO make this dynamic, do not hardcode listbox_height_request/number_of_rows + int width, height; + + adjustment = gtk_list_box_get_adjustment(GTK_LIST_BOX(history->priv->listbox)); + gtk_widget_get_size_request(GTK_WIDGET(history), &width, &height); + gtk_adjustment_set_page_size(adjustment, height / 3); + gtk_adjustment_set_value (adjustment, gtk_adjustment_get_upper (adjustment) + - gtk_adjustment_get_page_size (adjustment)); +} + +static gboolean +check_history(MathHistory *history, char *equation) +{ /* Checks if the last inserted calculation is the same as the current calculation to be inserted in history-history */ + if (history->priv->items_count >= 1 && g_strcmp0(equation, history->priv->prev_equation)==0) + return TRUE; /* returns true if last entered equation is the same as the current equation */ + else + return FALSE; +} + +void +math_history_insert_entry (MathHistory *history, char *equation, MPNumber *answer, int number_base) +{ /* Inserts a new entry into the history-history listbox */ + history->priv->entry = math_history_entry_new(history->priv->equation); + gboolean check = check_history (history, equation); + history->priv->prev_equation = g_strdup(equation); + if (!check) + { + math_history_entry_insert_entry(history->priv->entry, equation, answer, number_base); + if (history->priv->entry != NULL) + { + gtk_list_box_insert(GTK_LIST_BOX(history->priv->listbox), GTK_WIDGET(history->priv->entry), -1); + gtk_widget_set_can_focus(GTK_WIDGET(history->priv->entry), FALSE); + gtk_widget_show_all(GTK_WIDGET(history->priv->entry)); + history->priv->items_count++; + } + } + g_signal_emit_by_name(history, "row-added"); +} + +static void +math_history_class_init(MathHistoryClass *klass) +{ + g_signal_new("row-added", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 0, + NULL); +} + +static void +math_history_init(MathHistory *history) +{ + history->priv = math_history_get_instance_private(history); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(history), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(history), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(history), GTK_CORNER_TOP_LEFT); + + history->priv->items_count = 0; + history->priv->prev_equation = ""; + history->priv->listbox = gtk_list_box_new(); + gtk_list_box_set_selection_mode(GTK_LIST_BOX(history->priv->listbox), GTK_SELECTION_NONE); + gtk_widget_show(GTK_WIDGET(history->priv->listbox)); + + gtk_container_add(GTK_CONTAINER(history), history->priv->listbox); + gtk_widget_set_valign(GTK_WIDGET(history->priv->listbox), GTK_ALIGN_END); + gtk_widget_set_size_request(GTK_WIDGET(history), 100, 100); + gtk_widget_set_can_focus(GTK_WIDGET(history), FALSE); + + g_signal_connect(history, "row-added", G_CALLBACK(scroll_bottom_cb), NULL); +} diff --git a/src/math-history.h b/src/math-history.h new file mode 100644 index 0000000..6301dd6 --- /dev/null +++ b/src/math-history.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 MATE developers + * + * This program 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. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + * + * + */ + +#ifndef MATH_HISTORY_VIEW_H +#define MATH_HISTORY_VIEW_H + +#include <glib-object.h> +#include <gtk/gtk.h> + +#include "math-history-entry.h" +#include "math-display.h" +#include "math-equation.h" + +G_BEGIN_DECLS + +#define MATH_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), math_history_get_type(), MathHistory)) + +typedef struct MathHistoryPrivate MathHistoryPrivate; + +typedef struct +{ + GtkScrolledWindow parent_instance; + MathHistoryPrivate *priv; +} MathHistory; + +typedef struct +{ + GtkScrolledWindowClass parent_class; +} MathHistoryClass; + +GType math_history_get_type(void); + +MathHistory * +math_history_new(MathEquation *equation); + +void +math_history_insert_entry(MathHistory *history, char *equation, MPNumber *answer, int number_base); + +G_END_DECLS + +#endif /* MATH_HISTORY_VIEW_H */ diff --git a/src/math-window.c b/src/math-window.c index 9030893..98ab60d 100644 --- a/src/math-window.c +++ b/src/math-window.c @@ -14,6 +14,7 @@ #include <gdk/gdkkeysyms.h> #include "math-window.h" +#include "math-history.h" #include "utility.h" // gtk3 hack @@ -31,7 +32,8 @@ enum { PROP_0, - PROP_EQUATION + PROP_EQUATION, + PROP_SHOW_HISTORY }; struct MathWindowPrivate @@ -39,13 +41,16 @@ struct MathWindowPrivate GtkWidget *menu_bar; MathEquation *equation; MathDisplay *display; + MathHistory *history; MathButtons *buttons; MathPreferencesDialog *preferences_dialog; gboolean right_aligned; + gboolean show_history; GtkWidget *mode_basic_menu_item; GtkWidget *mode_advanced_menu_item; GtkWidget *mode_financial_menu_item; GtkWidget *mode_programming_menu_item; + GtkWidget *view_history_menu_item; }; G_DEFINE_TYPE_WITH_PRIVATE (MathWindow, math_window, GTK_TYPE_WINDOW); @@ -93,6 +98,36 @@ math_window_get_buttons(MathWindow *window) return window->priv->buttons; } +gboolean +math_window_get_show_history(MathWindow *window) +{ + g_return_val_if_fail(window != NULL, FALSE); + return window->priv->show_history; +} + +void +math_window_set_show_history(MathWindow *window, gboolean visible) +{ + g_return_if_fail(window != NULL); + + if (math_window_get_show_history(window) == visible) + return; + + window->priv->show_history = visible; + + if (visible) + { + gtk_widget_show(GTK_WIDGET(window->priv->history)); + gtk_window_set_resizable(GTK_WINDOW(window), TRUE); + } + else + { + gtk_widget_hide(GTK_WIDGET(window->priv->history)); + gtk_window_resize(GTK_WINDOW(window), 1, 1); //FIXME: is there a better way to shrink window size to its children? + gtk_window_set_resizable(GTK_WINDOW(window), FALSE); + } + g_object_notify(G_OBJECT(window), "show-history"); +} void math_window_critical_error(MathWindow *window, const gchar *title, const gchar *contents) @@ -129,6 +164,22 @@ static void mode_changed_cb(GtkWidget *menu, MathWindow *window) math_buttons_set_mode(window->priv->buttons, mode); } +static void history_check_toggled_cb(GtkWidget *menu, MathWindow *window) +{ + gboolean value; + + value = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu)); + math_window_set_show_history(window, value); +} + +static void show_history_cb(MathWindow *window, GParamSpec *spec) +{ + GtkWidget *menu = window->priv->view_history_menu_item; + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu), + math_window_get_show_history(window)); + g_settings_set_boolean(g_settings_var, "show-history", math_window_get_show_history(window)); +} + static void show_preferences_cb(GtkMenuItem *menu, MathWindow *window) { if (!window->priv->preferences_dialog) @@ -356,6 +407,13 @@ static GtkWidget *add_menu(GtkWidget *menu_bar, const gchar *name) return menu; } +static void +update_history_cb (MathEquation *equation, char *answer, MPNumber *number, int number_base, gpointer data) +{ /* Recieves signal emitted by a MathEquation object for updating history */ + MathWindow *window = MATH_WINDOW(data); + math_history_insert_entry (window->priv->history, answer, number, number_base); /* Sends current equation and answer for updating History-View */ +} + static void quit_cb(GtkWidget* widget, MathWindow* window) { g_signal_emit(window, signals[QUIT], 0); @@ -425,6 +483,8 @@ static void create_menu(MathWindow* window) #define CALCULATOR_MENU_LABEL _("_Calculator") /* Mode menu */ #define MODE_MENU_LABEL _("_Mode") + /* View menu */ + #define VIEW_MENU_LABEL _("_View") /* Help menu label */ #define HELP_MENU_LABEL _("_Help") /* Basic menu label */ @@ -435,6 +495,8 @@ static void create_menu(MathWindow* window) #define MODE_FINANCIAL_LABEL _("_Financial") /* Programming menu label */ #define MODE_PROGRAMMING_LABEL _("_Programming") + /* History menu label */ + #define VIEW_HISTORY_LABEL _("_History") /* Help>Contents menu label */ #define HELP_CONTENTS_LABEL _("_Contents") @@ -464,6 +526,10 @@ static void create_menu(MathWindow* window) window->priv->mode_programming_menu_item = add_menu_item(menu, radio_menu_item_new(&group, MODE_PROGRAMMING_LABEL), G_CALLBACK(mode_changed_cb), window); g_object_set_data(G_OBJECT(window->priv->mode_programming_menu_item), "calcmode", GINT_TO_POINTER(PROGRAMMING)); + menu = add_menu(window->priv->menu_bar, VIEW_MENU_LABEL); + window->priv->view_history_menu_item = add_menu_item(menu, gtk_check_menu_item_new_with_mnemonic(VIEW_HISTORY_LABEL), G_CALLBACK(history_check_toggled_cb), window); + gtk_widget_add_accelerator(window->priv->view_history_menu_item, "activate", accel_group, GDK_KEY_H, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + menu = add_menu(window->priv->menu_bar, HELP_MENU_LABEL); menu_item = add_menu_item(menu, gtk_image_menu_item_new_from_icon("help-browser", HELP_CONTENTS_LABEL, accel_group), G_CALLBACK(help_cb), window); gtk_widget_add_accelerator(menu_item, "activate", accel_group, GDK_KEY_F1, 0, GTK_ACCEL_VISIBLE); @@ -481,7 +547,7 @@ create_gui(MathWindow *window) gtk_widget_show(main_vbox); window->priv->menu_bar = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(main_vbox), window->priv->menu_bar, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(main_vbox), window->priv->menu_bar, FALSE, FALSE, 0); gtk_widget_show(window->priv->menu_bar); create_menu(window); @@ -491,10 +557,16 @@ create_gui(MathWindow *window) gtk_box_pack_start(GTK_BOX(main_vbox), vbox, TRUE, TRUE, 0); gtk_widget_show(vbox); + window->priv->history = math_history_new(window->priv->equation); + g_signal_connect(window->priv->equation, "history", G_CALLBACK(update_history_cb), window); + g_signal_connect(window, "notify::show-history", G_CALLBACK(show_history_cb), NULL); + show_history_cb(window, NULL); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(window->priv->history), TRUE, TRUE, 0); + scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); - gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolled_window), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(scrolled_window), FALSE, FALSE, 0); g_signal_connect(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(scrolled_window)), "changed", G_CALLBACK(scroll_changed_cb), window); g_signal_connect(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(scrolled_window)), "value-changed", G_CALLBACK(scroll_value_changed_cb), window); window->priv->right_aligned = TRUE; @@ -507,7 +579,7 @@ create_gui(MathWindow *window) window->priv->buttons = math_buttons_new(window->priv->equation); g_signal_connect(window->priv->buttons, "notify::mode", G_CALLBACK(button_mode_changed_cb), window); button_mode_changed_cb(window->priv->buttons, NULL, window); - gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(window->priv->buttons), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(window->priv->buttons), FALSE, FALSE, 0); gtk_widget_show(GTK_WIDGET(window->priv->buttons)); } @@ -527,6 +599,9 @@ math_window_set_property(GObject *object, self->priv->equation = g_value_get_object(value); create_gui(self); break; + case PROP_SHOW_HISTORY: + math_window_set_show_history(self, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -548,6 +623,9 @@ math_window_get_property(GObject *object, case PROP_EQUATION: g_value_set_object(value, self->priv->equation); break; + case PROP_SHOW_HISTORY: + g_value_set_boolean(value, math_window_get_show_history(self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -571,6 +649,14 @@ math_window_class_init(MathWindowClass *klass) math_equation_get_type(), G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property(object_class, + PROP_EQUATION, + g_param_spec_boolean("show-history", + "show-history", + "Show-history", + FALSE, + G_PARAM_READWRITE)); + signals[QUIT] = g_signal_new("quit", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, diff --git a/src/math-window.h b/src/math-window.h index 5575cf3..72f19bc 100644 --- a/src/math-window.h +++ b/src/math-window.h @@ -49,6 +49,10 @@ MathDisplay *math_window_get_display(MathWindow *window); MathButtons *math_window_get_buttons(MathWindow *window); +gboolean math_window_get_show_history(MathWindow *window); + +void math_window_set_show_history(MathWindow *window, gboolean visible); + void math_window_critical_error(MathWindow *window, const gchar *title, const gchar *contents); G_END_DECLS diff --git a/src/org.mate.calculator.gresource.xml b/src/org.mate.calculator.gresource.xml index 6766402..bfa4d8a 100644 --- a/src/org.mate.calculator.gresource.xml +++ b/src/org.mate.calculator.gresource.xml @@ -23,5 +23,6 @@ <file compressed="true" preprocess="xml-stripblanks">buttons-programming.ui</file> <file compressed="true">mate-calc.about</file> <file compressed="true" preprocess="xml-stripblanks">preferences.ui</file> + <file compressed="true" preprocess="xml-stripblanks">history-entry.ui</file> </gresource> </gresources> |