'  
'   Rebex Sample Code License
' 
'   Copyright 2026, REBEX CR s.r.o.
'   All rights reserved.
'   https://www.rebex.net/
' 
'   Permission to use, copy, modify, and/or distribute this software for any
'   purpose with or without fee is hereby granted.
' 
'   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
'   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
'   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
'   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
'   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
'   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
'   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
'   OTHER DEALINGS IN THE SOFTWARE.
' 

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

''' <summary>
''' A dialog that asks for a new name.
''' </summary>
Partial Public Class NewNameDialog
    Inherits Form

    ''' <summary>
    ''' Initializes a new instance of the dialog.
    ''' </summary>
    ''' <param name="originalName">Original name.</param>
    ''' <param name="isFileName">Whether the name is a file or directory name.</param>
    Public Sub New(ByVal originalName As String, ByVal isFileName As Boolean)
        InitializeComponent()

        If String.IsNullOrEmpty(originalName) Then
            If isFileName Then
                labelInfo.Text = "Enter a file name:"
            Else
                labelInfo.Text = "Enter a directory name:"
            End If
        Else
            If isFileName Then
                labelInfo.Text = String.Format("Enter a new name for the file {0}:", originalName)
            Else
                labelInfo.Text = String.Format("Enter a new name for the directory {0}:", originalName)
            End If
        End If

        txtNewName.Text = originalName
    End Sub

    ''' <summary>
    ''' Gets the new name.
    ''' </summary>
    Public ReadOnly Property NewName() As String
        Get
            Return txtNewName.Text
        End Get
    End Property

    ''' <summary>
    ''' Validates user input on closing.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub NewNameDialog_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
        If DialogResult = DialogResult.OK AndAlso NewName.Trim() = String.Empty Then
            MessageBox.Show("Name cannot be empty.")
            e.Cancel = True
        End If
    End Sub
End Class
