|
|
@ -1,43 +1,83 @@
|
|
|
|
|
|
|
|
// 导入 vscode 模块中的 API 接口
|
|
|
|
import { API } from '../vscode';
|
|
|
|
import { API } from '../vscode';
|
|
|
|
|
|
|
|
// 导入 actions 模块中的 Action 和 ActionType 类型
|
|
|
|
import { Action, ActionType } from './actions';
|
|
|
|
import { Action, ActionType } from './actions';
|
|
|
|
|
|
|
|
// 导入 state 模块中的默认状态、配置编辑器状态、新配置状态和开始屏幕状态
|
|
|
|
import { DEFAULT_STATE, IConfigEditorState, INewConfigState, IStartScreenState, IState } from './state';
|
|
|
|
import { DEFAULT_STATE, IConfigEditorState, INewConfigState, IStartScreenState, IState } from './state';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置当前视图并发送消息到 VSCode API
|
|
|
|
|
|
|
|
* @param state - 当前状态
|
|
|
|
|
|
|
|
* @returns 更新后的状态
|
|
|
|
|
|
|
|
*/
|
|
|
|
function setView(state: IState): IState {
|
|
|
|
function setView(state: IState): IState {
|
|
|
|
|
|
|
|
// 向 VSCode API 发送消息,通知视图已更改
|
|
|
|
API.postMessage({ type: 'navigated', view: state.view });
|
|
|
|
API.postMessage({ type: 'navigated', view: state.view });
|
|
|
|
|
|
|
|
// 返回更新后的状态
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Redux reducer 函数,根据传入的动作类型更新状态
|
|
|
|
|
|
|
|
* @param state - 当前状态
|
|
|
|
|
|
|
|
* @param action - 要执行的动作
|
|
|
|
|
|
|
|
* @returns 更新后的状态
|
|
|
|
|
|
|
|
*/
|
|
|
|
export function reducer(state = DEFAULT_STATE, action: Action): IState {
|
|
|
|
export function reducer(state = DEFAULT_STATE, action: Action): IState {
|
|
|
|
|
|
|
|
// 根据动作类型进行状态更新
|
|
|
|
switch (action.type) {
|
|
|
|
switch (action.type) {
|
|
|
|
// Startscreen
|
|
|
|
// Startscreen
|
|
|
|
|
|
|
|
// 打开开始屏幕
|
|
|
|
case ActionType.OPEN_STARTSCREEN: {
|
|
|
|
case ActionType.OPEN_STARTSCREEN: {
|
|
|
|
|
|
|
|
// 获取分组依据,默认为当前开始屏幕状态的分组依据
|
|
|
|
const groupBy = action.groupBy || (state as IStartScreenState).groupBy || 'group';
|
|
|
|
const groupBy = action.groupBy || (state as IStartScreenState).groupBy || 'group';
|
|
|
|
|
|
|
|
// 设置视图为开始屏幕,并更新分组依据
|
|
|
|
return setView({ ...state, view: 'startscreen', groupBy });
|
|
|
|
return setView({ ...state, view: 'startscreen', groupBy });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// New Config
|
|
|
|
// New Config
|
|
|
|
|
|
|
|
// 打开新配置界面
|
|
|
|
case ActionType.OPEN_NEWCONFIG: {
|
|
|
|
case ActionType.OPEN_NEWCONFIG: {
|
|
|
|
|
|
|
|
// 获取新配置的名称
|
|
|
|
const { name } = action;
|
|
|
|
const { name } = action;
|
|
|
|
|
|
|
|
// 设置视图为新配置,并更新名称和位置
|
|
|
|
return setView({ ...state, view: 'newconfig', name, location: undefined });
|
|
|
|
return setView({ ...state, view: 'newconfig', name, location: undefined });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置新配置的名称
|
|
|
|
case ActionType.NEWCONFIG_SETNAME:
|
|
|
|
case ActionType.NEWCONFIG_SETNAME:
|
|
|
|
|
|
|
|
// 更新新配置的名称
|
|
|
|
return { ...state as INewConfigState, name: action.name };
|
|
|
|
return { ...state as INewConfigState, name: action.name };
|
|
|
|
|
|
|
|
// 设置新配置的位置
|
|
|
|
case ActionType.NEWCONFIG_SETLOCATION:
|
|
|
|
case ActionType.NEWCONFIG_SETLOCATION:
|
|
|
|
|
|
|
|
// 更新新配置的位置
|
|
|
|
return { ...state as INewConfigState, location: action.location };
|
|
|
|
return { ...state as INewConfigState, location: action.location };
|
|
|
|
// ConfigEditor
|
|
|
|
// ConfigEditor
|
|
|
|
|
|
|
|
// 打开配置编辑器
|
|
|
|
case ActionType.OPEN_CONFIGEDITOR: {
|
|
|
|
case ActionType.OPEN_CONFIGEDITOR: {
|
|
|
|
|
|
|
|
// 获取要编辑的配置
|
|
|
|
const { config } = action;
|
|
|
|
const { config } = action;
|
|
|
|
|
|
|
|
// 设置视图为配置编辑器,并更新旧配置和新配置
|
|
|
|
return setView({ ...state, view: 'configeditor', oldConfig: config, newConfig: config });
|
|
|
|
return setView({ ...state, view: 'configeditor', oldConfig: config, newConfig: config });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 打开配置定位器
|
|
|
|
case ActionType.OPEN_CONFIGLOCATOR: {
|
|
|
|
case ActionType.OPEN_CONFIGLOCATOR: {
|
|
|
|
|
|
|
|
// 获取要搜索的配置名称和配置列表
|
|
|
|
const { name, configs } = action;
|
|
|
|
const { name, configs } = action;
|
|
|
|
|
|
|
|
// 设置视图为配置定位器,并更新名称和配置列表
|
|
|
|
return setView({ ...state, view: 'configlocator', name, configs });
|
|
|
|
return setView({ ...state, view: 'configlocator', name, configs });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置配置编辑器中的新配置
|
|
|
|
case ActionType.CONFIGEDITOR_SETNEWCONFIG:
|
|
|
|
case ActionType.CONFIGEDITOR_SETNEWCONFIG:
|
|
|
|
|
|
|
|
// 更新配置编辑器中的新配置
|
|
|
|
return { ...state as IConfigEditorState, newConfig: action.config };
|
|
|
|
return { ...state as IConfigEditorState, newConfig: action.config };
|
|
|
|
|
|
|
|
// 设置配置编辑器的状态消息
|
|
|
|
case ActionType.CONFIGEDITOR_SETSTATUSMESSAGE:
|
|
|
|
case ActionType.CONFIGEDITOR_SETSTATUSMESSAGE:
|
|
|
|
|
|
|
|
// 更新配置编辑器的状态消息
|
|
|
|
return { ...state as IConfigEditorState, statusMessage: action.message };
|
|
|
|
return { ...state as IConfigEditorState, statusMessage: action.message };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果动作类型不匹配,返回当前状态
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导出默认的 reducer 函数
|
|
|
|
export default reducer;
|
|
|
|
export default reducer;
|
|
|
|
|
|
|
|
|
|
|
|