Skip to content

Commit 0816a31

Browse files
committed
new rename on duplicate system
1 parent bbc601d commit 0816a31

13 files changed

+243
-130
lines changed

TODO

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
- need a tooltip on tabs showing the caption
1+
- workspacegroup_top_load() has to do three types of renaming:
22

3-
needs a ->label on workspaceview
3+
case WORKSPACEGROUP_LOAD_NEW:
44

5-
also for rename tab
5+
rename workspaces, but nothing else
6+
7+
case WORKSPACEGROUP_LOAD_COLUMNS:
8+
9+
rename
10+
11+
12+
13+
14+
- rmb duplicate tab, name does not change
15+
16+
we rename the symbol (we get Workspaces.tab2), but the ->name on the WS is
17+
not changed
618

719
- how odd, in workspacegroup_load_new() we do:
820

src/columnview.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ columnview_clone_cb( GtkWidget *wid, GtkWidget *host, Columnview *cview )
7272
{
7373
Column *col = COLUMN( VOBJECT( cview )->iobject );
7474
Workspace *ws = col->ws;
75-
char *newname = workspace_column_name_new( ws, NULL );
76-
Column *newcol = workspace_column_get( ws, newname );
7775

78-
IM_FREE( newname );
76+
char new_name[MAX_STRSIZE];
77+
Column *newcol;
78+
79+
workspace_column_name_new( ws, new_name );
80+
newcol = workspace_column_get( ws, new_name );
7981
iobject_set( IOBJECT( newcol ), NULL, IOBJECT( col )->caption );
8082
newcol->x = col->x + 30;
8183
newcol->y = col->y + 30;

src/mainw.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,15 +1148,12 @@ mainw_column_new_action_cb( GtkAction *action, Mainw *mainw )
11481148
Workspace *ws;
11491149

11501150
if( (ws = mainw_get_workspace( mainw )) ) {
1151-
char *name;
1151+
char new_name[MAX_STRSIZE];
11521152
Column *col;
11531153

1154-
name = workspace_column_name_new( ws, NULL );
1155-
if( !(col = column_new( ws, name )) )
1156-
iwindow_alert( GTK_WIDGET( mainw ), GTK_MESSAGE_ERROR );
1157-
else
1158-
workspace_column_select( ws, col );
1159-
IM_FREE( name );
1154+
workspace_column_name_new( ws, new_name );
1155+
col = workspace_column_get( ws, new_name );
1156+
workspace_column_select( ws, col );
11601157
}
11611158
}
11621159

@@ -1207,16 +1204,16 @@ static void
12071204
mainw_column_new_named_action_cb( GtkAction *action, Mainw *mainw )
12081205
{
12091206
GtkWidget *ss = stringset_new();
1210-
char *name;
1207+
char new_name[MAX_STRSIZE];
12111208
Workspace *ws;
12121209

12131210
if( !(ws = mainw_get_workspace( mainw )) )
12141211
return;
12151212

1216-
name = workspace_column_name_new( ws, NULL );
1213+
workspace_column_name_new( ws, new_name );
12171214

12181215
stringset_child_new( STRINGSET( ss ),
1219-
_( "Name" ), name, _( "Set column name here" ) );
1216+
_( "Name" ), new_name, _( "Set column name here" ) );
12201217
stringset_child_new( STRINGSET( ss ),
12211218
_( "Caption" ), "", _( "Set column caption here" ) );
12221219

@@ -1229,8 +1226,6 @@ mainw_column_new_named_action_cb( GtkAction *action, Mainw *mainw )
12291226
iwindow_build( IWINDOW( ss ) );
12301227

12311228
gtk_widget_show( ss );
1232-
1233-
IM_FREE( name );
12341229
}
12351230

12361231
/* Callback from program.

src/model.c

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ModelLoadState *model_loadstate = NULL;
6868
/* Rename list functions.
6969
*/
7070
static void *
71-
model_loadstate_rename_destroy( ModelRename *rename )
71+
model_rename_destroy( ModelRename *rename )
7272
{
7373
IM_FREE( rename->old_name );
7474
IM_FREE( rename->new_name );
@@ -77,9 +77,8 @@ model_loadstate_rename_destroy( ModelRename *rename )
7777
return( NULL );
7878
}
7979

80-
ModelRename *
81-
model_loadstate_rename_new( ModelLoadState *state,
82-
const char *old_name, const char *new_name )
80+
static ModelRename *
81+
model_rename_new( const char *old_name, const char *new_name )
8382
{
8483
ModelRename *rename;
8584

@@ -88,15 +87,67 @@ model_loadstate_rename_new( ModelLoadState *state,
8887
rename->old_name = im_strdup( NULL, old_name );
8988
rename->new_name = im_strdup( NULL, new_name );
9089
if( !rename->old_name || !rename->new_name ) {
91-
model_loadstate_rename_destroy( rename );
90+
model_rename_destroy( rename );
9291
return( NULL );
9392
}
9493

94+
return( rename );
95+
}
96+
97+
static void *
98+
model_loadstate_taken_sub( ModelRename *rename, const char *name )
99+
{
100+
if( strcmp( rename->new_name, name ) == 0 )
101+
return( rename );
102+
103+
return( NULL );
104+
}
105+
106+
/* Is something already being renamed to @name.
107+
*/
108+
gboolean
109+
model_loadstate_taken( ModelLoadState *state, const char *name )
110+
{
111+
return( !!slist_map( state->renames,
112+
(SListMapFn) model_loadstate_taken_sub, (char *) name ) );
113+
}
114+
115+
ModelRename *
116+
model_loadstate_rename_new( ModelLoadState *state,
117+
const char *old_name, const char *new_name )
118+
{
119+
ModelRename *rename;
120+
121+
if( !(rename = model_rename_new( old_name, new_name )) )
122+
return( NULL );
95123
state->renames = g_slist_prepend( state->renames, rename );
96124

97125
return( rename );
98126
}
99127

128+
ModelRename *
129+
model_loadstate_column_rename_new( ModelLoadState *state,
130+
const char *old_name, const char *new_name )
131+
{
132+
ModelRename *rename;
133+
134+
if( !(rename = model_rename_new( old_name, new_name )) )
135+
return( NULL );
136+
state->column_renames =
137+
g_slist_prepend( state->column_renames, rename );
138+
139+
return( rename );
140+
}
141+
142+
/* Is something already being renamed to @name.
143+
*/
144+
gboolean
145+
model_loadstate_column_taken( ModelLoadState *state, const char *name )
146+
{
147+
return( !!slist_map( state->column_renames,
148+
(SListMapFn) model_loadstate_taken_sub, (char *) name ) );
149+
}
150+
100151
void
101152
model_loadstate_destroy( ModelLoadState *state )
102153
{
@@ -108,7 +159,9 @@ model_loadstate_destroy( ModelLoadState *state )
108159
IM_FREE( state->filename_user );
109160
IM_FREEF( xmlFreeDoc, state->xdoc );
110161
slist_map( state->renames,
111-
(SListMapFn) model_loadstate_rename_destroy, NULL );
162+
(SListMapFn) model_rename_destroy, NULL );
163+
slist_map( state->column_renames,
164+
(SListMapFn) model_rename_destroy, NULL );
112165
g_slist_free( state->renames );
113166

114167
if( state->old_dir ) {
@@ -150,6 +203,7 @@ model_loadstate_new( const char *filename, const char *filename_user )
150203
return( NULL );
151204
state->xdoc = NULL;
152205
state->renames = NULL;
206+
state->column_renames = NULL;
153207
state->major = MAJOR_VERSION;
154208
state->minor = MINOR_VERSION;
155209
state->micro = MICRO_VERSION;

src/model.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ typedef struct _ModelLoadState {
5555
FIXME ... a linked list? try a hash sometime
5656
see model_loadstate_rewrite_name()
5757
58-
would probably only see a speedup for merging large
58+
would probably only see a speedup for merging very large
5959
workspaces, not something we do often
6060
6161
*/
6262
GSList *renames; /* Rename table for this load context */
6363

64+
/* The column renames we have planned. Don't rewrite exprs with these.
65+
*/
66+
GSList *column_renames;
67+
6468
/* Version info we read from this XML file.
6569
*/
6670
int major;
@@ -176,8 +180,13 @@ typedef struct _ModelClass {
176180

177181
extern ModelLoadState *model_loadstate;
178182

183+
gboolean model_loadstate_taken( ModelLoadState *state, const char *name );
179184
ModelRename *model_loadstate_rename_new( ModelLoadState *state,
180185
const char *old_name, const char *new_name );
186+
gboolean model_loadstate_column_taken( ModelLoadState *state,
187+
const char *name );
188+
ModelRename *model_loadstate_column_rename_new( ModelLoadState *state,
189+
const char *old_name, const char *new_name );
181190
ModelLoadState *model_loadstate_new(
182191
const char *filename, const char *filename_user );
183192
ModelLoadState *model_loadstate_new_openfile( iOpenFile *of );

src/symbol.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,37 @@ symbol_new( Compile *compile, const char *name )
711711
return( sym );
712712
}
713713

714+
gboolean
715+
symbol_rename( Symbol *sym, const char *new_name )
716+
{
717+
Compile *compile = COMPILE( ICONTAINER( sym )->parent );
718+
Symbol *old_sym;
719+
720+
if( strcmp( IOBJECT( sym )->name, new_name ) == 0 )
721+
return( TRUE );
722+
723+
if( (old_sym = compile_lookup( compile, new_name )) ) {
724+
error_top( "%s", _( "Name in use." ) );
725+
error_sub( _( "Can't rename %s \"%s\" as \"%s\". "
726+
"The name is already in use." ),
727+
decode_SymbolType_user( sym->type ),
728+
IOBJECT( sym )->name,
729+
new_name );
730+
return( FALSE );
731+
}
732+
733+
g_object_ref( sym );
734+
735+
icontainer_child_remove( ICONTAINER( sym ) );
736+
iobject_set( IOBJECT( sym ), new_name, NULL );
737+
icontainer_child_add( ICONTAINER( compile ), ICONTAINER( sym ),
738+
ICONTAINER( sym )->pos );
739+
740+
g_object_unref( sym );
741+
742+
return( TRUE );
743+
}
744+
714745
void
715746
symbol_error_redefine( Symbol *sym )
716747
{

src/symbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void *symbol_patch_add( void **pnt, Symbol *sym );
160160
Symbol *symbol_root_init( void );
161161

162162
Symbol *symbol_new( Compile *compile, const char *name );
163+
gboolean symbol_rename( Symbol *sym, const char *new_name );
163164
void symbol_error_redefine( Symbol *sym );
164165
Symbol *symbol_new_defining( Compile *compile, const char *name );
165166
Symbol *symbol_new_reference( Compile *compile, const char *name );

src/workspace.c

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -325,40 +325,14 @@ workspace_column_get( Workspace *ws, const char *name )
325325
return( column_new( ws, name ) );
326326
}
327327

328-
/* Make up a new column name. Check for not already in workspace, and not in
329-
* xml file (if columns non-NULL).
328+
/* Make up a new column name. Check for not already in workspace.
330329
*/
331-
char *
332-
workspace_column_name_new( Workspace *ws, xmlNode *columns )
330+
void
331+
workspace_column_name_new( Workspace *ws, char *name )
333332
{
334-
char buf[256];
335-
336-
/* Search for one not in use.
337-
*/
338-
for(;;) {
339-
number_to_string( ws->next++, buf );
340-
341-
if( workspace_column_find( ws, buf ) )
342-
continue;
343-
if( columns ) {
344-
xmlNode *i;
345-
346-
for( i = columns; i; i = i->next ) {
347-
char name[MAX_STRSIZE];
348-
349-
if( strcmp( (char *) i->name, "Column" ) == 0 &&
350-
get_sprop( i, "name",
351-
name, MAX_STRSIZE ) )
352-
if( strcmp( name, buf ) == 0 )
353-
break;
354-
}
355-
356-
if( i )
357-
continue;
358-
}
359-
360-
return( im_strdup( NULL, buf ) );
361-
}
333+
do {
334+
number_to_string( ws->next++, name );
335+
} while( workspace_column_find( ws, name ) );
362336
}
363337

364338
/* Make sure we have a column selected ... pick one of the existing columns; if
@@ -417,17 +391,13 @@ workspace_column_select( Workspace *ws, Column *col )
417391
gboolean
418392
workspace_column_new( Workspace *ws )
419393
{
420-
char *name;
394+
char new_name[MAX_STRSIZE];
421395
Column *col;
422396

423-
name = workspace_column_name_new( ws, NULL );
424-
if( !(col = column_new( ws, name )) ) {
397+
workspace_column_name_new( ws, new_name );
398+
if( !(col = column_new( ws, new_name )) )
425399
return( FALSE );
426-
IM_FREE( name );
427-
}
428-
429400
workspace_column_select( ws, col );
430-
IM_FREE( name );
431401

432402
return( TRUE );
433403
}
@@ -656,8 +626,8 @@ workspace_link( Workspace *ws, Workspacegroup *wsg, const char *name )
656626
Symbol *sym;
657627

658628
#ifdef DEBUG
659-
printf( "workspace_link: naming ws as %s\n", name );
660629
#endif /*DEBUG*/
630+
printf( "workspace_link: naming ws %p as %s\n", ws, name );
661631

662632
sym = symbol_new_defining( wsr->sym->expr->compile, name );
663633

@@ -1727,17 +1697,20 @@ workspace_rename( Workspace *ws, const char *name, const char *caption )
17271697
{
17281698
Workspacegroup *wsg = workspace_get_workspacegroup( ws );
17291699

1730-
/* Don't prevent rename if the new name is the same as the old.
1731-
*/
1732-
if( strcmp( IOBJECT( ws )->name, name ) != 0 &&
1733-
compile_lookup( wsg->wsr->sym->expr->compile, name ) ) {
1734-
error_top( _( "Tab exists." ) );
1735-
error_sub( _( "A tab called \"%s\" already exists. "
1736-
"Pick another name." ), name );
1700+
if( !symbol_rename( ws->sym, name ) )
17371701
return( FALSE );
1738-
}
17391702

1740-
iobject_set( IOBJECT( ws ), name, caption );
1703+
g_object_ref( ws );
1704+
1705+
icontainer_child_remove( ICONTAINER( ws ) );
1706+
iobject_set( IOBJECT( ws ), IOBJECT( ws->sym )->name, caption );
1707+
icontainer_child_add( ICONTAINER( wsg ), ICONTAINER( ws ),
1708+
ICONTAINER( ws )->pos );
1709+
1710+
g_object_unref( ws );
1711+
1712+
// do we need this? unclear
1713+
//iobject_changed( IOBJECT( wsg ) );
17411714

17421715
return( TRUE );
17431716
}

src/workspace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Column *workspace_is_one_empty( Workspace *ws );
137137

138138
Column *workspace_column_find( Workspace *ws, const char *name );
139139
Column *workspace_column_get( Workspace *ws, const char *name );
140-
char *workspace_column_name_new( Workspace *ws, xmlNode *columns );
140+
void workspace_column_name_new( Workspace *ws, char *name );
141141
Column *workspace_column_pick( Workspace *ws );
142142
void workspace_column_select( Workspace *ws, Column *col );
143143
gboolean workspace_column_new( Workspace *ws );

0 commit comments

Comments
 (0)