/[cvs]/nfo/projects/mess/src/client/windows/context_menu.py
ViewVC logotype

Diff of /nfo/projects/mess/src/client/windows/context_menu.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by joko, Sat Jun 3 20:29:52 2006 UTC revision 1.7 by joko, Sat Jun 3 22:27:45 2006 UTC
# Line 27  class ShellExtension: Line 27  class ShellExtension:
27      _com_interfaces_ = [shell.IID_IShellExtInit, shell.IID_IContextMenu]      _com_interfaces_ = [shell.IID_IShellExtInit, shell.IID_IContextMenu]
28      _public_methods_ = IContextMenu_Methods + IShellExtInit_Methods      _public_methods_ = IContextMenu_Methods + IShellExtInit_Methods
29    
30      def Initialize(self, folder, dataobj, hkey):      def Initialize(self, pidlFolder, dataobj, hkey):
31          print "Init", folder, dataobj, hkey          print "Init", pidlFolder, dataobj, hkey
32          self.dataobj = dataobj          self.dataobj = dataobj
33    
34      def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags):      def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags):
35                    
36          # debug          # debug
37          print "QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags          print "QCM", hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags
           
         # query the items clicked on  
         format_etc = win32con.CF_HDROP, None, 1, -1, pythoncom.TYMED_HGLOBAL  
         sm = self.dataobj.GetData(format_etc)  
         num_files = shell.DragQueryFile(sm.data_handle, -1)  
           
         #if num_files>1:  
         #    msg = "&Hello from Python (with %d files selected)" % num_files  
         #else:  
         #    fname = shell.DragQueryFile(sm.data_handle, 0)  
         #    msg = "&Hello from Python (with '%s' selected)" % fname  
         self.files_selected = []  
         for i in range(0, num_files):  
           fname = shell.DragQueryFile(sm.data_handle, i)  
           if fname == 0: continue  
           self.files_selected.append(fname)  
38    
39          # build context menu(s)          # clicking on a directory background leaves us with dataobj == None
40          msg = "Add to A&rchive"          if self.dataobj:
41          idCmd = idCmdFirst            
42              # query the items clicked on
43              format_etc = win32con.CF_HDROP, None, 1, -1, pythoncom.TYMED_HGLOBAL
44              sm = self.dataobj.GetData(format_etc)
45              
46              # how many items are selected
47              num_files = shell.DragQueryFile(sm.data_handle, -1)
48            
49              # grab all items
50              self.files_selected = []
51              for i in range(0, num_files):
52                fname = shell.DragQueryFile(sm.data_handle, i)
53                if fname == 0: continue
54                self.files_selected.append(fname)
55    
56    
57            # calculate items to be added to context menu
58          items = []          items = []
59          if (uFlags & 0x000F) == shellcon.CMF_NORMAL: # Check == here, since CMF_NORMAL=0          
60              print "CMF_NORMAL..."          # CMF_NORMAL: e.g. files on desktop
61              items.append(msg + " - normal")          # CMF_VERBSONLY: e.g. shortcuts
62          elif uFlags & shellcon.CMF_VERBSONLY:          # CMF_EXPLORE: regular files/folders via explorer
63              print "CMF_VERBSONLY..."          
64              items.append(msg + " - shortcut")          # Check == here, since CMF_NORMAL=0
65          elif uFlags & shellcon.CMF_EXPLORE:          if ((uFlags & 0x000F) == shellcon.CMF_NORMAL) or (uFlags & shellcon.CMF_VERBSONLY) or (uFlags & shellcon.CMF_EXPLORE):
66              print "CMF_EXPLORE..."              if self.dataobj:
67              #items.append(msg + " - normal file, right-click in Explorer")                items.append("Add to A&rchive")
68              items.append(msg)                items.append("Named Shortcut &1")
69              items.append("Named Shortcut &1")                items.append("Named Shortcut &2")
             items.append("Named Shortcut &2")  
70          elif uFlags & CMF_DEFAULTONLY:          elif uFlags & CMF_DEFAULTONLY:
71              print "CMF_DEFAULTONLY...\r\n"              print "CMF_DEFAULTONLY...\r\n"
72              items.append("hello world - 1!")              items.append("hello world - 1!")
73          else:          else:
74              print "** unknown flags", uFlags              print "** unknown flags", uFlags
75              items.append("hello world - 2!")              items.append("hello world - 2!")
76            
77    
78            # build context menu(s)
79            idCmd = idCmdFirst
80    
81          # add seperator line          # add seperator line
82          win32gui.InsertMenu(hMenu, indexMenu,          win32gui.InsertMenu(hMenu, indexMenu,
83                              win32con.MF_SEPARATOR|win32con.MF_BYPOSITION,                              win32con.MF_SEPARATOR|win32con.MF_BYPOSITION,
# Line 140  class ShellExtension: Line 143  class ShellExtension:
143            method = "Shortcut 2"            method = "Shortcut 2"
144          else:          else:
145            method = "Unknown"            method = "Unknown"
146            
147          # do action(s)          # do action(s)
148          win32gui.MessageBox(hwnd, "\n".join(self.files_selected), method, win32con.MB_OK)          if hasattr(self, 'files_selected'):
149              win32gui.MessageBox(hwnd, "\n".join(self.files_selected), method, win32con.MB_OK)
150            else:
151              win32gui.MessageBox(hwnd, "No selection!", method, win32con.MB_OK)
152    
153    
154  def DllRegisterServer():  def DllRegisterServer():
# Line 150  def DllRegisterServer(): Line 156  def DllRegisterServer():
156            
157      # extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html)      # extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html)
158    
159        # for directory background
160        background_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Directory\\Background\\shellex")
161        background_subkey = _winreg.CreateKey(background_key, "ContextMenuHandlers")
162        background_subkey2 = _winreg.CreateKey(background_subkey, ShellExtension._reg_name_)
163        _winreg.SetValueEx(background_subkey2, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
164    
165      # for folders      # for folders
166      folder_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\shellex")      folder_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\shellex")
167      folder_subkey = _winreg.CreateKey(folder_key, "ContextMenuHandlers")      folder_subkey = _winreg.CreateKey(folder_key, "ContextMenuHandlers")
# Line 171  def DllUnregisterServer(): Line 183  def DllUnregisterServer():
183      # extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html)      # extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html)
184    
185      try:      try:
186            # for directory background
187            background_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
188                                    "Directory\\Background\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_)
189          # for folders          # for folders
190          folder_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,          folder_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
191                                  "Folder\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_)                                  "Folder\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_)

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.7

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed