Le 15/07/12 22:35, Scott Kostyshak a écrit :
Attached is a patch that implements LFUN_BUFFER_FORALL, which applies a
passed LFUN command to all buffers. My motivation was that I sometimes
need to do the same thing in all of the buffers that I have open.
Another advantage of implementing this LFUN is that it allows
buffer-specific settings to be made global. For example, if a user wants
to be able to toggle track changes for all documents, he can do that
(similarly for read only).

This looks like a useful feature.

When a buffer-forall command is issued and the command passed to it is
disabled on one of the buffers, currently buffer-forall continues on to
the other buffers and tries to execute the passed command. I think this
is the correct behavior. Alternatively, buffer-forall could stop
whenever it finds a buffer where the command is disabled.

You current choice looks good.

buffer-forall allows for an optional flag, includehidden. If
includehidden is not specified, hidden buffers are ignored. If
includehidden is specified, the action is applied to the hidden buffers
and then they are hidden again. I might extend this option to allow for
onlyhidden, which would not apply the command to non-hidden buffers.
This would allow, e.g., to close all hidden buffers.

Any comments?

See below in the patch.

JMarc
+               case LFUN_BUFFER_FORALL: {
+                       Buffer * const buf = &currentBufferView()->buffer();
+                       if (!buf)
+                               break;

Why is this test needed? The current buffer has nothing to do with buffer-forall. Moreover, this code should not be in GuiView, but in GuiApplication, since the function is at application level.

+
+                       bool processHidden = false;
+                       string commandToRun = argument;
+                       if (argument.substr(0,13) == "includehidden") {
+                               processHidden = true;
+                               commandToRun = argument.substr(14, 
argument.size());
+                       }

Please do not use string methods by hand. FuncRequest object have methods getArg and getLongArg that work very well for these uses.

+
+                       docstring const hiddenOrNot = processHidden ? _("all hidden and 
non-hidden") : _("all non-hidden");
+                       dr.setMessage(bformat(_("Applied the command \"%1$s\" to 
%2$s buffers"), from_utf8(commandToRun), hiddenOrNot));

Please use two complete sentences (one for hidden and one for not hidden). Your sentences may be difficult to translate in some languages.

+
+                       Buffer * const last = theBufferList().last();
+                       Buffer * b = theBufferList().first();
+                       Buffer * nextBuf = 0;
+                       // We cannot use a for loop as the buffer list cycles.

I know this code is taken from somewhere else, but I am not sure why you can't use BufferList::begin()/end(). The only problem is maybe what happens if the buffer is deleted by the lfun.

+                       while (true) {
+                               if (b != last)
+                                       nextBuf = theBufferList().next(b); 
//get next now bc LFUN might close current
+
+                               bool const hidden = !(guiApp->currentView() && 
guiApp->currentView()->workArea(*b));
+                               if (hidden) {
+                                       if (processHidden) {
+                                               setBuffer(b);
+                                               
lyx::dispatch(FuncRequest(lyxaction.lookupFunc(commandToRun)));
+                                               GuiWorkArea * const wa = 
currentWorkArea();
+                                               wa->view().hideWorkArea(wa);
+                                       }
+                               }
+
+                               else {
+                                       setBuffer(b);
+                                       
lyx::dispatch(FuncRequest(lyxaction.lookupFunc(commandToRun)));
+                               }

if (!hidden || processHidden) {
        setBuffer(b);
        lyx::dispatch(FuncRequest(lyxaction.lookupFunc(commandToRun)));
        if (hidden) {
                GuiWorkArea * const wa = currentWorkArea();
                wa->view().hideWorkArea(wa);
        }
}

The lookup of commandToRun should be done at the place where the arguments are parsed.

Reply via email to