Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to flat headerbars #798

Merged
merged 5 commits into from
Oct 21, 2023
Merged
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
9 changes: 0 additions & 9 deletions data/style/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

.header {
background-image:
linear-gradient(
to bottom,
@bg_color,
shade(@bg_color, 1.2)
);
}

.daylabel {
padding: 3px;
border-left: solid 1px @menu_separator;
Expand Down
34 changes: 30 additions & 4 deletions src/AgendaView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,35 @@
* Corentin Noël <corentin@elementaryos.org>
*/

public class Maya.View.AgendaView : Gtk.ScrolledWindow {
public class Maya.View.AgendaView : Gtk.Box {
public signal void event_removed (ECal.Component event);

public Hdy.HeaderBar header_bar { get; construct; }

private Gtk.Label day_label;
private Gtk.Label weekday_label;
private Gtk.ListBox selected_date_events_list;
private Gtk.ListBox upcoming_events_list;
private DateTime selected_date;

construct {
var contractor = new Maya.View.Widgets.ContractorButtonWithMenu (_("Export or Share the default Calendar"));

var source_popover = new Calendar.Widgets.SourcePopover ();

var menu_button = new Gtk.MenuButton () {
image = new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR),
popover = source_popover,
tooltip_text = _("Manage Calendars")
};

header_bar = new Hdy.HeaderBar () {
show_close_button = true
};
header_bar.pack_start (contractor);
header_bar.pack_end (menu_button);
header_bar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

weekday_label = new Gtk.Label ("");
weekday_label.xalign = 0;
weekday_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
Expand Down Expand Up @@ -98,13 +117,20 @@ public class Maya.View.AgendaView : Gtk.ScrolledWindow {

var grid = new Gtk.Grid ();
grid.orientation = Gtk.Orientation.VERTICAL;
grid.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
grid.add (selected_data_grid);
grid.add (selected_date_events_list);
grid.add (upcoming_events_list);

hscrollbar_policy = Gtk.PolicyType.NEVER;
add (grid);
var scrolled_window = new Gtk.ScrolledWindow (null, null) {
hscrollbar_policy = NEVER,
child = grid,
vexpand = true
};

orientation = VERTICAL;
add (header_bar);
add (scrolled_window);
get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);

// Listen to changes for events
var calmodel = Calendar.EventStore.get_default ();
Expand Down
34 changes: 32 additions & 2 deletions src/Grid/CalendarView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
/**
* Represents the entire calendar, including the headers, the week labels and the grid.
*/
public class Maya.View.CalendarView : Gtk.Grid {
public class Maya.View.CalendarView : Gtk.Box {
/*
* Event emitted when the day is double clicked or the ENTER key is pressed.
*/
public signal void on_event_add (DateTime date);
public signal void selection_changed (DateTime new_date);

public Hdy.HeaderBar header_bar { get; construct; }
public DateTime? selected_date { get; private set; }

private WeekLabels weeks { get; private set; }
Expand All @@ -54,11 +55,24 @@ public class Maya.View.CalendarView : Gtk.Grid {
construct {
selected_date = Maya.Application.get_selected_datetime ();

var error_label = new Gtk.Label (null);
error_label.show ();

var error_bar = new Gtk.InfoBar () {
message_type = Gtk.MessageType.ERROR,
revealed = false,
show_close_button = true
};
error_bar.get_content_area ().add (error_label);

var info_bar = new Calendar.Widgets.ConnectivityInfoBar ();

header_bar = new Calendar.Widgets.HeaderBar ();

stack = new Gtk.Stack ();
stack.expand = true;

sync_with_model (); // Populate stack with a grid
stack.show_all ();

var model = Calendar.EventStore.get_default ();
model.parameters_changed.connect (on_model_parameters_changed);
Expand All @@ -84,7 +98,23 @@ public class Maya.View.CalendarView : Gtk.Grid {
events |= Gdk.EventMask.KEY_PRESS_MASK;
events |= Gdk.EventMask.SCROLL_MASK;
events |= Gdk.EventMask.SMOOTH_SCROLL_MASK;
orientation = VERTICAL;
get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
add (header_bar);
add (error_bar);
add (info_bar);
add (stack);
show_all ();

error_bar.response.connect ((id) => error_bar.set_revealed (false));

Calendar.EventStore.get_default ().error_received.connect ((message) => {
Idle.add (() => {
error_label.label = message;
error_bar.set_revealed (true);
return false;
});
});
}

public override bool scroll_event (Gdk.EventScroll event) {
Expand Down
1 change: 0 additions & 1 deletion src/Grid/Header.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class Header : Gtk.EventBox {
// EventBox properties
set_visible_window (true); // needed for style
get_style_context ().add_provider (style_provider, 600);
get_style_context ().add_class ("header");

labels = new Gtk.Label[7];
for (int c = 0; c < 7; c++) {
Expand Down
42 changes: 10 additions & 32 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -59,57 +59,35 @@ public class Maya.MainWindow : Hdy.ApplicationWindow {
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
default_theme.add_resource_path ("/io/elementary/calendar");

var headerbar = new Calendar.Widgets.HeaderBar ();

var error_label = new Gtk.Label (null);
error_label.show ();

var error_bar = new Gtk.InfoBar () {
message_type = Gtk.MessageType.ERROR,
revealed = false,
show_close_button = true
calview = new View.CalendarView () {
vexpand = true
};
error_bar.get_content_area ().add (error_label);

var info_bar = new Calendar.Widgets.ConnectivityInfoBar ();

var sidebar = new View.AgendaView () {
no_show_all = true,
width_request = 160
};
sidebar.show ();

calview = new View.CalendarView () {
vexpand = true
};

var hpaned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
hpaned.pack1 (calview, true, false);
hpaned.pack2 (sidebar, false, false);

var grid = new Gtk.Grid ();
grid.orientation = Gtk.Orientation.VERTICAL;
grid.add (headerbar);
grid.add (error_bar);
grid.add (info_bar);
grid.add (hpaned);
add (hpaned);

add (grid);
var header_group = new Hdy.HeaderGroup ();
header_group.add_header_bar (calview.header_bar);
header_group.add_header_bar (sidebar.header_bar);

var size_group = new Gtk.SizeGroup (VERTICAL);
size_group.add_widget (calview.header_bar);
size_group.add_widget (sidebar.header_bar);

calview.on_event_add.connect ((date) => on_tb_add_clicked (date));
calview.selection_changed.connect ((date) => sidebar.set_selected_date (date));
error_bar.response.connect ((id) => error_bar.set_revealed (false));
sidebar.event_removed.connect (on_remove);

Maya.Application.saved_state.bind ("hpaned-position", hpaned, "position", GLib.SettingsBindFlags.DEFAULT);

Calendar.EventStore.get_default ().error_received.connect ((message) => {
Idle.add (() => {
error_label.label = message;
error_bar.set_revealed (true);
return false;
});
});
}

public void on_tb_add_clicked (DateTime dt) {
Expand Down
29 changes: 10 additions & 19 deletions src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,31 @@ public class Calendar.Widgets.HeaderBar : Hdy.HeaderBar {
construct {
var application_instance = ((Gtk.Application) GLib.Application.get_default ());

var button_add = new Gtk.Button.from_icon_name ("appointment-new", Gtk.IconSize.LARGE_TOOLBAR);
button_add.action_name = Maya.MainWindow.ACTION_PREFIX + Maya.MainWindow.ACTION_NEW_EVENT;
button_add.tooltip_markup = Granite.markup_accel_tooltip (
application_instance.get_accels_for_action (button_add.action_name),
_("Create a new event")
);

var button_today = new Gtk.Button.from_icon_name ("calendar-go-today", Gtk.IconSize.LARGE_TOOLBAR);
button_today.action_name = Maya.MainWindow.ACTION_PREFIX + Maya.MainWindow.ACTION_SHOW_TODAY;
button_today.tooltip_markup = Granite.markup_accel_tooltip (
application_instance.get_accels_for_action (button_today.action_name),
_("Go to today's date")
);

var source_popover = new Calendar.Widgets.SourcePopover ();

var menu_button = new Gtk.MenuButton ();
menu_button.image = new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR);
menu_button.popover = source_popover;
menu_button.tooltip_text = _("Manage Calendars");

month_switcher = new Calendar.Widgets.DateSwitcher (10) {
valign = Gtk.Align.CENTER
};
year_switcher = new Calendar.Widgets.DateSwitcher (-1) {
valign = Gtk.Align.CENTER
};

var button_add = new Gtk.Button.from_icon_name ("appointment-new", Gtk.IconSize.LARGE_TOOLBAR) {
action_name = Maya.MainWindow.ACTION_PREFIX + Maya.MainWindow.ACTION_NEW_EVENT
};
button_add.tooltip_markup = Granite.markup_accel_tooltip (
application_instance.get_accels_for_action (button_add.action_name),
_("Create a new event")
);

var calmodel = Calendar.EventStore.get_default ();
set_switcher_date (calmodel.month_start);

var contractor = new Maya.View.Widgets.ContractorButtonWithMenu (_("Export or Share the default Calendar"));

var title_grid = new Gtk.Grid ();
title_grid.column_spacing = 6;
title_grid.add (button_today);
Expand All @@ -73,11 +65,10 @@ public class Calendar.Widgets.HeaderBar : Hdy.HeaderBar {

var spinner = new Maya.View.Widgets.DynamicSpinner ();

pack_start (button_add);
pack_start (spinner);
pack_end (button_add);
set_custom_title (title_grid);
pack_end (menu_button);
pack_end (contractor);
get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

month_switcher.left_clicked.connect (() => Calendar.EventStore.get_default ().change_month (-1));
month_switcher.right_clicked.connect (() => Calendar.EventStore.get_default ().change_month (1));
Expand Down