Skip to content

Commit c1391bf

Browse files
committed
Auto-close current file when opening another one
1 parent 10eef3c commit c1391bf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

main.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ static int open_dwarf_file(char *path)
145145

146146
static void close_dwarf_file(void)
147147
{
148+
if (dwarf == NULL)
149+
return;
150+
148151
dwarf_end(dwarf);
152+
dwarf = NULL;
149153

150154
gtk_tree_store_clear(arg->main_store);
151155
gtk_tree_store_clear(arg->attr_store);
@@ -176,7 +180,6 @@ static void close_dwarf_file(void)
176180
}
177181

178182
g_free(arg->filename);
179-
180183
g_free(arg);
181184
}
182185

@@ -916,9 +919,6 @@ static void on_file_open(GtkMenuItem *menu, gpointer *window)
916919
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
917920
GtkFileChooser *chooser;
918921

919-
if (dwarf != NULL)
920-
return;
921-
922922
dialog = gtk_file_chooser_dialog_new("Open File", GTK_WINDOW(window), action,
923923
"_Cancel", GTK_RESPONSE_CANCEL,
924924
"_Open", GTK_RESPONSE_ACCEPT,
@@ -934,6 +934,7 @@ static void on_file_open(GtkMenuItem *menu, gpointer *window)
934934
filename = gtk_file_chooser_get_filename(chooser);
935935
gtk_widget_destroy (dialog);
936936

937+
close_dwarf_file();
937938
res = open_dwarf_file(filename);
938939
if (res != 0)
939940
show_warning(GTK_WIDGET(window), "Error: %s: %s\n",
@@ -944,11 +945,7 @@ static void on_file_open(GtkMenuItem *menu, gpointer *window)
944945

945946
static void on_file_close(GtkMenuItem *menu, gpointer *unused)
946947
{
947-
if (dwarf == NULL)
948-
return;
949-
950948
close_dwarf_file();
951-
dwarf = NULL;
952949
}
953950

954951
static gboolean on_attr_press(GtkWidget *widget, GdkEvent *event, gpointer data)

0 commit comments

Comments
 (0)