Skip to content

Gtk4 Prep: Use extra_menu model for sourceview context menu#1732

Open
jeremypw wants to merge 5 commits into
masterfrom
jeremypw/sourceview/use-glib-menu
Open

Gtk4 Prep: Use extra_menu model for sourceview context menu#1732
jeremypw wants to merge 5 commits into
masterfrom
jeremypw/sourceview/use-glib-menu

Conversation

@jeremypw

@jeremypw jeremypw commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

As far as possible moves towards the code that will be required for sourceview-5 (Gtk4) with regards to the context menu. While in Gtk3 we still have to create Gtk.MenuItems as that is what is required for sourceview-4. However we create these items from an extra_menu MenuModel which in sourceview-5 will be automatically used.

Actions required by the extra items are moved from MainWindow into the SourceView class which makes more sense. Their associated accelerators are also moved, using a keycontroller.

Rather than setting the actions enabled/disabled only on popping up the context menu, they are constantly updated according to various property notifications as will be required for sourceview-5.

Overall this saves a few lines and porting the context menu will require little more than deleting some of these.

In passing

Stripping whitespace is inhibited if there is a selection when the context menu is invoked to avoid the selection being lost when the menu is focused.


populate_popup.connect_after (on_context_menu);
// Actions and menumodel for additional context menu items
var sort_action = new SimpleAction ("sort-lines", null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we already have actions for these that we were using previously. Is there a reason to create new actions instead of reusing the existing ones?

@jeremypw jeremypw Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in the process of removing those actions and associated functions from MainWindow. It makes more sense to handle them locally, especially in Gtk4.

Note that this pattern has already been used for the Terminal pane and Sidebar for example.

@jeremypw jeremypw changed the title Gtk4 Prep: Use extra_menu model for context menu Gtk4 Prep: Use extra_menu model for sourceview context menu Jun 19, 2026
@jeremypw jeremypw added this to the 8.3.2 milestone Jun 20, 2026
@jeremypw jeremypw marked this pull request as ready for review June 20, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants