rabbit-vcs.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 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 *
  27. from rabbitvcs.util.contextmenu import MenuBuilder, MainContextMenu, MainContextMenuCallbacks
  28. from rabbitvcs.services.checkerservice import StatusCheckerStub
  29. except:
  30. exit(1)
  31. class DCSender:
  32. """Double Commander sender class"""
  33. def rescan_after_process_exit(self, proc, paths):
  34. print "rescan_after_process_exit"
  35. return
  36. class DCMenuItem:
  37. """Double Commander menu item class"""
  38. identifier = None
  39. label = None
  40. icon = None
  41. menu = []
  42. def connect(self, signal, *callback):
  43. return
  44. class DCContextMenu(MenuBuilder):
  45. """Double Commander context menu class"""
  46. signal = "activate"
  47. def make_menu_item(self, item, id_magic):
  48. menuitem = DCMenuItem()
  49. if type(item) is MenuSeparator:
  50. menuitem.label = "-"
  51. else:
  52. menuitem.icon = item.icon
  53. menuitem.label = item.make_label()
  54. menuitem.identifier = item.callback_name
  55. return menuitem
  56. def attach_submenu(self, menu_node, submenu_list):
  57. menu_node.menu = []
  58. menu_node.identifier = ""
  59. for item in submenu_list:
  60. menu_node.menu.append(item)
  61. def top_level_menu(self, items):
  62. return items
  63. class DCMainContextMenu(MainContextMenu):
  64. """Double Commander main context menu class"""
  65. def Execute(self, identifier):
  66. # Try to find and execute callback function
  67. if hasattr(self.callbacks, identifier):
  68. function = getattr(self.callbacks, identifier)
  69. if callable(function):
  70. function(self, None)
  71. def GetMenu(self):
  72. return DCContextMenu(self.structure, self.conditions, self.callbacks).menu
  73. def GetContextMenu(paths):
  74. upaths = []
  75. for path in paths:
  76. upaths.append(unicode(path))
  77. sender = DCSender()
  78. base_dir = os.path.dirname(upaths[0])
  79. return DCMainContextMenu(sender, base_dir, upaths, None)
  80. if __name__ == "__main__":
  81. status_checker = StatusCheckerStub()