5. Add User Interface

This is what we want the UI to look like:

 

Step 1: Create the Expander.

Create an Expander - FILES_IN_FOLDER. This will receive the list of files from our Code Nanite.

Check "Contains Multiple Items" 

Set Delimiter to "|"

 

 

Step 2: Create the form

You can download the form here..

 

frmFilesList.cs:

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace DolaSoft.CodeNanites
{
    public partial class FrmFilesList : BaseForm
    {
        public string[] FileList { get; private set; }
        public FrmFilesList()
        {
            InitializeComponent();
        }

        private FolderBrowserDialog _folderPicker;
        private void btnFolder_Click(object sender, EventArgs e)
        {
            _folderPicker = new FolderBrowserDialog();
            if (_folderPicker.ShowDialog() == DialogResult.OK && _folderPicker.SelectedPath != null)
            {
                btnRetrieve.Enabled = true;
                txtSelectedFolder.Text = _folderPicker.SelectedPath;
            }
            else
                btnRetrieve.Enabled = false;
        }

        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            listBox.Items.Clear();
            var files = Directory.GetFiles(_folderPicker.SelectedPath, txtWildcard.Text);
            foreach (var file in files)
                listBox.Items.Add(chkShowFullPath.Checked ? file : Path.GetFileName(file));

            if (files.Length > 0)
                lblTotalFiles.Text = files.Length.ToString() + " File(s)";
            else
                lblTotalFiles.Text = string.Empty;

            FileList = listBox.Items.OfType().ToArray();
        }
    }
}

 

Step 3: Hook up the form to  FolderListing.Fucntions.cs

FolderListing.Fucntions.cs:

using System.Windows.Forms;
  
namespace DolaSoft.CodeNanites
{
    public partial class FolderListing
    {
        private void MainFunction()
        {
            var frm = new FrmFilesList();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                ExpanderUpdater(string.Join("|", frm.FileList), "FILES_IN_FOLDER",0,true,"|");
            }
        }
    }
}

The ExpanderUpdater method will update the Expander - "FILES_IN_FOLDER"

 

Step 4: Add Node for Expander

Next, we need to add a node (files.html) that will contain the code that uses our Code Nanite:

 

Step 5: Generate Code

Once you start generating code, you will be prompted to fill the Form we created in the Nanite.

 

 

You can see what the generated code looks like:

 

 

 

About CodeStencil

CodeStencil is Published and Marketed by Zera Systems Inc.





© 2018-2019 CodeStencil - Zera Systems Inc. All Rights Reserved.

No items in cart