diff --git a/Changes b/Changes index 24bb375d..15325532 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,11 @@ Revision history for berrybrew 1.42 UNREL - - - + - Added `dev/ui_simulator.pl`, a non-functioning layout simulator which on + the click of any button, reloads the window after loading in updated + config elements from the `data/ui.json` config file (closes #358) + - Added new UI layout manipulation scripts and tools + - Updated development documentation for new UI tools 1.41 2023-08-03 - Renamed `PerlOp.PerlOrphansIgnore()` to `Berrybrew.SpecialInstanceDirectories()` diff --git a/dev/build_staging_ui.bat b/dev/build_staging_ui.bat index baede050..5339f1b1 100644 --- a/dev/build_staging_ui.bat +++ b/dev/build_staging_ui.bat @@ -12,7 +12,7 @@ call perl -i.bak -ne "s/\"run_mode\"\s+:\s+\"prod\"/\"run_mode\"\t\t : \"stagin echo "compiling UI..." -call csc^ +call mcs^ src\berrybrew-ui.cs^ src\perloperations.cs^ -lib:staging^ @@ -23,4 +23,4 @@ call csc^ -r:Newtonsoft.Json.dll^ -win32icon:inc/berrybrew.ico^ -win32manifest:berrybrew.manifest^ - -out:staging/berrybrew-ui.exe^ \ No newline at end of file + -out:staging/berrybrew-ui.exe \ No newline at end of file diff --git a/dev/data/ui.json b/dev/data/ui.json new file mode 100644 index 00000000..500f7cf7 --- /dev/null +++ b/dev/data/ui.json @@ -0,0 +1,262 @@ +{ + "checkbox" : { + "windowsHomedir" : { + "width" : 200, + "autosize" : true, + "location" : [ + 10, + 295 + ], + "text" : "Windows homedir" + }, + "powershell" : { + "width" : 200, + "location" : [ + 10, + 235 + ], + "text" : "Use Powershell", + "autosize" : true + }, + "warnOrphans" : { + "width" : 200, + "autosize" : true, + "text" : "Warn on orphans", + "location" : [ + 10, + 275 + ] + }, + "debug" : { + "location" : [ + 10, + 215 + ], + "text" : "Debug", + "autosize" : true, + "width" : 200 + }, + "fileAssoc" : { + "width" : 200, + "autosize" : true, + "location" : [ + 10, + 255 + ], + "text" : "Manage file association" + } + }, + "label" : { + "currentPerl" : { + "location" : [ + 10, + 10 + ], + "text" : "Current Perl: None Configured", + "index" : 1, + "name" : "BBUI", + "size" : [ + 159, + 20 + ], + "tabindex" : 0, + "autosize" : true + } + }, + "ui_simulator" : { + "font_size" : 11 + }, + "ui_object" : { + "client_size" : [ + 265, + 325 + ], + "trayicon_text" : "berrybrew UI" + }, + "button" : { + "perlFetch" : { + "index" : 8, + "name" : "perlFetchButton", + "text" : "Fetch", + "location" : [ + 10, + 185 + ], + "size" : [ + 75, + 23 + ], + "tabindex" : 1 + }, + "perlSwitch" : { + "size" : [ + 75, + 23 + ], + "name" : "perlSwitchButton", + "index" : 3, + "tabindex" : 1, + "location" : [ + 139, + 35 + ], + "text" : "Switch" + }, + "perlOff" : { + "size" : [ + 35, + 20 + ], + "index" : 2, + "name" : "perlOffButton", + "location" : [ + 215, + 10 + ], + "text" : "Off", + "tabindex" : 1 + }, + "perlOpen" : { + "size" : [ + 45, + 20 + ], + "tabindex" : 1, + "index" : 1, + "name" : "perlOpenButton", + "text" : "Open", + "location" : [ + 169, + 10 + ] + }, + "perlUse" : { + "size" : [ + 75, + 23 + ], + "location" : [ + 139, + 95 + ], + "text" : "Use", + "index" : 5, + "name" : "perlUseButton", + "tabindex" : 1 + }, + "perlInstall" : { + "size" : [ + 75, + 23 + ], + "text" : "Install", + "location" : [ + 139, + 65 + ], + "index" : 4, + "name" : "perlInstallButton", + "tabindex" : 1 + }, + "perlClone" : { + "tabindex" : 1, + "text" : "Clone", + "location" : [ + 139, + 155 + ], + "name" : "perlCloneButton", + "index" : 7, + "size" : [ + 75, + 23 + ] + }, + "perlRemove" : { + "tabindex" : 1, + "name" : "perlRemoveButton", + "index" : 6, + "location" : [ + 139, + 125 + ], + "text" : "Remove", + "size" : [ + 75, + 23 + ] + } + }, + "combobox" : { + "perlClone" : { + "location" : [ + 10, + 155 + ], + "tabindex" : 0, + "name" : "perlCloneSelect", + "index" : 5, + "size" : [ + 121, + 30 + ], + "formatting_enabled" : true + }, + "perlInstall" : { + "formatting_enabled" : true, + "size" : [ + 121, + 30 + ], + "location" : [ + 10, + 65 + ], + "tabindex" : 0, + "index" : 2, + "name" : "perlInstallSelect" + }, + "perlUse" : { + "formatting_enabled" : true, + "size" : [ + 121, + 30 + ], + "index" : 3, + "name" : "perlUseSelect", + "tabindex" : 0, + "location" : [ + 10, + 95 + ] + }, + "perlSwitch" : { + "location" : [ + 10, + 35 + ], + "name" : "perlSwitchSelect", + "index" : 1, + "size" : [ + 121, + 30 + ], + "tabindex" : 0, + "formatting_enabled" : true + }, + "perlRemove" : { + "size" : [ + 121, + 30 + ], + "formatting_enabled" : true, + "location" : [ + 10, + 125 + ], + "name" : "perlRemoveSelect", + "index" : 4, + "tabindex" : 0 + } + } +} diff --git a/dev/ui_simulator.pl b/dev/ui_simulator.pl new file mode 100755 index 00000000..c7de4891 --- /dev/null +++ b/dev/ui_simulator.pl @@ -0,0 +1,161 @@ +use warnings; +use strict; + +use FindBin qw($RealBin); +use lib "$RealBin/../lib"; + +use BuildHelper qw(:all); +use Data::Dumper; +use JSON; +use Tkx; + + +# NOTE: If a UTF error occurs reading the JSON, open the conf +# file up in vi and execute: ':set nobomb' + +# NOTE: All buttons have a command that will destroy the existing +# window and recreate it from scratch. This allows us to auto-refresh +# the UI live time while making changes to the UI config file + +my $ui_conf_file = 'dev/data/ui.json'; +my $data = BuildHelper::config_read($ui_conf_file); +my $font_size = $data->{ui_simulator}{font_size}; + +my $mw; + +window_create_and_display(); + +sub buttons { + my $button_conf = $data->{button}; + + my @buttons; + + for (keys %$button_conf) { + push @buttons, $button_conf->{$_}; + } + + return @buttons; +} +sub checkboxes { + my $checkboxes_conf = $data->{checkbox}; + + my @checkboxes; + + for (keys %$checkboxes_conf) { + push @checkboxes, $checkboxes_conf->{$_}; + } + + return @checkboxes; +} +sub comboboxes { + my $combobox_conf = $data->{combobox}; + + my @comboboxes; + + for (keys %$combobox_conf) { + push @comboboxes, $combobox_conf->{$_}; + } + + return @comboboxes; +} +sub labels { + my $label_conf = $data->{label}; + + my @labels; + + for (keys %$label_conf) { + push @labels, $label_conf->{$_}; + } + + return @labels; +} +sub window_create_and_display { + $data = BuildHelper::config_read($ui_conf_file); + $font_size = $data->{ui_simulator}{font_size}; + + $mw = Tkx::widget->new("."); + + # Window + $mw->g_wm_title("BB UI Simulator"); + $mw->g_wm_minsize(_window_size()); + + # Buttons + _generate_buttons($mw); + + # Checkboxes + _generate_checkboxes($mw); + + # Comboboxex + _generate_comboboxes($mw); + + # Labels + _generate_labels($mw); + + # Deploy + Tkx::MainLoop(); +} + +sub _generate_buttons { + for my $button_conf (buttons()) { + my $button = $mw->new_button( + -text => $button_conf->{text}, + -font => [ -size => $font_size ], + -command => sub { + $mw->DESTROY; + window_create_and_display(); + } + ); + $button->g_place( + -width => $button_conf->{size}[0], + -height => $button_conf->{size}[1], + -x => $button_conf->{location}[0], + -y => $button_conf->{location}[1] + ); + } +} +sub _generate_checkboxes { + for my $checkbox_conf (checkboxes()) { + my $checkbox = $mw->new_checkbutton( + -text => $checkbox_conf->{text}, + -font => [ -size => $font_size ], + -anchor => 'w' + ); + $checkbox->g_place( + -width => $checkbox_conf->{width}, + -x => $checkbox_conf->{location}[0], + -y => $checkbox_conf->{location}[1] + ); + } +} +sub _generate_comboboxes { + for my $combobox_conf (comboboxes()) { + my $combobox = $mw->new_ttk__combobox( + -values => [ $combobox_conf->{name} ], + ); + $combobox->g_place( + -width => $combobox_conf->{size}[0], + -height => $combobox_conf->{size}[1], + -x => $combobox_conf->{location}[0], + -y => $combobox_conf->{location}[1] + ); + } +} +sub _generate_labels { + for my $label_conf (labels()) { + my $label = $mw->new_label( + -text => $label_conf->{text}, + -font => [ + -size => $font_size, + ] + ); + $label->g_place( + -width => $label_conf->{size}[0], + -height => $label_conf->{size}[1], + -x => $label_conf->{location}[0], + -y => $label_conf->{location}[1] + ); + } +} +sub _window_size { + return @{ $data->{ui_object}{client_size} }; +} \ No newline at end of file diff --git a/dev/ui_tools/move_element_block.pl b/dev/ui_tools/move_element_block.pl new file mode 100644 index 00000000..9011cafe --- /dev/null +++ b/dev/ui_tools/move_element_block.pl @@ -0,0 +1,80 @@ +use warnings; +use strict; + +# move_element_block.pl + +# Moves all elements of a certain type up or down within the UI, +# asks the user if they'd like to expand the main window size, +# and then updates the UI configuration file + +use FindBin qw($RealBin); +use lib "$RealBin/../../lib"; + +use BuildHelper qw(:all); +use Getopt::Long; + +my ($element_type, $direction, $pixels); + +GetOptions ( + 'e|element=s' => \$element_type, + 'd|direction=s' => \$direction, + 'p|pixels=s' => \$pixels, +); + +if (! $element_type || ! $direction || ! defined $pixels) { + help(); +} +if ($direction !~ /(?:up|down)/) { + print "\n\t--direction must be 'up' or 'down'\n\n"; + exit; +} + +if ($pixels !~ /^\d+$/) { + print "\n\t--pixels must be an unsigned integer\n\n"; + exit; +} + +my $ui_conf_file = 'dev/data/ui.json'; +my $data = BuildHelper::config_read($ui_conf_file); + +if (! grep { $element_type eq $_ } grep { $_ !~ /^ui_/ } keys %$data) { + my $element_list = join ', ', grep { $_ !~ /^ui/ } keys %$data; + + print "\n--element-type argument must be one of '$element_list'\n\n"; + exit; +} + +$data = BuildHelper::ui_change_element_block_location( + $data, + $element_type, + $direction, + $pixels +); + +if ($direction eq 'down') { + print "\nWould you like to expand the size of the main window by '$pixels' pixels [y|n]?"; + my $input = <>; + + if ($input =~ /(?:y|Y)/) { + my @window_size = BuildHelper::ui_window_size($data); + $window_size[1] += $pixels; + + $data = BuildHelper::ui_window_size($data, @window_size); + } +} + +BuildHelper::config_write($ui_conf_file, $data); + +print "\nUpdated the '$ui_conf_file' with the updated element locations\n\n"; + +sub help { + print qq{ + Parameters: + + -e|--element Mandatory: The element type + -d|--direction Mandatory: 'down' or 'up' + -p|--pixels Mandatory: The number of pixels to move the elements + + }; + exit; +} \ No newline at end of file diff --git a/dev/ui_tools/resize_window.pl b/dev/ui_tools/resize_window.pl new file mode 100644 index 00000000..f36497cc --- /dev/null +++ b/dev/ui_tools/resize_window.pl @@ -0,0 +1,58 @@ +use warnings; +use strict; + +# resize_window.pl + +# Resizes the main UI window + +use FindBin qw($RealBin); +use lib "$RealBin/../../lib"; + +use BuildHelper qw(:all); +use Getopt::Long; + +my $ui_conf_file = 'dev/data/ui.json'; +my $data = BuildHelper::config_read($ui_conf_file); + +my ($x_current, $y_current) = BuildHelper::ui_window_size($data); +my ($x, $y, $help); + +GetOptions ( + 'x=i' => \$x, + 'y=i' => \$y, + 'h|help' => \$help +); + +if ($help) { + help(); +} + +$x //= $x_current; +$y //= $y_current; + +if ($x != $x_current && $y != $y_current) { + $data = BuildHelper::ui_window_size($data, $x, $y); + BuildHelper::config_write($ui_conf_file, $data); + print "\nUpdated the '$ui_conf_file' with the updated main window size...\n\n"; +} +else { + print "\nNo new coordinates sent in. Existing window is '$x' x '$y' pixels...\n\n"; +} + +sub help { + print qq{ + + If no parameters are sent in, we'll display the current window size. + + if only one of -x or -y are sent in, we'll re-use the existing setting + for the missing value. + + Parameters: + + -x Optional: Number of horizontal pixels + -y Optional: Number of vertical pixels + -h Optional: Display this help screen + + }; + exit; +} \ No newline at end of file diff --git a/doc/Berrybrew development.md b/doc/Berrybrew development.md index 7394a84c..2035c214 100644 --- a/doc/Berrybrew development.md +++ b/doc/Berrybrew development.md @@ -12,7 +12,7 @@ This document contains information on the entire development lifecycle of - [Compile Full Build (With Installer)](#development-installer-build) - [Compile Binary Only](#berrybrew-binary-only) - [Compile API Only](#api-only) -- [Compile User Interface](#user-interface) +- [User Interface](#user-interface) - [Manually Compile Your Own](#manually-compile-your-own) - [Unit Testing](#unit-testing) - [Production Build for Testing](#production-build) @@ -49,6 +49,9 @@ These are the files and tools in the `dev\` directory, and their purposes: | **release.pl** | Creates a Berrybrew release. See [Create a Release](Create%20a%20release.md) | | **release_cycle.pl** | After a release, this script cycles the repository in preparation for the next version. See [Prepare for next version](Create%20a%20release.md#prepare-a-branch-for-the-next-release-cycle) | | **release_post.pl** | After a release, restores any backed up configuration files (very rarely used) | +| **ui_simulator.pl** | Non-functional layout simulator of the UI for modifying its config file | +| **ui_tools\move_element_block.pl** | Move an element block of the UI up or down | +| **ui_tools\resize_window.pl** | Resize the UI main window | ### Berrybrew data directory layout @@ -120,12 +123,7 @@ and perl instances in `C:\berrybrew-staging\instance`. ### User Interface -- Run the `dev\build_staging_ui.bat` script, which runs `dev\build_staging.bat` -compiling the API and the `berrybrew` binary, followed by the UI binary itself. - -- Run the `staging\berrybrew-ui.exe` to start the UI. Note that the staging UI -build will execute out of a command line window, so that you can see the debugging -output. +See the [User Interface development](UI.md) document. ### Manually Compile your Own @@ -142,7 +140,7 @@ See the [Unit Testing](Unit%20testing.md) document. ### Production Build To perform testing with the production aspects of `berrybrew` without creating -a full blown release, run the `dev\build_prod.bat` script. The production build +a full-blown release, run the `dev\build_prod.bat` script. The production build operates out of the `bin\` directory (ie. `bin\berrybrew.exe`). The production installer can be built using the `dev\build_prod_installer.bat` diff --git a/doc/UI.md b/doc/UI.md new file mode 100644 index 00000000..d686c8c7 --- /dev/null +++ b/doc/UI.md @@ -0,0 +1,87 @@ +# User Interface development + +- Code is in `src/berrybrew-ui.cs` +- Staging UI built binary is `staging/berrybrew-ui.exe` +- Production UI built binary is `bin/berrybrew-ui.exe` +- Configuration for UI layout is `dev/data/ui.json` + +- [UI Build](#ui-build) +- [UI Simulator](#ui-simulator) +- [UI Tools](#ui-tools) +- [UI Tools - Move element block](#move-element-block) +- [UI Tools - Resize main window](#resize-main-window) + +### UI Build + +To build and test the development/staging UI: + +- Run the `dev\build_staging_ui.bat` script, which runs `dev\build_staging.bat` + compiling the API and the `berrybrew` binary, followed by the UI binary itself. +- Run the `staging\berrybrew-ui.exe` to start the UI. Note that the staging UI + build will execute out of a command line window, so that you can see the debugging + output. + +To build the production UI for testing, see the +[Prod UI build](Berrybrew%20development.md#production-build) documentation. + +### UI Simulator + +To aid in manipulating the UI element layout collected from the +`dev\data\ui.json` configuration file, we've got a UI simulator in +`dev\ui_simulator.pl`. + +This simulator is `Tkx` based, and runs on MacOS and Linux. + +It is non-functional; it's used solely to replicate the exact layout. If you +modify any of the elements in the `src\ui.json` configuration file, a click of +any button in the UI simulator will reload the window live time, so you don't +have to close and reopen the UI sim on each change. + +### UI Tools + +The UI manipulation tool scripts reside in the `dev/ui_tools` directory. + +#### Move element block + +This script is `dev/ui_tools/move_element_block.pl`. + +It allows you to move an entire element block up and down by a pixel count. +The element block types are listed in the `dev/data/ui.json` file. It will +automatically update the configuration file. + +If this script is used to move an element block down, you will be asked if you +want to resize the main window by the same number of pixels you move the block. + +Usage of the script: + + dev/ui_tools/move_element_block.pl + + Parameters: + + -e|--element Mandatory: The element type + -d|--direction Mandatory: 'down' or 'up' + -p|--pixels Mandatory: The number of pixels to move the elements + +#### Resize main window + +This script is `dev/ui_tools/resize_window.pl`. + +It allows you to resize the main window dynamically. It will automatically +update the configuration file. + +Usage of the script: + + dev/ui_tools/resize_window.pl + + If no parameters are sent in, we'll display the current window size. + + if only one of -x or -y are sent in, we'll re-use the existing setting + for the missing value. + + Parameters: + + -x Optional: Number of horizontal pixels + -y Optional: Number of vertical pixels + -h Optional: Display this help screen + +© 2016-2023 by Steve Bertrand \ No newline at end of file diff --git a/lib/BuildHelper.pm b/lib/BuildHelper.pm index 41593984..03a430b2 100644 --- a/lib/BuildHelper.pm +++ b/lib/BuildHelper.pm @@ -6,16 +6,39 @@ use strict; # environments have in common. use Exporter qw(import); +use JSON; our @EXPORT_OK = qw( check_installer_manifest - update_installer_script + config_read + config_write create_installer + ui_change_element_block_location + ui_window_size + update_installer_script ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, ); +# Common + +sub config_read { + my ($file) = @_; + local $/; + open my $fh, '<', $file or die $!; + my $json = <$fh>; + return decode_json $json; +} +sub config_write { + my ($file, $data) = @_; + open my $wfh, '>', $file or die $!; + my $json = JSON->new->pretty->encode($data); + print $wfh $json; +} + +# Installer + sub create_installer { my ($installer_script) = @_; @@ -244,6 +267,56 @@ sub update_installer_script { close $wfh; } +# UI + + +sub ui_change_element_block_location { + my ($config, $element_type, $direction, $pixels) = @_; + + # Moves all elements of a certain type up or down + # RETURN: The updated configuration data struct + + if (! $config || ! $element_type || ! $direction || ! defined $pixels) { + die "Need to send in the config hash, element type, 'up' or 'down' and the number of pixels"; }; if ($direction ne 'up' && $direction ne 'down') { + die "\$direction parameter needs to be 'up' or 'down'"; + } + if ($pixels !~ /^\d+$/) { + die "\$pixels param needs to be an unsigned integer"; + } + + my $data = $config->{$element_type}; + + for (keys %$data) { + if ($direction eq 'up') { + $data->{$_}{location}[1] -= $pixels; + } + else { + $data->{$_}{location}[1] += $pixels; + } + } + + return $config; +} +sub ui_window_size { + my ($config, $x, $y) = @_; + + if (! $config) { + die "Need UI configuration hash as param"; + } + + if (! defined $x && ! defined $y) { + return _ui_current_window_size($config); + } + else { + $config->{ui_object}{client_size}[0] = $x; + $config->{ui_object}{client_size}[1] = $y; + } + + return $config; +} + +# Private + sub _berrybrew_version { open my $fh, '<', 'src/berrybrew.cs' or die $!; @@ -266,3 +339,7 @@ sub _berrybrew_version { return $ver; } +sub _ui_current_window_size { + my ($config) = @_; + return @{ $config->{ui_object}{client_size} }; +} \ No newline at end of file diff --git a/src/berrybrew-ui.cs b/src/berrybrew-ui.cs index 5f497b56..f82e3986 100644 --- a/src/berrybrew-ui.cs +++ b/src/berrybrew-ui.cs @@ -12,11 +12,14 @@ public class BBUI : System.Windows.Forms.Form { private Berrybrew bb = new Berrybrew(); + private dynamic Conf; + private System.Windows.Forms.NotifyIcon trayIcon; private System.Windows.Forms.ContextMenu contextMenu; private System.Windows.Forms.MenuItem rightClickExit; private Label currentPerlLabel; + private Button perlOpenButton; private Button perlOffButton; @@ -46,45 +49,50 @@ public class BBUI : System.Windows.Forms.Form { private System.ComponentModel.IContainer components; [STAThread] - static void Main() { + static void Main() { Application.Run(new BBUI()); } public BBUI() { - this.components = new System.ComponentModel.Container(); - this.contextMenu = new System.Windows.Forms.ContextMenu(); - this.rightClickExit = new System.Windows.Forms.MenuItem(); + Conf = bb.JsonParse("ui"); - this.contextMenu.MenuItems.AddRange( - new System.Windows.Forms.MenuItem[] { this.rightClickExit } + ClientSize = new System.Drawing.Size( + (int) Conf["ui_object"]["client_size"][0], + (int) Conf["ui_object"]["client_size"][1] + ); + Text = "berrybrew UI"; + + components = new System.ComponentModel.Container(); + contextMenu = new System.Windows.Forms.ContextMenu(); + rightClickExit = new System.Windows.Forms.MenuItem(); + + contextMenu.MenuItems.AddRange( + new System.Windows.Forms.MenuItem[] { rightClickExit } ); - this.rightClickExit.Index = 0; - this.rightClickExit.Text = "Exit"; - this.rightClickExit.Click += new System.EventHandler(this.rightClickExit_Click); - - this.ClientSize = new System.Drawing.Size(240, 100); - this.Text = "berrybrew UI"; + rightClickExit.Index = 0; + rightClickExit.Text = "Exit"; + rightClickExit.Click += new System.EventHandler(rightClickExit_Click); - this.trayIcon = new System.Windows.Forms.NotifyIcon(this.components); + trayIcon = new System.Windows.Forms.NotifyIcon(components); string iconPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string iconFile = System.IO.Directory.GetParent(iconPath) + @"\inc\berrybrew.ico"; trayIcon.Icon = new Icon(iconFile); - trayIcon.ContextMenu = this.contextMenu; - trayIcon.Text = "berrybrew UI"; + trayIcon.ContextMenu = contextMenu; + trayIcon.Text = Conf["ui_object"]["trayicon_text"]; trayIcon.Visible = true; - trayIcon.Click += new System.EventHandler(this.trayIcon_Click); + trayIcon.Click += new System.EventHandler(trayIcon_Click); InitializeComponents(); - this.Name = "Form"; - this.Load += new System.EventHandler(this.Form1_Load); - this.ResumeLayout(false); + Name = "Form"; + Load += new System.EventHandler(Form1_Load); + ResumeLayout(false); - this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); + FormClosing += new FormClosingEventHandler(Form1_FormClosing); } protected override void Dispose(bool disposing) { @@ -96,109 +104,63 @@ protected override void Dispose(bool disposing) { } private void InitializeComponents() { - this.InitializeCurrentPerlLabel(); - this.InitializePerlOpenButton(); - this.InitializePerlOffButton(); + InitializeCurrentPerlLabel(); - this.InitializePerlSwitchSelect(); - this.InitializePerlSwitchButton(); + InitializePerlOpenButton(); + InitializePerlOffButton(); - this.InitializePerlInstallSelect(); - this.InitializePerlInstallButton(); + InitializePerlSwitchSelect(); + InitializePerlSwitchButton(); - this.InitializePerlUseSelect(); - this.InitializePerlUseButton(); + InitializePerlInstallSelect(); + InitializePerlInstallButton(); - this.InitializePerlRemoveSelect(); - this.InitializePerlRemoveButton(); + InitializePerlUseSelect(); + InitializePerlUseButton(); - this.InitializePerlCloneSelect(); - this.InitializePerlCloneButton(); + InitializePerlRemoveSelect(); + InitializePerlRemoveButton(); - this.InitializePerlFetchButton(); + InitializePerlCloneSelect(); + InitializePerlCloneButton(); - this.InitializeFileAssocCheckBox(); - this.InitializeWarnOrphansCheckBox(); - this.InitializeUsePowershellCheckbox(); - this.InitializeDebugCheckBox(); - this.InitializeWindowsHomedirCheckBox(); - } + InitializePerlFetchButton(); - private void InitializeCurrentPerlLabel() { - this.currentPerlLabel = new System.Windows.Forms.Label(); - this.SuspendLayout(); - - this.currentPerlLabel.AutoSize = true; - this.currentPerlLabel.Location = new System.Drawing.Point(10, 10); - this.currentPerlLabel.Name = "currentPerlLabel"; - this.currentPerlLabel.Size = new System.Drawing.Size(35, 35); - this.currentPerlLabel.TabIndex = 0; - this.currentPerlLabel.Font = new Font(this.Font, FontStyle.Bold); - - this.ClientSize = new System.Drawing.Size(284, 261); - this.Controls.Add(this.currentPerlLabel); - this.Name = "BBUI"; - this.ResumeLayout(false); - this.PerformLayout(); + InitializeFileAssocCheckBox(); + InitializeWarnOrphansCheckBox(); + InitializeUsePowershellCheckbox(); + InitializeDebugCheckBox(); + InitializeWindowsHomedirCheckBox(); } - private void InitializePerlOpenButton() { - this.perlOpenButton = new System.Windows.Forms.Button(); - - this.perlOpenButton.Location = new System.Drawing.Point(169, 10); - this.perlOpenButton.Name = "perlOpenButton"; - this.perlOpenButton.Size = new System.Drawing.Size(45, 20); - this.perlOpenButton.TabIndex = 1; - this.perlOpenButton.Text = "Open"; - this.perlOpenButton.UseVisualStyleBackColor = true; - - this.perlOpenButton.Click += new System.EventHandler(this.openPerlButton_Click); - } - - private void openPerlButton_Click(object Sender, EventArgs e) { - // MessageBox.Show(((Button)Sender).Name + " was pressed!"); - string perlInUse = bb.PerlOp.PerlInUse().Name; - - if (perlInUse == null) { - System.Windows.Forms.MessageBox.Show("No Perl currently in use!"); - return; - } - - bb.UseCompile(perlInUse, true); - this.WindowState = FormWindowState.Minimized; - this.Hide(); - DrawComponents(); - } - - private void InitializePerlOffButton() { - this.perlOffButton = new System.Windows.Forms.Button(); - - this.perlOffButton.Location = new System.Drawing.Point(215, 10); - this.perlOffButton.Name = "perlOffButton"; - this.perlOffButton.Size = new System.Drawing.Size(35, 20); - this.perlOffButton.TabIndex = 1; - this.perlOffButton.Text = "Off"; - this.perlOffButton.UseVisualStyleBackColor = true; - - this.perlOffButton.Click += new System.EventHandler(this.offPerlButton_Click); - } + // Label - Current Perl + private void InitializeCurrentPerlLabel() { + string name = "currentPerl"; + var data = Conf["label"][name]; - private void offPerlButton_Click(object Sender, EventArgs e) { - string perlInUse = bb.PerlOp.PerlInUse().Name; + currentPerlLabel = new System.Windows.Forms.Label(); + SuspendLayout(); - if (perlInUse == null) { - System.Windows.Forms.MessageBox.Show("No Perl currently in use!"); - return; - } + currentPerlLabel.AutoSize = data["autosize"]; + currentPerlLabel.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + currentPerlLabel.Name = name; + currentPerlLabel.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + currentPerlLabel.TabIndex = data["tabindex"]; + currentPerlLabel.Font = new Font(Font, FontStyle.Bold); - bb.Off(); - this.WindowState = FormWindowState.Minimized; - this.Hide(); - DrawComponents(); + Controls.Add(currentPerlLabel); + Name = data["name"]; + ResumeLayout(false); + PerformLayout(); } - private void CurrentPerlLabel_Redraw() { - this.currentPerlLabel.Text = "Current Perl: "; + currentPerlLabel.Text = "Current Perl: "; string perlInUse = bb.PerlOp.PerlInUse().Name; @@ -206,21 +168,29 @@ private void CurrentPerlLabel_Redraw() { perlInUse = "Not configured"; } - this.currentPerlLabel.Text = currentPerlLabel.Text += perlInUse; + currentPerlLabel.Text = currentPerlLabel.Text += perlInUse; } - + + // Checkbox - File association private void InitializeFileAssocCheckBox() { - this.fileAssocCheckBox = new System.Windows.Forms.CheckBox(); - this.fileAssocCheckBox.Width = 200; - this.fileAssocCheckBox.AutoSize = true; - this.fileAssocCheckBox.Text = "Manage file association"; - this.fileAssocCheckBox.Location = new System.Drawing.Point(10, 255); - this.fileAssocCheckBox.Checked = FileAssocManaged() ? true : false; - this.fileAssocCheckBox.CheckedChanged += new System.EventHandler(this.fileAssocCheckedChanged); + string name = "fileAssoc"; + var data = Conf["checkbox"][name]; + + fileAssocCheckBox = new System.Windows.Forms.CheckBox(); + + fileAssocCheckBox.Text = data["text"]; + fileAssocCheckBox.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + fileAssocCheckBox.Width = data["width"]; + fileAssocCheckBox.AutoSize = data["autosize"]; + fileAssocCheckBox.Checked = FileAssocManaged() ? true : false; + fileAssocCheckBox.CheckedChanged += new System.EventHandler(fileAssocCheckedChanged); Controls.Add(fileAssocCheckBox); } private void FileAssocCheckBox_Redraw() { - this.fileAssocCheckBox.Checked = FileAssocManaged() ? true : false; + fileAssocCheckBox.Checked = FileAssocManaged() ? true : false; } private bool FileAssocManaged() { string assoc = bb.Options("file_assoc", null, true); @@ -243,14 +213,21 @@ private void fileAssocCheckedChanged(object Sender, EventArgs e) { } } + // Checkbox - Warn orphans private void InitializeWarnOrphansCheckBox() { - this.warnOrphansCheckBox = new System.Windows.Forms.CheckBox(); - this.warnOrphansCheckBox.Width = 200; - this.warnOrphansCheckBox.AutoSize = true; - this.warnOrphansCheckBox.Text = "Warn on orphans"; - this.warnOrphansCheckBox.Checked = WarnOrphans() ? true : false; - this.warnOrphansCheckBox.Location = new System.Drawing.Point(10, 275); - this.warnOrphansCheckBox.CheckedChanged += new System.EventHandler(this.warnOrphansCheckedChanged); + string name = "warnOrphans"; + var data = Conf["checkbox"][name]; + + warnOrphansCheckBox = new System.Windows.Forms.CheckBox(); + warnOrphansCheckBox.Text = data["text"]; + warnOrphansCheckBox.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + warnOrphansCheckBox.Width = data["width"]; + warnOrphansCheckBox.AutoSize = data["autosize"]; + warnOrphansCheckBox.Checked = WarnOrphans() ? true : false; + warnOrphansCheckBox.CheckedChanged += new System.EventHandler(warnOrphansCheckedChanged); Controls.Add(warnOrphansCheckBox); } private bool WarnOrphans() { @@ -268,17 +245,24 @@ private void warnOrphansCheckedChanged(object Sender, EventArgs e) { } } private void WarnOrphansCheckBox_Redraw() { - this.warnOrphansCheckBox.Checked = WarnOrphans() ? true : false; + warnOrphansCheckBox.Checked = WarnOrphans() ? true : false; } + // Checkbox - Debug private void InitializeDebugCheckBox() { - this.debugCheckBox = new System.Windows.Forms.CheckBox(); - this.debugCheckBox.Width = 200; - this.debugCheckBox.AutoSize = true; - this.debugCheckBox.Checked = bb.Options("debug", null, true) == "true" ? true : false; - this.debugCheckBox.Text = "Debug"; - this.debugCheckBox.Location = new System.Drawing.Point(10, 215); - this.debugCheckBox.CheckedChanged += new System.EventHandler(this.debugCheckedChanged); + string name = "debug"; + var data = Conf["checkbox"][name]; + + debugCheckBox = new System.Windows.Forms.CheckBox(); + debugCheckBox.Text = data["text"]; + debugCheckBox.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + debugCheckBox.Width = data["width"]; + debugCheckBox.AutoSize = data["autosize"]; + debugCheckBox.Checked = bb.Options("debug", null, true) == "true" ? true : false; + debugCheckBox.CheckedChanged += new System.EventHandler(debugCheckedChanged); Controls.Add(debugCheckBox); } private void debugCheckedChanged(object Sender, EventArgs e) { @@ -292,17 +276,24 @@ private void debugCheckedChanged(object Sender, EventArgs e) { } } private void DebugCheckBox_Redraw() { - this.debugCheckBox.Checked = bb.Options("debug", null, true) == "true" ? true : false; + debugCheckBox.Checked = bb.Options("debug", null, true) == "true" ? true : false; } + // Checkbox - Powershell private void InitializeUsePowershellCheckbox() { - this.powershellCheckBox = new System.Windows.Forms.CheckBox(); - this.powershellCheckBox.Width = 200; - this.powershellCheckBox.AutoSize = true; - this.powershellCheckBox.Checked = bb.Options("shell", null, true) == "powershell" ? true : false; - this.powershellCheckBox.Text = "Use Powershell"; - this.powershellCheckBox.Location = new System.Drawing.Point(10, 235); - this.powershellCheckBox.CheckedChanged += new System.EventHandler(this.powershellCheckedChanged); + string name = "powershell"; + var data = Conf["checkbox"][name]; + + powershellCheckBox = new System.Windows.Forms.CheckBox(); + powershellCheckBox.Text = data["text"]; + powershellCheckBox.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + powershellCheckBox.Width = data["width"]; + powershellCheckBox.AutoSize = data["autosize"]; + powershellCheckBox.Checked = bb.Options("shell", null, true) == "powershell" ? true : false; + powershellCheckBox.CheckedChanged += new System.EventHandler(powershellCheckedChanged); Controls.Add(powershellCheckBox); } private void powershellCheckedChanged(object Sender, EventArgs e) { @@ -316,17 +307,24 @@ private void powershellCheckedChanged(object Sender, EventArgs e) { } } private void PowershellCheckBox_Redraw() { - this.powershellCheckBox.Checked = bb.Options("shell", null, true) == "powershell" ? true : false; + powershellCheckBox.Checked = bb.Options("shell", null, true) == "powershell" ? true : false; } + // Checkbox - Windows homedir private void InitializeWindowsHomedirCheckBox() { - this.windowsHomedirCheckBox = new System.Windows.Forms.CheckBox(); - this.windowsHomedirCheckBox.Width = 200; - this.windowsHomedirCheckBox.AutoSize = true; - this.windowsHomedirCheckBox.Checked = bb.Options("windows_homedir", null, true) == "true" ? true : false; - this.windowsHomedirCheckBox.Text = "Windows homedir"; - this.windowsHomedirCheckBox.Location = new System.Drawing.Point(10, 295); - this.windowsHomedirCheckBox.CheckedChanged += new System.EventHandler(this.windowsHomedirCheckedChanged); + string name = "windowsHomedir"; + var data = Conf["checkbox"][name]; + + windowsHomedirCheckBox = new System.Windows.Forms.CheckBox(); + windowsHomedirCheckBox.Text = data["text"]; + windowsHomedirCheckBox.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + windowsHomedirCheckBox.Width = data["width"]; + windowsHomedirCheckBox.AutoSize = data["autosize"]; + windowsHomedirCheckBox.Checked = bb.Options("windows_homedir", null, true) == "true" ? true : false; + windowsHomedirCheckBox.CheckedChanged += new System.EventHandler(windowsHomedirCheckedChanged); Controls.Add(windowsHomedirCheckBox); } private void windowsHomedirCheckedChanged(object Sender, EventArgs e) { @@ -340,22 +338,104 @@ private void windowsHomedirCheckedChanged(object Sender, EventArgs e) { } } private void WindowsHomedirCheckBox_Redraw() { - this.windowsHomedirCheckBox.Checked = bb.Options("windows_homedir", null, true) == "true" ? true : false; + windowsHomedirCheckBox.Checked = bb.Options("windows_homedir", null, true) == "true" ? true : false; } - private void InitializePerlInstallButton() { - this.perlInstallButton = new System.Windows.Forms.Button(); + // Button - Open Perl + private void InitializePerlOpenButton() { + string name = "perlOpen"; + var data = Conf["button"][name]; + + perlOpenButton = new System.Windows.Forms.Button(); + + perlOpenButton.Name = data["name"]; + perlOpenButton.Text = data["text"]; + perlOpenButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlOpenButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlOpenButton.TabIndex = data["tabindex"]; + perlOpenButton.UseVisualStyleBackColor = true; + + perlOpenButton.Click += new System.EventHandler(openPerlButton_Click); + } + private void openPerlButton_Click(object Sender, EventArgs e) { + // MessageBox.Show(((Button)Sender).Name + " was pressed!"); + string perlInUse = bb.PerlOp.PerlInUse().Name; - this.perlInstallButton.Location = new System.Drawing.Point(139, 65); - this.perlInstallButton.Name = "perlInstallButton"; - this.perlInstallButton.Size = new System.Drawing.Size(75, 23); - this.perlInstallButton.TabIndex = 1; - this.perlInstallButton.Text = "Install"; - this.perlInstallButton.UseVisualStyleBackColor = true; + if (perlInUse == null) { + System.Windows.Forms.MessageBox.Show("No Perl currently in use!"); + return; + } - this.perlInstallButton.Click += new System.EventHandler(this.installPerlButton_Click); + bb.UseCompile(perlInUse, true); + WindowState = FormWindowState.Minimized; + Hide(); + DrawComponents(); } + // Button - Off + private void InitializePerlOffButton() { + string name = "perlOff"; + var data = Conf["button"][name]; + + perlOffButton = new System.Windows.Forms.Button(); + + perlOffButton.Name = data["name"]; + perlOffButton.Text = data["text"]; + perlOffButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlOffButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlOffButton.TabIndex = data["tabindex"]; + perlOffButton.UseVisualStyleBackColor = true; + + perlOffButton.Click += new System.EventHandler(offPerlButton_Click); + } + private void offPerlButton_Click(object Sender, EventArgs e) { + string perlInUse = bb.PerlOp.PerlInUse().Name; + + if (perlInUse == null) { + System.Windows.Forms.MessageBox.Show("No Perl currently in use!"); + return; + } + + bb.Off(); + WindowState = FormWindowState.Minimized; + Hide(); + DrawComponents(); + } + + // Button - Install + private void InitializePerlInstallButton() { + string name = "perlInstall"; + var data = Conf["button"][name]; + + perlInstallButton = new System.Windows.Forms.Button(); + + perlInstallButton.Name = data["name"]; + perlInstallButton.Text = data["text"]; + perlInstallButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlInstallButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlInstallButton.TabIndex = data["tabindex"]; + perlInstallButton.UseVisualStyleBackColor = true; + + perlInstallButton.Click += new System.EventHandler(installPerlButton_Click); + } private void installPerlButton_Click(object Sender, EventArgs e) { if (perlInstallSelect.Text == "") { System.Windows.Forms.MessageBox.Show("No Perl selected to install!"); @@ -367,19 +447,28 @@ private void installPerlButton_Click(object Sender, EventArgs e) { DrawComponents(); } + // Button - Switch private void InitializePerlSwitchButton() { - this.perlSwitchButton = new System.Windows.Forms.Button(); - - this.perlSwitchButton.Location = new System.Drawing.Point(139, 35); - this.perlSwitchButton.Name = "perlSwitchButton"; - this.perlSwitchButton.Size = new System.Drawing.Size(75, 23); - this.perlSwitchButton.TabIndex = 1; - this.perlSwitchButton.Text = "Switch"; - this.perlSwitchButton.UseVisualStyleBackColor = true; + string name = "perlSwitch"; + var data = Conf["button"][name]; + + perlSwitchButton = new System.Windows.Forms.Button(); + + perlSwitchButton.Name = data["name"]; + perlSwitchButton.Text = data["text"]; + perlSwitchButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlSwitchButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlSwitchButton.TabIndex = data["tabindex"]; + perlSwitchButton.UseVisualStyleBackColor = true; - this.perlSwitchButton.Click += new System.EventHandler(this.switchPerlButton_Click); + perlSwitchButton.Click += new System.EventHandler(switchPerlButton_Click); } - private void switchPerlButton_Click(object Sender, EventArgs e) { if (perlSwitchSelect.Text == "") { System.Windows.Forms.MessageBox.Show("No Perl selected to switch to!"); @@ -388,25 +477,34 @@ private void switchPerlButton_Click(object Sender, EventArgs e) { string newPerl = perlSwitchSelect.Text; bb.Switch(newPerl); - this.WindowState = FormWindowState.Minimized; - this.Hide(); + WindowState = FormWindowState.Minimized; + Hide(); Application.Restart(); Environment.Exit(0); } + // Button - Use private void InitializePerlUseButton() { - this.perlUseButton = new System.Windows.Forms.Button(); - - this.perlUseButton.Location = new System.Drawing.Point(139, 95); - this.perlUseButton.Name = "perlUseButton"; - this.perlUseButton.Size = new System.Drawing.Size(75, 23); - this.perlUseButton.TabIndex = 1; - this.perlUseButton.Text = "Use"; - this.perlUseButton.UseVisualStyleBackColor = true; + string name = "perlUse"; + var data = Conf["button"][name]; + + perlUseButton = new System.Windows.Forms.Button(); + + perlUseButton.Name = data["name"]; + perlUseButton.Text = data["text"]; + perlUseButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlUseButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlUseButton.TabIndex = data["tabindex"]; + perlUseButton.UseVisualStyleBackColor = true; - this.perlUseButton.Click += new System.EventHandler(this.usePerlButton_Click); + perlUseButton.Click += new System.EventHandler(usePerlButton_Click); } - private void usePerlButton_Click(object Sender, EventArgs e) { if (perlUseSelect.Text == "") { System.Windows.Forms.MessageBox.Show("No Perl selected to use!"); @@ -418,19 +516,28 @@ private void usePerlButton_Click(object Sender, EventArgs e) { DrawComponents(); } + // Button - Remove private void InitializePerlRemoveButton() { - this.perlRemoveButton = new System.Windows.Forms.Button(); - - this.perlRemoveButton.Location = new System.Drawing.Point(139, 125); - this.perlRemoveButton.Name = "perlRemoveButton"; - this.perlRemoveButton.Size = new System.Drawing.Size(75, 23); - this.perlRemoveButton.TabIndex = 1; - this.perlRemoveButton.Text = "Remove"; - this.perlRemoveButton.UseVisualStyleBackColor = true; + string name = "perlRemove"; + var data = Conf["button"][name]; + + perlRemoveButton = new System.Windows.Forms.Button(); + + perlRemoveButton.Name = data["name"]; + perlRemoveButton.Text = data["text"]; + perlRemoveButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlRemoveButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlRemoveButton.TabIndex = data["tabindex"]; + perlRemoveButton.UseVisualStyleBackColor = true; - this.perlRemoveButton.Click += new System.EventHandler(this.removePerlButton_Click); + perlRemoveButton.Click += new System.EventHandler(removePerlButton_Click); } - private void removePerlButton_Click(object Sender, EventArgs e) { if (perlRemoveSelect.Text == "") { System.Windows.Forms.MessageBox.Show("No Perl selected to remove!"); @@ -442,19 +549,28 @@ private void removePerlButton_Click(object Sender, EventArgs e) { DrawComponents(); } + // Button - Clone private void InitializePerlCloneButton() { - this.perlCloneButton = new System.Windows.Forms.Button(); - - this.perlCloneButton.Location = new System.Drawing.Point(139, 155); - this.perlCloneButton.Name = "perlCloneButton"; - this.perlCloneButton.Size = new System.Drawing.Size(75, 23); - this.perlCloneButton.TabIndex = 1; - this.perlCloneButton.Text = "Clone"; - this.perlCloneButton.UseVisualStyleBackColor = true; + string name = "perlClone"; + var data = Conf["button"][name]; + + perlCloneButton = new System.Windows.Forms.Button(); + + perlCloneButton.Name = data["name"]; + perlCloneButton.Text = data["text"]; + perlCloneButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlCloneButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlCloneButton.TabIndex = data["tabindex"]; + perlCloneButton.UseVisualStyleBackColor = true; - this.perlCloneButton.Click += new System.EventHandler(this.clonePerlButton_Click); + perlCloneButton.Click += new System.EventHandler(clonePerlButton_Click); } - private void clonePerlButton_Click(object Sender, EventArgs e) { if (perlCloneSelect.Text == "") { System.Windows.Forms.MessageBox.Show("No Perl selected to clone!"); @@ -475,59 +591,87 @@ private void clonePerlButton_Click(object Sender, EventArgs e) { MessageBox.Show(String.Format("Successfully cloned Perl {0} to {1}", clonePerl, clonePerlName)); } + // Button - Fetch private void InitializePerlFetchButton() { - this.perlFetchButton = new System.Windows.Forms.Button(); - - this.perlFetchButton.Location = new System.Drawing.Point(10, 185); - this.perlFetchButton.Name = "perlFetchButton"; - this.perlFetchButton.Size = new System.Drawing.Size(75, 23); - this.perlFetchButton.TabIndex = 1; - this.perlFetchButton.Text = "Fetch"; - this.perlFetchButton.UseVisualStyleBackColor = true; + string name = "perlFetch"; + var data = Conf["button"][name]; + + perlFetchButton = new System.Windows.Forms.Button(); + + perlFetchButton.Name = data["name"]; + perlFetchButton.Text = data["text"]; + perlFetchButton.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlFetchButton.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlFetchButton.TabIndex = data["tabindex"]; + perlFetchButton.UseVisualStyleBackColor = true; - this.perlFetchButton.Click += new System.EventHandler(this.fetchPerlButton_Click); + perlFetchButton.Click += new System.EventHandler(fetchPerlButton_Click); } - private void fetchPerlButton_Click(object Sender, EventArgs e) { bb.PerlOp.PerlUpdateAvailableList(); DrawComponents(); MessageBox.Show("Successfully updated the list of available Perls.", "berrybrew fetch"); } + // Select - Install private void InitializePerlInstallSelect() { - this.perlInstallSelect = new System.Windows.Forms.ComboBox(); - this.perlInstallSelect.DropDownStyle = ComboBoxStyle.DropDownList; - - this.perlInstallSelect.FormattingEnabled = true; - this.perlInstallSelect.Location = new System.Drawing.Point(10, 65); - this.perlInstallSelect.Name = "perlSwitchSelect"; - this.perlInstallSelect.Size = new System.Drawing.Size(121, 30); - this.perlInstallSelect.TabIndex = 0; + string name = "perlInstall"; + var data = Conf["combobox"][name]; + + perlInstallSelect = new System.Windows.Forms.ComboBox(); + perlInstallSelect.DropDownStyle = ComboBoxStyle.DropDownList; + + perlInstallSelect.Name = data["name"]; + perlInstallSelect.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlInstallSelect.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlInstallSelect.FormattingEnabled = data["formatting_enabled"]; + perlInstallSelect.TabIndex = data["tabindex"]; foreach (string perlName in bb.AvailableList()) { - this.perlInstallSelect.Items.Add(perlName ); + perlInstallSelect.Items.Add(perlName ); } } - private void PerlInstallSelect_Redraw() { perlInstallSelect.Items.Clear(); foreach (string perlName in bb.AvailableList()) { - this.perlInstallSelect.Items.Add(perlName ); + perlInstallSelect.Items.Add(perlName ); } perlInstallSelect.SelectedIndex = -1; } + // Select - Switch private void InitializePerlSwitchSelect() { - this.perlSwitchSelect = new System.Windows.Forms.ComboBox(); - this.perlSwitchSelect.DropDownStyle = ComboBoxStyle.DropDownList; - - this.perlSwitchSelect.FormattingEnabled = true; - this.perlSwitchSelect.Location = new System.Drawing.Point(10, 35); - this.perlSwitchSelect.Name = "perlSwitchSelect"; - this.perlSwitchSelect.Size = new System.Drawing.Size(121, 30); - this.perlSwitchSelect.TabIndex = 0; + string name = "perlSwitch"; + var data = Conf["combobox"][name]; + + perlSwitchSelect = new System.Windows.Forms.ComboBox(); + perlSwitchSelect.DropDownStyle = ComboBoxStyle.DropDownList; + + perlSwitchSelect.Name = data["name"]; + perlSwitchSelect.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlSwitchSelect.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlSwitchSelect.FormattingEnabled = data["formatting_enabled"]; + perlSwitchSelect.TabIndex = data["tabindex"]; string perlInUse = bb.PerlOp.PerlInUse().Name; @@ -535,10 +679,9 @@ private void InitializePerlSwitchSelect() { if (perl.Name == perlInUse) continue; - this.perlSwitchSelect.Items.Add(perl.Name ); + perlSwitchSelect.Items.Add(perl.Name ); } } - private void PerlSwitchSelect_Redraw() { perlSwitchSelect.Items.Clear(); @@ -548,163 +691,187 @@ private void PerlSwitchSelect_Redraw() { if (perl.Name == perlInUse) continue; - this.perlSwitchSelect.Items.Add(perl.Name ); + perlSwitchSelect.Items.Add(perl.Name ); } perlSwitchSelect.SelectedIndex = -1; } + // Select - Use private void InitializePerlUseSelect() { - this.perlUseSelect = new System.Windows.Forms.ComboBox(); - this.perlUseSelect.DropDownStyle = ComboBoxStyle.DropDownList; - - this.perlUseSelect.FormattingEnabled = true; - this.perlUseSelect.Location = new System.Drawing.Point(10, 95); - this.perlUseSelect.Name = "perlUseSelect"; - this.perlUseSelect.Size = new System.Drawing.Size(121, 30); - this.perlUseSelect.TabIndex = 0; + string name = "perlUse"; + var data = Conf["combobox"][name]; + + perlUseSelect = new System.Windows.Forms.ComboBox(); + perlUseSelect.DropDownStyle = ComboBoxStyle.DropDownList; + + perlUseSelect.Name = data["name"]; + perlUseSelect.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlUseSelect.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlUseSelect.FormattingEnabled = data["formatting_enabled"]; + perlUseSelect.TabIndex = data["tabindex"]; foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlUseSelect.Items.Add(perl.Name ); + perlUseSelect.Items.Add(perl.Name ); } } - private void PerlUseSelect_Redraw() { perlUseSelect.Items.Clear(); foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlUseSelect.Items.Add(perl.Name ); + perlUseSelect.Items.Add(perl.Name ); } perlUseSelect.SelectedIndex = -1; } + // Select - Remove private void InitializePerlRemoveSelect() { - this.perlRemoveSelect = new System.Windows.Forms.ComboBox(); - this.perlRemoveSelect.DropDownStyle = ComboBoxStyle.DropDownList; - - this.perlRemoveSelect.FormattingEnabled = true; - this.perlRemoveSelect.Location = new System.Drawing.Point(10, 125); - this.perlRemoveSelect.Name = "perlRemoveSelect"; - this.perlRemoveSelect.Size = new System.Drawing.Size(121, 30); - this.perlRemoveSelect.TabIndex = 0; + string name = "perlRemove"; + var data = Conf["combobox"][name]; + + perlRemoveSelect = new System.Windows.Forms.ComboBox(); + perlRemoveSelect.DropDownStyle = ComboBoxStyle.DropDownList; + + perlRemoveSelect.Name = data["name"]; + perlRemoveSelect.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlRemoveSelect.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlRemoveSelect.FormattingEnabled = data["formatting_enabled"]; + perlRemoveSelect.TabIndex = data["tabindex"]; foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlRemoveSelect.Items.Add(perl.Name); + perlRemoveSelect.Items.Add(perl.Name); } } - private void PerlRemoveSelect_Redraw() { perlRemoveSelect.Items.Clear(); foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlRemoveSelect.Items.Add(perl.Name); + perlRemoveSelect.Items.Add(perl.Name); } perlRemoveSelect.SelectedIndex = -1; } + // Select - Clone private void InitializePerlCloneSelect() { - this.perlCloneSelect = new System.Windows.Forms.ComboBox(); - this.perlCloneSelect.DropDownStyle = ComboBoxStyle.DropDownList; - - this.perlCloneSelect.FormattingEnabled = true; - this.perlCloneSelect.Location = new System.Drawing.Point(10, 155); - this.perlCloneSelect.Name = "perlCloneSelect"; - this.perlCloneSelect.Size = new System.Drawing.Size(121, 30); - this.perlCloneSelect.TabIndex = 0; + string name = "perlClone"; + var data = Conf["combobox"][name]; + + perlCloneSelect = new System.Windows.Forms.ComboBox(); + perlCloneSelect.DropDownStyle = ComboBoxStyle.DropDownList; + + perlCloneSelect.Name = data["name"]; + perlCloneSelect.Location = new System.Drawing.Point( + (int) data["location"][0], + (int) data["location"][1] + ); + perlCloneSelect.Size = new System.Drawing.Size( + (int) data["size"][0], + (int) data["size"][1] + ); + perlCloneSelect.FormattingEnabled = data["formatting_enabled"]; + perlCloneSelect.TabIndex = data["tabindex"]; foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlCloneSelect.Items.Add(perl.Name); + perlCloneSelect.Items.Add(perl.Name); } } - private void PerlCloneSelect_Redraw() { perlCloneSelect.Items.Clear(); foreach (StrawberryPerl perl in bb.PerlOp.PerlsInstalled()) { - this.perlCloneSelect.Items.Add(perl.Name); + perlCloneSelect.Items.Add(perl.Name); } perlCloneSelect.SelectedIndex = -1; } + // Tray Icon private void trayIcon_Click(object Sender, EventArgs e) { DrawComponents(); - if (this.WindowState == FormWindowState.Minimized) { - this.Show(); - this.WindowState = FormWindowState.Normal; + if (WindowState == FormWindowState.Minimized) { + Show(); + WindowState = FormWindowState.Normal; } else { - this.WindowState = FormWindowState.Minimized; - this.Hide(); + WindowState = FormWindowState.Minimized; + Hide(); } } - private void rightClickExit_Click(object Sender, EventArgs e) { - this.Close(); + Close(); } private void Form1_Load(object sender, EventArgs e) { - - this.ClientSize = new System.Drawing.Size(265, 325); - + if (bb.PerlOp.PerlInUse().Name != null) { - this.Controls.Add(this.perlOpenButton); + Controls.Add(perlOpenButton); } - this.Controls.Add(this.perlSwitchButton); - this.Controls.Add(this.perlSwitchSelect); + Controls.Add(perlSwitchButton); + Controls.Add(perlSwitchSelect); - this.Controls.Add(this.perlInstallButton); - this.Controls.Add(this.perlInstallSelect); + Controls.Add(perlInstallButton); + Controls.Add(perlInstallSelect); - this.Controls.Add(this.perlUseButton); - this.Controls.Add(this.perlUseSelect); + Controls.Add(perlUseButton); + Controls.Add(perlUseSelect); - this.Controls.Add(this.perlRemoveButton); - this.Controls.Add(this.perlRemoveSelect); + Controls.Add(perlRemoveButton); + Controls.Add(perlRemoveSelect); - this.Controls.Add(this.perlCloneButton); - this.Controls.Add(this.perlCloneSelect); + Controls.Add(perlCloneButton); + Controls.Add(perlCloneSelect); - this.Controls.Add(this.perlFetchButton); + Controls.Add(perlFetchButton); DrawComponents(); - this.Name = "BBUI"; + Name = "BBUI"; string runMode = bb.Options("run_mode", null, true); if (runMode == "prod" || runMode == null) { - this.Text = "BB UI v" + bb.Version(); + Text = "BB UI v" + bb.Version(); } else if (runMode == "staging") { - this.Text = "BB-DEV UI v" + bb.Version(); + Text = "BB-DEV UI v" + bb.Version(); } - this.WindowState = FormWindowState.Minimized; - this.Hide(); - this.ShowInTaskbar = false; - this.ResumeLayout(false); + WindowState = FormWindowState.Minimized; + Hide(); + ShowInTaskbar = false; + ResumeLayout(false); } - private void Form1_FormClosing(Object sender, FormClosingEventArgs e) { if (! new StackTrace().GetFrames().Any(x => x.GetMethod().Name == "Close")){ - this.Hide(); - this.WindowState = FormWindowState.Minimized; + Hide(); + WindowState = FormWindowState.Minimized; e.Cancel = true; } } private void DrawComponents() { if (bb.PerlOp.PerlInUse().Name != null) { - this.Controls.Add(this.perlOpenButton); - this.Controls.Add(this.perlOffButton); + Controls.Add(perlOpenButton); + Controls.Add(perlOffButton); } else { - this.Controls.Remove(this.perlOpenButton); - this.Controls.Remove(this.perlOffButton); + Controls.Remove(perlOpenButton); + Controls.Remove(perlOffButton); } CurrentPerlLabel_Redraw();