| 1 |
/* |
| 2 |
* Copyright (c) 2017-2019 José Amuedo (https://github.com/spheras) |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
public class RenameDialog : Gtk.Dialog { |
| 19 |
private Gtk.Entry entry; |
| 20 |
|
| 21 |
public signal void on_rename (string new_name); |
| 22 |
public signal void on_cancel (); |
| 23 |
|
| 24 |
public RenameDialog (Gtk.Window parent, string title, string label_message, string entry_text) { |
| 25 |
if (parent != null) { |
| 26 |
this.set_transient_for (parent); |
| 27 |
} |
| 28 |
this.title = title; |
| 29 |
this.border_width = 5; |
| 30 |
set_default_size (350, 100); |
| 31 |
this.get_style_context ().add_class ("df_dialog"); |
| 32 |
this.set_decorated (true); |
| 33 |
this.window_position = Gtk.WindowPosition.MOUSE; |
| 34 |
|
| 35 |
create_widgets (label_message, entry_text); |
| 36 |
connect_signals (); |
| 37 |
} |
| 38 |
|
| 39 |
private void create_widgets (string label_message, string entry_text) { |
| 40 |
|
| 41 |
var description = new Gtk.Label (label_message); |
| 42 |
description.halign = Gtk.Align.START; |
| 43 |
this.entry = new Gtk.Entry (); |
| 44 |
this.entry.activate.connect (() => { |
| 45 |
this.response (Gtk.ResponseType.OK); |
| 46 |
}); |
| 47 |
this.entry.set_text (entry_text); |
| 48 |
|
| 49 |
// Layout widgets |
| 50 |
Gtk.Box hbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 5); |
| 51 |
hbox.pack_start (description, false, true, 0); |
| 52 |
hbox.pack_start (entry, true, true, 0); |
| 53 |
|
| 54 |
var grid = new Gtk.Grid (); |
| 55 |
grid.margin = 10; |
| 56 |
grid.attach (hbox, 0, 0, 1, 1); |
| 57 |
|
| 58 |
Gtk.Box content = this.get_content_area () as Gtk.Box; |
| 59 |
content.pack_start (grid, false, true, 0); |
| 60 |
content.spacing = 10; |
| 61 |
|
| 62 |
// Add buttons to button area at the bottom |
| 63 |
add_button (DesktopFolder.Lang.DIALOG_OK, Gtk.ResponseType.OK); |
| 64 |
add_button (DesktopFolder.Lang.DIALOG_CANCEL, Gtk.ResponseType.CANCEL); |
| 65 |
} |
| 66 |
|
| 67 |
private void connect_signals () { |
| 68 |
this.response.connect (on_response); |
| 69 |
} |
| 70 |
|
| 71 |
private void on_response (Gtk.Dialog source, int response_id) { |
| 72 |
switch (response_id) { |
| 73 |
case Gtk.ResponseType.OK: |
| 74 |
this.on_rename (this.entry.get_text ()); |
| 75 |
this.destroy (); |
| 76 |
break; |
| 77 |
case Gtk.ResponseType.CANCEL: |
| 78 |
this.on_cancel (); |
| 79 |
this.destroy (); |
| 80 |
break; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
} |