home *** CD-ROM | disk | FTP | other *** search
- *******************************************************************************
- * PROGRAM: Changdir.prg
- *
- * WRITTEN BY: Borland Samples Group
- *
- * DATE: 11/93
- *
- * UPDATED: 6/94
- *
- * VERSION: dBASE FOR WINDOWS 5.0
- *
- * DESCRIPTION: This is a tool for changing directories. It brings up a
- * listbox of the current subdirectories, and lets you traverse
- * your directory tree. Double clicking in the listbox will
- * select that directory. Selecting the OK button makes your
- * selected directory the current directory, and the CANCEL
- * button cancels the program.
- *
- * PARAMETERS: None
- *
- * CALLS: Buttons.cc (Custom controls file)
- *
- * USAGE: Do Changdir/Changdir()
- *
- * NOTE: dBASEWIN has a function, GetDirectory(), which accomplishes
- * the same task as this program.
- *
- *******************************************************************************
-
- #include <Messdlg.h>
- #include <Utils.h>
-
- create session
-
- set talk off
- set ldCheck off
- set procedure to program(1) additive
- set procedure to buttons.cc additive
-
- public f
- f = new ChangDir()
- f.ReadModal()
-
- *******************************************************************************
- *******************************************************************************
- class ChangDir of Form
- *******************************************************************************
- this.top = 5.30
- this.left = 6.76
- this.height = 19.49
- this.width = 54.06
- this.mdi = .f.
- this.sysmenu = .t.
- this.text = "Change Directory"
- this.sizeable = .t.
- this.OnSelection = CLASS::OkOnClick
-
- define listbox directList of this;
- property;
- OnLeftDblClick CLASS::SetNewDir,;
- top 3.18,;
- left 1.35,;
- height 15.91,;
- width 36.49,;
- colornormal "b/w",;
- statusmessage "Click on a directory to display it,;
- Double click select it.";
- custom;
- dir set("directory")
-
- define entryfield curDirEntry of this;
- property;
- top 1.06,;
- left 0.00,;
- width 54.06,;
- value space(78),;
- colornormal "b/bg",;
- colorhighlight "b/w",;
- picture "@S78!",;
- statusmessage "Currently selected directory.",;
- OnGotFocus {;form.prevDir = this.Value},;
- OnLostFocus CLASS::CheckDirExists
-
- define OkButton okToChange of this;
- property;
- OnClick CLASS::OkOnClick,;
- top 3.18,;
- left 39.19,;
- statusmessage "Change directory to the one selected."
-
- define CancelButton cancelChange of this;
- property;
- OnClick CLASS::CancelOnClick,;
- top 5.05,;
- left 39.19,;
- statusmessage "Forget it."
-
-
-
- ******************************************************************************
- procedure OkOnClick
- ******************************************************************************
- private temp
-
- if CLASS::CheckDirExists()
- temp = form.curDir
- cd &temp
- form.Close()
- endif
-
- ******************************************************************************
- procedure CancelOnClick
- ******************************************************************************
- private d && macrosubstituted variables cannot be local.
-
- d = form.saveDir
- cd &d
- form.Close()
-
-
- ******************************************************************************
- procedure OnOpen
- ******************************************************************************
- private temp && macrosubstituted variables cannot be local.
-
- form.saveDir = set("directory") && save current dir in case Cancel selected
- form.savePath = setto("path") && save current path because it will change
- form.setExact = set("exact") && for restoring when leave
-
- form.curDir = setto("directory") && current directory
- set path to &_dbwinhome.samples
- set exact on
- form.CreateDirArray() && Create array of current subdirectories
-
- form.directList.dataSource = "array form.dirAr"
- form.curDirEntry.dataLink = "form.curDir"
- show object form.directList
- show object form.curDirEntry
-
-
- ******************************************************************************
- procedure OnClose
- ******************************************************************************
- private p,e && macrosubstituted variables cannot be local.
-
- p = form.savePath
- e = form.setExact
- set path to &p
- set exact &e
- cd
-
-
- ******************************************************************************
- procedure SetNewDir
-
- ******************************************************************************
- private newDir,divideChar,showDir,lastSlashLoc,trimCurDir,temp
-
- newDir = ALLTRIM(form.directList.value)
- trimCurDir = ALLTRIM(form.curDir)
- lastSlashLoc = rat("\",trimCurDir)
- if .not. empty(newDir) .and. newDir <> "."
- divideChar = iif(right(trimCurDir,1) = "\","","\")
- && if last char of
- && form.curDir is '\', don't need
- && to add it
- if newDir = ".." && Go back a directory
- && ?more than one branch off the root
- form.curDir = substr(trimCurDir,1,lastSlashLoc - ;
- iif(lastSlashLoc > 3,1,0))
- else
- form.curDir = trimCurDir + iif(.not. empty(newDir),divideChar,"");
- + newDir
- endif
- temp = form.curDir
- cd &temp
- form.dirAr = new Array(0)
- form.CreateDirArray()
- show object form.curDirEntry
- show object form.directList
- redefine listbox directList of form;
- property;
- top 3.18,;
- left 1.35,;
- height 15.91,;
- width 36.49,;
- dataSource "array form.dirAr",;
- colornormal "b/w";
- custom;
- dir form.curDir
- endif
-
- ******************************************************************************
- procedure CreateDirArray
-
- * This needs to be a function to be called with () convention
- ******************************************************************************
- private i,j,tempAr,tempArSize
-
- tempAr = new Array(0)
- tempArSize = tempAr.Dir("*.*","D")
- j = 0
- form.dirAr = new Array(0)
- for i = 1 to tempArSize
- if tempAr[i,5] = "....D" && if directory, add it to form.dirAr
- j = j + 1
- form.dirAr.Grow(1)
- form.dirAr[j] = tempAr[i,1]
- endif
- next i
- form.dirAr.Sort()
-
-
- ******************************************************************************
- function CheckDirExists
- ******************************************************************************
- local ratSlash,tempDir,lenCurDir,exit
- private dirExists,temp && LOCALs cannot be macrosubstituted
-
- ratSlash = rat("\",form.curDir)
- lenCurDir = len(rtrim(form.curDir))
- dirExists = .t.
- exit = .f.
-
- do case
- case .not. DirExists(form.curDir)
- if ConfirmationMessage(ALLTRIM(form.curDir) + chr(13) +;
- "Doesn't exist. Continue?","Confirmation") = YES
- form.curDir = form.prevDir
- show object form.curDirEntry
- else
- exit = .t.
- endif
- dirExists = .f.
- case rat(":",form.curDir) = lenCurDir && only drive is entered
- form.curDir = form.directList.dir
- show object form.curDirEntry
- case form.curDir <> form.directList.dir
- * can't use RIGHT() because string doesn't necessarily fill value
- if ratSlash = lenCurDir .and. lenCurDir > 3 && get rid of last \
- form.curDir = stuff(form.curDir, ratSlash, 1, "")
- endif
- temp = form.curDir
- cd &temp
- show object form.curDirEntry && update entryfield display
- form.CreateDirArray()
- redefine listbox directList of form;
- property;
- top 3.18,;
- left 1.35,;
- height 15.91,;
- width 36.49,;
- dataSource "array form.dirAr",;
- colornormal "b/w";
- custom;
- dir form.curDir
- endcase
- if exit
- form.cancelChange.OnClick()
- endif
- return dirExists
-
-
- endclass
-
- ******************************************************************************
- function DirExists( dir )
-
- * Use adir() to create an array of subdirectories of the dir in question.
- * If any subdirectories exist (including ..\.), then dir exists.
- ******************************************************************************
- private d,checkAr,retVal,lastSlashLoc
-
- d = rtrim(dir)
- declare checkAr[1]
- d = iif(right(d, 1) <> "\", rtrim(d) + "\", d) && make dir end with \
- return iif(adir(checkAr, d + "*.", "D") = 0, .f., .t.)
-