The attached patch and two new files (app/select.h and app/select.c)
implement a new submenu on the display (right-button) menu, similar to the
Select menu in Gimp. It allows selecting all, none, invert, same type or
connected (one step transitive), and allows setting the selection mechanism
(currently only for drag-select) to either replace, union, intersection,
removal or inversal. These five ought to be radiomenuitems, but I haven't
found the proper docs on doing those. (There's also a Gnome menu
corresponding to the Toolbox items, but I haven't gotten that finished
yet, and there's a fix of a memory leak from drag select.)
-Lars
[My apologies if the charset is odd. Gnus is misbehaving.]
--
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause) | H�rdgrim of Numenor
"I do not agree with a word that you say, but I | Retainer of Sir Kegg
will defend to the death your right to say it." | of Westfield
--Evelyn Beatrice Hall paraphrasing Voltaire | Chaos Berserker of Khorne
===File ~/src/dia/lrclause.diff.gz.uue======================
begin 664 lrclause.diff.gz
M'XL("%V+KS@``VQR8VQA=7-E+F1I9F8`S5I[<]I($O\;/D4O6Y4#(PP(\`-O
MG/A!?-S:.&7C[-7M;JED-(#6LD1)PHEWB^]^W?-`@P0&UK[448E!,SV_Z>G7
MM*;G`]B3235B'AO$N^/\!_UQD._Z#OO6YFU7]@,;NA[;M1_S[U__R=^<W0+A
MM:$Z>(JJ(S]X9%7'M:NIR8RG?,CBT&5/KC^"$+\B-_"AOMMLYAUW.(3*%"KW
M4#F%2DB-H#-:J532S.?,6JU6K9E5LP:U9ML\:-=;.8Y6+I=?)-YK-^OMFIG_
M^!$JC::Q!V7\>P`?/^8A!_CQ[&<66K@$+QCMCN$WV>RXT02[=@>9%J(I\Q8E
M\'1#@C((O""T[)#9&I#6F%!ZKL^^NDX\3J@U-2)[H]!^1-W^SY4XGVJE"LW#
M)2HT#R%A4BEPWB(U4J^:^U`[;#=;[7HMQY&4^M*D6>7M[1V@WLKTM<?5!W!Q
MZ48Q[$1!&#/'\O#A2&L.0G>D&O,5@$GH^O&P6)!36:C-`;.F*.70$IIC3K'T
MFU\H'1$Y(;E#*")YY=BQ8_RKJ*Q!,/5C>/\>:B4B`Q1//`U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A$==7RIDV0WQAK+.&(6-SWUZXK0"J-=SUV)#J
MJE?='C_UYPK!+.T^^$85>]&$\4PTR&C2JIM&_1#YKC>-UJ%6I@UWXV"R`NTY
MC?9<.DK&W0<8M!YIZ,F_-QRJ!$++A?=*%.()=!E@)^3$Q;.AZSN6VBM=']4L
M!9Q2F+K88Z-/HAGPP0:\"Q.6U7QDS,)"T'E%9D(W#6X[EYVSOG73^7QY<M:!
M=^_TBNX6QO\WS?\UACQ3A:AUB^OV^IV;6_S5O>XML"S-<2&LJ4L6Y83LZQA3
M!BARC6DW&31!I:^T$*FZNZ*1Z;_E_0B^=C=:O6:*;ZG9`%(<RQLTF$&@X17U
M3C%^@8G9*HZD14HPG^IK_!*.-EH;*ZGUR8[>0JNO%K=.J-@0<R^5;6K$=D)0
M5Y?0>1?$KAFINJCS\N(@]]*:,H;SDB-?77_I9`UF&VM+7^J8[U'^8MJW0IR:
MJ8G%K_/.+YV;/G(,_P\L`V=Y%=S+=I19..F5)Q&;KX/NFVP]&XZBG6.EZ:8-
==Y9L2KH%+QIZND?M4MK6HL#XPW\!C/LW@'TN````
`
end
============================================================
===File ~/src/dia/app/select.c==============================
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* select.c -- callbacks to implement the Select menu */
#include <assert.h>
#include "select.h"
#include "menu.h"
#include "intl.h"
enum SelectionStyle selection_style = SELECT_REPLACE;
void
select_all_callback(GtkWidget *widget, gpointer data) {
Diagram *dia;
GList *objects;
dia = ddisplay_active()->diagram;
objects = dia->data->active_layer->objects;
while (objects != NULL) {
Object *obj = (Object *)objects->data;
if (!diagram_is_selected(dia, obj))
diagram_select(dia, obj);
objects = g_list_next(objects);
}
diagram_update_menu_sensitivity(dia);
object_add_updates_list(dia->data->selected, dia);
diagram_flush(dia);
}
void
select_none_callback(GtkWidget *widget, gpointer data) {
Diagram * dia = ddisplay_active()->diagram;
diagram_remove_all_selected(dia, TRUE);
diagram_update_menu_sensitivity(dia);
object_add_updates_list(dia->data->selected, dia);
diagram_flush(dia);
}
void
select_invert_callback(GtkWidget *widget, gpointer data) {
Diagram *dia;
GList *objects, *tmp;
dia = ddisplay_active()->diagram;
tmp = dia->data->active_layer->objects;
for (; tmp != NULL; tmp = g_list_next(tmp)) {
Object *obj = (Object *)tmp->data;
if (!diagram_is_selected(dia, obj))
diagram_select(dia, obj);
else
diagram_unselect_object(dia, obj);
}
diagram_update_menu_sensitivity(dia);
object_add_updates_list(dia->data->selected, dia);
diagram_flush(dia);
}
void
select_connected_callback(GtkWidget *widget, gpointer data) {
Diagram *dia = ddisplay_active()->diagram;
GList *objects, *tmp;
objects = dia->data->selected;
for (tmp = objects; tmp != NULL; tmp = g_list_next(tmp)) {
Object *obj = (Object *)tmp->data;
int i;
for (i = 0; i < obj->num_handles; i++) {
Handle *handle = obj->handles[i];
if (handle->connected_to != NULL) {
if (!diagram_is_selected(dia, handle->connected_to->object)) {
diagram_select(dia, handle->connected_to->object);
}
}
}
}
for (tmp = objects; tmp != NULL; tmp = tmp->next) {
Object *obj = (Object *)tmp->data;
int i;
for (i = 0; i < obj->num_connections; i++) {
ConnectionPoint *connection = obj->connections[i];
GList *conns = connection->connected;
for (; conns != NULL; conns = g_list_next(conns)) {
Object *obj2 = (Object *)conns->data;
if (!diagram_is_selected(dia, obj2)) {
diagram_select(dia, obj2);
}
}
}
}
diagram_update_menu_sensitivity(dia);
object_add_updates_list(dia->data->selected, dia);
diagram_flush(dia);
}
void
select_same_type_callback(GtkWidget *widget, gpointer data) {
/* For now, do a brute force version: Check vs. all earlier selected.
Later, we should really sort the selecteds first to avoid n^2 */
Diagram *dia;
GList *objects, *tmp, *tmp2;
dia = ddisplay_active()->diagram;
tmp = dia->data->active_layer->objects;
objects = dia->data->selected;
for (; tmp != NULL; tmp = g_list_next(tmp)) {
Object *obj = (Object *)tmp->data;
if (!diagram_is_selected(dia, obj)) {
for (tmp2 = objects; tmp2 != NULL; tmp2 = g_list_next(tmp2)) {
Object *obj2 = (Object *)tmp2->data;
if (obj->type == obj2->type) {
diagram_select(dia, obj);
break;
}
}
}
}
diagram_update_menu_sensitivity(dia);
object_add_updates_list(dia->data->selected, dia);
diagram_flush(dia);
}
void
select_style_callback(GtkWidget *widget, gpointer data) {
static GtkCheckMenuItem *replace_item;
static GtkCheckMenuItem *union_item;
static GtkCheckMenuItem *intersect_item;
static GtkCheckMenuItem *remove_item;
static GtkCheckMenuItem *invert_item;
static GString *path;
static int initialized = 0;
char *display = "<Display>";
selection_style = (int)data;
if (initialized == 0) {
# ifdef GNOME
if (ddisplay_active () == NULL) return;
# endif
/* Now do the radio button thing */
path = g_string_new ("<Display>");
g_string_append (path,_("/Select/Replace"));
replace_item = (GtkCheckMenuItem *)menus_get_item_from_path(path->str);
g_string_append (g_string_assign(path, display),_("/Select/Union"));
union_item = (GtkCheckMenuItem *)menus_get_item_from_path(path->str);
g_string_append (g_string_assign(path, display),_("/Select/Intersect"));
intersect_item = (GtkCheckMenuItem *)menus_get_item_from_path(path->str);
g_string_append (g_string_assign(path, display),_("/Select/Remove"));
remove_item = (GtkCheckMenuItem *)menus_get_item_from_path(path->str);
g_string_append (g_string_assign(path, display),_("/Select/Invert"));
invert_item = (GtkCheckMenuItem *)menus_get_item_from_path(path->str);
g_string_free(path, FALSE);
initialized = 1;
}
/* Ok, this should really be done with a radiomenu, but I don't have
any docs on that */
if ((selection_style == SELECT_REPLACE)^(replace_item->active))
gtk_check_menu_item_toggled(replace_item);
if ((selection_style == SELECT_UNION)^(union_item->active))
gtk_check_menu_item_toggled(union_item);
if ((selection_style == SELECT_INTERSECTION)^(intersect_item->active))
gtk_check_menu_item_toggled(intersect_item);
if ((selection_style == SELECT_REMOVE)^(remove_item->active))
gtk_check_menu_item_toggled(remove_item);
if ((selection_style == SELECT_INVERT)^(invert_item->active))
gtk_check_menu_item_toggled(invert_item);
}
============================================================
===File ~/src/dia/app/select.h==============================
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef SELECT_H
#define SELECT_H
#include "diagram.h"
#include "display.h"
enum SelectionStyle {SELECT_REPLACE, SELECT_UNION,
SELECT_INTERSECTION, SELECT_REMOVE, SELECT_INVERT};
extern enum SelectionStyle selection_style;
void select_all_callback(GtkWidget *widget, gpointer data);
void select_none_callback(GtkWidget *widget, gpointer data);
void select_invert_callback(GtkWidget *widget, gpointer data);
void select_connected_callback(GtkWidget *widget, gpointer data);
void select_same_type_callback(GtkWidget *widget, gpointer data);
void select_style_callback(GtkWidget *widget, gpointer data);
#endif
============================================================