Fix crashes when no documents (tabs) are open

Two crashes are possible:

1. Fixes #450 (toggle overview map without any open tabs/docs)
2. Pressing ESC (e.g. to close searchbar) without any tabs open
This commit is contained in:
okaestne 2021-04-10 21:05:13 +02:00 committed by Michael Webster
parent 8ff2d3fd74
commit 5b769045f0
3 changed files with 19 additions and 9 deletions

View File

@ -155,6 +155,12 @@ _xed_cmd_view_toggle_overview_map (GtkAction *action,
xed_debug (DEBUG_COMMANDS); xed_debug (DEBUG_COMMANDS);
tab = xed_window_get_active_tab (window); tab = xed_window_get_active_tab (window);
if (tab == NULL)
{
return;
}
frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (tab)); frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (tab));
map_frame = xed_view_frame_get_map_frame (frame); map_frame = xed_view_frame_get_map_frame (frame);
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

View File

@ -3001,5 +3001,7 @@ xed_tab_set_info_bar (XedTab *tab,
GtkWidget * GtkWidget *
_xed_tab_get_view_frame (XedTab *tab) _xed_tab_get_view_frame (XedTab *tab)
{ {
g_return_val_if_fail (XED_IS_TAB (tab), NULL);
return GTK_WIDGET (tab->priv->frame); return GTK_WIDGET (tab->priv->frame);
} }

View File

@ -115,7 +115,7 @@ save_panes_state (XedWindow *window)
g_settings_apply (window->priv->window_settings); g_settings_apply (window->priv->window_settings);
} }
static gint static gboolean
on_key_pressed (GtkWidget *widget, on_key_pressed (GtkWidget *widget,
GdkEventKey *event, GdkEventKey *event,
XedWindow *window) XedWindow *window)
@ -126,18 +126,20 @@ on_key_pressed (GtkWidget *widget,
XedViewFrame *frame; XedViewFrame *frame;
tab = xed_window_get_active_tab (window); tab = xed_window_get_active_tab (window);
if (tab != NULL)
{
frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (tab)); frame = XED_VIEW_FRAME (_xed_tab_get_view_frame (tab));
if (xed_view_frame_get_search_popup_visible (frame)) if (xed_view_frame_get_search_popup_visible (frame))
{ {
return GDK_EVENT_PROPAGATE; return GDK_EVENT_PROPAGATE;
} }
else }
{
xed_searchbar_hide (XED_SEARCHBAR (window->priv->searchbar)); xed_searchbar_hide (XED_SEARCHBAR (window->priv->searchbar));
return GDK_EVENT_STOP; return GDK_EVENT_STOP;
} }
}
return GDK_EVENT_PROPAGATE; return GDK_EVENT_PROPAGATE;
} }