Page 1 of 1

Menu option for "New Test"

Posted: Wed Nov 07, 2007 4:26 am
by PB
I think I requested this before but I can't find it now.

It'd be handy to have in the File menu, a new entry called "New Test"
or something like that, so that the editor pastes the following code in:

Code: Select all

If OpenWindow(0,0,0,640,480,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  CreateGadgetList(WindowID(0))
  Repeat
    ev=WaitWindowEvent()

  Until ev=#PB_Event_CloseWindow
EndIf
I know it can be done with a tool, but a native way would be nicer, and it
means one can always quickly start a new test app without having to type
the above code in first, as the skeleton code above is ready to be edited.
It'd be a massive timesaver for quick test apps. It could go directly under
the File -> New menu command.

Posted: Wed Nov 07, 2007 11:09 am
by freak
And what if somebody's test code looks slightly different ?

This is what the templates tool is for. Just put this code in a template.
Then all you need to do is open a new source and double-click on the template and thats it.

Posted: Wed Nov 07, 2007 12:28 pm
by PB
> what if somebody's test code looks slightly different ?

Well the code I posted is an absolute bare-minimum skeleton, obviously. :)
Besides, that's not really an argument because I could say the same about
every bit of code in the "Examples" folder too. :P :twisted: Who gets to say what
code "looks right" or not?

I was thinking along the lines of something like that, or even enhanced with
skeleton gadget loops, which would be good for beginners to see how an
app should be set up. Good for teaching newbies. Like, they'd buy PureBasic,
click the File menu, see an option for a skeleton app and bang, they'd see
how an event-driven app in PureBasic is meant to work. They can then start
to tweak the skeleton code to their heart's contents, and for others like us,
we can use it to quickly test something without having to mess around with
templates (which aren't portable in that they aren't part of the IDE itself).

Posted: Wed Nov 07, 2007 12:49 pm
by #NULL
i don't think it's a good idea to implement didactics in the ide.
i never had problems using templates. i just move the mouse, one click, and such code is in there.
(i even wouldn't like that particular snippet)

Posted: Wed Nov 07, 2007 12:57 pm
by PB
> i don't think it's a good idea to implement didactics in the ide

Why not? Again: the Help file is full of examples of how to do things. What's
the difference between that and having one example in the IDE itself?

> i even wouldn't like that particular snippet

Fair enough, but it was just an example. You could use the example found
in the Help file for WaitWindowEvent() then, which teaches and is a good
sample skeleton code without needing to install it as a template:

Code: Select all

  If OpenWindow(0, 0, 0, 230, 90, "Event handling example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   If CreateGadgetList(WindowID(0))
     ButtonGadget  (1, 10, 10, 200, 20, "Click me")
     CheckBoxGadget(2, 10, 40, 200, 20, "Check me")
   EndIf

   If CreateMenu(0, WindowID(0))
     MenuTitle("Menu")
     MenuItem(1, "Item 1")
     MenuItem(2, "Item 2")
     MenuItem(3, "Item 3")
   EndIf

   Repeat
     Event = WaitWindowEvent()
     
     Select Event
     
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 1 : Debug "Button 1 clicked!"
           Case 2 : Debug "Button 2 clicked!"
           Case 3 : Debug "Button 3 clicked!"
         EndSelect
       
       Case #PB_Event_Menu
         Select EventMenu()
           Case 1 : Debug "Menu item 1 clicked!"
           Case 2 : Debug "Menu item 2 clicked!"
           Case 3 : Debug "Menu item 3 clicked!"
         EndSelect
     
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf
It was just an idea. Obviously I can live without it, but it would be a missed
opportunity, IMO. It's something I'd like to have seen when I started with
the language. Anything to make it easier and convenient for the end user.

Posted: Wed Nov 07, 2007 1:11 pm
by tinman
PB wrote:templates (which aren't portable in that they aren't part of the IDE itself).
I run the PB editor with the /portable switch and it picks up my templates.prefs from the PureBasic directory. Or is that not what you meant by portable (I guess if you don't use portable then they're per-user)?

But rather than simple "File -> New skeleton" and have it just dump some code into the IDE, maybe something to add would be like a new application wizard where you can configure what you want added. Like the Visual Studio new MFC application wizard if you've ever seen that. I don't know if PB has enough standard things or complexity to warrant it though.

Posted: Wed Nov 07, 2007 1:20 pm
by PB
By portable I meant not having to rely on a separate file. That is, it's not part
of PureBasic.exe itself, because this file gets updated often and the skeleton
might need to be updated too. And it's also not portable in that you can't just
pick the skeleton out of a template file (easily) to give to someone else. If it
were in the IDE, everyone would have it and it would be updated with every
new PureBasic.exe (if need be).

Hasn't anyone else experienced the need for this? Like, you want to reply to
help in these forums when someone says "how do I do this", and you have to
go and either type a skeleton app manually, or load it from a file or template.
It's too slow and cumbersome, IMO. Quicker to just go "File -> New Test" and
bang, there's the code and it's ready to go. If the newbie has any questions,
you can then say "look at line 7, that's what does it" and they'll know exactly
what you mean, as the skeleton is the same for all users of the IDE.

A new app wizard sounds like a good idea. I may write one, one day. :)

Posted: Wed Nov 07, 2007 1:34 pm
by gnozal
Why not use a form designer ?

When I need a working code snippet for testing purpose, I do the following :
- jaPBe : Menu Tools -> PureFORM
- PureFORM : Project menu -> New project (if needed)
- PureFORM : add some gadgets (if needed)

- PureFORM : Codeviewer -> Complete code
- PureFORM : Codeviewer -> New tab in jaPBe
( or with PB IDE :
- PureFORM : Codeviewer -> Copy to clipboard
- PB IDE : New file
- PB IDE : Paste
)

- PureFORM : Quit
Done : 4 clicks in jaPBe for a minimal open window code

Note : it may sound as advertising, but it is not.

Posted: Wed Nov 07, 2007 1:55 pm
by PB
That's even worse than using templates. :) The idea is to keep it in the IDE.

Posted: Wed Nov 07, 2007 1:58 pm
by PB
How's this for a compromise: stick the WaitWindowEvent() code in the
official template file for distribution, and make templates visible in the
tools panel. That way, newbies can see it, click it, and use it. No need
for a menu item and the skeleton code is there in every official setup
for use from the get-go. Problem solved! :)

Posted: Wed Nov 07, 2007 2:20 pm
by Trond
I don't want my templates in tool panel. If you want that, just change it from the preferences.

Standard templates were already planned if I remember correctly.