Skip to content

Commit e71134a

Browse files
danirabbitjeremypw
andauthored
SourceView: prepare context menu for GLib.Menu (#1675)
* SourceView: prepare context menu for GLib.Menu * More string tweaks --------- Co-authored-by: Jeremy Wootten <[email protected]>
1 parent 79766ab commit e71134a

File tree

1 file changed

+25
-47
lines changed

1 file changed

+25
-47
lines changed

src/Widgets/SourceView.vala

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -578,72 +578,50 @@ namespace Scratch.Widgets {
578578
private void on_context_menu (Gtk.Menu menu) {
579579
scroll_mark_onscreen (buffer.get_mark ("insert"));
580580

581-
var sort_item = new Gtk.MenuItem ();
582-
sort_item.sensitive = get_selected_line_count () > 1;
583-
sort_item.add (new Granite.AccelLabel.from_action_name (
584-
_("Sort Selected Lines"),
585-
MainWindow.ACTION_PREFIX + MainWindow.ACTION_SORT_LINES
586-
));
587-
sort_item.activate.connect (sort_selected_lines);
588-
589-
menu.add (sort_item);
581+
var sort_item = new Gtk.MenuItem.with_label (_("Sort Lines")) {
582+
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_SORT_LINES
583+
};
590584

591-
var add_edit_item = new Gtk.MenuItem () {
585+
var add_edit_item = new Gtk.MenuItem.with_label (_("Mark Line")) {
592586
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_ADD_MARK
593587
};
594-
add_edit_item.add (new Granite.AccelLabel.from_action_name (
595-
_("Mark Current Line"),
596-
add_edit_item.action_name
597588

598-
));
599-
menu.add (add_edit_item);
600-
601-
var previous_edit_item = new Gtk.MenuItem () {
602-
sensitive = navmark_gutter_renderer.has_marks,
589+
var previous_edit_item = new Gtk.MenuItem.with_label (_("Previous Mark")) {
603590
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_PREVIOUS_MARK
604591
};
605-
previous_edit_item.add (new Granite.AccelLabel.from_action_name (
606-
_("Goto Previous Edit Mark"),
607-
previous_edit_item.action_name
608-
609-
));
610-
menu.add (previous_edit_item);
611592

612-
var next_edit_item = new Gtk.MenuItem () {
613-
sensitive = navmark_gutter_renderer.has_marks,
593+
var next_edit_item = new Gtk.MenuItem.with_label (_("Next Mark")) {
614594
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_NEXT_MARK
615595
};
616-
next_edit_item.add (new Granite.AccelLabel.from_action_name (
617-
_("Goto Next Edit Mark"),
618-
next_edit_item.action_name
619596

620-
));
597+
menu.add (sort_item);
598+
menu.add (add_edit_item);
599+
menu.add (previous_edit_item);
621600
menu.add (next_edit_item);
622601

623-
if (!navmark_gutter_renderer.has_marks) {
624-
previous_edit_item.action_name = "";
625-
previous_edit_item.sensitive = false;
626-
next_edit_item.action_name = "";
627-
next_edit_item.sensitive = false;
628-
}
629-
630602
if (buffer is Gtk.SourceBuffer) {
631-
var can_comment = CommentToggler.language_has_comments (((Gtk.SourceBuffer) buffer).get_language ());
603+
var comment_item = new Gtk.MenuItem.with_label (_("Toggle Comment")) {
604+
action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_COMMENT
605+
};
632606

633-
var comment_item = new Gtk.MenuItem ();
634-
comment_item.sensitive = can_comment;
635-
comment_item.add (new Granite.AccelLabel.from_action_name (
636-
_("Toggle Comment"),
637-
MainWindow.ACTION_PREFIX + MainWindow.ACTION_TOGGLE_COMMENT
638-
));
639-
comment_item.activate.connect (() => {
640-
CommentToggler.toggle_comment ((Gtk.SourceBuffer) buffer);
641-
});
607+
var can_comment = CommentToggler.language_has_comments (((Gtk.SourceBuffer) buffer).get_language ());
608+
if (!can_comment) {
609+
comment_item.action_name = "";
610+
}
642611

643612
menu.add (comment_item);
644613
}
645614

646615
menu.show_all ();
616+
617+
if (!(get_selected_line_count () > 1)) {
618+
sort_item.action_name = "";
619+
}
620+
621+
if (!navmark_gutter_renderer.has_marks) {
622+
previous_edit_item.action_name = "";
623+
next_edit_item.action_name = "";
624+
}
647625
}
648626

649627
private static int calculate_bottom_margin (int height_in_px) {

0 commit comments

Comments
 (0)