From 56424694806c454fe4926f6e0f2193f3c353c216 Mon Sep 17 00:00:00 2001 From: Reza Mousavi Date: Mon, 1 Apr 2024 09:26:20 +0330 Subject: [PATCH] rewrite preferences window --- .../calendar.js | 4 +- .../dateMenu.js | 2 +- .../eventSource.js | 18 +- .../events.js | 2 +- ...lWorldEvents.js => internationalEvents.js} | 2 +- .../extension.js | 16 +- .../prefs.js | 194 ++++++++++-------- ...ell.extensions.PersianCalendar.gschema.xml | 18 +- 8 files changed, 144 insertions(+), 112 deletions(-) rename persian-calendar@iamrezamousavi.gmail.com/events/{unofficialWorldEvents.js => internationalEvents.js} (96%) diff --git a/persian-calendar@iamrezamousavi.gmail.com/calendar.js b/persian-calendar@iamrezamousavi.gmail.com/calendar.js index 3c3cc52..27e8246 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/calendar.js +++ b/persian-calendar@iamrezamousavi.gmail.com/calendar.js @@ -78,8 +78,8 @@ export const Calendar = GObject.registerClass({ this._weekStart = 6; this.settings = settings; - this.usePersianWeekday = this.settings.get_boolean('calendar-weekday-persian-number'); - this.usePersianDay = this.settings.get_boolean('calendar-day-persian-number'); + this.usePersianWeekday = this.settings.get_boolean('calendar-persian-weekday'); + this.usePersianDay = this.settings.get_boolean('calendar-persian-number'); this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.calendar'}); this._settings.connect(`changed::${SHOW_WEEKDATE_KEY}`, this._onSettingsChange.bind(this)); diff --git a/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js b/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js index 37f5d96..34c7815 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js +++ b/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js @@ -346,7 +346,7 @@ class DateMenuButton extends PanelMenu.Button { _updateCalendarDisplay() { let displayFormat = this.settings.get_string('panel-format'); - let usePersianDigit = this.settings.get_boolean('top-panel-persian-number'); + let usePersianDigit = this.settings.get_boolean('panel-persian-number'); let date = new PersianDate(); this._calendarDisplay.set_text( usePersianDigit diff --git a/persian-calendar@iamrezamousavi.gmail.com/eventSource.js b/persian-calendar@iamrezamousavi.gmail.com/eventSource.js index ab7b9de..adf11b0 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/eventSource.js +++ b/persian-calendar@iamrezamousavi.gmail.com/eventSource.js @@ -7,7 +7,7 @@ import { GregorianEvents, PersianEvents, HijriEvents, - UnofficialWorldEvents + InternationalEvents } from './events.js'; @@ -22,7 +22,7 @@ export const EventSource = GObject.registerClass({ this._gregorianEvents = new GregorianEvents(); this._persianEvents = new PersianEvents(); this._hijriEvents = new HijriEvents(); - this._unofficialWorldEvents = new UnofficialWorldEvents(); + this._InternationalEvents = new InternationalEvents(); } getEvents(_begin, _end) { @@ -46,10 +46,10 @@ export const EventSource = GObject.registerClass({ this._result = this._result.concat(hijriEvents); } - let unofficialEventsActive = this.settings.get_boolean('unofficial-events-active'); - if (unofficialEventsActive) { - let unofficialEvents = this._unofficialWorldEvents.getEvents(_begin); - this._result = this._result.concat(unofficialEvents); + let internationalEventsActive = this.settings.get_boolean('international-events-active'); + if (internationalEventsActive) { + let internationalEvents = this._InternationalEvents.getEvents(_begin); + this._result = this._result.concat(internationalEvents); } return this._result; @@ -59,7 +59,7 @@ export const EventSource = GObject.registerClass({ let gregorianEventsActive = this.settings.get_boolean('gregorian-events-active'); let persianEventsActive = this.settings.get_boolean('persian-events-active'); let hijriEventsActive = this.settings.get_boolean('hijri-events-active'); - let unofficialEventsActive = this.settings.get_boolean('unofficial-events-active'); + let internationalEventsActive = this.settings.get_boolean('international-events-active'); let has = false; if (gregorianEventsActive) has ||= this._gregorianEvents.hasEvents(_day); @@ -67,8 +67,8 @@ export const EventSource = GObject.registerClass({ has ||= this._persianEvents.hasEvents(_day); if (hijriEventsActive) has ||= this._hijriEvents.hasEvents(_day); - if (unofficialEventsActive) - has ||= this._unofficialWorldEvents.hasEvents(_day); + if (internationalEventsActive) + has ||= this._InternationalEvents.hasEvents(_day); return has; } diff --git a/persian-calendar@iamrezamousavi.gmail.com/events.js b/persian-calendar@iamrezamousavi.gmail.com/events.js index d7678f1..0536adc 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/events.js +++ b/persian-calendar@iamrezamousavi.gmail.com/events.js @@ -1,4 +1,4 @@ export * from './events/gregorianEvents.js'; export * from './events/persianEvents.js'; export * from './events/hijriEvents.js'; -export * from './events/unofficialWorldEvents.js'; +export * from './events/internationalEvents.js'; diff --git a/persian-calendar@iamrezamousavi.gmail.com/events/unofficialWorldEvents.js b/persian-calendar@iamrezamousavi.gmail.com/events/internationalEvents.js similarity index 96% rename from persian-calendar@iamrezamousavi.gmail.com/events/unofficialWorldEvents.js rename to persian-calendar@iamrezamousavi.gmail.com/events/internationalEvents.js index 555b8d4..3f848a0 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/events/unofficialWorldEvents.js +++ b/persian-calendar@iamrezamousavi.gmail.com/events/internationalEvents.js @@ -4,7 +4,7 @@ import {CalendarEvent, CalendarEvents} from './calendarEvent.js'; -export const UnofficialWorldEvents = class UnofficialWorldEvents extends CalendarEvents { +export const InternationalEvents = class InternationalEvents extends CalendarEvents { constructor() { super(); this._events.set('7-1', [new CalendarEvent('روز جهانی بال مرغ', false)]); diff --git a/persian-calendar@iamrezamousavi.gmail.com/extension.js b/persian-calendar@iamrezamousavi.gmail.com/extension.js index 46ceec6..98e568b 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/extension.js +++ b/persian-calendar@iamrezamousavi.gmail.com/extension.js @@ -43,11 +43,11 @@ export default class PersianCalendar extends Extension { Gio.SettingsBindFlags.DEFAULT ); - this.settings.connect('changed::position', () => { + this.settings.connect('changed::indicator-position', () => { this.disable(); this.enable(); }); - this.settings.connect('changed::index', () => { + this.settings.connect('changed::indicator-index', () => { this.disable(); this.enable(); }); @@ -57,17 +57,17 @@ export default class PersianCalendar extends Extension { this.enable(); }); - this.settings.connect('changed::top-panel-persian-number', () => { + this.settings.connect('changed::panel-persian-number', () => { this.disable(); this.enable(); }); - this.settings.connect('changed::calendar-weekday-persian-number', () => { + this.settings.connect('changed::calendar-persian-weekday', () => { this.disable(); this.enable(); }); - this.settings.connect('changed::calendar-day-persian-number', () => { + this.settings.connect('changed::calendar-persian-number', () => { this.disable(); this.enable(); }); @@ -87,7 +87,7 @@ export default class PersianCalendar extends Extension { this.enable(); }); - this.settings.connect('changed::unofficial-events-active', () => { + this.settings.connect('changed::international-events-active', () => { this.disable(); this.enable(); }); @@ -95,8 +95,8 @@ export default class PersianCalendar extends Extension { Main.panel.addToStatusArea( this.uuid, this._indicator, - this.settings.get_int('index'), - this.settings.get_string('position') + this.settings.get_int('indicator-index'), + this.settings.get_string('indicator-position') ); } diff --git a/persian-calendar@iamrezamousavi.gmail.com/prefs.js b/persian-calendar@iamrezamousavi.gmail.com/prefs.js index 9befb1a..c6df7be 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/prefs.js +++ b/persian-calendar@iamrezamousavi.gmail.com/prefs.js @@ -13,175 +13,203 @@ export default class PersianCalendarPreferences extends ExtensionPreferences { // Create a preferences page and group const page = new Adw.PreferencesPage(); - const group = new Adw.PreferencesGroup(); - page.add(group); + + + /** ********* Indicator Settings **************/ + + const indicatorGroup = new Adw.PreferencesGroup(); + page.add(indicatorGroup); // Create a new preferences row - const row = new Adw.ActionRow({title: 'Show Extension Indicator'}); - group.add(row); + const showIndicatorRow = new Adw.ActionRow({title: 'Show Extension Indicator'}); + indicatorGroup.add(showIndicatorRow); // Create the switch and bind its value to the `show-indicator` key - const toggle = new Gtk.Switch({ + const showIndicatorSwitch = new Gtk.Switch({ active: settings.get_boolean('show-indicator'), valign: Gtk.Align.CENTER, }); settings.bind( 'show-indicator', - toggle, + showIndicatorSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); // Add the switch to the row - row.add_suffix(toggle); - row.activatable_widget = toggle; + showIndicatorRow.add_suffix(showIndicatorSwitch); + showIndicatorRow.activatable_widget = showIndicatorSwitch; - const posRow = new Adw.ActionRow({title: 'Position'}); - group.add(posRow); + const indicatorPosRow = new Adw.ActionRow({title: 'Position'}); + indicatorGroup.add(indicatorPosRow); - const pos = new Gtk.ComboBoxText({ - active: settings.get_string('position'), + const indicatorPos = new Gtk.ComboBoxText({ + active: settings.get_string('indicator-position'), }); - pos.append('left', 'left'); - pos.append('center', 'center'); - pos.append('right', 'right'); - settings.bind('position', pos, 'active-id', Gio.SettingsBindFlags.DEFAULT); - - const item = new Gtk.SpinButton(); - let adjustment = new Gtk.Adjustment(); - adjustment.set_lower(-99); - adjustment.set_upper(99); - adjustment.set_step_increment(1); - item.set_adjustment(adjustment); - item.set_value(settings.get_int('index')); - settings.bind('index', item, 'value', Gio.SettingsBindFlags.DEFAULT); - - posRow.add_suffix(pos); - posRow.add_suffix(item); - - const formatRow = new Adw.ActionRow({title: 'Panel Date Format'}); - group.add(formatRow); - - const format = new Gtk.Entry(); - format.set_text(settings.get_string('panel-format')); - format.connect('changed', innerFormat => { + indicatorPos.append('left', 'left'); + indicatorPos.append('center', 'center'); + indicatorPos.append('right', 'right'); + settings.bind( + 'indicator-position', + indicatorPos, + 'active-id', + Gio.SettingsBindFlags.DEFAULT + ); + + indicatorPosRow.add_suffix(indicatorPos); + + const indicatorIndex = new Gtk.SpinButton(); + let indicatorIndexAdjustment = new Gtk.Adjustment(); + indicatorIndexAdjustment.set_lower(-99); + indicatorIndexAdjustment.set_upper(99); + indicatorIndexAdjustment.set_step_increment(1); + indicatorIndex.set_adjustment(indicatorIndexAdjustment); + indicatorIndex.set_value(settings.get_int('indicator-index')); + settings.bind('indicator-index', indicatorIndex, 'value', Gio.SettingsBindFlags.DEFAULT); + + indicatorPosRow.add_suffix(indicatorIndex); + + /** ************ End Indicator Settings ***************/ + + + /** ************ Locale Settings ***************/ + + const localeGroup = new Adw.PreferencesGroup(); + page.add(localeGroup); + + const panelFormatRow = new Adw.ActionRow({title: 'Panel Date Format'}); + localeGroup.add(panelFormatRow); + + const panelFormat = new Gtk.Entry(); + panelFormat.set_text(settings.get_string('panel-format')); + panelFormat.connect('changed', innerFormat => { settings.set_string('panel-format', innerFormat.text); }); - formatRow.add_suffix(format); + panelFormatRow.add_suffix(panelFormat); - const toPersianRow = new Adw.ActionRow({title: 'Use Persian Digit'}); - group.add(toPersianRow); + const panelPersianDigitRow = new Adw.ActionRow({title: 'Use Persian Digit on panel'}); + localeGroup.add(panelPersianDigitRow); - const toPersian = new Gtk.Switch({ - active: settings.get_boolean('top-panel-persian-number'), + const panelPersianDigitSwitch = new Gtk.Switch({ + active: settings.get_boolean('panel-persian-number'), valign: Gtk.Align.CENTER, }); settings.bind( - 'top-panel-persian-number', - toPersian, + 'panel-persian-number', + panelPersianDigitSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - toPersianRow.add_suffix(toPersian); - toPersianRow.activatable_widget = toPersian; + panelPersianDigitRow.add_suffix(panelPersianDigitSwitch); + panelPersianDigitRow.activatable_widget = panelPersianDigitSwitch; - const persianWeekdayRow = new Adw.ActionRow({title: 'Use Persian Weekday'}); - group.add(persianWeekdayRow); + const calPersianWeekdayRow = new Adw.ActionRow({title: 'Use Persian Weekday in calendar'}); + localeGroup.add(calPersianWeekdayRow); - const persianWeekday = new Gtk.Switch({ - active: settings.get_boolean('calendar-weekday-persian-number'), + const calPersianWeekdaySwitch = new Gtk.Switch({ + active: settings.get_boolean('calendar-persian-weekday'), valign: Gtk.Align.CENTER, }); settings.bind( - 'calendar-weekday-persian-number', - persianWeekday, + 'calendar-persian-weekday', + calPersianWeekdaySwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - persianWeekdayRow.add_suffix(persianWeekday); - persianWeekdayRow.activatable_widget = persianWeekday; + calPersianWeekdayRow.add_suffix(calPersianWeekdaySwitch); + calPersianWeekdayRow.activatable_widget = calPersianWeekdaySwitch; - const persianCalDayRow = new Adw.ActionRow({title: 'Use Persian Number in Calendar'}); - group.add(persianCalDayRow); + const persianCalNumRow = new Adw.ActionRow({title: 'Use Persian Number in Calendar'}); + localeGroup.add(persianCalNumRow); - const persianCalDay = new Gtk.Switch({ - active: settings.get_boolean('calendar-day-persian-number'), + const persianCalNum = new Gtk.Switch({ + active: settings.get_boolean('calendar-persian-number'), valign: Gtk.Align.CENTER, }); settings.bind( - 'calendar-day-persian-number', - persianCalDay, + 'calendar-persian-number', + persianCalNum, 'active', Gio.SettingsBindFlags.DEFAULT ); - persianCalDayRow.add_suffix(persianCalDay); - persianCalDayRow.activatable_widget = persianCalDay; + persianCalNumRow.add_suffix(persianCalNum); + persianCalNumRow.activatable_widget = persianCalNum; + + /** ************ End Locale Settings ***************/ + + + /** ************ Event Settings ***************/ + + const eventsGroup = new Adw.PreferencesGroup(); + page.add(eventsGroup); // Event Switchs const gregorianEventsRow = new Adw.ActionRow({title: 'Show Gregorian Events'}); - group.add(gregorianEventsRow); + eventsGroup.add(gregorianEventsRow); - const gregorianEvents = new Gtk.Switch({ + const gregorianEventsSwitch = new Gtk.Switch({ active: settings.get_boolean('gregorian-events-active'), valign: Gtk.Align.CENTER, }); settings.bind( 'gregorian-events-active', - gregorianEvents, + gregorianEventsSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - gregorianEventsRow.add_suffix(gregorianEvents); - gregorianEventsRow.activatable_widget = gregorianEvents; + gregorianEventsRow.add_suffix(gregorianEventsSwitch); + gregorianEventsRow.activatable_widget = gregorianEventsSwitch; const persianEventRow = new Adw.ActionRow({title: 'Show Persian Events'}); - group.add(persianEventRow); + eventsGroup.add(persianEventRow); - const persianEvents = new Gtk.Switch({ + const persianEventsSwitch = new Gtk.Switch({ active: settings.get_boolean('persian-events-active'), valign: Gtk.Align.CENTER, }); settings.bind( 'persian-events-active', - persianEvents, + persianEventsSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - persianEventRow.add_suffix(persianEvents); - persianEventRow.activatable_widget = persianEvents; + persianEventRow.add_suffix(persianEventsSwitch); + persianEventRow.activatable_widget = persianEventsSwitch; const hijriEventsRow = new Adw.ActionRow({title: 'Show Hijri Events'}); - group.add(hijriEventsRow); + eventsGroup.add(hijriEventsRow); - const hijriEvents = new Gtk.Switch({ + const hijriEventsSwitch = new Gtk.Switch({ active: settings.get_boolean('hijri-events-active'), valign: Gtk.Align.CENTER, }); settings.bind( 'hijri-events-active', - hijriEvents, + hijriEventsSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - hijriEventsRow.add_suffix(hijriEvents); - hijriEventsRow.activatable_widget = hijriEvents; + hijriEventsRow.add_suffix(hijriEventsSwitch); + hijriEventsRow.activatable_widget = hijriEventsSwitch; - const unofficialEventRow = new Adw.ActionRow({title: 'Show Unofficial World Events'}); - group.add(unofficialEventRow); + const internationalEventRow = new Adw.ActionRow({title: 'Show International World Events'}); + eventsGroup.add(internationalEventRow); - const unofficialEvents = new Gtk.Switch({ - active: settings.get_boolean('unofficial-events-active'), + const internationalEventsSwitch = new Gtk.Switch({ + active: settings.get_boolean('international-events-active'), valign: Gtk.Align.CENTER, }); settings.bind( - 'unofficial-events-active', - unofficialEvents, + 'international-events-active', + internationalEventsSwitch, 'active', Gio.SettingsBindFlags.DEFAULT ); - unofficialEventRow.add_suffix(unofficialEvents); - unofficialEventRow.activatable_widget = unofficialEvents; + internationalEventRow.add_suffix(internationalEventsSwitch); + internationalEventRow.activatable_widget = internationalEventsSwitch; + + /** ************ End Event Settings ***************/ // Add our page to the window window.add(page); diff --git a/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml b/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml index f250242..bc38015 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml +++ b/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml @@ -1,33 +1,36 @@ + true - + "center" Indicator position in top panel - + 0 Indicator position in selected area + "d mmmm yyyy" Panel date format - + true Use persian digit in top panel - + true Use persian digit in calendar weekday - + true Use persian digit in calendar day + true Show Gregorian Events @@ -40,9 +43,10 @@ true Show Hijri Events - + true - Show Unofficial World Events + Show International World Events + \ No newline at end of file