Commit 79303141 authored by Claes Sjofors's avatar Claes Sjofors

wb: Default name for created objects in wtt fetched from name of previous sibling

parent 991cb749
......@@ -2816,6 +2816,49 @@ cdh_StringToObjectName (
return rs;
}
//! Create an similar objectname from another object name.
/*!
Converts an object name consisting of a number at the end of the name, The
number is incremented by 1 in the new name. If no number is found error status
is returned.
\param t Out string.
\param s In string.
\return Status.
*/
pwr_tStatus
cdh_NextObjectName (
char *t,
const char *s
)
{
int i;
int num;
int len = strlen(s);
char name[80];
for ( i = len - 1; i >= 0; i--) {
if ( isdigit( s[i]) == 0)
break;
}
if ( i == len - 1)
return CDH__NONAME;
strncpy( name, s, i+1);
sscanf( &s[i+1], "%d", &num);
num++;
if ( s[i+1] == '0')
sprintf( &name[i+1], "%0*d", len - i - 1, num);
else
sprintf( &name[i+1], "%d", num);
if ( strlen(name) > sizeof(pwr_tObjName) - 1)
return CDH__NAMELEN;
strcpy( t, name);
return CDH__SUCCESS;
}
/*@}*/
......
......@@ -1039,6 +1039,8 @@ int cdh_TypeToMaxStrSize( pwr_eType type, int attr_size, int attr_elements);
char *cdh_StringToObjectName( char *t, const char *s);
pwr_tStatus cdh_NextObjectName( char *t, const char *s);
/*@}*/
#ifdef __cplusplus
......
......@@ -1785,6 +1785,7 @@ int WNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
pwr_sAttrRef *sel_list;
int *sel_is_attr;
int sel_cnt;
pwr_tOid prev;
if ( wnav->get_global_select_cb)
(wnav->get_global_select_cb)( wnav->parent_ctx, &sel_list,
......@@ -1827,6 +1828,28 @@ int WNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
destcode);
if (EVEN(sts))
wnav->message(' ', wnav_get_message(sts));
// Get name from previous sibling
sts = ldh_GetPreviousSibling( wnav->ldhses, objid, &prev);
if ( ODD(sts)) {
pwr_tObjName name;
pwr_tCid prev_cid;
int size;
sts = ldh_GetObjectClass( wnav->ldhses, prev, &prev_cid);
if ( EVEN(sts)) break;
if ( prev_cid == classid) {
sts = ldh_ObjidToName( wnav->ldhses, prev, ldh_eName_Object, name, sizeof(name),
&size);
if ( EVEN(sts)) break;
sts = cdh_NextObjectName( name, name);
if ( ODD(sts))
sts = ldh_SetObjectName( wnav->ldhses, objid, name);
}
}
break;
default:
;
......
......@@ -1008,8 +1008,9 @@ void Wtt::activate_copy()
return;
}
if ( sel_cnt == 1)
if ( sel_cnt == 1) {
message( 'I', "Object copied");
}
else
message( 'I', "Objects copied");
......@@ -1095,6 +1096,42 @@ void Wtt::activate_paste()
else
sts = ldh_Paste( ldhses, sel_list2->Objid, ldh_eDest_After, 0, 0, 0);
reset_cursor();
if ( (sel_cnt1 == 1 && sel_is_attr1[0] == 0) ||
(sel_cnt2 == 1 && sel_is_attr2[0] == 0)) {
pwr_tOid oid;
pwr_tOid prev;
if ( sel_cnt1)
prev = sel_list1[0].Objid;
else
prev = sel_list2[0].Objid;
// Get name from previous sibling
sts = ldh_GetNextSibling( wnav->ldhses, prev, &oid);
if ( ODD(sts)) {
pwr_tObjName name;
pwr_tCid prev_cid, cid;
int size;
sts = ldh_GetObjectClass( wnav->ldhses, prev, &prev_cid);
if ( EVEN(sts)) return;
sts = ldh_GetObjectClass( wnav->ldhses, oid, &cid);
if ( EVEN(sts)) return;
if ( prev_cid == cid) {
sts = ldh_ObjidToName( wnav->ldhses, prev, ldh_eName_Object, name, sizeof(name),
&size);
if ( EVEN(sts)) return;
sts = cdh_NextObjectName( name, name);
if ( ODD(sts))
sts = ldh_SetObjectName( wnav->ldhses, oid, name);
}
}
}
if ( sel_cnt1 > 0)
free( (char *)sel_list1);
if ( sel_cnt2 > 0)
......@@ -1331,6 +1368,29 @@ void Wtt::activate_creaobj( ldh_eDest dest)
else
wnav->select_object( oid);
// Get name from previous sibling
pwr_tOid prev;
sts = ldh_GetPreviousSibling( wnav->ldhses, oid, &prev);
if ( ODD(sts)) {
pwr_tObjName name;
pwr_tCid prev_cid;
int size;
sts = ldh_GetObjectClass( wnav->ldhses, prev, &prev_cid);
if ( EVEN(sts)) return;
if ( prev_cid == cid) {
sts = ldh_ObjidToName( wnav->ldhses, prev, ldh_eName_Object, name, sizeof(name),
&size);
if ( EVEN(sts)) return;
sts = cdh_NextObjectName( name, name);
if ( ODD(sts))
sts = ldh_SetObjectName( wnav->ldhses, oid, name);
}
}
free( (char *)sel_list);
free( (char *)sel_is_attr);
}
......
......@@ -153,4 +153,6 @@
091102 cs ge Menu items for connections changed to radio items.
091103 cs xtt Translation and utf8 conversion of search condition in EventLog window fixed.
091104 cs glow Fixcolor added to arc properties.
091106 cs ge Different ways to show hot object added: linewith, light color, dark color.
\ No newline at end of file
091106 cs ge Different ways to show hot object added: linewith, light color, dark color.
091208 cs xtt New pixmap for weblink in helpwindow.
091208 cs xtt EventSelectList exended to 40 elements.
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment