From 8bca52392948efe2d042c9881ed51f8f1b4e8ce6 Mon Sep 17 00:00:00 2001 From: basti Date: Fri, 19 Jul 2013 08:44:29 +0200 Subject: [PATCH] #26, #28 fixed, add docu --- MONI/Data/WorkDayParser.cs | 22 ++++++-- MONI/MONI.csproj | 1 + MONI/MainView.xaml | 3 +- MONI/MainView.xaml.cs | 9 +++- MONI/Tests/WorkDayParserExtensionsTester.cs | 14 +++-- MONI/Util/IAddShortcutService.cs | 7 +++ MONI/Views/PNSearchView.xaml | 60 +++++++++++++++++++-- MONI/Views/PNSearchView.xaml.cs | 18 +++++++ moni_updates.json | 2 + 9 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 MONI/Util/IAddShortcutService.cs diff --git a/MONI/Data/WorkDayParser.cs b/MONI/Data/WorkDayParser.cs index 9906024..b6f247f 100644 --- a/MONI/Data/WorkDayParser.cs +++ b/MONI/Data/WorkDayParser.cs @@ -275,7 +275,9 @@ public string IncDec(string text, int stepsToIncrementBy, INCDEC_OPERATOR incDec var hoursToIncrementBy = stepsToIncrementBy * 15 / 60f; var parts = this.SplitIntoParts(text).ToList(); int idx; - var part = this.FindPositionPart(parts, selectionStart, out idx); + bool moveCursorLeft; + int cursorInPartPosition; + var part = this.FindPositionPart(parts, selectionStart, out idx, out cursorInPartPosition); var newPart = part; if (idx == 0) { // is daystart, has no - @@ -302,6 +304,10 @@ public string IncDec(string text, int stepsToIncrementBy, INCDEC_OPERATOR incDec newPart = hIncremented.ToString(CultureInfo.InvariantCulture); } } + // check if we need to move cursor to left + if (cursorInPartPosition > newPart.Length) { + selectionStart -= part.Length - newPart.Length; + } if (idx >= 0) { parts[idx] = newPart; } @@ -349,7 +355,8 @@ public IList SplitIntoPartsIntern(string text) { return splitted; } - public string FindPositionPart(IList parts, int position, out int foundPartsIndex) { + public string FindPositionPart(IList parts, int cursorPosition, out int foundPartsIndex, out int cursorInPartPosition) { + cursorInPartPosition = 0; var partsComplete = parts.Aggregate(string.Empty, (aggr, s) => aggr + s); for (int i = 0; i < parts.Count(); i++) { var partsLower = parts.Take(i).Aggregate(string.Empty, (aggr, s) => aggr + s); @@ -358,16 +365,23 @@ public string FindPositionPart(IList parts, int position, out int foundP var b = partsLower.Length; var t = partsUpper.Length; - if ((position >= b && position < t) || partsUpper == partsComplete) { + if ((cursorPosition >= b && cursorPosition < t) || partsUpper == partsComplete) { if (parts[i] == this.itemSeparator.ToString() || parts[i] == this.hourProjectInfoSeparator.ToString()) { + // cursor left of separator foundPartsIndex = i - 1; - return parts.ElementAt(i - 1); + var prevPart = parts.ElementAt(foundPartsIndex); + // find out where in the found part the cursor is, need to use prevpart an its length + cursorInPartPosition = prevPart.Length; + return prevPart; } else { + // find out where in the found part the cursor is + cursorInPartPosition = cursorPosition - b; foundPartsIndex = i; return parts.ElementAt(i); } } } + // not found foundPartsIndex = -1; return string.Empty; } diff --git a/MONI/MONI.csproj b/MONI/MONI.csproj index 79f88f9..adc0247 100644 --- a/MONI/MONI.csproj +++ b/MONI/MONI.csproj @@ -105,6 +105,7 @@ + diff --git a/MONI/MainView.xaml b/MONI/MainView.xaml index 19af7ce..86dad71 100644 --- a/MONI/MainView.xaml +++ b/MONI/MainView.xaml @@ -333,7 +333,8 @@ + IsOpen="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=IsOpen}" + AddShortCutService="{Binding ElementName=mv}"/> diff --git a/MONI/MainView.xaml.cs b/MONI/MainView.xaml.cs index f272aa8..fbd08bc 100644 --- a/MONI/MainView.xaml.cs +++ b/MONI/MainView.xaml.cs @@ -6,6 +6,7 @@ using System.Windows.Controls; using System.Windows.Input; using MONI.Data; +using MONI.Util; using MONI.ViewModels; using MahApps.Metro.Controls; using NLog; @@ -15,7 +16,7 @@ namespace MONI /// /// Interaction logic for MainView.xaml /// - public partial class MainView : MetroWindow + public partial class MainView : MetroWindow, IAddShortcutService { private static readonly Logger logger = LogManager.GetCurrentClassLogger(); @@ -215,5 +216,11 @@ private void PasswordOK_OnClick(object sender, RoutedEventArgs e) { private void ShowPNSearch_Button_Click(object sender, RoutedEventArgs e) { this.ViewModel.PNSearch.ShowPNSearch = true; } + + public void AddShortCut(string key, string expansion) { + this.ViewModel.PNSearch.ShowPNSearch = false; + var sc = new ShortCut(key, expansion); + this.ViewModel.EditShortCut = new ShortcutViewModel(sc, this.ViewModel.WorkWeek, this.ViewModel.Settings, () => this.ViewModel.EditShortCut = null) { IsNew = true}; + } } } \ No newline at end of file diff --git a/MONI/Tests/WorkDayParserExtensionsTester.cs b/MONI/Tests/WorkDayParserExtensionsTester.cs index e86b068..39cad90 100644 --- a/MONI/Tests/WorkDayParserExtensionsTester.cs +++ b/MONI/Tests/WorkDayParserExtensionsTester.cs @@ -91,9 +91,11 @@ public void WDPCurserUp_DayStart_Increment() { public void WDPFindPositionPart_Pos0_Return0() { var parts = wdp.SplitIntoParts("9,4;12345-000,-16:00;12345-000"); int idx; - var newText = wdp.FindPositionPart(parts, 2, out idx); + bool cursorNextoSeparator; + int cursorInPartPosition; + var newText = wdp.FindPositionPart(parts, 2, out idx, out cursorInPartPosition); Assert.AreEqual("4", newText, "for pos 2"); - newText = wdp.FindPositionPart(parts, 3, out idx); + newText = wdp.FindPositionPart(parts, 3, out idx, out cursorInPartPosition); Assert.AreEqual("4", newText, "for pos 3"); } @@ -101,7 +103,9 @@ public void WDPFindPositionPart_Pos0_Return0() { public void WDPFindPositionPart_Pos2_Return0() { var parts = wdp.SplitIntoParts("8"); int idx; - var newText = wdp.FindPositionPart(parts, 1, out idx); + bool cursorNextoSeparator; + int cursorInPartPosition; + var newText = wdp.FindPositionPart(parts, 1, out idx, out cursorInPartPosition); Assert.AreEqual("8", newText); } @@ -110,7 +114,9 @@ public void WDPFindPositionPart_Pos1_Return0() { var parts = wdp.SplitIntoParts("9,4;12345-000,-16:00;12345-001"); for (int i = 14; i <= 20; i++) { int idx; - var newText = wdp.FindPositionPart(parts, i, out idx); + bool cursorNextoSeparator; + int cursorInPartPosition; + var newText = wdp.FindPositionPart(parts, i, out idx, out cursorInPartPosition); Assert.AreEqual("-16:00", newText, string.Format("wrong text pos:{0}", i)); Assert.AreEqual(6, idx); } diff --git a/MONI/Util/IAddShortcutService.cs b/MONI/Util/IAddShortcutService.cs new file mode 100644 index 0000000..e93168a --- /dev/null +++ b/MONI/Util/IAddShortcutService.cs @@ -0,0 +1,7 @@ +namespace MONI.Util +{ + public interface IAddShortcutService + { + void AddShortCut(string key, string expansion); + } +} \ No newline at end of file diff --git a/MONI/Views/PNSearchView.xaml b/MONI/Views/PNSearchView.xaml index 718fc8d..11e2896 100644 --- a/MONI/Views/PNSearchView.xaml +++ b/MONI/Views/PNSearchView.xaml @@ -9,7 +9,15 @@ d:DesignWidth="300" d:DataContext="{d:DesignInstance ViewModels:PNSearchViewModel}"> - + + + + + + + + @@ -37,24 +45,66 @@ + + + + - - + + + TextTrimming="CharacterEllipsis" + Foreground="Gainsboro"> + + + diff --git a/MONI/Views/PNSearchView.xaml.cs b/MONI/Views/PNSearchView.xaml.cs index 36c1321..875f504 100644 --- a/MONI/Views/PNSearchView.xaml.cs +++ b/MONI/Views/PNSearchView.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using MONI.Util; using MONI.ViewModels; namespace MONI.Views @@ -11,6 +12,8 @@ public partial class PNSearchView : UserControl { public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(PNSearchView), new PropertyMetadata(default(bool), IsOpenPropertyChangedCallback)); + public static readonly DependencyProperty AddShortCutServiceProperty = + DependencyProperty.Register("AddShortCutService", typeof(IAddShortcutService), typeof(PNSearchView)); private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { var view = dependencyObject as PNSearchView; @@ -24,8 +27,23 @@ public bool IsOpen { set { this.SetValue(IsOpenProperty, value); } } + public IAddShortcutService AddShortCutService { + get { return (IAddShortcutService)this.GetValue(AddShortCutServiceProperty); } + set { this.SetValue(AddShortCutServiceProperty, value); } + } + public PNSearchView() { this.InitializeComponent(); } + + private void AddAsShortcut_OnClick(object sender, RoutedEventArgs e) { + Button button = sender as Button; + if (button != null) { + ProjectNumber pn = button.Tag as ProjectNumber; + if (pn != null && this.AddShortCutService!=null) { + this.AddShortCutService.AddShortCut(string.Empty, string.Format("{0}-000({1})", pn.Number, pn.Description)); + } + } + } } } \ No newline at end of file diff --git a/moni_updates.json b/moni_updates.json index 1eec779..6bb55c8 100644 --- a/moni_updates.json +++ b/moni_updates.json @@ -27,6 +27,8 @@ "Version":"0.9.8.7", "Changes":[ "pausen können nun nicht nur im stundenformat (z.b. 1!), sondern auch im zeitformat (z.b. -10:30!) angegeben werden", + "issue #28 closed: beim cursor up/down gab es ein problem wenn der neu eingesetzte textteil kürzer als der vcorige war. dann sprang der cursor in den nächsten eintrag.", + "issue #26 closed: shortcut anlegen aus der projektnummern suche", ], "DownLoadURL" : "http://mtools" },