Browse Source

Add refresh button (and shortcut)

Adds a refresh button after the back button, uses ctrl-r as shortcut key.
debug-epoch
Zane Ashby 10 months ago
parent
commit
8e18e32867
3 changed files with 53 additions and 4 deletions
  1. 29
    4
      src/castor.glade
  2. 9
    0
      src/gui.rs
  3. 15
    0
      src/main.rs

+ 29
- 4
src/castor.glade View File

@@ -21,6 +21,11 @@
21 21
     <property name="can_focus">False</property>
22 22
     <property name="stock">gtk-go-back</property>
23 23
   </object>
24
+  <object class="GtkImage" id="image4">
25
+    <property name="visible">True</property>
26
+    <property name="can_focus">False</property>
27
+    <property name="stock">gtk-refresh</property>
28
+  </object>
24 29
   <object class="GtkApplicationWindow" id="window">
25 30
     <property name="name">window</property>
26 31
     <property name="can_focus">False</property>
@@ -48,7 +53,6 @@
48 53
                 <property name="receives_default">True</property>
49 54
                 <property name="tooltip_text" translatable="yes">Go back</property>
50 55
                 <property name="margin_left">6</property>
51
-                <property name="margin_right">1</property>
52 56
                 <property name="margin_top">15</property>
53 57
                 <property name="margin_bottom">15</property>
54 58
                 <property name="image">image3</property>
@@ -64,6 +68,27 @@
64 68
               </packing>
65 69
             </child>
66 70
             <child>
71
+              <object class="GtkButton" id="refresh_button">
72
+                <property name="name">refresh_button</property>
73
+                <property name="visible">True</property>
74
+                <property name="can_focus">True</property>
75
+                <property name="receives_default">True</property>
76
+                <property name="tooltip_text" translatable="yes">Refresh</property>
77
+                <property name="margin_right">1</property>
78
+                <property name="margin_top">15</property>
79
+                <property name="margin_bottom">15</property>
80
+                <property name="image">image4</property>
81
+                <property name="always_show_image">True</property>
82
+                <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
83
+              </object>
84
+              <packing>
85
+                <property name="expand">False</property>
86
+                <property name="fill">True</property>
87
+                <property name="padding">1</property>
88
+                <property name="position">1</property>
89
+              </packing>
90
+            </child>
91
+            <child>
67 92
               <object class="GtkButton" id="add_bookmark_button">
68 93
                 <property name="name">add_bookmark_button</property>
69 94
                 <property name="visible">True</property>
@@ -80,7 +105,7 @@
80 105
                 <property name="expand">False</property>
81 106
                 <property name="fill">True</property>
82 107
                 <property name="padding">1</property>
83
-                <property name="position">1</property>
108
+                <property name="position">2</property>
84 109
               </packing>
85 110
             </child>
86 111
             <child>
@@ -98,7 +123,7 @@
98 123
               <packing>
99 124
                 <property name="expand">False</property>
100 125
                 <property name="fill">True</property>
101
-                <property name="position">2</property>
126
+                <property name="position">3</property>
102 127
               </packing>
103 128
             </child>
104 129
             <child>
@@ -117,7 +142,7 @@
117 142
                 <property name="expand">True</property>
118 143
                 <property name="fill">True</property>
119 144
                 <property name="padding">1</property>
120
-                <property name="position">3</property>
145
+                <property name="position">4</property>
121 146
               </packing>
122 147
             </child>
123 148
           </object>

+ 9
- 0
src/gui.rs View File

@@ -8,6 +8,7 @@ pub struct Gui {
8 8
     url_bar: Entry,
9 9
     content_view: TextView,
10 10
     back_button: Button,
11
+    refresh_button: Button,
11 12
     add_bookmark_button: Button,
12 13
     show_bookmarks_button: Button,
13 14
 }
@@ -33,6 +34,9 @@ impl Gui {
33 34
         let back_button: Button = builder
34 35
             .get_object("back_button")
35 36
             .expect("Couldn't get back_button");
37
+        let refresh_button: Button = builder
38
+            .get_object("refresh_button")
39
+            .expect("Couldn't get refresh_button");
36 40
         let add_bookmark_button: Button = builder
37 41
             .get_object("add_bookmark_button")
38 42
             .expect("Couldn't get add_bookmark_button");
@@ -45,6 +49,7 @@ impl Gui {
45 49
             url_bar,
46 50
             content_view,
47 51
             back_button,
52
+            refresh_button,
48 53
             add_bookmark_button,
49 54
             show_bookmarks_button,
50 55
         }
@@ -81,6 +86,10 @@ impl Gui {
81 86
         &self.back_button
82 87
     }
83 88
 
89
+    pub fn refresh_button(&self) -> &Button {
90
+        &self.refresh_button
91
+    }
92
+
84 93
     pub fn add_bookmark_button(&self) -> &Button {
85 94
         &self.add_bookmark_button
86 95
     }

+ 15
- 0
src/main.rs View File

@@ -60,6 +60,15 @@ fn main() {
60 60
         });
61 61
     }
62 62
 
63
+    // Bind refresh button
64
+    {
65
+        let button = gui.refresh_button();
66
+        let gui = gui.clone();
67
+        button.connect_clicked(move |_| {
68
+            refresh(&gui);
69
+        });
70
+    }
71
+
63 72
     // Bind add_bookmark button
64 73
     {
65 74
         let button = gui.add_bookmark_button();
@@ -162,6 +171,12 @@ fn go_back(gui: &Arc<Gui>) {
162 171
     }
163 172
 }
164 173
 
174
+fn refresh(gui: &Arc<Gui>) {
175
+    let url_bar = gui.url_bar();
176
+    let url = url_bar.get_text().expect("get_text failed").to_string();
177
+    route_url(&gui, url)
178
+}
179
+
165 180
 fn update_url_field(gui: &Arc<Gui>, url: &str) {
166 181
     let url_bar = gui.url_bar();
167 182
     url_bar.get_buffer().set_text(url);

Loading…
Cancel
Save