Skip to content

Commit ba6a654

Browse files
committed
close mainw on no tabs
1 parent 663dda6 commit ba6a654

File tree

8 files changed

+52
-35
lines changed

8 files changed

+52
-35
lines changed

TODO

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ in cast to `Workspace'
77

88
could just be the WM on my desktop PC, try at home
99

10-
- we really do need a close-mainw-on-no-ws thing
11-
12-
can't put this in at a low level, must happen at the top level in response
13-
to some specific user action, eg. on clicking "YES" on "close tab" dialog
14-
1510
- test new compat stuff
1611

1712
test for warning on merge incompatible ws

src/columnview.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ columnview_destroy_cb( GtkWidget *wid, GtkWidget *host, Columnview *cview )
635635
{
636636
Column *col = COLUMN( VOBJECT( cview )->iobject );
637637

638-
model_check_destroy( view_get_toplevel( VIEW( cview ) ), MODEL( col ) );
638+
model_check_destroy( view_get_toplevel( VIEW( cview ) ),
639+
MODEL( col ), NULL );
639640
}
640641

641642
/* Delete this column with a click on the 'x' button.
@@ -645,7 +646,8 @@ columnview_destroy2_cb( GtkWidget *wid, Columnview *cview )
645646
{
646647
Column *col = COLUMN( VOBJECT( cview )->iobject );
647648

648-
model_check_destroy( view_get_toplevel( VIEW( cview ) ), MODEL( col ) );
649+
model_check_destroy( view_get_toplevel( VIEW( cview ) ),
650+
MODEL( col ), NULL );
649651
}
650652

651653
/* Callback for enter in caption edit box.

src/mainw.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,3 +1965,20 @@ mainw_new( Workspacegroup *wsg )
19651965
return( mainw );
19661966
}
19671967

1968+
static void *
1969+
mainw_cull_sub( Mainw *mainw )
1970+
{
1971+
if( !ICONTAINER( mainw->wsg )->children ) {
1972+
filemodel_set_modified( FILEMODEL( mainw->wsg ), FALSE );
1973+
iwindow_kill( IWINDOW( mainw ) );
1974+
}
1975+
1976+
return( NULL );
1977+
}
1978+
1979+
void
1980+
mainw_cull( void )
1981+
{
1982+
slist_map( mainw_all,
1983+
(SListMapFn) mainw_cull_sub, NULL );
1984+
}

src/mainw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ Workspacegroup *mainw_open_workspace( Workspaceroot *wsr,
145145

146146
Mainw *mainw_new( Workspacegroup *wsg );
147147

148+
void mainw_cull( void );

src/model.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ typedef struct {
799799
iDialog *idlg; /* The yesno we run */
800800
Model *model; /* The model we watch */
801801
guint destroy_sid; /* sid for the destroy */
802+
iWindowFn done_cb; /* Call this at the end */
802803
} ModelCheckDestroy;
803804

804805
/* OK to destroy.
@@ -813,7 +814,7 @@ model_check_destroy_sub( iWindow *iwnd, void *client,
813814
IDESTROY( mcd->model );
814815
symbol_recalculate_all();
815816

816-
nfn( sys, IWINDOW_YES );
817+
mcd->done_cb( iwnd, NULL, nfn, sys );
817818
}
818819

819820
/* The model we are watching has been killed, maybe by us.
@@ -848,7 +849,7 @@ model_check_destroy_finished( void *client, iWindowResult result )
848849
}
849850

850851
void
851-
model_check_destroy( GtkWidget *parent, Model *model )
852+
model_check_destroy( GtkWidget *parent, Model *model, iWindowFn done_cb )
852853
{
853854
char txt[30];
854855
VipsBuf buf = VIPS_BUF_STATIC( txt );
@@ -858,6 +859,7 @@ model_check_destroy( GtkWidget *parent, Model *model )
858859

859860
mcd->idlg = NULL;
860861
mcd->model = model;
862+
mcd->done_cb = done_cb ? done_cb : iwindow_true_cb;
861863

862864
if( IS_SYMBOL( model ) ) {
863865
symbol_qualified_name( SYMBOL( model ), &buf );

src/model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ void model_base_init( void );
225225

226226
View *model_build_display_all( Model *model, View *parent );
227227

228-
void model_check_destroy( GtkWidget *parent, Model *model );
228+
void model_check_destroy( GtkWidget *parent, Model *model, iWindowFn done_cb );
229229

230230
void *model_clear_edited( Model *model );

src/program.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ program_remove_object_cb( GtkWidget *menu, Program *program )
703703
Model *model = program_get_selected( program );
704704

705705
if( model )
706-
model_check_destroy( GTK_WIDGET( program ), model );
706+
model_check_destroy( GTK_WIDGET( program ), model, NULL );
707707
}
708708

709709
static void
@@ -1450,7 +1450,7 @@ program_remove_tool_action_cb( GtkAction *action, Program *program )
14501450
Model *model = program_get_selected( program );
14511451

14521452
if( model && IS_TOOL( model ) )
1453-
model_check_destroy( GTK_WIDGET( program ), model );
1453+
model_check_destroy( GTK_WIDGET( program ), model, NULL );
14541454
else {
14551455
error_top( _( "No tool selected" ) );
14561456
iwindow_alert( GTK_WIDGET( program ), GTK_MESSAGE_INFO );
@@ -1463,7 +1463,8 @@ program_remove_toolkit_action_cb( GtkAction *action, Program *program )
14631463
if( !program_check_kit( program ) )
14641464
return;
14651465

1466-
model_check_destroy( GTK_WIDGET( program ), MODEL( program->kit ) );
1466+
model_check_destroy( GTK_WIDGET( program ),
1467+
MODEL( program->kit ), NULL );
14671468
}
14681469

14691470
static void

src/workspacegroupview.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,23 @@ static void
188188
workspacegroupview_switch_page_cb( GtkNotebook *notebook,
189189
GtkWidget *page, guint page_num, gpointer user_data )
190190
{
191-
static int level = 0;
192-
193191
Workspaceview *wview = WORKSPACEVIEW( page );
194192
Workspace *ws = WORKSPACE( VOBJECT( wview )->iobject );
193+
Workspacegroup *old_wsg = WORKSPACEGROUP( ICONTAINER( ws )->parent );
195194
Workspacegroupview *wsgview = WORKSPACEGROUPVIEW( user_data );
196195
Workspacegroup *wsg = WORKSPACEGROUP( VOBJECT( wsgview )->iobject );
197196

198-
int this_level;
199-
200-
this_level = level;
201-
level += 1;
202-
203-
printf( "workspacegroupview_switch_page_cb: %d wsg = %s, ws = %s\n",
204-
this_level,
205-
NN( IOBJECT( wsg )->name ), NN( IOBJECT( ws )->name ) );
206-
207197
if( ICONTAINER( ws )->parent != ICONTAINER( wsg ) ) {
208-
printf( "workspacegroupview_switch_page_cb: %d moving tab\n",
209-
this_level );
210-
211198
icontainer_reparent( ICONTAINER( wsg ),
212199
ICONTAINER( ws ), -1 );
213200

214-
printf( "workspacegroupview_switch_page_cb: %d tab move done\n",
215-
this_level );
201+
filemodel_set_modified( FILEMODEL( wsg ), TRUE );
202+
filemodel_set_modified( FILEMODEL( old_wsg ), TRUE );
203+
204+
/* If dragging the tab has emptied the old wsg, we can junk
205+
* the window.
206+
*/
207+
mainw_cull();
216208
}
217209

218210
icontainer_current( ICONTAINER( wsg ), ICONTAINER( ws ) );
@@ -234,11 +226,6 @@ workspacegroupview_switch_page_cb( GtkNotebook *notebook,
234226
if( wview &&
235227
wview->fixed )
236228
gtk_container_check_resize( GTK_CONTAINER( wview->fixed ) );
237-
238-
printf( "workspacegroupview_switch_page_cb: %d all done\n",
239-
this_level );
240-
241-
level -= 1;
242229
}
243230

244231
static void
@@ -505,13 +492,25 @@ workspacegroupview_save_as_cb( GtkWidget *wid, GtkWidget *host,
505492
gtk_widget_show( GTK_WIDGET( filesel ) );
506493
}
507494

495+
/* ws has been destroyed.
496+
*/
497+
static void
498+
workspacegroupview_delete_done_cb( iWindow *iwnd, void *client,
499+
iWindowNotifyFn nfn, void *sys )
500+
{
501+
mainw_cull();
502+
503+
nfn( sys, IWINDOW_YES );
504+
}
505+
508506
static void
509507
workspacegroupview_delete_cb( GtkWidget *wid, GtkWidget *host,
510508
Workspaceview *wview )
511509
{
512510
Workspace *ws = WORKSPACE( VOBJECT( wview )->iobject );
513511

514-
model_check_destroy( view_get_toplevel( VIEW( wview ) ), MODEL( ws ) );
512+
model_check_destroy( view_get_toplevel( VIEW( wview ) ),
513+
MODEL( ws ), workspacegroupview_delete_done_cb );
515514
}
516515

517516
static void

0 commit comments

Comments
 (0)