Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
EndSessionDialog: Subclass Gtk.Window (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jul 2, 2019
1 parent ba2d2ab commit 0ad4d7c
Showing 1 changed file with 53 additions and 36 deletions.
89 changes: 53 additions & 36 deletions src/Widgets/EndSessionDialog.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2011-2015 Tom Beckmann
* Copyright 2019 elementary, Inc (https://elementary.io)
* 2011-2015 Tom Beckmann
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Expand Down Expand Up @@ -27,22 +28,14 @@ public enum Session.Widgets.EndSessionDialogType {
RESTART = 2
}

public class Session.Widgets.EndSessionDialog : Gtk.Dialog {
public class Session.Widgets.EndSessionDialog : Gtk.Window {
private static LogoutInterface? logout_interface;
private static SystemInterface? system_interface;

public EndSessionDialogType dialog_type { get; construct; }

public EndSessionDialog (Session.Widgets.EndSessionDialogType type) {
Object (
dialog_type: type,
title: "",
deletable: false,
resizable: false,
skip_taskbar_hint: true,
skip_pager_hint: true,
type_hint: Gdk.WindowTypeHint.DIALOG
);
Object (dialog_type: type);
}

construct {
Expand Down Expand Up @@ -79,35 +72,37 @@ public class Session.Widgets.EndSessionDialog : Gtk.Dialog {
break;
}

set_position (Gtk.WindowPosition.CENTER_ALWAYS);
set_keep_above (true);
stick ();

var image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG);
image.valign = Gtk.Align.START;

var heading = new Gtk.Label (heading_text);
heading.get_style_context ().add_class (Granite.STYLE_CLASS_PRIMARY_LABEL);
heading.xalign = 0;
var primary_label = new Gtk.Label (heading_text);
primary_label.get_style_context ().add_class (Granite.STYLE_CLASS_PRIMARY_LABEL);
primary_label.max_width_chars = 50;
primary_label.wrap = true;
primary_label.xalign = 0;

var secondary_label = new Gtk.Label (content_text);
secondary_label.max_width_chars = 50;
secondary_label.wrap = true;
secondary_label.xalign = 0;

var grid = new Gtk.Grid ();
grid.column_spacing = 12;
grid.row_spacing = 6;
grid.margin_start = grid.margin_end = grid.margin_bottom = 12;
grid.attach (image, 0, 0, 1, 2);
grid.attach (heading, 1, 0, 1, 1);
grid.attach (secondary_label, 1, 1, 1, 1);
var cancel = new Gtk.Button.with_label (_("Cancel"));

var confirm = new Gtk.Button.with_label (button_text);
confirm.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

var action_area = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
action_area.layout_style = Gtk.ButtonBoxStyle.END;
action_area.margin_top = 16;
action_area.spacing = 6;

/*
* the indicator does not have a separate item for restart, that's
* why we show both shutdown and restart for the restart action
* (which is sent for shutdown as described above)
*/
if (dialog_type == EndSessionDialogType.RESTART) {
var confirm_restart = add_button (_("Restart"), Gtk.ResponseType.OK) as Gtk.Button;
var confirm_restart = new Gtk.Button.with_label (_("Restart"));
confirm_restart.clicked.connect (() => {
try {
server.confirmed_reboot ();
Expand All @@ -119,17 +114,46 @@ public class Session.Widgets.EndSessionDialog : Gtk.Dialog {
server.closed ();
destroy ();
});

action_area.add (confirm_restart);
}

var cancel = add_button (_("Cancel"), Gtk.ResponseType.CANCEL) as Gtk.Button;
action_area.add (cancel);
action_area.add (confirm);

var grid = new Gtk.Grid ();
grid.column_spacing = 12;
grid.margin = 12;
grid.margin_top = 6;
grid.attach (image, 0, 0, 1, 2);
grid.attach (primary_label, 1, 0);
grid.attach (secondary_label, 1, 1);
grid.attach (action_area, 0, 2, 2);

var titlebar = new Gtk.HeaderBar ();
titlebar.custom_title = new Gtk.Grid ();
titlebar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

deletable = false;
resizable = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.DIALOG;
get_style_context ().add_class ("rounded");
set_keep_above (true);
set_position (Gtk.WindowPosition.CENTER);
set_titlebar (titlebar);
stick ();
add (grid);

cancel.grab_focus ();

cancel.clicked.connect (() => {
server.canceled ();
server.closed ();
destroy ();
});

var confirm = add_button (button_text, Gtk.ResponseType.OK) as Gtk.Button;
confirm.get_style_context ().add_class ("destructive-action");
confirm.clicked.connect (() => {
if (dialog_type == EndSessionDialogType.RESTART || dialog_type == EndSessionDialogType.SHUTDOWN) {
try {
Expand All @@ -150,12 +174,5 @@ public class Session.Widgets.EndSessionDialog : Gtk.Dialog {
server.closed ();
destroy ();
});

set_default (confirm);

get_content_area ().add (grid);

var action_area = get_action_area ();
action_area.margin = 6;
}
}

0 comments on commit 0ad4d7c

Please sign in to comment.