Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/12 17:13:25 (12 years ago)
Author:
jkarder
Message:

#1926:

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.Designer.cs

    r8563 r8748  
    182182      this.Text = "HeuristicLab Starter";
    183183      this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.StarterForm_FormClosing);
    184       this.Shown += new System.EventHandler(this.StarterForm_Shown);
     184      this.Load += new System.EventHandler(this.StarterForm_Load);
    185185      this.ResumeLayout(false);
    186186
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs

    r8677 r8748  
    4040    private const string updatePluginsItemName = "Updates Available";
    4141
     42    private readonly ICommandLineArgument[] arguments;
    4243
    4344    private ListViewItem pluginManagerListViewItem;
     
    4647    private SplashScreen splashScreen;
    4748    private bool updatesAvailable = false;
    48     private string[] arguments;
    4949
    5050    /// <summary>
     
    6565      pluginManager = new PluginManager(pluginPath);
    6666      splashScreen = new SplashScreen(pluginManager, 1000);
     67      splashScreen.VisibleChanged += new EventHandler(splashScreen_VisibleChanged);
    6768      splashScreen.Show(this, "Loading HeuristicLab...");
    6869
     
    7172
    7273      CheckUpdatesAvailableAsync();
     74    }
     75
     76    /// <summary>
     77    /// Creates a new StarterForm and passes the arguments in <paramref name="args"/>.
     78    /// </summary>
     79    /// <param name="args">The arguments that should be processed</param>
     80    public StarterForm(string[] args)
     81      : this() {
     82      arguments = CommandLineArgumentHandling.GetArguments(args);
     83    }
     84
     85    protected override void SetVisibleCore(bool value) {
     86      value &= !arguments.OfType<HideStarterArgument>().Any();
     87      if (!value) HandleArguments();
     88      base.SetVisibleCore(value);
     89    }
     90
     91    #region Events
     92    private void StarterForm_Load(object sender, EventArgs e) {
     93      HandleArguments();
     94    }
     95
     96    private void StarterForm_FormClosing(object sender, FormClosingEventArgs e) {
     97      splashScreen.Close();
     98      abortRequested = true;
     99    }
     100
     101    private void applicationsListView_SelectedIndexChanged(object sender, EventArgs e) {
     102      startButton.Enabled = applicationsListView.SelectedItems.Count > 0;
     103    }
     104
     105    private void applicationsListView_ItemActivate(object sender, EventArgs e) {
     106      if (applicationsListView.SelectedItems.Count > 0) {
     107        ListViewItem selected = applicationsListView.SelectedItems[0];
     108        if (selected.Text == pluginManagerItemName) {
     109          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
     110            MessageBox.Show("Installation Manager cannot be started while another HeuristicLab application is active." + Environment.NewLine +
     111              "Please stop all active HeuristicLab applications and try again.", "Plugin Manager",
     112              MessageBoxButtons.OK, MessageBoxIcon.Information);
     113          } else {
     114            try {
     115              Cursor = Cursors.AppStarting;
     116              using (InstallationManagerForm form = new InstallationManagerForm(pluginManager)) {
     117                form.ShowDialog(this);
     118              }
     119              UpdateApplicationsList();
     120            }
     121            finally {
     122              Cursor = Cursors.Arrow;
     123            }
     124          }
     125        } else if (selected.Text == updatePluginsItemName) {
     126          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
     127            MessageBox.Show("Updating is not possible while another HeuristicLab application is active." + Environment.NewLine +
     128              "Please stop all active HeuristicLab applications and try again.", "Update plugins",
     129              MessageBoxButtons.OK, MessageBoxIcon.Information);
     130          } else {
     131            try {
     132              Cursor = Cursors.AppStarting;
     133              using (PluginUpdaterForm form = new PluginUpdaterForm(pluginManager)) {
     134                form.ShowDialog(this);
     135              }
     136              updatesAvailable = false;
     137              CheckUpdatesAvailableAsync();
     138              UpdateApplicationsList();
     139            }
     140            finally {
     141              Cursor = Cursors.Arrow;
     142            }
     143          }
     144        } else {
     145          ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
     146          StartApplication(app);
     147        }
     148      }
     149    }
     150
     151    private void largeIconsButton_Click(object sender, EventArgs e) {
     152      applicationsListView.View = View.LargeIcon;
     153    }
     154
     155    private void detailsButton_Click(object sender, EventArgs e) {
     156      applicationsListView.View = View.Details;
     157      foreach (ColumnHeader column in applicationsListView.Columns) {
     158        if (applicationsListView.Items.Count > 0)
     159          column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     160        else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     161      }
     162    }
     163
     164    private void aboutButton_Click(object sender, EventArgs e) {
     165      List<IPluginDescription> plugins = new List<IPluginDescription>(pluginManager.Plugins.OfType<IPluginDescription>());
     166      using (var dialog = new AboutDialog(plugins)) {
     167        dialog.ShowDialog();
     168      }
     169    }
     170
     171    private void splashScreen_VisibleChanged(object sender, EventArgs e) {
     172      // close hidden starter form
     173      if (!splashScreen.Visible && arguments != null && arguments.OfType<HideStarterArgument>().Any())
     174        Close();
     175    }
     176    #endregion
     177
     178    #region Helpers
     179    private void UpdateApplicationsList() {
     180      if (InvokeRequired) Invoke((Action)UpdateApplicationsList);
     181      else {
     182        applicationsListView.Items.Clear();
     183        AddPluginManagerItem();
     184        AddUpdatePluginsItem();
     185
     186        foreach (ApplicationDescription info in pluginManager.Applications) {
     187          ListViewItem item = new ListViewItem(info.Name, 0);
     188          item.Tag = info;
     189          item.Group = applicationsListView.Groups["Applications"];
     190          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Version.ToString()));
     191          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Description));
     192          item.ToolTipText = info.Description;
     193          applicationsListView.Items.Add(item);
     194        }
     195        foreach (ColumnHeader column in applicationsListView.Columns) {
     196          if (applicationsListView.Items.Count > 0)
     197            column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     198          else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     199        }
     200      }
     201    }
     202
     203    private void AddPluginManagerItem() {
     204      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
     205      pluginManagerListViewItem = new ListViewItem(pluginManagerItemName, 0);
     206      pluginManagerListViewItem.Group = applicationsListView.Groups["Plugin Management"];
     207      pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, pluginInfrastructureVersion.FileVersion));
     208      pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, "Install, upgrade or delete plugins"));
     209      pluginManagerListViewItem.ToolTipText = "Install, upgrade or delete plugins";
     210
     211      applicationsListView.Items.Add(pluginManagerListViewItem);
     212    }
     213
     214    private void AddUpdatePluginsItem() {
     215      if (updatesAvailable) {
     216        var updateListViewItem = new ListViewItem(updatePluginsItemName, 1);
     217        updateListViewItem.Group = applicationsListView.Groups["Plugin Management"];
     218        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, ""));
     219        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, "Download and install updates"));
     220        updateListViewItem.ToolTipText = "Download and install updates";
     221
     222        applicationsListView.Items.Add(updateListViewItem);
     223      }
    73224    }
    74225
     
    110261    }
    111262
    112     /// <summary>
    113     /// Creates a new StarterForm and passes the arguments in <paramref name="args"/>.
    114     /// </summary>
    115     /// <param name="args">The arguments that should be processed</param>
    116     public StarterForm(string[] args)
    117       : this() {
    118       this.arguments = args;
    119     }
    120 
    121     private void StarterForm_Shown(object sender, EventArgs e) {
     263    private void HandleArguments() {
    122264      try {
    123         foreach (var argument in ArgumentHandling.GetArguments(arguments)) {
    124           if (argument.Token == Argument.START) {
     265        foreach (var argument in arguments) {
     266          if (argument is StartArgument) {
    125267            var appDesc = (from desc in pluginManager.Applications
    126                            where desc.Name == argument.Value
     268                           where desc.Name.Equals(argument.Value)
    127269                           select desc).SingleOrDefault();
    128270            if (appDesc != null) {
     
    142284    }
    143285
    144     private void applicationsListView_ItemActivate(object sender, EventArgs e) {
    145       if (applicationsListView.SelectedItems.Count > 0) {
    146         ListViewItem selected = applicationsListView.SelectedItems[0];
    147         if (selected.Text == pluginManagerItemName) {
    148           if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
    149             MessageBox.Show("Installation Manager cannot be started while another HeuristicLab application is active." + Environment.NewLine +
    150               "Please stop all active HeuristicLab applications and try again.", "Plugin Manager",
    151               MessageBoxButtons.OK, MessageBoxIcon.Information);
    152           } else {
    153             try {
    154               Cursor = Cursors.AppStarting;
    155               using (InstallationManagerForm form = new InstallationManagerForm(pluginManager)) {
    156                 form.ShowDialog(this);
    157               }
    158               UpdateApplicationsList();
    159             }
    160             finally {
    161               Cursor = Cursors.Arrow;
    162             }
    163           }
    164         } else if (selected.Text == updatePluginsItemName) {
    165           if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
    166             MessageBox.Show("Updating is not possible while another HeuristicLab application is active." + Environment.NewLine +
    167               "Please stop all active HeuristicLab applications and try again.", "Update plugins",
    168               MessageBoxButtons.OK, MessageBoxIcon.Information);
    169           } else {
    170             try {
    171               Cursor = Cursors.AppStarting;
    172               using (PluginUpdaterForm form = new PluginUpdaterForm(pluginManager)) {
    173                 form.ShowDialog(this);
    174               }
    175               updatesAvailable = false;
    176               CheckUpdatesAvailableAsync();
    177               UpdateApplicationsList();
    178             }
    179             finally {
    180               Cursor = Cursors.Arrow;
    181             }
    182           }
    183         } else {
    184           ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
    185           StartApplication(app);
    186         }
    187       }
    188     }
    189 
    190     private void UpdateApplicationsList() {
    191       if (InvokeRequired) Invoke((Action)UpdateApplicationsList);
    192       else {
    193         applicationsListView.Items.Clear();
    194         AddPluginManagerItem();
    195         AddUpdatePluginsItem();
    196 
    197         foreach (ApplicationDescription info in pluginManager.Applications) {
    198           ListViewItem item = new ListViewItem(info.Name, 0);
    199           item.Tag = info;
    200           item.Group = applicationsListView.Groups["Applications"];
    201           item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Version.ToString()));
    202           item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Description));
    203           item.ToolTipText = info.Description;
    204           applicationsListView.Items.Add(item);
    205         }
    206         foreach (ColumnHeader column in applicationsListView.Columns) {
    207           if (applicationsListView.Items.Count > 0)
    208             column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    209           else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
    210         }
    211       }
    212     }
    213 
    214     private void AddPluginManagerItem() {
    215       FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
    216       pluginManagerListViewItem = new ListViewItem(pluginManagerItemName, 0);
    217       pluginManagerListViewItem.Group = applicationsListView.Groups["Plugin Management"];
    218       pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, pluginInfrastructureVersion.FileVersion));
    219       pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, "Install, upgrade or delete plugins"));
    220       pluginManagerListViewItem.ToolTipText = "Install, upgrade or delete plugins";
    221 
    222       applicationsListView.Items.Add(pluginManagerListViewItem);
    223     }
    224 
    225     private void AddUpdatePluginsItem() {
    226       if (updatesAvailable) {
    227         var updateListViewItem = new ListViewItem(updatePluginsItemName, 1);
    228         updateListViewItem.Group = applicationsListView.Groups["Plugin Management"];
    229         updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, ""));
    230         updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, "Download and install updates"));
    231         updateListViewItem.ToolTipText = "Download and install updates";
    232 
    233         applicationsListView.Items.Add(updateListViewItem);
    234       }
    235     }
    236 
    237286    private void StartApplication(ApplicationDescription app) {
    238287      splashScreen.Show("Loading " + app.Name);
     
    256305      t.Start();
    257306    }
    258 
    259     private void applicationsListView_SelectedIndexChanged(object sender, EventArgs e) {
    260       startButton.Enabled = applicationsListView.SelectedItems.Count > 0;
    261     }
    262 
    263     private void largeIconsButton_Click(object sender, EventArgs e) {
    264       applicationsListView.View = View.LargeIcon;
    265     }
    266 
    267     private void detailsButton_Click(object sender, EventArgs e) {
    268       applicationsListView.View = View.Details;
    269       foreach (ColumnHeader column in applicationsListView.Columns) {
    270         if (applicationsListView.Items.Count > 0)
    271           column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    272         else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
    273       }
    274     }
    275 
    276     private void StarterForm_FormClosing(object sender, FormClosingEventArgs e) {
    277       splashScreen.Close();
    278       abortRequested = true;
    279     }
    280 
    281     private void aboutButton_Click(object sender, EventArgs e) {
    282       List<IPluginDescription> plugins = new List<IPluginDescription>(pluginManager.Plugins.OfType<IPluginDescription>());
    283       using (var dialog = new AboutDialog(plugins)) {
    284         dialog.ShowDialog();
    285       }
    286     }
     307    #endregion
    287308  }
    288309}
Note: See TracChangeset for help on using the changeset viewer.