📄 fsupselector.class
字号:
' Gambas class file' 15 Jul 2005 - BM: For a symlink to directory, IsDir() is true, but Stat().Type = gb.Link! See in Fill_Explorer' 14 Jul 2004 - BM: Replace the old Splitter by the new HSplit' 17 Jun 2004 - BM: Initial refresh is done later so that initial Path is correctly set' 03 Apr 2004 - BM: Use TreeExplorer_Select instead of TreeExplorer_Click and display some messages in Validate' 14 Mar 2004 - BM: Fix loading/saving Splitter.Layout' 11 Feb 2004 - BM: Fix code indentation and upgrade Stat() usage' 27 Jan 2004 - BM: TestProtected() tests if a file is protected, i.e. inside the current project.' 09 Jan 2004 - BM: The initial path works' 20 Dec 2003 - BM: Fix bug in ChangeExplorer() that lead to a bad Splitter layout.' 20 Dec 2003 - BM: New TreeView/ListView syntax' 16 Dec 2003 - BM: Modified for the use of the New Dir() syntaxPUBLIC CONST SHOW_PROJECT AS Integer = 1PUBLIC CONST SHOW_DIRECTORY AS Integer = 2PUBLIC CONST SHOW_FILE AS Integer = 3PUBLIC CONST SHOW_IMAGE AS Integer = 4PRIVATE CONST FILE_CLIPBOARD_FORMAT AS String = "text/uri-list"PRIVATE CONST MAX_PIC_FILE_SIZE AS Integer = 65536'EVENT Select()PUBLIC PreviewImg AS BooleanPUBLIC ShowHidden AS Boolean'Define RootPUBLIC Root AS String'Define Parent button placePUBLIC ButtonWidth AS Integer'Define Default Path and return Selected PathPUBLIC Path AS String'Allow New FileName or not and return it by PathPUBLIC bAllowNewFile AS Boolean'Fix The key property to save bookmark and positionPUBLIC key AS String'Select The Dialog version for project selecting, directory or picturePUBLIC DialogType AS Integer'Store the Filter string as : "Gambas files|*.form,*.class|All files|*"PUBLIC Filters AS String'Define the default filter selected in the Filters stringPUBLIC FilterIndex AS Integer'Define the Default bookmark'Show home bookmarkPUBLIC ShowHomeTab AS Boolean'Show Root bookmarkPUBLIC ShowRootTab AS Boolean'Show Current Project bookmarkPUBLIC ShowProjectTab AS Boolean'Allow or not to select a project child. For the new project for example.PUBLIC ChildSelect AS Boolean' OK buttonPUBLIC OKButton AS ButtonPUBLIC NoProjectDir AS BooleanPUBLIC DoNotShowCustomTabs AS BooleanPRIVATE Explorer AS ObjectPRIVATE $arFilters AS NEW Object[]PRIVATE imgProject AS PicturePRIVATE imgNothing AS PicturePRIVATE imgBackup AS PicturePRIVATE imgClass AS PicturePRIVATE imgForm AS PicturePRIVATE imgModule AS PicturePRIVATE imgPicture AS PicturePRIVATE imgDirectory AS PicturePRIVATE imgNoDir AS PicturePRIVATE imgTreeDir AS PicturePRIVATE imgTreeNoDir AS PicturePRIVATE imgTreeProject AS picturePRIVATE imgTreeRoot AS picturePRIVATE CurrentPath AS StringPRIVATE arMenu AS NEW Object[]PRIVATE arTmpImg AS NEW String[]PRIVATE iImageSize AS IntegerPRIVATE TExplorer AS IntegerPRIVATE CoolTab AS CCoolTabsPRIVATE IsCutMode AS BooleanPRIVATE stkCurStr AS StringPUBLIC TreeSequence AS StringPRIVATE bCutMode AS BooleanPRIVATE arFile AS NEW String[]PRIVATE iLevel AS IntegerPRIVATE iMenuFrom AS IntegerPRIVATE CurSeq AS StringPRIVATE $sLastPath AS StringPRIVATE $bDoNotConfirm AS BooleanPUBLIC SUB Init() DIM TExplo AS Integer DIM sElt AS String DIM sDir AS String WITH cvExplorer .Columns.Count = 4 .Columns[0].Text = ("Name") .Columns[0].Width = 150 .Columns[1].Text = ("Size") .Columns[1].Width = 50 .Columns[1].Alignment = Align.Right .Columns[2].Text = ("Type") .Columns[2].Width = 80 .Columns[3].Text = ("Date") .Columns[3].Width = 80 END WITH imgTreeDir = Picture["img/16/close.png"] imgTreeNoDir = Picture["img/16/forbid.png"] imgTreeProject = Picture["img/16/gambas.png"] imgTreeRoot = Picture["img/16/close.png"] CoolTab = NEW CCoolTabs(ME,ShowRootTab,ShowHomeTab,ShowProjectTab) AS "CoolTab" TExplorer = -1 GetTabs() IF (NOT Exist(Root) OR NOT Root) AND NOT TreeSequence THEN TreeSequence = "0" ELSE TreeSequence = "$" ENDIF IF NOT Key THEN Key = "/GenericExplorer" 'Project.Config.Read(Key &/ "Key") TExplo = Settings[Key &/ "ExplorerType", 0]' IF Project.Config.Read(Key &/ "ExplorerType") THEN' TExplo = CInt(Project.Config.Read(Key &/ "ExplorerType"))' ELSE' Texplo = 0' ENDIF 'CurrentPath = Project.Config.Read(Key &/ "Path") 'IF Project.Config.Read(Key &/ "ExplorerSplitPos") THEN 'ENDIF 'IF Project.Config.Read(key &/ "TreeSequence") THEN TreeSequence = Settings[Key &/ "TreeSequence", TreeSequence] 'PRINT TreeSequence 'ENDIF' IF Project.Config.Read(key &/ "PreviewImg") AND NOT PreviewImg THEN' PreviewImg = CBool(Project.Config.Read(key &/ "PreviewImg"))' ENDIF PreviewImg = Settings[Key &/ "PreviewImg", FALSE]' IF Project.Config.Read(key &/ "ShowHidden") AND NOT ShowHidden THEN' ShowHidden = CBool(Project.Config.Read(key &/ "ShowHidden"))' ENDIF ShowHidden = Settings[Key &/ "ShowHidden", FALSE] CurrentPath = Settings[Key &/ "Path", System.Home] SELECT CASE DialogType CASE SHOW_PROJECT ChangeExplorer(TExplo) lblFile.Text = ("Project") CASE SHOW_DIRECTORY ChangeExplorer(TExplo) cboFilter.Visible = FALSE lblFilter.Visible = FALSE lblFile.Text = ("Directory") CASE SHOW_IMAGE ChangeExplorer(1) lblFile.Text = ("File") CASE SHOW_FILE ChangeExplorer(TExplo) lblFile.Text = ("File") END SELECT Splitter.Layout = Settings[Key &/ "Splitter", "10,10"] IF NOT Filters THEN Filters = ("All files") & "|*" Definefilters IF Path AND Exist(Path) THEN 'PRINT Path IF NOT IsDir(Path) THEN CurrentPath = File.Dir(Path) ELSE CurrentPath = Path ENDIF ELSE IF NOT CurrentPath THEN CurrentPath = Root ENDIF IF Left$(CurrentPath) <> "/" THEN CurrentPath = Root &/ CurrentPath IF NOT (CurrentPath LIKE (Root &/ "*")) THEN CurrentPath = Root btnRefresh_Click MakeMenu() IF DialogType = SHOW_DIRECTORY THEN txtFile.Text = File.Name(CurrentPath) TreeExplorer.MoveFirst IF SelectNode(Left$(TreeExplorer.Key) & CurrentPath) THEN CurrentPath = Mid$(TreeExplorer.Key,2) ENDIF 'arProtectedFiles.Add(System.Home) 'arProtectedFiles.Add(Project.Path) 'arProtectedFiles.Add(System.Home &/ ".gambas") Fill_Explorer(CurrentPath) 'PRINT Root & " " & CurrentPathENDPUBLIC SUB Fill_Explorer(sPath AS String) DIM arFile AS NEW String[] DIM arTemp AS NEW String[] DIM sDir AS String DIM scDir AS String DIM rapport AS Float DIM hPic AS NEW Picture DIM sFilter AS String DIM fTime AS Float IF sPath = $sLastPath THEN RETURN INC Application.Busy Explorer.Clear arTmpImg.Clear 'TRY sDir = Dir(sPath) 'IF Error THEN RETURN FOR EACH sDir IN Dir(sPath) IF NOT IsDir(sPath &/ sDir) THEN CONTINUE IF NOT ShowHidden THEN IF Stat(sPath &/ sDir).Hidden THEN CONTINUE ENDIF arFile.add(sDir) NEXT arFile.Sort FOR EACH sFilter IN $arFilters[(cboFilter.Index + 1) * 2 - 1] FOR EACH sDir IN Dir(sPath, sFilter) IF IsDir(sPath &/ sDir) THEN CONTINUE WITH Stat(sPath &/ sDir) IF NOT ShowHidden THEN IF .Hidden THEN CONTINUE IF Right(sDir) = "~" THEN CONTINUE ENDIF END WITH arTemp.add(sDir) NEXT NEXT arTemp.Sort arFile.Insert(arTemp) fTime = Timer WAIT FOR EACH sDir IN arFile 'scDir = Conv$(sDir, System.Charset, DeskTop.Charset) scDir = sDir 'Stat(sPath &/ sDir) IF IsDir(sPath &/ sDir) THEN IF Exist(sPath &/ sDir &/ ".project") THEN Explorer.Add(sPath &/ sDir, scDir, imgProject) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Gambas project") ELSE IF AccessTest(sPath &/ sDir) THEN Explorer.Add(sPath &/ sDir, scDir, imgDirectory) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Directory") ELSE Explorer.Add(sPath &/ sDir, scDir, imgNoDir) ENDIF ENDIF ELSE SELECT CASE LCase(File.Ext(sDir)) CASE "class" Explorer.Add(sPath &/ sDir, scDir, imgClass) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Gambas class") CASE "form" Explorer.Add(sPath &/ sDir, scDir, imgForm) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Gambas form") CASE "module" Explorer.Add(sPath &/ sDir, scDir, imgModule) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Gambas module") CASE "xpm", "png", "jpg", "bmp", "gif","jpeg","svg" 'Explorer.Add(sPath &/ sDir, scDir, imgPicture) WITH Stat(SPath &/ sDir) IF NOT PreviewImg THEN 'Case not preview Explorer.add(sPath &/ sDir, File.Name(scDir), imgPicture) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Picture file") GOTO NoPic ENDIF' IF .Size < MAX_PIC_FILE_SIZE THEN'' TRY hPic.Load(sPath &/ sDir)' IF Error THEN hPic = Picture["img/16/image.png"]'' IF hPic.Height > iImageSize OR hPic.Width > iImageSize THEN' IF hPic.height > hPic.Width THEN' rapport = iImageSize / hPic.Height' TRY hPic = hPic.Image.Stretch(hPic.Width * rapport,iImageSize).Picture' ELSE' rapport = iImageSize / hPic.Width' TRY hPic = hPic.Image.Stretch(iImageSize, hPic.Height * rapport).Picture' END IF' Explorer.Add(sPath &/ sDir, File.Name(scDir), hPic)' ELSE' Explorer.Add(sPath &/ sDir, File.Name(scDir), hPic)' ENDIF' IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Picture file")'' ELSE IF .Size < MAX_PIC_FILE_SIZE THEN arTmpImg.Push(sPath &/ sDir) Explorer.add(sPath &/ sDir, File.Name(scDir), imgPicture) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Picture file")' END IF END WITH CASE ELSE IF Right(sDir) = "~" THEN Explorer.Add(sPath &/ sDir, scDir, imgBackup) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("Backup file") ELSE Explorer.Add(sPath &/ sDir, scDir, imgNothing) IF TExplorer = 0 THEN Explorer[sPath &/ sDir][2] = ("File") ENDIF END SELECT ENDIF NoPic: IF TExplorer = 0 THEN WITH Stat(sPath &/ sDir) Explorer[sPath &/ sDir][1] = Subst(("&1 K"),(.Size + 1023) \ 1024) Explorer[sPath &/ sDir][3] = Format(.Time, gb.ShortDate) END WITH ENDIF IF fTime < (Timer - 4) THEN fTime = Timer WAIT ENDIF NEXT imgTimer.Enabled = TRUE Fill_Look(sPath)FINALLY DEC Application.Busy $sLastPath = sPathCATCH Explorer.ClearENDPUBLIC SUB Explorer_Activate() IF IsDir(Explorer.Key) THEN IF AccessTest(Explorer.Key) THEN CurrentPath = Explorer.Key Fill_Explorer(CurrentPath) 'Message(Left(TreeExplorer.Current.Key,1) & CurrentPath) SelectNode(Left(TreeExplorer.Key,1) & CurrentPath) ENDIF ELSE IF Validate(Explorer.Key) THEN txtFile.Text = Explorer.Current.Text RaiseSelect ENDIFCATCHENDPRIVATE FUNCTION AccessTest(sPath AS String) AS Boolean ' $BM Il y a un appel à cette fonction avec sPath = "". C'est bizarre ! ' $BM Mais ça m'a permis de trouver un bug dans l'interpréteur :-) 'Dir(sPath) DIM aDir AS String[] aDir = Dir(sPath) IF aDir.Count THEN Stat(sPath &/ aDir[0]) RETURN TRUE CATCH RETURN FALSEENDPRIVATE FUNCTION IsProjectChild(sPath AS String) AS Boolean WHILE sPath <> "/" IF Exist(sPath &/ ".project") THEN RETURN TRUE sPath = File.Dir(sPath) WEND RETURN FALSEENDPUBLIC SUB imgTimer_Timer() DIM hPicPicture AS Picture DIM sDir AS String DIM rapport AS Float IF arTmpImg.Count = 0 THEN imgTimer.Enabled = FALSE RETURN ENDIF sDir = arTmpImg[0] arTmpImg.Remove(0) hPicPicture = NEW Picture TRY hPicPicture.Load(sDir) IF ERROR THEN RETURN 'IF hPicPicture.height > iImageSize OR hPicPicture.width > iImageSize THEN IF hPicPicture.height > hPicPicture.Width THEN rapport = iImageSize / hPicPicture.Height TRY hPicPicture = hPicPicture.Image.Stretch(hPicPicture.Width * rapport,iImageSize).Picture ELSE rapport = iImageSize / hPicPicture.Width TRY hPicPicture = hPicPicture.Image.Stretch(iImageSize, hPicPicture.Height * rapport).Picture END IF Explorer[sDir].Picture = hPicPicture ' $BM ' Explorer.Arrangement = Explorer.TopBottom' ELSE'' Explorer[sDir].Picture = hPicPicture' Explorer.Refresh'' ENDIFENDPRIVATE SUB ChangeExplorer(iType AS Integer) DIM arSpl AS String[] IF iType = TExplorer THEN RETURN Texplorer = iType IF TExplorer = 0 THEN imgNothing = Picture["img/16/unknown.png"] imgBackup = Picture["img/16/backup.png"] imgClass = Picture["img/16/class.png"] imgForm = Picture["img/16/form.png"] imgModule = Picture["img/16/module.png"] imgPicture = Picture["img/16/image.png"] imgProject = Picture["img/16/gambas.png"] imgDirectory = Picture["img/16/close.png"] imgNoDir = Picture["img/16/forbid.png"] Explorer = cvExplorer iImageSize = 16 ivExplorer.Visible = FALSE cvExplorer.Visible = TRUE btnTypeList.Picture = Picture["img/16/icon.png"] btnTypeList.ToolTip = ("Show by icon") ELSE imgNothing = Picture["img/32/text.png"] imgBackup = Picture["img/32/backup.png"] imgClass = Picture["img/32/class.png"]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -