Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config_file = configure_file(
core_deps = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('libadwaita-1'),
meson.get_compiler('vala').find_library('posix'),
meson.get_compiler('c').find_library('m', required : false)
]
Expand Down
2 changes: 1 addition & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
src/Application.vala
src/Button.vala
src/MainWindow.vala
src/HistoryDialog.vala
src/HistorySidebar.vala
src/Core/Token.vala
src/Core/Scanner.vala
src/Core/Evaluation.vala
154 changes: 0 additions & 154 deletions src/HistoryDialog.vala

This file was deleted.

122 changes: 122 additions & 0 deletions src/HistorySidebar.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*-
* Copyright 2018-2021 elementary, Inc. (https://elementary.io)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright 2018 - 2025

* 2014 Marvin Beckers <beckersmarvin@gmail.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Marvin Beckers <beckersmarvin@gmail.com>
*/

namespace PantheonCalculator {
public class HistorySidebar : Gtk.Grid {
public signal void clear_history ();

private GLib.ListStore history_list;

public signal void added (string text);

construct {
var clear_button = new Gtk.Button () {
icon_name = "user-trash-full-symbolic",
tooltip_text = _("Clear History")
};

clear_button.clicked.connect (() => {
clear_history ();
history_list.remove_all ();
});

var headerbar = new Adw.HeaderBar () {
Copy link
Collaborator

@jeremypw jeremypw Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we should hide the close button in this header. I thought it would close the history but in fact it unexpectedly closed the whole window. Should replace with a "close sidebar" button? On the other hand other apps do have the close button inside the sidebar but there the sidebar is not a temporary overlay so I am not sure what to do. @danirabbit please advise. Another solution would be to have the sidebar on the right.

show_title = false
};
headerbar.pack_end (clear_button);
headerbar.add_css_class (Granite.STYLE_CLASS_FLAT);
headerbar.add_css_class (Granite.STYLE_CLASS_DEFAULT_DECORATION);

history_list = new GLib.ListStore (typeof (MainWindow.History));

var listbox = new Gtk.ListBox () {
hexpand = true
};
listbox.bind_model (history_list, create_widget_func);
listbox.add_css_class (Granite.STYLE_CLASS_BACKGROUND);
listbox.row_activated.connect ((row) => {
MainWindow.History history = row.get_data<MainWindow.History> ("history");
added (history.output);
});

var listbox_scrolled = new Gtk.ScrolledWindow () {
hscrollbar_policy = NEVER,
max_content_height = 200,
propagate_natural_height = true,
child = listbox,
hexpand = true,
vexpand = true
};

var main_box = new Gtk.Box (VERTICAL, 0) {
hexpand = true,
vexpand = true
};
main_box.append (listbox_scrolled);

var toolbar_view = new Adw.ToolbarView ();
toolbar_view.add_top_bar (headerbar);
toolbar_view.content = main_box;

attach (toolbar_view, 0, 0);
}

public void append (MainWindow.History entry) {
history_list.insert (0, entry);
}

private Gtk.Widget create_widget_func (Object object) {
var history = (MainWindow.History) object;

var exp_label = new Gtk.Label (history.exp) {
halign = START,
ellipsize = END,
tooltip_text = history.exp
};
exp_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);
exp_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);

var output_label = new Gtk.Label ("<b>%s</b>".printf (history.output)) {
halign = START,
use_markup = true,
ellipsize = END,
tooltip_text = history.output
};

var row_grid = new Gtk.Grid () {
margin_top = 6,
margin_bottom = 6,
margin_start = 12,
margin_end = 12,
row_spacing = 3
};
row_grid.attach (exp_label, 0, 0, 1, 1);
row_grid.attach (output_label, 0, 1, 1, 1);

var row = new Gtk.ListBoxRow () {
child = row_grid
};

row.set_data ("history", history);

return row;
}
}
}
Loading