4
4
5
5
from __future__ import annotations
6
6
7
- import os
8
- import uuid
9
- from typing import Any
7
+ import datetime
8
+ from typing import Any , ClassVar
10
9
11
10
from textual import on
12
11
from textual .message import Message
@@ -19,19 +18,28 @@ class DoubleClickDirectoryTree(DirectoryTree):
19
18
A DirectoryTree that can handle any filesystem.
20
19
"""
21
20
21
+ _double_click_time : ClassVar [datetime .timedelta ] = datetime .timedelta (
22
+ seconds = 0.333333
23
+ )
24
+
22
25
def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
23
26
"""
24
27
Initialize the DirectoryTree
25
28
"""
26
29
super ().__init__ (* args , ** kwargs )
27
- self ._last_clicked_path : os .PathLike [UPath ] = UPath (uuid .uuid4 ().hex )
30
+ self ._last_clicked_path : UPath = UPath (
31
+ "13041530b3174c569e1895fdfc2676fc57af1e02606059e0d2472d04c1bb360f"
32
+ )
33
+ self ._last_clicked_time = datetime .datetime (
34
+ 1970 , 1 , 1 , tzinfo = datetime .timezone .utc
35
+ )
28
36
29
37
class DoubleClicked (Message ):
30
38
"""
31
39
A message that is emitted when the directory is changed
32
40
"""
33
41
34
- def __init__ (self , path : os . PathLike [ Any ] ) -> None :
42
+ def __init__ (self , path : UPath ) -> None :
35
43
"""
36
44
Initialize the message
37
45
"""
@@ -69,12 +77,17 @@ def handle_double_click_file(self, message: DirectoryTree.FileSelected) -> None:
69
77
message .stop ()
70
78
self .post_message (self .FileDoubleClicked (path = message .path ))
71
79
72
- def is_double_click (self , path : os . PathLike [ Any ] ) -> bool :
80
+ def is_double_click (self , path : UPath ) -> bool :
73
81
"""
74
82
Check if the path is double clicked
75
83
"""
76
- if self ._last_clicked_path != path :
77
- self ._last_clicked_path = path
84
+ click_time = datetime .datetime .now (datetime .timezone .utc )
85
+ click_delta = click_time - self ._last_clicked_time
86
+ self ._last_clicked_time = click_time
87
+ if self ._last_clicked_path == path and click_delta <= self ._double_click_time :
88
+ return True
89
+ elif self ._last_clicked_path == path and click_delta > self ._double_click_time :
78
90
return False
79
91
else :
80
- return True
92
+ self ._last_clicked_path = path
93
+ return False
0 commit comments