File: rabbit-vcs.py

package info (click to toggle)
doublecmd 1.1.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,968 kB
  • sloc: pascal: 374,335; sh: 1,180; ansic: 724; makefile: 132; python: 52; xml: 16
file content (99 lines) | stat: -rw-r--r-- 2,883 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# This is an extension to the Double Commander to allow
# integration with the version control systems.
#
# Copyright (C) 2009 Jason Heeris <jason.heeris@gmail.com>
# Copyright (C) 2009 Bruce van der Kooij <brucevdkooij@gmail.com>
# Copyright (C) 2009 Adam Plumb <adamplumb@gmail.com>
# Copyright (C) 2014-2021 Alexander Koblov <alexx2000@mail.ru>
#
# RabbitVCS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# RabbitVCS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with RabbitVCS;  If not, see <http://www.gnu.org/licenses/>.
#

import os, os.path
import sys

try:
  from rabbitvcs.util.contextmenuitems import MenuItem, MenuSeparator
  from rabbitvcs.util.contextmenu import MenuBuilder, MainContextMenu, MainContextMenuCallbacks
  import rabbitvcs.services.checkerservice
except Exception as e:
  print("RabbitVCS: {}".format(e))
  exit(1)

class DCSender:
  """Double Commander sender class"""
  def rescan_after_process_exit(self, proc, paths):
    print("rescan_after_process_exit")
    return

class DCMenuItem:
  """Double Commander menu item class"""

  identifier = None
  label = None
  icon = None
  menu = []

  def connect(self, signal, *callback):
    return

class DCContextMenu(MenuBuilder):
  """Double Commander context menu class"""

  signal = "activate"

  def make_menu_item(self, item, id_magic):

    menuitem = DCMenuItem()

    if type(item) is MenuSeparator:
      menuitem.label = "-"
    else:
      menuitem.icon = item.icon
      menuitem.label = item.make_label()
      menuitem.identifier = item.callback_name

    return menuitem

  def attach_submenu(self, menu_node, submenu_list):
    menu_node.menu = []
    menu_node.identifier = ""
    for item in submenu_list:
      menu_node.menu.append(item)

  def top_level_menu(self, items):
    return items

class DCMainContextMenu(MainContextMenu):
  """Double Commander main context menu class"""

  def Execute(self, identifier):
    # Try to find and execute callback function
    if hasattr(self.callbacks, identifier):
      function = getattr(self.callbacks, identifier)
      if callable(function):
        function(self, None)

  def GetMenu(self):
    return DCContextMenu(self.structure, self.conditions, self.callbacks).menu

def GetContextMenu(paths):
  sender = DCSender()
  base_dir = os.path.dirname(paths[0])
  return DCMainContextMenu(sender, base_dir, paths, None)

def StartService():
  rabbitvcs.services.checkerservice.start()