Skip to content

Commit

Permalink
fix: the syntax menu wasn't working anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyCreak committed Apr 7, 2023
1 parent d42b0b9 commit f5f425d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- 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

Expand Down
10 changes: 5 additions & 5 deletions src/diffuse/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def __init__(self, n, prefs):
self.undoblock = None

# cached data
self.syntax = None
self.syntax = ''
self.diffmap_cache = None

# editing mode
Expand Down Expand Up @@ -545,13 +545,13 @@ def setCharMode(self) -> None:
self.emit('mode-changed')

# sets the syntax highlighting rules
def setSyntax(self, s):
if self.syntax is not s:
self.syntax = s
def setSyntax(self, new_syntax: str) -> None:
if self.syntax is not new_syntax:
self.syntax = new_syntax
# invalidate the syntax caches
for pane in self.panes:
pane.syntax_cache = []
self.emit('syntax-changed', s)
self.emit('syntax-changed', new_syntax)
# force all panes to redraw
for darea in self.dareas:
darea.queue_draw()
Expand Down
14 changes: 4 additions & 10 deletions src/diffuse/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,6 @@ def __init__(self, rc_dir, **kwargs):
]
]])

# used to disable menu events when switching tabs
self.menu_update_depth = 0

menubar = Gio.Menu()
for label, sections in menu_specs:
menubar.append_submenu(label, self._create_menu(sections))
Expand Down Expand Up @@ -1257,9 +1254,9 @@ def setStatus(self, s: Optional[str]) -> None:
sb.push(context, s)

# update the label in the status bar
def setSyntax(self, s):
def setSyntax(self, s: str) -> None:
# 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
def switch_page_cb(self, widget, ptr, page_num):
Expand Down Expand Up @@ -1691,11 +1688,8 @@ def preferences_cb(self, widget, data):
self.preferences_updated()

# callback for all of the syntax highlighting menu items
def syntax_cb(self, widget, data):
# ignore events while we update the menu when switching tabs
# also ignore notification of the newly disabled item
if self.menu_update_depth == 0 and widget.get_active():
self.getCurrentViewer().setSyntax(data)
def syntax_cb(self, widget: Gtk.Widget, data: GLib.Variant) -> None:
self.getCurrentViewer().setSyntax(data.get_string())

# callback for the first tab menu item
def first_tab_cb(self, widget, data):
Expand Down

0 comments on commit f5f425d

Please sign in to comment.