selectTool method
切换主工具
Implementation
void selectTool(EditToolsMenu tool) {
if (isSingleToolMode) return;
EditToolsMenu? resolvedTool;
if (isCropTool(tool)) {
resolvedTool = _resolveCropTool(tool);
} else if (isRotateTool(tool)) {
resolvedTool = _resolveRotateTool(tool);
} else if (tool == EditToolsMenu.text) {
resolvedTool = isToolEnabled(tool) ? tool : null;
} else {
resolvedTool = tool;
}
if (resolvedTool == null) {
return; // 所请求的工具被禁用
}
if (_activeTool == resolvedTool) {
// 如果重复点击同一个工具,则关闭它
cancelCurrentTool();
return;
}
_activeTool = resolvedTool;
// 进入工具时,备份当前状态以便取消
if (isCroppingActive) {
_backupCropRect = _cropRect; // 备份当前裁剪框
_initializeCropRect(aspectRatio: _getCurrentAspectRatio());
} else {
_cropRect = null; // 确保非裁剪模式下没有裁剪框
}
if (isRotateTool(_activeTool)) {
_backupRotationAngle = _currentRotationAngle; // 备份当前旋转角度
}
notifyListeners();
}