1/*
2Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>
3
4This file is part of Peek.
5
6This software is licensed under the GNU General Public License
7(version 3 or later). See the LICENSE file in this distribution.
8*/
9
10using Gtk;
11
12namespace Peek.Ui {
13  [GtkTemplate (ui = "/com/uploadedlobster/peek/set-window-size-dialog.ui")]
14  class SetWindowSizeDialog : Gtk.Dialog {
15
16    private static SetWindowSizeDialog? instance;
17
18    public static Dialog present_single_instance (ApplicationWindow main_window) {
19      if (instance == null) {
20        instance = new SetWindowSizeDialog (main_window);
21        instance.delete_event.connect ((event) => {
22          instance = null;
23          return false;
24        });
25      }
26
27      var area = main_window.get_recording_area ();
28      instance.height = area.height;
29      instance.width = area.width;
30
31      instance.transient_for = main_window;
32      instance.present ();
33      return instance;
34    }
35
36    public static void close_instance () {
37      if (instance != null) {
38        instance.close ();
39      }
40    }
41
42    [GtkChild]
43    private Adjustment width_adjustment;
44
45    [GtkChild]
46    private Adjustment height_adjustment;
47
48    private ApplicationWindow window;
49
50    private SetWindowSizeDialog (ApplicationWindow window) {
51      Object (use_header_bar: 1);
52      this.window = window;
53    }
54
55    private int width {
56      get {
57        return (int) width_adjustment.value;
58      }
59
60      set {
61        width_adjustment.value = value;
62      }
63    }
64
65    private int height {
66      get {
67        return (int) height_adjustment.value;
68      }
69
70      set {
71        height_adjustment.value = value;
72      }
73    }
74
75    [GtkCallback]
76    private void on_set_size_button_clicked (Button source) {
77      window.resize_recording_area (width, height);
78      this.close ();
79    }
80
81    [GtkCallback]
82    private void on_cancel_button_clicked (Button source) {
83      this.close ();
84    }
85  }
86}