Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2504] Use tool position to place created node
Bug: #2504 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
- Loading branch information
Showing
17 changed files
with
243 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...grams/frontend/sirius-components-diagrams-reactflow/src/renderer/layout/LayoutContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import React, { useCallback, useState } from 'react'; | ||
import { | ||
LayoutContextContextProviderProps, | ||
LayoutContextContextProviderState, | ||
LayoutContextContextValue, | ||
} from './LayoutContext.types'; | ||
import { FutureNodePosition } from './useLayout.types'; | ||
|
||
const defaultValue: LayoutContextContextValue = { | ||
futureNodePosition: null, | ||
setFuturNodePosition: () => {}, | ||
resetFuturNodePosition: () => {}, | ||
}; | ||
|
||
export const LayoutContext = React.createContext<LayoutContextContextValue>(defaultValue); | ||
|
||
export const LayoutContextContextProvider = ({ children }: LayoutContextContextProviderProps) => { | ||
const [state, setState] = useState<LayoutContextContextProviderState>({ | ||
futureNodePosition: null, | ||
}); | ||
|
||
const setFuturNodePosition = useCallback((futureNodePosition: FutureNodePosition) => { | ||
setState((prevState) => ({ ...prevState, futureNodePosition })); | ||
}, []); | ||
|
||
const resetFuturNodePosition = useCallback(() => { | ||
setState((prevState) => ({ ...prevState, futureNodePosition: null })); | ||
}, []); | ||
|
||
return ( | ||
<LayoutContext.Provider | ||
value={{ | ||
futureNodePosition: state.futureNodePosition, | ||
setFuturNodePosition, | ||
resetFuturNodePosition, | ||
}}> | ||
{children} | ||
</LayoutContext.Provider> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
.../frontend/sirius-components-diagrams-reactflow/src/renderer/layout/LayoutContext.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { FutureNodePosition } from './useLayout.types'; | ||
export interface LayoutContextContextValue { | ||
futureNodePosition: FutureNodePosition | null; | ||
setFuturNodePosition: (futureNodePosition: FutureNodePosition) => void; | ||
resetFuturNodePosition: () => void; | ||
} | ||
|
||
export interface LayoutContextContextProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export interface LayoutContextContextProviderState { | ||
futureNodePosition: FutureNodePosition | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.