set_first_sel(): returns first selected element (if any)

This commit is contained in:
stefan schippers 2023-11-09 15:12:56 +01:00
parent 584f88fba1
commit 8231cd65db
3 changed files with 32 additions and 23 deletions

View File

@ -1760,25 +1760,8 @@ void edit_property(int x)
tclsetvar("preserve_unchanged_attrs", "0");
}
/* retrieve first selected element (if still selected)... */
if(xctx->first_sel.n >=0 && xctx->first_sel.type == ELEMENT &&
xctx->inst[xctx->first_sel.n].sel == SELECTED) {
type = ELEMENT;
for(j=0; j < xctx->lastsel; j++) {
if(xctx->sel_array[j].type == ELEMENT && xctx->sel_array[j].n == xctx->first_sel.n) {
break;
}
}
/* ... otherwise get first from sel_array[] list */
} else {
type = xctx->sel_array[0].type;
for(j=0; j < xctx->lastsel; j++) {
if(xctx->sel_array[j].type == ELEMENT) {
type = ELEMENT;
break;
}
}
}
j = set_first_sel(0, -2, 0);
type = xctx->sel_array[j].type;
switch(type)
{

View File

@ -725,17 +725,43 @@ void bbox(int what,double x1,double y1, double x2, double y2)
}
}
void set_first_sel(unsigned short type, int n, unsigned int col)
/* n = -1 : clear first selected info
* n = -2 : return first selected element if still selected, or get first from
* selected list. Id no elements selected return first selected item (j = 0)
* n >= 0 : store indicated element as first selected
*/
int set_first_sel(unsigned short type, int n, unsigned int col)
{
if(n == -1) { /* reset first_sel */
if(n == -2) {
int j;
/* retrieve first selected element (if still selected)... */
if(xctx->first_sel.n >=0 && xctx->first_sel.type == ELEMENT &&
xctx->inst[xctx->first_sel.n].sel == SELECTED) {
for(j=0; j < xctx->lastsel; j++) {
if(xctx->sel_array[j].type == ELEMENT && xctx->sel_array[j].n == xctx->first_sel.n) {
break;
}
}
/* ... otherwise get first from sel_array[] list */
} else {
for(j=0; j < xctx->lastsel; j++) {
if(xctx->sel_array[j].type == ELEMENT) {
break;
}
}
}
if(j >= xctx->lastsel) j = 0;
return j;
} else if(n == -1) { /* reset first_sel */
xctx->first_sel.type = 0;
xctx->first_sel.n = -1;
xctx->first_sel.col = 0;
}else if(xctx->first_sel.n == -1) {
} else if(xctx->first_sel.n == -1) {
xctx->first_sel.type = type;
xctx->first_sel.n = n;
xctx->first_sel.col = col;
}
return 0;
}
void unselect_all(int dr)

View File

@ -1331,7 +1331,7 @@ extern int text_bbox_nocairo(const char * str,double xscale, double yscale,
extern Selected select_object(double mx,double my, unsigned short sel_mode,
int override_lock); /* return type 20160503 */
extern void set_first_sel(unsigned short type, int n, unsigned int col);
extern int set_first_sel(unsigned short type, int n, unsigned int col);
extern void unselect_all(int dr);
extern void select_attached_nets(void);
extern void select_inside(double x1,double y1, double x2, double y2, int sel);