Skip to content

Commit

Permalink
Line, column and file name show now
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiu Marton committed Jul 31, 2018
1 parent 06506e4 commit 4a8c86f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
7 changes: 4 additions & 3 deletions PseudoEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:avalonEdit="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit"
mc:Ignorable="d"
Title="PseudoEditor" Height="600" Width="800" MinHeight="400" MinWidth="400"
Title="PseudoEditor - NewFile*" Height="600" Width="800" MinHeight="400" MinWidth="400"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
Expand Down Expand Up @@ -125,7 +125,8 @@

<avalonEdit:TextEditor x:Name="Editor" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
FontFamily="Consolas" ShowLineNumbers="True" FontSize="16">
FontFamily="Consolas" ShowLineNumbers="True" FontSize="16"
TextChanged="Editor_OnTextChanged">
<avalonEdit:TextEditor.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding Source={x:Static local:StringResources.Cut}}" Command="Cut">
Expand Down Expand Up @@ -158,7 +159,7 @@
<ColumnDefinition Width="Auto" MinWidth="75"/>
</Grid.ColumnDefinitions>

<Label x:Name="LabelFilename" Grid.Column="0" Content="Filename"/>
<Label x:Name="LabelFilename" Grid.Column="0" Content="New file*"/>
<Label Grid.Column="2" Content="Ln"/>
<Label x:Name="LabelLines" Grid.Column="3"/>
<Label Grid.Column="4" Content="Col"/>
Expand Down
35 changes: 35 additions & 0 deletions PseudoEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,34 @@ namespace PseudoEditor
public partial class MainWindow : Window
{
private string _currentFileName;
private const string ProgramName = "PseudoEditor";

public MainWindow()
{
InitializeComponent();

Editor.Focus();

ShowLineColumn();
Editor.TextArea.Caret.PositionChanged += (sender, args) => ShowLineColumn();
}

private void ShowLineColumn()
{
LabelLines.Content = Editor.TextArea.Caret.Line;
LabelColumns.Content = Editor.TextArea.Caret.Column;
}

private void ShowFileName()
{
LabelFilename.Content = _currentFileName;
Title = $"{ProgramName} - {_currentFileName}";
}

private void ShowFileNameChanged()
{
LabelFilename.Content = $"{_currentFileName}*";
Title = $"{ProgramName} - {_currentFileName}*";
}

private void New_Executed(object sender, ExecutedRoutedEventArgs e)
Expand Down Expand Up @@ -61,6 +85,7 @@ private void Open_Executed(object sender, ExecutedRoutedEventArgs e)
{
_currentFileName = dialog.FileName;
Editor.Load(_currentFileName);
ShowFileName();
}
}

Expand All @@ -73,6 +98,7 @@ private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
else
{
Editor.Save(_currentFileName);
ShowFileName();
}
}

Expand All @@ -91,12 +117,21 @@ private void SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
{
_currentFileName = dialog.FileName;
Editor.Save(_currentFileName);
ShowFileName();
}
}

private void Close_Executed(object sender, ExecutedRoutedEventArgs e)
{
this.Close();
}

private void Editor_OnTextChanged(object sender, EventArgs e)
{
if (_currentFileName != null)
{
ShowFileNameChanged();
}
}
}
}
7 changes: 0 additions & 7 deletions PseudoEditor/PseudoEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="NewFileDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="NewFileDialog.xaml.cs">
<DependentUpon>NewFileDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down

0 comments on commit 4a8c86f

Please sign in to comment.