Page 1 of 1 1
Topic Options
#91735 - 2003-03-13 11:02 PM Kixforms: Notepad ala Kixscript ...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
This script is one of the latest beta test scripts and demonstrates most of the new features (Anchors/Menus/CommonDialogs) ... its a Notepad work-alike written in Kixscript.

Requires the lastest Kixforms beta release available here:

Kixforms Download Page

The editor is the real deal - one can load and save scripts so caution is warranted.

Screenshot:

 -

Sourcecode (np.kix):



Break On

;//////////////////////
; KIXTART  4.20      //
; KIXFORMS 2.30 BETA //
;//////////////////////

$TITLE = "kixpad"

$Untitled = "Untitled"

$RegKey = "HKCU\Software\Kixpad"

;//////////////
; Main form ...
;//////////////

$Form = CreateObject("Kixtart.Form")
$Form.Icon = 0
$Form.Text = $CurrentFileName + " - " + $TITLE
$Form.BorderStyle = 2 ; Sizable
$Form.ClientWidth = ReadValueEx($RegKey,"ClientWidth",600)
$Form.ClientHeight = ReadValueEx($RegKey,"ClientHeight",400)
$Form.Left = ReadValueEx($RegKey,"Left",100)
$Form.Top = ReadValueEx($RegKey,"Top",100)
$Form.OnActivate = "OnFormActivate()"
$Form.ClipChildren = 1

;//////////////
; Main menu ...
;//////////////

$File = $Form.Menu.MenuItems.Add("File")
$New = $File.MenuItems.Add("New","OnNewClick")
$Open = $File.MenuItems.Add("Open...","OnOpenClick")
$Save = $File.MenuItems.Add("Save","OnSaveClick")
$File.MenuItems.Add("-")
$Run = $File.MenuItems.Add("Run","OnRun")
$File.MenuItems.Add("-")
$Exit = $File.MenuItems.Add("Exit","OnExitClick")

$Edit = $Form.Menu.MenuItems.Add("Edit")
$Undo = $Edit.MenuItems.Add("Undo")

$Format = $Form.Menu.MenuItems.Add("Format")
$WordWrap = $Format.MenuItems.Add("WordWrap","OnWordWrapClick")
$Font = $Format.MenuItems.Add("Font...","OnFontClick")
$mnuBackColor = $Format.MenuItems.Add("Background Color...","OnBackColorClick")

$lblSep = $Form.Label
$lblSep.Location = 2,2
$lblSep.BorderStyle = 5
$lblSep.Size = $Form.ClientWidth-5,2
$lblSep.Anchor = 1+2+4

$btnNew = $Form.Controls.ToolButton()
$btnNew.Location = 5,$lblSep.Bottom+2
$btnNew.Size = 23,23
$btnNew.Icon = 58
$btnNew.FlatStyle = 1
$btnNew.OnClick = "OnNewClick()"
$btnNew.ToolTip = "New"

$btnOpen = $Form.Controls.ToolButton()
$btnOpen.Location = $btnNew.Right,$btnNew.Top
$btnOpen.Size = $btnNew.Size
$btnOpen.Icon = 1
$btnOpen.FlatStyle = $btnNew.FlatStyle
$btnOpen.OnClick = "OnOpenClick()"
$btnOpen.ToolTip = "Open"

$btnSave = $Form.Controls.ToolButton()
$btnSave.Location = $btnOpen.Right,$btnNew.Top
$btnSave.Size = $btnNew.Size
$btnSave.Icon = 2
$btnSave.FlatStyle = $btnNew.FlatStyle
$btnSave.OnClick = "OnSaveClick()"
$btnSave.ToolTip = "Save"

;//////////////////
; Common dialogs...
;//////////////////

$WarningBox = $Form.Dialogs.MessageBox
$WarningBox.Title = $TITLE
$WarningBox.Icon = 48
$WarningBox.Buttons = 3

$OpenFileDialog = $Form.Dialogs.OpenFileDialog()
$OpenFileDialog.InitialDirectory = @CURDIR
$OpenFileDialog.Filter = "Kixtart files (*.kix)|*.kix|All files (*.*)|*.*"
$OpenFileDialog.Title = "Open"
$OpenFileDialog.DefaultExt = "txt"
$OpenFileDialog.ShowReadOnly = "True"
$OpenFileDialog.CheckFileExists = "True"

$SaveFileDialog = $Form.Dialogs.SaveFileDialog()
$SaveFileDialog.Title = "Save As"
$SaveFileDialog.InitialDirectory = @CURDIR
$SaveFileDialog.Filter = "Kixtart files (*.kix)|*.kix|All files (*.*)|*.*"
$SaveFileDialog.Title = "Save"
$SaveFileDialog.DefaultExt = "txt"

$TextBox = $Form.TextBox
$TextBox.Location = 0,$btnNew.Bottom+2
$TextBox.Right = $Form.ClientWidth
$TextBox.Bottom = $Form.ClientHeight
$TextBox.Anchor = 15
$TextBox.MultiLine = "True"
$TextBox.ScrollBars = 3
$TextBox.Modified = 0
$TextBox.WordWrap = ReadValueEx($RegKey,"WordWrap",0)
$TextBox.FontName = ReadValueEx($RegKey,"FontName","Courier New")
$TextBox.FontSize = ReadValueEx($RegKey,"FontSize",10)
$TextBox.FontBold = ReadValueEx($RegKey,"FontBold",0)
$TextBox.ForeColor = Val(ReadValueEx($RegKey,"ForeColor",0))
$TextBox.BackColor = Val(ReadValueEx($RegKey,"BackColor",16777215))

;///////////////
; Initialize ...
;///////////////

$WordWrap.Checked = $TextBox.WordWrap

$CurrentFileName = ReadValueEx($RegKey,"FileName","")

If $CurrentFileName
 If Not LoadFile($CurrentFileName)
  $CurrentFileName = $Untitled
 Endif
Else
 $CurrentFileName = $Untitled
EndIf

$Form.Text = GetFileName($CurrentFileName) + " - " + $TITLE

;////////////////////////
; Run the application ...
;////////////////////////

$Form.Show
$TextBox.SetFocus

While $form.Visible
 $=Execute($form.DoEvents)
Loop

SaveSettings()

Exit 1

Function OnNewClick()

 If CheckUnSavedData()

  $TextBox.Clear()
  $CurrentFileName = $Untitled
  $Form.Text = $CurrentFileName + " - " + $TITLE

 EndIf 

EndFunction

Function OnOpenClick()

 Dim $Line
 Dim $FileName

 If CheckUnSavedData()

  If $OpenFileDialog.ShowDialog() = 1

   $FileName = $OpenFileDialog.FileName

   $= LoadFile($FileName)

   $CurrentFileName = $FileName
   $Form.Text =  GetFileName($CurrentFileName) + " - $TITLE"

  EndIf

 EndIf
 
EndFunction

Function OnSaveClick()

 $= SaveFile()

EndFunction

Function OnWordWrapClick()

 $TextBox.WordWrap = Not $TextBox.WordWrap
 $WordWrap.Checked = $TextBox.WordWrap

EndFunction

Function OnFontClick()
 
 Dim $FontDialog;

 $FontDialog = $Form.Dialogs.FontDialog()
 $FontDialog.Font = $TextBox.Font
 $FontDialog.Color = $TextBox.ForeColor;

 If $FontDialog.ShowDialog() = 1
  $TextBox.Font = $FontDialog.Font
  $TextBox.ForeColor = $FontDialog.Color
 EndIf

EndFunction

Function OnBackColorClick()

 Dim $ColorDialog;

 $ColorDialog = $Form.Dialogs.ColorDialog;
 $ColorDialog.Color = $TextBox.BackColor

 If $ColorDialog.ShowDialog() = 1
  $TextBox.BackColor = $ColorDialog.Color
 EndIf

EndFunction

Function OnFormActivate()

 $TextBox.SetFocus()

EndFunction

Function OnRun()

 If CheckUnSavedData()

  run 'wkix32 "$CurrentFileName"'

 EndIf

EndFunction

;/////////////////////////
;// Support functions ...
;/////////////////////////

Function CheckUnSavedData()

 $CheckUnSavedData = 1

 If $TextBox.Modified

  $Message = "The text in the $CurrentFileName file has changed.@CRLF"+
         "Do you want to save the changes ?"

  $Result = $WarningBox.Show($Message)

  Select

   Case $Result = 6

    $CheckUnSavedData = SaveFile()

   Case $Result = 2

    $CheckUnSavedData = 0

   Case $Result = 7

    $CheckUnSavedData = 1

   Case 1

    $CheckUnSavedData = 0

  EndSelect

 EndIf

EndFunction

Function LoadFile($FileName)

 $LoadFile = 0


 If Open(1,$FileName) = 0

  $Form.MousePointer = 11
  $TextBox.BeginUpdate

  $Line = ReadLine(1)

  While @ERROR = 0

   $Line = $Line + @CRLF + ReadLine(1)

  Loop

  $= Close(1)

  $TextBox.Text = $Line
  $TextBox.SelStart = 0
  $TextBox.SelLength = 0

  $TextBox.EndUpdate
  $Form.MousePointer = 0

  $LoadFile = 1

 EndIf

EndFunction

Function SaveFile()

 $SaveFile = 1

 If $CurrentFileName = $Untitled

  $SaveFileDialog.FileName = ""

  If $SaveFileDialog.ShowDialog() = 1

   $CurrentFileName = $SaveFileDialog.FileName
 
  Else

   $SaveFile = 0   

   Return

  EndIf

 EndIf

 If Exist($CurrentFilename)
  Del $CurrentFilename
 EndIf

 If Open(1,$CurrentFileName,5) = 0

  $=WriteLine(1,$TextBox.Text)

  $=Close(1)

  $Form.Text = GetFileName($CurrentFileName) + " - $TITLE"

  $TextBox.Modified = 0

 Endif

EndFunction

Function OnExitClick()

 If CheckUnSavedData()

  $Form.Hide

 EndIf

EndFunction

Function GetFileName($FileName)

 $GetFileName = SubStr($FileName,InStrRev($FileName,"\")+1)

EndFunction

Function SaveSettings()

 $= WriteValue($RegKey,"FontName",$TextBox.FontName,"REG_SZ")
 $= WriteValue($RegKey,"FontSize",$TextBox.FontSize,"REG_DWORD")
 $= WriteValue($RegKey,"FontBold",$TextBox.FontBold,"REG_DWORD")
 $= WriteValue($RegKey,"ForeColor",$TextBox.ForeColor,"REG_DWORD")
 $= WriteValue($RegKey,"BackColor",$TextBox.BackColor,"REG_DWORD")
 $= WriteValue($RegKey,"WordWrap",$TextBox.WordWrap,"REG_DWORD")
 $= WriteValue($RegKey,"ClientWidth",$Form.ClientWidth,"REG_DWORD")
 $= WriteValue($RegKey,"ClientHeight",$Form.ClientHeight,"REG_DWORD")
 $= WriteValue($RegKey,"Left",$Form.Left,"REG_DWORD")
 $= WriteValue($RegKey,"Top",$Form.Top,"REG_DWORD")
 $= WriteValue($RegKey,"FileName",$CurrentFileName,"REG_SZ")

EndFunction

Function ReadValueEx($Key, $Value, $Default)
 
 Dim $Data

 $ReadValueEx = $Default

 $Data = ReadValue($Key,$Value)
 If @ERROR = 0
  $ReadValueEx = $Data
 EndIf

EndFunction



-Shawn

[ 13. March 2003, 23:17: Message edited by: Shawn ]

Top
#91736 - 2003-03-13 11:34 PM Re: Kixforms: Notepad ala Kixscript ...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Does it have
  • Syntax Highlighting
  • Show function syntax in toooltip like VS IDE?
  • Syntax Check
  • BreakPoints with DEBUG ON/OFF
  • Suggest potential functions based on already typed characters
  • All the other cool stuff that modern IDEs have
[Big Grin] [Big Grin] Really nice job!
_________________________
There are two types of vessels, submarines and targets.

Top
#91737 - 2003-03-14 09:23 AM Re: Kixforms: Notepad ala Kixscript ...
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Wow Shawn [Eek!]

Now I know why you haven't got that much time for us recently ...

Great new stuff! (already have a picture of how PostPrep 1.0.3 will look [Wink] )
_________________________



Top
#91738 - 2003-03-14 09:52 AM Re: Kixforms: Notepad ala Kixscript ...
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Great stuff, shawn !! This opens up a new era of KiXforms coding !! Not to be annoying, but do you have an idea when the manual/help is ready. There is so much possible with KiXforms and we know so little....
_________________________
Kind regards,

Top
#91739 - 2003-03-14 10:43 AM Re: Kixforms: Notepad ala Kixscript ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jens, I quess you have weird notepad on your computer.

as my notepad has no syntax highlighting or any of the other features you listed...
_________________________
!

download KiXnet

Top
#91740 - 2003-03-14 02:19 PM Re: Kixforms: Notepad ala Kixscript ...
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shawn,

Very good stuff.

Downloaded 38 of Kixforms..

Does the Find work? Has there been any consderation of putting a replace in the code? The best replace code (compiled that is, IMHO) that is out there is in EditPad.

Anyway, thank you for the KiXPad.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#91741 - 2003-03-14 02:22 PM Re: Kixforms: Notepad ala Kixscript ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
replace in kixforms is so freaking easy!
it's matter of $.text=join(split($.text,$what),$with)
but find is different matter.

although that is also easy, it requires some coding.
_________________________
!

download KiXnet

Top
#91742 - 2003-03-14 02:23 PM Re: Kixforms: Notepad ala Kixscript ...
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Right..

I am talking in the UI, though.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#91743 - 2003-03-14 02:25 PM Re: Kixforms: Notepad ala Kixscript ...
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
OK.. Now I see what is going on. Shawn is working on a new version.. I went to the link and downloaded the KiXPad script from http://kixforms.org and then I came back and copied the code from here.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#91744 - 2003-03-14 03:51 PM Re: Kixforms: Notepad ala Kixscript ...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Jooel:

My tongue-in-cheek post rather referred to a fully developed IDE (Integrated Development Environment) coded entirely in KiXtart. Shawn's notepad demo is definitely the underlying basis for the IDE, which I am sure Shawn's already working on. [Big Grin] [Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#91745 - 2003-03-14 04:01 PM Re: Kixforms: Notepad ala Kixscript ...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I doubt Shawn actually has the time right now to code an IDE. More likely, he's posting this as a shell hoping that someone will pick up the ball and run with it.
Top
#91746 - 2003-03-14 04:01 PM Re: Kixforms: Notepad ala Kixscript ...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
uh... [Eek!]
will see.
_________________________
!

download KiXnet

Top
#91747 - 2003-03-14 08:11 PM Re: Kixforms: Notepad ala Kixscript ...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Here's a small snippet. Not extremely useful, but easy to roll with it.

code:
$Find = $Edit.MenuItems.Add("Find", "OnFindClick")

And
code:
function OnFindClick()
dim $toFind, $loc
$TextBox.SelStart = 0
$TextBox.SelLength = 0
$toFind = $Form.InputBox("Find What", "Find", "")
$loc = instr($TextBox.Text, $toFind)
if $toFind <> "" and $loc
$TextBox.SelStart = $loc - 1
$textBox.SelLength = len($toFind)
endif
endfunction

_________________________
Eric

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 735 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.107 seconds in which 0.06 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org