Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensured that Script window short cut keys work correctly #8405

Merged
merged 7 commits into from
Jul 10, 2023
113 changes: 78 additions & 35 deletions instat/ucrScript.vb
Original file line number Diff line number Diff line change
Expand Up @@ -236,40 +236,42 @@ Public Class ucrScript
Private Sub EnableDisableButtons()

Dim bIsLogTab As Boolean = TabControl.SelectedIndex = iTabIndexLog

mnuUndo.Enabled = clsScriptActive.CanUndo AndAlso Not bIslogTab
mnuRedo.Enabled = clsScriptActive.CanRedo AndAlso Not bIslogTab

Dim bScriptselected = clsScriptActive.SelectedText.Length > 0
Patowhiz marked this conversation as resolved.
Show resolved Hide resolved
Dim bScriptExists = clsScriptActive.TextLength > 0

mnuCut.Enabled = bScriptselected AndAlso Not bIsLogTab
mnuCopy.Enabled = bScriptselected
mnuPaste.Enabled = Clipboard.ContainsData(DataFormats.Text) AndAlso Not bIslogTab
mnuSelectAll.Enabled = bScriptExists
mnuClear.Enabled = bScriptExists AndAlso Not bIslogTab

mnuRunCurrentLineSelection.Enabled = bScriptExists
mnuRunAllText.Enabled = bScriptExists

mnuOpenScriptasFile.Enabled = bScriptExists
mnuLoadScriptFromFile.Enabled = Not bIsLogTab
mnuSaveScript.Enabled = bScriptExists

cmdRunLineSelection.Enabled = bScriptExists
cmdRunAll.Enabled = bScriptExists
cmdLoadScript.Enabled = Not bIsLogTab
cmdSave.Enabled = bScriptExists
cmdClear.Enabled = bScriptExists AndAlso Not bIslogTab
cmdClear.Enabled = bScriptExists AndAlso Not bIsLogTab

cmdRemoveTab.Enabled = TabControl.TabCount > 2 AndAlso Not bIslogTab
cmdRemoveTab.Enabled = TabControl.TabCount > 2 AndAlso Not bIsLogTab
End Sub

Private Sub EnableRunButtons(bEnable As Boolean)
cmdRunLineSelection.Enabled = bEnable
cmdRunAll.Enabled = bEnable
End Sub

''' <summary>
''' Enables or disables all right click menu options
''' </summary>
''' <param name="bEnable">If true, enables all right click options,false otherwise</param>
Private Sub EnableRightClickMenuOptions(bEnable)
Patowhiz marked this conversation as resolved.
Show resolved Hide resolved
mnuUndo.Enabled = bEnable
mnuRedo.Enabled = bEnable
mnuCut.Enabled = bEnable
mnuCopy.Enabled = bEnable
mnuPaste.Enabled = bEnable
mnuSelectAll.Enabled = bEnable
mnuClear.Enabled = bEnable
mnuRunCurrentLineSelection.Enabled = bEnable
mnuRunAllText.Enabled = bEnable
mnuLoadScriptFromFile.Enabled = bEnable
mnuOpenScriptasFile.Enabled = bEnable
mnuSaveScript.Enabled = bEnable
End Sub

'''--------------------------------------------------------------------------------------------
''' <summary>
''' If the caret is next to a bracket, then it highlights the paired open/close bracket.
Expand Down Expand Up @@ -433,6 +435,11 @@ Public Class ucrScript
End Function

Private Sub LoadScript()
If TabControl.SelectedIndex = iTabIndexLog Then
MsgBox("You can only load script to a script tab, not the log tab.", MsgBoxStyle.Exclamation, "Load to log tab")
Exit Sub
End If

If clsScriptActive.TextLength > 0 _
AndAlso MsgBox("Loading a script from file will clear your current script" _
& Environment.NewLine & "Do you still want to load?",
Expand Down Expand Up @@ -634,6 +641,54 @@ Public Class ucrScript
EnableDisableButtons()
End Sub


Private Sub mnuContextScript_Opening(sender As Object, e As EventArgs) Handles mnuContextScript.Opening
'enable and disable menu options based on the active script properties before the user views them

Dim bScriptSelected As Boolean = clsScriptActive.SelectedText.Length > 0
Dim bScriptExists As Boolean = clsScriptActive.TextLength > 0

'initially disable all the right click menu options
EnableRightClickMenuOptions(False)

'if active tab is not log tab then enable the options based on active tab state
'below are options that are not to be used in the log tab
If TabControl.SelectedIndex <> iTabIndexLog Then
mnuUndo.Enabled = clsScriptActive.CanUndo
mnuRedo.Enabled = clsScriptActive.CanRedo
mnuCut.Enabled = bScriptSelected
mnuCopy.Enabled = bScriptSelected
mnuPaste.Enabled = Clipboard.ContainsData(DataFormats.Text)
mnuClear.Enabled = bScriptExists
mnuLoadScriptFromFile.Enabled = True
End If

'enable remaining options based on tab state
mnuSelectAll.Enabled = bScriptExists
mnuRunCurrentLineSelection.Enabled = bScriptExists
mnuRunAllText.Enabled = bScriptExists
mnuOpenScriptasFile.Enabled = bScriptExists
mnuSaveScript.Enabled = bScriptExists
End Sub

Private Sub mnuContextScript_Closing(sender As Object, e As EventArgs) Handles mnuContextScript.Closing
'On closing menu context, just enable all the menu options to restore their short cut keys
'validations of the options actions is done by the functions that the events call.
EnableRightClickMenuOptions(True)
End Sub

Private Sub mnuCut_Click(sender As Object, e As EventArgs) Handles mnuCut.Click
CutText()
End Sub

Private Sub mnuCopy_Click(sender As Object, e As EventArgs) Handles mnuCopy.Click
CopyText()
End Sub

Private Sub mnuPaste_Click(sender As Object, e As EventArgs) Handles mnuPaste.Click
PasteText()
End Sub

Private Sub mnuClearContents_Click(sender As Object, e As EventArgs) Handles mnuClear.Click, cmdClear.Click

If TabControl.SelectedIndex = iTabIndexLog Then
Expand All @@ -650,18 +705,6 @@ Public Class ucrScript
EnableDisableButtons()
End Sub

Private Sub mnuContextScript_Opening(sender As Object, e As EventArgs) Handles mnuContextScript.Opening
EnableDisableButtons()
End Sub

Private Sub mnuCopy_Click(sender As Object, e As EventArgs) Handles mnuCopy.Click
CopyText()
End Sub

Private Sub mnuCut_Click(sender As Object, e As EventArgs) Handles mnuCut.Click
CutText()
End Sub

Private Sub mnuHelp_Click(sender As Object, e As EventArgs) Handles mnuHelp.Click, cmdHelp.Click
Help.ShowHelp(Me, frmMain.strStaticPath & "\" & frmMain.strHelpFilePath, HelpNavigator.TopicId, "542")
End Sub
Expand Down Expand Up @@ -695,10 +738,6 @@ Public Class ucrScript
End Try
End Sub

Private Sub mnuPaste_Click(sender As Object, e As EventArgs) Handles mnuPaste.Click
PasteText()
End Sub

Private Sub mnuRedo_Click(sender As Object, e As EventArgs) Handles mnuRedo.Click
If TabControl.SelectedIndex = iTabIndexLog Then
MsgBox("You can only redo in a script tab, not the log tab.", MsgBoxStyle.Exclamation, "Redo log tab")
Expand All @@ -720,19 +759,23 @@ Public Class ucrScript
End If

EnableRunButtons(False) 'temporarily disable the run buttons in case its a long operation
EnableRightClickMenuOptions(False)
RunText(clsScriptActive.Text)
EnableRunButtons(True)
EnableRightClickMenuOptions(True)
End Sub

Private Sub mnuRunCurrentLineSelection_Click(sender As Object, e As EventArgs) Handles mnuRunCurrentLineSelection.Click, cmdRunLineSelection.Click
'temporarily disable the buttons in case its a long operation
EnableRunButtons(False)
EnableRightClickMenuOptions(False)
If clsScriptActive.SelectedText.Length > 0 Then
RunText(clsScriptActive.SelectedText)
Else
RunCurrentLine()
End If
EnableRunButtons(True)
EnableRightClickMenuOptions(True)
End Sub

Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
Expand Down