Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion src/debug/debug-adapters-yaml-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { PathType } from '../views/manage-solution/messages';
Comment thread
arneschmid marked this conversation as resolved.
Outdated
import { createInterfaceFactory } from '../generic/interface-factory';
import { ETextFileResult } from '../generic/text-file';
import { ITreeItem, CTreeItem } from '../generic/tree-item';
Expand All @@ -27,7 +28,8 @@ export type UIOption<T extends string, V> = {
description?: string; //Hover over text.
'yml-node': string; //Name of the node in the csolution file under debugger: section.
type: T; //Type of the option [number, enum, string, file]
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
pname?: string; //If present, the option is pname based. Then the same property will be created for each pname instance.
'path-type'?: PathType; //If the type is file, indicates if the path is absolute or relative to the solution file directory. Default is relative.
} & V;
Comment thread
arneschmid marked this conversation as resolved.

export type UIEnumValue = {
Expand Down
12 changes: 7 additions & 5 deletions src/views/manage-solution/manage-solution-webview-main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,13 @@ describe('ContextSelectionWebviewMain', () => {

const dialogOptions = showOpenDialogSpy.mock.calls[0][0];
expect(dialogOptions?.defaultUri?.toString()).toBe(URI.file(path.dirname(defaultPath)).toString());
expect(webviewManager.sendMessage).toHaveBeenCalledWith({
type: 'FILE_SELECTED',
data: ['images/app.axf'],
for: 'image-path'
});
expect(webviewManager.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
type: 'FILE_SELECTED',
data: ['images/app.axf'],
Comment thread
arneschmid marked this conversation as resolved.
for: 'image-path'
Comment thread
arneschmid marked this conversation as resolved.
})
);
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/views/manage-solution/manage-solution-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ export class ManageSolutionWebviewMain {

if (fileUri && fileUri[0]) {
const paths = fileUri.map(u =>
backToForwardSlashes(path.relative(solutionDir, u.fsPath))
backToForwardSlashes(options?.pathType === 'absolute'
? u.fsPath
: path.relative(solutionDir, u.fsPath)
)
Comment thread
arneschmid marked this conversation as resolved.
);

await this.webviewManager.sendMessage({ type: 'FILE_SELECTED', data: paths, for: targetElementId });
Expand Down
69 changes: 36 additions & 33 deletions src/views/manage-solution/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,51 @@
import { DebugAdapter } from '../../debug/debug-adapters-yaml-file';
import { ActiveTargetSet, SolutionData } from './view/state/manage-solution-state';

export type PathType = 'absolute' | 'relative';

Comment thread
arneschmid marked this conversation as resolved.
Outdated
export type FileSelectorOptionsType = {
canSelectMany?: boolean,
defaultUri?: string,
openLabel?: string,
title?: string,
filters?: { [key: string]: string[] }
canSelectMany?: boolean,
defaultUri?: string,
openLabel?: string,
title?: string,
pathType?: PathType,
filters?: { [key: string]: string[] }
};

/**
* Messages that the context selection view can pass to the extension.
*/
export type OutgoingMessage
= { type: 'GET_CONTEXT_SELECTION_DATA' }
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
| { type: 'OPEN_FILE', path: string }
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
| { type: 'GET_DEBUG_ADAPTERS' }
| { type: 'SET_DEBUGGER', name: string }
| { type: 'ADD_NEW_CONTEXT' }
| { type: 'ADD_NEW_PROJECT' }
| { type: 'ADD_NEW_IMAGE' }
| { type: 'UNLINK_IMAGE', image: string }
| { type: 'SET_START_PROCESSOR', value: string }
| { type: 'SAVE_CONTEXT_SELECTION' }
| { type: 'OPEN_HELP' }
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
| { type: 'SET_AUTO_UPDATE', value: boolean }
| { type: 'TOGGLE_DEBUGGER', value: boolean }
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
;
= { type: 'GET_CONTEXT_SELECTION_DATA' }
| { type: 'SET_SELECTED_TARGET', target: string, set: string | undefined }
| { type: 'OPEN_FILE', path: string }
| { type: 'SET_SELECTED_CONTEXTS', data: SolutionData }
| { type: 'GET_DEBUG_ADAPTERS' }
| { type: 'SET_DEBUGGER', name: string }
| { type: 'ADD_NEW_CONTEXT' }
| { type: 'ADD_NEW_PROJECT' }
| { type: 'ADD_NEW_IMAGE' }
| { type: 'UNLINK_IMAGE', image: string }
| { type: 'SET_START_PROCESSOR', value: string }
| { type: 'SAVE_CONTEXT_SELECTION' }
| { type: 'OPEN_HELP' }
| { type: 'SET_DEBUG_ADAPTER_PROPERTY', service: string | undefined, key: string, value: string | number, pname?: string }
| { type: 'SELECT_FILE', targetElementId: string, options?: FileSelectorOptionsType }
| { type: 'SET_AUTO_UPDATE', value: boolean }
| { type: 'TOGGLE_DEBUGGER', value: boolean }
| { type: 'TOGGLE_DEBUG_ADAPTER_SECTION', section: string }
;

/**
* Messages that the extension can pass to the context selection view.
*/
export type IncomingMessage
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
| { type: 'DEBUGGER', data: string }
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
| { type: 'IS_DIRTY', data: boolean }
| { type: 'IS_BUSY', data: boolean }
| { type: 'FILE_SELECTED', data: string[], for: string }
| { type: 'AUTO_UPDATE', data: boolean }
;
= { type: 'DATA_CONTEXT_SELECTION', data: SolutionData }
| { type: 'DEBUG_ADAPTERS', data: DebugAdapter[], sectionsInUse: string[] }
| { type: 'DEBUGGER', data: string }
| { type: 'ACTIVE_TARGET_SET', data: ActiveTargetSet }
| { type: 'IS_DIRTY', data: boolean }
| { type: 'IS_BUSY', data: boolean }
| { type: 'FILE_SELECTED', data: string[], for: string }
| { type: 'AUTO_UPDATE', data: boolean }
;
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SolutionUpdateAction, contextUpdateReducer, initialState, manageSolutio
import './manage-solution.css';
import { ProjectsTable } from './projects-table';
import { TargetsTable } from './targets-table';
import { PathType } from '../../messages';

export interface ManageSolutionProps {
messageHandler: MessageHandler<IncomingMessage, OutgoingMessage>;
Expand Down Expand Up @@ -212,6 +213,7 @@ export const ManageSolution = (props: ManageSolutionProps) => {
input?.setAttribute('id', id);
}
const title = input?.getAttribute('title') || 'Select File';
const optionPathType = input?.getAttribute('data-option-path-type') as (PathType | undefined) ?? 'relative';
Comment thread
arneschmid marked this conversation as resolved.
Outdated
const currentValue = input?.value || '';
props.messageHandler.push({
type: 'SELECT_FILE',
Expand All @@ -221,7 +223,8 @@ export const ManageSolution = (props: ManageSolutionProps) => {
defaultUri: currentValue,
openLabel: 'Select File', // title of the dialog button to choose the file
title: title, // dialog title
filters: { 'All Files': ['*'] }
filters: { 'All Files': ['*'] },
pathType: optionPathType
}
});
};
Expand Down Expand Up @@ -433,6 +436,7 @@ export const ManageSolution = (props: ManageSolutionProps) => {
addonAfter={<Button type="primary" className='file-button' onClick={selectFile}> Browse</Button>}
value={(localValues[k] as string) ?? ''}
data-yml-node={o['yml-node']}
data-option-path-type={o['path-type']}
onPressEnter={blurOnEnter}
onChange={(e) => {
setLocalValues(prev => ({ ...prev, [k]: e.target.value }));
Expand Down
Loading