Skip to content

Commit

Permalink
shows current profile on action bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Mjishu committed Jan 29, 2025
1 parent 0e63359 commit 03fefc5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ext/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ a:has(rt) {
background-color: var(--sidebar-background-color);
display: flex;
flex-flow: column nowrap;
align-items: center;
}
:root[data-popup-action-bar-location=top] .content-outer,
:root[data-popup-action-bar-location=bottom] .content-outer {
Expand Down Expand Up @@ -579,6 +580,11 @@ button.sidebar-button.sidebar-button-highlight {
--button-active-content-color: var(--accent-color);
}

.vertical-text {
writing-mode: vertical-rl;
text-orientation: upright;
}


/* Search page */
.search-header-wrapper {
Expand Down
16 changes: 16 additions & 0 deletions ext/js/display/display-profile-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class DisplayProfileSelection {
this._profileButton = querySelectorNotNull(document, '#profile-button');
/** @type {HTMLElement} */
const profilePanelElement = querySelectorNotNull(document, '#profile-panel');
/** @type {HTMLElement} */
this._profileLanguage = querySelectorNotNull(document, '#profile-language');
/** @type {PanelElement} */
this._profilePanel = new PanelElement(profilePanelElement, 375); // Milliseconds; includes buffer
/** @type {boolean} */
Expand All @@ -49,6 +51,7 @@ export class DisplayProfileSelection {
this._display.application.on('optionsUpdated', this._onOptionsUpdated.bind(this));
this._profileButton.addEventListener('click', this._onProfileButtonClick.bind(this), false);
this._profileListNeedsUpdate = true;
await this._updateProfileLanguage();
}

// Private
Expand Down Expand Up @@ -85,6 +88,17 @@ export class DisplayProfileSelection {
}
}

/**
*
*/
async _updateProfileLanguage() { // call this somewhere that gets updated when popActionBarLocation gets called?
const {profileCurrent, profiles} = await this._display.application.api.optionsGetFull();
const currentProfile = profiles[profileCurrent];
this._profileLanguage.textContent = currentProfile.name;
// ? currentprofile popactionbarlocation only changes on reload
// this._profileLanguage.textContent = currentProfile.options.general.popupActionBarLocation;
}

/** */
async _updateProfileList() {
this._profileListNeedsUpdate = false;
Expand All @@ -109,6 +123,7 @@ export class DisplayProfileSelection {
}
this._profileList.textContent = '';
this._profileList.appendChild(fragment);
await this._updateProfileLanguage();
}

/**
Expand Down Expand Up @@ -136,5 +151,6 @@ export class DisplayProfileSelection {
};
await this._display.application.api.modifySettings([modification], this._source);
this._setProfilePanelVisible(false);
await this._updateProfileLanguage();
}
}
14 changes: 14 additions & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export class Display extends EventDispatcher {
this._languageSummaries = [];
/** @type {import('dictionary-importer').Summary[]} */
this._dictionaryInfo = [];
/** @type {HTMLElement} */
this._profileLanguage = querySelectorNotNull(document, '#profile-language');

/* eslint-disable @stylistic/no-multi-spaces */
this._hotkeyHandler.registerActions([
Expand Down Expand Up @@ -443,6 +445,17 @@ export class Display extends EventDispatcher {
await this.updateOptions();
}

/**
* @param {import('settings').ProfileOptions} currentProfile
*/
async _updateCurrentProfileDisplay(currentProfile) {
if (currentProfile.general.popupActionBarLocation === 'left' || currentProfile.general.popupActionBarLocation === 'right') {
this._profileLanguage.classList.add('vertical-text');
} else {
this._profileLanguage.classList.remove('vertical-text');
}
}

/** */
async updateOptions() {
const options = await this._application.api.optionsGet(this.getOptionsContext());
Expand Down Expand Up @@ -484,6 +497,7 @@ export class Display extends EventDispatcher {

void this._updateNestedFrontend(options);
this._updateContentTextScanner(options);
await this._updateCurrentProfileDisplay(options);

this.trigger('optionsUpdated', {options});
}
Expand Down
1 change: 1 addition & 0 deletions ext/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ <h3>Default Profile</h3>
<button type="button" class="sidebar-button" disabled id="navigate-next-button" title="Next definition" data-hotkey='["historyForward","title","Next definition ({0})"]'><span class="sidebar-button-icon icon" data-icon="right-chevron"></span></button>
</div>
<div class="content-sidebar-bottom">
<p class="sidebar-profile-language" id="profile-language"></p>
<button type="button" class="sidebar-button" id="profile-button"><span class="sidebar-button-icon icon" data-icon="profile"></span></button>
</div>
</div>
Expand Down

0 comments on commit 03fefc5

Please sign in to comment.