@@ -98,15 +98,14 @@ impl Window {
9898
9999 this. bind_signals ( ) ;
100100 this. setup_actions ( ) ;
101- this. add_tab ( ) ;
102- this. open_url ( bookmarks_url ( ) ) ;
101+ this. open_in_new_tab ( bookmarks_url ( ) . as_str ( ) ) ;
103102 this
104103 }
105104
106105 fn setup_actions ( & self ) {
107106 self_action ! ( self , "back" , back) ;
108- self_action ! ( self , "new-tab" , add_tab ) ;
109- self_action ! ( self , "show-bookmarks" , add_tab ) ;
107+ self_action ! ( self , "new-tab" , add_tab_focused ) ;
108+ self_action ! ( self , "show-bookmarks" , add_tab_focused ) ;
110109 self_action ! ( self , "bookmark-current" , bookmark_current) ;
111110 self_action ! ( self , "close-tab" , close_tab) ;
112111 self_action ! ( self , "focus-url-bar" , focus_url_bar) ;
@@ -137,7 +136,7 @@ impl Window {
137136 ) ;
138137 self . add_action ( & act_set_clipboard) ;
139138 }
140- fn add_tab ( & self ) {
139+ fn add_tab ( & self ) -> adw :: TabPage {
141140 let imp = self . imp ( ) ;
142141 let tab = Tab :: new ( imp. config . borrow ( ) . clone ( ) ) ;
143142 let tab_view = imp. tab_view . clone ( ) ;
@@ -164,9 +163,13 @@ impl Window {
164163 } ) ,
165164 ) ;
166165
167- let w = imp. tab_view . append ( & tab) ;
168- imp. tab_view . set_selected_page ( & w) ;
169- self . open_url ( bookmarks_url ( ) ) ;
166+ imp. tab_view . append ( & tab)
167+ }
168+ fn add_tab_focused ( & self ) {
169+ let imp = self . imp ( ) ;
170+ let p = self . add_tab ( ) ;
171+ self . inner_tab ( & p) . spawn_open_url ( bookmarks_url ( ) ) ;
172+ imp. tab_view . set_selected_page ( & p) ;
170173 }
171174 fn close_tab ( & self ) {
172175 let imp = self . imp ( ) ;
@@ -228,7 +231,7 @@ impl Window {
228231 imp. progress_animation . replace ( Some ( animation) ) ;
229232 }
230233 fn open_url ( & self , url : Url ) {
231- self . current_tab ( ) . spawn_open ( url) ;
234+ self . current_tab ( ) . spawn_open_url ( url) ;
232235 }
233236 fn back ( & self ) {
234237 match self . current_tab ( ) . back ( ) {
@@ -262,12 +265,23 @@ impl Window {
262265 }
263266 }
264267 fn open_in_new_tab ( & self , v : & str ) {
265- self . add_tab ( ) ;
266- self . open_url_str ( v) ;
268+ let w = self . add_tab ( ) ;
269+ let url = Url :: parse ( v) ;
270+ match url {
271+ Ok ( url) => self . inner_tab ( & w) . spawn_open_url ( url) ,
272+ Err ( e) => error ! ( "Failed to parse url: {:?}" , e) ,
273+ }
267274 }
268275 fn set_clipboard ( & self , v : & str ) {
269276 gdk:: Display :: default ( ) . unwrap ( ) . clipboard ( ) . set_text ( v) ;
270277 }
278+ fn tab_page ( & self , tab : & Tab ) -> adw:: TabPage {
279+ let imp = self . imp ( ) ;
280+ imp. tab_view . page ( tab)
281+ }
282+ fn inner_tab ( & self , tab : & adw:: TabPage ) -> Tab {
283+ tab. child ( ) . downcast ( ) . unwrap ( )
284+ }
271285 //TODO: Reintroduce colors
272286 //fn set_special_color_from_hash(&self, hash: u64) {
273287 // let color1 = Color(
0 commit comments