PureBasic Forum
http://forums.purebasic.com/english/

[Module] EditorEx (Custom Editor Gadget)
http://forums.purebasic.com/english/viewtopic.php?f=27&t=71774
Page 1 of 2

Author:  Thorsten1867 [ Thu Nov 22, 2018 5:43 pm ]
Post subject:  [Module] EditorEx (Custom Editor Gadget)

Extended EditorGadget Module

  • Automatic line break & hyphenation (german/english/french)
  • soft hyphen or conditional hyphen
  • Manual line break for WordWrap/Hyphenation (Return or Ctrl-Return for existing automatic line break)
  • Undo / Redo
  • Simple syntax highlighting (e.g. for spell checking)
  • (Automatic) spell checking (german/english/french)
  • Automatic hiding of scrollbars

Code:
;{ ===== Module Commands =====

  ; EditEx::AddItem()                - Add text row at 'Position' (or #FirstRow / #LastRow)
  ; EditEx::AddToUserDictionary()    - Add a new word to user dictionary
  ; EditEx::AddWord()                - Add word to syntax highlighting
  ; EditEx::AttachPopup()            - Attach 'PopUpMenu' to gadget
  ; EditEx::ClearWords()             - Delete the list with the words for syntax highlighting
  ; EditEx::ClearUndo()              - Delete the list with Undo/Redo steps
  ; EditEx::Copy()                   - Copy selected text to clipboard
  ; EditEx::Cut()                    - Cut the selected text and copy it to the clipboard
  ; EditEx::DeleteSelection()        - Delete selected text (Remove selection: #True/#False)
  ; EditEx::DeleteWord()             - Delete word from syntax highlighting
  ; EditEx::EnableAutoSpellCheck()   - Activate automatic spelling correction
  ; EditEx::EnableSyntaxHighlight()  - Enable syntax highlighting (#False/#CaseSensitiv/#NoCase)
  ; EditEx::EnableUndoRedo()         - Enable 'Undo/Redo' function (#True/#False)
  ; EditEx::FreeDictionary()         - Removes the loaded dictionary from memory
  ; EditEx::GetAttribute()           - Returns value of attribute (#ReadOnly/#WordWrap/#Hyphenation/#AutoHide/#Border/#CtrlChars)
  ; EditEx::GetColor()               - Returns color of attribute (#FrontColor/#BackColor/#SyntaxColor/#SelectionColor)
  ; EditEx::GetItemText()            - Returns text row at 'Position'
  ; EditEx::GetSelection()           - Returns selected text (Remove selection: #True/#False)
  ; EditEx::GetText()                - Returns all text rows seperated by 'Seperator'
  ; EditEx::InsertText()             - Insert text at cursor position (or replace selection)
  ; EditEx::IsRedo()                 - Checks if an redo is possible
  ; EditEx::IsSelected()             - Returns whether a selection exists
  ; EditEx::IsUndo()                 - Checks if an undo is possible
  ; EditEx::LoadDictionary()         - Load the dictionary for spell checking
  ; EditEx::LoadHyphenationPattern() - Load hyphenation pattern for selected language (#Deutsch/#English/#French)
  ; EditEx::Redo()                   - Perform Redo
  ; EditEx::ReDraw()                 - Redraw the gadget
  ; EditEx::RemoveGadget()           - Releases the used memory and deletes the cursor thread
  ; EditEx::Paste()                  - Inserting text from the clipboard
  ; EditEx::SaveUserDictionary()     - Save user dictionary
  ; EditEx::SetAttribute()           - Enable/Disable attribute (#ReadOnly/#WordWrap/#Hyphenation/#AutoHide/#Border/#CtrlChars)
  ; EditEx::SetColor()               - Set or change color of attribute (#FrontColor/#BackColor/#SyntaxColor/#SelectionColor)
  ; EditEx::SetFont()                - Set or change font FontID(#Font)
  ; EditEx::SetItemText()            - Replace text row at 'Position'
  ; EditEx::SetText()                - Set or replace all text rows
  ; EditEx::SpellCheck()             - Checks the spelling of the word (returns: #True/#False)
  ; EditEx::SpellChecking()          - Check the spelling in the editor gadget (#Highlight/#WrongWords)
  ; EditEx::Undo()                   - Perform Undo
  ; -----------------------
  ; EditEx::Gadget()                 - Creates an editor gadget
  ; -----------------------

;} ===========================


Download: EditorExModule.pbi (with Dictionary and Hyphen-Pattern)

Download: Language packages

Author:  skywalk [ Thu Nov 22, 2018 8:16 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Quick look:
Double-Click to select items and then delete on lower editor, leaves 1st character in place?

Author:  Thorsten1867 [ Fri Nov 23, 2018 11:50 am ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

skywalk wrote:
Quick look:
Double-Click to select items and then delete on lower editor, leaves 1st character in place?

Bug fixed

Author:  Kwai chang caine [ Fri Nov 23, 2018 1:15 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Thanks for sharing 8)

Quick try too :wink:
I don't know if it's normal, but the first backspace delete all the line :|
After the second backspace have the good behavior (Only one character deleted)

Author:  infratec [ Fri Nov 23, 2018 5:13 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Maybe a fix:

Code:
Procedure.s DeleteStringPart(String.s, Position.i, Length.i=1) ; Delete string part at Position (with Length)
    If Position > 0 And Position <= Len(String)
      ProcedureReturn Left(String, Position - 1) + Mid(String, Position + Length)
    Else
      ProcedureReturn String
    EndIf
  EndProcedure


Bernd

Author:  Thorsten1867 [ Fri Nov 23, 2018 10:09 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

infratec wrote:
Maybe a fix

Bug Fixed!

Code:
  Procedure.s DeleteStringPart(String.s, Position.i, Length.i=1) ; Delete string part at Position (with Length)
   
    If Position <= 0 : Position = 1 : EndIf
    If Position > Len(String) : Position = Len(String) : EndIf
   
    ProcedureReturn Left(String, Position - 1) + Mid(String, Position + Length)
  EndProcedure

Author:  Thorsten1867 [ Sat Nov 24, 2018 7:32 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Code:
; [23/11/18] Spellchecking & Bugfixes
; [24/11/18] WordWrap and Hyphenation revised & Bugfixes


Examples in different languages (German/English/French).
Code:
Language = EditEx::#Deutsch  ; #Deutsch / #English / #French

Author:  mestnyi [ Fri Nov 30, 2018 6:14 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

For a start, not a bad job. :)
Now mistakes.
This example for some reason does not work out with mouse.
There are not all similar words to paint.
and your example when you select korektor lags behind.

Code:
;- Example
;{

EnableExplicit

Global Window_0
Global Canvas_0, Editor_0, Button_0

Declare ResizeGadgetsWindow_0()

Procedure OpenWindow_0(X = 0, Y = 0, Width = 690, Height = 470)
  Window_0 = OpenWindow(#PB_Any, X, Y, Width, Height, "MyEditor Gadget", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  Canvas_0 = CanvasGadget(#PB_Any, 10, 10, 670, 350, #PB_Canvas_Keyboard)
  Editor_0 = EditorGadget(#PB_Any, 10, 390, 670, 70)
  Button_0 = ButtonGadget(#PB_Any, 10, 360, 130, 30, "Close Editor")
EndProcedure
Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(Window_0)
  FormWindowHeight = WindowHeight(Window_0)
  ResizeGadget(Canvas_0, 10, 10, FormWindowWidth - 20, FormWindowHeight - 120)
  ResizeGadget(Editor_0, 10, FormWindowHeight - 80, FormWindowWidth - 20, 70)
  ResizeGadget(Button_0, 10, FormWindowHeight - 110, 130, 30)
EndProcedure

Global Font_0, Font_1, Font_2, Font_3
Global Txt_1.s, txt.s, Editor, Style, i
Global sep.s = #CRLF$ ; #LF$

;Txt_1 + "x" + sep + sep
Txt_1 + sep + sep
Txt_1 + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + sep + sep
Txt_1 + "PureBasic is a high-level programming language based on established BASIC rules. It is mostly compatible with any other BASIC compiler, whether it's for the Amiga or PC format. Learning PureBasic is very easy! PureBasic has been created for beginners and experts alike. Compilation time is extremely fast. This software has been developed for the Windows operating system. We have put a lot of effort into its realization to produce a fast, reliable and system-friendly language. " + sep
Txt_1 + "The syntax is easy and the possibilities are huge with the advanced functions that have been added to this language like pointers, structures, procedures, dynamic lists and much more. For the experienced coder, there are no problems gaining access to any of the legal OS structures or Windows API objects. " + sep
Txt_1 + "PureBasic is a portable programming language which currently works on AmigaOS, Linux, MacOS X and Windows computer systems. This means that the same code can be compiled natively for the OS and use the full power of each. There are no bottlenecks like a virtual machine or a code translator, the generated code produces an optimized executable. " + sep
Txt_1 + "The main features of PureBasic" + sep
Txt_1 + "- x86, x64, 680x0 and PowerPC support" + sep
Txt_1 + "- Built-in arrays, dynamic lists, complex structures, pointers and variable definitions"  + sep
Txt_1 + "- Supported types: Byte (8-bit), Word (16-bit), Long (32-bit), Quad (64-bit), Float (32-bit), Double (64-bit) and Characters"  + sep
Txt_1 + "- User defined types (structures)"  + sep
Txt_1 + "- Built-in string types (characters), including ascii and unicode"  ;+ sep
Txt_1 + " 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + sep
Txt_1 + "- Powerful macro support"  + sep
Txt_1 + "- Constants, binary and hexadecimal numbers supported " + sep
Txt_1 + "- Expression reducer by grouping constants and numeric numbers together " + sep
Txt_1 + "- Standard arithmetic support in respect of sign priority and parenthesis: +, -, /, *, and, or, <<, >> " + sep
Txt_1 + "- Extremely fast compilation " + sep
Txt_1 + "- Procedure support for structured programming with local and global variables " + sep
Txt_1 + "- All Standard BASIC keywords: If-Else-EndIf, Repeat-Until, etc " + sep
Txt_1 + "- Specialized libraries to manipulate BMP pictures, windows, gadgets, DirectX, etc " + sep
Txt_1 + "- Specialized libraries are very optimized for maximum speed and compactness " + sep
Txt_1 + "- The Win32 API is fully supported as if they were BASIC keywords " + sep
Txt_1 + "- Inline Assembler " + sep + sep
Txt_1 + "- Precompiled structures with constants files for extra-fast compilation " + sep
Txt_1 + "- Configurable CLI compiler " + sep
Txt_1 + "- Very high productivity, comprehensive keywords, online help " + sep
Txt_1 + "- System friendly, easy to install and easy to use " + sep + sep


;Txt_1 = "a " + sep + " b"
;Txt_1 = "a" +#TAB$+ "bb" +#TAB$+ "ccc" +#TAB$+ "dddd" +#TAB$+ "eeeee" +#TAB$+ "ffffff"
;Txt_1 = sep + "a"
;Txt_1 = sep + "a" + sep
;Txt_1 = "- System friendly, easy to install and easy to use " + sep + sep
;Txt_1 = sep + "x" + sep + "a" + sep + sep
;Txt_1 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
;Txt_1 = "a " + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"

;Txt_1 = ReverseString(Txt_1)
;Txt_1 = "a " + "PureBasic is a high-level programming language based on established BASIC rules. It is mostly compatible with any other BASIC compiler" + sep

;Txt_1 = "Hello said"

OpenWindow_0()

Font_0 = LoadFont(#PB_Any, "Arial", 10)
Font_1 = LoadFont(#PB_Any, "Courier New", 14 , #PB_Font_Bold|#PB_Font_Italic|#PB_Font_HighQuality)
Font_2 = LoadFont(#PB_Any, "Tahoma", 12 , #PB_Font_Bold|#PB_Font_HighQuality)
Font_3 = LoadFont(#PB_Any, "Impact", 18 , #PB_Font_HighQuality)

Canvas_0 = MyEditor::Gadget(-1, 10, 10, 670, 350)
Editor=GetGadgetData(Canvas_0)

MyEditor::SetText(Editor, Txt_1)

MyEditor::EnableSyntaxHighlight(Canvas_0)
MyEditor::AddWord(Canvas_0, "PureBasic")
MyEditor::AddWord(Canvas_0, "(64-bit)")
MyEditor::AddWord(Canvas_0, "Long", #Blue)
MyEditor::ReDraw(Canvas_0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
;}

Author:  Thorsten1867 [ Sun Dec 02, 2018 2:27 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Code:
[02/12/18] Continuous text for hyphenation and wordwrap & Resize Handler & many Bugfixes

Author:  Thorsten1867 [ Sun Dec 02, 2018 3:01 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

mestnyi wrote:
This example for some reason does not work out with mouse.
There are not all similar words to paint.
and your example when you select korektor lags behind.


Code:
;- Example

XIncludeFile "EditorEx.pbi"

EnableExplicit

Global Font_0, Font_1, Font_2, Font_3
Global Txt_1.s
Global sep.s = #CRLF$

Txt_1 + sep + sep
Txt_1 + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + sep + sep
Txt_1 + "PureBasic is a high-level programming language based on established BASIC rules. It is mostly compatible with any other BASIC compiler, whether it's for the Amiga or PC format. Learning PureBasic is very easy! PureBasic has been created for beginners and experts alike. Compilation time is extremely fast. This software has been developed for the Windows operating system. We have put a lot of effort into its realization to produce a fast, reliable and system-friendly language. " + sep
Txt_1 + "The syntax is easy and the possibilities are huge with the advanced functions that have been added to this language like pointers, structures, procedures, dynamic lists and much more. For the experienced coder, there are no problems gaining access to any of the legal OS structures or Windows API objects. " + sep
Txt_1 + "PureBasic is a portable programming language which currently works on AmigaOS, Linux, MacOS X and Windows computer systems. This means that the same code can be compiled natively for the OS and use the full power of each. There are no bottlenecks like a virtual machine or a code translator, the generated code produces an optimized executable. " + sep
Txt_1 + "The main features of PureBasic" + sep
Txt_1 + "- x86, x64, 680x0 and PowerPC support" + sep
Txt_1 + "- Built-in arrays, dynamic lists, complex structures, pointers and variable definitions"  + sep
Txt_1 + "- Supported types: Byte (8-bit), Word (16-bit), Long (32-bit), Quad (64-bit), Float (32-bit), Double (64-bit) and Characters"  + sep
Txt_1 + "- User defined types (structures)"  + sep
Txt_1 + "- Built-in string types (characters), including ascii and unicode"  ;+ sep
Txt_1 + " 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + sep
Txt_1 + "- Powerful macro support"  + sep
Txt_1 + "- Constants, binary and hexadecimal numbers supported " + sep
Txt_1 + "- Expression reducer by grouping constants and numeric numbers together " + sep
Txt_1 + "- Standard arithmetic support in respect of sign priority and parenthesis: +, -, /, *, and, or, <<, >> " + sep
Txt_1 + "- Extremely fast compilation " + sep
Txt_1 + "- Procedure support for structured programming with local and global variables " + sep
Txt_1 + "- All Standard BASIC keywords: If-Else-EndIf, Repeat-Until, etc " + sep
Txt_1 + "- Specialized libraries to manipulate BMP pictures, windows, gadgets, DirectX, etc " + sep
Txt_1 + "- Specialized libraries are very optimized for maximum speed and compactness " + sep
Txt_1 + "- The Win32 API is fully supported as if they were BASIC keywords " + sep
Txt_1 + "- Inline Assembler " + sep + sep
Txt_1 + "- Precompiled structures with constants files for extra-fast compilation " + sep
Txt_1 + "- Configurable CLI compiler " + sep
Txt_1 + "- Very high productivity, comprehensive keywords, online help " + sep
Txt_1 + "- System friendly, easy to install and easy to use " + sep + sep

Font_0 = LoadFont(#PB_Any, "Arial", 10)
Font_1 = LoadFont(#PB_Any, "Courier New", 14 , #PB_Font_Bold|#PB_Font_Italic|#PB_Font_HighQuality)
Font_2 = LoadFont(#PB_Any, "Tahoma", 12 , #PB_Font_Bold|#PB_Font_HighQuality)
Font_3 = LoadFont(#PB_Any, "Impact", 18 , #PB_Font_HighQuality)

Define.i QuitWindow = #False

#Win = 0
#Edit   = 1
#EditEx = 2
#Button = 3

If OpenWindow(#Win, 0, 0, 690, 470, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
 
  EditEx::Gadget(#EditEx, 10, 10, 670, 350, EditEx::#Border|EditEx::#ScrollBars)
 
  EditorGadget(#Edit, 10, 390, 670, 70)
 
  ButtonGadget(#Button, 10, 365, 135, 20, "Close Editor")
 
  EditEx::SetText(#EditEx, Txt_1)

  EditEx::EnableSyntaxHighlight(#EditEx)
  EditEx::AddWord(#EditEx, "PureBasic")
  EditEx::AddWord(#EditEx, "(64-bit)")
  EditEx::AddWord(#EditEx, "Long", #Blue)
  EditEx::ReDraw(#EditEx)
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow ;{ Close Window
        QuitWindow = #True
        ;}
      Case #PB_Event_Gadget      ;{ Gadgets
        Select EventGadget()
          Case #Button
            QuitWindow = #True
        EndSelect ;}
    EndSelect
  Until QuitWindow
 
EndIf

Author:  mestnyi [ Sun Dec 02, 2018 7:04 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

I check the example on mac os, nothing has changed.

Author:  Thorsten1867 [ Mon Dec 03, 2018 10:19 am ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Under Windows the mouse works for me. The "(64-Bit)" are not recognized as "word" because of the brackets. I'm trying to fix this problem.

Gesendet von meinem Aquaris X mit Tapatalk

Author:  acreis [ Mon Dec 03, 2018 2:51 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Great Work!

I've been working in something like it in "C"!

The most difficult feature is UNDO / REDO!

Please think about it before going too far!

Good luck

Author:  Thorsten1867 [ Mon Dec 03, 2018 5:50 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Code:
[03/12/18] Syntax highlighting revised & Bugfixes


Undo/Redo - Feature in progress

Author:  Thorsten1867 [ Wed Dec 05, 2018 4:54 pm ]
Post subject:  Re: [Module] EditorEx (Custom Editor Gadget)

Code:
[05/12/18] Undo/Redo feature & Copy / Cut / Paste & Bugfixes

Multi-stage Undo (differential storage of undo steps) & Redo

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/