@@ -62,7 +62,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6262using ScriptNotepadPluginBase . PluginTemplateInterface ;
6363using System ;
6464using System . Collections . Generic ;
65- using System . ComponentModel ;
6665using System . Diagnostics ;
6766using System . Diagnostics . CodeAnalysis ;
6867using System . Drawing ;
@@ -71,7 +70,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
7170using System . Reflection ;
7271using System . Text ;
7372using System . Threading ;
74- using System . Windows . Controls ;
7573using System . Windows . Forms ;
7674using RpcSelf ;
7775using ScriptNotepad . Database . DirectAccess ;
@@ -99,7 +97,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9997using ScriptNotepad . Editor . Utility . ModelHelpers ;
10098using ScriptNotepad . UtilityClasses . EventArguments ;
10199using ScriptNotepad . UtilityClasses . TextManipulation . BaseClasses ;
102- using ScriptNotepad . UtilityClasses . TextManipulation . Interfaces ;
103100using VPKSoft . DBLocalization ;
104101using FileSaveHelper = ScriptNotepad . Editor . Utility . ModelHelpers . FileSaveHelper ;
105102using FileSessionHelper = ScriptNotepad . Editor . EntityHelpers . FileSessionHelper ;
@@ -1950,7 +1947,7 @@ private void SaveDocument(ScintillaTabbedDocument document, bool saveAs)
19501947 // only an existing file can be saved directly..
19511948 if ( fileSave . ExistsInFileSystem && ! saveAs )
19521949 {
1953- File . WriteAllBytes ( fileSave . FileNameFull , fileSave . GetFileContents ( ) ) ;
1950+ File . WriteAllBytes ( fileSave . FileNameFull , fileSave . GetFileContents ( ) ?? Array . Empty < byte > ( ) ) ;
19541951
19551952 // update the file system modified time stamp so the software doesn't ask if the file should
19561953 // be reloaded from the file system..
@@ -1977,7 +1974,7 @@ private void SaveDocument(ScintillaTabbedDocument document, bool saveAs)
19771974 fileSave . FileSystemModified = DateTime . Now ;
19781975
19791976 // write the new contents of a file to the existing file overriding it's contents..
1980- File . WriteAllBytes ( sdAnyFile . FileName , fileSave . GetFileContents ( ) ) ;
1977+ File . WriteAllBytes ( sdAnyFile . FileName , fileSave . GetFileContents ( ) ?? Array . Empty < byte > ( ) ) ;
19811978
19821979 // the file now exists in the file system..
19831980 fileSave . ExistsInFileSystem = true ;
@@ -2766,6 +2763,118 @@ private void mnuManageScriptSnippets_Click(object sender, EventArgs e)
27662763 FormDialogScriptLoad . Execute ( true ) ;
27672764 }
27682765
2766+ // fold the current level..
2767+ private void mnuFoldCurrentLevel_Click ( object sender , EventArgs e )
2768+ {
2769+ CurrentDocumentAction ( document =>
2770+ {
2771+ if ( document . Scintilla . CurrentLine != - 1 )
2772+ {
2773+ var parent = document . Scintilla . Lines [ document . Scintilla . CurrentLine ] . FoldParent ;
2774+ if ( parent >= 0 )
2775+ {
2776+ document . Scintilla . Lines [ parent ] . FoldLine ( sender . Equals ( mnuFoldCurrentLevel ) ? FoldAction . Contract : FoldAction . Expand ) ;
2777+ }
2778+ }
2779+ } ) ;
2780+ }
2781+
2782+ // fold a specified level..
2783+ private void mnuFold1_Click ( object sender , EventArgs e )
2784+ {
2785+ var level = 1 ;
2786+ if ( sender . Equals ( mnuFold2 ) )
2787+ {
2788+ level = 2 ;
2789+ }
2790+ else if ( sender . Equals ( mnuFold3 ) )
2791+ {
2792+ level = 3 ;
2793+ }
2794+ else if ( sender . Equals ( mnuFold4 ) )
2795+ {
2796+ level = 4 ;
2797+ }
2798+ else if ( sender . Equals ( mnuFold5 ) )
2799+ {
2800+ level = 5 ;
2801+ }
2802+ else if ( sender . Equals ( mnuFold6 ) )
2803+ {
2804+ level = 6 ;
2805+ }
2806+ else if ( sender . Equals ( mnuFold7 ) )
2807+ {
2808+ level = 7 ;
2809+ }
2810+ else if ( sender . Equals ( mnuFold8 ) )
2811+ {
2812+ level = 8 ;
2813+ }
2814+
2815+ CurrentDocumentAction ( document =>
2816+ {
2817+ if ( document . Scintilla . CurrentLine != - 1 )
2818+ {
2819+ foreach ( var scintillaLine in document . Scintilla . Lines )
2820+ {
2821+ if ( scintillaLine . FoldLevel - 1023 == level )
2822+ {
2823+ scintillaLine . FoldLine ( FoldAction . Contract ) ;
2824+ }
2825+ }
2826+ }
2827+ } ) ;
2828+ }
2829+
2830+ // unfold a specified level..
2831+ private void mnuUnfold1_Click ( object sender , EventArgs e )
2832+ {
2833+ var level = 1 ;
2834+ if ( sender . Equals ( mnuUnfold2 ) )
2835+ {
2836+ level = 2 ;
2837+ }
2838+ else if ( sender . Equals ( mnuUnfold3 ) )
2839+ {
2840+ level = 3 ;
2841+ }
2842+ else if ( sender . Equals ( mnuUnfold4 ) )
2843+ {
2844+ level = 4 ;
2845+ }
2846+ else if ( sender . Equals ( mnuUnfold5 ) )
2847+ {
2848+ level = 5 ;
2849+ }
2850+ else if ( sender . Equals ( mnuUnfold6 ) )
2851+ {
2852+ level = 6 ;
2853+ }
2854+ else if ( sender . Equals ( mnuUnfold7 ) )
2855+ {
2856+ level = 7 ;
2857+ }
2858+ else if ( sender . Equals ( mnuUnfold8 ) )
2859+ {
2860+ level = 8 ;
2861+ }
2862+
2863+ CurrentDocumentAction ( document =>
2864+ {
2865+ if ( document . Scintilla . CurrentLine != - 1 )
2866+ {
2867+ foreach ( var scintillaLine in document . Scintilla . Lines )
2868+ {
2869+ if ( scintillaLine . FoldLevel - 1023 == level )
2870+ {
2871+ scintillaLine . FoldLine ( FoldAction . Expand ) ;
2872+ }
2873+ }
2874+ }
2875+ } ) ;
2876+ }
2877+
27692878 // a user wanted to find or find and replace something of the active document..
27702879 private void mnuFind_Click ( object sender , EventArgs e )
27712880 {
@@ -3389,10 +3498,14 @@ private void StyleSelectOf_Click(object sender, EventArgs e)
33893498 {
33903499 if ( sttcMain . CurrentDocument != null )
33913500 {
3392- int styleNum = int . Parse ( ( ( ToolStripMenuItem ) sender ) . Tag . ToString ( ) ) ;
3501+ int styleNum = int . Parse ( ( ( ToolStripMenuItem ) sender ) . Tag . ToString ( ) ?? "-1" ) ;
3502+
33933503
3394- Highlight . HighlightWords ( sttcMain . CurrentDocument . Scintilla , styleNum ,
3395- sttcMain . CurrentDocument . Scintilla . SelectedText , FormSettings . Settings . GetMarkColor ( styleNum - 9 ) ) ;
3504+ if ( styleNum != - 1 )
3505+ {
3506+ Highlight . HighlightWords ( sttcMain . CurrentDocument . Scintilla , styleNum ,
3507+ sttcMain . CurrentDocument . Scintilla . SelectedText , FormSettings . Settings . GetMarkColor ( styleNum - 9 ) ) ;
3508+ }
33963509 }
33973510 }
33983511
@@ -3402,7 +3515,7 @@ private void ClearStyleOf_Click(object sender, EventArgs e)
34023515 if ( sttcMain . CurrentDocument != null )
34033516 {
34043517 Highlight . ClearStyle ( sttcMain . CurrentDocument . Scintilla ,
3405- int . Parse ( ( ( ToolStripMenuItem ) sender ) . Tag . ToString ( ) ) ) ;
3518+ int . Parse ( ( ( ToolStripMenuItem ) sender ) . Tag . ToString ( ) ?? "-1" ) ) ;
34063519 }
34073520 }
34083521
@@ -4093,114 +4206,5 @@ private void MnuShowWrapSymbol_Click(object sender, EventArgs e)
40934206 : WrapVisualFlags . None ) ;
40944207 }
40954208 #endregion
4096-
4097- private void mnuFoldCurrentLevel_Click ( object sender , EventArgs e )
4098- {
4099- CurrentDocumentAction ( document =>
4100- {
4101- if ( document . Scintilla . CurrentLine != - 1 )
4102- {
4103- var parent = document . Scintilla . Lines [ document . Scintilla . CurrentLine ] . FoldParent ;
4104- if ( parent >= 0 )
4105- {
4106- document . Scintilla . Lines [ parent ] . FoldLine ( sender . Equals ( mnuFoldCurrentLevel ) ? FoldAction . Contract : FoldAction . Expand ) ;
4107- }
4108- }
4109- } ) ;
4110- }
4111-
4112- private void mnuFold1_Click ( object sender , EventArgs e )
4113- {
4114- var level = 1 ;
4115- if ( sender . Equals ( mnuFold2 ) )
4116- {
4117- level = 2 ;
4118- }
4119- else if ( sender . Equals ( mnuFold3 ) )
4120- {
4121- level = 3 ;
4122- }
4123- else if ( sender . Equals ( mnuFold4 ) )
4124- {
4125- level = 4 ;
4126- }
4127- else if ( sender . Equals ( mnuFold5 ) )
4128- {
4129- level = 5 ;
4130- }
4131- else if ( sender . Equals ( mnuFold6 ) )
4132- {
4133- level = 6 ;
4134- }
4135- else if ( sender . Equals ( mnuFold7 ) )
4136- {
4137- level = 7 ;
4138- }
4139- else if ( sender . Equals ( mnuFold8 ) )
4140- {
4141- level = 8 ;
4142- }
4143-
4144- CurrentDocumentAction ( document =>
4145- {
4146- if ( document . Scintilla . CurrentLine != - 1 )
4147- {
4148- foreach ( var scintillaLine in document . Scintilla . Lines )
4149- {
4150- if ( scintillaLine . FoldLevel - 1023 == level )
4151- {
4152- scintillaLine . FoldLine ( FoldAction . Contract ) ;
4153- }
4154- }
4155- }
4156- } ) ;
4157- }
4158-
4159- private void mnuUnfold1_Click ( object sender , EventArgs e )
4160- {
4161- var level = 1 ;
4162- if ( sender . Equals ( mnuUnfold2 ) )
4163- {
4164- level = 2 ;
4165- }
4166- else if ( sender . Equals ( mnuUnfold3 ) )
4167- {
4168- level = 3 ;
4169- }
4170- else if ( sender . Equals ( mnuUnfold4 ) )
4171- {
4172- level = 4 ;
4173- }
4174- else if ( sender . Equals ( mnuUnfold5 ) )
4175- {
4176- level = 5 ;
4177- }
4178- else if ( sender . Equals ( mnuUnfold6 ) )
4179- {
4180- level = 6 ;
4181- }
4182- else if ( sender . Equals ( mnuUnfold7 ) )
4183- {
4184- level = 7 ;
4185- }
4186- else if ( sender . Equals ( mnuUnfold8 ) )
4187- {
4188- level = 8 ;
4189- }
4190-
4191- CurrentDocumentAction ( document =>
4192- {
4193- if ( document . Scintilla . CurrentLine != - 1 )
4194- {
4195- foreach ( var scintillaLine in document . Scintilla . Lines )
4196- {
4197- if ( scintillaLine . FoldLevel - 1023 == level )
4198- {
4199- scintillaLine . FoldLine ( FoldAction . Expand ) ;
4200- }
4201- }
4202- }
4203- } ) ;
4204- }
42054209 }
42064210}
0 commit comments