From f7fc824c70acba392eb40a2ca7e9521ddb297595 Mon Sep 17 00:00:00 2001 From: HelioGuilherme66 Date: Tue, 16 Apr 2024 22:46:37 +0100 Subject: [PATCH] Add Open Containing Folder to context menu of Test Suites directories in Project Explorer --- CHANGELOG.adoc | 1 + src/robotide/application/CHANGELOG.html | 2 + src/robotide/application/releasenotes.py | 3 +- src/robotide/controller/ctrlcommands.py | 5 ++- src/robotide/controller/filecontrollers.py | 49 ++++++++++++---------- src/robotide/ui/treenodehandlers.py | 20 +++++++-- src/robotide/version.py | 2 +- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ae66bb7c6..eb21a3c10 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni === Added +- Added context option ``Open Containing Folder`` to test suites directories in Project Explorer. - Added a setting for a specific file manager by editing the settings.cfg file. Add the string parameter ``file manager`` in the section ``[General]``. - Added minimal support to have comment lines in Import settings. These are not supposed to be edited in Editor, and new lines are added at Text Editor. - Added a selector for Tasks and Language to the New Project dialog. Still some problems: Tasks type changes to Tests, diff --git a/src/robotide/application/CHANGELOG.html b/src/robotide/application/CHANGELOG.html index 586b40481..06d145d6f 100644 --- a/src/robotide/application/CHANGELOG.html +++ b/src/robotide/application/CHANGELOG.html @@ -1,6 +1,8 @@ Changelog

Changelog


All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

1.1. Added

  • +Added context option ``Open Containing Folder`` to test suites directories in Project Explorer. +
  • Added a setting for a specific file manager by editing the settings.cfg file. Add the string parameter ``file manager`` in the section ``[General]``.
  • Added minimal support to have comment lines in Import settings. These are not supposed to be edited in Editor, and new lines are added at Text Editor. diff --git a/src/robotide/application/releasenotes.py b/src/robotide/application/releasenotes.py index 4a620b40e..c400415c4 100644 --- a/src/robotide/application/releasenotes.py +++ b/src/robotide/application/releasenotes.py @@ -182,6 +182,7 @@ def set_content(self, html_win, content):

New Features and Fixes Highlights

    +
  • Added context option Open Containing Folder to test suites directories in Project Explorer.
  • Added a setting for a specific file manager by editing the settings.cfg file. Add the string parameter file manager in the section [General]
  • Added minimal support to have comment lines in Import settings. These are not supposed to be edited in Editor, and new lines are added at Text Editor.
  • @@ -283,6 +284,6 @@ def set_content(self, html_win, content):
     python -m robotide.postinstall -install
     
    -

    RIDE {VERSION} was released on 10/Apr/2024.

    +

    RIDE {VERSION} was released on 16/Apr/2024.

""" diff --git a/src/robotide/controller/ctrlcommands.py b/src/robotide/controller/ctrlcommands.py index a8a7da5bf..3380d75d9 100644 --- a/src/robotide/controller/ctrlcommands.py +++ b/src/robotide/controller/ctrlcommands.py @@ -535,11 +535,12 @@ def execute(self, context): class OpenContainingFolder(_Command): modifying = False - def __init__(self, tool: str = None): + def __init__(self, tool: str = None, path: str = None): self.tool = tool + self.path = path def execute(self, context): - context.open_filemanager(tool=self.tool) + context.open_filemanager(path=self.path, tool=self.tool) class RemoveReadOnly(_Command): diff --git a/src/robotide/controller/filecontrollers.py b/src/robotide/controller/filecontrollers.py index 6b7370c43..eb5b7be6a 100644 --- a/src/robotide/controller/filecontrollers.py +++ b/src/robotide/controller/filecontrollers.py @@ -343,7 +343,10 @@ def remove_readonly(self, path=None): @staticmethod def _explorer_linux(path, tool): - folder = os.path.dirname(path) + if not os.path.isfile(path): + folder = path + else: + folder = os.path.dirname(path) if tool: try: subprocess.Popen([tool, folder]) @@ -364,29 +367,33 @@ def _explorer_linux(path, tool): def open_filemanager(self, path=None, tool=None): path = path or self.filename - if os.path.exists(path): + if not os.path.exists(path): + return + if not os.path.isfile(path): + folder = path + else: folder = os.path.dirname(path) - if sys.platform == 'win32': - if tool: - try: - subprocess.Popen([tool, folder]) - return - except OSError: - print(f"DEBUG: Error when launching tool={tool}") - os.startfile(folder, 'explore') - elif sys.platform.startswith('linux'): - self._explorer_linux(path, tool) - else: - if tool: - try: - subprocess.Popen([tool, folder]) - return - except OSError: - print(f"DEBUG: Error when launching tool={tool}") + if sys.platform == 'win32': + if tool: try: - subprocess.Popen(["finder", folder]) + subprocess.Popen([tool, folder]) + return except OSError: - subprocess.Popen(["open", folder]) + print(f"DEBUG: Error when launching tool={tool}") + os.startfile(folder, 'explore') + elif sys.platform.startswith('linux'): + self._explorer_linux(folder, tool) + else: + if tool: + try: + subprocess.Popen([tool, folder]) + return + except OSError: + print(f"DEBUG: Error when launching tool={tool}") + try: + subprocess.Popen(["finder", folder]) + except OSError: + subprocess.Popen(["open", folder]) def remove_from_filesystem(self, path=None): path = path or self.filename diff --git a/src/robotide/ui/treenodehandlers.py b/src/robotide/ui/treenodehandlers.py index 9bfa1ed35..bc636918e 100644 --- a/src/robotide/ui/treenodehandlers.py +++ b/src/robotide/ui/treenodehandlers.py @@ -33,6 +33,8 @@ _ = wx.GetTranslation # To keep linter/code analyser happy builtins.__dict__['_'] = wx.GetTranslation +FILE_MANAGER = 'file manager' + def action_handler_class(controller): return { @@ -341,7 +343,8 @@ def __init__(self, *args): _ActionHandler._label_new_list_variable, _ActionHandler._label_new_dict_variable, '---', - _ActionHandler._label_change_format + _ActionHandler._label_change_format, + _ActionHandler._label_open_folder ] if self.controller.parent: self._actions.extend([_ActionHandler._label_delete_no_kbsc]) @@ -380,6 +383,17 @@ def on_new_resource(self, event): def on_delete(self, event): FolderDeleteDialog(self.controller).execute() + def on_open_containing_folder(self, event): + __ = event + try: + file_manager = self._settings['General'][FILE_MANAGER] + except KeyError: + file_manager = None + directory = self.controller.source + # print(f"DEBUG: treenodecontrollers.py TestDataDirectoryHandler on_open_containing_folder" + # f" directory={directory}") + self.controller.execute(ctrlcommands.OpenContainingFolder(tool=file_manager, path=directory)) + def on_exclude(self, event): try: self.controller.execute(ctrlcommands.Exclude()) @@ -463,7 +477,7 @@ def return_true(): def on_open_containing_folder(self, event): __ = event try: - file_manager = self._settings['General']['file manager'] + file_manager = self._settings['General'][FILE_MANAGER] except KeyError: file_manager = None self.controller.execute(ctrlcommands.OpenContainingFolder(file_manager)) @@ -536,7 +550,7 @@ def return_true(): def on_open_containing_folder(self, event): __ = event try: - file_manager = self._settings['General']['file manager'] + file_manager = self._settings['General'][FILE_MANAGER] except KeyError: file_manager = None self.controller.execute(ctrlcommands.OpenContainingFolder(file_manager)) diff --git a/src/robotide/version.py b/src/robotide/version.py index dc3564abf..b4ad3ac46 100644 --- a/src/robotide/version.py +++ b/src/robotide/version.py @@ -14,4 +14,4 @@ # limitations under the License. # # Automatically generated by `tasks.py`. -VERSION = 'v2.1dev28' +VERSION = 'v2.1dev29'