-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditTitle.js
More file actions
71 lines (63 loc) · 2.27 KB
/
editTitle.js
File metadata and controls
71 lines (63 loc) · 2.27 KB
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
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
import Clutter from 'gi://Clutter';
import St from 'gi://St';
import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
export const EditTitleDialog = GObject.registerClass(
class EditTitleDialog extends ModalDialog.ModalDialog {
_init(article, api, notifications, refreshCallback) {
super._init({styleClass: 'run-dialog'});
this._article = article;
this._api = api;
this._notifications = notifications;
this._refreshCallback = refreshCallback;
const label = new St.Label({
text: _('Edit article title:'),
style_class: 'run-dialog-label',
});
this.contentLayout.add_child(label);
this._entry = new St.Entry({
style_class: 'run-dialog-entry',
can_focus: true,
text: this._article.title,
hint_text: this._article.title,
});
this.contentLayout.add_child(this._entry);
this._entry.clutter_text.connect('activate', () => this._save());
this.setButtons([
{
label: _('Cancel'),
action: () => this.close(),
key: Clutter.KEY_Escape,
},
{
label: _('Save'),
action: () => this._save(),
default: true,
},
]);
}
async _save() {
const newTitle = this._entry.get_text().trim();
if (!newTitle || newTitle === this._article.title)
return;
try {
await this._api.updateTitle(this._article.id, newTitle);
this._notifications.showInfo(_('Article title updated successfully'));
this._refreshCallback();
this.close();
} catch (e) {
console.error('Failed to update article title:', e);
this._notifications.showError(_('Failed to update article title'));
}
}
open() {
super.open();
this._entry.grab_key_focus();
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
this._entry.clutter_text.set_selection(0, -1);
return GLib.SOURCE_REMOVE;
});
}
});