RE: [PATCH] LFUN_BUFFER_FORALL

2012-07-17 Thread Scott Kostyshak
From: Jean-Marc Lasgouttes [lasgout...@lyx.org]
Sent: Sunday, July 15, 2012 5:14 PM

Moreover, this code should not be in GuiView, but in
GuiApplication, since the function is at application level.

Attached is my attempt to move the code to GuiApplication. I am having trouble 
instantiating a GuiWorkArea. Here are the errors I get:

GuiApplication.cpp: In member function ‘virtual void 
lyx::frontend::GuiApplication::dispatch(const lyx::FuncRequest, 
lyx::DispatchResult)’:
GuiApplication.cpp:1633:8: error: invalid use of incomplete type ‘class 
lyx::frontend::GuiWorkArea’
In file included from GuiApplication.cpp:15:0:
GuiApplication.h:41:7: error: forward declaration of ‘class 
lyx::frontend::GuiWorkArea’

I think that this patch also addresses the other points you raised.

Thanks,

Scottdiff --git a/src/FuncCode.h b/src/FuncCode.h
index 9a7b06e..2c99432 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -452,6 +452,7 @@ enum FuncCode
 	// 350
 	LFUN_CLIPBOARD_PASTE_SIMPLE,	// tommaso, 20111028
 	LFUN_IPA_INSERT,// spitz, 20120305
+	LFUN_BUFFER_FORALL, // scottkostyshak, 20120715
 
 	LFUN_LASTACTION // end of the table
 };
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 39018ce..ff3f7fe 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3127,6 +3127,26 @@ void LyXAction::init()
  */
 		{ LFUN_BUFFER_WRITE_AS, buffer-write-as, ReadOnly, Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_FORALL
+ * \li Action: Applies a command to all visible, hidden, or both types of buffers.
+ * \li Syntax: buffer-forall [BUFFER-TYPE] LFUN-COMMAND
+ * \li Params: BUFFER-TYPE: visible|hidden|both default: default: visible   
+   LFUN-COMMAND: The command that is to be applied to the buffers.
+ * \li Sample: Close all Notes in all visible documents: \n
+	   buffer-forall inset-forall Note inset-toggle close \n
+   Toggle change tracking on all documents: \n
+	   buffer-forall both changes-track \n
+   Toggle read-only for all visible documents: \n
+	   buffer-forall buffer-toggle-read-only \n
+   Show statistics for each document: \n
+	   buffer-forall both statistics \n
+   Activate the branch named Solutions in all visible documents: \n
+	   buffer-forall branch-activate Solutions \n
+ * \li Origin: scottkostyshak, 15 Jul 2012
+ * \endvar
+ */
+		{ LFUN_BUFFER_FORALL, buffer-forall, ReadOnly | Argument, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_WRITE_ALL
  * \li Action: Save all changed documents.
  * \li Syntax: buffer-write-all
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index b855067..fe37b81 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -1074,6 +1074,7 @@ bool GuiApplication::getStatus(FuncRequest const  cmd, FuncStatus  flag) const
 	case LFUN_RECONFIGURE:
 	case LFUN_SERVER_GET_FILENAME:
 	case LFUN_SERVER_NOTIFY:
+	case LFUN_BUFFER_FORALL:
 		enable = true;
 		break;
 
@@ -1592,6 +1593,64 @@ void GuiApplication::dispatch(FuncRequest const  cmd, DispatchResult  dr)
 		break;
 	}
 
+	case LFUN_BUFFER_FORALL: {
+		GuiView * cv = currentView();
+		Buffer * const buf = cv-currentBufferView()-buffer();
+
+		bool processVisible = true;
+		bool processHidden = false;
+		docstring msg = _(Applied the following command to all visible buffers: );
+		string commandToRun = argument;
+		if (cmd.getArg(0) == both) {
+			processHidden = true;
+			msg = _(Applied the following command to all visible and hidden buffers: );
+			commandToRun = cmd.getLongArg(1);
+		} else if (cmd.getArg(0) == visible) {
+			commandToRun = cmd.getLongArg(1);
+		} else if (cmd.getArg(0) == hidden) {
+			processHidden = true;
+			processVisible = false;
+			commandToRun = cmd.getLongArg(1);
+			msg = _(Applied the following command to all hidden buffers: );
+		}
+		FuncRequest FuncToRun = lyxaction.lookupFunc(commandToRun);
+		dr.setMessage(bformat(_(%1$s%2$s), msg, from_utf8(commandToRun)));
+
+		Buffer * const last = theBufferList().last();
+		Buffer * b = theBufferList().first();
+		Buffer * nextBuf = 0;
+		// We cannot use a for loop as the buffer list cycles.
+		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) {
+	cv-setBuffer(b);
+	lyx::dispatch(FuncToRun);
+	GuiWorkArea * const wa = cv-currentWorkArea();
+	wa-view().hideWorkArea(wa);
+}
+			}
+
+			else {
+if (processVisible) {
+	cv-setBuffer(b);
+	lyx::dispatch(FuncToRun);
+}
+			}
+
+			if (b == last)
+break;
+			b = nextBuf;
+		}
+
+		if (theBufferList().isLoaded(buf)) //the LFUN might have closed buf
+			cv-setBuffer(buf);
+		break;
+	}
+
 	case LFUN_COMMAND_ALTERNATIVES: {
 		// 

problematic copier for JPEG figures?

2012-07-17 Thread Yihui Xie
Hi,

I'm not sure anyone else can reproduce this weird behavior under LyX
2.0.4 (Ubuntu): the tex code for jpeg figures seems to be wrong.
Suppose the jpeg file is foo.jpg; in the tex code exported from LyX it
will become this:

\includegraphics{\string0_path_to_foo\string.jpg, jpeg}

pdflatex will write the text jpeg jpeg before the figure in the PDF
output. It turns out that LyX copied foo.jpg to the temp dir as
0_path_to_foo.jpg, jpeg. I do not understand why this happens. PNG
figures are fine.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


RE: [PATCH] LFUN_BUFFER_FORALL

2012-07-17 Thread Scott Kostyshak
From: Jean-Marc Lasgouttes [lasgout...@lyx.org]
Sent: Sunday, July 15, 2012 5:14 PM

>Moreover, this code should not be in GuiView, but in
>GuiApplication, since the function is at application level.

Attached is my attempt to move the code to GuiApplication. I am having trouble 
instantiating a GuiWorkArea. Here are the errors I get:

GuiApplication.cpp: In member function ‘virtual void 
lyx::frontend::GuiApplication::dispatch(const lyx::FuncRequest&, 
lyx::DispatchResult&)’:
GuiApplication.cpp:1633:8: error: invalid use of incomplete type ‘class 
lyx::frontend::GuiWorkArea’
In file included from GuiApplication.cpp:15:0:
GuiApplication.h:41:7: error: forward declaration of ‘class 
lyx::frontend::GuiWorkArea’

I think that this patch also addresses the other points you raised.

Thanks,

Scottdiff --git a/src/FuncCode.h b/src/FuncCode.h
index 9a7b06e..2c99432 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -452,6 +452,7 @@ enum FuncCode
 	// 350
 	LFUN_CLIPBOARD_PASTE_SIMPLE,	// tommaso, 20111028
 	LFUN_IPA_INSERT,// spitz, 20120305
+	LFUN_BUFFER_FORALL, // scottkostyshak, 20120715
 
 	LFUN_LASTACTION // end of the table
 };
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 39018ce..ff3f7fe 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3127,6 +3127,26 @@ void LyXAction::init()
  */
 		{ LFUN_BUFFER_WRITE_AS, "buffer-write-as", ReadOnly, Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_FORALL
+ * \li Action: Applies a command to all visible, hidden, or both types of buffers.
+ * \li Syntax: buffer-forall [] 
+ * \li Params: :  default: visible   
+   : The command that is to be applied to the buffers.
+ * \li Sample: Close all Notes in all visible documents: \n
+	   buffer-forall inset-forall Note inset-toggle close \n
+   Toggle change tracking on all documents: \n
+	   buffer-forall both changes-track \n
+   Toggle read-only for all visible documents: \n
+	   buffer-forall buffer-toggle-read-only \n
+   Show statistics for each document: \n
+	   buffer-forall both statistics \n
+   Activate the branch named "Solutions" in all visible documents: \n
+	   buffer-forall branch-activate Solutions \n
+ * \li Origin: scottkostyshak, 15 Jul 2012
+ * \endvar
+ */
+		{ LFUN_BUFFER_FORALL, "buffer-forall", ReadOnly | Argument, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_WRITE_ALL
  * \li Action: Save all changed documents.
  * \li Syntax: buffer-write-all
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index b855067..fe37b81 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -1074,6 +1074,7 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
 	case LFUN_RECONFIGURE:
 	case LFUN_SERVER_GET_FILENAME:
 	case LFUN_SERVER_NOTIFY:
+	case LFUN_BUFFER_FORALL:
 		enable = true;
 		break;
 
@@ -1592,6 +1593,64 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		break;
 	}
 
+	case LFUN_BUFFER_FORALL: {
+		GuiView * cv = currentView();
+		Buffer * const buf = >currentBufferView()->buffer();
+
+		bool processVisible = true;
+		bool processHidden = false;
+		docstring msg = _("Applied the following command to all visible buffers: ");
+		string commandToRun = argument;
+		if (cmd.getArg(0) == "both") {
+			processHidden = true;
+			msg = _("Applied the following command to all visible and hidden buffers: ");
+			commandToRun = cmd.getLongArg(1);
+		} else if (cmd.getArg(0) == "visible") {
+			commandToRun = cmd.getLongArg(1);
+		} else if (cmd.getArg(0) == "hidden") {
+			processHidden = true;
+			processVisible = false;
+			commandToRun = cmd.getLongArg(1);
+			msg = _("Applied the following command to all hidden buffers: ");
+		}
+		FuncRequest FuncToRun = lyxaction.lookupFunc(commandToRun);
+		dr.setMessage(bformat(_("%1$s%2$s"), msg, from_utf8(commandToRun)));
+
+		Buffer * const last = theBufferList().last();
+		Buffer * b = theBufferList().first();
+		Buffer * nextBuf = 0;
+		// We cannot use a for loop as the buffer list cycles.
+		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) {
+	cv->setBuffer(b);
+	lyx::dispatch(FuncToRun);
+	GuiWorkArea * const wa = cv->currentWorkArea();
+	wa->view().hideWorkArea(wa);
+}
+			}
+
+			else {
+if (processVisible) {
+	cv->setBuffer(b);
+	lyx::dispatch(FuncToRun);
+}
+			}
+
+			if (b == last)
+break;
+			b = nextBuf;
+		}
+
+		if (theBufferList().isLoaded(buf)) //the LFUN might have closed buf
+			cv->setBuffer(buf);
+		break;
+	}
+
 	case LFUN_COMMAND_ALTERNATIVES: {
 		// 

problematic copier for JPEG figures?

2012-07-17 Thread Yihui Xie
Hi,

I'm not sure anyone else can reproduce this weird behavior under LyX
2.0.4 (Ubuntu): the tex code for jpeg figures seems to be wrong.
Suppose the jpeg file is foo.jpg; in the tex code exported from LyX it
will become this:

\includegraphics{\string"0_path_to_foo\string".jpg, jpeg}

pdflatex will write the text "jpeg jpeg" before the figure in the PDF
output. It turns out that LyX copied foo.jpg to the temp dir as
"0_path_to_foo.jpg, jpeg". I do not understand why this happens. PNG
figures are fine.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA