Prevent running the formatter without appropriate selection.
- VERBESSERT: Formatieren läßt sich nicht mehr starten, ohne daß Labor-Text markiert ist.
This commit is contained in:
parent
7a105d7aad
commit
863dfa071a
@ -119,7 +119,7 @@ namespace zaaReloaded2.Formatter
|
|||||||
/// current position of the cursor).</param>
|
/// current position of the cursor).</param>
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
if (!CanRun) throw new InvalidOperationException("No laboratory data to format.");
|
if (!CanRun) throw new NoLaboratoryDataException("No laboratory data to format.");
|
||||||
|
|
||||||
CreateParagraphStyle();
|
CreateParagraphStyle();
|
||||||
_secondaryBuffer.ParagraphStyle = zaaReloaded2.Properties.Settings.Default.ParagraphStyleName;
|
_secondaryBuffer.ParagraphStyle = zaaReloaded2.Properties.Settings.Default.ParagraphStyleName;
|
||||||
|
35
zaaReloaded2/Formatter/NoLaboratoryDataException.cs
Executable file
35
zaaReloaded2/Formatter/NoLaboratoryDataException.cs
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
/* NoLaboratoryDataException.cs
|
||||||
|
* part of zaaReloaded2
|
||||||
|
*
|
||||||
|
* Copyright 2015 Daniel Kraus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace zaaReloaded2.Formatter
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
class NoLaboratoryDataException : Exception
|
||||||
|
{
|
||||||
|
public NoLaboratoryDataException() { }
|
||||||
|
public NoLaboratoryDataException(string message) : base(message) { }
|
||||||
|
public NoLaboratoryDataException(string message,
|
||||||
|
Exception innerException)
|
||||||
|
: base(message, innerException) { }
|
||||||
|
public NoLaboratoryDataException(SerializationInfo info,
|
||||||
|
StreamingContext context)
|
||||||
|
: base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,9 @@ using zaaReloaded2.ViewModels;
|
|||||||
using zaaReloaded2.Importer.ZaaImporter;
|
using zaaReloaded2.Importer.ZaaImporter;
|
||||||
using zaaReloaded2.Formatter;
|
using zaaReloaded2.Formatter;
|
||||||
using zaaReloaded2.Controller;
|
using zaaReloaded2.Controller;
|
||||||
|
using Word = Microsoft.Office.Interop.Word;
|
||||||
|
using Bovender.Mvvm.Actions;
|
||||||
|
using Bovender.Mvvm.Messaging;
|
||||||
|
|
||||||
// TODO: Follow these steps to enable the Ribbon (XML) item:
|
// TODO: Follow these steps to enable the Ribbon (XML) item:
|
||||||
|
|
||||||
@ -79,7 +82,8 @@ namespace zaaReloaded2
|
|||||||
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
|
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
|
||||||
{
|
{
|
||||||
_ribbon = ribbonUI;
|
_ribbon = ribbonUI;
|
||||||
Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange;
|
Microsoft.Office.Interop.Word.Application word = Globals.ThisAddIn.Application;
|
||||||
|
word.WindowSelectionChange += Application_WindowSelectionChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -152,9 +156,19 @@ namespace zaaReloaded2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if there is at least one paragraph selected.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The Selection object in Word is a bit tricky: Its Length property
|
||||||
|
/// is never 0, because even if no text passage is selected, the character
|
||||||
|
/// after the cursor is the content of the Selection.
|
||||||
|
/// </remarks>
|
||||||
public bool CanFormat(Office.IRibbonControl control)
|
public bool CanFormat(Office.IRibbonControl control)
|
||||||
{
|
{
|
||||||
return Globals.ThisAddIn.Application.Selection.Paragraphs.Count > 0;
|
Word.Selection s = Globals.ThisAddIn.Application.ActiveWindow.Selection;
|
||||||
|
return s.Paragraphs.Count > 1 ||
|
||||||
|
(s.Text.Length > 1 && s.Text.EndsWith("\r"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -182,12 +196,23 @@ namespace zaaReloaded2
|
|||||||
void DoFormat(Settings settings)
|
void DoFormat(Settings settings)
|
||||||
{
|
{
|
||||||
ZaaImporter importer = new ZaaImporter();
|
ZaaImporter importer = new ZaaImporter();
|
||||||
importer.Import(Globals.ThisAddIn.Application.Selection.Text);
|
importer.Import(Globals.ThisAddIn.Application.ActiveWindow.Selection.Text);
|
||||||
Formatter.Formatter formatter =new Formatter.Formatter(
|
Formatter.Formatter formatter = new Formatter.Formatter(
|
||||||
Globals.ThisAddIn.Application.ActiveDocument);
|
Globals.ThisAddIn.Application.ActiveDocument);
|
||||||
formatter.Settings = settings;
|
formatter.Settings = settings;
|
||||||
formatter.Laboratory = importer.Laboratory;
|
formatter.Laboratory = importer.Laboratory;
|
||||||
formatter.Run();
|
try
|
||||||
|
{
|
||||||
|
formatter.Run();
|
||||||
|
}
|
||||||
|
catch (NoLaboratoryDataException)
|
||||||
|
{
|
||||||
|
NotificationAction a = new NotificationAction();
|
||||||
|
a.Caption = "Formatieren nicht möglich";
|
||||||
|
a.Message = "Die aktuelle Markierung scheint keine Labordaten zu enthalten.";
|
||||||
|
a.OkButtonLabel = "Schließen";
|
||||||
|
a.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoChooseSettings()
|
void DoChooseSettings()
|
||||||
|
@ -26,6 +26,7 @@ using zaaReloaded2.Controller;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Runtime.Serialization.Formatters.Soap;
|
using System.Runtime.Serialization.Formatters.Soap;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.Office.Interop.Word;
|
||||||
|
|
||||||
namespace zaaReloaded2.ViewModels
|
namespace zaaReloaded2.ViewModels
|
||||||
{
|
{
|
||||||
@ -314,7 +315,12 @@ namespace zaaReloaded2.ViewModels
|
|||||||
|
|
||||||
bool CanUseSettings()
|
bool CanUseSettings()
|
||||||
{
|
{
|
||||||
return LastSelected != null && LastSelected.IsSelected;
|
Selection selection = Globals.ThisAddIn.Application.ActiveWindow.Selection;
|
||||||
|
return LastSelected != null && LastSelected.IsSelected &&
|
||||||
|
(
|
||||||
|
selection.Paragraphs.Count > 1
|
||||||
|
|| (selection.Text.Length > 1 && selection.Text.EndsWith("\r"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoAddSettings()
|
void DoAddSettings()
|
||||||
|
@ -213,6 +213,7 @@
|
|||||||
<Compile Include="ExceptionHandler\SubmissionSuccessView.xaml.cs" />
|
<Compile Include="ExceptionHandler\SubmissionSuccessView.xaml.cs" />
|
||||||
<Compile Include="Formatter\DanielsStyle.cs" />
|
<Compile Include="Formatter\DanielsStyle.cs" />
|
||||||
<Compile Include="Formatter\DocumentWriter.cs" />
|
<Compile Include="Formatter\DocumentWriter.cs" />
|
||||||
|
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
|
||||||
<Compile Include="Ribbon.cs" />
|
<Compile Include="Ribbon.cs" />
|
||||||
<Compile Include="Thesaurus\ThesaurusBase.cs" />
|
<Compile Include="Thesaurus\ThesaurusBase.cs" />
|
||||||
<Compile Include="Formatter\IItemFormatterDictionary.cs" />
|
<Compile Include="Formatter\IItemFormatterDictionary.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user