Print
Parent Category: Development
Category: yab
Hits: 1256

yab - How to create a shell tool GUI


In this tutorial i want to show how to create a gui for a shell tool using the yab scripting language.
I need some time to find a tool for this description, because it should be something similar to a program i created before. This help me to create a good example and descript it as tutorial without trying to explaine something i finished month or years before.

I choose the AMIGA compressing tool lha, because i can use here my tarGUI and zipGUI sources.

What will you learn in this tutorial?


Ok lets start with the tutorial:


 


Index

 


 


1. The shell tool

First you need to know that functionality the shell tool have. To do this open a Terminal window and type in the name of the shell tool:

lha

 

~> lha

LHarc for UNIX V 1.02 Copyright(C) 1989 Y.Tagawa
LHx for MSDOS V C2.01 Copyright(C) 1990 H.Yoshizaki
LHx(arc) for OSK V 2.01 Modified 1990 Momozou
LHa for UNIX V 1.00 Copyright(C) 1992 Masaru Oki
LHa for UNIX V 1.14 Modified 1995 Nobutaka Watazaki
LHa for UNIX V 1.14i Modified 2000 Tsugio Okamoto
Autoconfiscated 2001-2005 Koji Arai

usage: lha [-]<commands>[<options>] [-<options> ...] archive_file [file...]
    commands: [axelvudmcpt]
    options: [q[012]vnfto[567]dizg012e[w=<dir>|x=<pattern>]]
    long options: --system-kanji-code={euc,sjis,utf8,cap}
    --archive-kanji-code={euc,sjis,utf8,cap}
    --extract-broken-archive
    --help
    --version 

 

commands: options:
a Add(or replace) to archive q{num} quiet (num:quiet mode)
x,e EXtract from archive v verbose
l,v List / Verbose List n not execute
u Update newer files to archive f force (over write at extract)
d Delete from archive t FILES are TEXT file
m Move to archive (means 'ad') o[567] compression method (a/u/c)
c re-Construct new archive d delete FILES after (a/u/c)
p Print to STDOUT from archive i ignore directory path (x/e)
t Test file CRC in archive z files not compress (a/u/c)
  g Generic format (for compatibility)
  or not convert case when extracting
  0/1/2 header level (a/u/c)
  e TEXT code convert from/to EUC
  w=<dir> specify extract directory (x/e)
  x=<pattern> eXclude

 

Many shell tools give out the description of the tool typing the program name into the Terminal. If this does not match, try the options -h or --help.

 

Then you should watch the options list and write down that functions you want to add into the GUI.

By this tool i think the most importand options are compress, extract and list. So you need to make some tests with the tool to get a good result and learn how to use it.

My result for this tutorial:


So we have the main functions for our GUI.

back to Index


 


2. The yab script

First we create a basic yab source. We open an editor of our choice and creating a new file (I choose the file name lhaGUI).

In the following source code some separate marked parts with two "//" sings will be available, this will help me to tell you where to put which program code.

 

#!/boot/system/bin/yab

//Main

//################### Global Variables ###################

screenWidth = peek("desktopwidth")
screenHeight = peek("desktopheight")



//Main Loop

dim msgparts$(1)
dim part$(1)

inloop = true
while(inloop)
if (split(msg$, part$(), ":|") > 2) then
    PartOne$=part$(1)
    PartTwo$ = part$(2)
    PartThree$ = part$(3)
endif
if (split(msg$, part$(), ":|") > 3) then
    PartFour$ = part$(4)
endif
if (msg$ <> "") print msg$
switch msg$

//Cases

default:
    end switch
if(window count<1) inloop = false
    sleep 0.05
wend

//Subroutines

Every yab source have 4 parts:


Ok let us take a look to the script:

#!/boot/system/bin/yab

This line is for the use of the source as script. If you make the yab source executeable, the shell will take here the program to start it (yab).

//Main

//################### Global Variables ###################

screenWidth = peek("desktopwidth")
screenHeight = peek("desktopheight")

Here we have the Main part of the script. At the moment we collect only the screen resolution with screenWidth and screenHeight. Later we creating here the main window and the complete gui for the lha tool.

//Main Loop

dim part$(1)

inloop = true
while(inloop)
if (split(msg$, part$(), ":|") > 2) then
    PartOne$=part$(1)
    PartTwo$ = part$(2)
    PartThree$ = part$(3)
endif
if (split(msg$, part$(), ":|") > 3) then
    PartFour$ = part$(4)
endif
if (msg$ <> "") print msg$
switch msg$

//Cases

default:
    end switch
if(window count<1) inloop = false
    sleep 0.05
wend

This is the main loop. As long as the loop is running, the program remains open. In the loop you collect the data done by the user and executing the program functions.

We create an array called parts$ with dim part$(1). This array is importand to take the input by the user, because we split this messages (msg$) of the system to proceed the functions of our program with the cases. The messages can vary in length, so we split the message with if (split(msg$, part$(), ":|") > 2) then if longer as 2 tiles separated with a : or |. Then we do the same with messages longer as 3 tiles, because I add many times more informations into the name of the program switches (buttons, textcontrols, checkboxes...). You will see and understand this later.

With if (msg$ <> "") print msg$ all processes in the program who make an output to the shell will be print into the terminal or output field in the yabIDE. This includes the output of the yab switches (widgets).

Between //Cases and default: we will place all case functions.

default:
    end switch
if(window count<1) inloop = false
    sleep 0.05
wend

This is the end of the loop. There are several ways to make the loop, this is one of it.

back to Index


 


3. Creating the GUI



Since I have used one of my previous projects here, it is easy for me to describe this gui. In reality, it is one of the most important work, because you have to think about a lot.

One should always remember that not developers will use the program, it is the normal user.


Following function I thought of the program:


These are the functions of the program which we will create here in the tutorial. I will now piece by piece describe the associated program code and insert here and there more information.

Global variables

Add following code into the Main part under screenHeight

//Global variables

AppInternalName$="lha-gui"
AppName$="lhaGUI"
AppVersion$="0.5"
LHAVersion$=System$("lha --version 2>&1")
LHAVersion$=trim$(LHAVersion$)
Target$="/boot/home/Desktop"

These all are Variables we create in order to use them for faster development.


Program window

Next we create the program window, Add following code behind the global variable:

//Main window

WINDOW OPEN screenWidth/2-225,screenHeight/2-200 to screenWidth/2+225,screenHeight/2+200, AppInternalName$, AppName$
    WINDOW SET AppInternalName$, "ResizeTo", 450,190
    WINDOW SET AppInternalName$, "Flags", "Not-Resizable,Not-Zoomable"
    WINDOW SET AppInternalName$, "MinimumTo", 450,190
    WINDOW SET AppInternalName$, "MaximumTo", 450,400
WINDOW OPEN...

We create a window with window open.

...screenWidth/2-225,screenHeight/2-200 to screenWidth/2+225,screenHeight/2+200,...

Behind the command we give the size of the window. The size is given in x and y co-ordinates (x1=left edge, x2=right edge, y1 upper edge, y2 bottom edge). Here we use the screen size determined at the beginning (screenWidth, screenHeight). We divide the respective size by 2 and subtract half of the desired window size for the left and upper edge and add the half of the disired window size for the right and bottom edge.

...AppInternalName$...

The internal name of the window only serves to call or retrieve the window. Since this can happen very often, the name was stored in a variable (AppInternalName$).

...AppName$...

At the end we indicate the displayed name of the window. This is defined only once and therefore would not have to be stored in a variable, but since the name can still change before the release, you have the possibility to change the name at the beginning of the program code.

This typical composition will meet you again and again in yab:

Name_of_Command X1,Y1 TO X2,Y2, Name_of_Widget, Name_of_View
or
Name_of_Command X1,Y1 TO X2,Y2, Name_of_Widget, Viewable_Name_of_Widget, Option, Name_of_View

 

GUI elements (Buttons, Lists, Checkboxes...

Next, we set the buttons, lists and input fields to the program window. Place following code behind the window code:

LAYOUT "None", AppInternalName$

    STACKVIEW 0,0 TO 450,400, "VI:Stack", 2, AppInternalName$

    //Stackview 1 - Archiving and Extracting
        VIEW 0,0 TO 450,400, "VI:Main", "VI:Stack1"
            VIEW DROPZONE "VI:Main"

            BUTTON 10,30 TO 110,50, "BT:Source", "Source", "VI:Main"
            BUTTON 10,55 TO 110,75, "BT:Remove", "Remove", "VI:Main"
                option set "BT:Remove", "enabled", false
            BUTTON 10,80 TO 110,100, "BT:RemoveAll", "Remove All", "VI:Main"
                option set "BT:RemoveAll", "enabled", false
            LISTBOX 127,32 TO 438,122, "LB:Source", 1, "VI:Main"
            BUTTON 10,132 TO 110,152, "BT:Target", "Target", "VI:Main"
            TEXTCONTROL 120,132 TO 440,152, "TC:Target", "", DefaultTarget$, "VI:Main"
            BUTTON 10,162 TO 110,182, "BT:compress", "compress", "VI:Main"
                option set "BT:compress", "enabled", false
            BUTTON 120,162 TO 220,182, "BT:extract", "extract", "VI:Main"
                option set "BT:extract", "enabled", false
            CHECKBOX 240,163, "CB:all", "all files", 0, "VI:Main"
                option set "CB:all", "enabled", false
            CHECKBOX 325,163, "CB:contents", "show contents", 0, "VI:Main"
                option set "CB:contents", "enabled", false
            LISTBOX 12,200 TO 438,390, "LB:Output", 3, "VI:Main"

These are all the switch and input fields that we will integrate into the program.

LAYOUT "None", AppInternalName$

With the LAYOUT command, we determine how views should behave who are set to the current view.

With "None" we define that the views should not change when the program window is changed. We set the command on the mail window (AppInternalName$).

STACKVIEW 0,0 TO 450,400, "VI:Stack", 2, AppInternalName$

I set this STACKVIEW for a later extension of the program. A stackview consists of several views that are stacked on top of each other. Later I want to use this stackview for the settings of the program (not part of this tutorial). After the stackview has been created, the first stack is automatically displayed.

You can read more about stackviews here: yab and the layout command

VIEW 0,0 TO 450,400, "VI:Main", "VI:Stack1"

We will create a new view with the name "VI:Main".

The first two coordinates are the left and the top position of the view (0,0). The other two coordinates are the right and the bottom position of the view (450,400).

The view gets the name "VI:Main" and will be placed on the first stackview "VI:Stack1".

VIEW DROPZONE "VI:Main"

With this command we make a dropzone from the view "VI:Main".

If a file or folder is dropped on a dropzone, this output can be determined and used.

BUTTON 10,30 TO 110,50, "BT:Source", "Source", "VI:Main"

Next we create the first button. We place this with 10 pixel distance from the left edge and 30 pixel from the upper edge of the view "VI:Main". As well as views, a button has an internal and a visible name. The internal name is "BT:Source" and the visible name is "Source". At the end, we indicate on which view the button should be set.

The button is set here 30 pixels from the upper edge, because later we will insert a menu above it.
BUTTON 10,55 TO 110,75, "BT:Remove", "Remove", "VI:Main"

We do the same with the second button, only this gets another internal ("BT:Remove") and external ("Remove") name and is placed 5 pixels lower as the first one.

option set "BT:Remove", "enabled", false

Since the remove button only makes sense, if there is something to remove, we deactivate it.

We do this with the command "option set". To the command, we indicate which object we want to visually change ("BT:Remove").

The specification "enabled" is a fixed specification that can not be changed, it only defines the component that should be changed. We can define this with "true" or "false". Since we want to disable the button, we say "false" here.

BUTTON 10,80 TO 110,100, "BT:RemoveAll", "Remove All", "VI:Main"
    option set "BT:RemoveAll", "enabled", false

Then we create the third button with the same distance to the upper button. We deactivate this too.

LISTBOX 127,32 TO 438,122, "LB:Source", 1, "VI:Main"

Next, we will create a one-line table called LISTBOX. All files that are inserted into the program via the source button or drag-and-drop will be displayed later in this list.

We place the listbox to the right of the already created buttons. We give the listbox the internal name "LB:Source". The next specification is the type of the scrollbars.

Since we only need a vertical scrollbar for the program this is defined here with "1".

Types of scrollbars:

0 = keine
1 = vertical scrollbars
2 = horizontal scrollbars
3 = vertical & horizontal scrollbars

 

We also place the listbox on the view "VI:Main"

BUTTON 10,132 TO 110,152, "BT:Target", "Target", "VI:Main"

A little further below the other buttons we create another button. This button will later be used to specify the output folder for the lha file.

The button gets the internal name "BT:Target" and the visible name "Target".

This button is also placed on the view "VI:Main".

TEXTCONTROL 120,132 TO 440,152, "TC:Target", "", Target$, "VI:Main"

At the same height as the target button, we create an input field called TEXTCONTROL.

We call the textcontrol "TC:Target".

The next statement ("") is the displayed name of the textcontrol, but in this case it remains empty because the button "BT:Target" is given as an indication.

The next step is to specify which text should be in the textcontrol. Here we use the initially created variable "Target$".

This textcontrol is also placed on the view "VI:Main".

BUTTON 10,162 TO 110,182, "BT:compress", "compress", "VI:Main"
    option set "BT:compress", "enabled", false
BUTTON 120,162 TO 220,182, "BT:extract", "extract", "VI:Main"
    option set "BT:extract", "enabled", false

We create two more buttons in the lower left area. These are the buttons for the lha commands compress and extract. They get the internal names "BT:compress" and "BT:extract". The visible names are "compress" and "extract".

CHECKBOX 240,163, "CB:all", "all files", 0, "VI:Main"
    option set "CB:all", "enabled", false

Next we create a CHECKBOX. The structure is like the BUTTON. The only difference is that we only have to specify the position for left and above.

Then follows the indication for the visible label "all files".

The following statement "0" stands for a non-active checkbox (no check mark).

At the end then, as usual, the specification for the view on which the checkbox is set ("VI:Main".

The CHECKBOX is deactivated just like a button. This should only be active if the user has selected a file in the upper list.

With "all files", the user specifies that he should compress or unpack all files from the list into a lha file.

CHECKBOX 325,163, "CB:contents", "show contents", 0, "VI:Main"
    option set "CB:contents", "enabled", false

Next to the CHECKBOX we put another one. The second checkbox is deactivated just like the other one. If the user chooses this, the contents of the lha file will be displayed.

LISTBOX 12,200 TO 438,390, "LB:Output", 3, "VI:Main"

In the lower part of the program window we create another LISTBOX.

In this list, we will later extract the contents of the selected lha file when the user presses "show contents".

What was visible so far, we will hide now

We will now make a few changes to the appearance of the program window.

Paste the following program code below the WINDOW OPEN command:

WINDOW SET AppInternalName$, "ResizeTo", 450,190
WINDOW SET AppInternalName$, "Flags", "Not-Resizable,Not-Zoomable"
WINDOW SET AppInternalName$, "MinimumTo", 450,190
WINDOW SET AppInternalName$, "MaximumTo", 450,400

Now the explanation:

WINDOW SET AppInternalName$, "ResizeTo", 450,190

First we change the size of the window.

With the command "WINDOW SET" we give a command to the window AppInternalName$ ("VI:Main").

The addition "ResizeTo" changes the size of the window to a desired specification. The two numbers behind indicate the new size of the window. The first number is the desired width and the second number is the desired height of the window.

This reduces the size of the window so that the list of file contents is hidden.

WINDOW SET AppInternalName$, "Flags", "Not-Resizable,Not-Zoomable"

Again, we use the WINDOW SET command for the program window AppInternalName$.

This time we use the addition of "flags" to prevent the user from enlarging the window, by hand, in size.

We do that with the Not-Resizable and Not-Zoomable information.

WINDOW SET AppInternalName$, "MinimumTo", 450,190

Again, the WINDOW SET command is used. This time we define the minimum size ("MinumumTo") of the window. Again, we indicated the size again with the numbers for width and height.

WINDOW SET AppInternalName$, "MaximumTo", 450,400

We do the same with the maximum size of the window. With "MaximumTo" we define the size of the window to the specification of the width and height.

How this works in the end, I explain in the description of the processing of the input information.

The window menu

As a final step for the gui elements, we create a window menu.

Insert the following program code below the window set commands:

SUBMENU "App", "About", "lhaGUI", "", AppInternalName$
SUBMENU "App", "About", "lha", "", AppInternalName$
MENU "App", "--", "", AppInternalName$
MENU "App", "Quit", "Q", AppInternalName$

There are two types of menu commands, the menu and the submenu.

To create a submenu, you do not have to create a menu before.
SUBMENU "App", "About", "lhaGUI", "", AppInternalName$

We create a "SUBMENU". This consists of the root menu item "App", the head menu item "About" and the menu item "lhaGUI".

The following statement, which is released here (""), refers to the keyboard shortcut over which this menu item can be additionally started.

At the end, as always, you specify on which view the submenu should be set (ApplicationName$).

This menu item will later provide information about the program.

SUBMENU "App", "About", "lha", "", AppInternalName$

We create another submenu, which is placed in the same root menu and header menu. The entry is called "lha" and will later provide information about the lha tool.

MENU "App", "--", "", AppInternalName$

Then we create a MENU. The structure is the same as the SUBMENU, except that we do not have three levels, only two.

The menu item is inserted in the root menu item "App" and causes a separator, which is defined by a double line ("--").

MENU "App", "Quit", "Q", AppInternalName$

Then we create another menu item into the root item "App". This menu item we call "Quit" and define the keyboard short "Q".

The program will be ended via this menu item or the associated shortcut key.

This completes the creation of the program window.

back to Index


 


4. The execution of user activities

The processing of user activities is done via the CASE command.

Add the following lines between "switch msg$" and "default:":

case AppInternalName$+":App:Quit|"
case AppInternalName$+":_QuitRequested|"
    WINDOW CLOSE AppInternalName$
    break

case AppInternalName$+":App:About:"+PartFour$+"|"
    if(PartFour$="lhaGUI")then
        ALERT AppName$+"\n\nVersion: "+AppVersion$+"/ December 2017\n\nlhaGUI is a simple GUI for the lha compressing tool.\n\n(C) 2013-2015 - Christian Albrecht\nBeSly Software Solutions\nhttp://www.software.besly.de", "Ok", "info"
    elseif(PartFour$="lha")then
        ALERT LHAVersion$, "Ok", "info"
    endif
    break

case "VI:Main:_Dropped:"+PartFour$+"|"
    Listbox add "LB:Source", PartFour$
    break

case "LB:Source:_Select:"+PartFour$+"|"
    Enable_Buttons()
    SelectedFile$= LISTBOX GET$ "LB:Source", val(PartFour$)
    option set "BT:Remove", "enabled", true
    option set "BT:RemoveAll", "enabled", true
    break

case "BT:Remove|"
case "BT:RemoveAll|"
    if(PartTwo$="Remove")then
        LISTBOX REMOVE "LB:Source", SelectedFile$
    elseif(PartTwo$="RemoveAll")then
        LISTBOX CLEAR "LB:Source"
    endif

    CountLBEntries = LISTBOX COUNT "LB:Source"
    if(CountLBEntries=0)then
        option set "BT:Remove", "enabled", false
        option set "BT:RemoveAll", "enabled", false
        Disable_Buttons()
    endif
    break

case "BT:"+PartTwo$+"|"
    if(PartTwo$="compress")then
        Disable_Buttons()
        if(CompressAllFiles$="yes")then
            CountLBEntries = LISTBOX COUNT "LB:Source"
            i=0
            for i = 1 to CountLBEntries
                CountingListboxFiles$ = LISTBOX GET$ "LB:Source", i
                SelectedFile$=SelectedFile$+" "+"\""+CountingListboxFiles$+"\""
            next i

            if(trim$(Target$)="")then
                Target$="/boot/home/Desktop"
                Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
            else
                Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
            endif
        else
            Target$=TEXTCONTROL GET$ "TC:Target"
            if(trim$(Target$)="")then
                Target$="/boot/home/Desktop"
                Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
            else
                Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
            endif
        endif

        Enable_Buttons()
    elseif(PartTwo$="extract")then
        Disable_Buttons()
        if(trim$(Target$)="")then
            Target$="/boot/home/Desktop"
            Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
        else
            Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
        endif

        Enable_Buttons()
    elseif(PartTwo$="Source")then
        Source$ = FILEPANEL "Load-File-and-Directory", "Select Source file", "/boot/home"
        if(Source$="")then
        else
            LISTBOX ADD "LB:Source", Source$
        endif
    endif
    break

case "CB:contents:"+PartThree$+"|"
    if(PartThree$="ON")then
        LISTBOX CLEAR "LB:Output"
        OutPut$=System$("lha -l "+SelectedFile$)
        dim TarFiles$(1)
            files = split(OutPut$, TarFiles$(), "\n")
            for i = 1 to files
                if(TarFiles$(i)="")then
                else
                    LISTBOX ADD "LB:Output", TarFiles$(i)
                endif
            next i
            WINDOW SET AppInternalName$, "ResizeTo", 450,450
    elseif(PartThree$="OFF")then
        WINDOW SET AppInternalName$, "ResizeTo", 450,120
    else
    endif
    break

case "CB:all:"+PartThree$+"|"
    if(PartThree$="ON")then
        CompressAllFiles$="yes"
    elseif(PartThree$="OFF")then
        CompressAllFiles$="no"
    endif
    break


Each case command starts with "CASE" and ends with "BREAK".

If you use a yab IDE, the state queried here, or rather the output intercepted here, will be displayed.
case AppInternalName$+":App:Quit|"
case AppInternalName$+":_QuitRequested|"
    WINDOW CLOSE AppInternalName$
    break

We start with a classic case query. This causes the closing of the program window. You will certainly notice that we have here two different "cases" that are ended by one "break".

Both case processes cause the same at the end. We have two options to closing the program. On the one hand we can use the menu and on the other hand close the program window with the closing button of the tab.

case AppInternalName$+":App:Quit|"

Here we see the command "case", then the internal name ("AppInternalName$") of the window, next the menu header "App" and the menu item "Quit".

At the end, the punctuation mark "|", which indicates the end of the case string.

case AppInternalName$+":_QuitRequested|"

As with the first case command, the internal name of the program window is required here as well, followed by the output that is given when someone presses the close button in the program window ("_QuitRequested").

Again, the case query with a "|" sign ending.

WINDOW CLOSE AppInternalName$

"WINDOW CLOSE" is the command to close the program window, which will indicate behind it ("AppInternalName$").

With "break" the process is terminated.

As you can see, this way you can query cases with the same function together and let them do the same at the end.

This saves a lot of lines and work.
case AppInternalName$+":App:About:"+PartFour$+"|"
    if(PartFour$="lhaGUI")then
        ALERT AppName$+"\n\nVersion: "+AppVersion$+"/ December 2017\n\nlhaGUI is a simple GUI for the lha compressing tool.\n\n(C) 2013-2015 - Christian Albrecht\nBeSly Software Solutions\nhttp://www.software.besly.de", "Ok", "info"
    elseif(PartFour$="lha")then
        ALERT LHAVersion$, "Ok", "info"
    endif
    break

The second classic case query is the display of the about window. We do this with the "ALERT" command.

case AppInternalName$+":App:About:"+PartFour$+"|"

Also this time we will work with this query several things at the same time. Unlike the query before, this time we will not use two case inputs, we break the user's input into its parts and use an "IF" query to either edit one input or the other one.

But for that you first have to understand how to get the parts of the query:

dim part$(1)

if (split(msg$, part$(), ":|") > 2) then
    PartOne$=part$(1)
    PartTwo$ = part$(2)
    PartThree$ = part$(3)
endif
if (split(msg$, part$(), ":|") > 3) then
    PartFour$ = part$(4)
endif
if (msg$ <> "") print msg$
switch msg$ 

The necessary code you have already created in the main loop area.

First we dimension an array with "dim parts$(1)".

Then we split the system internal message ("msg$") on each : and | character using "if (split(msg$, part$(), ":|") > value) then".

A system message may look like this:

"View_Name:Menu_Header:Menu_Item|"
"Widget_Name|"
"Widget_Name:Option|"

Then we split the message msg$ at the above characters (: and |) and save the items into the array part$(). We do this once to save the entries in the array that are higher than 2 (> 2) and once to store the entries in the array that are larger than 3 (> 3).

The query if (msg $ <> "") print msg $ returns this informations while the program is running. Through this command line, any action that the user performs in the program is output into the terminal or IDE (depending on how you do it).

If you would like to deactivate this function later, to publish your program, put this // signs in front of print msg$ (if (msg$ <> "") //print msg$).

There are then, depending on the query, in the variable PartOne$, PartTwo$, PartThree$ ... the respective items stored.

An Example:

"VI:Main:App:About|"

PartOne$ = "VI
PartTwo$ = "Main"
PartThree$ = "App"
PartFour$ = "About" 

I hope I could illustrate that?

if(PartFour$="lhaGUI")then
        ALERT AppName$+"\n\nVersion: "+AppVersion$+"/ December 2017\n\nlhaGUI is a simple GUI for the lha compressing tool.\n\n(C) 2013-2015 - Christian Albrecht\nBeSly Software Solutions\nhttp://www.software.besly.de", "Ok", "info"

Here we apply the input information by checking PartFour$ with an if query. If the information in PartFour$ is "lhaGUI", we execute the command ALERT.

Using this we give information about the program. Names of the program, version and general informations.

elseif(PartFour$="lha")then
        ALERT LHAVersion$, "Ok", "info"
    endif

If the name in PartFour$ does not match with "lhaGUI", the alternate query will occur (elseif("")then).

If the content of PartFour$ is "lha", we use the version of lha stored at the beginning of the program (LHAVersion$) with the ALERT command.


Next we create a case for the dropzone.

case "VI:Main:_Dropped:"+PartFour$+"|"
    Listbox add "LB:Source", PartFour$
    break

If you drop a file on the dropzone, we will get information about the captured file.

case "VI:Main:_Dropped:"+PartFour$+"|"

The output contains the name of the view (VI: Main) on which the dropzone was set, then the information of the DROPZONE that something is captured (_Dropped) and the name and path of the file (PartFour$) who dropped on it.

Listbox add "LB:Source", PartFour$

Then we take the path and name of the dropped file (PartFour$) and put it into the LISTBOX (LB:Source).

Over the next CASE we determine which file was selected in the source LISTBOX.

case "LB:Source:_Select:"+PartFour$+"|"
    Enable_Buttons()
    SelectedFile$= LISTBOX GET$ "LB:Source", val(PartFour$)
    option set "BT:Remove", "enabled", true
    option set "BT:RemoveAll", "enabled", true
    break

Now we certainly do not know two things:


The only thing we can determine is the number of the selected line.

case "LB:Source:_Select:"+PartFour$+"|"

If a file is selected in the LISTBOX this will be displayed. We catch this information with the CASE. This information consists of the name of the LISTBOX (LB: Source), the information that something was selected (_Selected) and which row is selected (PartFour$).

Enable_Buttons()

Here we activate buttons of the program, which may only be active when a file has been selected. A subroutine (Enable_Buttons()) is used for this.

I will describe the subroutines at the end of the tutorial.

SelectedFile$= LISTBOX GET$ "LB:Source", val(PartFour$)

With the command LISTBOX GET$ we now determine which file was selected in the LISTBOX and store them into the variable SelectedFile$.

For this we give the command (LISTBOX GET$) the name of the listbox ("LB:Source") and which line is selected (val(PartFour$).

Since we need a number for the line of the listbox for the command, we have to convert the text-variable (PartFour$) into a number-variable. For this we use the command val()
(val=value).
option set "BT:Remove", "enabled", true
option set "BT:RemoveAll", "enabled", true

With the command option set we activate the buttons "BT:Remove" and "BT:RemoveAll".


This makes sense because it prevents us from trying to remove something that does not exist.

With "break" the process is terminated.


Next we will deal with the removal of an entry from the "Source List". This divorced by "Remove" or "Remove All".

case "BT:Remove|"
case "BT:RemoveAll|"
    if(PartTwo$="Remove")then
        LISTBOX REMOVE "LB:Source", SelectedFile$
    elseif(PartTwo$="RemoveAll")then
        LISTBOX CLEAR "LB:Source"
    endif

    CountLBEntries = LISTBOX COUNT "LB:Source"
    if(CountLBEntries=0)then
        option set "BT:Remove", "enabled", false
        option set "BT:RemoveAll", "enabled", false
        Disable_Buttons()
    endif
    break

Since both cases basically do the same thing (either remove a file or remove all files), I've merged them here.

case "BT:Remove|"
case "BT:RemoveAll|"

As with the case for terminating the program, here we write the queries among each other.

if(PartTwo$="Remove")then
    LISTBOX REMOVE "LB:Source", SelectedFile$
elseif(PartTwo$="RemoveAll")then
    LISTBOX CLEAR "LB:Source"
endif

We use an IF query to determine which case has actually been selected.

We ask for the second part of the edited CASE output. If it is "Remove", the corresponding command is executed.

LISTBOX REMOVE "LB:Source", SelectedFile$ removes the selected entry (SelectedFile$) in the Listbox "LB: Source".

If PartTwo$ contains "Remove All" then the corresponding command will be executed here too.

LISTBOX CLEAR "LB:Source" deletes all entries in the specified LISTBOX

CountLBEntries = LISTBOX COUNT "LB:Source"
if(CountLBEntries=0)then
    option set "BT:Remove", "enabled", false
    option set "BT:RemoveAll", "enabled", false
    Disable_Buttons()
endif
break

Whenever all contents of the LISTBOX have been removed, the buttons for "remove" and "remove all" must be deactivated again.

CountLBEntries = LISTBOX COUNT "LB:Source"

With CountLBEntries = LISTBOX COUNT "LB:Source" we determine the number of existing entries in the LISTBOX.

if(CountLBEntries=0)then
    option set "BT:Remove", "enabled", false
    option set "BT:RemoveAll", "enabled", false
    Disable_Buttons()
endif

If "CountLBEntries" is "0" then the buttons "BT:Remove" and "BT:RemoveAll" are deactivated by the "option set" command.
Since the other buttons should not be active anymore, they will be deactivated too. This deactivation is not done directly in the case, it will be outsourced to a subroutine Disable_Buttons().

But I will discuss the subroutines later.

With "break" the process is terminated.


Now we come to the core point of the program, compressing, decompressing and displaying the content of the lha file

Paste the following source code below the last cases:

case "BT:"+PartTwo$+"|"
   if(PartTwo$="compress")then
       Disable_Buttons()
       if(CompressAllFiles$="yes")then
           CountLBEntries = LISTBOX COUNT "LB:Source"
           i=0
           for i = 1 to CountLBEntries
               CountingListboxFiles$ = LISTBOX GET$ "LB:Source", i
               SelectedFile$=SelectedFile$+" "+"\""+CountingListboxFiles$+"\""
           next i

           if(trim$(Target$)="")then
               Target$="/boot/home/Desktop"
               Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
           else
               Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
           endif
       else
           Target$=TEXTCONTROL GET$ "TC:Target"
           if(trim$(Target$)="")then
               Target$="/boot/home/Desktop"
               Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
           else
               Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
           endif
       endif

       Enable_Buttons()
   elseif(PartTwo$="extract")then
       Disable_Buttons()
       if(trim$(Target$)="")then
           Target$="/boot/home/Desktop"
           Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
       else
           Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
       endif

       Enable_Buttons()
   elseif(PartTwo$="Source")then
       Source$ = FILEPANEL "Load-File-and-Directory", "Select Source file", "/boot/home"
       if(Source$="")then
       else
           LISTBOX ADD "LB:Source", Source$
       endif
   endif
break

With case "BT:"+PartTwo$+"|" we get all three buttons. The PartTwo$ contains the respective relevant part of the name of our buttons.

if(PartTwo$="compress")then
   expiration of the compression
elseif(PartTwo$="extract")then
   expiration of the decompressing
elseif(PartTwo$="Source")then br>    Showing contents of lha file
endif

An IF query starts the respective program sequence.

Compressing

We start to expain the compress part:

If PartTwo$ is "compress" this part of the IF query will be active.

Disable_Buttons()

.......

Enable_Buttons()

We start with the deactivation of all buttons, because the user should see that the program is working.

At the end we activate them again.

if(CompressAllFiles$="yes")then

......

else

......

endif

When we ask the array CompressAllFiles$ if "compress all files" is activated with a If query.

CountLBEntries = LISTBOX COUNT "LB:Source"

If we want to compress all files we ask the listbox "LB:Source" with the command LISTBOX COUNT how many entries are in this list and store them into the value variable CountLBEntries.

for i = 1 to CountLBEntries
    CountingListboxFiles$ = LISTBOX GET$ "LB:Source", i
    SelectedFile$=SelectedFile$+" "+"\""+CountingListboxFiles$+"\""
next i

Next we use a FOR loop to count all entries of the listbox into a variable called CountingListboxFiles$.

The loop start with 1 and ends with the value of the variable CountLBEntries.

Then we get the entry at position i from the listbox "LB:Source", using the command LISTBOX GET$, and store them into the variable CountingListboxFiles$.

If you have more then one file, you need to add them to the lha command with free space between the files, so we add the collected listbox entry CountingListboxFiles$ to a other variable called SelectedFile$.

if(trim$(Target$)="")then
    Target$="/boot/home/Desktop"
    Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
else
    Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
endif

If the variable for the output folder Target$ is not specified, then /boot/home/Desktop is automatically set as the destination path.


Then the lha file will be created. To do this we use the System$() command which allows you to execute system-level operations. The System$() command needs an output variable (here Output$).

Within the system command, the program "lha" is specified with the specification for compressing "-a", the target directory Target$, the output file "/archive.lha" and the file/files to be compressed SelectedFile$.

The System$() command must include a quoted string. Therefore, the included string must begin with a text variable or with quotation marks and on the end as well.

If there is a change between text and variables, these are combined with a + sign.
You always have to make sure that you pay attention in the text and variables on the required empty signs

 

The rest is self-evident, if Target$ is not empty, then the lha command is executed directly.

if(CompressAllFiles$="yes")then
else
    Target$=TEXTCONTROL GET$ "TC:Target"
    if(trim$(Target$)="")then
        Target$="/boot/home/Desktop"
        Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
    else
        Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
    endif
endif

Enable_Buttons()

Let's go back to the query whether all files should be compressed and treat the area, if "not all files should be compressed". In this case, the IF query changes to ELSE.

In this case, exactly the same thing is done as described above, with the exception that the LISTBOX is not read out and we have only one file in the SelectedFile$ variable.

This completes the field of compression.

Extracting

if(PartTwo$="compress")then
elseif(PartTwo$="extract")then
   expiration of the decompressing
elseif(PartTwo$="Source")then
endif

Back to the query of PartTwo$ and the description of the process of "extracting".

Disable_Buttons()
if(trim$(Target$)="")then
    Target$="/boot/home/Desktop"
    Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
else
    Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
endif

Enable_Buttons()

We start by disabling the buttons Disable_Buttons() again.

Again, we check if something is included in the variable Target$. If nothing is included the varialben, a target directory is automatically determined.

Then the System$() command is executed as in the previous compression.

Within the system command, the program "lha" is specified with the specification for extracting "-x", into the target directory Target$ and the file who should be extracted SelectedFile$.

At the end the buttons are reactivated Enable_Buttons().

Source

if(PartTwo$="compress")then
elseif(PartTwo$="extract")then
elseif(PartTwo$="Source")then
endif

Back to the query of PartTwo$ and the description of the process of "source".

Source$ = FILEPANEL "Load-File-and-Directory", "Select Source file", "/boot/home"
    if(Source$="")then
    else
        LISTBOX ADD "LB:Source", Source$
    endif

Now we come to the addition of files into the listing of files ("LB:Source").

Source$ = FILEPANEL "Load-File-and-Directory", "Select Source file", "/boot/home"

For this we use another command, which creates a window with file browser. In this window, the user selects a file and presses Add. The selected file is then saved with is file path into the variable Source$.

With "Load-File-and-Directory" we indicate that the command FILEPANEL determine the file name and its file path.

"Select Source file" is the heading of the FILEPANEL.

"/boot/home" is the specification for the directory which is displayed in the FILEPANEL.


Next, I'll explain to you, displaying the contents of the Lha file.

Add the following sourcecode below the last CASE:

case "CB:contents:"+PartThree$+"|"
    if(PartThree$="ON")then
        LISTBOX CLEAR "LB:Output"
        OutPut$=System$("lha -l "+SelectedFile$)
        dim LHAFiles$(1)
            files = split(OutPut$, LHAFiles$(), "\n")
            for i = 1 to files
                if(LHAFiles$(i)="")then
                else
                    LISTBOX ADD "LB:Output", LHAFiles$(i)
                endif
            next i
            WINDOW SET AppInternalName$, "ResizeTo", 450,450
    elseif(PartThree$="OFF")then
        WINDOW SET AppInternalName$, "ResizeTo", 450,120
    else
    endif
    break

This function is activated by selecting the CHECKBOX "Show contents".

case "CB:contents:"+PartThree$+"|"
    break

A CHECKBOX returns only ON or OFF so we use again the splitted strings into Parts$.

if(PartThree$="ON")then
elseif(PartThree$="OFF")then
endif

Via an IF query, we check the variable PartThree$, whether it is ON or OFF.

CB:contents:ON

LISTBOX CLEAR "LB:Output"

If the CHECKBOX is activated (ON), the output LISTBOX "LB:Output" will be emptied first usind the command LISTBOX CLEAR.

OutPut$=System$("lha -l "+SelectedFile$)
dim LHAFiles$(1)
    files = split(OutPut$, LHAFiles$(), "\n")

Then we create a new variable OutPut$ and use the system$ command to save the content of the selected lha file (SelectedFile$) into it.

Then we create an ARRAY$() of size 1.

Then in this ARRAY$() (LHAFiles$()) we split the content of the variable OutPut$ by each line break ("\n").

for i = 1 to files
    if(LHAFiles$(i)="")then
    else
        LISTBOX ADD "LB:Output", LHAFiles$(i)
    endif
next i

Now we read out the ARRAY$() (LHAFiles$()) and insert their entries line by line into the LISTBOX "LB:Output".

We use a FOR loop that runs from 1 to the number of entries (files of the ARRAY$() (LHAFiles$()).

Since we do not want to display blank lines in the LISTBOX, we ask each ARRAY$() entrie to determine if it is empty (if(LHAFiles$(i)="")then). If the entry in the ARRAY is empty, the loop will skip it.

If the entry in the ARRAY is not empty, the loop follows the ELSE node. Here the input from the ARRAY (LHAFiles$(i)) is written to the LISTBOX "LB:Output" usind the command LISTBOX ADD.

WINDOW SET AppInternalName$, "ResizeTo", 450,450

Since the LISTBOX is out of the visible area, we enlarge the window with the commands WINDOW SET (WINDOW SET "WindowName", "ResizeTo", x,y).

CB:contents:OFF

elseif(PartThree$="OFF")then
    WINDOW SET AppInternalName$, "ResizeTo", 450,120

If the CHECKBOX is deactivated we reduce the window size to the standard size. We use here the WINDOW SET command again.

Now we come to the last CASE for this program. This is the indication if all files in the source list ("LB:Source") should be included into the LHA file.

case "CB:all:"+PartThree$+"|"
    if(PartThree$="ON")then
        CompressAllFiles$="yes"
    elseif(PartThree$="OFF")then
        CompressAllFiles$="no"
    endif
    break

As with the last CHECKBOX, it is also determined here whether the CHECKBOX is ON or OFF.

Depending on how the CHECKBOX is set, the content of the variable CompressAllFiles$ is changed. Is the checkbox ON we change the variable to "yes" and if this is OFF to "no".

back to Index


 

5. Outsourced program areas (Subroutines)

Let's move on to the last part of the tutorial. This deals with the subroutines.

A subroutine serves to outsource program areas so that you can use them several times. This area will not turn out to be spectacular in this program, because there is not really much that you could do more than once.

The only thing you can write well in a subroutine is the activation and deactivation of program parts. Which would be the topic, let's disable some widgets.

Insert the following source code after the end of the LOOP ("wend"):

sub Enable_Buttons()
    option set "BT:compress", "enabled", true
    option set "BT:extract", "enabled", true
    option set "CB:all", "enabled", true
    option set "CB:contents", "enabled", true
end sub

sub Disable_Buttons()
    option set "BT:compress", "enabled", false
    option set "BT:extract", "enabled", false
    option set "CB:all", "enabled", false
    option set "CB:contents", "enabled", false
end sub

Enable Buttons

sub Enable_Buttons()
end sub

A SUBROUTINE is created by the call SUB and ends with END SUB.

option set "BT:compress", "enabled", true
option set "BT:extract", "enabled", true
option set "CB:all", "enabled", true
option set "CB:contents", "enabled", true

If a widget does not have its own command to disable/enable, use the "OPTION SET" command.

The command is composed as follows, starting with the command OPTION SET and the object to be activated "BT:compress", the specification what OPTION SET should change "enabled" and the value (true) which activates this.

This is defined here for the button of "BT:compress" and "BT:extract", as well as for the checkboxes <i"CB:all"> and "CB:contents".


After that follows the identical subroutine with the deactivation of the widgets. The only difference is the name and the value of OPTION SET commanded. Here we define false and not true.


 


6. The complete source code

#!/boot/home/config/bin/yab
REM Requires yab v 1.7-3
REM Start of Creating 22.12.2017
REM Copyright by Christian Albecht, BeSly Software Solutions
REM Developer: Christian Albrecht

//##################################### Global Variables #####################################

screenWidth = peek("desktopwidth")
screenHeight = peek("desktopheight")

AppInternalName$="lha-gui"
AppName$="lhaGUI"
AppVersion$="0.5"
LHAVersion$=System$("lha --version 2>&1")
LHAVersion$=trim$(LHAVersion$)
Target$="/boot/home/Desktop"

if(IfExists("/boot/home/config/settings/lhaGUI"))then
else
    Output$=System$("mkdir /boot/home/config/settings/lhaGUI")
endif

SettingsFolder$="/boot/home/config/settings/lhaGUI"

//Main window

WINDOW OPEN screenWidth/2-225,screenHeight/2-200 to screenWidth/2+225,screenHeight/2+200, AppInternalName$, AppName$
    WINDOW SET AppInternalName$, "ResizeTo", 450,190
    WINDOW SET AppInternalName$, "Flags", "Not-Resizable,Not-Zoomable"
    WINDOW SET AppInternalName$, "MinimumTo", 450,190
    WINDOW SET AppInternalName$, "MaximumTo", 450,400

    SUBMENU "App", "About", "lhaGUI", "", AppInternalName$
    SUBMENU "App", "About", "lha", "", AppInternalName$
    MENU "App", "--", "", AppInternalName$
    MENU "App", "Quit", "Q", AppInternalName$

    LAYOUT "None", AppInternalName$
    STACKVIEW 0,0 TO 450,400, "VI:Stack", 2, AppInternalName$
        //Stackview 1 - Archiving and Extracting
        VIEW 0,0 TO 450,400, "VI:Main", "VI:Stack1"
            VIEW DROPZONE "VI:Main"
            BUTTON 10,30 TO 110,50, "BT:Source", "Source", "VI:Main"
            BUTTON 10,55 TO 110,75, "BT:Remove", "Remove", "VI:Main"
                option set "BT:Remove", "enabled", false
            BUTTON 10,80 TO 110,100, "BT:RemoveAll", "Remove All", "VI:Main"
                option set "BT:RemoveAll", "enabled", false
            LISTBOX 127,32 TO 438,122, "LB:Source", 1, "VI:Main"

            BUTTON 10,132 TO 110,152, "BT:Target", "Target", "VI:Main"
            TEXTCONTROL 120,132 TO 440,152, "TC:Target", "", DefaultTarget$, "VI:Main"
            BUTTON 10,162 TO 110,182, "BT:compress", "compress", "VI:Main"
                option set "BT:compress", "enabled", false
            BUTTON 120,162 TO 220,182, "BT:extract", "extract", "VI:Main"
                option set "BT:extract", "enabled", false
            CHECKBOX 240,163, "CB:all", "all files", 0, "VI:Main"
                option set "CB:all", "enabled", false
            CHECKBOX 325,163, "CB:contents", "show contents", 0, "VI:Main"
                option set "CB:contents", "enabled", false
            LISTBOX 12,200 TO 438,390, "LB:Output", 3, "VI:Main"

        //Stackview 2 - Preferences
        VIEW 0,0 TO 450,300, "VI:Preferences", "VI:Stack2"
            TEXTCONTROL 10,30 TO 380,50, "TC:DefaultTarget", "Default target folder:", DefaultTarget$, "VI:Preferences"
            BUTTON 390,30 TO 440,51, "BT:DefaultTarget", "set", "VI:Preferences"
            BUTTON 10,210 TO 440,230, "BT:Return", "Back", "VI:Preferences"

//Main Loop

dim dropped$(1)
dim droppedfiles$(1)
dim msgparts$(1)
dim part$(1)
inloop = true
while(inloop)
    msg$ = message$
    if (split(msg$, dropped$(), "|") > 2) then
        OPTION SET "VI:Main", "Focus", 1
        dropped=1
        droppedfiles=split(msg$, droppedfiles$(), "|")
        if(dropped=1)then
            addfiles=0
            i=0

            for i = 1 to droppedfiles
                OPTION SET "VI:Main", "Focus", 1
                addfiles=split(droppedfiles$(i), msgparts$(), ":")
                if(addfiles<4)then
                else
                    if(left$(msgparts$(4),1)="1")then
                    elseif(left$(msgparts$(4),1)="2")then
                    elseif(left$(msgparts$(4),1)="3")then
                    elseif(left$(msgparts$(4),1)="4")then
                    elseif(left$(msgparts$(4),1)="5")then
                    elseif(left$(msgparts$(4),1)="6")then
                    elseif(left$(msgparts$(4),1)="7")then
                    elseif(left$(msgparts$(4),1)="8")then
                    elseif(left$(msgparts$(4),1)="9")then
                    elseif(left$(msgparts$(4),1)="0")then
                    else
                        Listbox add "LB:Source", msgparts$(4)
                    endif
                endif
            next i
            dropped=0
        else
        endif
    endif

    if (split(msg$, part$(), ":|") > 2) then
        PartOne$=part$(1)
        PartTwo$ = part$(2)
        PartThree$ = part$(3)
    fi
    if (split(msg$, part$(), ":|") > 3) then
        PartFour$ = part$(4)
    fi
if (msg$ <> "") print msg$
    switch msg$

    case AppInternalName$+":App:Quit|"
    case AppInternalName$+":_QuitRequested|"
        WINDOW CLOSE AppInternalName$
        break

    case AppInternalName$+":App:About:"+PartFour$+"|"
        if(PartFour$="lhaGUI")then
            ALERT AppName$+"\n\nVersion: "+AppVersion$+"/ December 2017\n\nlhaGUI is a simple GUI for the lha compressing tool.\n\n(C) 2013-2015 - Christian Albrecht\nBeSly Software Solutions\nhttp://www.software.besly.de", "Ok", "info"
        elseif(PartFour$="lha")then
            ALERT LHAVersion$, "Ok", "info"
        endif
        break

    case "VI:Main:_Dropped:"+PartFour$+"|"
        Listbox add "LB:Source", PartFour$
        break

    case "LB:Source:_Select:"+PartFour$+"|"
        Enable_Buttons()
        SelectedFile$= LISTBOX GET$ "LB:Source", val(PartFour$)
        option set "BT:Remove", "enabled", true
        option set "BT:RemoveAll", "enabled", true
        break

    case "BT:Remove|"
    case "BT:RemoveAll|"
        if(PartTwo$="Remove")then
            LISTBOX REMOVE "LB:Source", SelectedFile$
        elseif(PartTwo$="RemoveAll")then
            LISTBOX CLEAR "LB:Source"
        endif
        CountLBEntries = LISTBOX COUNT "LB:Source"
        if(CountLBEntries=0)then
            option set "BT:Remove", "enabled", false
            option set "BT:RemoveAll", "enabled", false
            Disable_Buttons()
        endif
        break

    case "BT:"+PartTwo$+"|"
        if(PartTwo$="compress")then
            Disable_Buttons()
            if(CompressAllFiles$="yes")then
                CountLBEntries = LISTBOX COUNT "LB:Source"
                i=0
                for i = 1 to CountLBEntries
                    CountingListboxFiles$ = LISTBOX GET$ "LB:Source", i
                    SelectedFile$=SelectedFile$+" "+"\""+CountingListboxFiles$+"\""
                    //print SelectedFile$=SelectedFile$
                next i
                if(trim$(Target$)="")then
                    Target$="/boot/home/Desktop"
                    Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
                else
                    Output$=System$("lha -a "+Target$+"/archive.lha "+SelectedFile$)
                endif
            else
                Target$=TEXTCONTROL GET$ "TC:Target"
                if(trim$(Target$)="")then
                    Target$="/boot/home/Desktop"
                    Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
                else
                    Output$=System$("lha -a "+Target$+"/archive.lha "+"\""+SelectedFile$+"\"")
                endif
            endif
            Enable_Buttons()
        elseif(PartTwo$="extract")then
            Disable_Buttons()
            if(trim$(Target$)="")then
                Target$="/boot/home/Desktop"
                Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
            else
                Output$=System$("cd "+Target$+";lha -x "+SelectedFile$)
            endif
            Enable_Buttons()
        elseif(PartTwo$="Source")then
            Source$ = FILEPANEL "Load-File-and-Directory", "Select Source file", "/boot/home"
            if(Source$="")then
            else
                LISTBOX ADD "LB:Source", Source$
            endif
        endif
        break

    case "CB:contents:"+PartThree$+"|"
        if(PartThree$="ON")then
            LISTBOX CLEAR "LB:Output"
            OutPut$=System$("lha -l "+SelectedFile$)
            dim TarFiles$(1)
                files = split(OutPut$, TarFiles$(), "\n")
                for i = 1 to files
                    if(TarFiles$(i)="")then
                    else
                        LISTBOX ADD "LB:Output", TarFiles$(i)
                    endif
                next i
                WINDOW SET AppInternalName$, "ResizeTo", 450,450
        elseif(PartThree$="OFF")then
            WINDOW SET AppInternalName$, "ResizeTo", 450,120
        else
        endif
        break

    case "CB:all:"+PartThree$+"|"
        if(PartThree$="ON")then
            CompressAllFiles$="yes"
        elseif(PartThree$="OFF")then
            CompressAllFiles$="no"
        endif
        break

    default:
end switch

    if(window count<1) inloop = false
    sleep 0.05
wend

sub Enable_Buttons()
    option set "BT:compress", "enabled", true
    option set "BT:extract", "enabled", true
    option set "CB:all", "enabled", true
    option set "CB:contents", "enabled", true
end sub

sub Disable_Buttons()
    option set "BT:compress", "enabled", false
    option set "BT:extract", "enabled", false
    option set "CB:all", "enabled", false
    option set "CB:contents", "enabled", false#
end sub

back to Index


 

Tutorial by Christian Albrecht, Spring 2018
Made available by the BeSly, the Haiku knowledge base.