| 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 |
|
| 24 |
import os, os.path |
| 25 |
import sys |
| 26 |
|
| 27 |
try: |
| 28 |
from rabbitvcs.util.contextmenuitems import MenuItem, MenuSeparator |
| 29 |
from rabbitvcs.util.contextmenu import MenuBuilder, MainContextMenu, MainContextMenuCallbacks |
| 30 |
import rabbitvcs.services.checkerservice |
| 31 |
except Exception as e: |
| 32 |
print("RabbitVCS: {}".format(e)) |
| 33 |
exit(1) |
| 34 |
|
| 35 |
class DCSender: |
| 36 |
"""Double Commander sender class""" |
| 37 |
def rescan_after_process_exit(self, proc, paths): |
| 38 |
print("rescan_after_process_exit") |
| 39 |
return |
| 40 |
|
| 41 |
class DCMenuItem: |
| 42 |
"""Double Commander menu item class""" |
| 43 |
|
| 44 |
identifier = None |
| 45 |
label = None |
| 46 |
icon = None |
| 47 |
menu = [] |
| 48 |
|
| 49 |
def connect(self, signal, *callback): |
| 50 |
return |
| 51 |
|
| 52 |
class DCContextMenu(MenuBuilder): |
| 53 |
"""Double Commander context menu class""" |
| 54 |
|
| 55 |
signal = "activate" |
| 56 |
|
| 57 |
def make_menu_item(self, item, id_magic): |
| 58 |
|
| 59 |
menuitem = DCMenuItem() |
| 60 |
|
| 61 |
if type(item) is MenuSeparator: |
| 62 |
menuitem.label = "-" |
| 63 |
else: |
| 64 |
menuitem.icon = item.icon |
| 65 |
menuitem.label = item.make_label() |
| 66 |
menuitem.identifier = item.callback_name |
| 67 |
|
| 68 |
return menuitem |
| 69 |
|
| 70 |
def attach_submenu(self, menu_node, submenu_list): |
| 71 |
menu_node.menu = [] |
| 72 |
menu_node.identifier = "" |
| 73 |
for item in submenu_list: |
| 74 |
menu_node.menu.append(item) |
| 75 |
|
| 76 |
def top_level_menu(self, items): |
| 77 |
return items |
| 78 |
|
| 79 |
class DCMainContextMenu(MainContextMenu): |
| 80 |
"""Double Commander main context menu class""" |
| 81 |
|
| 82 |
def Execute(self, identifier): |
| 83 |
# Try to find and execute callback function |
| 84 |
if hasattr(self.callbacks, identifier): |
| 85 |
function = getattr(self.callbacks, identifier) |
| 86 |
if callable(function): |
| 87 |
function(self, None) |
| 88 |
|
| 89 |
def GetMenu(self): |
| 90 |
return DCContextMenu(self.structure, self.conditions, self.callbacks).menu |
| 91 |
|
| 92 |
def GetContextMenu(paths): |
| 93 |
sender = DCSender() |
| 94 |
base_dir = os.path.dirname(paths[0]) |
| 95 |
return DCMainContextMenu(sender, base_dir, paths, None) |
| 96 |
|
| 97 |
def StartService(): |
| 98 |
rabbitvcs.services.checkerservice.start() |
| 99 |
|