Skip to content

Commit

Permalink
Python Node Editor Visual Update - part DynamoDS#2 (DynamoDS#13763)
Browse files Browse the repository at this point in the history
* Python editor visual restyle - initial commit

- initial commit for python editor visual restyle
- for general idea of the desired scope, visit https://www.figma.com/file/1q7EWQGYO7pPDhyLf8nuwW/Python-node-editor-restyling?node-id=0%3A1&t=QGCSTKllX8Q7OnhK-0

* Icon Update

- updated python scrip editor icons

* Hover icon update

- minor update for one of the icons

* Change hyperlink color

- due to readability issues, changed the hyperlink text color

* Text Folding

- first implementation working

* Custom indentation strategy added

- added custom Python indentation strategy based around line ending with a column

* TabFoldingStrategy changes, saves on Esc exist, WIP

- WIP code, still playing with the avalon editor visual capabilities
- Implemented the 'save on exit' (still missing prompt)
- Folding strategy works more or less correctly, except we are not tracking folded states (which we can) - more work needed, but should we?

* Undo/Redo, Zoom-in/out buttons added

- added buttons for the undo/redo and zoom-in/out functionalities

* Keywords color update

- updated keywords as per latest Figma color scheme

* Warning bar on unsaved changes exit added

- added a warning message with controls when user tries to exit the Script interface by pressing the Escape button, but has unsaved changes
- made Avalon edit support classes Internal

* Fix tab folding

- now will correctly continue after ":" not being the end of the text line (no tabbing)

* Small icons test

- testing screen resolution against 24x24 icons

* Back to 48x48 icons

- updated icons back to 48x48px

* Disable UI when prompt to save changes

- will disable any user interaction while in 'warning' mode
- forces the user to `keep editing` -> `save` -> `close`

* Color brushes replaced with Dynamo brushes where possible

- re[placed with dynamo library brushes where possible

* Localized unsaved changes prompt texts

- unsaved changes prompt title and text localized

* Cleaned up tabfoldingstrategy comments

- removed old or unnecessary comments
- kept comments that help to clarify the logic

* Update ScriptEditorWindow.xaml
  • Loading branch information
dnenov authored and sm6srw committed Mar 29, 2023
1 parent 118f210 commit b40b679
Show file tree
Hide file tree
Showing 10 changed files with 729 additions and 43 deletions.
64 changes: 59 additions & 5 deletions src/Libraries/PythonNodeModels/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion src/Libraries/PythonNodeModels/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@
<data name="PythonScriptEditorRevertButtonTooltip" xml:space="preserve">
<value>Revert the changes made to current Python node editor and close it.</value>
</data>
<data name="PythonScriptEditorUndoButtonTooltip" xml:space="preserve">
<value>Undo</value>
</data>
<data name="PythonScriptEditorRedoButtonTooltip" xml:space="preserve">
<value>Redo</value>
</data>
<data name="PythonScriptEditorZoomInButtonTooltip" xml:space="preserve">
<value>Zoom in</value>
</data>
<data name="PythonScriptEditorZoomOutButtonTooltip" xml:space="preserve">
<value>Zoom out</value>
</data>
<data name="PythonScriptEditorRunButton" xml:space="preserve">
<value>Save and run</value>
</data>
Expand All @@ -196,4 +208,10 @@
<data name="PythonSearchTags" xml:space="preserve">
<value>IronPython;CPython;</value>
</data>
</root>
<data name="PythonScriptUnsavedChangesPromptText" xml:space="preserve">
<value>It looks like you are still working on this. You may lose any unsaved changes if you leave now</value>
</data>
<data name="PythonScriptUnsavedChangesPromptTitle" xml:space="preserve">
<value>Are you sure you want to leave?</value>
</data>
</root>
20 changes: 19 additions & 1 deletion src/Libraries/PythonNodeModels/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@
<data name="PythonScriptEditorRevertButtonTooltip" xml:space="preserve">
<value>Revert the changes made to current Python node editor and close it.</value>
</data>
<data name="PythonScriptEditorUndoButtonTooltip" xml:space="preserve">
<value>Undo</value>
</data>
<data name="PythonScriptEditorRedoButtonTooltip" xml:space="preserve">
<value>Redo</value>
</data>
<data name="PythonScriptEditorZoomInButtonTooltip" xml:space="preserve">
<value>Zoom in</value>
</data>
<data name="PythonScriptEditorZoomOutButtonTooltip" xml:space="preserve">
<value>Zoom out</value>
</data>
<data name="PythonScriptEditorRunButton" xml:space="preserve">
<value>Save and run</value>
</data>
Expand All @@ -197,4 +209,10 @@
<data name="PythonSearchTags" xml:space="preserve">
<value>IronPython;CPython;</value>
</data>
</root>
<data name="PythonScriptUnsavedChangesPromptText" xml:space="preserve">
<value>It looks like you are still working on this. You may lose any unsaved changes if you leave now</value>
</data>
<data name="PythonScriptUnsavedChangesPromptTitle" xml:space="preserve">
<value>Are you sure you want to leave?</value>
</data>
</root>
82 changes: 82 additions & 0 deletions src/Libraries/PythonNodeModelsWpf/PythonIndentationStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Indentation;
using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PythonNodeModelsWpf
{
/// <summary>
/// Custom Indentation Strategy for Python
/// https://csharp.hotexamples.com/site/file?hash=0x1abeea836b72c6db1910df1767e84d7bfcb620ed58a499d176fdf158851c1d5f&fullName=Yanitta/LuaIndentationStrategy.cs&project=Konctantin/Yanitta
/// </summary>
internal class PythonIndentationStrategy : DefaultIndentationStrategy
{
#region Fields

const int indent_space_count = 4;

TextEditor textEditor;

#endregion Fields

#region Constructors

internal PythonIndentationStrategy(TextEditor textEditor)
{
this.textEditor = textEditor;
}

#endregion Constructors


/// <inheritdoc cref="IIndentationStrategy.IndentLine"/>
public override void IndentLine(TextDocument document, DocumentLine line)
{
if (line?.PreviousLine == null)
return;

var prevLine = document.GetText(line.PreviousLine.Offset, line.PreviousLine.Length);
var curLine = document.GetText(line.Offset, line.Length);
int prev = CalcSpace(prevLine);

var previousIsComment = prevLine.TrimStart().StartsWith("#", StringComparison.CurrentCulture);

// If the current line ends with a column and was not followed by a comment
if (curLine.EndsWith(":") && !previousIsComment)
{
var ind = new string(' ', prev);
document.Insert(line.Offset, ind);
}
// If the previous line ends with a column and was not followed by a comment
// We should indent
else if (prevLine.EndsWith(":") && !previousIsComment)
{
var ind = new string(' ', prev + indent_space_count);
document.Insert(line.Offset, ind);
}
else
{
var ind = new string(' ', prev);
if (line != null)
document.Insert(line.Offset, ind);
}
}

// Calculates the amount of white space leading in a string
private int CalcSpace(string str)
{
for (int i = 0; i < str.Length; ++i)
{
if (!char.IsWhiteSpace(str[i]))
return i;
if (i == str.Length - 1)
return str.Length;
}
return 0;
}
}
}
2 changes: 2 additions & 0 deletions src/Libraries/PythonNodeModelsWpf/PythonNodeModelsWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ReferenceCopyLocalPaths>
</ItemDefinitionGroup>
<ItemGroup>
<None Remove="Resources\alert.png" />
<None Remove="Resources\convert.png" />
<None Remove="Resources\convert_hover.png" />
<None Remove="Resources\question-filled.png" />
Expand Down Expand Up @@ -78,6 +79,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\alert.png" />
<Resource Include="Resources\convert.png" />
<EmbeddedResource Include="Resources\ICSharpCode.PythonBinding.Resources.Python.xshd">
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<KeyWords name="ClassStatement" color="#E0A86F" bold="false">
<Key word="class" />
</KeyWords>
<KeyWords name="ExceptionHandlingStatements" bold="false" color="#F92672">
<KeyWords name="ExceptionHandlingStatements" bold="false" color="#BC8CDF">
<Key word="except" />
<Key word="finally" />
<Key word="raise" />
Expand All @@ -58,37 +58,37 @@
<KeyWords name="FunctionDefinition" italic="true" color="#66D9EF">
<Key word="def" />
</KeyWords>
<KeyWords name="Imports" bold="false" color="#F2A9F2">
<KeyWords name="Imports" bold="false" color="#F5C1D1">
<Key word="import" />
<Key word="from" />
</KeyWords>
<KeyWords name="IterationStatements" bold="false" color="#F92672">
<KeyWords name="IterationStatements" bold="false" color="#BC8CDF">
<Key word="for" />
<Key word="in" />
<Key word="while" />
</KeyWords>
<KeyWords name="JumpStatements" color="#F92672">
<KeyWords name="JumpStatements" color="#BC8CDF">
<Key word="break" />
<Key word="continue" />
<Key word="yield" />
<Key word="return" />
</KeyWords>
<KeyWords name="OperatorStatements" bold="true" color="#F92672">
<KeyWords name="OperatorStatements" bold="true" color="#BC8CDF">
<Key word="and" />
<Key word="as" />
<Key word="is" />
<Key word="not" />
<Key word="or" />
</KeyWords>
<KeyWords name="PassStatement" color="#F92672">
<KeyWords name="PassStatement" color="#BC8CDF">
<Key word="pass" />
</KeyWords>
<KeyWords name="SelectionStatements" bold="true" color="#F92672">
<KeyWords name="SelectionStatements" bold="true" color="#BC8CDF">
<Key word="elif" />
<Key word="else" />
<Key word="if" />
</KeyWords>
<KeyWords name="WithStatement" color="#F92672">
<KeyWords name="WithStatement" color="#BC8CDF">
<Key word="with" />
</KeyWords>
</RuleSet>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b40b679

Please sign in to comment.