Skip to content

Commit

Permalink
C-style relational operators
Browse files Browse the repository at this point in the history
Added support for C-style relational operators: == , !=, >=, <=.
Fixed save as to cpd for cpdz files.
Fixed input fields counting in code.
Fixed resetting input fields to zero after editing the source code.
Html select input is replaced with text in output only if class "post" is added.
  • Loading branch information
Proektsoftbg committed Aug 16, 2022
1 parent 6a16111 commit 4112feb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
30 changes: 23 additions & 7 deletions Calcpad.Wpf/HighLighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,17 @@ internal void Parse(Paragraph p, bool isComplex, int line)
if (p is null)
return;

if (p.Tag is Queue<string> queue)
_values = queue;
else
GetValues(p);

var text = InitParagraph(p);
InitState(p, text, line);
_tagHelper = new();
LocalVariables.Clear();
_hasTargetUnitsDelimiter = false;
_allowUnaryMinus = true;

if (_state.Paragraph.Tag is Queue<string> queue)
_values = queue;
else
GetValues(_state.Paragraph);

_builder.Clear();
for (int i = 0, len = text.Length; i < len; ++i)
{
Expand Down Expand Up @@ -748,8 +747,25 @@ private void Append(Types t)
return;

var s = _builder.ToString();
string sourceCode = string.Empty;
_builder.Clear();
var count = _state.Paragraph.Inlines.Count;
if (s == "=" && count > 0)
{
Run r = (Run)_state.Paragraph.Inlines.LastInline;
var runText = r.Text;
if (runText == " = " || runText == "!" || runText == " > " || runText == " < ")
{
r.Text = runText switch
{
" = " => " ≡ ",
"!" => " ≠ ",
" > " => " ≥ ",
_ => " ≤ "
};
return;
}
}
string sourceCode = string.Empty;
if (t == Types.Include)
{
var sourceFlieName = s.Trim();
Expand Down
20 changes: 10 additions & 10 deletions Calcpad.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,16 @@ private void RecentFileList_Click(object sender, RoutedEventArgs e)
if (File.Exists(fileName))
FileOpen(fileName);
}

private void Command_SaveAs(object sender, ExecutedRoutedEventArgs e) => FileSaveAs();

private void FileSaveAs()
{
string s;
if (string.IsNullOrWhiteSpace(CurrentFileName))
var count = CountInputFields(InputText);
if (!string.IsNullOrWhiteSpace(CurrentFileName))
s = Path.GetExtension(CurrentFileName);
else if (InputText.Contains('?', StringComparison.Ordinal))
else if (count > 0)
s = ".cpd";
else
s = ".txt";
Expand Down Expand Up @@ -2128,8 +2129,7 @@ private void RichTextBox_SelectionChanged(object sender, RoutedEventArgs e)
return;

var p = tps.Paragraph;
if (p is null)
p = tpe.Paragraph;
p ??= tpe.Paragraph;

if (!ReferenceEquals(_currentParagraph, tps.Paragraph) &&
!ReferenceEquals(_currentParagraph, tpe.Paragraph))
Expand Down Expand Up @@ -2576,8 +2576,7 @@ private void HighLightPastedText()
RichTextBox.BeginChange();
var p = _pasteEnd.Paragraph;
_currentParagraph = RichTextBox.Selection.Start.Paragraph;
if (p is null)
p = (Paragraph)_document.Blocks.FirstBlock;
p ??= (Paragraph)_document.Blocks.FirstBlock;

var lineNumber = GetLineNumber(p);
while (p != _currentParagraph)
Expand Down Expand Up @@ -2765,8 +2764,7 @@ private void Include_Click(object sender, MouseButtonEventArgs e)
if (tt is not null)
tt.Visibility = Visibility.Hidden;
var process = RunExternalApp("NOTEPAD++", fileName);
if (process is null)
process = RunExternalApp("NOTEPAD", fileName);
process ??= RunExternalApp("NOTEPAD", fileName);
if (tt is not null)
tt.Visibility = Visibility.Visible;
if (process is not null)
Expand Down Expand Up @@ -2847,7 +2845,9 @@ private static int CountInputFields(string s)
char commentChar = nullChar;
foreach (var c in s)
{
if (c == '\'' || c == '"')
if (c == '\n')
commentChar = nullChar;
else if (c == '\'' || c == '"')
{
if (commentChar == nullChar)
commentChar = c;
Expand Down
Binary file modified Setup/calcpad-setup-en-x64.exe
Binary file not shown.

0 comments on commit 4112feb

Please sign in to comment.