Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[email protected]: Improve code readability #12338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions files/usr/share/cinnamon/applets/[email protected]/appGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const PopupMenu = imports.ui.popupMenu;
const Mainloop = imports.mainloop;
const {SignalManager} = imports.misc.signalManager;
const {unref} = imports.misc.util;
const {createStore} = imports.misc.state;

const createStore = require('./state');
const {AppMenuButtonRightClickMenu, HoverMenuController, AppThumbnailHoverMenu} = require('./menus');
const {
FLASH_INTERVAL,
Expand Down Expand Up @@ -62,7 +62,7 @@ const getFocusState = function(metaWindow) {
class AppGroup {
constructor(params) {
this.state = params.state;
this.listState = params.listState;
this.workspaceState = params.workspaceState;
this.groupState = createStore({
app: params.app,
appId: params.appId,
Expand Down Expand Up @@ -254,10 +254,10 @@ class AppGroup {
}

setMargin() {
const applet = this.state.appletActor;
const appletActor = this.state.appletActor;
const direction = this.state.isHorizontal ? 'right' : 'bottom';
const existingStyle = this.actor.style ? this.actor.style : '';
let spacing = parseInt(applet.get_theme_node().get_length('spacing'));
let spacing = parseInt(appletActor.get_theme_node().get_length('spacing'));
if (!spacing) {
spacing = 6;
}
Expand Down Expand Up @@ -346,7 +346,7 @@ class AppGroup {

const allocateForLabel = this.labelVisiblePref ||
(this.state.settings.titleDisplay == TitleDisplay.Focused &&
this.listState.lastFocusedApp === appId);
this.workspaceState.lastFocusedApp === appId);

if (this.state.orientation === St.Side.TOP || this.state.orientation === St.Side.BOTTOM) {
if (allocateForLabel) {
Expand Down Expand Up @@ -581,13 +581,13 @@ class AppGroup {
const {appId, metaWindows, lastFocused} = this.groupState;

if (hasFocus === undefined) {
hasFocus = this.listState.lastFocusedApp === appId;
hasFocus = this.workspaceState.lastFocusedApp === appId;
}

// If any of the windows associated with our app have focus,
// we should set ourselves to active
if (hasFocus) {
this.listState.trigger('updateFocusState', appId);
this.workspaceState.trigger('updateFocusState', appId);
this.actor.add_style_pseudo_class('focus');
this.actor.remove_style_class_name('grouped-window-list-item-demands-attention');
if (this.hoverMenu) {
Expand All @@ -609,17 +609,17 @@ class AppGroup {
if (!this.groupState || !this.groupState.groupReady || this.groupState.willUnmount) {
return;
}
const windows = this.groupState.metaWindows;
for (let i = 0, len = windows.length; i < len; i++) {
if (windows[i] === metaWindow && !getFocusState(windows[i])) {

this.groupState.metaWindows.forEach( window => {
if (window === metaWindow && !getFocusState(window)) {
// Even though this may not be the last focused window, we want it to be
// the window that gets focused when a user responds to an alert.
this.groupState.set({lastFocused: metaWindow});
this.handleButtonLabel(metaWindow);
this.getAttention();
return true;
}
}
});
return false;
}

Expand Down Expand Up @@ -654,7 +654,7 @@ class AppGroup {
Main.activateWindow(this.groupState.lastFocused, global.get_current_time());
} else {
if (this.groupState.fileDrag) {
this.listState.trigger('closeAllHoverMenus');
this.workspaceState.trigger('closeAllHoverMenus');
}
// Open the thumbnail menu and activate the window corresponding to the dragged over thumbnail.
if (!this.hoverMenu) this.initThumbnailMenu();
Expand Down Expand Up @@ -800,13 +800,13 @@ class AppGroup {
} else if (button === 3) {
if (!this.rightClickMenu) this.initRightClickMenu();
if (!this.rightClickMenu.isOpen) {
this.listState.trigger('closeAllRightClickMenus', () => {
this.listState.trigger('closeAllHoverMenus', () => {
this.workspaceState.trigger('closeAllRightClickMenus', () => {
this.workspaceState.trigger('closeAllHoverMenus', () => {
this.rightClickMenu.toggle();
});
});
} else {
this.listState.trigger('closeAllRightClickMenus', this.listState.trigger('closeAllHoverMenus'));
this.workspaceState.trigger('closeAllRightClickMenus', this.workspaceState.trigger('closeAllHoverMenus'));
}
}
if (this.hoverMenu) this.hoverMenu.onButtonPress();
Expand All @@ -833,7 +833,7 @@ class AppGroup {
if (!this.hoverMenu) this.initThumbnailMenu();
this.hoverMenu.open(true);
} else {
this.listState.trigger('closeAllHoverMenus');
this.workspaceState.trigger('closeAllHoverMenus');
}
this.windowHandle();
this.appKeyTimeout = setTimeout(() => {
Expand Down Expand Up @@ -948,7 +948,7 @@ class AppGroup {
this.calcWindowNumber();
} else {
// This is the last window, so this group needs to be destroyed. We'll call back windowRemoved
// in appList to put the final nail in the coffin.
// in workspace to put the final nail in the coffin.
if (typeof cb === 'function') {
if (this.hoverMenu && this.groupState.isFavoriteApp) {
this.groupState.trigger('removeThumbnailFromMenu', metaWindow);
Expand All @@ -959,10 +959,10 @@ class AppGroup {
}

onAppChange(metaWindow) {
if (!this.listState) return;
if (!this.workspaceState) return;

this.listState.trigger('windowRemoved', metaWindow);
this.listState.trigger('windowAdded', metaWindow);
this.workspaceState.trigger('windowRemoved', metaWindow);
this.workspaceState.trigger('windowAdded', metaWindow);
}

onWindowTitleChanged(metaWindow, refresh) {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ class AppGroup {

const hasFocus = getFocusState(metaWindow);
if (hasFocus && this.groupState.hasOwnProperty('lastFocused')) {
this.listState.set({lastFocusedApp: this.groupState.appId});
this.workspaceState.set({lastFocusedApp: this.groupState.appId});
this.groupState.set({lastFocused: metaWindow});
}
this.onFocusChange(hasFocus);
Expand Down Expand Up @@ -1058,7 +1058,7 @@ class AppGroup {
if (this.actor.is_finalized()) return;

if (changed) {
setTimeout(() => this.listState.trigger('updateAppGroupIndexes', this.groupState.appId), 0);
setTimeout(() => this.workspaceState.trigger('updateAppGroupIndexes', this.groupState.appId), 0);
}

if (this.groupState.metaWindows.length === 0 && this.state.appletReady) {
Expand Down Expand Up @@ -1163,7 +1163,7 @@ class AppGroup {
this.hoverMenu.destroy();
}

this.listState.trigger('removeChild', this.actor);
this.workspaceState.trigger('removeChild', this.actor);
this.actor.destroy();

if (!skipRefCleanup) {
Expand Down
Loading
Loading