Se agregó una nueva ruta API para obtener el archivo de solución (.sln) de proyectos C#, mejorando la gestión de proyectos C# en la aplicación. Además, se implementó la lógica para abrir el archivo de solución específico en Visual Studio 2022, si está disponible, al abrir un proyecto. Se mejoró la notificación al usuario con información sobre el archivo de solución abierto.
This commit is contained in:
parent
13ceda63ba
commit
df6e40e68d
35
app.py
35
app.py
|
@ -993,6 +993,29 @@ def get_all_csharp_executables(project_id):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route("/api/csharp-solution-file/<project_id>", methods=["GET"])
|
||||||
|
def get_csharp_solution_file(project_id):
|
||||||
|
"""Obtener archivo de solución (.sln) del proyecto C#"""
|
||||||
|
try:
|
||||||
|
solution_file = csharp_launcher_manager.find_solution_file(project_id)
|
||||||
|
if solution_file:
|
||||||
|
return jsonify({
|
||||||
|
"status": "success",
|
||||||
|
"solution_file": solution_file,
|
||||||
|
"exists": True
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
return jsonify({
|
||||||
|
"status": "success",
|
||||||
|
"solution_file": None,
|
||||||
|
"exists": False
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
"status": "error",
|
||||||
|
"message": f"Error buscando archivo de solución: {str(e)}"
|
||||||
|
}), 500
|
||||||
|
|
||||||
# === FIN C# LAUNCHER APIs ===
|
# === FIN C# LAUNCHER APIs ===
|
||||||
|
|
||||||
|
|
||||||
|
@ -1332,13 +1355,21 @@ def open_group_in_editor(editor, group_system, group_id):
|
||||||
print(f"Launching {editor_name} from: {editor_path}")
|
print(f"Launching {editor_name} from: {editor_path}")
|
||||||
print(f"Opening directory: {script_group_path}")
|
print(f"Opening directory: {script_group_path}")
|
||||||
|
|
||||||
|
# Para Visual Studio 2022 y proyectos C#, intentar abrir archivo .sln específico
|
||||||
|
target_to_open = script_group_path
|
||||||
|
if editor == 'vs2022' and group_system == 'csharp':
|
||||||
|
solution_file = csharp_launcher_manager.find_solution_file(group_id)
|
||||||
|
if solution_file:
|
||||||
|
target_to_open = solution_file
|
||||||
|
print(f"Found solution file: {solution_file}")
|
||||||
|
|
||||||
# Ejecutar el editor
|
# Ejecutar el editor
|
||||||
process = subprocess.Popen(f'"{editor_path}" "{script_group_path}"', shell=True)
|
process = subprocess.Popen(f'"{editor_path}" "{target_to_open}"', shell=True)
|
||||||
print(f"{editor_name} process started with PID: {process.pid}")
|
print(f"{editor_name} process started with PID: {process.pid}")
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"message": f"{editor_name} abierto en: {script_group_path}"
|
"message": f"{editor_name} abierto en: {target_to_open}"
|
||||||
})
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -978,3 +978,45 @@ class CSharpLauncherManager:
|
||||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error cleaning favorites for project {project_id}: {e}")
|
print(f"Error cleaning favorites for project {project_id}: {e}")
|
||||||
|
|
||||||
|
def find_solution_file(self, project_id: str) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
Buscar archivo .sln en el directorio del proyecto.
|
||||||
|
Prioridades:
|
||||||
|
1. Si hay un solo .sln, retornarlo
|
||||||
|
2. Si hay múltiples .sln, buscar uno que coincida con el nombre del directorio
|
||||||
|
3. Si no hay coincidencias exactas, retornar el primero alfabéticamente
|
||||||
|
4. Si no hay .sln, retornar None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
project = self.get_csharp_project(project_id)
|
||||||
|
if not project:
|
||||||
|
return None
|
||||||
|
|
||||||
|
project_dir = project["directory"]
|
||||||
|
if not os.path.isdir(project_dir):
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Buscar archivos .sln en el directorio raíz del proyecto
|
||||||
|
sln_pattern = os.path.join(project_dir, "*.sln")
|
||||||
|
sln_files = glob.glob(sln_pattern)
|
||||||
|
|
||||||
|
if not sln_files:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if len(sln_files) == 1:
|
||||||
|
return sln_files[0]
|
||||||
|
|
||||||
|
# Si hay múltiples archivos, buscar uno que coincida con el nombre del directorio
|
||||||
|
project_name = os.path.basename(project_dir.rstrip(os.sep))
|
||||||
|
for sln_file in sln_files:
|
||||||
|
sln_name = os.path.splitext(os.path.basename(sln_file))[0]
|
||||||
|
if sln_name.lower() == project_name.lower():
|
||||||
|
return sln_file
|
||||||
|
|
||||||
|
# Si no hay coincidencias exactas, retornar el primero alfabéticamente
|
||||||
|
return sorted(sln_files)[0]
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error finding solution file for project {project_id}: {e}")
|
||||||
|
return None
|
|
@ -844,6 +844,19 @@ async function openCSharpProjectInEditor(editor) {
|
||||||
const projectId = window.csharpLauncherManager.currentProject.id;
|
const projectId = window.csharpLauncherManager.currentProject.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Para VS2022, primero verificar si hay archivo .sln disponible
|
||||||
|
let solutionInfo = null;
|
||||||
|
if (editor === 'vs2022') {
|
||||||
|
try {
|
||||||
|
const solutionResponse = await fetch(`/api/csharp-solution-file/${projectId}`);
|
||||||
|
if (solutionResponse.ok) {
|
||||||
|
solutionInfo = await solutionResponse.json();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('No se pudo verificar archivo de solución:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(`/api/open-editor/${editor}/csharp/${projectId}`, {
|
const response = await fetch(`/api/open-editor/${editor}/csharp/${projectId}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
@ -852,10 +865,22 @@ async function openCSharpProjectInEditor(editor) {
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (response.ok && result.status === 'success') {
|
if (response.ok && result.status === 'success') {
|
||||||
const editorName = editor === 'cursor' ? 'Cursor' : 'Visual Studio 2022';
|
const editorName = editor === 'cursor' ? 'Cursor' : 'Visual Studio 2022';
|
||||||
if (window.csharpLauncherManager && window.csharpLauncherManager.showNotification) {
|
let message = `${editorName} abierto exitosamente`;
|
||||||
window.csharpLauncherManager.showNotification(`${editorName} abierto exitosamente`, 'success');
|
|
||||||
|
// Agregar información específica para VS2022
|
||||||
|
if (editor === 'vs2022' && solutionInfo) {
|
||||||
|
if (solutionInfo.exists && solutionInfo.solution_file) {
|
||||||
|
const solutionName = solutionInfo.solution_file.split('\\').pop().split('/').pop();
|
||||||
|
message = `${editorName} abierto con solución: ${solutionName}`;
|
||||||
} else {
|
} else {
|
||||||
alert(`${editorName} abierto exitosamente`);
|
message = `${editorName} abierto (carpeta del proyecto)`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.csharpLauncherManager && window.csharpLauncherManager.showNotification) {
|
||||||
|
window.csharpLauncherManager.showNotification(message, 'success');
|
||||||
|
} else {
|
||||||
|
alert(message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const errorMsg = `Error: ${result.message}`;
|
const errorMsg = `Error: ${result.message}`;
|
||||||
|
|
Loading…
Reference in New Issue