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
|
# -*- coding: utf-8 -*-
#********************************************************************************
#Copyright © 2023 Wcq
#File Name: test.py
#Author: Wcq
#Email: wcq-062821@163.com
#Created: 2023-02-25 11:55:57
#Last Update: 2023-02-25 15:45:19
# By: Wcq
#Description: A nautilus plugin for comparing files with meld
#********************************************************************************
from gi.repository import Nautilus, GObject
from typing import List
import os
class compare_files_by_meld (GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
super().__init__()
self.left_file = None
self.right_file = None
print("Initialized compare_with_meld extension")
def mark_left_file (self, menu: Nautilus.MenuItem, file: Nautilus.FileInfo,) -> None:
self.left_file = file.get_uri()
def compare_with_left_file (self, menu: Nautilus.MenuItem, file: Nautilus.FileInfo,) -> None:
self.right_file = file.get_uri()
os.system("meld \"%s\" \"%s\" &"%(self.left_file, self.right_file))
def compare_files(self, menu: Nautilus.MenuItem, files: List[Nautilus.FileInfo]) -> None:
compare_files = ""
for x in files:
compare_files += "\"%s\" "%x.get_uri()
os.system("meld %s &"%(compare_files))
def get_file_items(self, files: List[Nautilus.FileInfo],) -> List[Nautilus.MenuItem]:
if len(files) < 1:
return []
items = []
if len(files) == 1:
item = Nautilus.MenuItem(name="select left file to compare", label="select left compare file", tip="select %s as left compare file" % files[0])
item.connect("activate", self.mark_left_file, files[0])
items.append(item)
if self.left_file:
item = Nautilus.MenuItem(name="compare with left file", label="compare with left file", tip="compare with %s "%self.left_file)
item.connect("activate", self.compare_with_left_file, files[0])
items.append(item)
if len(files) > 1:
item = Nautilus.MenuItem(name="compare all selected files", label="compare all selected files", tip="compaer %s and %s ..." % (files[0].get_name(), files[1].get_name()))
item.connect("activate", self.compare_files, files)
items.append(item)
return items
# Even though we're not using background items, Nautilus will generate
# a warning if the method isn't present
def get_background_items(self, current_folder: Nautilus.FileInfo,) -> List[Nautilus.MenuItem]:
return []
|