fix: the syntax menu wasn't working anymore

This commit is contained in:
Romain Failliot 2023-04-07 17:08:01 -04:00
parent d42b0b925e
commit f5f425d089
3 changed files with 10 additions and 15 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Some signals weren't properly renamed from the previous GTK3 migration (@MightyCreak) - Some signals weren't properly renamed from the previous GTK3 migration (@MightyCreak)
- The syntax menu wasn't working anymore (@MightyCreak)
## 0.8.1 - 2023-04-07 ## 0.8.1 - 2023-04-07

View File

@ -215,7 +215,7 @@ class FileDiffViewerBase(Gtk.Grid):
self.undoblock = None self.undoblock = None
# cached data # cached data
self.syntax = None self.syntax = ''
self.diffmap_cache = None self.diffmap_cache = None
# editing mode # editing mode
@ -545,13 +545,13 @@ class FileDiffViewerBase(Gtk.Grid):
self.emit('mode-changed') self.emit('mode-changed')
# sets the syntax highlighting rules # sets the syntax highlighting rules
def setSyntax(self, s): def setSyntax(self, new_syntax: str) -> None:
if self.syntax is not s: if self.syntax is not new_syntax:
self.syntax = s self.syntax = new_syntax
# invalidate the syntax caches # invalidate the syntax caches
for pane in self.panes: for pane in self.panes:
pane.syntax_cache = [] pane.syntax_cache = []
self.emit('syntax-changed', s) self.emit('syntax-changed', new_syntax)
# force all panes to redraw # force all panes to redraw
for darea in self.dareas: for darea in self.dareas:
darea.queue_draw() darea.queue_draw()

View File

@ -906,9 +906,6 @@ class DiffuseWindow(Gtk.ApplicationWindow):
] ]
]]) ]])
# used to disable menu events when switching tabs
self.menu_update_depth = 0
menubar = Gio.Menu() menubar = Gio.Menu()
for label, sections in menu_specs: for label, sections in menu_specs:
menubar.append_submenu(label, self._create_menu(sections)) menubar.append_submenu(label, self._create_menu(sections))
@ -1257,9 +1254,9 @@ class DiffuseWindow(Gtk.ApplicationWindow):
sb.push(context, s) sb.push(context, s)
# update the label in the status bar # update the label in the status bar
def setSyntax(self, s): def setSyntax(self, s: str) -> None:
# update menu # update menu
self.syntax_action.set_state(GLib.Variant.new_string(s or '')) self.syntax_action.set_state(GLib.Variant.new_string(s))
# callback used when switching notebook pages # callback used when switching notebook pages
def switch_page_cb(self, widget, ptr, page_num): def switch_page_cb(self, widget, ptr, page_num):
@ -1691,11 +1688,8 @@ class DiffuseWindow(Gtk.ApplicationWindow):
self.preferences_updated() self.preferences_updated()
# callback for all of the syntax highlighting menu items # callback for all of the syntax highlighting menu items
def syntax_cb(self, widget, data): def syntax_cb(self, widget: Gtk.Widget, data: GLib.Variant) -> None:
# ignore events while we update the menu when switching tabs self.getCurrentViewer().setSyntax(data.get_string())
# also ignore notification of the newly disabled item
if self.menu_update_depth == 0 and widget.get_active():
self.getCurrentViewer().setSyntax(data)
# callback for the first tab menu item # callback for the first tab menu item
def first_tab_cb(self, widget, data): def first_tab_cb(self, widget, data):