44
55from __future__ import annotations
66
7- import os
8- import uuid
9- from typing import Any
7+ import datetime
8+ from typing import Any , ClassVar
109
1110from textual import on
1211from textual .message import Message
@@ -19,19 +18,28 @@ class DoubleClickDirectoryTree(DirectoryTree):
1918 A DirectoryTree that can handle any filesystem.
2019 """
2120
21+ _double_click_time : ClassVar [datetime .timedelta ] = datetime .timedelta (
22+ seconds = 0.333333
23+ )
24+
2225 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
2326 """
2427 Initialize the DirectoryTree
2528 """
2629 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+ )
2836
2937 class DoubleClicked (Message ):
3038 """
3139 A message that is emitted when the directory is changed
3240 """
3341
34- def __init__ (self , path : os . PathLike [ Any ] ) -> None :
42+ def __init__ (self , path : UPath ) -> None :
3543 """
3644 Initialize the message
3745 """
@@ -69,12 +77,17 @@ def handle_double_click_file(self, message: DirectoryTree.FileSelected) -> None:
6977 message .stop ()
7078 self .post_message (self .FileDoubleClicked (path = message .path ))
7179
72- def is_double_click (self , path : os . PathLike [ Any ] ) -> bool :
80+ def is_double_click (self , path : UPath ) -> bool :
7381 """
7482 Check if the path is double clicked
7583 """
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 :
7890 return False
7991 else :
80- return True
92+ self ._last_clicked_path = path
93+ return False
0 commit comments