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

Add option to disable reorder on WEG and Toolbar: Feat(#412) #533

Open
wants to merge 8 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
3 changes: 3 additions & 0 deletions src/apps/seelenweg/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ app_menu:
pin_to_right: Pin to Right
run_as: Run as Administrator
unpin: Unpin
context_menu:
reorder_disable: Lock taskbar
reorder_enable: Unlock taskbar
media:
not_playing: Nothing is playing
media_menu:
Expand Down
5 changes: 3 additions & 2 deletions src/apps/seelenweg/modules/bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function SeelenWeg() {
const settings = useSelector(Selectors.settings);
const isOverlaped = useSelector(Selectors.isOverlaped);

let isReorderDisabled: boolean = useSelector(Selectors.reorderDisabled);
const pinnedOnLeft = useSelector(Selectors.itemsOnLeft);
const pinnedOnCenter = useSelector(Selectors.itemsOnCenter);
const pinnedOnRight = useSelector(Selectors.itemsOnRight);
Expand Down Expand Up @@ -165,15 +166,15 @@ export function SeelenWeg() {
const projectSwItem = (item: SwItem) => ItemByType(item, shit);

return (
<WithContextMenu items={getSeelenWegMenu(t, isTemporalOnlyWegBar)}>
<WithContextMenu items={getSeelenWegMenu(t, isTemporalOnlyWegBar, isReorderDisabled)}>
<Reorder.Group
as="div"
values={
isTemporalOnlyWegBar
? [...pinnedOnLeft, ...pinnedOnCenter, ...pinnedOnRight]
: [...pinnedOnLeft, Separator1, ...pinnedOnCenter, Separator2, ...pinnedOnRight]
}
onReorder={onReorderPinned}
onReorder={!isReorderDisabled ? onReorderPinned : () => {}}
axis={isHorizontal ? 'x' : 'y'}
className={cx('taskbar', settings.position.toLowerCase(), {
horizontal: isHorizontal,
Expand Down
10 changes: 9 additions & 1 deletion src/apps/seelenweg/modules/bar/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RootActions } from '../shared/store/app';

import { Icon } from '../../../shared/components/Icon';

export function getSeelenWegMenu(t: TFunction, restrictedBar?: boolean): ItemType[] {
export function getSeelenWegMenu(t: TFunction, restrictedBar?: boolean, isReorderDisabled?: boolean): ItemType[] {
if (!!restrictedBar) {
return [
{
Expand Down Expand Up @@ -86,6 +86,14 @@ export function getSeelenWegMenu(t: TFunction, restrictedBar?: boolean): ItemTyp
{
type: 'divider',
},
{
key: 'reoder',
icon: <Icon iconName={!isReorderDisabled ? 'VscLock' : 'VscUnlock' } />,
label: t(!isReorderDisabled ? 'context_menu.reorder_disable' : 'context_menu.reorder_enable' ),
onClick() {
store.dispatch(RootActions.setWegReorderDisabled(!isReorderDisabled));
},
},
{
key: 'task_manager',
label: t('taskbar_menu.task_manager'),
Expand Down
5 changes: 3 additions & 2 deletions src/apps/seelenweg/modules/item/infra/DraggableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import { cx } from '../../../../shared/styles';
interface Props extends PropsWithChildren {
item: SwItem;
className?: String;
drag?: boolean;
luriusTM marked this conversation as resolved.
Show resolved Hide resolved
}

export function DraggableItem({ children, item, className }: Props) {
export function DraggableItem({ children, item, className, drag }: Props) {
const ref = useRef<HTMLDivElement>(null);

return (
<Reorder.Item
as="div"
ref={ref}
value={item}
drag
drag={drag}
className={cx('weg-item-drag-container', className)}
onDragStart={() => {
ref.current?.classList.add('dragging');
Expand Down
1 change: 1 addition & 0 deletions src/apps/seelenweg/modules/item/infra/UserApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const UserApplication = memo(({ item, onAssociatedViewOpenChanged }: Prop
return (
<DraggableItem
item={item}
drag
className={cx({ 'associated-view-open': openPreview || openContextMenu })}
>
<WithContextMenu
Expand Down
5 changes: 5 additions & 0 deletions src/apps/seelenweg/modules/shared/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const initialState: RootState = {
itemsOnLeft: [],
itemsOnCenter: [],
itemsOnRight: [],
reorderDisabled: false,
focusedApp: null,
isOverlaped: false,
settings: (await Settings.default()).seelenweg,
Expand Down Expand Up @@ -76,6 +77,10 @@ export const RootSlice = createSlice({
}
savePinnedItems(current(state));
},
setWegReorderDisabled(state, isDisabled: PayloadAction<boolean>) {
state.reorderDisabled = isDisabled.payload;
savePinnedItems(current(state));
},
},
});

Expand Down
1 change: 1 addition & 0 deletions src/apps/seelenweg/modules/shared/store/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface RootState extends IRootState<SeelenWegSettings> {
itemsOnLeft: SwItem[];
itemsOnCenter: SwItem[];
itemsOnRight: SwItem[];
reorderDisabled: boolean;
// ----------------------
focusedApp: FocusedApp | null;
isOverlaped: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/apps/seelenweg/modules/shared/store/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function loadSettingsToStore(settings: Settings) {
}

function loadWegItemsToStore(items: WegItems) {
store.dispatch(RootActions.setReorderDisabled(items.inner.isReorderDisabled));
store.dispatch(RootActions.setItemsOnLeft(items.inner.left));
store.dispatch(RootActions.setItemsOnCenter(items.inner.center));
store.dispatch(RootActions.setItemsOnRight(items.inner.right));
Expand Down
2 changes: 1 addition & 1 deletion src/apps/seelenweg/modules/shared/store/storeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const savePinnedItems = debounce(
};

const data = new WegItems({
isReorderDisabled: false,
isReorderDisabled: state.reorderDisabled,
left: state.itemsOnLeft.filter(cb),
center: state.itemsOnCenter.filter(cb),
right: state.itemsOnRight.filter(cb),
Expand Down
2 changes: 2 additions & 0 deletions src/apps/toolbar/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ context_menu:
add_module: Add Module
remove: Remove Module
settings: Settings
reorder_disable: Lock toolbar
reorder_enable: Unlock toolbar
task_manager: Task Manager
media:
device:
Expand Down
1 change: 1 addition & 0 deletions src/apps/toolbar/modules/item/infra/Inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export function InnerItem(props: InnerItemProps) {
<Reorder.Item
{...rest}
id={id}
drag
value={(module as any).__value__ || module}
style={style}
className={cx('ft-bar-item', {
Expand Down
9 changes: 9 additions & 0 deletions src/apps/toolbar/modules/main/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export function MainContextMenu() {
{
type: 'divider',
},
{
luriusTM marked this conversation as resolved.
Show resolved Hide resolved
key: 'reoder',
icon: <Icon iconName={!items.isReorderDisabled ? 'VscLock' : 'VscUnlock' } />,
label: t(!items.isReorderDisabled ? 'context_menu.reorder_disable' : 'context_menu.reorder_enable' ),
onClick() {
dispatch(RootActions.setToolbarReorderDisabled(!items.isReorderDisabled));
SaveToolbarItems();
},
},
{
key: 'task_manager',
icon: <Icon iconName="PiChartLineFill" />,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/main/infra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function ToolBar() {
DividerEnd,
...structure.right,
]}
onReorder={onReorderPinned}
onReorder={!structure.isReorderDisabled ? onReorderPinned : () => {}}
className={cx('ft-bar', {
'ft-bar-hidden': shouldBeHidden,
'ft-bar-delayed': delayed,
Expand Down
6 changes: 6 additions & 0 deletions src/apps/toolbar/modules/shared/store/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice, Dispatch, PayloadAction } from '@reduxjs/toolkit';
import {
ApplicationHistory,

Check failure on line 3 in src/apps/toolbar/modules/shared/store/app.ts

View workflow job for this annotation

GitHub Actions / js-test-and-linter

Module '"@seelen-ui/lib"' has no exported member 'ApplicationHistory'.
DesktopFolder,
DocumentsFolder,
DownloadsFolder,
Expand Down Expand Up @@ -110,6 +110,12 @@
state.items.right = state.items.right.filter(filter);
}
},
setToolbarReorderDisabled(state, action: PayloadAction<boolean>) {
let enabled = action.payload;
if (state.items) {
state.items.isReorderDisabled = enabled;
}
},
},
});

Expand Down
1 change: 1 addition & 0 deletions src/background/state/application/toolbar_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::FullState;
impl FullState {
fn initial_toolbar_items() -> Placeholder {
Placeholder {
is_reorder_disabled: false,
left: vec![
ToolbarItem2::Plugin("@default/user-folder".into()),
ToolbarItem2::Inline(ToolbarItem::Text(TextToolbarItem {
Expand Down
Loading