rabbit-vcs.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #
  2. # This is an extension to the Double Commander to allow
  3. # integration with the version control systems.
  4. #
  5. # Copyright (C) 2009 Jason Heeris <[email protected]>
  6. # Copyright (C) 2009 Bruce van der Kooij <[email protected]>
  7. # Copyright (C) 2009 Adam Plumb <[email protected]>
  8. # Copyright (C) 2014-2021 Alexander Koblov <[email protected]>
  9. #
  10. # RabbitVCS is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # RabbitVCS is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with RabbitVCS; If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. import os, os.path
  24. import sys
  25. try:
  26. from rabbitvcs.util.contextmenuitems import MenuItem, MenuSeparator
  27. from rabbitvcs.util.contextmenu import MenuBuilder, MainContextMenu, MainContextMenuCallbacks
  28. import rabbitvcs.services.checkerservice
  29. except Exception as e:
  30. print("RabbitVCS: {}".format(e))
  31. exit(1)
  32. class DCSender:
  33. """Double Commander sender class"""
  34. def rescan_after_process_exit(self, proc, paths):
  35. print("rescan_after_process_exit")
  36. return
  37. class DCMenuItem:
  38. """Double Commander menu item class"""
  39. identifier = None
  40. label = None
  41. icon = None
  42. menu = []
  43. def connect(self, signal, *callback):
  44. return
  45. class DCContextMenu(MenuBuilder):
  46. """Double Commander context menu class"""
  47. signal = "activate"
  48. def make_menu_item(self, item, id_magic):
  49. menuitem = DCMenuItem()
  50. if type(item) is MenuSeparator:
  51. menuitem.label = "-"
  52. else:
  53. menuitem.icon = item.icon
  54. menuitem.label = item.make_label()
  55. menuitem.identifier = item.callback_name
  56. return menuitem
  57. def attach_submenu(self, menu_node, submenu_list):
  58. menu_node.menu = []
  59. menu_node.identifier = ""
  60. for item in submenu_list:
  61. menu_node.menu.append(item)
  62. def top_level_menu(self, items):
  63. return items
  64. class DCMainContextMenu(MainContextMenu):
  65. """Double Commander main context menu class"""
  66. def Execute(self, identifier):
  67. # Try to find and execute callback function
  68. if hasattr(self.callbacks, identifier):
  69. function = getattr(self.callbacks, identifier)
  70. if callable(function):
  71. function(self, None)
  72. def GetMenu(self):
  73. return DCContextMenu(self.structure, self.conditions, self.callbacks).menu
  74. def GetContextMenu(paths):
  75. sender = DCSender()
  76. base_dir = os.path.dirname(paths[0])
  77. return DCMainContextMenu(sender, base_dir, paths, None)
  78. def StartService():
  79. rabbitvcs.services.checkerservice.start()