forked from DynamoDS/Dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python Node Editor Visual Update - part DynamoDS#2 (DynamoDS#13763)
* 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
Showing
10 changed files
with
729 additions
and
43 deletions.
There are no files selected for viewing
64 changes: 59 additions & 5 deletions
64
src/Libraries/PythonNodeModels/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Libraries/PythonNodeModelsWpf/PythonIndentationStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.