fix: toolbar buttons not visible - hbox was never packed into window
The build_toolbar() method created a local GtkBox (hbox) and packed all buttons into it, but never added hbox to the window's vbox. The toolbar was created then immediately garbage collected. Fix: Inline all UI construction directly into build_ui() and pack the toolbar box into the vbox with gtk_box_pack_start().
This commit is contained in:
+21
-32
@@ -84,62 +84,51 @@ void SshClientWindow::build_ui() {
|
|||||||
GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
GtkWidget* vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
gtk_container_add(GTK_CONTAINER(window_), vbox);
|
gtk_container_add(GTK_CONTAINER(window_), vbox);
|
||||||
|
|
||||||
build_toolbar();
|
GtkWidget* toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
||||||
|
gtk_widget_set_margin_start(toolbar, 6);
|
||||||
GtkWidget* sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
|
gtk_widget_set_margin_end(toolbar, 6);
|
||||||
gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
|
gtk_widget_set_margin_top(toolbar, 4);
|
||||||
|
gtk_widget_set_margin_bottom(toolbar, 4);
|
||||||
build_notebook();
|
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
|
||||||
build_statusbar();
|
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(vbox), notebook_, TRUE, TRUE, 0);
|
|
||||||
gtk_box_pack_end(GTK_BOX(vbox), statusbar_, FALSE, FALSE, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshClientWindow::build_toolbar() {
|
|
||||||
GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
||||||
gtk_widget_set_margin_start(hbox, 6);
|
|
||||||
gtk_widget_set_margin_end(hbox, 6);
|
|
||||||
gtk_widget_set_margin_top(hbox, 4);
|
|
||||||
gtk_widget_set_margin_bottom(hbox, 4);
|
|
||||||
|
|
||||||
server_combo_ = gtk_combo_box_text_new();
|
server_combo_ = gtk_combo_box_text_new();
|
||||||
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(server_combo_), 0);
|
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(server_combo_), 0);
|
||||||
gtk_widget_set_size_request(server_combo_, 180, -1);
|
gtk_widget_set_size_request(server_combo_, 180, -1);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), server_combo_, FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), server_combo_, FALSE, FALSE, 0);
|
||||||
|
|
||||||
quick_entry_ = gtk_entry_new();
|
quick_entry_ = gtk_entry_new();
|
||||||
gtk_entry_set_placeholder_text(GTK_ENTRY(quick_entry_), "host");
|
gtk_entry_set_placeholder_text(GTK_ENTRY(quick_entry_), "host");
|
||||||
gtk_widget_set_size_request(quick_entry_, 150, -1);
|
gtk_widget_set_size_request(quick_entry_, 150, -1);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), quick_entry_, FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), quick_entry_, FALSE, FALSE, 0);
|
||||||
|
|
||||||
user_entry_ = gtk_entry_new();
|
user_entry_ = gtk_entry_new();
|
||||||
gtk_entry_set_placeholder_text(GTK_ENTRY(user_entry_), "user");
|
gtk_entry_set_placeholder_text(GTK_ENTRY(user_entry_), "user");
|
||||||
gtk_widget_set_size_request(user_entry_, 100, -1);
|
gtk_widget_set_size_request(user_entry_, 100, -1);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), user_entry_, FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), user_entry_, FALSE, FALSE, 0);
|
||||||
|
|
||||||
port_spin_ = gtk_spin_button_new_with_range(1, 65535, 1);
|
port_spin_ = gtk_spin_button_new_with_range(1, 65535, 1);
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(port_spin_), 22);
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(port_spin_), 22);
|
||||||
gtk_widget_set_size_request(port_spin_, 80, -1);
|
gtk_widget_set_size_request(port_spin_, 80, -1);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), port_spin_, FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), port_spin_, FALSE, FALSE, 0);
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("Connect", G_CALLBACK(on_quick_connect), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("Connect", G_CALLBACK(on_quick_connect), this), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("+ Tab", G_CALLBACK(on_new_tab), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("+ Tab", G_CALLBACK(on_new_tab), this), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("Close Tab", G_CALLBACK(on_close_tab), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("Close Tab", G_CALLBACK(on_close_tab), this), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("Disconnect", G_CALLBACK(on_disconnect), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("Disconnect", G_CALLBACK(on_disconnect), this), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("Servers", G_CALLBACK(on_manage_servers), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("Servers", G_CALLBACK(on_manage_servers), this), FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), make_button("Keys", G_CALLBACK(on_manage_keys), this), FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(toolbar), make_button("Keys", G_CALLBACK(on_manage_keys), this), FALSE, FALSE, 0);
|
||||||
|
|
||||||
update_server_combo();
|
update_server_combo();
|
||||||
}
|
|
||||||
|
|
||||||
void SshClientWindow::build_notebook() {
|
GtkWidget* sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
|
||||||
|
gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
|
||||||
|
|
||||||
notebook_ = gtk_notebook_new();
|
notebook_ = gtk_notebook_new();
|
||||||
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook_), TRUE);
|
gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook_), TRUE);
|
||||||
}
|
gtk_box_pack_start(GTK_BOX(vbox), notebook_, TRUE, TRUE, 0);
|
||||||
|
|
||||||
void SshClientWindow::build_statusbar() {
|
|
||||||
statusbar_ = gtk_statusbar_new();
|
statusbar_ = gtk_statusbar_new();
|
||||||
|
gtk_box_pack_end(GTK_BOX(vbox), statusbar_, FALSE, FALSE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshClientWindow::update_server_combo() {
|
void SshClientWindow::update_server_combo() {
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void build_ui();
|
void build_ui();
|
||||||
void build_toolbar();
|
|
||||||
void build_notebook();
|
|
||||||
void build_statusbar();
|
|
||||||
|
|
||||||
void add_new_tab();
|
void add_new_tab();
|
||||||
void close_current_tab();
|
void close_current_tab();
|
||||||
void close_tab_at(int idx);
|
void close_tab_at(int idx);
|
||||||
|
|||||||
Reference in New Issue
Block a user