[Ipe-discuss] Execute command for several objects at once?
Tim Hutt
tdhutt at gmail.com
Mon May 9 16:08:51 CEST 2011
On 9 May 2011 14:26, elwood151 <elwood151 at web.de> wrote:
>
> I have another difficulty with IPE 7.0.13 on MacOS X:
>
> If I select several objects and then chose a command like "dotted line" or
> "send to layer xy", it is only changed for the first selected item but not
> the other ones.
Yes I have this problem too. It's annoying for changing the line style
(dashed/dotted).
I think the relevant code is in properties.lua:
function MODEL:propertiesPopup()
self:updateCloseSelection(true)
local prim = self:page():primarySelection() -- Here we only use the
primary selection; we need a list of all selections.
if not prim then
self.ui:explain("No selection")
return
end
local obj = self:page()[prim] -- Not sure? I guess obj is a
different type... (damn you weakly typed languages!)
local m = ipeui.Menu()
self["properties_" .. obj:type()](self, obj, m) -- Populate menu
according to primary object type (group, path, text, image, reference)
local gp = self.ui:globalPos()
local item, num, value = m:execute(gp.x, gp.y) -- Execute menu
if item then -- Process action.
if item == "layer" then
self:changeLayerOfPrimary(prim, value)
elseif item:sub(1,7) == "action_" then
self:action(item:sub(8))
elseif item == "comment" then
-- nothing to do
else
self:setAttributeOfPrimary(prim, item, value)
end
end
end
So I *think* could fix it. But the problem is that if you select a
text object it shows a different menu to if you select a line...
Should we merge all the possible menu options? I suppose the best we
would be to make sure that all selected objects are the same type....
but what should be done if they are not? An error message? Or just
ignore objects that aren't the same type as the primary selection?
That would probably be easiest...
Hmm, it could be changed to something like this: (Nb I know no Lua and
haven't tested this at all):
function MODEL:propertiesPopup()
self:updateCloseSelection(true)
local prim = self:page():primarySelection() -- Get primary selection
if not prim then
self.ui:explain("No selection")
return
end
local obj = self:page()[prim]
local secObjs = {} -- Secondary selected objects with the same type.
for i = 0, self:page():count()-1 do
if self:page():select(i) == ESecondarySelected and
self:page()[i]:type() == obj:type() then
secObjs.append(self:page()[i])
end
end
local m = ipeui.Menu()
self["properties_" .. obj:type()](self, obj, m) -- Populate menu
according to primary object type (group, path, text, image, reference)
local gp = self.ui:globalPos()
local item, num, value = m:execute(gp.x, gp.y) -- Execute menu
if item then -- Process action.
if item == "layer" then
self:changeLayerOfPrimary(prim, value)
for i in secObjs
self:changeLayerOfPrimary(i, value)
end
elseif item:sub(1,7) == "action_" then
self:action(item:sub(8)) -- And add the secObjs loop here
elseif item == "comment" then
-- nothing to do
else
self:setAttributeOfPrimary(prim, item, value) -- And here.
end
end
end
Obviously that won't run, and possibly the C++ code will have to be
changed (to make 'select()' available to lua).
More information about the Ipe-discuss
mailing list