home *** CD-ROM | disk | FTP | other *** search
- *******************************************************************************
- * PROGRAM: Procfils.wfm
- *
- * WRITTEN BY: Borland Samples Group
- *
- * DATE: 3/95
- *
- * UPDATED: 5/95
- *
- * REVISION: $Revision: 1.6 $
- *
- * VERSION: Visual dBASE
- *
- * DESCRIPTION: This is a tool for viewing, adding and deleting currently
- * available Visual dBASE procedure files. It also optionally
- * allows viewing the classes/procedures/functions defined in a
- * procedure file you select.
- * The procedure list is updated whenever the form loses and regains
- * focus, to make sure the list is up to date.
- *
- * PARAMETERS: None
- *
- * CALLS: Buttons.cc (Custom controls file)
- *
- * USAGE: DO Procfils.wfm
- *
- ********************************************************************************
- #include <Messdlg.h>
-
- *** Error code returned for invalid file name from fopen()
- #define INVALID_FILE_NAME -1
- #define CONTINUE_LINE ";"
- #define INLINE_COMMENT "&" + "&" && Cannot have in one string
-
- create session
- set talk off
-
- ** END HEADER -- do not remove this line*
- * Generated on 04/20/95
- *
- parameter bModal
- local f
- f = new PROCFILSFORM()
- if (bModal)
- f.mdi = .F. && ensure not MDI
- f.ReadModal()
- else
- f.Open()
- endif
- CLASS PROCFILSFORM OF FORM
- set procedure to &_dbwinhome.custom\buttons.cc additive
- this.OnOpen = CLASS::FORM_ONOPEN
- this.OnClose = CLASS::FORM_ONCLOSE
- this.OnGotFocus = CLASS::FORM_ONGOTFOCUS
- this.ColorNormal = "N/BTNFACE"
- this.PageNo = 1
- this.TopMost = .F.
- this.Text = "dBASE Procedure File List"
- this.Height = 9.4111
- this.Left = 0
- this.Top = 0.6465
- this.Width = 79.833
-
- DEFINE RECTANGLE LISTRECT OF THIS;
- PROPERTY;
- ColorNormal "BTNTEXT/BTNFACE",;
- PageNo 1,;
- FontBold .F.,;
- Text "Open Procedure Files:",;
- Border .T.,;
- Height 8.9785,;
- Left 1,;
- Top 0.1973,;
- Width 62.666
-
- DEFINE RECTANGLE PROCFUNCLISTRECT OF THIS;
- PROPERTY;
- ColorNormal "BTNTEXT/BTNFACE",;
- PageNo 1,;
- Visible .F.,;
- FontBold .F.,;
- Text "Classes, Procedures and Functions in Selected Procedure File:",;
- Border .T.,;
- Height 9,;
- Left 1,;
- Top 10,;
- Width 78
-
- DEFINE LISTBOX PROCLIST OF THIS;
- PROPERTY;
- ColorNormal "B/W",;
- PageNo 1,;
- FontBold .F.,;
- ID 100,;
- Sorted .T.,;
- Height 7.8818,;
- ColorHighLight "W+/B",;
- OnSelChange CLASS::PROCLIST_ONSELCHANGE,;
- Left 2,;
- Top 1,;
- Width 60.666
-
- DEFINE PUSHBUTTON ADDPROCBUTTON OF THIS;
- PROPERTY;
- ColorNormal "BtnText/BtnFace",;
- PageNo 1,;
- FontBold .F.,;
- Text "Add ...",;
- SpeedTip "Add a Procedure File",;
- UpBitmap "RESOURCE #616",;
- Height 1.4023,;
- OnClick CLASS::ADDPROCBUTTON_ONCLICK,;
- Default .T.,;
- Group .T.,;
- Left 65,;
- Top 0.5977,;
- Width 14.166
-
- DEFINE PUSHBUTTON REMOVEPROCBUTTON OF THIS;
- PROPERTY;
- ColorNormal "BtnText/BtnFace",;
- PageNo 1,;
- FontBold .F.,;
- Text "Remove ...",;
- SpeedTip "Remove Selected Procedure File",;
- UpBitmap "RESOURCE #28",;
- Height 1.4258,;
- OnClick CLASS::REMOVEPROCBUTTON_ONCLICK,;
- Group .T.,;
- Left 65,;
- Top 2.3975,;
- Width 14.166
-
- DEFINE PUSHBUTTON PROCFUNCBUTTON OF THIS;
- PROPERTY;
- ColorNormal "BtnText/BtnFace",;
- PageNo 1,;
- FontBold .F.,;
- Text "Procedures...",;
- SpeedTip "Show Procedures in Selected File",;
- UpBitmap "RESOURCE #137",;
- Height 1.4072,;
- OnClick CLASS::PROCFUNCBUTTON_ONCLICK,;
- Group .T.,;
- Left 65,;
- Top 4.2979,;
- Width 14.166
-
- DEFINE CLOSEBUTTON CLOSEBUTTON1 OF THIS;
- PROPERTY;
- FontBold .F.,;
- SpeedTip "Close This Form",;
- Height 1.5371,;
- Group .T.,;
- Left 65,;
- Top 7.6973,;
- Width 14.166
-
- DEFINE LISTBOX PROCFUNCLIST OF THIS;
- PROPERTY;
- ColorNormal "B/W",;
- PageNo 1,;
- Visible .F.,;
- FontBold .F.,;
- ID 100,;
- Sorted .T.,;
- Height 7.9072,;
- ColorHighLight "W+/B",;
- Left 2,;
- Top 10.7979,;
- Width 76
-
- DEFINE CHECKBOX SORTPROCFILESCHECK OF THIS;
- PROPERTY;
- ColorNormal "BTNTEXT/BTNFACE",;
- PageNo 1,;
- FontBold .F.,;
- Text "Sorted",;
- Height 1.1172,;
- OnChange CLASS::SORTPROCFILESCHECK_ONCHANGE,;
- Group .T.,;
- Value .F.,;
- Left 65,;
- Top 6,;
- Width 14.833
-
- Procedure FORM_OnOpen
- *****************************************************************************
- private procName, procCnt
-
- form.procFileAr = new array(0) && Array of procedure files
- form.procFuncAr = new array(0) && Array of procs and funcs
-
- procName = ""
- procCnt = 0
- do
- procCnt = procCnt + 1
- procName = setto("procedure", procCnt)
- if .not. empty(procName)
- form.procFileAr.Add(procName)
- endif
- until empty(procName)
-
- form.sortedProcFileAr = new array(procCnt - 1) && Sorted version
- acopy(form.procFileAr, form.sortedProcFileAr)
- form.sortedProcFileAr.Sort()
-
- form.procList.dataSource = "array form.procFileAr" && Start with unsorted
- * Custom property for indicating currently used array
- form.procList.dataArray = form.procFileAr
- form.procList.curSel = 1
- form.procList.SetFocus()
-
-
- *****************************************************************************
-
- Procedure FORM_OnClose
- * Clean up
- *****************************************************************************
-
- close procedure &_dbwinhome.samples\Buttons.cc
-
-
- *****************************************************************************
-
- Procedure FORM_OnGotFocus
- * Refresh procedure list (delete closed procs, and add new procs)
- *****************************************************************************
- private i, procFileArSize, procFile, deletedElement, numDeleted, selected,;
- numAdded
-
- * Check for closed procedures
-
- procFileArSize = form.procFileAr.size
- numDeleted = 0
- i = 1
- do while (i <= procFileArSize) .and. (.not. empty(form.procFileAr[i]))
- procFile = form.procFileAr[i]
- if setto("procedure", i) <> procFile
- deletedElement = form.procFileAr.Scan(procFile) && Delete from
- form.procFileAr.Delete(deletedElement) && procFileAr
-
- deletedElement = form.sortedProcFileAr.Scan(procFile) && Delete from
- form.sortedProcFileAr.Delete(deletedElement) && sortedProcFileAr
- numDeleted = numDeleted + 1
- i = i - 1 && When proc file is deleted, all next array
- endif && elements move up by one
- i = i + 1
- enddo
-
- * Check for new opened procedures
-
- procFile = setto("procedure", i)
- numAdded = 0
- do while .not. empty(procFile)
- numAdded = numAdded + 1
- form.procFileAr.Add(procFile)
- form.sortedProcFileAr.Add(procFile)
- i = i + 1
- procFile = setto("procedure", i)
- enddo
-
- if numDeleted > 0 .or. numAdded > 0 && If open procedure list changed
- procFileArSize = form.procFileAr.size
- form.procFileAr.Resize(procFileArSize - numDeleted)
- form.sortedProcFileAr.Resize(procFileArSize - numDeleted)
- form.sortedProcFileAr.Sort()
- show object form.procList
-
- form.procList.OnSelChange()
- endif
-
- *****************************************************************************
-
- Procedure ADDPROCBUTTON_OnClick
- * Add a procedure file
- *****************************************************************************
- private procFile, addedElement
-
- if ConfirmationMessage("Are you sure you want to add a Procedure File?",;
- "Confirmation") = YES
- procFile = getfile("*.prg", "Select a procedure file")
- if .not. empty(procFile)
- if form.procFileAr.Scan(procFile) <> 0 && Already open procedure file
- InformationMessage(procfile + " is already open.", "Info")
- else
- set procedure to &procFile additive && Open new procedure file
- form.procFileAr.Add(procFile) && Add to array of open files
- form.sortedProcFileAr.Add(procFile) && Add to sorted array
- form.sortedProcFileAr.Sort()
- * Scan in currently used array
- addedElement = form.procList.dataArray.Scan(procFile)
- show object form.procList && Update proc listbox
- form.procList.curSel = addedElement
- form.procList.OnSelChange()
- endif
- else
- InformationMessage("No procedure file was selected.", "Info")
- endif
- endif
-
-
- *****************************************************************************
-
- Procedure REMOVEPROCBUTTON_OnClick
- * Remove a procedure file
- *****************************************************************************
- private procFile, procFileCnt, selected, deletedElement
-
- procFile = form.procList.Selected()
- do case
- case empty(procFile)
- InformationMessage("No Procedure file is currently selected", "Info")
- case procFile = program(1)
- InformationMessage("You cannot close the file associated with this program", "Info")
- case procFile = _dbwinhome + "SAMPLES\BUTTONS.CC"
- InformationMessage("You cannot close Buttons.cc -- this program uses that file.", "Info")
- otherwise
- if ConfirmationMessage("Are you sure you want to close " + chr(13) +;
- procFile + "?",;
- "Confirmation") = YES
- close procedure &procFile
- * Delete procFile from sorted and unsorted arrays
- if form.sortProcFilesCheck.value && If sorted list
- form.sortedProcFileAr.Delete(form.procList.curSel)
- deletedElement = form.procFileAr.Scan(procFile)
- form.procFileAr.Delete(deletedElement)
- procFileCnt = form.sortedProcFileAr.size
- else
- form.procFileAr.Delete(form.procList.curSel)
- deletedElement = form.sortedProcFileAr.Scan(procFile)
- form.sortedProcFileAr.Delete(deletedElement)
- procFileCnt = form.procFileAr.size
- endif
-
- if procFileCnt > 1 && If more than one proc file
- selected = form.procList.curSel
- form.procFileAr.Resize(procFileCnt - 1)
- form.sortedProcFileAr.Resize(procFileCnt - 1)
- if selected > form.procFileAr.size
- form.procList.curSel = form.procFileAr.size
- else
- form.procList.curSel = selected
- endif
- show object form.procList
- form.procList.OnSelChange()
- else && No Procedure files
- form.procFileAr = new array(0)
- form.sortedProcFileAr = new array(0)
- form.sortProcFilesCheck.OnChange()
- if form.procFuncButton.text = "No Procs..."
- form.procFuncAr = new array(0)
- form.procFuncList.dataSource = "array form.procFuncAr"
- show object form.procFuncList
- endif
- InformationMessage("All procedure files are closed.", "Info")
- endif
- endif
- endcase
-
-
-
- *****************************************************************************
-
- Procedure PROCFUNCBUTTON_OnClick
- * Show/Close list of classes/procedures/functions
- *****************************************************************************
- private selProcFile
-
- selProcFile = form.procList.Selected()
- if this.text = "No Procs..." && Don't show procedures
- this.text = "Procedures..." && Make procedures visible
- && on next click
- this.speedTip = "Show Procedures in Selected File"
- this.upBitmap = "RESOURCE #137"
- form.height = 9.4
- form.procFuncList.visible = .F.
- form.procFuncListRect.visible = .F.
- form.procFuncAr = new array(0)
- else
- if empty(selProcFile) && Make sure a procedure file
- && is selected
- InformationMessage("No procedure file has been selected.", "Info")
- else
- CLASS::ShowProcFuncs(selProcFile)
- this.text = "No Procs..."
- this.speedTip = "Don't Show Procedures"
- this.upBitmap = "RESOURCE #136"
- form.height = 19.4
- form.procFuncListRect.visible = .T.
- form.procFuncList.visible = .T.
- endif
- endif
-
-
- *****************************************************************************
-
- Procedure PROCLIST_OnSelChange
- * If procedure list is visible, update it as you move thorough procedure
- * file list
- *****************************************************************************
- if form.procfuncbutton.text = "No Procs..." && If showing procedures,
- CLASS::ShowProcFuncs(this.selected()) && retrieve current ones
- endif
-
-
- *******************************************************************************
-
- Procedure ShowProcFuncs(selProcFile)
- * Show classes/procedures/functions defined in selected procedure file
- *******************************************************************************
- private hProcFile, line, trimLine, firstSpaceAfterWordLoc, lowFirstWord,;
- saveExact, prevLineLastChar, noCommentLine
-
- form.mousePointer = 11 && Wait
-
- saveExact = set("exact")
- set exact on
- prevLineLastChar = " "
- hProcFile = fopen(selProcFile, "R") && Open selected file
-
- if hProcFile = INVALID_FILE_NAME
- ErrorMessage("Couldn't open file " + chr(13) + selProcFile, "Oops")
- else
- form.procFuncAr = new array(0)
- do while .not. feof(hProcFile) && Until end of file
- line = fgets(hProcFile) && Get a line, and
- && remove initial spaces
- trimLine = ltrim(line)
- firstSpaceAfterWordLoc = at(" ", trimLine) && First space after
- && routine indicator
- lowFirstWord = lower(left(trimLine, firstSpaceAfterWordLoc - 1))
-
- if (lowFirstWord = "procedure" .or. lowFirstWord = "function" .or.;
- lowFirstWord = "class" ) .and. prevLineLastChar <> CONTINUE_LINE
-
- form.procFuncAr.Add(line)
- endif
-
- * Get last non comment character
- commentLoc = rat(INLINE_COMMENT, line) && Comment char location
- if commentLoc > 0 && If have comment,
- noCommentLine = left(line, commentLoc - 1) && strip it.
- else && Otherwise,
- noCommentLine = line && use whole line
- endif
-
- * Store last character on line before inline comment
- prevLineLastChar = right(rtrim(noCommentLine), 1)
-
- enddo
-
- * Update procFuncList listbox
- form.procFuncList.dataSource = "array form.procFuncAr"
- show object form.procFuncList
- fclose(hProcFile) && Close file
-
- endif
- set exact &saveExact
-
- form.mousePointer = 0
-
- *******************************************************************************
-
- Procedure SORTPROCFILESCHECK_OnChange
- * Display procedures in sorted/setting order
- *******************************************************************************
- private selProcFile, newCurSelProcFile
-
- selProcFile = form.procList.Selected()
- if this.value && Sort List
- form.procList.dataSource = "array form.sortedProcFileAr"
- * Custom property on listbox that indicates currently used array
- form.procList.dataArray = form.sortedProcFileAr
- newCurSelProcFile = form.sortedProcFileAr.Scan(selProcFile)
- else && Put list in procedure setting order
- form.procList.dataSource = "array form.procFileAr"
- * Custom property on listbox that indicates currently used array
- form.procList.dataArray = form.procFileAr
- newCurSelProcFile = form.procFileAr.Scan(selProcFile)
- endif
-
- form.procList.curSel = newCurSelProcFile
- show object form.procList
-
- ENDCLASS
-
-
-
-
-
-
-
-
-
-
-
-