Il 20/04/2011 18:25, Jens Nöckel ha scritto:
On Apr 19, 2011, at 3:06 PM, Tommaso Cucinotta wrote:
AFAIK, after the thread

  http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg154697.html

there was no actual implementation of this feature, for creating
quickly empty external files over which to invoke an external editor.

In the current trunk, you can specify a non-existent external file in
the Insert ->  External Material... dialog, but when trying to externally
edit you get a "non-existent file" error dialog.

Is there anyone with a patch for this ? (i.e., a "create" button the
Insert ->  External Material... dialog).

Guess #3205 is the corresponding Trac entry (#5726 seems related as well).
Regarding the topic "Simple Drawing Ability" - just in case this was 
overlooked, let me mention that simple drawings can be made by copy and paste.
[...]

That's fine for quickly pasting images from the clipboard, but I'd like something that gives me control of what I'm inserting (and its source format), without the burden to have to launch the program externally first, create a new file, place it into the same working folder as the ".lyx" I'm editing, then back to LyX, insert it, and re-edit.

Shortly, please try the attached preliminary patch.

It adds a "Create" button in the "Insert->File->External Material..." dialog which creates an empty file with the name specified by the user by copying from a file template, which is found into the "lib/samples" folder, with the filename specified into the a new "Sample" property of external material items.

I say "preliminary" because things that one may want to add are:
-) launch also the editor, when you press "Create..."
-) add another "Edit..." button for launching the external editor
-) better control of *where* the new file is created (in the patch it is the current folder, but I guess I should use the folder of the ".lyx" file I'm inserting into (how to get that ?) -) possibility to use different empty template files, and to specify which one we want (e.g., for images, .png, .svg, .dia, ...).

On a related note, as a user, I'm really confused by:
-) Insert->Graphics...
-) Insert->File->External Material..., then pick "dia" or "XFig"

From a user viewpoint, what is supposed to be the difference between these 2 actions ?

And also by (despite the documentation):
-) Insert->Date
-) Insert->File->External Material..., then pick "Date"

Any comments welcome!

    T.

Index: src/insets/ExternalTemplate.cpp
===================================================================
--- src/insets/ExternalTemplate.cpp	(revisione 38483)
+++ src/insets/ExternalTemplate.cpp	(copia locale)
@@ -313,7 +313,8 @@
 		TO_PREVIEW,
 		TO_TRANSFORM,
 		TO_FORMAT,
-		TO_END
+		TO_END,
+		TO_SAMPLE
 	};
 
 	LexerKeyword templateoptiontags[] = {
@@ -325,7 +326,8 @@
 		{ "inputformat", TO_INPUTFORMAT },
 		{ "preview", TO_PREVIEW },
 		{ "templateend", TO_END },
-		{ "transform", TO_TRANSFORM }
+		{ "transform", TO_TRANSFORM },
+		{ "sample", TO_SAMPLE }
 	};
 
 	PushPopHelper pph(lex, templateoptiontags);
@@ -386,6 +388,11 @@
 		case TO_END:
 			return;
 
+		case TO_SAMPLE:
+			lex.next(true);
+			sample = lex.getString();
+			break;
+
 		default:
 			lex.printError("external::Template::readTemplate: "
 				       "Wrong tag: $$Token");
Index: src/insets/ExternalTemplate.h
===================================================================
--- src/insets/ExternalTemplate.h	(revisione 38483)
+++ src/insets/ExternalTemplate.h	(copia locale)
@@ -66,6 +66,8 @@
 	PreviewMode preview_mode;
 	/// A collection of transforms that we can use to transform the data.
 	std::vector<TransformID> transformIds;
+	/// Pathname of a sample empty file
+	std::string sample;
 
 	/// This is the information needed to support a specific output format
 	class Format {
Index: src/frontends/qt4/ui/ExternalUi.ui
===================================================================
--- src/frontends/qt4/ui/ExternalUi.ui	(revisione 38483)
+++ src/frontends/qt4/ui/ExternalUi.ui	(copia locale)
@@ -1,107 +1,108 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>ExternalUi</class>
- <widget class="QDialog" name="ExternalUi" >
-  <property name="geometry" >
+ <widget class="QDialog" name="ExternalUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>386</width>
-    <height>453</height>
+    <height>491</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <property name="sizeGripEnabled" >
+  <property name="sizeGripEnabled">
    <bool>true</bool>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
+  <layout class="QGridLayout">
+   <property name="margin">
     <number>9</number>
    </property>
-   <property name="spacing" >
+   <property name="spacing">
     <number>6</number>
    </property>
-   <item row="0" column="0" >
-    <widget class="QTabWidget" name="tab" >
-     <property name="toolTip" >
+   <item row="0" column="0">
+    <widget class="QTabWidget" name="tab">
+     <property name="toolTip">
       <string/>
      </property>
-     <property name="currentIndex" >
+     <property name="currentIndex">
       <number>0</number>
      </property>
-     <widget class="QWidget" name="filetab" >
-      <attribute name="title" >
+     <widget class="QWidget" name="filetab">
+      <attribute name="title">
        <string>F&amp;ile</string>
       </attribute>
-      <layout class="QGridLayout" >
-       <property name="margin" >
+      <layout class="QGridLayout">
+       <property name="margin">
         <number>9</number>
        </property>
-       <property name="spacing" >
+       <property name="spacing">
         <number>6</number>
        </property>
-       <item row="0" column="1" >
-        <widget class="QLineEdit" name="fileED" >
-         <property name="toolTip" >
+       <item row="0" column="1">
+        <widget class="QLineEdit" name="fileED">
+         <property name="toolTip">
           <string>Filename</string>
          </property>
         </widget>
        </item>
-       <item row="0" column="0" >
-        <widget class="QLabel" name="fileLA" >
-         <property name="toolTip" >
+       <item row="0" column="0">
+        <widget class="QLabel" name="fileLA">
+         <property name="toolTip">
           <string>Filename</string>
          </property>
-         <property name="text" >
+         <property name="text">
           <string>&amp;File:</string>
          </property>
-         <property name="buddy" >
+         <property name="buddy">
           <cstring>fileED</cstring>
          </property>
         </widget>
        </item>
-       <item row="0" column="2" >
-        <widget class="QPushButton" name="browsePB" >
-         <property name="toolTip" >
+       <item row="0" column="2">
+        <widget class="QPushButton" name="browsePB">
+         <property name="toolTip">
           <string>Select a file</string>
          </property>
-         <property name="text" >
+         <property name="text">
           <string>&amp;Browse...</string>
          </property>
         </widget>
        </item>
-       <item row="2" column="0" colspan="3" >
-        <widget class="QCheckBox" name="draftCB" >
-         <property name="text" >
+       <item row="2" column="0" colspan="3">
+        <widget class="QCheckBox" name="draftCB">
+         <property name="text">
           <string>&amp;Draft</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="0" colspan="3" >
-        <widget class="QGroupBox" name="GroupBox3" >
-         <property name="title" >
+       <item row="1" column="0" colspan="3">
+        <widget class="QGroupBox" name="GroupBox3">
+         <property name="title">
           <string>&amp;Template</string>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="1" column="0" colspan="2" >
-           <widget class="QTextBrowser" name="externalTB" />
+          <item row="1" column="0" colspan="3">
+           <widget class="QTextBrowser" name="externalTB"/>
           </item>
-          <item row="0" column="1" >
+          <item row="0" column="2">
            <spacer>
-            <property name="orientation" >
+            <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeType" >
+            <property name="sizeType">
              <enum>QSizePolicy::Preferred</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" stdset="0">
              <size>
               <width>20</width>
               <height>20</height>
@@ -109,75 +110,85 @@
             </property>
            </spacer>
           </item>
-          <item row="0" column="0" >
-           <widget class="QComboBox" name="externalCO" >
-            <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+          <item row="0" column="0">
+           <widget class="QComboBox" name="externalCO">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
-            <property name="toolTip" >
+            <property name="toolTip">
              <string>Available templates</string>
             </property>
            </widget>
           </item>
+          <item row="0" column="1">
+           <widget class="QPushButton" name="createPB">
+            <property name="text">
+             <string>Create...</string>
+            </property>
+            <property name="toolTip">
+              <string>Create file from empty template (specify name first)</string>
+            </property>
+           </widget>
+          </item>
          </layout>
         </widget>
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="lyxviewtab" >
-      <attribute name="title" >
+     <widget class="QWidget" name="lyxviewtab">
+      <attribute name="title">
        <string>LaTe&amp;X and LyX options</string>
       </attribute>
-      <layout class="QVBoxLayout" >
-       <property name="spacing" >
+      <layout class="QVBoxLayout">
+       <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin" >
+       <property name="margin">
         <number>9</number>
        </property>
        <item>
-        <widget class="QGroupBox" name="optionsGB" >
-         <property name="title" >
+        <widget class="QGroupBox" name="optionsGB">
+         <property name="title">
           <string>LaTeX Options</string>
          </property>
-         <property name="flat" >
+         <property name="flat">
           <bool>true</bool>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="1" column="1" >
-           <widget class="QLineEdit" name="extraED" />
+          <item row="1" column="1">
+           <widget class="QLineEdit" name="extraED"/>
           </item>
-          <item row="0" column="1" >
-           <widget class="QLabel" name="optionLA" >
-            <property name="text" >
+          <item row="0" column="1">
+           <widget class="QLabel" name="optionLA">
+            <property name="text">
              <string>O&amp;ption:</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>extraED</cstring>
             </property>
            </widget>
           </item>
-          <item row="1" column="0" >
-           <widget class="QComboBox" name="extraFormatCO" />
+          <item row="1" column="0">
+           <widget class="QComboBox" name="extraFormatCO"/>
           </item>
-          <item row="0" column="0" >
-           <widget class="QLabel" name="formatLA" >
-            <property name="text" >
+          <item row="0" column="0">
+           <widget class="QLabel" name="formatLA">
+            <property name="text">
              <string>Forma&amp;t:</string>
             </property>
-            <property name="textFormat" >
+            <property name="textFormat">
              <enum>Qt::AutoText</enum>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>extraFormatCO</cstring>
             </property>
            </widget>
@@ -186,61 +197,61 @@
         </widget>
        </item>
        <item>
-        <widget class="QGroupBox" name="displayGB" >
-         <property name="toolTip" >
+        <widget class="QGroupBox" name="displayGB">
+         <property name="toolTip">
           <string>Enable LyX to preview this material; only if graphics previewing is not disabled at application level (see Preference dialog).</string>
          </property>
-         <property name="title" >
+         <property name="title">
           <string>&amp;Show in LyX</string>
          </property>
-         <property name="flat" >
+         <property name="flat">
           <bool>true</bool>
          </property>
-         <property name="checkable" >
+         <property name="checkable">
           <bool>true</bool>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="0" column="0" >
-           <widget class="QLabel" name="scaleLA" >
-            <property name="toolTip" >
+          <item row="0" column="0">
+           <widget class="QLabel" name="scaleLA">
+            <property name="toolTip">
              <string>Percentage to scale by in LyX</string>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>Sca&amp;le on Screen (%):</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>displayscaleED</cstring>
             </property>
            </widget>
           </item>
-          <item row="0" column="1" >
-           <widget class="QLineEdit" name="displayscaleED" >
-            <property name="enabled" >
+          <item row="0" column="1">
+           <widget class="QLineEdit" name="displayscaleED">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
-            <property name="toolTip" >
+            <property name="toolTip">
              <string>Percentage to scale by in LyX</string>
             </property>
            </widget>
           </item>
-          <item row="0" column="2" >
+          <item row="0" column="2">
            <spacer>
-            <property name="orientation" >
+            <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" stdset="0">
              <size>
               <width>40</width>
               <height>20</height>
@@ -253,10 +264,10 @@
        </item>
        <item>
         <spacer>
-         <property name="orientation" >
+         <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
-         <property name="sizeHint" stdset="0" >
+         <property name="sizeHint" stdset="0">
           <size>
            <width>81</width>
            <height>196</height>
@@ -266,41 +277,41 @@
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="sizetab" >
-      <attribute name="title" >
+     <widget class="QWidget" name="sizetab">
+      <attribute name="title">
        <string>Si&amp;ze and Rotation</string>
       </attribute>
-      <layout class="QGridLayout" >
-       <property name="margin" >
+      <layout class="QGridLayout">
+       <property name="margin">
         <number>9</number>
        </property>
-       <property name="spacing" >
+       <property name="spacing">
         <number>6</number>
        </property>
-       <item row="1" column="0" >
-        <widget class="QGroupBox" name="rotationGB" >
-         <property name="title" >
+       <item row="1" column="0">
+        <widget class="QGroupBox" name="rotationGB">
+         <property name="title">
           <string>Rotate</string>
          </property>
-         <property name="flat" >
+         <property name="flat">
           <bool>true</bool>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="0" column="1" >
+          <item row="0" column="1">
            <spacer>
-            <property name="orientation" >
+            <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeType" >
+            <property name="sizeType">
              <enum>QSizePolicy::Expanding</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" stdset="0">
              <size>
               <width>20</width>
               <height>20</height>
@@ -308,59 +319,59 @@
             </property>
            </spacer>
           </item>
-          <item row="0" column="0" >
-           <layout class="QGridLayout" >
-            <property name="margin" >
+          <item row="0" column="0">
+           <layout class="QGridLayout">
+            <property name="margin">
              <number>0</number>
             </property>
-            <property name="spacing" >
+            <property name="spacing">
              <number>6</number>
             </property>
-            <item row="0" column="1" >
-             <widget class="QLineEdit" name="angleED" >
-              <property name="sizePolicy" >
-               <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
+            <item row="0" column="1">
+             <widget class="QLineEdit" name="angleED">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
                 <horstretch>0</horstretch>
                 <verstretch>0</verstretch>
                </sizepolicy>
               </property>
-              <property name="toolTip" >
+              <property name="toolTip">
                <string>Angle to rotate image by</string>
               </property>
-              <property name="text" >
+              <property name="text">
                <string/>
               </property>
              </widget>
             </item>
-            <item row="1" column="0" >
-             <widget class="QLabel" name="originLA" >
-              <property name="toolTip" >
+            <item row="1" column="0">
+             <widget class="QLabel" name="originLA">
+              <property name="toolTip">
                <string>The origin of the rotation</string>
               </property>
-              <property name="text" >
+              <property name="text">
                <string>Ori&amp;gin:</string>
               </property>
-              <property name="buddy" >
+              <property name="buddy">
                <cstring>originCO</cstring>
               </property>
              </widget>
             </item>
-            <item row="1" column="1" >
-             <widget class="QComboBox" name="originCO" >
-              <property name="toolTip" >
+            <item row="1" column="1">
+             <widget class="QComboBox" name="originCO">
+              <property name="toolTip">
                <string>The origin of the rotation</string>
               </property>
              </widget>
             </item>
-            <item row="0" column="0" >
-             <widget class="QLabel" name="angleLA" >
-              <property name="toolTip" >
+            <item row="0" column="0">
+             <widget class="QLabel" name="angleLA">
+              <property name="toolTip">
                <string>Angle to rotate image by</string>
               </property>
-              <property name="text" >
+              <property name="text">
                <string>A&amp;ngle:</string>
               </property>
-              <property name="buddy" >
+              <property name="buddy">
                <cstring>angleED</cstring>
               </property>
              </widget>
@@ -370,82 +381,82 @@
          </layout>
         </widget>
        </item>
-       <item row="0" column="0" >
-        <widget class="QGroupBox" name="scaleGB" >
-         <property name="title" >
+       <item row="0" column="0">
+        <widget class="QGroupBox" name="scaleGB">
+         <property name="title">
           <string>Scale</string>
          </property>
-         <property name="flat" >
+         <property name="flat">
           <bool>true</bool>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="1" column="2" >
-           <widget class="LengthCombo" name="heightUnitCO" />
+          <item row="1" column="2">
+           <widget class="LengthCombo" name="heightUnitCO"/>
           </item>
-          <item row="0" column="2" >
-           <widget class="LengthCombo" name="widthUnitCO" />
+          <item row="0" column="2">
+           <widget class="LengthCombo" name="widthUnitCO"/>
           </item>
-          <item row="1" column="1" >
-           <widget class="QLineEdit" name="heightED" >
-            <property name="enabled" >
+          <item row="1" column="1">
+           <widget class="QLineEdit" name="heightED">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="toolTip" >
+            <property name="toolTip">
              <string>Height of image in output</string>
             </property>
            </widget>
           </item>
-          <item row="0" column="1" >
-           <widget class="QLineEdit" name="widthED" >
-            <property name="enabled" >
+          <item row="0" column="1">
+           <widget class="QLineEdit" name="widthED">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="toolTip" >
+            <property name="toolTip">
              <string>Width of image in output</string>
             </property>
            </widget>
           </item>
-          <item row="0" column="0" >
-           <widget class="QLabel" name="widthLA" >
-            <property name="enabled" >
+          <item row="0" column="0">
+           <widget class="QLabel" name="widthLA">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>&amp;Width:</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>widthED</cstring>
             </property>
            </widget>
           </item>
-          <item row="2" column="1" colspan="2" >
-           <widget class="QCheckBox" name="aspectratioCB" >
-            <property name="enabled" >
+          <item row="2" column="1" colspan="2">
+           <widget class="QCheckBox" name="aspectratioCB">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="toolTip" >
+            <property name="toolTip">
              <string>Maintain aspect ratio with largest dimension</string>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>&amp;Maintain aspect ratio</string>
             </property>
            </widget>
           </item>
-          <item row="1" column="0" >
-           <widget class="QLabel" name="heightLA" >
-            <property name="enabled" >
+          <item row="1" column="0">
+           <widget class="QLabel" name="heightLA">
+            <property name="enabled">
              <bool>true</bool>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>&amp;Height:</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>heightED</cstring>
             </property>
            </widget>
@@ -453,84 +464,84 @@
          </layout>
         </widget>
        </item>
-       <item row="2" column="0" >
-        <widget class="QGroupBox" name="cropGB" >
-         <property name="title" >
+       <item row="2" column="0">
+        <widget class="QGroupBox" name="cropGB">
+         <property name="title">
           <string>Crop</string>
          </property>
-         <property name="flat" >
+         <property name="flat">
           <bool>true</bool>
          </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
+         <layout class="QGridLayout">
+          <property name="margin">
            <number>9</number>
           </property>
-          <property name="spacing" >
+          <property name="spacing">
            <number>6</number>
           </property>
-          <item row="0" column="0" colspan="2" >
-           <widget class="QCheckBox" name="clipCB" >
-            <property name="toolTip" >
+          <item row="0" column="0" colspan="2">
+           <widget class="QCheckBox" name="clipCB">
+            <property name="toolTip">
              <string>Clip to bounding box values</string>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>Clip to &amp;bounding box</string>
             </property>
            </widget>
           </item>
-          <item row="3" column="0" >
-           <widget class="QLabel" name="lbLA" >
-            <property name="text" >
+          <item row="3" column="0">
+           <widget class="QLabel" name="lbLA">
+            <property name="text">
              <string>&amp;Left bottom:</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>xlED</cstring>
             </property>
            </widget>
           </item>
-          <item row="2" column="3" >
-           <widget class="QLineEdit" name="ytED" />
+          <item row="2" column="3">
+           <widget class="QLineEdit" name="ytED"/>
           </item>
-          <item row="1" column="1" >
-           <widget class="QLabel" name="xLA" >
-            <property name="text" >
+          <item row="1" column="1">
+           <widget class="QLabel" name="xLA">
+            <property name="text">
              <string>x</string>
             </property>
            </widget>
           </item>
-          <item row="2" column="0" >
-           <widget class="QLabel" name="rtLA" >
-            <property name="text" >
+          <item row="2" column="0">
+           <widget class="QLabel" name="rtLA">
+            <property name="text">
              <string>Right &amp;top:</string>
             </property>
-            <property name="buddy" >
+            <property name="buddy">
              <cstring>xrED</cstring>
             </property>
            </widget>
           </item>
-          <item row="0" column="3" >
-           <widget class="QPushButton" name="getbbPB" >
-            <property name="toolTip" >
+          <item row="0" column="3">
+           <widget class="QPushButton" name="getbbPB">
+            <property name="toolTip">
              <string>Get bounding box from the (EPS) file</string>
             </property>
-            <property name="text" >
+            <property name="text">
              <string>&amp;Get from File</string>
             </property>
            </widget>
           </item>
-          <item row="3" column="1" colspan="2" >
-           <widget class="QLineEdit" name="xlED" >
-            <property name="toolTip" >
+          <item row="3" column="1" colspan="2">
+           <widget class="QLineEdit" name="xlED">
+            <property name="toolTip">
              <string/>
             </property>
            </widget>
           </item>
-          <item row="0" column="2" >
+          <item row="0" column="2">
            <spacer>
-            <property name="orientation" >
+            <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" stdset="0">
              <size>
               <width>43</width>
               <height>18</height>
@@ -538,18 +549,18 @@
             </property>
            </spacer>
           </item>
-          <item row="3" column="3" >
-           <widget class="QLineEdit" name="ybED" />
+          <item row="3" column="3">
+           <widget class="QLineEdit" name="ybED"/>
           </item>
-          <item row="1" column="3" >
-           <widget class="QLabel" name="yLA" >
-            <property name="text" >
+          <item row="1" column="3">
+           <widget class="QLabel" name="yLA">
+            <property name="text">
              <string>y</string>
             </property>
            </widget>
           </item>
-          <item row="2" column="1" colspan="2" >
-           <widget class="QLineEdit" name="xrED" />
+          <item row="2" column="1" colspan="2">
+           <widget class="QLineEdit" name="xrED"/>
           </item>
          </layout>
         </widget>
@@ -558,23 +569,23 @@
      </widget>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
+   <item row="1" column="0">
+    <layout class="QHBoxLayout">
+     <property name="spacing">
       <number>6</number>
      </property>
-     <property name="margin" >
+     <property name="margin">
       <number>0</number>
      </property>
      <item>
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" stdset="0" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
          <height>20</height>
@@ -583,34 +594,34 @@
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
+      <widget class="QPushButton" name="okPB">
+       <property name="text">
         <string>&amp;OK</string>
        </property>
-       <property name="default" >
+       <property name="default">
         <bool>true</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="applyPB" >
-       <property name="text" >
+      <widget class="QPushButton" name="applyPB">
+       <property name="text">
         <string>&amp;Apply</string>
        </property>
-       <property name="default" >
+       <property name="default">
         <bool>false</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="closePB" >
-       <property name="text" >
+      <widget class="QPushButton" name="closePB">
+       <property name="text">
         <string>&amp;Close</string>
        </property>
-       <property name="autoDefault" >
+       <property name="autoDefault">
         <bool>false</bool>
        </property>
-       <property name="default" >
+       <property name="default">
         <bool>false</bool>
        </property>
       </widget>
@@ -640,7 +651,7 @@
   <tabstop>closePB</tabstop>
  </tabstops>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>
Index: src/frontends/qt4/GuiExternal.h
===================================================================
--- src/frontends/qt4/GuiExternal.h	(revisione 38483)
+++ src/frontends/qt4/GuiExternal.h	(copia locale)
@@ -41,6 +41,7 @@
 	void sizeChanged();
 	void templateChanged();
 	void widthUnitChanged();
+	void createClicked();
 
 private:
 	///
Index: src/frontends/qt4/GuiExternal.cpp
===================================================================
--- src/frontends/qt4/GuiExternal.cpp	(revisione 38483)
+++ src/frontends/qt4/GuiExternal.cpp	(copia locale)
@@ -27,6 +27,8 @@
 #include "graphics/GraphicsCacheItem.h"
 #include "graphics/GraphicsImage.h"
 
+#include "frontends/alert.h"
+
 #include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -43,6 +45,7 @@
 #include <QPushButton>
 #include <QTabWidget>
 #include <QTextBrowser>
+#include <QFile>
 
 using namespace std;
 using namespace lyx::support;
@@ -110,6 +113,8 @@
 		this, SLOT(change_adaptor()));
 	connect(browsePB, SIGNAL(clicked()),
 		this, SLOT(browseClicked()));
+	connect(createPB, SIGNAL(clicked()),
+		this, SLOT(createClicked()));
 	connect(externalCO, SIGNAL(activated(QString)),
 		this, SLOT(templateChanged()));
 	connect(extraED, SIGNAL(textChanged(QString)),
@@ -266,8 +271,35 @@
 }
 
 
+void GuiExternal::createClicked()
+{
+	int const choice =  externalCO->currentIndex();
+	external::Template const & templ = getTemplate(choice);
+	LASSERT(!templ.sample.empty(), /**/);
+	QString const sample_qname = toqstr(templ.sample);
+	FileName sample_fname = libFileSearch(toqstr("samples"), sample_qname);
+	LASSERT(sample_fname.exists(), /**/);
+
+	LASSERT(!fromqstr(fileED->text()).empty(), /**/);
+	FileName dest_fname(fromqstr(fileED->text()));
+	// @TODO Check if exists
+	if (dest_fname.exists()) {
+		int overwrite = frontend::Alert::prompt(
+			_("Overwrite ?"), _("File exists. Replace with empty template ?"),
+			0, 1, _("&Yes"), _("&No"));
+		if (overwrite != 0)
+			return;
+	}
+	sample_fname.copyTo(dest_fname);
+}
+
+
 void GuiExternal::change_adaptor()
 {
+	if (fromqstr(fileED->text()).empty())
+		createPB->setEnabled(false);
+	else
+		createPB->setEnabled(true);
 	changed();
 }
 
Index: lib/external_templates
===================================================================
--- lib/external_templates	(revisione 38483)
+++ lib/external_templates	(copia locale)
@@ -376,6 +376,7 @@
 	HelpTextEnd
 	InputFormat dia
 	FileFilter "*.dia"
+	Sample "sample.dia"
 	AutomaticProduction true
 	# LyX has hard-coded support for these transformations
 	Transform Rotate

Reply via email to