Page 1 of 1

text editor

Posted: Mon Sep 12, 2016 1:44 am
by k3pto
I am a newbie to PB and would like to know if anyone can point me to a simple text editor that I can use to help learn how to use PB and some of its gadgets.

Re: text editor

Posted: Mon Sep 12, 2016 4:12 am
by flaviofornazier
Hi K3pto!

The Purebasic Editor itself is very intuitive, but there many
others that can help you. Please try do a search here with
the keywords "IDE, RAD, Editor", etc.

I'm a newbie too and I'm always doing searches about PB
over all the internet.

Best regards.

Re: text editor

Posted: Mon Sep 12, 2016 4:13 am
by netmaestro
If you're a new user the best text editor for you would be the PureBasic IDE in my opinion. You can test your code from there and get debugger messages immediately.

Re: text editor

Posted: Mon Sep 12, 2016 4:44 am
by Keya
i think ive seen mention of some people using ones like Ultraedit where you can macro/program them but that sounds more complicated to me, and i think the PB IDE is pretty good

or you could make your own text editor!?

pbnotepad.pb ...

Code: Select all

Global gsFilename.s
XIncludeFile("pbnotepad.pbf")
XIncludeFile("helpers.pbi")

OpenDlg1()

Define event.i
Repeat         ;main message loop
  event = WaitWindowEvent()
  Dlg1_Events (event)
Until event = #PB_Event_CloseWindow
End
pbnotepad.pbf ...

Code: Select all

Enumeration FormWindow
  #Dlg1
EndEnumeration

Enumeration FormGadget
  #Editor1
EndEnumeration

Enumeration FormMenu
  #mnuNew
  #mnuOpen
  #mnuSave
  #mnuSaveAs
  #mnuExit
  #mnuAbout
EndEnumeration

Declare ResizeGadgetsDlg1()

Declare mnuAbout(Event)
Declare mnuOpen(Event)
Declare mnuSave(Event)
Declare mnuNew(Event)
Declare mnuSaveAs(Event)
Declare mnuExit(Event)

Procedure OpenDlg1(x = 0, y = 0, width = 568, height = 372)
  OpenWindow(#Dlg1, x, y, width, height, "PBNotepad", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_WindowCentered)
  CreateMenu(0, WindowID(#Dlg1))
  MenuTitle("File")
  MenuItem(#mnuNew, "New")
  MenuItem(#mnuOpen, "Open...")
  MenuItem(#mnuSave, "Save")
  MenuItem(#mnuSaveAs, "Save As...")
  MenuBar()
  MenuItem(#mnuExit, "Exit")
  MenuTitle("Help")
  MenuItem(#mnuAbout, "About")
  EditorGadget(#Editor1, 0, 0, 568, 350, #PB_Editor_WordWrap)
EndProcedure

Procedure ResizeGadgetsDlg1()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(#Dlg1)
  FormWindowHeight = WindowHeight(#Dlg1)
  ResizeGadget(#Editor1, 0, 0, FormWindowWidth - 0, FormWindowHeight - MenuHeight() - 0)
EndProcedure

Procedure Dlg1_Events(event)
  Select event
    Case #PB_Event_SizeWindow
      ResizeGadgetsDlg1()
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
        Case #mnuNew
          mnuNew(EventMenu())
        Case #mnuOpen
          mnuOpen(EventMenu())
        Case #mnuSave
          mnuSave(EventMenu())
        Case #mnuSaveAs
          mnuSaveAs(EventMenu())
        Case #mnuExit
          mnuExit(EventMenu())
        Case #mnuAbout
          mnuAbout(EventMenu())
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
helpers.pbi

Code: Select all

Procedure SetMainTitle()
  SetWindowTitle(#Dlg1, "PBNotepad - " + GetFilePart(gsFilename))
EndProcedure


Procedure mnuNew(eventid)
  gsFilename = ""
  SetGadgetText(#Editor1, "")
  SetMainTitle()
EndProcedure


Procedure mnuOpen(eventid)
  Protected sOpenfile.s = OpenFileRequester("Select file to open...", "", "", 0)
  If sOpenfile <> ""
    Protected hFile = ReadFile(#PB_Any, sOpenfile)
    If hFile = 0
      MessageRequester("Error", "Couldn't open file")
    Else
      Protected sBuf.s
      sBuf = ReadString(hFile, #PB_Ascii | #PB_File_IgnoreEOL, -1)
      CloseFile(hFile)
      SetGadgetText(#Editor1, sBuf)
      gsFilename = sOpenfile
      SetMainTitle()
    EndIf
  EndIf
EndProcedure


Procedure SaveToFile(sFile.s)
    Protected hFile = CreateFile(#PB_Any, sFile)
    If hFile = 0
      MessageRequester("Error", "Couldn't create file")
    Else
      WriteString(hFile, GetGadgetText(#Editor1), #PB_Ascii)
      CloseFile(hFile)
      gsFilename = sFile
    EndIf
    SetMainTitle()
EndProcedure


Procedure mnuSaveAs(eventid)
  Protected sFile.s = SaveFileRequester("Save file as...", "", "", 0)
  If sFile <> ""
    SaveToFile(sFile)
  EndIf
EndProcedure


Procedure mnuSave(eventid)
  If gsFilename <> ""
    SaveToFile(gsFileName)
  Else
    mnuSaveAs(eventid)
  EndIf
EndProcedure


Procedure mnuExit(eventid)
  End
EndProcedure


Procedure mnuAbout(eventid)
  MessageRequester("PBNotepad", "Simple start to a basic text editor")
EndProcedure

Re: text editor

Posted: Mon Sep 12, 2016 5:26 am
by IdeasVacuum
I think a few people use either UltraEdit or NotePad++ since they are feature rich and it's much easier to use just the one editor if you have to use more than one programming language.

Personally I use UltraEdit - Column mode editing and macros are very handy tools. Multiple tabs are spread over multiple rows on bigger projects so you can still see what you have loaded and 1-click to any source. The PB IDE and Visual Studio both auto-detect changes to source files so it all works rather well.

Edit: PB's graphical Window Form Designer is good, if a bit restrictive. I use it to define the intial layout of my forms and beyond that manually edit them, which is very easy.

Re: text editor

Posted: Mon Sep 12, 2016 7:07 am
by Marc56us
k3pto wrote:I am a newbie to PB and would like to know if anyone can point me to a simple text editor that I can use to help learn how to use PB and some of its gadgets.
If you start in PB, the best IDE is the internal editor. The main interesting thing is the syntax helper in status bar. Alway look at bottom screen when typing.
(The only downside of this function is that it does not understand embedded commands :| )

PS. Alway start new code with EnableExplicit :idea:
:arrow: You will gain a lot of time because of typos :!:

Have a good time with PB 8)

Re: text editor

Posted: Mon Sep 12, 2016 4:15 pm
by Tenaja
k3pto wrote:I am a newbie to PB and would like to know if anyone can point me to a simple text editor that I can use to help learn how to use PB and some of its gadgets.
If you are looking for a sample die to edit yourself, search for goscintilla.

Re: text editor

Posted: Tue Sep 13, 2016 4:59 pm
by k3pto
Thank you all for the quick replies. I think I need to be a little clearer in future posts...

The example from Keya is just what I was looking for - an example of PB code that creates a simple editor.
However, after reviewing and running the code, I do have a question: where do the menu bar, its contents and Dlg1 come from? I did not see them in the PB list of objects. I did see a menu gadget but I could not figure how to add items to it.

Re: text editor

Posted: Sun Feb 05, 2017 8:41 am
by collectordave
Hi k3pto

I am a newbie as well but here is some help.
However, after reviewing and running the code, I do have a question: where do the menu bar, its contents and Dlg1 come from? I did not see them in the PB list of objects. I did see a menu gadget but I could not figure how to add items to it.
Look for

OpenDlg1() in the file pbnotepad.pb

This is telling the programme to run the procedure OpenDlg1()

then look for

Procedure OpenDlg1(x = 0, y = 0, width = 568, height = 372) in the file pbnotepad.pbf

That is the procedure that creates the Dlg and is where the menu is created.

Hope this helps a little

Regards

cd

Re: text editor

Posted: Sun Feb 05, 2017 5:45 pm
by collectordave
Print and print preview added to the notepad application written by keya no font selection.

All available here https://github.com/collectordave/PureBasic-NotePad

Regards

cd