diff --git a/App.xojo_code b/App.xojo_code index e7ec314..e2fb8b7 100644 --- a/App.xojo_code +++ b/App.xojo_code @@ -203,6 +203,12 @@ Inherits Application #Tag Instance, Platform = Linux, Language = Default, Definition = \"&Delete" #tag EndConstant + #tag Constant, Name = kEditComment, Type = String, Dynamic = False, Default = \"Comment", Scope = Public + #tag EndConstant + + #tag Constant, Name = kEditUncomment, Type = String, Dynamic = False, Default = \"Uncomment", Scope = Public + #tag EndConstant + #tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public #Tag Instance, Platform = Windows, Language = Default, Definition = \"E&xit" #tag EndConstant diff --git a/Classes/IDEEmulator.xojo_code b/Classes/IDEEmulator.xojo_code index 65e27b1..08f32a6 100644 --- a/Classes/IDEEmulator.xojo_code +++ b/Classes/IDEEmulator.xojo_code @@ -2,14 +2,24 @@ Protected Class IDEEmulator #tag Method, Flags = &h1 Protected Sub Beep() + Extras.ShowWarning + End Sub + #tag EndMethod + + #tag Method, Flags = &h1 + Protected Sub BuildApp(buildType As Integer) + #pragma unused buildType + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 - Protected Function BuildApp(buildType As Integer, reveal As Boolean = False) As String + Protected Function BuildApp(buildType As Integer, reveal As Boolean) As String #pragma unused buildType #pragma unused reveal + + Extras.ShowWarning End Function #tag EndMethod @@ -21,12 +31,15 @@ Protected Class IDEEmulator #pragma unused scope #pragma unused implement + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function ConstantValue(name As String) As String #pragma unused name + + Extras.ShowWarning End Function #tag EndMethod @@ -34,42 +47,50 @@ Protected Class IDEEmulator Protected Sub ConstantValue(name As String, Assigns value As String) #pragma unused name #pragma unused value + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function CurrentBuildAppName() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function CurrentBuildLocation() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function CurrentBuildTarget() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function DecryptItem(password As String) As Boolean #pragma unused password + + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Sub DoCommand(cmd As String) #pragma unused cmd + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function DoShellCommand(cmd As String) As String #pragma unused cmd + + Extras.ShowWarning End Function #tag EndMethod @@ -79,60 +100,68 @@ Protected Class IDEEmulator #pragma unused timeOut #pragma unused resultCode + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function EncryptItem(password As String) As Boolean #pragma unused password + + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function EndOfLine() As String + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Sub NewConsoleProject() - + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub NewGUIProject() - + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub NewWebProject() - + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub OpenFile(filePath As String) #pragma unused filePath + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function ProjectItem() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function ProjectShellPath() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function PropertyValue(name As String) As String #pragma unused name + + Extras.ShowWarning End Function #tag EndMethod @@ -140,36 +169,48 @@ Protected Class IDEEmulator Protected Sub PropertyValue(name As String, Assigns value As String) #pragma unused name #pragma unused value + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub QuitIDE(saveChanges As Boolean) #pragma unused saveChanges + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub RunScript(name As String) #pragma unused name + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function SelectProjectItem(itemPath As String) As Boolean #pragma unused itemPath + + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Sub SelectWindow(index As Integer) #pragma unused index + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub SelectWindow(windowTitle As String) #pragma unused windowTitle + + Extras.ShowWarning End Sub #tag EndMethod @@ -179,6 +220,7 @@ Protected Class IDEEmulator #pragma unused explanation #pragma unused defaultButtonCaption + Extras.ShowWarning End Function #tag EndMethod @@ -189,6 +231,7 @@ Protected Class IDEEmulator #pragma unused defaultButtonCaption #pragma unused CancelButtonCaption + Extras.ShowWarning End Function #tag EndMethod @@ -200,6 +243,7 @@ Protected Class IDEEmulator #pragma unused CancelButtonCaption #pragma unused altButtonCaption + Extras.ShowWarning End Function #tag EndMethod @@ -212,112 +256,345 @@ Protected Class IDEEmulator #pragma unused altButtonCaption #pragma unused icon + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Sub ShowURL(url As String) #pragma unused url + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Sub Speak(s As String) #pragma unused s + + Extras.ShowWarning End Sub #tag EndMethod #tag Method, Flags = &h1 Protected Function SubLocation(baseLocation As String) As String #pragma unused baseLocation + + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function TypeOfCurrentLocation() As String - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Function WindowCount() As Integer - + Extras.ShowWarning End Function #tag EndMethod #tag Method, Flags = &h1 Protected Sub WindowTitle(index As Integer) #pragma unused index + + Extras.ShowWarning End Sub #tag EndMethod - #tag Property, Flags = &h1 + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildCurrentPlatform As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildLanguage As String - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildLinux As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildMacCocoa As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 - Protected BuildMacMachOx86 As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h0 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter + BuildMacMachOx86 As Boolean + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildRegion As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildWebDebugPort As Integer - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildWebPort As Integer - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildWebProtocol As Integer - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected BuildWin32 As Boolean - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected Clipboard As String - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h21 + #tag Getter + Get + if mExtras is nil then + mExtras = new IDEEmulatorExtras + end if + + return mExtras + End Get + #tag EndGetter + Attributes( exclude ) Private Extras As IDEEmulatorExtras + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected Location As String - #tag EndProperty + #tag EndComputedProperty - #tag Property, Flags = &h1 - Protected SelLength As Integer + #tag Property, Flags = &h21 + Attributes( exclude ) Private mExtras As IDEEmulatorExtras #tag EndProperty - #tag Property, Flags = &h1 + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter + Protected SelLength As Integer + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected SelStart As Integer - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected SelText As String - #tag EndProperty - - #tag Property, Flags = &h1 + #tag EndComputedProperty + + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Extras.ShowWarning + End Get + #tag EndGetter + #tag Setter + Set + #pragma unused value + + Extras.ShowWarning + End Set + #tag EndSetter Protected Text As String - #tag EndProperty + #tag EndComputedProperty #tag ViewBehavior + #tag ViewProperty + Name="BuildMacMachOx86" + Group="Behavior" + Type="Boolean" + #tag EndViewProperty + #tag ViewProperty + Name="BuildWebProtocol" + Group="Behavior" + Type="Integer" + #tag EndViewProperty + #tag ViewProperty + Name="BuildWin32" + Group="Behavior" + Type="Boolean" + #tag EndViewProperty #tag ViewProperty Name="Index" Visible=true @@ -332,6 +609,11 @@ Protected Class IDEEmulator InitialValue="0" Type="Integer" #tag EndViewProperty + #tag ViewProperty + Name="Location" + Group="Behavior" + Type="String" + #tag EndViewProperty #tag ViewProperty Name="Name" Visible=true diff --git a/Classes/IDEEmulatorExtras.xojo_code b/Classes/IDEEmulatorExtras.xojo_code new file mode 100644 index 0000000..1929004 --- /dev/null +++ b/Classes/IDEEmulatorExtras.xojo_code @@ -0,0 +1,57 @@ +#tag Class +Protected Class IDEEmulatorExtras + #tag Method, Flags = &h0 + Sub ShowWarning() + if not WasWarningShown then + MsgBox "You are running an IDE script within XsEdit. " + _ + "While the methods, functions, and properties available to you within the IDE are replicated here, " + _ + "they are only to allow compilation and do not perform any true function or return a value." + WasWarningShown = true + end if + + End Sub + #tag EndMethod + + + #tag Property, Flags = &h0 + WasWarningShown As Boolean + #tag EndProperty + + + #tag ViewBehavior + #tag ViewProperty + Name="Index" + Visible=true + Group="ID" + InitialValue="-2147483648" + Type="Integer" + #tag EndViewProperty + #tag ViewProperty + Name="Left" + Visible=true + Group="Position" + InitialValue="0" + Type="Integer" + #tag EndViewProperty + #tag ViewProperty + Name="Name" + Visible=true + Group="ID" + Type="String" + #tag EndViewProperty + #tag ViewProperty + Name="Super" + Visible=true + Group="ID" + Type="String" + #tag EndViewProperty + #tag ViewProperty + Name="Top" + Visible=true + Group="Position" + InitialValue="0" + Type="Integer" + #tag EndViewProperty + #tag EndViewBehavior +End Class +#tag EndClass diff --git a/Example Scripts/Pair & Dictionary.xojo_script b/Example Scripts/Pair & Dictionary.xojo_script new file mode 100644 index 0000000..6a83269 --- /dev/null +++ b/Example Scripts/Pair & Dictionary.xojo_script @@ -0,0 +1,244 @@ +Class Pair +Dim LeftValue As Variant +Dim RightValue As Variant + +Sub Constructor() + +End Sub + +Sub Constructor( leftValue As Variant, rightValue As Variant ) +self.LeftValue = leftValue +self.RightValue = rightValue +End Sub +End Class + +Class Dictionary +Private Const kBinCount = 10000 + +Private Bins() As Variant +Private mIsCaseSensitive As Boolean + +Private Function KeyToStorageKey( key As Variant ) As Variant +if not mIsCaseSensitive then +select case key.Type +case Variant.TypeString, Variant.TypeText +key = key.StringValue.Lowercase +end select +end if + +return key +End Function + +Private Function StorageIndexOf( storageKeyArr() As Variant, storageKey As Variant ) As Integer +if mIsCaseSensitive and _ +( storageKey.Type = Variant.TypeString or storageKey.Type = Variant.TypeText ) then +dim storageKeyString as string = storageKey.StringValue + +for i as integer = 0 to storageKeyArr.Ubound +dim thisKey as variant = storageKeyArr( i ) +select case thisKey.Type +case Variant.TypeString, Variant.TypeText +if StrComp( thisKey.StringValue, storageKeyString, 0 ) = 0 then +return i +end if + +case else +if thisKey = storageKey then +return i +end if +end select +next i + +else + +for i as integer = 0 to storageKeyArr.Ubound +dim thisKey as variant = storageKeyArr( i ) +if thisKey = storageKey then +return i +end if +next i + +end if + +return -1 +End Function + +Private Sub GetIndexes( key As Variant, ByRef binIndex As Integer, ByRef subBinIndex As Integer ) +dim storageKey as variant = KeyToStorageKey( key ) + +dim keyHash as UInt64 = storageKey.Hash +binIndex = keyHash mod kBinCount +if binIndex > Bins.Ubound or Bins( binIndex ).IsNull then +subBinIndex = -1 +else +dim entry as Pair = Bins( binIndex ) +dim storageKeyArr() as variant = entry.LeftValue + +subBinIndex = StorageIndexOf( storageKeyArr, storageKey ) +end if + +'print "key: " + key + _ +'", sk: " + storageKey + _ +'", hash: " + str( keyHash ) + _ +'", binIndex: " + str( binIndex ) + _ +'", subBinIndex: " + str( subBinIndex ) +End Sub + +Sub Constructor( caseSensitive As Boolean = False ) +mIsCaseSensitive = caseSensitive +End Sub + +Function IsCaseSensitive() As Boolean +return mIsCaseSensitive +End Function + +Function HasKey( key As Variant ) As Boolean +dim binIndex as integer +dim subBinIndex as integer +GetIndexes( key, binIndex, subBinIndex ) +return subBinIndex <> -1 +End Function + +Function Value( key As Variant ) As Variant +dim binIndex as integer +dim subBinIndex as integer +GetIndexes( key, binIndex, subBinIndex ) + +dim entry as Pair = Bins( binIndex ) +dim p as Pair = entry.RightValue +dim valueArr() as variant = p.RightValue +return valueArr( subBinIndex ) + +End Function + +Sub Value( key As Variant, Assigns value As Variant ) +dim binIndex as integer +dim subBinIndex as integer +GetIndexes( key, binIndex, subBinIndex ) + +if Bins.Ubound < binIndex then +redim Bins( binIndex ) +end if + +dim storageKeyArr() as variant +dim keyArr() as variant +dim valueArr() as variant +dim entry as Pair +if Bins( binIndex ).IsNull then +entry = new Pair( storageKeyArr, new Pair( keyArr, valueArr ) ) +Bins( binIndex ) = entry +else +entry = Bins( binIndex ) +storageKeyArr = entry.LeftValue +dim p as Pair = entry.RightValue +keyArr = p.LeftValue +valueArr = p.RightValue +end if + +if subBinIndex = -1 then +storageKeyArr.Append KeyToStorageKey( key ) +keyArr.Append key +valueArr.Append value +else +valueArr( subBinIndex ) = value +end if +End Sub + +Function Keys() as Variant() +dim r() as variant +for binIndex as integer = 0 to Bins.Ubound +dim entry as Pair = Bins( binIndex ) +if entry is nil then +continue for binIndex +end if + +dim p as Pair = entry.RightValue +dim keyArr() as variant = p.LeftValue +for keyIndex as integer = 0 to keyArr.Ubound +dim key as variant = keyArr( keyIndex ) +r.Append key +next +next +return r +End Function + +Function Values() as Variant() +dim r() as variant +for binIndex as integer = 0 to Bins.Ubound +dim entry as Pair = Bins( binIndex ) +if entry is nil then +continue for binIndex +end if + +dim p as Pair = entry.RightValue +dim valueArr() as variant = p.RightValue +for keyIndex as integer = 0 to valueArr.Ubound +dim value as variant = valueArr( keyIndex ) +r.Append value +next +next +return r +End Function + +Private Sub PrintVariantArray( arr() as Variant ) +dim s() as string +for i as integer = 0 to arr.Ubound +dim v as variant = arr( i ) +select case v.Type +case Variant.TypeString, Variant.TypeText +s.Append """" + v.StringValue + """" +case Variant.TypeBoolean, Variant.TypeInteger, Variant.TypeDouble, Variant.TypeSingle, Variant.TypeColor +s.Append v +case Variant.TypeNil +s.Append "nil" +case else +s.Append "" +end select +next +print join( s, ", " ) +End Sub + +Sub PrintKeys() +PrintVariantArray( self.Keys ) +End Sub + +Sub PrintValues() +PrintVariantArray( self.Values ) +End Sub +End Class + +dim startms as double = Microseconds +dim d as Dictionary = new Dictionary( true ) +for i as integer = 1 to 1000 +d.Value( i ) = nil +next +dim endms as double = Microseconds +print format( endms - startms, "#," ) + +d = new Dictionary( false ) + +d.Value( 12 ) = 12 +d.Value( "a" ) = "a" +d.Value( "A" ) = "b" + +print d.Value( "a" ) +if d.HasKey( 1 ) then +print "what?!?" +end if + +d.Value( 1 ) = nil +if d.HasKey( 1 ) then +print "ok then" +end if + +if d.HasKey( "1" ) then +print "well, that makes no sense" +end if + +print "last section" +d.Value( 13 ) = &cFFFFFF +d.Value( new Pair ) = "pair" + +print "printing keys" +d.PrintKeys +d.PrintValues \ No newline at end of file diff --git a/Example Scripts/With Included.xojo_script b/Example Scripts/With Included.xojo_script index 57a3faf..e1a82e5 100644 --- a/Example Scripts/With Included.xojo_script +++ b/Example Scripts/With Included.xojo_script @@ -1 +1,5 @@ -print "before included" '#include ~ktekinay/Desktop/../Desktop/Included.xojo_script '#include ../Desktop/Included.xojo_script '#include /Users/ktekinay/Documents/../Desktop/Bozo/../Included.xojo_script print "after included" \ No newline at end of file +print "before included" +'#include ~ktekinay/Desktop/../Desktop/Included.xojo_script +'#include ../Desktop/Included.xojo_script +'#include /Users/ktekinay/Documents/../Desktop/Bozo/../Included.xojo_script +print "after included" \ No newline at end of file diff --git a/Menu Stuff/MainMenuBar.xojo_menu b/Menu Stuff/MainMenuBar.xojo_menu index 855bd6c..55174dd 100644 --- a/Menu Stuff/MainMenuBar.xojo_menu +++ b/Menu Stuff/MainMenuBar.xojo_menu @@ -178,7 +178,7 @@ Begin Menu MainMenuBar End Begin MenuItem EditComment SpecialMenu = 0 - Text = "Comment" + Text = "#App.kEditComment" Index = -2147483648 ShortcutKey = "'" Shortcut = "Cmd+'" @@ -186,17 +186,6 @@ Begin Menu MainMenuBar AutoEnable = True Visible = True End - Begin MenuItem EditUncomment - SpecialMenu = 0 - Text = "Uncomment" - Index = -2147483648 - ShortcutKey = "'" - Shortcut = "Cmd+Shift+'" - MenuModifier = True - AltMenuModifier = True - AutoEnable = True - Visible = True - End Begin MenuItem UntitledSeparator5 SpecialMenu = 0 Text = "-" diff --git a/README.md b/README.md index 1256b0c..4321f8a 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,10 @@ Fork the project to your GitHub account. Use the "develop" branch for general fi - Initial release. +1.1 (July 9, 2015) + +- Emulated methods, functions, and properties will show a message if used in a script that's run within XsEdit. +- Fixed bug in CustomEditField that munged the test when pasting multiple lines at once. +- Added additional keywords. +- Files will be saved with the EOL for the given platform. +- Comment/Uncomment has been combined and improved. diff --git a/Third Party Classes/CustomEditField/CustomEditField.xojo_code b/Third Party Classes/CustomEditField/CustomEditField.xojo_code index 9f0dad4..0469e02 100644 --- a/Third Party Classes/CustomEditField/CustomEditField.xojo_code +++ b/Third Party Classes/CustomEditField/CustomEditField.xojo_code @@ -3748,7 +3748,8 @@ Implements MessageReceiver dim lock as new LinesLock(self) // prevents LineHighlighter from interfering while we're modifying the lines // Use the default line ending from the line manager if the text is just the Return or Enter character. - if text = chr(13) or text = chr(3) then text = lines.lineEnding + text = ReplaceLineEndings(text, lines.lineEnding) + text = text.ReplaceAll(Chr(3), lines.lineEnding) dim removedText as String = TextStorage.getText(offset, length) dim removedAttrs() as TextLineAttributes = lines.getAttributesOfLinesInRange(offset, length) diff --git a/Windows/WndEditor.xojo_window b/Windows/WndEditor.xojo_window index 6a2dd9c..674e932 100644 --- a/Windows/WndEditor.xojo_window +++ b/Windows/WndEditor.xojo_window @@ -312,6 +312,12 @@ End EditUndo.Enabled = fldCode.CanUndo EditRedo.Enabled = fldCode.CanRedo + if IsLineCommented( fldCode.LineNumAtCharPos( fldCode.SelStart ) ) then + EditComment.Text = App.kEditUncomment + else + EditComment.Text = App.kEditComment + end if + ViewShowInvisibles.Checked = App.Prefs.ShowInvisibles ViewShowLineNumbers.Checked = App.Prefs.ShowLineNumbers @@ -495,17 +501,62 @@ End fldCode.IgnoreRepaint = true - for each index as integer in lineIndexes - dim charPos as integer = fldCode.CharPosAtLineNum( index ) + // + // See if the first line is already commented + // + dim doUncomment as boolean = IsLineCommented( lineIndexes( 0 ) ) + + if doUncomment then + + dim rx as new RegEx + rx.SearchPattern = "^\s*(?://|'|rem\b)\s*(.*)" + rx.ReplacementPattern = "$1" + + for i as integer = lineIndexes.Ubound downto 0 + dim lineIndex as integer = lineIndexes( i ) + dim startPos as integer = fldCode.CharPosAtLineNum( lineIndex ) + dim endPos as integer = fldCode.CharPosAtLineNum( lineIndex + 1 ) + if endPos = -1 then + endPos = fldCode.Text.Len + end if + + fldCode.SelStart = startPos + fldCode.SelLength = endPos - startPos + dim thisLine as string = fldCode.SelText + dim origLine as string = thisLine + + thisLine = rx.Replace( thisLine ) + if thisLine <> origLine then + if thisLine = "" then + thisLine = EndOfLine + end if + fldCode.SelText = thisLine + + // + // Mark it dirty + // + fldCode.SelText = " " + fldCode.SelStart = fldCode.SelStart - 1 + fldCode.SelLength = 1 + fldCode.SelText = "" + end if + next + + else + + for each lineIndex as integer in lineIndexes + dim charPos as integer = fldCode.CharPosAtLineNum( lineIndex ) fldCode.SelStart = charPos fldCode.SelLength = 0 fldCode.SelText = kCommentToken next + end if + // - // Select after the last line + // Select the affected lines // - SelectAfterLineIndex( lineIndexes( lineIndexes.Ubound ) ) + SelectLineRange( lineIndexes( 0 ), lineIndexes( lineIndexes.Ubound ) ) fldCode.IgnoreRepaint = false fldCode.Invalidate @@ -541,48 +592,6 @@ End End Function #tag EndMenuHandler - #tag MenuHandler - Function EditUncomment() As Boolean Handles EditUncomment.Action - dim lineIndexes() as integer = SelectedLineIndexes - if lineIndexes.Ubound = -1 then - return true - end if - - dim rx as new RegEx - rx.SearchPattern = "^([\x20\t]*)(" + kCommentToken + ")" - rx.ReplacementPattern = "$1" - - fldCode.IgnoreRepaint = true - - for each lineIndex as integer in lineIndexes - dim startPos as integer = fldCode.CharPosAtLineNum( lineIndex ) - dim endPos as integer - if lineIndex >= fldCode.LineCount then - endPos = fldCode.Text.Len - else - endPos = fldCode.CharPosAtLineNum( lineIndex + 1 ) - end if - fldCode.SelStart = startPos - fldCode.SelLength = endPos - startPos - dim thisLine as string = fldCode.SelText - dim origLine as string = thisLine - - thisLine = rx.Replace( thisLine ) - if thisLine <> origLine then - fldCode.SelText = thisLine - end if - next - - SelectAfterLineIndex( lineIndexes( lineIndexes.Ubound ) ) - - fldCode.IgnoreRepaint = false - fldCode.Invalidate - - Return True - - End Function - #tag EndMenuHandler - #tag MenuHandler Function EditUndo() As Boolean Handles EditUndo.Action fldCode.Undo @@ -1080,22 +1089,15 @@ End #tag EndMethod #tag Method, Flags = &h21 - Private Function LineAtLineIndex(lineIndex As Integer) As String - // Returns the text of the line at lineIndex - - if lineIndex >= fldCode.LineCount then - return "" + Private Function IsLineCommented(lineIndex As Integer) As Boolean + static rx as RegEx + if rx is nil then + rx = new RegEx + rx.SearchPattern = "^\s*(?://|'|rem\b)" end if - dim startCharPos as integer = fldCode.CharPosAtLineNum( lineIndex ) + 1 - dim endCharPos as integer - if lineIndex = ( fldCode.LineCount - 1 ) then - endCharPos = fldCode.Text.Len - else - endCharPos = fldCode.CharPosAtLineNum( lineIndex + 1 ) + 1 - end if - - return fldCode.Text.Mid( startCharPos, endCharPos - startCharPos ).Trim + dim line as string = fldCode.GetLine( lineIndex ) + return rx.Search( line ) isa RegExMatch End Function #tag EndMethod @@ -1181,7 +1183,7 @@ End return SaveAs() end if - MyDocument.TextContents_MTC = fldCode.Text + MyDocument.TextContents_MTC = ReplaceLineEndings( fldCode.Text, EndOfLine ) ContentsChanged = false fldCode.ClearDirtyLines @@ -1335,28 +1337,20 @@ End End Sub #tag EndMethod - #tag Method, Flags = &h21 - Private Sub SelectAfterLineIndex(lineIndex As Integer) - lineIndex = lineIndex + 1 - - dim charPos as integer - if lineIndex >= fldCode.LineCount then - charPos = fldCode.Text.Len - else - charPos = fldCode.CharPosAtLineNum( lineIndex ) - end if - fldCode.SelStart = charPos - - End Sub - #tag EndMethod - #tag Method, Flags = &h21 Private Function SelectedLineIndexes() As Integer() // Returns an array of the line indexes that cover the current selection + dim selText as string = fldCode.SelText + dim startLine as integer = fldCode.LineNumAtCharPos( fldCode.SelStart ) dim endLine as integer = fldCode.LineNumAtCharPos( fldCode.SelStart + fldCode.SelLength ) + dim lastChar as string = selText.Right( 1 ) + if startLine <> endLine and ( lastChar = &uA or lastChar = &u0D ) then + endLine = endLine - 1 + end if + dim r() as integer for i as integer = startLine to endLine r.Append i @@ -1366,6 +1360,19 @@ End End Function #tag EndMethod + #tag Method, Flags = &h21 + Private Sub SelectLineRange(firstLineIndex As Integer, lastLineIndex As Integer) + dim startPos as integer = fldCode.CharPosAtLineNum( firstLineIndex ) + dim endPos as integer = fldCode.CharPosAtLineNum( lastLineIndex + 1 ) + if endPos = -1 then + endPos = fldCode.Text.Len + end if + + fldCode.SelStart = startPos + fldCode.SelLength = endPos - startPos + End Sub + #tag EndMethod + #tag Method, Flags = &h21 Private Sub SetAutocompleteWords() if AutocompleterKeywords is nil then @@ -1395,6 +1402,7 @@ End // // Add all methods and properties from IDEEmulator + // except those with "exclude" attribute // dim ti as Introspection.TypeInfo = GetTypeInfo( IDEEmulator ) @@ -1404,6 +1412,12 @@ End // dim props() as Introspection.PropertyInfo = ti.GetProperties for each prop as Introspection.PropertyInfo in props + dim attrs() as Introspection.AttributeInfo = prop.GetAttributes + for each attr as Introspection.AttributeInfo in attrs + if attr.Name = "exclude" then + continue for prop + end if + next call AutocompleterKeywords.AddKey( prop.Name, nil ) next @@ -1412,6 +1426,12 @@ End // dim methods() as Introspection.MethodInfo = ti.GetMethods for each method as Introspection.MethodInfo in methods + dim attrs() as Introspection.AttributeInfo = method.GetAttributes + for each attr as Introspection.AttributeInfo in attrs + if attr.Name = "exclude" then + continue for method + end if + next call AutocompleterKeywords.AddKey( method.Name, nil ) next @@ -1576,7 +1596,7 @@ End #tag EndProperty - #tag Constant, Name = kAdditionalKeywords, Type = String, Dynamic = False, Default = \"Abs\nAcos\nAppend\nAsc\nAscB\nAsin\nAtan\nAtan2\nBin\nCdbl\nCeil\nChr\nChrB\nCMY\nCos\nCountFields\nCStr\nEndOfLine\nExp\nFloor\nFormat\nHex\nHSV\nInput\nInStr\nInStrB\nLeft\nLeftB\nLen\nLenB\nLog\nLowercase\nLTrim\nMax\nMicroseconds\nMid\nMidB\nMin\nNthField\nOct\nPow\nPrint\nReplace\nReplaceAll\nReplaceAllB\nReplaceB\nRGB\nRight\nRightB\nRnd\nRound\nRTrim\nSin\nSqrt\nStr\nStrComp\nTan\nTicks\nTitlecase\nTrim\nUbound\nUppercase\nVal", Scope = Protected + #tag Constant, Name = kAdditionalKeywords, Type = String, Dynamic = False, Default = \"Abs\nAcos\nAppend\nAsc\nAscB\nAsin\nAtan\nAtan2\nAuto\nBin\nCdbl\nCeil\nChr\nChrB\nCMY\nCos\nCountFields\nCStr\nEndOfLine\nExp\nFloor\nFormat\nHex\nHSV\nIndexOf\nInput\nInStr\nInStrB\nLeft\nLeftB\nLen\nLenB\nLog\nLowercase\nLTrim\nMax\nMicroseconds\nMid\nMidB\nMin\nNthField\nOct\nPow\nPrint\nRemove\nReplace\nReplaceAll\nReplaceAllB\nReplaceB\nRGB\nRight\nRightB\nRnd\nRound\nRTrim\nSin\nSqrt\nStr\nStrComp\nTan\nTicks\nTitlecase\nToText\nTrim\nUbound\nUppercase\nVal\n\nVariant\nBooleanValue\nInt32Value\nSingleValue\nCFStringRefValue\nInt64Value\nStringValue\nTextValue\nCStringValue\nIntegerValue\nUInt32Value\nColorValue\nOSTypeValue\nUInt64Value\nCurrencyValue\nObjectValue\nWStringValue\nDateValue\nPStringValue\nWindowPtrValue\nDoubleValue\nPtrValue\n\nArrayElementType\nEquals\nHash\nIsArray\nIsNull\nIsNumeric\n\nType\nTypeArray\nTypeBoolean\nTypeCFStringRef\nTypeColor\nTypeCString\nTypeCurrency\nTypeDate\nTypeDouble\nTypeInteger\nTypeLong\nTypeNil\nTypeObject\nTypeOSType\nTypePString\nTypePtr\nTypeSingle\nTypeString\nTypeStructure\nTypeText\nTypeWindowPtr\nTypeWString", Scope = Protected #tag EndConstant #tag Constant, Name = kColorError, Type = Color, Dynamic = False, Default = \"&cFF00007F", Scope = Private @@ -1924,7 +1944,7 @@ End return end if - dim thisLine as string = LineAtLineIndex( lineIndex ) + dim thisLine as string = fldCode.GetLine( lineIndex ) dim match as RegExMatch match = rxDimFinder.Search( thisLine ) diff --git a/XsEdit.xojo_project b/XsEdit.xojo_project index 531e92e..2230964 100644 --- a/XsEdit.xojo_project +++ b/XsEdit.xojo_project @@ -112,15 +112,16 @@ Module=TBConstants;Windows/TBConstants.xojo_code;&h18D68FFF;&h1B897FFF;false Picture=arrowright3small;Images/arrow-right-3-small.png;&h4AC07FFF;&h3F391FFF;false;0;&h0 Picture=arrowrightdouble3small;Images/arrow-right-double-3-small.png;&h1866C7FF;&h3F391FFF;false;0;&h0 Picture=systemrun3small;Images/system-run-3-small.png;&h4075DFFF;&h3F391FFF;false;0;&h0 +Class=IDEEmulatorExtras;Classes/IDEEmulatorExtras.xojo_code;&h3EF787FF;&h8E0CFFF;false AppMenuBar=MainMenuBar MajorVersion=1 -MinorVersion=0 +MinorVersion=1 SubVersion=0 NonRelease=0 Release=3 InfoVersion=Advanced XojoScript editor -LongVersion=v.1.0. ©2015 by Kem Tekinay and Jeremy Cowgar. All rights reserved. -ShortVersion=1.0 +LongVersion=v.1.1. ©2015 by Kem Tekinay and Jeremy Cowgar. All rights reserved. +ShortVersion=1.1 WinCompanyName=MacTechnologies Consulting WinInternalName=XsEdit WinProductName=XsEdit