Am Donnerstag, 27. Februar 2003 08:35 schrieb Andre Poenitz:
> So be happy and send the patch.

Sorry for the delay, I have been too busy. Here is the patch, reworked 
against todays CVS. A few remarks:

- A simple shell script lyxedit is called for editing a file. This shell 
script decides what editor to use, based on the file extension. This was ok 
for me, but is probably not for general use. I first tried to overtake the 
external_templates stuff, but this was too complicated. I think another 
alternative would be to create something like
\editor "png" "gimp $$f"
in preferences.

- The position and labeling of the "edit" button of the dialog can probably 
be done better.


Georg

Attachment: lyxedit
Description: application/shellscript

Index: src/frontends/controllers/ControlGraphics.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlGraphics.C,v
retrieving revision 1.60
diff -u -3 -p -r1.60 ControlGraphics.C
--- src/frontends/controllers/ControlGraphics.C	2003/02/28 09:49:46	1.60
+++ src/frontends/controllers/ControlGraphics.C	2003/03/01 15:25:02
@@ -93,6 +93,17 @@ string const ControlGraphics::Browse(str
 }
 
 
+// Taken from the external material inset
+void ControlGraphics::editGraphics()
+{
+	// fill the local, controller's copy of the Params struct with
+	// the contents of the dialog's fields.
+	view().apply();
+
+	inset()->editGraphics(params().filename);
+}
+
+
 string const ControlGraphics::readBB(string const & file)
 {
 	string const abs_file = MakeAbsPath(file, buffer()->filePath());
Index: src/frontends/controllers/ControlGraphics.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/ControlGraphics.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 ControlGraphics.h
--- src/frontends/controllers/ControlGraphics.h	2003/02/13 16:52:47	1.18
+++ src/frontends/controllers/ControlGraphics.h	2003/03/01 15:25:02
@@ -44,6 +44,8 @@ public:
 	bool bbChanged;
 	/// test if file exist
 	bool isFilenameValid(string const & fname) const;
+	/// edit file
+	void editGraphics();
 
 private:
 	/// Dispatch the changed parameters to the kernel.
Index: src/frontends/qt2/QGraphicsDialog.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QGraphicsDialog.C,v
retrieving revision 1.16
diff -u -3 -p -r1.16 QGraphicsDialog.C
--- src/frontends/qt2/QGraphicsDialog.C	2003/02/13 16:52:52	1.16
+++ src/frontends/qt2/QGraphicsDialog.C	2003/03/01 15:25:04
@@ -44,6 +44,8 @@ QGraphicsDialog::QGraphicsDialog(QGraphi
 		form, SLOT(slotClose()));
 	connect(restorePB, SIGNAL(clicked()),
 		form, SLOT(slotRestore()));
+	connect(editPB, SIGNAL(clicked()),
+		this, SLOT(edit_clicked()));
 }
 
 
@@ -101,3 +103,11 @@ void QGraphicsDialog::getBB_clicked()
 {
 	form_->getBB();
 }
+
+
+void QGraphicsDialog::edit_clicked()
+{
+	form_->changed();
+	form_->controller().editGraphics();
+}
+
Index: src/frontends/qt2/QGraphicsDialog.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QGraphicsDialog.h,v
retrieving revision 1.9
diff -u -3 -p -r1.9 QGraphicsDialog.h
--- src/frontends/qt2/QGraphicsDialog.h	2003/02/13 16:52:52	1.9
+++ src/frontends/qt2/QGraphicsDialog.h	2003/03/01 15:25:04
@@ -30,6 +30,7 @@ protected slots:
 	virtual void change_WUnit();
 	virtual void browse_clicked();
 	virtual void getBB_clicked();
+	virtual void edit_clicked();
 protected:
 	virtual void closeEvent(QCloseEvent * e);
 private:
Index: src/frontends/qt2/ui/QGraphicsDialogBase.ui
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ui/QGraphicsDialogBase.ui,v
retrieving revision 1.2
diff -u -3 -p -r1.2 QGraphicsDialogBase.ui
--- src/frontends/qt2/ui/QGraphicsDialogBase.ui	2003/01/23 16:23:40	1.2
+++ src/frontends/qt2/ui/QGraphicsDialogBase.ui	2003/03/01 15:25:06
@@ -1106,6 +1106,25 @@
                         <bool>false</bool>
                     </property>
                 </widget>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>editPB</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>&amp;Edit</string>
+                    </property>
+                    <property stdset="1">
+                        <name>autoDefault</name>
+                        <bool>false</bool>
+                    </property>
+                    <property stdset="1">
+                        <name>default</name>
+                        <bool>false</bool>
+                    </property>
+                </widget>
                 <spacer>
                     <property>
                         <name>name</name>
Index: src/frontends/xforms/FormGraphics.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/FormGraphics.C,v
retrieving revision 1.100
diff -u -3 -p -r1.100 FormGraphics.C
--- src/frontends/xforms/FormGraphics.C	2003/02/13 16:52:56	1.100
+++ src/frontends/xforms/FormGraphics.C	2003/03/01 15:25:09
@@ -629,6 +629,8 @@ ButtonPolicy::SMInput FormGraphics::inpu
 		setEnabled(extra_->input_subcaption,
 			   fl_get_button(extra_->check_subcaption));
 
+        } else if (ob == dialog_->button_edit) {
+		controller().editExternal();
 	}
 
 	return ButtonPolicy::SMI_VALID;
Index: src/frontends/xforms/forms/form_graphics.fd
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/forms/form_graphics.fd,v
retrieving revision 1.41
diff -u -3 -p -r1.41 form_graphics.fd
--- src/frontends/xforms/forms/form_graphics.fd	2003/02/15 19:03:09	1.41
+++ src/frontends/xforms/forms/form_graphics.fd	2003/03/01 15:25:10
@@ -9,14 +9,14 @@ SnapGrid: 5
 
 =============== FORM ===============
 Name: form_graphics
-Width: 395
+Width: 495
 Height: 300
-Number of Objects: 6
+Number of Objects: 7
 
 --------------------
 class: FL_BOX
 type: FLAT_BOX
-box: 0 0 395 300
+box: 0 0 495 300
 boxtype: FL_FLAT_BOX
 colors: FL_COL1 FL_COL1
 alignment: FL_ALIGN_CENTER
@@ -34,7 +34,7 @@ argument: 
 --------------------
 class: FL_TABFOLDER
 type: TOP_TABFOLDER
-box: 0 5 395 260
+box: 0 5 495 260
 boxtype: FL_FRAME_BOX
 colors: FL_COL1 FL_COL1
 alignment: FL_ALIGN_TOP_LEFT
@@ -77,6 +77,24 @@ alignment: FL_ALIGN_CENTER
 style: FL_NORMAL_STYLE
 size: FL_NORMAL_SIZE
 lcol: FL_BLACK
+label: Edit
+shortcut:
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: button_edit
+callback: C_FormBaseEditCB
+argument: 0
+
+--------------------
+class: FL_BUTTON
+type: RETURN_BUTTON
+box: 210 270 90 25
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
 label: OK
 shortcut: ^M
 resize: FL_RESIZE_ALL
@@ -88,7 +106,7 @@ argument: 0
 --------------------
 class: FL_BUTTON
 type: NORMAL_BUTTON
-box: 300 270 90 25
+box: 400 270 90 25
 boxtype: FL_UP_BOX
 colors: FL_COL1 FL_COL1
 alignment: FL_ALIGN_CENTER
@@ -106,7 +124,7 @@ argument: 0
 --------------------
 class: FL_BUTTON
 type: NORMAL_BUTTON
-box: 205 270 90 25
+box: 305 270 90 25
 boxtype: FL_UP_BOX
 colors: FL_COL1 FL_COL1
 alignment: FL_ALIGN_CENTER
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.153
diff -u -3 -p -r1.153 insetgraphics.C
--- src/insets/insetgraphics.C	2003/02/28 09:49:49	1.153
+++ src/insets/insetgraphics.C	2003/03/01 15:25:13
@@ -190,6 +190,7 @@ void InsetGraphics::Cache::update(string
 
 InsetGraphics::InsetGraphics()
 	: graphic_label(uniqueID()),
+	  view_(0),
 	  cache_(new Cache(*this))
 {}
 
@@ -199,6 +200,7 @@ InsetGraphics::InsetGraphics(InsetGraphi
 			     bool same_id)
 	: Inset(ig, same_id),
 	  graphic_label(uniqueID()),
+	  view_(0),
 	  cache_(new Cache(*this))
 {
 	setParams(ig.params(), filepath);
@@ -304,7 +306,7 @@ int InsetGraphics::width(BufferView *, L
 void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
 			 int baseline, float & x, bool) const
 {
-	// MakeAbsPath returns params().filename unchanged if it absolute
+	// MakeAbsPath returns params().filename unchanged if it is absolute
 	// already.
 	string const file_with_path =
 		MakeAbsPath(params().filename, bv->buffer()->filePath());
@@ -396,6 +398,7 @@ void InsetGraphics::draw(BufferView * bv
 
 void InsetGraphics::edit(BufferView *bv, int, int, mouse_button::state)
 {
+	view_ = bv;
 	bv->owner()->getDialogs().showGraphics(this);
 }
 
@@ -833,3 +836,27 @@ InsetGraphicsParams const & InsetGraphic
 {
 	return params_;
 }
+
+
+// Taken from the external material inset
+void InsetGraphics::editGraphics(string const &fileName) const
+{
+	string editCommand("lyxedit ");
+	editCommand.append(fileName);
+	executeCommand(editCommand, view_->buffer()->filePath());
+	// Redraw the image if necessary
+	cache_->update(fileName);
+}
+
+
+// Taken from the external material inset
+void InsetGraphics::executeCommand(string const & s, string const & filePath) const
+{
+	Systemcall one;
+	if (lyxerr.debugging()) {
+		lyxerr << "Executing '" << s << "' in '"
+		<< filePath << "'" << endl;
+	}
+	one.startscript(Systemcall::Wait, s);
+}
+
Index: src/insets/insetgraphics.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetgraphics.h,v
retrieving revision 1.57
diff -u -3 -p -r1.57 insetgraphics.h
--- src/insets/insetgraphics.h	2003/02/13 16:53:04	1.57
+++ src/insets/insetgraphics.h	2003/03/01 15:25:14
@@ -88,6 +88,9 @@ public:
 	/// Get the inset parameters, used by the GUIndependent dialog.
 	InsetGraphicsParams const & params() const;
 
+	/// edit the graphics file
+	void editGraphics(string const &) const;
+
 	/** This signal is connected by our dialog and called when the inset
 	    is deleted.
 	*/
@@ -102,6 +105,9 @@ private:
 	 */
 	void statusChanged();
 
+	/// Execute this command in the directory of this document
+	void executeCommand(string const &, string const &) const;
+
 	/// Read the inset native format
 	void readInsetGraphics(LyXLex & lex);
 
@@ -117,6 +123,9 @@ private:
 
 	/// holds the entity name that defines the graphics location (SGML).
 	string const graphic_label;
+
+	/// our owning view
+	BufferView * view_;
 
 	/// The cached variables
 	class Cache;

Reply via email to