From 93afd49f7c129ad8acac46b4aa123479d92b1da5 Mon Sep 17 00:00:00 2001 From: Bruce Steers Date: Fri, 7 Jan 2022 22:42:38 +0000 Subject: [PATCH] New FileBox control. Add Path property to DirBox and FileBox. [GB.FORM] * NEW: Add FileBox control, supports open/save mode, filters, custom picture and placeholder. * NEW: Add Path property to DirBox and FileBox as a synonym for Value and show it in the IDE. --- comp/src/gb.form/.hidden/control/filebox.png | Bin 0 -> 802 bytes comp/src/gb.form/.project | 2 +- comp/src/gb.form/.src/File/DirBox.class | 4 +- comp/src/gb.form/.src/File/FileBox.class | 172 ++++++++++++++++++ comp/src/gb.form/.src/Test/FTestFileBox.class | 2 + comp/src/gb.form/.src/Test/FTestFileBox.form | 24 +++ 6 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 comp/src/gb.form/.hidden/control/filebox.png create mode 100644 comp/src/gb.form/.src/File/FileBox.class create mode 100644 comp/src/gb.form/.src/Test/FTestFileBox.class create mode 100644 comp/src/gb.form/.src/Test/FTestFileBox.form diff --git a/comp/src/gb.form/.hidden/control/filebox.png b/comp/src/gb.form/.hidden/control/filebox.png new file mode 100644 index 0000000000000000000000000000000000000000..23f30186a7364a94d3c8ed19b367e382e0f3ea7d GIT binary patch literal 802 zcmV+-1Ks?IP)E%d(i9oW!pvEDls31OX=}CkP>!nVI4A^ptwN zj^jAY&(D*|WB~d^jEn%d3pZ#N=ni@X=#bY#YNifHlF8kc6LS(1bzFDg#e{g?{yrFenfE_4V~N+uPe%mW5IZDJ5YTa&>jZ(a{mE>prR-3juH^VPaweDJ9Kjv$tI- zg>Bok+wDi&yNr#1Y&OgK`g-3LWgN#GA0KmYaPVZ^*a+y(0DlujQEv)-im@03{{0dX92adGkLUs;2olzOyo_z>*^=H}+u*x1l^{KOA}Mu6@Bx-kNP zHrzcul|Wh+@B^S$t0hsw&%{3{ncCaiyIfse{RWhPcR*Hiu(zfOd>2A|saC6py2BU@ g27|$1Fc@_42VEKeOW5^r7XSbN07*qoM6N<$g7cDUH~;_u literal 0 HcmV?d00001 diff --git a/comp/src/gb.form/.project b/comp/src/gb.form/.project index 3106818c5..81da1edc1 100644 --- a/comp/src/gb.form/.project +++ b/comp/src/gb.form/.project @@ -1,6 +1,6 @@ # Gambas Project File 3.0 Title=More controls for graphical components -Startup=FTestTableView +Startup=FTestFileBox Icon=.hidden/icon.png Version=3.16.90 VersionFile=1 diff --git a/comp/src/gb.form/.src/File/DirBox.class b/comp/src/gb.form/.src/File/DirBox.class index b09fb8782..e5a0d48c4 100644 --- a/comp/src/gb.form/.src/File/DirBox.class +++ b/comp/src/gb.form/.src/File/DirBox.class @@ -3,7 +3,7 @@ Export Inherits UserControl -Public Const _Properties As String = "*,Action,Border=True" +Public Const _Properties As String = "*,Path,Action,Border=True" Public Const _DefaultEvent As String = "Click" Public Const _DefaultSize As String = "32,4" Public Const _Similar As String = "TextBox" @@ -12,7 +12,7 @@ Public Const _Group As String = "Chooser" Event Click Event Change -Property Value As String +Property Value, Path As String Property Border As Boolean Private $hButtonBox As ButtonBox diff --git a/comp/src/gb.form/.src/File/FileBox.class b/comp/src/gb.form/.src/File/FileBox.class new file mode 100644 index 000000000..19ddaf012 --- /dev/null +++ b/comp/src/gb.form/.src/File/FileBox.class @@ -0,0 +1,172 @@ +' Gambas class file + +Export +Inherits UserControl + +Public Const _Properties As String = "*,Path,Action,Border=True,SaveFile,Title,Filter,Picture,Placeholder" +Public Const _DefaultEvent As String = "Click" +Public Const _DefaultSize As String = "32,4" +Public Const _Similar As String = "TextBox,DirBox" +Public Const _Group As String = "Chooser" + +Event Click +Event Change + +Property Value, Path As String +Property Border As Boolean +Property Title As String + +'' Use a custom image for the button. Default is a file icon. +Property Picture As Picture +Property Placeholder As String + +'' File dialog will be for saving files. (it will give overwrite warnings for existing files) +Property SaveFile As Boolean + +'' A space separated list of filters and their names\ +'' Filter extensions use wildcards and are seperated with semicolons;\ +'' Use doublequotes to use spaces in names. +'' +'' [[ +'' == +'' Eg.\ +'' "*.png;*.jpg "Image files" *.ico "Icon Files" +'' ]] +'' . +Property Filter As String + +Private $sFilter As String +Private $bSaveFile As Boolean +Private $sTitle As String = "Select file..." + +Private $hButtonBox As ButtonBox + +Public Sub _new() + + $hButtonBox = New ButtonBox(Me) As "Button" + Me.Proxy = $hButtonBox + $hButtonBox.Picture = Picture["icon:/small/file"] + $hButtonBox.ReadOnly = True + $hButtonBox.ClearButton = True + +End + +Public Sub Button_Click() + + Dim sTitleBU As String = Dialog.Title + Dim sFilters, sFilterBU As String[] + + If $sFilter Then + sFilterBU = Dialog.Filter + sFilters = Split($sFilter, " ", "\"") + Dialog.Filter = sFilters + Endif + + Dialog.Path = $hButtonBox.Text + Dialog.Title = $sTitle + + If $bSaveFile Then + If Dialog.SaveFile() Then Goto CleanUp + Else + If Dialog.OpenFile() Then Goto CleanUp + Endif + + $hButtonBox.Text = Dialog.Path + Raise Click + +CleanUp: + Dialog.Title = sTitleBU + If $sFilter Then Dialog.Filter = sFilterBU + Return + +End + +Public Sub Button_Change() + + Raise Change + +End + +Private Function Border_Read() As Boolean + + Return $hButtonBox.Border + +End + +Private Sub Border_Write(Value As Boolean) + + $hButtonBox.Border = Value + +End + +Private Function Value_Read() As String + + Return $hButtonBox.Text + +End + +Private Sub Value_Write(Value As String) + + $hButtonBox.Text = Value + +End + +Private Function SaveFile_Read() As Boolean + + Return $bSaveFile + +End + +Private Sub SaveFile_Write(Value As Boolean) + + $bSaveFile = Value + +End + +Private Function Title_Read() As String + + Return $sTitle + +End + +Private Sub Title_Write(Value As String) + + $sTitle = Value + +End + +Private Function Filter_Read() As String + + Return $sFilter + +End + +Private Sub Filter_Write(Value As String) + + $sFilter = Value + +End + +Private Function Picture_Read() As Picture + + Return $hButtonBox.Picture + +End + +Private Sub Picture_Write(Value As Picture) + + $hButtonBox.Picture = Value + +End + +Private Function Placeholder_Read() As String + + Return $hButtonBox.Placeholder + +End + +Private Sub Placeholder_Write(Value As String) + + $hButtonBox.Placeholder = Value + +End diff --git a/comp/src/gb.form/.src/Test/FTestFileBox.class b/comp/src/gb.form/.src/Test/FTestFileBox.class new file mode 100644 index 000000000..0a5fa73ac --- /dev/null +++ b/comp/src/gb.form/.src/Test/FTestFileBox.class @@ -0,0 +1,2 @@ +' Gambas class file + diff --git a/comp/src/gb.form/.src/Test/FTestFileBox.form b/comp/src/gb.form/.src/Test/FTestFileBox.form new file mode 100644 index 000000000..a47ff2247 --- /dev/null +++ b/comp/src/gb.form/.src/Test/FTestFileBox.form @@ -0,0 +1,24 @@ +# Gambas Form File 3.0 + +{ Form Form + MoveScaled(0,0,64,30) + { FileBox1 FileBox + MoveScaled(11,4,32,4) + Path = "/etc/lsb-release" + Title = ("Open a file") + Placeholder = ("File to open") + } + { FileBox2 FileBox + MoveScaled(11,12,32,4) + SaveFile = True + Title = ("Save file as") + Placeholder = ("File to save") + } + { FileBox3 FileBox + MoveScaled(11,19,32,4) + Title = ("Open image file") + Filter = "*.png;*.jpg \"Image files\" *.ico \"Icon Files\"" + Picture = Picture["icon:/small/insert-image"] + Placeholder = ("Image filters") + } +}