Support opening 'project' files like .csproj

This commit is contained in:
Sage Vaillancourt 2023-03-07 11:35:19 -05:00
parent ba1c32b383
commit b0cfe40b96
1 changed files with 18 additions and 11 deletions

View File

@ -21,25 +21,29 @@ def get_application_desktop_file_info(application: str, prefix: str) -> str:
return line
def get_project_type(project) -> str:
def get_project_type(project) -> (str, str):
ret = ("idea", None)
for file in os.listdir(project):
if file.endswith("pom.xml"):
return "idea"
return ("idea", None)
if file.endswith("package.json"):
return "webstorm"
return ("webstorm", None)
if file.endswith("cargo.toml") or file.endswith(".c"):
return "clion"
if file.endswith(".csproj") or file.endswith("DotSettings"):
return "rider"
return ("clion", None)
if file.endswith(".csproj"):
return ("rider", file)
if file.endswith("DotSettings"):
# Allow .csproj to override this value
ret = ("rider", None)
if file.endswith(".py"):
return "pycharm"
return ("pycharm", None)
if file.endswith(".go"):
return "goland"
return "idea"
return ("goland", None)
return ret
def get_icon(project: str) -> str | None:
project_type = get_project_type(project)
(project_type, _) = get_project_type(project)
if project_type is None:
return None
icon_line = get_application_desktop_file_info(project_type, 'Icon')
@ -47,9 +51,12 @@ def get_icon(project: str) -> str | None:
def open_project(project: str) -> ():
project_type = get_project_type(project)
(project_type, file) = get_project_type(project)
if project_type is None:
return
if file is not None:
project = f'{project}/{file}'
command = get_application_desktop_file_info(project_type, 'Exec')[6:-5]
subprocess.Popen([command + " " + project], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)