Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

SEU line number commands GUI start (WIP) #13

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a9f4fda
Merge pull request #1 from WorksOfBarry/master
NathanielACollier Dec 9, 2017
aa8a45d
lineNumberCommands:GUI:Pulled over initial code
NathanielACollier Dec 9, 2017
bf3fb0f
lineNumberCommands:Adding files into project
NathanielACollier Dec 13, 2017
ade2c37
lineNumberCommands:Changing it to display a textbox next to line number
NathanielACollier Dec 13, 2017
c0677a2
lineNumberCommands:Moving towards switching list numbers to a listvie…
NathanielACollier Dec 13, 2017
ed82b4d
lineNumbersCommands:Changed from ListView to ItemsControl
NathanielACollier Dec 13, 2017
152e905
lineNumberCommands:Add the listview to the adorner visual children
NathanielACollier Dec 13, 2017
0470062
lineNumberCommands:Only need the adorner layer update once
NathanielACollier Dec 13, 2017
48783cb
lineNumberCommands:Only redraw line number commands if lines have cha…
NathanielACollier Dec 13, 2017
0c3d228
lineNumbersCommand:New Idea:Dont clear just collapse out of view line…
NathanielACollier Dec 13, 2017
0b9ff4f
lineNumberCommands:Populate line number display for initial text lines
NathanielACollier Dec 13, 2017
2920abd
Merge pull request #2 from WorksOfBarry/master
NathanielACollier Dec 18, 2017
7aa7560
Merge branch 'master' into SEU-Line-Number-Commands-GUI-Start
NathanielACollier Dec 18, 2017
6fdd8c5
lineNumberCommands:Making progress towards listview width controling …
NathanielACollier Dec 18, 2017
4598826
lineNumberCommands:Rearranging to move this closer to OnMeasure
NathanielACollier Dec 22, 2017
9b4e187
lineNumberCommands:Width of listview will now control margin width
NathanielACollier Dec 22, 2017
7d483ce
lineNumberCommands:Fixing data triggers
NathanielACollier Dec 22, 2017
20b88db
lineNumberCommands:Got the command entry on/off figured out
NathanielACollier Jan 4, 2018
4ddfbc9
lineNumberCommands:Starting work to implement d and dd
NathanielACollier Jan 4, 2018
8e19bc0
lineNumberCommands:Changing it to pass all line number entries to eve…
NathanielACollier Jan 5, 2018
46f8163
lineNumberCommands:Putting in a temporary hold for any exceptions tha…
NathanielACollier Jan 5, 2018
ac3a51d
lineNumberCommands:Made progress towards implementing d
NathanielACollier Jan 5, 2018
0fca37a
lineNumberCommands:Need update source trigger so you can type d and t…
NathanielACollier Jan 5, 2018
89fb7c3
lineNumberCommands:Figured out how to get a line deleted
NathanielACollier Jan 5, 2018
2143ecf
lineNumberCommands:Adding in the new files
NathanielACollier Jan 5, 2018
25fddfb
lineNumberCommands:Got d working right
NathanielACollier Jan 10, 2018
8e85346
lineNumberCommands:Bug fix for d command
NathanielACollier Jan 10, 2018
3c7a259
lineNumberCommands:d command:getting closer to making it work in all …
NathanielACollier Jan 10, 2018
69cde18
lineNumberCommands:Forgot to add AvalonEditUtility to project file
NathanielACollier Jan 10, 2018
2d9adb1
lineNumberCommands:Delete line works in all cases
NathanielACollier Jan 10, 2018
e8b2504
lineNumberCommands:First attempt at implementing dd
NathanielACollier Jan 10, 2018
7d097e9
Merge pull request #3 from WorksOfBarry/master
NathanielACollier Jan 20, 2018
6696d96
Merge branch 'master' into SEU-Line-Number-Commands-GUI-Start
NathanielACollier Jan 20, 2018
92517b2
lineNumberCommands:Notes - Arrow Keys
NathanielACollier Jan 23, 2018
5555645
lineNumberCommands:Starting to hookup some signaling for moving from …
NathanielACollier Jan 23, 2018
78c0002
lineNumberCommands:Implemented arrow key on AvalonEdit line causes co…
NathanielACollier Jan 23, 2018
61760ed
lineNumberCommands:Up key goes to next line number command, and down …
NathanielACollier Jan 23, 2018
a85701d
lineNumberCommands:Bug fix to line height being 1 if there where not …
NathanielACollier Jan 30, 2018
c4d289c
Merge in stuff
NathanielACollier Oct 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILEditor.Classes.AvalonEdit.LineNumberCommandMargin
{
public static class AvalonEditUtility
{
public static void DeleteLine( TextEditor editor, int lineNumber)
{
var editorLine = editor.Document.GetLineByNumber(lineNumber);
// remove the line from AvalonEdit

if( editorLine.NextLine != null && editorLine.PreviousLine == null)
{
// has no previous but has next
editor.Document.Remove(editorLine.Offset, editorLine.NextLine.Offset - editorLine.Offset);
}
else if( editorLine.PreviousLine != null )
{
// has previous (Having a next either way doesn't matter)
editor.Document.Remove(editorLine.PreviousLine.EndOffset, editorLine.EndOffset - editorLine.PreviousLine.EndOffset);
}
else
{
// has no next or previous
editor.Document.Remove(editorLine); // this just clears contents of the line
}
}
}
}
16 changes: 16 additions & 0 deletions ILEditor/Classes/AvalonEdit.LineNumberCommandMargin/LineInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILEditor.Classes.AvalonEdit.LineNumberCommandMargin
{
public class LineInfo
{
public int Number { get; set; }
public double LineHeight { get; set; }


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<UserControl x:Class="ILEditor.Classes.AvalonEdit.LineNumberCommandMargin.LineNumberDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ILEditor.Classes.AvalonEdit.LineNumberCommandMargin"
mc:Ignorable="d"
x:Name="lineNumberDisplayCtl"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Style>
<Style TargetType="UserControl">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Model.IsInView, ElementName=lineNumberDisplayCtl}" Value="true">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
<DockPanel Height="{Binding Path=Model.ControlHeight, Mode=TwoWay, ElementName=lineNumberDisplayCtl}">
<TextBox DockPanel.Dock="Left"
MinWidth="25"
Text="{Binding Path=Model.CommandText, ElementName=lineNumberDisplayCtl, UpdateSourceTrigger=PropertyChanged}"
Name="lineNumberCommandTextBox"
LostFocus="lineNumberCommandTextBox_LostFocus"
KeyDown="lineNumberCommandTextBox_KeyDown"
PreviewKeyDown="lineNumberCommandTextBox_PreviewKeyDown"
>
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Model.IsCommandEntryVisible, ElementName=lineNumberDisplayCtl}" Value="true">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>

<TextBlock DockPanel.Dock="Left"
MinWidth="25"
Text="{Binding Path=Model.CommandText, ElementName=lineNumberDisplayCtl}"
Name="lineNumberCommandTextBlock"
MouseUp="lineNumberCommandTextBlock_MouseUp"
>
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Model.HasCommandText, ElementName=lineNumberDisplayCtl}" Value="true" />
<Condition Binding="{Binding Path=Model.IsCommandEntryVisible, ElementName=lineNumberDisplayCtl}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>

<TextBlock DockPanel.Dock="Left"
Text="{Binding Path=Model.LineNumber, ElementName=lineNumberDisplayCtl}"
Name="lineNumberTextBlock"
TextAlignment="Right"
MouseUp="lineNumberTextBlock_MouseUp"
>
</TextBlock>

</DockPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace ILEditor.Classes.AvalonEdit.LineNumberCommandMargin
{
/// <summary>
/// Interaction logic for LineNumberDisplay.xaml
/// </summary>
public partial class LineNumberDisplay : UserControl
{

#region Model DP

public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(LineNumberDisplayModel), typeof(LineNumberDisplay), new PropertyMetadata { PropertyChangedCallback = new PropertyChangedCallback( OnModelChanged) });

public LineNumberDisplayModel Model
{
get { return (LineNumberDisplayModel)this.GetValue(ModelProperty); }
set { this.SetValue(ModelProperty, value); }
}

private static void OnModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
var ctrl = d as LineNumberDisplay;
ctrl.InitModel();
}

#endregion

public LineNumberDisplay()
{
InitializeComponent();

}


public void InitModel()
{
// hookup events and other things
var model = this.DataContext as LineNumberDisplayModel;

// different things can signal us to turn on command mode
model.OnSignalToTurnOnCommandMode += Model_OnSignalToTurnOnCommandMode;
}

private void Model_OnSignalToTurnOnCommandMode(object arg1, EventArgs arg2)
{
var model = this.DataContext as LineNumberDisplayModel;
model.IsCommandEntryVisible = true;
// focus the textbox
lineNumberCommandTextBox.Focus();
}

private void lineNumberTextBlock_MouseUp(object sender, MouseButtonEventArgs e)
{
// clicked line number so go to command mode
var context = this.DataContext as LineNumberDisplayModel;
context.IsCommandEntryVisible = true;
lineNumberCommandTextBox.Focus();
}

private void lineNumberCommandTextBox_LostFocus(object sender, RoutedEventArgs e)
{
var context = this.DataContext as LineNumberDisplayModel;
// they may have entered a command that got rid of the line
if( context != null)
{
context.IsCommandEntryVisible = false;
}

}

private void lineNumberCommandTextBlock_MouseUp(object sender, MouseButtonEventArgs e)
{
// clicked a command area so go to command mode
var context = this.DataContext as LineNumberDisplayModel;
context.IsCommandEntryVisible = true;
lineNumberCommandTextBox.Focus();
}

private void lineNumberCommandTextBox_KeyDown(object sender, KeyEventArgs e)
{
var model = this.DataContext as LineNumberDisplayModel;
if( e.Key == Key.Return)
{
// signal command submitted
model.signalSubmitAllCommands();
}
}

private void lineNumberCommandTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
var model = this.DataContext as LineNumberDisplayModel;
//arrow keys only available on this event. They don't show up on KeyDown
if (e.Key == Key.Right &&
( lineNumberCommandTextBox.Text.Length == 0 ||
lineNumberCommandTextBox.CaretIndex == lineNumberCommandTextBox.Text.Length - 1
)
)
{
// signal that we should move to avalonedit
model.IsCommandEntryVisible = false;
model.signalCommandModeArrowKeyShouldCauseCursorToBeOnAvalonEdit();// I bet we need to pass line number later
} else if( e.Key == Key.Up)
{
// signal that we should move up a line number command
model.IsCommandEntryVisible = false;
model.signalUpArrowKeyPressedInCommandTextBox();
} else if( e.Key == Key.Down)
{
// signal that we should move down a line number command
model.IsCommandEntryVisible = false;
model.signalDownArrowKeyPressedInCommandTextBox();
}
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ILEditor.Classes.AvalonEdit.LineNumberCommandMargin
{
public class LineNumberDisplayModel : WPFHelpers.ViewModelBase
{

public event Action<object, EventArgs> SubmitAllLineNumberCommands;

public class LineNumberEventArgs : EventArgs
{
public int LineNumber { get; set; }
}

public event Action<object, EventArgs> OnSignalToTurnOnCommandMode;
public event Action<object, LineNumberEventArgs> CommandModeKeyPressShouldCauseTransitionToAvalonEditLine;

public event Action<object, LineNumberEventArgs> OnSignalToTurnOnCommandModeForPreviousLineNumber;
public event Action<object, LineNumberEventArgs> OnSignalToTurnOnCommandModeForNextLineNumber;


public int LineNumber
{
get { return this.GetValue(() => this.LineNumber); }
set { this.SetValue(() => this.LineNumber, value); }
}

public string CommandText
{
get { return this.GetValue(() => this.CommandText); }
set {
this.SetValue(() => this.CommandText, value);
OnPropertyChanged(nameof(HasCommandText));
}
}

public bool HasCommandText
{
get
{
return !string.IsNullOrWhiteSpace(CommandText);
}
}

// each line number is a specific height
public double ControlHeight
{
get { return this.GetValue(() => this.ControlHeight); }
set { this.SetValue(() => this.ControlHeight, value); }
}


public bool IsInView
{
get { return this.GetValue(() => this.IsInView); }
set { this.SetValue(() => this.IsInView, value); }
}

// this decided wether to show textbox or label for command
public bool IsCommandEntryVisible
{
get { return this.GetValue(() => this.IsCommandEntryVisible); }
set { this.SetValue(() => this.IsCommandEntryVisible, value); }
}





public void signalSubmitAllCommands()
{
if( this.SubmitAllLineNumberCommands != null)
{
this.SubmitAllLineNumberCommands(this, new EventArgs());
}
}



public void signalTurnOnCommandMode()
{
// user is on a line and they've used the arrow key all the way to the left which should make the cursor jump to command mode
if( this.OnSignalToTurnOnCommandMode != null)
{
this.OnSignalToTurnOnCommandMode(this, new EventArgs());
}
}

public void signalCommandModeArrowKeyShouldCauseCursorToBeOnAvalonEdit()
{
// user was in command mode and they'ved arrowed all the way to the right which should cause command mode to end
// - then the cursor should go to the avalonedit line
if( this.CommandModeKeyPressShouldCauseTransitionToAvalonEditLine != null)
{
this.CommandModeKeyPressShouldCauseTransitionToAvalonEditLine(this, new LineNumberEventArgs
{
LineNumber = this.LineNumber
});
}
}


public void signalUpArrowKeyPressedInCommandTextBox()
{
if( this.OnSignalToTurnOnCommandModeForPreviousLineNumber != null)
{
this.OnSignalToTurnOnCommandModeForPreviousLineNumber(this, new LineNumberEventArgs
{
LineNumber = this.LineNumber
});
}
}

public void signalDownArrowKeyPressedInCommandTextBox()
{
if( this.OnSignalToTurnOnCommandModeForNextLineNumber != null)
{
this.OnSignalToTurnOnCommandModeForNextLineNumber(this, new LineNumberEventArgs
{
LineNumber = this.LineNumber
});
}
}


}
}
Loading