1- use crate :: commands:: { ClipBoardContentType , ClipboardContent , Function } ;
1+ use crate :: clipboard:: ClipBoardContentType ;
2+ use crate :: commands:: Function ;
23use crate :: config:: Config ;
34use crate :: macos:: { focus_this_app, transform_process_to_ui_element} ;
45use crate :: { macos, utils:: get_installed_apps} ;
56
6- use arboard:: { Clipboard , ImageData } ;
7+ use arboard:: Clipboard ;
78use global_hotkey:: { GlobalHotKeyEvent , HotKeyState } ;
89use iced:: futures:: SinkExt ;
910use iced:: {
@@ -14,7 +15,7 @@ use iced::{
1415 stream,
1516 widget:: {
1617 Button , Column , Row , Text , container, image:: Viewer , operation, scrollable, space,
17- text :: LineHeight , text_input,
18+ text_input,
1819 } ,
1920 window:: { self , Id , Settings } ,
2021} ;
@@ -56,6 +57,7 @@ impl App {
5657 } ,
5758 ]
5859 }
60+
5961 pub fn render ( & self , show_icons : bool ) -> impl Into < iced:: Element < ' _ , Message > > {
6062 let mut tile = Row :: new ( ) . width ( Fill ) . height ( 55 ) ;
6163
@@ -106,6 +108,12 @@ impl App {
106108 }
107109}
108110
111+ #[ derive( Debug , Clone , PartialEq ) ]
112+ pub enum Page {
113+ Main ,
114+ ClipboardHistory ,
115+ }
116+
109117#[ derive( Debug , Clone ) ]
110118pub enum Message {
111119 OpenWindow ,
@@ -118,7 +126,6 @@ pub enum Message {
118126 ClearSearchQuery ,
119127 ReloadConfig ,
120128 ClipboardHistory ( ClipBoardContentType ) ,
121- ShowClipboardHistory ,
122129 _Nothing,
123130}
124131
@@ -151,7 +158,8 @@ pub struct Tile {
151158 frontmost : Option < Retained < NSRunningApplication > > ,
152159 config : Config ,
153160 open_hotkey_id : u32 ,
154- clipboard_content : Vec < ClipboardContent > ,
161+ clipboard_content : Vec < ClipBoardContentType > ,
162+ page : Page ,
155163}
156164
157165impl Tile {
@@ -202,6 +210,7 @@ impl Tile {
202210 theme : config. theme . to_owned ( ) . to_iced_theme ( ) ,
203211 open_hotkey_id : keybind_id,
204212 clipboard_content : vec ! [ ] ,
213+ page : Page :: Main ,
205214 } ,
206215 Task :: batch ( [ open. map ( |_| Message :: OpenWindow ) ] ) ,
207216 )
@@ -255,20 +264,33 @@ impl Tile {
255264 id,
256265 iced:: Size :: new ( WINDOW_WIDTH , 55. + DEFAULT_WINDOW_HEIGHT ) ,
257266 ) ;
267+ } else if self . query_lc == "cbhist" {
268+ self . page = Page :: ClipboardHistory
269+ } else if self . query_lc == "main" {
270+ self . page = Page :: Main
258271 }
259272
260273 self . handle_search_query_changed ( ) ;
261274 let new_length = self . results . len ( ) ;
262275
263276 let max_elem = min ( 5 , new_length) ;
264- if prev_size != new_length {
277+ if prev_size != new_length && self . page == Page :: Main {
265278 window:: resize (
266279 id,
267280 iced:: Size {
268281 width : WINDOW_WIDTH ,
269282 height : ( ( max_elem * 55 ) + DEFAULT_WINDOW_HEIGHT as usize ) as f32 ,
270283 } ,
271284 )
285+ } else if self . page == Page :: ClipboardHistory {
286+ let element_count = min ( self . clipboard_content . len ( ) , 5 ) ;
287+ window:: resize (
288+ id,
289+ iced:: Size {
290+ width : WINDOW_WIDTH ,
291+ height : ( ( element_count * 55 ) + DEFAULT_WINDOW_HEIGHT as usize ) as f32 ,
292+ } ,
293+ )
272294 } else {
273295 Task :: none ( )
274296 }
@@ -353,13 +375,10 @@ impl Tile {
353375 }
354376
355377 Message :: ClipboardHistory ( clip_content) => {
356- self . clipboard_content
357- . push ( ClipboardContent :: from_content_type ( clip_content) ) ;
378+ self . clipboard_content . push ( clip_content) ;
358379 Task :: none ( )
359380 }
360381
361- Message :: ShowClipboardHistory => Task :: none ( ) ,
362-
363382 Message :: _Nothing => Task :: none ( ) ,
364383 }
365384 }
@@ -378,19 +397,32 @@ impl Tile {
378397 } )
379398 . id ( "query" )
380399 . width ( Fill )
381- . padding ( 20 )
382- . line_height ( LineHeight :: Relative ( 1.5 ) ) ;
400+ . padding ( 20 ) ;
401+
402+ match self . page {
403+ Page :: Main => {
404+ let mut search_results = Column :: new ( ) ;
405+ for result in & self . results {
406+ search_results =
407+ search_results. push ( result. render ( self . config . theme . show_icons ) ) ;
408+ }
383409
384- let mut search_results = Column :: new ( ) ;
385- for result in & self . results {
386- search_results =
387- search_results. push ( result. render ( self . config . theme . clone ( ) . show_icons ) ) ;
410+ Column :: new ( )
411+ . push ( title_input)
412+ . push ( scrollable ( search_results) )
413+ . into ( )
414+ }
415+ Page :: ClipboardHistory => {
416+ let mut clipboard_history = Column :: new ( ) ;
417+ for result in & self . clipboard_content {
418+ clipboard_history = clipboard_history. push ( result. render_clipboard_item ( ) ) ;
419+ }
420+ Column :: new ( )
421+ . push ( title_input)
422+ . push ( scrollable ( clipboard_history) )
423+ . into ( )
424+ }
388425 }
389-
390- Column :: new ( )
391- . push ( title_input)
392- . push ( scrollable ( search_results) )
393- . into ( )
394426 } else {
395427 space ( ) . into ( )
396428 }
0 commit comments