Тема: gtk4 неактивні кнопки меню
Намагаюся створити звичайне меню.
Завантажив їхній офіційний приклад з Github та створив меню Settings.
Хоча я начебто все скопіював, але кнопки в меню Settings неактивні,
а в меню File все працює як слід.
Ніяк не зрозумію, що не так.
main.rs
mod main_window;
pub use crate::main_window::{activate_main_window, build_main_window};
use gtk::prelude::*;
fn main() {
// Create a new application
let application = gtk::Application::builder()
.application_id("com.github.gtk-rs.examples.menubar")
.build();
application.connect_startup(build_main_window);
application.connect_activate(activate_main_window);
application.run();
}
main_window.rs
use gtk::{gio, prelude::*};
pub fn build_main_window(app: >k::Application) {
let about = gio::ActionEntry::builder("about")
.activate(|_, _, _| println!("About was pressed"))
.build();
let quit = gio::ActionEntry::builder("quit")
.activate(|app: >k::Application, _, _| app.quit())
.build();
let dict_settings = gio::ActionEntry::builder("Dictionary settings")
.activate(|_, _, _| println!("Dictionary settings was pressed"))
.build();
let clean_search_history = gio::ActionEntry::builder("Clean search history")
.activate(|_, _, _| println!("Clean search history"))
.build();
let show_search_history = gio::ActionEntry::builder("Show search history")
.activate(|_, _, _| println!("Show search history"))
.build();
app.add_action_entries([
about,
quit,
dict_settings,
clean_search_history,
show_search_history,
]);
let menubar = {
let file_menu = {
let about_menu_item = gio::MenuItem::new(Some("About"), Some("app.about"));
let quit_menu_item = gio::MenuItem::new(Some("Quit"), Some("app.quit"));
let file_menu = gio::Menu::new();
file_menu.append_item(&about_menu_item);
file_menu.append_item(&quit_menu_item);
file_menu
};
let settings_menu = {
let dict_settings_menu_item = gio::MenuItem::new(
Some("Dictionary settings"), Some("app.dict_settings"));
let search_history_submenu = gio::Menu::new();
let clean_search_history_menu_item = gio::MenuItem::new(
Some("Clean search history"), Some("app.clean_search_history"));
let show_search_history_menu_item = gio::MenuItem::new(
Some("Show search history"), Some("app.show_search_history"));
search_history_submenu.append_item(&clean_search_history_menu_item);
search_history_submenu.append_item(&show_search_history_menu_item);
let settings_menu = gio::Menu::new();
settings_menu.append_item(&dict_settings_menu_item);
settings_menu.append_submenu(Some("Search history"), &search_history_submenu);
settings_menu
};
let menubar = gio::Menu::new();
menubar.append_submenu(Some("File"), &file_menu);
menubar.append_submenu(Some("Settings"), &settings_menu);
menubar
};
app.set_menubar(Some(&menubar));
}
pub fn activate_main_window(application: >k::Application) {
let window = gtk::ApplicationWindow::builder()
.application(application)
.title("Menubar Example")
.default_width(350)
.default_height(350)
.show_menubar(true)
.build();
window.present();
}