@@ -2,8 +2,8 @@ use crate::app::icon_cache::IconCache;
2
2
use chrono:: { NaiveDate , TimeZone , Utc } ;
3
3
use cosmic:: iced:: { Alignment , Length } ;
4
4
use cosmic:: iced_widget:: row;
5
- use cosmic:: widget:: segmented_button;
6
5
use cosmic:: widget:: segmented_button:: Entity ;
6
+ use cosmic:: widget:: { segmented_button, text_editor} ;
7
7
use cosmic:: { theme, widget, Element } ;
8
8
use slotmap:: { DefaultKey , SecondaryMap , SlotMap } ;
9
9
use tasks_core:: models:: { self , Priority , Status } ;
@@ -17,12 +17,13 @@ pub struct Details {
17
17
pub subtasks : SlotMap < DefaultKey , models:: Task > ,
18
18
pub editing : SecondaryMap < DefaultKey , bool > ,
19
19
pub sub_task_input_ids : SecondaryMap < DefaultKey , widget:: Id > ,
20
+ pub text_editor_content : widget:: text_editor:: Content ,
20
21
}
21
22
22
23
#[ derive( Debug , Clone ) ]
23
24
pub enum Message {
24
25
SetTitle ( String ) ,
25
- SetNotes ( String ) ,
26
+ Editor ( text_editor :: Action ) ,
26
27
Favorite ( bool ) ,
27
28
CompleteSubTask ( DefaultKey , bool ) ,
28
29
DeleteSubTask ( DefaultKey ) ,
@@ -70,20 +71,22 @@ impl Details {
70
71
subtasks : SlotMap :: new ( ) ,
71
72
editing : SecondaryMap :: new ( ) ,
72
73
sub_task_input_ids : SecondaryMap :: new ( ) ,
74
+ text_editor_content : widget:: text_editor:: Content :: new ( ) ,
73
75
}
74
76
}
75
77
76
78
pub fn update ( & mut self , message : Message ) -> Vec < Task > {
77
79
let mut tasks = vec ! [ ] ;
78
80
match message {
79
- Message :: SetTitle ( title) => {
80
- if let Some ( ref mut task) = & mut self . task {
81
- task. title . clone_from ( & title) ;
81
+ Message :: Editor ( action) => {
82
+ if let Some ( task) = & mut self . task {
83
+ self . text_editor_content . perform ( action) ;
84
+ task. notes . clone_from ( & self . text_editor_content . text ( ) ) ;
82
85
}
83
86
}
84
- Message :: SetNotes ( notes ) => {
87
+ Message :: SetTitle ( title ) => {
85
88
if let Some ( ref mut task) = & mut self . task {
86
- task. notes . clone_from ( & notes ) ;
89
+ task. title . clone_from ( & title ) ;
87
90
}
88
91
}
89
92
Message :: Favorite ( favorite) => {
@@ -251,8 +254,14 @@ impl Details {
251
254
. add(
252
255
widget:: column:: with_children( vec![
253
256
widget:: text:: body( fl!( "notes" ) ) . into( ) ,
254
- widget:: text_input( fl!( "notes" ) , & task. notes)
255
- . on_input( Message :: SetNotes )
257
+ widget:: text_editor( & self . text_editor_content)
258
+ . class( cosmic:: theme:: iced:: TextEditor :: Custom ( Box :: new(
259
+ text_editor_class,
260
+ ) ) )
261
+ . padding( spacing. space_xxs)
262
+ . placeholder( fl!( "notes" ) )
263
+ . height( 100.0 )
264
+ . on_action( Message :: Editor )
256
265
. into( ) ,
257
266
] )
258
267
. spacing( spacing. space_xxs)
@@ -293,3 +302,53 @@ impl Details {
293
302
. into ( )
294
303
}
295
304
}
305
+
306
+ fn text_editor_class (
307
+ theme : & cosmic:: Theme ,
308
+ status : cosmic:: widget:: text_editor:: Status ,
309
+ ) -> cosmic:: iced_widget:: text_editor:: Style {
310
+ let cosmic = theme. cosmic ( ) ;
311
+ let container = theme. current_container ( ) ;
312
+
313
+ let mut background: cosmic:: iced:: Color = container. component . base . into ( ) ;
314
+ background. a = 0.25 ;
315
+ let selection = cosmic. accent . base . into ( ) ;
316
+ let value = cosmic. palette . neutral_9 . into ( ) ;
317
+ let mut placeholder = cosmic. palette . neutral_9 ;
318
+ placeholder. alpha = 0.7 ;
319
+ let placeholder = placeholder. into ( ) ;
320
+ let icon = cosmic. background . on . into ( ) ;
321
+
322
+ match status {
323
+ cosmic:: iced_widget:: text_editor:: Status :: Active
324
+ | cosmic:: iced_widget:: text_editor:: Status :: Disabled => {
325
+ cosmic:: iced_widget:: text_editor:: Style {
326
+ background : background. into ( ) ,
327
+ border : cosmic:: iced:: Border {
328
+ radius : cosmic. corner_radii . radius_m . into ( ) ,
329
+ width : 2.0 ,
330
+ color : container. component . divider . into ( ) ,
331
+ } ,
332
+ icon,
333
+ placeholder,
334
+ value,
335
+ selection,
336
+ }
337
+ }
338
+ cosmic:: iced_widget:: text_editor:: Status :: Hovered
339
+ | cosmic:: iced_widget:: text_editor:: Status :: Focused => {
340
+ cosmic:: iced_widget:: text_editor:: Style {
341
+ background : background. into ( ) ,
342
+ border : cosmic:: iced:: Border {
343
+ radius : cosmic. corner_radii . radius_m . into ( ) ,
344
+ width : 2.0 ,
345
+ color : cosmic:: iced:: Color :: from ( cosmic. accent . base ) ,
346
+ } ,
347
+ icon,
348
+ placeholder,
349
+ value,
350
+ selection,
351
+ }
352
+ }
353
+ }
354
+ }
0 commit comments