Refactor Input & InputBox in FileCommander

Issue #656 resolved
prl created an issue

Input, InputBox and InputBoxmod in FileCommander differ little from their corresponding classes in Screens and Components, but have "inherited" from them by copy-paste-modify, leading to a lot of redundant code and the FileCommander not keeping up with changes to the corresponding classes in the main code.

The substantive differences between the FileCommander and the corresponding main code classes are:

  • In FileCommander.InputBoxmod.Input, handleAscii() calls Components.config.getCharValue(code), while the main code for Input calls unichr(code) instead. However getCharValue() doesn't work correctly (see bug #317). Other than that, the classes only really differ in the instance initialiser arguments.
  • In FileCommander.InputBoxmod.InputBox, the instance initialiser arguments differ from the main code InputBox (similar differences to those in Input), and the FileCommander code adds some additional ActionMap actions, but only to existing methods.
  • FileCommander.InputBoxmod.InputBoxmod is a copy-paste-modify of FileCommander.InputBoxmod.InputBox that only actually changes the default skin to have a wide inputBox to use in the FileCommanders's primitive text editor.
  • FileCommander.InputBoxmod.PinInput differs from the main code PinInput in the same way thatInputBox does. PinInput (in either form) is not used in FileCommander

The two modules should be refactored to inherit from the corresponding main code classes. FileCommander.InputBoxmod.Input should not over-ride Components.Input.handleAscii(), but rather use the one in the base class. That will avoid bug #655, and allow Components.config.getCharValue() to be removed from the code as suggested in issue #655.

The differences in the instance initialiser arguments could either be preserved, or changed to be the same as the main code classes, and the places where the objects are instantiated changed to correspond. The latter would allow FileCommander.InputBox.Input to be removed entirely. Comment on that choice is sought.

The refactor of FileCommander.InputBox was motivated by wanting to incorporate the fix to bug #317 into FileCommander without further "inheritance by copy-paste". The refactor of FileCommander.InputBoxmod followed by noticing that it had similar "inheritance by copy-paste".

Comments (8)

  1. Peter Urbanec

    If you are going to attack this, then I think that the best strategy would be to eliminate as much code from FileCommander plugin as possible. If you have the opportunity to eliminate FileCommander.InputBox.Input, go ahead. Just make sure that the result is maintainable and if there are any "gotchas", feel free to be generous with code comments.

  2. Peter Urbanec

    Fix issue #656: Refactor Input & InputBox in FileCommander

    Remove module Plugins.Extensions.FileCommander.Input and re-base Plugins.Extensions.FileCommander.InputBoxmod.InputBox on Screens.InputBox.

    The only functionality required in the new rebased InputBoxmod.InputBox is to add an ActionMap to it that supports the use of PLAY/PAUSE to toggle insert/overwrite.

    The previous mappings of KEY_REWIND and KEY_FASTFORWARD to seekBack and seekForward and to the HOME and END actions on "break" respectively in the InfobarSeekActions context are made dummy actions, because the actions are already covered by mappings of the buttons to "home" and "end" on "make" in the KeyboardInputActions context in the ActionMap in Screens.InputBox.

    The only functionality that InputBoxmod.InputBoxmod added is to provide a default skin, so it simply inherits from InputBoxmod.InputBox and adds the default skin.

    InputBoxmod.PinInput is unused in FileCommander, so it has been removed. The old version only added similar functionality to that added by InputBoxmod.InputBox, and that extra functionality is probably unnecessary.

    → <<cset 6664508473e4>>

  3. Peter Urbanec

    Fix issue #656: Refactor Input & InputBox in FileCommander - module rename

    Rename module Plugins.Extensions.FileCommander.InputBoxmod to Plugins.Extensions.FileCommander.InputBox.

    Change imports of the module to match.

    Remove unused import of InputBox from FileCommander/addons/type_utils.py.

    Remove commented-out imports of InputBox, FileList and MultiFileSelectList from FileCommander/addons/key_actions.py.

    → <<cset 2779773f657a>>

  4. Peter Urbanec

    Fix issue #656: Refactor Input & InputBox in FileCommander - class rename

    Rename class Plugins.Extensions.FileCommander.InputBox.InputBoxmod to Plugins.Extensions.FileCommander.InputBox.InputBoxWide, to match what its default skin allows.

    Change imports of the cless to match.

    → <<cset 24d36142331e>>

  5. Peter Urbanec

    Fix issue #656: Refactor Input & InputBox in FileCommander - small cleanup

    Remove unused definition of EXTENSIONS dict from FileCommander/addons/type_utils.py.

    → <<cset a728300ba90a>>

  6. Log in to comment