Skip to content

Commit 65ce9a4

Browse files
committed
feat: when a clipboard history item is copied, remove all occurrences, then bring it to top.
1 parent 1116c2b commit 65ce9a4

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

sounds/copy.wav

189 KB
Binary file not shown.

src/managers/data_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,10 @@ def add_snippet(self, name, contents):
248248
'contents': contents
249249
})
250250

251-
self.load_snippets_from_files()
251+
self.load_snippets_from_files()
252+
253+
def forget_clipboard(self):
254+
self.clipboard_history.forget_last_value();
255+
256+
def delete_clipboard_history_item_by_text(self, text_of_item):
257+
self.clipboard_history.delete_clipboard_history_item_by_text(text_of_item)

src/managers/ui_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,12 @@ def run_button_clicked(self, event):
223223
if (selected_option['type'] == 'snippet'):
224224
selected_snippet_text = str(selected_option['name'])
225225
copy_to_clipboard(selected_snippet_text)
226+
SoundPlayer.play("copy")
226227

227228
if (selected_option['type'] == 'clip'):
229+
self.dataManager.delete_clipboard_history_item_by_text(selected_option['name'])
230+
self.dataManager.forget_clipboard()
231+
SoundPlayer.play("copy")
228232
copy_to_clipboard(str(selected_option['name']))
229233

230234
self.frame.Hide()

src/services/clipboard_history.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import pyperclip
12
import threading
23
import time
3-
import pyperclip
4+
import uuid
45
import json
56

6-
77
class ClipboardHistory:
88
def __init__(self):
99
self.last_value = None
@@ -43,7 +43,13 @@ def get_history_items(self):
4343
# create list with history_items with its name as value and index as shortcut
4444
history_items = []
4545
for index, item in enumerate(self.history_items):
46-
history_items.append({"name": item, "shortcut": str(index + 1), "type": "clip"})
46+
history_items.append({
47+
"name": item,
48+
"shortcut": str(index + 1),
49+
"id": str(uuid.uuid4()),
50+
"type": "clip"
51+
})
52+
4753
return history_items
4854

4955
def sync_to_storage(self):
@@ -65,3 +71,13 @@ def createClipboardHistoryFileIFNotExists(self):
6571
except FileNotFoundError:
6672
with open('clipboard_history.json', 'w') as outputFile:
6773
outputFile.write("[]")
74+
75+
def forget_last_value(self):
76+
self.last_value = None
77+
78+
def delete_clipboard_history_item_by_text(self, text):
79+
for index, item in enumerate(self.history_items):
80+
if item == text:
81+
self.history_items.pop(index)
82+
83+
self.sync_to_storage()

0 commit comments

Comments
 (0)