GiorgosXou / TUIFIManager

A cross-platform terminal-based termux-oriented file manager (and component), meant to be used with a Uni-Curses project or as is.
GNU General Public License v3.0
688 stars 13 forks source link

Use hashmap for menu selected action #33

Closed Sigmanificient closed 1 year ago

GiorgosXou commented 1 year ago

Yes to hashmaps , but shouldn't menu_select_actions be outside of __perform_menu_selected_action?

Sigmanificient commented 1 year ago

It could actually to avoid recomputing the dictionnary, tho it's very small so i think the impact would be minimal

Sigmanificient commented 1 year ago

Would you prefer something like this?

    def open_cicked_file(self):
        return self.open(self.__clicked_file)

    openfolder = partial(open, 'folder')
    open_file = partial(open, 'file')
    menu_select_actions = {
        'Open': open_clicked_file,
        'Cut': cut,
        'Delete': delete,
        'Copy': copy,
        'Paste': paste,
        'Rename': rename,
        'New File': open_file,
        'New Folder': openfolder,
        'Reload': reload,
    }

    def __perform_menu_selected_action(self, action):
        if not action:
            return False

        action_func = self.menu_select_actions.get(action)
        if not action_func:
            return False

        action_func()
        return True
GiorgosXou commented 1 year ago

Yes, preferably with __, because we need them as private at the momment