From df6e40e68d3a39aef1c60aaad1a90c48588d9e6b Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 23 Jun 2025 11:13:50 +0200 Subject: [PATCH] =?UTF-8?q?Se=20agreg=C3=B3=20una=20nueva=20ruta=20API=20p?= =?UTF-8?q?ara=20obtener=20el=20archivo=20de=20soluci=C3=B3n=20(.sln)=20de?= =?UTF-8?q?=20proyectos=20C#,=20mejorando=20la=20gesti=C3=B3n=20de=20proye?= =?UTF-8?q?ctos=20C#=20en=20la=20aplicaci=C3=B3n.=20Adem=C3=A1s,=20se=20im?= =?UTF-8?q?plement=C3=B3=20la=20l=C3=B3gica=20para=20abrir=20el=20archivo?= =?UTF-8?q?=20de=20soluci=C3=B3n=20espec=C3=ADfico=20en=20Visual=20Studio?= =?UTF-8?q?=202022,=20si=20est=C3=A1=20disponible,=20al=20abrir=20un=20pro?= =?UTF-8?q?yecto.=20Se=20mejor=C3=B3=20la=20notificaci=C3=B3n=20al=20usuar?= =?UTF-8?q?io=20con=20informaci=C3=B3n=20sobre=20el=20archivo=20de=20soluc?= =?UTF-8?q?i=C3=B3n=20abierto.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 35 +++++++++++++++++++++++++-- lib/csharp_launcher_manager.py | 44 +++++++++++++++++++++++++++++++++- static/js/csharp_launcher.js | 29 ++++++++++++++++++++-- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 9871bb1..5b2cf86 100644 --- a/app.py +++ b/app.py @@ -993,6 +993,29 @@ def get_all_csharp_executables(project_id): except Exception as e: return jsonify({"error": str(e)}), 500 +@app.route("/api/csharp-solution-file/", 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 === @@ -1332,13 +1355,21 @@ def open_group_in_editor(editor, group_system, group_id): print(f"Launching {editor_name} from: {editor_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 - 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}") return jsonify({ "status": "success", - "message": f"{editor_name} abierto en: {script_group_path}" + "message": f"{editor_name} abierto en: {target_to_open}" }) except Exception as e: diff --git a/lib/csharp_launcher_manager.py b/lib/csharp_launcher_manager.py index 845dcb7..f4f67f9 100644 --- a/lib/csharp_launcher_manager.py +++ b/lib/csharp_launcher_manager.py @@ -977,4 +977,46 @@ class CSharpLauncherManager: with open(self.favorites_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2, ensure_ascii=False) except Exception as e: - print(f"Error cleaning favorites for project {project_id}: {e}") \ No newline at end of file + 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 \ No newline at end of file diff --git a/static/js/csharp_launcher.js b/static/js/csharp_launcher.js index f123834..db746f3 100644 --- a/static/js/csharp_launcher.js +++ b/static/js/csharp_launcher.js @@ -844,6 +844,19 @@ async function openCSharpProjectInEditor(editor) { const projectId = window.csharpLauncherManager.currentProject.id; 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}`, { method: 'POST', headers: { 'Content-Type': 'application/json' } @@ -852,10 +865,22 @@ async function openCSharpProjectInEditor(editor) { const result = await response.json(); if (response.ok && result.status === 'success') { const editorName = editor === 'cursor' ? 'Cursor' : 'Visual Studio 2022'; + let message = `${editorName} abierto exitosamente`; + + // 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 { + message = `${editorName} abierto (carpeta del proyecto)`; + } + } + if (window.csharpLauncherManager && window.csharpLauncherManager.showNotification) { - window.csharpLauncherManager.showNotification(`${editorName} abierto exitosamente`, 'success'); + window.csharpLauncherManager.showNotification(message, 'success'); } else { - alert(`${editorName} abierto exitosamente`); + alert(message); } } else { const errorMsg = `Error: ${result.message}`;