Skip to content

Commit

Permalink
#26, #28 fixed, add docu
Browse files Browse the repository at this point in the history
  • Loading branch information
dotob committed Jul 19, 2013
1 parent e67c208 commit 8bca523
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 15 deletions.
22 changes: 18 additions & 4 deletions MONI/Data/WorkDayParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand All @@ -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;
}
Expand Down Expand Up @@ -349,7 +355,8 @@ public IList<string> SplitIntoPartsIntern(string text) {
return splitted;
}

public string FindPositionPart(IList<string> parts, int position, out int foundPartsIndex) {
public string FindPositionPart(IList<string> 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);
Expand All @@ -358,16 +365,23 @@ public string FindPositionPart(IList<string> 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;
}
Expand Down
1 change: 1 addition & 0 deletions MONI/MONI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Compile Include="Util\DayOfWeekTranslatorConverter.cs" />
<Compile Include="Util\EnvironmentInfos.cs" />
<Compile Include="Util\ExceptionExtensions.cs" />
<Compile Include="Util\IAddShortcutService.cs" />
<Compile Include="Util\LessThanColorConverter.cs" />
<Compile Include="Util\Null2FalseConverter.cs" />
<Compile Include="Util\TimeSpanUtil.cs" />
Expand Down
3 changes: 2 additions & 1 deletion MONI/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@
</DataTemplate.Resources>
<!-- bind to IsOpen to set the focus to first editable textbox, not the best, but it works -->
<views:PNSearchView x:Name="pnSearchView"
IsOpen="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=IsOpen}" />
IsOpen="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=IsOpen}"
AddShortCutService="{Binding ElementName=mv}"/>
</DataTemplate>
</Controls:Flyout.ContentTemplate>
</Controls:Flyout>
Expand Down
9 changes: 8 additions & 1 deletion MONI/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@ namespace MONI
/// <summary>
/// Interaction logic for MainView.xaml
/// </summary>
public partial class MainView : MetroWindow
public partial class MainView : MetroWindow, IAddShortcutService
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();

Expand Down Expand Up @@ -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};
}
}
}
14 changes: 10 additions & 4 deletions MONI/Tests/WorkDayParserExtensionsTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ 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");
}

[Test]
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);
}

Expand All @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions MONI/Util/IAddShortcutService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MONI.Util
{
public interface IAddShortcutService
{
void AddShortCut(string key, string expansion);
}
}
60 changes: 55 additions & 5 deletions MONI/Views/PNSearchView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
d:DesignWidth="300"
d:DataContext="{d:DesignInstance ViewModels:PNSearchViewModel}">

<Grid Width="400"
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MONI;component/Resources/Icons.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

<Grid Width="400"
Margin="10">

<Grid.RowDefinitions>
Expand Down Expand Up @@ -37,24 +45,66 @@
<ListBox Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding Results}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Background="DimGray" CornerRadius="2" Margin="0 0 0 2" Padding="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"

<TextBlock Grid.Column="0"
Grid.Row="0"
Text="{Binding Number}"
FontSize="18"
FontWeight="Bold"
Foreground="Gainsboro"></TextBlock>
<TextBlock Grid.Row="1"
Foreground="Gainsboro">
</TextBlock>
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="{Binding Description}"
FontSize="10"
Foreground="Gainsboro"></TextBlock>
TextTrimming="CharacterEllipsis"
Foreground="Gainsboro">
</TextBlock>

<Button
Grid.Column="1"
Grid.Row="0"
Grid.RowSpan="2"
Width="13"
Height="20"
Margin="10 0 0 0"
Style="{StaticResource ImageButtonStyle}"
Click="AddAsShortcut_OnClick"
Tag="{Binding}">
<Button.ToolTip>
<ToolTip>
<TextBlock Text="Neuen Shortcut erstellen"
Foreground="White">
</TextBlock>
</ToolTip>
</Button.ToolTip>
<Rectangle Width="10"
Height="20">
<Rectangle.Resources>
<SolidColorBrush x:Key="BlackBrush"
Color="#CC119EDA" />
</Rectangle.Resources>
<Rectangle.Fill>
<VisualBrush Stretch="Fill"
Visual="{StaticResource appbar_location_add}" />
</Rectangle.Fill>
</Rectangle>
</Button>
</Grid>
</Border>
</DataTemplate>
Expand Down
18 changes: 18 additions & 0 deletions MONI/Views/PNSearchView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using MONI.Util;
using MONI.ViewModels;

namespace MONI.Views
Expand All @@ -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;
Expand All @@ -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));
}
}
}
}
}
2 changes: 2 additions & 0 deletions moni_updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 8bca523

Please sign in to comment.