NotepadUltra/Open Passed File.vb
2019-04-21 02:29:16 +10:00

106 lines
No EOL
4.4 KiB
VB.net

Public Class Open_Passed_File
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles SetDirectoryButton.Click, CopyButton.Click, MoveButton.Click
If Not My.Settings.SupportedExtensions.Contains(GetFileExtension(FileToOpen)) Then
My.Settings.SupportedExtensions.Add(GetFileExtension(FileToOpen))
My.Settings.Save()
End If
Dim FileToOpenPath As String = GetPath(FileToOpen)
Dim FileToOpenFile As String = GetFile(FileToOpen)
'MsgBox(FileToOpenPath & vbNewLine & FileToOpenFile)
Select Case sender.name.ToString.RemoveLast(6)
Case "SetDirectory"
Label1.Visible = True
TopMost = False
Splash_Screen.Show()
Hide()
Splash_Screen.Activate()
My.Settings.WorkingDirectory = FileToOpenPath
My.Settings.Save()
If RememberCheckbox.Checked Then My.Settings.DefaultFileAction = 1
Case "Copy", "Move"
Dim response As String = FileToOpenFile
'MsgBox(My.Settings.WorkingDirectory & FileToOpenFile)
While My.Computer.FileSystem.FileExists(My.Settings.WorkingDirectory & FileToOpenFile)
response = InputBox("A file with the name """ & FileToOpenFile & """already exists in your base directory (" & My.Settings.WorkingDirectory & "). Please enter a new name for the file.")
If Not ValidFileName(response, True) Then
MsgBox("Invalid filename!")
Else
If Not response.Contains(".") Then response &= ".txt"
Dim ValidExt As Boolean = False
For i = 0 To My.Settings.SupportedExtensions.Count - 1
If response.Split(".")(response.Split(".").Length - 1) = My.Settings.SupportedExtensions(i) Then ValidExt = True
Next
If ValidExt Then FileToOpenFile = response Else MsgBox("Unrecognised file extension! Try using "".txt"".")
End If
End While
Label1.Visible = True
TopMost = False
Splash_Screen.Show()
Hide()
Splash_Screen.Activate()
If sender.name.ToString.RemoveLast(6) = "Copy" Then
My.Computer.FileSystem.CopyFile(FileToOpen, My.Settings.WorkingDirectory & FileToOpenFile)
If RememberCheckbox.Checked Then My.Settings.DefaultFileAction = 2
Else
My.Computer.FileSystem.MoveFile(FileToOpen, My.Settings.WorkingDirectory & FileToOpenFile)
If RememberCheckbox.Checked Then My.Settings.DefaultFileAction = 3
End If
FileToOpen = FileToOpenPath & FileToOpenFile
Case Else
Throw New Exception("Unable to parse response!") 'if this happens, your computer is not in a very reliable state. either that, or i'm a moron.
End Select
Refresh()
My.Settings.Save()
CopyButton.Enabled = False
MoveButton.Enabled = False
SetDirectoryButton.Enabled = False
RememberCheckbox.Enabled = False
NPUWindow.Show()
End Sub
Private Sub Cancel() Handles CancelOpenButton.Click
End
End Sub
Private Sub Open_Passed_File_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Icon = ProgramIcon()
Splash_Screen.TopMost = False
Activate()
If Not My.Computer.FileSystem.FileExists(FileToOpen) Then
If MsgBox("Failed to open file. Ensure Notepad Ultra has the rights to open this file!", MsgBoxStyle.Critical, vbOKOnly) <> 99999 Then End
End If
If GetPath(FileToOpen).ToLower = My.Settings.WorkingDirectory.ToLower Then
HowToOpenQuestion.Text = "Notepad Ultra - Opening " & FileToOpen & "..."
SetDirectoryButton.PerformClick() 'if you're opening a file that's already in the basedir, there's obviously no point moving or copying it
Else
If My.Settings.DefaultFileAction <> 0 Then
HowToOpenQuestion.Text = "Notepad Ultra - Opening " & FileToOpen & "..."
Refresh()
Select Case My.Settings.DefaultFileAction
Case 1
SetDirectoryButton.PerformClick()
Case 2
CopyButton.PerformClick()
Case 3
MoveButton.PerformClick()
End Select
Else
Text = "Notepad Ultra - Opening " & FileToOpen
HowToOpenQuestion.Text = "How do you want to open " & FileToOpen & "?"
ToolTip1.SetToolTip(HoverMe, My.Settings.WorkingDirectory)
If Not My.Computer.FileSystem.DirectoryExists(My.Settings.WorkingDirectory) Then
CopyButton.Enabled = False
MoveButton.Enabled = False
ToolTip1.SetToolTip(HoverMe, My.Settings.WorkingDirectory & vbNewLine & "Unable to access this directory.")
End If
End If
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("C:\Windows\notepad.exe", FileToOpen)
End
End Sub
End Class