Browse Source

Add forward button

openbsd
Michael Beaumont 9 months ago
parent
commit
38c1c92c37
3 changed files with 85 additions and 31 deletions
  1. 33
    6
      src/castor.glade
  2. 9
    0
      src/gui.rs
  3. 43
    25
      src/main.rs

+ 33
- 6
src/castor.glade View File

@@ -24,6 +24,11 @@
24 24
   <object class="GtkImage" id="image4">
25 25
     <property name="visible">True</property>
26 26
     <property name="can_focus">False</property>
27
+    <property name="stock">gtk-go-forward</property>
28
+  </object>
29
+  <object class="GtkImage" id="image5">
30
+    <property name="visible">True</property>
31
+    <property name="can_focus">False</property>
27 32
     <property name="stock">gtk-refresh</property>
28 33
   </object>
29 34
   <object class="GtkApplicationWindow" id="window">
@@ -68,16 +73,38 @@
68 73
               </packing>
69 74
             </child>
70 75
             <child>
76
+              <object class="GtkButton" id="forward_button">
77
+                <property name="name">forward_button</property>
78
+                <property name="visible">True</property>
79
+                <property name="can_focus">True</property>
80
+                <property name="receives_default">True</property>
81
+                <property name="tooltip_text" translatable="yes">Go forward</property>
82
+                <property name="margin_right">1</property>
83
+                <property name="margin_top">15</property>
84
+                <property name="margin_bottom">15</property>
85
+                <property name="image">image4</property>
86
+                <property name="always_show_image">True</property>
87
+                <accelerator key="Left" signal="clicked" modifiers="GDK_MOD1_MASK"/>
88
+                <accelerator key="Back" signal="clicked"/>
89
+              </object>
90
+              <packing>
91
+                <property name="expand">False</property>
92
+                <property name="fill">True</property>
93
+                <property name="padding">1</property>
94
+                <property name="position">1</property>
95
+              </packing>
96
+            </child>
97
+            <child>
71 98
               <object class="GtkButton" id="refresh_button">
72 99
                 <property name="name">refresh_button</property>
73 100
                 <property name="visible">True</property>
74 101
                 <property name="can_focus">True</property>
75 102
                 <property name="receives_default">True</property>
76 103
                 <property name="tooltip_text" translatable="yes">Refresh</property>
77
-                <property name="margin_right">1</property>
104
+                <property name="margin_left">6</property>
78 105
                 <property name="margin_top">15</property>
79 106
                 <property name="margin_bottom">15</property>
80
-                <property name="image">image4</property>
107
+                <property name="image">image5</property>
81 108
                 <property name="always_show_image">True</property>
82 109
                 <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
83 110
               </object>
@@ -85,7 +112,7 @@
85 112
                 <property name="expand">False</property>
86 113
                 <property name="fill">True</property>
87 114
                 <property name="padding">1</property>
88
-                <property name="position">1</property>
115
+                <property name="position">2</property>
89 116
               </packing>
90 117
             </child>
91 118
             <child>
@@ -105,7 +132,7 @@
105 132
                 <property name="expand">True</property>
106 133
                 <property name="fill">True</property>
107 134
                 <property name="padding">1</property>
108
-                <property name="position">2</property>
135
+                <property name="position">3</property>
109 136
               </packing>
110 137
             </child>
111 138
             <child>
@@ -125,7 +152,7 @@
125 152
                 <property name="expand">False</property>
126 153
                 <property name="fill">True</property>
127 154
                 <property name="padding">1</property>
128
-                <property name="position">3</property>
155
+                <property name="position">4</property>
129 156
               </packing>
130 157
             </child>
131 158
             <child>
@@ -145,7 +172,7 @@
145 172
                 <property name="expand">False</property>
146 173
                 <property name="fill">True</property>
147 174
                 <property name="padding">1</property>
148
-                <property name="position">4</property>
175
+                <property name="position">5</property>
149 176
               </packing>
150 177
             </child>
151 178
           </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
+    forward_button: Button,
11 12
     refresh_button: Button,
12 13
     add_bookmark_button: Button,
13 14
     show_bookmarks_button: Button,
@@ -34,6 +35,9 @@ impl Gui {
34 35
         let back_button: Button = builder
35 36
             .get_object("back_button")
36 37
             .expect("Couldn't get back_button");
38
+        let forward_button: Button = builder
39
+            .get_object("forward_button")
40
+            .expect("Couldn't get forward_button");
37 41
         let refresh_button: Button = builder
38 42
             .get_object("refresh_button")
39 43
             .expect("Couldn't get refresh_button");
@@ -49,6 +53,7 @@ impl Gui {
49 53
             url_bar,
50 54
             content_view,
51 55
             back_button,
56
+            forward_button,
52 57
             refresh_button,
53 58
             add_bookmark_button,
54 59
             show_bookmarks_button,
@@ -86,6 +91,10 @@ impl Gui {
86 91
         &self.back_button
87 92
     }
88 93
 
94
+    pub fn forward_button(&self) -> &Button {
95
+        &self.forward_button
96
+    }
97
+
89 98
     pub fn refresh_button(&self) -> &Button {
90 99
         &self.refresh_button
91 100
     }

+ 43
- 25
src/main.rs View File

@@ -8,6 +8,7 @@ extern crate lazy_static;
8 8
 use std::env;
9 9
 use std::str::FromStr;
10 10
 use std::sync::Arc;
11
+use url::Url;
11 12
 
12 13
 use gtk::prelude::*;
13 14
 
@@ -60,6 +61,15 @@ fn main() {
60 61
         });
61 62
     }
62 63
 
64
+    // Bind forward button
65
+    {
66
+        let button = gui.forward_button();
67
+        let gui = gui.clone();
68
+        button.connect_clicked(move |_| {
69
+            go_forward(&gui);
70
+        });
71
+    }
72
+
63 73
     // Bind refresh button
64 74
     {
65 75
         let button = gui.refresh_button();
@@ -145,29 +155,38 @@ fn route_url(gui: &Arc<Gui>, url: String) {
145 155
 }
146 156
 
147 157
 fn go_back(gui: &Arc<Gui>) {
148
-    let previous = history::get_previous_url();
149
-    if let Some(url) = previous {
150
-        match url.scheme() {
151
-            "finger" => visit_url(
152
-                gui,
153
-                Finger {
154
-                    source: url.to_string(),
155
-                },
156
-            ),
157
-            "gemini" => visit_url(
158
-                gui,
159
-                Gemini {
160
-                    source: url.to_string(),
161
-                },
162
-            ),
163
-            "gopher" => visit_url(
164
-                gui,
165
-                Gopher {
166
-                    source: url.to_string(),
167
-                },
168
-            ),
169
-            _ => (),
170
-        }
158
+    if let Some(prev) = history::get_previous_url() {
159
+        visit(gui, &prev);
160
+    }
161
+}
162
+
163
+fn go_forward(gui: &Arc<Gui>) {
164
+    if let Some(next) = history::get_next_url() {
165
+        visit(gui, &next);
166
+    }
167
+}
168
+
169
+fn visit(gui: &Arc<Gui>, url: &Url) {
170
+    match url.scheme() {
171
+        "finger" => visit_url(
172
+            gui,
173
+            Finger {
174
+                source: url.to_string(),
175
+            },
176
+        ),
177
+        "gemini" => visit_url(
178
+            gui,
179
+            Gemini {
180
+                source: url.to_string(),
181
+            },
182
+        ),
183
+        "gopher" => visit_url(
184
+            gui,
185
+            Gopher {
186
+                source: url.to_string(),
187
+            },
188
+        ),
189
+        _ => (),
171 190
     }
172 191
 }
173 192
 
@@ -190,8 +209,7 @@ fn add_bookmark(gui: &Arc<Gui>) {
190 209
         if bookmarks::is_valid(&url) {
191 210
             bookmarks::add(&url);
192 211
             dialog::info(&gui, "Bookmark added.");
193
-        }
194
-        else {
212
+        } else {
195 213
             dialog::error(&gui, "Invalid bookmark URL.");
196 214
         }
197 215
     }

Loading…
Cancel
Save