better datetime tooltip
This commit is contained in:
@@ -12,6 +12,13 @@ Display date and time on GNOME taskbar.
|
|||||||
[Guide](https://gjs.guide/extensions/development/creating.html)
|
[Guide](https://gjs.guide/extensions/development/creating.html)
|
||||||
[Cinnamon_Applet](https://github.com/sonichy/Cinnamon_Applet)
|
[Cinnamon_Applet](https://github.com/sonichy/Cinnamon_Applet)
|
||||||
[Calendar](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/dateMenu.js#L901)
|
[Calendar](https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/dateMenu.js#L901)
|
||||||
|
[Tooltip](https://gitlab.com/arcmenu/ArcMenu)
|
||||||
|
[Dialog](https://gjs.guide/extensions/topics/dialogs.html)
|
||||||
|
[Settings](https://gjs.guide/extensions/development/preferences.html)
|
||||||
|
[Settings](https://gjs.guide/guides/gtk/3/16-settings.html#title:-application-settings)
|
||||||
|
|
||||||
|
## GSettings schema must be compiled
|
||||||
|
`glib-compile-schemas schemas/`
|
||||||
|
|
||||||
## Debug
|
## Debug
|
||||||
dbus-run-session -- gnome-shell --nested --wayland
|
dbus-run-session -- gnome-shell --nested --wayland
|
||||||
|
|||||||
@@ -36,19 +36,19 @@ export default class DatetimeExtension extends Extension {
|
|||||||
const menu_set = new PopupMenu.PopupMenuItem('Set');
|
const menu_set = new PopupMenu.PopupMenuItem('Set');
|
||||||
menu_set.connect('activate', () => {
|
menu_set.connect('activate', () => {
|
||||||
//https://gjs.guide/extensions/topics/dialogs.html
|
//https://gjs.guide/extensions/topics/dialogs.html
|
||||||
const dialog = new Dialog.Dialog(global.stage, 'my-dialog');
|
const dialog = new Dialog.Dialog(global.stage, 'my-dialog');
|
||||||
|
|
||||||
const box = new St.BoxLayout();
|
const box = new St.BoxLayout();
|
||||||
const label = new St.Label({ text: 'Memo', y_align: Clutter.ActorAlign.CENTER });
|
const label = new St.Label({ text: 'Memo', y_align: Clutter.ActorAlign.CENTER });
|
||||||
label.style = 'margin:0 10px;';
|
label.style = 'margin:0 10px;';
|
||||||
box.add_child(label);
|
box.add_child(label);
|
||||||
|
|
||||||
var s = this._settings.get_string('memo');
|
var s = this._settings.get_string('memo');
|
||||||
const entry = new St.Entry({ text: s });
|
const entry = new St.Entry({ text: s });
|
||||||
entry.width = 200;
|
entry.width = 200;
|
||||||
box.add_child(entry);
|
box.add_child(entry);
|
||||||
|
|
||||||
dialog.contentLayout.add_child(box);
|
dialog.contentLayout.add_child(box);
|
||||||
|
|
||||||
dialog.addButton({
|
dialog.addButton({
|
||||||
label: 'Save',
|
label: 'Save',
|
||||||
@@ -64,7 +64,7 @@ export default class DatetimeExtension extends Extension {
|
|||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dialog.set_position(parseInt(global.stage.width/2 - dialog.width/2), parseInt(global.stage.height/2 - dialog.height/2));
|
dialog.set_position(parseInt(global.stage.width/2 - dialog.width/2), parseInt(global.stage.height/2 - dialog.height/2));
|
||||||
});
|
});
|
||||||
this._indicator.menu.addMenuItem(menu_set);
|
this._indicator.menu.addMenuItem(menu_set);
|
||||||
|
|
||||||
@@ -94,17 +94,20 @@ export default class DatetimeExtension extends Extension {
|
|||||||
var date = new Date();
|
var date = new Date();
|
||||||
var h = date.getHours();
|
var h = date.getHours();
|
||||||
if (h < 10)
|
if (h < 10)
|
||||||
h = "0" + h;
|
h = '0' + h;
|
||||||
var m = date.getMinutes();
|
var m = date.getMinutes();
|
||||||
if (m < 10)
|
if (m < 10)
|
||||||
m = "0" + m;
|
m = '0' + m;
|
||||||
var day = date.getDay();
|
var day = date.getDay();
|
||||||
var weekday = ["日", "一", "二", "三", "四", "五", "六"];
|
var weekday = ['日', '一', '二', '三', '四', '五', '六'];
|
||||||
var weekday1 = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
var weekday1 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
||||||
var text = h + ':' + m + '\n' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + weekday[day];
|
var text = h + ':' + m + '\n' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + weekday[day];
|
||||||
label.set_text(text);
|
label.set_text(text);
|
||||||
var s = this._settings.get_string('memo');
|
var s = this._settings.get_string('memo');
|
||||||
this.label_tooltip.text = date.toLocaleString() + ' ' + weekday1[day] + '\n' + s;
|
if (s == '')
|
||||||
|
this.label_tooltip.text = date.toLocaleString() + ' ' + weekday1[day];
|
||||||
|
else
|
||||||
|
this.label_tooltip.text = date.toLocaleString() + ' ' + weekday1[day] + '\n' + s;
|
||||||
// Run as loop, not once.
|
// Run as loop, not once.
|
||||||
return GLib.SOURCE_CONTINUE;
|
return GLib.SOURCE_CONTINUE;
|
||||||
});
|
});
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 140 KiB |
Reference in New Issue
Block a user