From ac32aae77830f636203abc824e7c24c58192aa4c Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Fri, 21 Sep 2012 20:24:15 -0300
Subject: [PATCH v2 Browse] Button to clear the url entry SL #3499
Added an 'X' to clear the url entry easily. This button is shown when
the url entry has focus and the user is not reading a .pdf
webpage. When the focus is left the icon changes again to the correct
one (reload, stop loading or none)
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
---
browser.py | 5 +++++
pdfviewer.py | 6 ++++++
webtoolbar.py | 32 ++++++++++++++++++++++++++++----
3 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/browser.py b/browser.py
index 0d94649..f0b711d 100644
a
|
b
|
class TabbedView(BrowserNotebook): |
341 | 341 | self._append_tab(browser) |
342 | 342 | browser.set_history(tab_history) |
343 | 343 | |
| 344 | def is_current_page_pdf(self): |
| 345 | index = self.get_current_page() |
| 346 | current_page = self.get_nth_page(index) |
| 347 | return isinstance(current_page, PDFTabPage) |
| 348 | |
344 | 349 | |
345 | 350 | Gtk.rc_parse_string(''' |
346 | 351 | style "browse-tab-close" { |
diff --git a/pdfviewer.py b/pdfviewer.py
index 5f607bf..6ce4fcf 100644
a
|
b
|
class DummyBrowser(GObject.GObject): |
270 | 270 | def reload(self): |
271 | 271 | pass |
272 | 272 | |
| 273 | def load_uri(self, uri): |
| 274 | pass |
| 275 | |
| 276 | def grab_focus(self): |
| 277 | pass |
| 278 | |
273 | 279 | |
274 | 280 | class PDFTabPage(Gtk.HBox): |
275 | 281 | """Shows a basic PDF viewer, download the file first if the PDF is |
diff --git a/webtoolbar.py b/webtoolbar.py
index 28bc015..1e1b02f 100644
a
|
b
|
class PrimaryToolbar(ToolbarBase): |
258 | 258 | 'browse-dialog-cancel') |
259 | 259 | self.entry.connect('icon-press', self._stop_and_reload_cb) |
260 | 260 | self.entry.connect('activate', self._entry_activate_cb) |
| 261 | self.entry.connect('focus-in-event', self.__focus_in_event_cb) |
| 262 | self.entry.connect('focus-out-event', self.__focus_out_event_cb) |
261 | 263 | |
262 | 264 | entry_item = Gtk.ToolItem() |
263 | 265 | entry_item.set_expand(True) |
… |
… |
class PrimaryToolbar(ToolbarBase): |
387 | 389 | self.entry.props.title = title |
388 | 390 | self._title = title |
389 | 391 | |
| 392 | def __focus_in_event_cb(self, entry, event): |
| 393 | if not self._tabbed_view.is_current_page_pdf(): |
| 394 | self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY, |
| 395 | 'dialog-cancel') |
| 396 | |
| 397 | def __focus_out_event_cb(self, entry, event): |
| 398 | if self._loading: |
| 399 | self._show_stop_icon() |
| 400 | else: |
| 401 | if not self._tabbed_view.is_current_page_pdf(): |
| 402 | self._show_reload_icon() |
| 403 | |
| 404 | def _show_no_icon(self): |
| 405 | self.entry.remove_icon(iconentry.ICON_ENTRY_SECONDARY) |
| 406 | |
390 | 407 | def _show_stop_icon(self): |
391 | 408 | self.entry.set_icon_from_name(iconentry.ICON_ENTRY_SECONDARY, |
392 | 409 | 'browse-dialog-cancel') |
… |
… |
class PrimaryToolbar(ToolbarBase): |
432 | 449 | filepicker.cleanup_temp_files() |
433 | 450 | |
434 | 451 | def _stop_and_reload_cb(self, entry, icon_pos, button): |
435 | | if self._loading: |
436 | | self._browser.stop_loading() |
| 452 | if entry.has_focus() and \ |
| 453 | not self._tabbed_view.is_current_page_pdf(): |
| 454 | entry.set_text('') |
437 | 455 | else: |
438 | | self._browser.reload() |
| 456 | if self._loading: |
| 457 | self._browser.stop_loading() |
| 458 | else: |
| 459 | self._browser.reload() |
439 | 460 | |
440 | 461 | def _set_loading(self, loading): |
441 | 462 | self._loading = loading |
… |
… |
class PrimaryToolbar(ToolbarBase): |
443 | 464 | if self._loading: |
444 | 465 | self._show_stop_icon() |
445 | 466 | else: |
446 | | self._show_reload_icon() |
| 467 | if not self._tabbed_view.is_current_page_pdf(): |
| 468 | self._show_reload_icon() |
| 469 | else: |
| 470 | self._show_no_icon() |
447 | 471 | |
448 | 472 | def _reload_session_history(self): |
449 | 473 | back_forward_list = self._browser.get_back_forward_list() |