@@ -6,7 +6,6 @@ use glib::subclass::{Signal, SignalType};
66use glib:: Properties ;
77use gtk:: glib;
88use gtk:: prelude:: * ;
9- use gtk:: prelude:: * ;
109use gtk:: subclass:: prelude:: * ;
1110use gtk:: { gdk, gio} ;
1211use once_cell:: sync:: Lazy ;
@@ -112,7 +111,8 @@ impl Surface {
112111 . unwrap ( ) ,
113112 ) ;
114113 tag_a. set_line_height ( 1.4 ) ;
115- tag_a. set_foreground ( Some ( "blue" ) ) ;
114+ let accent_color = & self . text_view . style_context ( ) . lookup_color ( "accent_color" ) ;
115+ tag_a. set_foreground_rgba ( accent_color. as_ref ( ) ) ;
116116
117117 let tag_pre = Self :: create_tag (
118118 "pre" ,
@@ -140,23 +140,15 @@ impl Surface {
140140 . name ( name)
141141 . build ( )
142142 }
143- pub fn set_link_color ( & self , color : & gtk:: gdk:: RGBA ) {
144- self . text_view
145- . buffer ( )
146- . tag_table ( )
147- . lookup ( "a" )
148- . unwrap ( )
149- . set_foreground_rgba ( Some ( color) ) ;
150- }
143+
151144 pub fn clear ( & mut self ) {
152145 let b = & self . text_view . buffer ( ) ;
153146 b. delete ( & mut b. start_iter ( ) , & mut b. end_iter ( ) ) ;
154147 }
155148}
156149
157- pub enum PageEvent {
150+ pub enum HypertextEvent {
158151 Title ( String ) ,
159- Link ( gtk:: TextTag , String ) ,
160152}
161153
162154pub enum Title {
@@ -168,8 +160,8 @@ pub mod imp {
168160 use super :: * ;
169161
170162 #[ derive( Default , Properties ) ]
171- #[ properties( wrapper_type = super :: Page ) ]
172- pub struct Page {
163+ #[ properties( wrapper_type = super :: Hypertext ) ]
164+ pub struct Hypertext {
173165 pub ( super ) tag_stack : RefCell < Vec < gemini:: Tag > > ,
174166 pub ( super ) links : RefCell < HashMap < gtk:: TextTag , String > > ,
175167 pub ( super ) surface : RefCell < Option < Surface > > ,
@@ -181,12 +173,12 @@ pub mod imp {
181173 }
182174
183175 #[ glib:: object_subclass]
184- impl ObjectSubclass for Page {
185- const NAME : & ' static str = "GeopardPage " ;
186- type Type = super :: Page ;
176+ impl ObjectSubclass for Hypertext {
177+ const NAME : & ' static str = "GeopardHypertext " ;
178+ type Type = super :: Hypertext ;
187179 }
188180
189- impl ObjectImpl for Page {
181+ impl ObjectImpl for Hypertext {
190182 fn signals ( ) -> & ' static [ glib:: subclass:: Signal ] {
191183 static SIGNALS : Lazy < Vec < glib:: subclass:: Signal > > = Lazy :: new ( || {
192184 vec ! [
@@ -214,7 +206,7 @@ pub mod imp {
214206 }
215207 }
216208
217- impl Page {
209+ impl Hypertext {
218210 pub fn title ( & self ) -> String {
219211 match & * self . title . borrow ( ) {
220212 None => String :: new ( ) ,
@@ -225,14 +217,14 @@ pub mod imp {
225217 }
226218}
227219glib:: wrapper! {
228- pub struct Page ( ObjectSubclass <imp:: Page >) ;
220+ pub struct Hypertext ( ObjectSubclass <imp:: Hypertext >) ;
229221}
230- impl Default for Page {
222+ impl Default for Hypertext {
231223 fn default ( ) -> Self {
232224 glib:: Object :: new ( & [ ] ) . unwrap ( )
233225 }
234226}
235- impl Page {
227+ impl Hypertext {
236228 pub fn new ( url : String , surface : Surface ) -> Self {
237229 let text_view = surface. text_view . clone ( ) ;
238230
@@ -249,22 +241,22 @@ impl Page {
249241 text_view. add_controller ( & motion_ctrl) ;
250242
251243 left_click_ctrl. connect_released (
252- clone ! ( @weak this => @default -panic, move |ctrl, _n_press, x, y| {
244+ clone ! ( @strong this => @default -panic, move |ctrl, _n_press, x, y| {
253245 if let Err ( e) = this. handle_click( ctrl, x, y) {
254246 log:: info!( "{}" , e) ;
255247 } ;
256248 } ) ,
257249 ) ;
258250
259251 right_click_ctrl. connect_pressed (
260- clone ! ( @weak this => @default -panic, move |_ctrl, _n_press, x, y| {
252+ clone ! ( @strong this => @default -panic, move |_ctrl, _n_press, x, y| {
261253 if let Err ( e) = this. handle_right_click( x, y) {
262254 log:: info!( "{}" , e) ;
263255 } ;
264256 } ) ,
265257 ) ;
266258
267- motion_ctrl. connect_motion ( clone ! ( @weak this => @default -panic, move |_ctrl, x, y| {
259+ motion_ctrl. connect_motion ( clone ! ( @strong this => @default -panic, move |_ctrl, x, y| {
268260 let _ = this. handle_motion( x, y) ;
269261 } ) ) ;
270262
@@ -273,9 +265,9 @@ impl Page {
273265 pub fn render < ' e > (
274266 & self ,
275267 tokens : impl Iterator < Item = gemini:: Event < ' e > > ,
276- page_events : & ' e mut Vec < PageEvent > ,
268+ out_events : & ' e mut Vec < HypertextEvent > ,
277269 ) -> anyhow:: Result < ( ) > {
278- page_events . clear ( ) ;
270+ out_events . clear ( ) ;
279271 let mut tag_stack = self . imp ( ) . tag_stack . borrow_mut ( ) ;
280272 for ev in tokens {
281273 let parent_tag = tag_stack. last ( ) ;
@@ -323,7 +315,6 @@ impl Page {
323315 . links
324316 . borrow_mut ( )
325317 . insert ( tag. clone ( ) , url. clone ( ) ) ;
326- page_events. push ( PageEvent :: Link ( tag, url. clone ( ) ) ) ;
327318 }
328319 gemini:: Tag :: Heading ( 1 ) => {
329320 let mut title = self . imp ( ) . title . borrow_mut ( ) ;
@@ -358,7 +349,7 @@ impl Page {
358349 buffer. insert ( & mut buffer. end_iter ( ) , "\n " ) ;
359350 if matches ! ( parent_tag, gemini:: Tag :: Heading ( 1 ) ) {
360351 if let Some ( Title :: Incomplete ( title) ) = self . imp ( ) . title . take ( ) {
361- page_events . push ( PageEvent :: Title ( title. clone ( ) ) ) ;
352+ out_events . push ( HypertextEvent :: Title ( title. clone ( ) ) ) ;
362353 self . imp ( ) . title . replace ( Some ( Title :: Complete ( title) ) ) ;
363354 }
364355 }
@@ -415,36 +406,11 @@ impl Page {
415406 }
416407 Ok ( ( ) )
417408 }
418- pub fn display_error ( & self , error : anyhow:: Error ) {
419- log:: error!( "{:?}" , error) ;
420-
421- let status_page = adw:: StatusPage :: new ( ) ;
422- status_page. set_title ( "Error" ) ;
423- status_page. set_description ( Some ( & error. to_string ( ) ) ) ;
424- status_page. set_icon_name ( Some ( "dialog-error-symbolic" ) ) ;
425-
426- // TODO:
427- /* self.stack.add_child(&status_page);
428- self.stack.set_visible_child(&status_page); */
429- }
430409 fn parse_link ( & self , link : & str ) -> Result < Url , url:: ParseError > {
431410 let current_url = Url :: parse ( self . imp ( ) . url . borrow ( ) . as_str ( ) ) ?;
432411 let link_url = Url :: options ( ) . base_url ( Some ( & current_url) ) . parse ( link) ?;
433412 Ok ( link_url)
434413 }
435- pub fn set_link_color ( & self , color : & gtk:: gdk:: RGBA ) {
436- self . imp ( )
437- . surface
438- . borrow ( )
439- . as_ref ( )
440- . unwrap ( )
441- . text_view
442- . buffer ( )
443- . tag_table ( )
444- . lookup ( "a" )
445- . unwrap ( )
446- . set_foreground_rgba ( Some ( color) ) ;
447- }
448414 fn extract_linkhandler < ' a > (
449415 m : & ' a HashMap < gtk:: TextTag , String > ,
450416 text_view : & gtk:: TextView ,
0 commit comments