diff --git a/gimp/mm.xcf b/gimp/mm.xcf
new file mode 100644
index 0000000..b4162ed
Binary files /dev/null and b/gimp/mm.xcf differ
diff --git a/zaaReloaded2/Commands.cs b/zaaReloaded2/Commands.cs
index 6354980..4fbe14e 100755
--- a/zaaReloaded2/Commands.cs
+++ b/zaaReloaded2/Commands.cs
@@ -138,8 +138,13 @@ namespace zaaReloaded2
Globals.ThisAddIn.Application.Selection);
}
- public static void FormatDrugs()
+ public static void FormatDrugs(int columns)
{
+ if (columns < 1 || columns > 2)
+ {
+ throw new ArgumentOutOfRangeException("Can only format 1 or 2 columns, not " + columns);
+ }
+
// If no "real" selection exists, attempt to auto-detect the drugs section.
// (NB Technically, there is never _no_ selection in a document.)
Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow;
@@ -160,7 +165,18 @@ namespace zaaReloaded2
Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text);
Medication.Formatter formatter = new Medication.Formatter(importer.Prescriptions);
- formatter.FormatOneColumn(activeWindow.Document);
+
+ switch (columns)
+ {
+ case 1:
+ formatter.FormatOneColumn(activeWindow.Document);
+ break;
+ case 2:
+ formatter.FormatTwoColumns(activeWindow.Document);
+ break;
+ default:
+ break;
+ }
}
#endregion
diff --git a/zaaReloaded2/Formatter/DocumentWriter.cs b/zaaReloaded2/Formatter/DocumentWriter.cs
index 460ca9f..29548c2 100755
--- a/zaaReloaded2/Formatter/DocumentWriter.cs
+++ b/zaaReloaded2/Formatter/DocumentWriter.cs
@@ -171,6 +171,14 @@ namespace zaaReloaded2.Formatter
_buffer.AppendLine(text);
}
+ ///
+ /// Appends a newline to the buffer.
+ ///
+ public void WriteLine()
+ {
+ _buffer.AppendLine();
+ }
+
///
/// Inserts text at the start of the buffer.
///
diff --git a/zaaReloaded2/Icons/mm.png b/zaaReloaded2/Icons/mm.png
new file mode 100644
index 0000000..0fceba4
Binary files /dev/null and b/zaaReloaded2/Icons/mm.png differ
diff --git a/zaaReloaded2/Medication/Formatter.cs b/zaaReloaded2/Medication/Formatter.cs
index 9aadc30..090de5c 100755
--- a/zaaReloaded2/Medication/Formatter.cs
+++ b/zaaReloaded2/Medication/Formatter.cs
@@ -55,18 +55,38 @@ namespace zaaReloaded2.Medication
///
public void FormatOneColumn(Document document)
{
- if (document == null)
- {
- throw new ArgumentNullException(
- "Cannot format prescriptions because no document was given.");
- }
+ DoFormat("Medikation einspaltig formatieren",
+ document,
+ writer =>
+ {
+ foreach (Prescription p in Prescriptions)
+ {
+ writer.WriteLine(p.ToString());
+ }
+ });
+ }
- Helpers.StartUndo("Medikation formatieren");
- foreach (Prescription p in Prescriptions)
- {
- document.ActiveWindow.Selection.TypeText(p.ToString() + "\r");
- }
- Helpers.EndUndo();
+ ///
+ /// Writes a block of prescriptions with two columns to a
+ /// Word document.
+ ///
+ ///
+ public void FormatTwoColumns(Document document)
+ {
+ DoFormat("Medikation zweispaltig formatieren",
+ document,
+ writer =>
+ {
+ for (int i = 0; i < Prescriptions.Count; i += 2)
+ {
+ writer.Write(Prescriptions[i].ToString());
+ if (i + 1 < Prescriptions.Count)
+ {
+ writer.Write("\t" + Prescriptions[i+1].ToString());
+ }
+ writer.WriteLine();
+ }
+ });
}
///
@@ -77,6 +97,95 @@ namespace zaaReloaded2.Medication
{
throw new NotImplementedException();
}
+
+ #endregion
+
+ #region Private methods
+
+ void AddDisclaimer(zaaReloaded2.Formatter.DocumentWriter writer)
+ {
+ writer.WriteLine("Bitte Medikation überprüfen!");
+ }
+
+ ///
+ /// Creates a paragraph and character styles in the document.
+ ///
+ void CreateStyles(Document document)
+ {
+ if (document != null)
+ {
+ Style style;
+ // Don't see a better way to check for the existence of a particular
+ // paragraph style than by using a try...catch construction.
+ try
+ {
+ style = document.Styles[Properties.Settings.Default.DrugsParagraph];
+ }
+ catch
+ {
+ // Add default paragraph style for laboratory
+ style = document.Styles.Add(Properties.Settings.Default.DrugsParagraph);
+ style.Font.Size = 10; // pt
+ style.Font.Bold = 0;
+ style.Font.Italic = 0;
+ style.Font.Underline = 0;
+ style.ParagraphFormat.SpaceAfter = 0;
+ style.ParagraphFormat.SpaceBefore = 0;
+ style.ParagraphFormat.LeftIndent = 0; // pt
+ style.ParagraphFormat.FirstLineIndent = 0; // pt
+ style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
+ style.ParagraphFormat.TabStops.ClearAll();
+ int tabStop = 108; // 108 pt = 2.5 in = 3.8 cm
+ int halfWay = 227; // 227 pt = 3.15 in = 8 cm
+ style.ParagraphFormat.TabStops.Add(tabStop);
+ style.ParagraphFormat.TabStops.Add(halfWay);
+ style.ParagraphFormat.TabStops.Add(halfWay + tabStop);
+ }
+
+ // try
+ // {
+ // style = document.Styles[Properties.Settings.Default.DrugsHeader];
+ // }
+ // catch
+ // {
+ // // Add header paragraph style for laboratory
+ // style = document.Styles.Add(Properties.Settings.Default.DrugsHeader);
+ // style.Font.Size = 10; // pt
+ // style.Font.Bold = 1;
+ // style.Font.Italic = 0;
+ // style.Font.Underline = WdUnderline.wdUnderlineSingle;
+ // style.ParagraphFormat.SpaceAfter = 0;
+ // style.ParagraphFormat.SpaceBefore = 12;
+ // style.ParagraphFormat.LeftIndent = 36; // pt
+ // style.ParagraphFormat.FirstLineIndent = -36; // pt
+ // style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
+ // style.set_NextParagraphStyle(document.Styles[Properties.Settings.Default.DrugsParagraph]);
+ // }
+ }
+ }
+
+ ///
+ /// Does the heavy lifting in a DRY way.
+ ///
+ void DoFormat(string description, Document document,
+ Action outputAction)
+ {
+ if (document == null)
+ {
+ throw new ArgumentNullException(
+ "Cannot format prescriptions because no document was given.");
+ }
+
+ Helpers.StartUndo(description);
+ zaaReloaded2.Formatter.DocumentWriter writer = new zaaReloaded2.Formatter.DocumentWriter(document);
+ CreateStyles(document);
+ writer.Write(String.Format("", Properties.Settings.Default.DrugsParagraph));
+ outputAction(writer);
+ AddDisclaimer(writer);
+ // writer.Write(""); // causes COM exceptions, needs fix
+ writer.Flush();
+ Helpers.EndUndo();
+ }
#endregion
}
diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs
index 53fccbd..3ef9b9e 100755
--- a/zaaReloaded2/Properties/Settings.Designer.cs
+++ b/zaaReloaded2/Properties/Settings.Designer.cs
@@ -276,5 +276,14 @@ namespace zaaReloaded2.Properties {
this["NeedUpgrade"] = value;
}
}
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2-Medikamente")]
+ public string DrugsParagraph {
+ get {
+ return ((string)(this["DrugsParagraph"]));
+ }
+ }
}
}
diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings
index d448e89..0416614 100755
--- a/zaaReloaded2/Properties/Settings.settings
+++ b/zaaReloaded2/Properties/Settings.settings
@@ -80,5 +80,8 @@
True
+
+ zaaReloaded2-Medikamente
+
\ No newline at end of file
diff --git a/zaaReloaded2/Ribbon.cs b/zaaReloaded2/Ribbon.cs
index eb3809e..f008fbc 100755
--- a/zaaReloaded2/Ribbon.cs
+++ b/zaaReloaded2/Ribbon.cs
@@ -105,8 +105,11 @@ namespace zaaReloaded2
case "zrlDemo":
Commands.LoadDemo();
break;
- case "zrlFormatDrugs":
- Commands.FormatDrugs();
+ case "zrlFormatDrugsOneCol":
+ Commands.FormatDrugs(1);
+ break;
+ case "zrlFormatDrugsTwoCol":
+ Commands.FormatDrugs(2);
break;
default:
throw new InvalidOperationException("No operation defined for " + control.Id);
diff --git a/zaaReloaded2/Ribbon.xml b/zaaReloaded2/Ribbon.xml
index a59f63b..db54938 100755
--- a/zaaReloaded2/Ribbon.xml
+++ b/zaaReloaded2/Ribbon.xml
@@ -29,13 +29,18 @@
getEnabled="CanFormat" />
-
-
+
+
+
+