@@ -3,6 +3,7 @@ use std::collections::{HashMap, VecDeque};
3
3
use std:: { env, process} ;
4
4
5
5
use chrono:: { Local , NaiveDate } ;
6
+ use cli_clipboard:: { ClipboardContext , ClipboardProvider } ;
6
7
use cosmic:: app:: { message, Core , Message as CosmicMessage } ;
7
8
use cosmic:: iced:: alignment:: { Horizontal , Vertical } ;
8
9
use cosmic:: iced:: keyboard:: { Key , Modifiers } ;
@@ -18,6 +19,7 @@ use cosmic::{
18
19
Command , Element ,
19
20
} ;
20
21
use done_core:: models:: list:: List ;
22
+ use done_core:: models:: task:: Task ;
21
23
use done_core:: service:: Service ;
22
24
23
25
use crate :: app:: config:: { AppTheme , CONFIG_VERSION } ;
@@ -31,6 +33,7 @@ pub mod icon_cache;
31
33
mod key_bind;
32
34
pub mod localize;
33
35
pub mod menu;
36
+ pub mod markdown;
34
37
35
38
pub struct App {
36
39
core : Core ,
@@ -67,10 +70,12 @@ pub enum Message {
67
70
OpenRenameListDialog ,
68
71
OpenDeleteListDialog ,
69
72
OpenIconDialog ,
73
+ OpenCalendarDialog ,
74
+ OpenExportDialog ( String ) ,
70
75
AddList ( List ) ,
71
76
DeleteList ,
72
- OpenCalendarDialog ,
73
77
Focus ( widget:: Id ) ,
78
+ Export ( Vec < Task > ) ,
74
79
}
75
80
76
81
#[ derive( Clone , Debug , Eq , PartialEq ) ]
@@ -97,6 +102,7 @@ pub enum DialogPage {
97
102
Rename { to : String } ,
98
103
Delete ,
99
104
Calendar ( NaiveDate ) ,
105
+ Export ( String ) ,
100
106
}
101
107
102
108
#[ derive( Clone , Debug ) ]
@@ -746,6 +752,22 @@ impl Application for App {
746
752
) ;
747
753
dialog
748
754
}
755
+ DialogPage :: Export ( contents) => {
756
+ let dialog = widget:: dialog ( fl ! ( "export" ) )
757
+ . control (
758
+ widget:: container ( scrollable ( widget:: text ( contents) ) . width ( Length :: Fill ) )
759
+ . height ( Length :: Fixed ( 200.0 ) ) . width ( Length :: Fill ) ,
760
+ )
761
+ . primary_action (
762
+ widget:: button:: suggested ( fl ! ( "copy" ) )
763
+ . on_press_maybe ( Some ( Message :: DialogComplete ) ) ,
764
+ )
765
+ . secondary_action (
766
+ widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
767
+ ) ;
768
+
769
+ dialog
770
+ }
749
771
} ;
750
772
751
773
Some ( dialog. into ( ) )
@@ -931,6 +953,9 @@ impl Application for App {
931
953
} ) ;
932
954
commands. push ( command) ;
933
955
}
956
+ content:: Command :: Export ( tasks) => {
957
+ commands. push ( self . update ( Message :: Export ( tasks) ) ) ;
958
+ }
934
959
}
935
960
}
936
961
}
@@ -1034,6 +1059,12 @@ impl Application for App {
1034
1059
}
1035
1060
self . nav_model . remove ( self . nav_model . active ( ) ) ;
1036
1061
}
1062
+ Message :: Export ( tasks) => {
1063
+ if let Some ( list) = self . nav_model . data :: < List > ( self . nav_model . active ( ) ) {
1064
+ let exported_markdown = todo:: export_list ( list. clone ( ) , tasks) ;
1065
+ commands. push ( self . update ( Message :: OpenExportDialog ( exported_markdown) ) ) ;
1066
+ }
1067
+ }
1037
1068
Message :: OpenNewListDialog => {
1038
1069
self . dialog_pages . push_back ( DialogPage :: New ( String :: new ( ) ) ) ;
1039
1070
return widget:: text_input:: focus ( self . dialog_text_input . clone ( ) ) ;
@@ -1068,6 +1099,10 @@ impl Application for App {
1068
1099
self . dialog_pages
1069
1100
. push_back ( DialogPage :: Calendar ( Local :: now ( ) . date_naive ( ) ) ) ;
1070
1101
}
1102
+ Message :: OpenExportDialog ( content) => {
1103
+ self . dialog_pages
1104
+ . push_back ( DialogPage :: Export ( content) ) ;
1105
+ }
1071
1106
Message :: DialogCancel => {
1072
1107
self . dialog_pages . pop_front ( ) ;
1073
1108
}
@@ -1116,6 +1151,10 @@ impl Application for App {
1116
1151
DialogPage :: Calendar ( date) => {
1117
1152
self . details . update ( details:: Message :: SetDueDate ( date) ) ;
1118
1153
}
1154
+ DialogPage :: Export ( content) => {
1155
+ let mut clipboard = ClipboardContext :: new ( ) . unwrap ( ) ;
1156
+ clipboard. set_contents ( content) . unwrap ( ) ;
1157
+ }
1119
1158
}
1120
1159
}
1121
1160
}
0 commit comments