-
Notifications
You must be signed in to change notification settings - Fork 9
/
askNamePopup.js
78 lines (71 loc) · 2.81 KB
/
askNamePopup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* LICENSE INFORMATION
*
* Desktop Icons: Neo - A desktop icons extension for GNOME with numerous features,
* customizations, and optimizations.
*
* Copyright 2021 Abdurahman Elmawi ([email protected])
*
* This project is based on Desktop Icons NG (https://gitlab.com/rastersoft/desktop-icons-ng),
* a desktop icons extension for GNOME licensed under the GPL v3.
*
* This project is free and open source software as described in the GPL v3.
*
* This project (Desktop Icons: Neo) is licensed under the GPL v3. To view the details of this license,
* visit https://www.gnu.org/licenses/gpl-3.0.html for the necessary information
* regarding this project's license.
*/
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const DesktopIconsUtil = imports.desktopIconsUtil;
const Gettext = imports.gettext.domain('desktopicons-neo');
const _ = Gettext.gettext;
var AskNamePopup = class {
constructor(filename, title, parentWindow) {
this._desktopPath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP);
this._window = new Gtk.Dialog({use_header_bar: true,
window_position: Gtk.WindowPosition.CENTER_ON_PARENT,
transient_for: parentWindow,
resizable: false});
this._button = this._window.add_button(_("OK"), Gtk.ResponseType.OK);
this._window.add_button(_("Cancel"), Gtk.ResponseType.CANCEL);
this._window.set_modal(true);
this._window.set_title(title);
DesktopIconsUtil.windowHidePagerTaskbarModal(this._window, true);
let contentArea = this._window.get_content_area();
this._textArea = new Gtk.Entry();
if (filename) {
this._textArea.text = filename;
}
contentArea.pack_start(this._textArea, true, true, 5);
this._textArea.connect('activate', () => {
if (this._button.sensitive) {
this._window.response(Gtk.ResponseType.OK);
}
});
this._textArea.connect('changed', () => {
this._validate();
});
this._validate();
}
_validate() {
let text = this._textArea.text;
let final_path = this._desktopPath + '/' + text;
let final_file = Gio.File.new_for_commandline_arg(final_path);
if ((text == '') || (-1 != text.indexOf('/')) || final_file.query_exists(null)) {
this._button.sensitive = false;
} else {
this._button.sensitive = true;
}
}
run() {
this._window.show_all();
let retval = this._window.run();
this._window.hide();
if (retval == Gtk.ResponseType.OK) {
return this._textArea.text;
} else {
return null;
}
}
};