Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mostypc123 authored Nov 30, 2024
1 parent 8b80a8d commit a56ac3b
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def CreateMenuBar(self):
copy_item = editMenu.Append(wx.ID_COPY, '&Copy\tCtrl+C', 'Copy selection')
paste_item = editMenu.Append(wx.ID_PASTE, '&Paste\tCtrl+V', 'Paste from clipboard')
find_replace_item = editMenu.Append(wx.ID_FIND, '&Find and Replace\tCtrl+F', 'Find and replace text')
jump_line_item = editMenu.Append(wx.ID_ANY, '&Jump to Line\tCtrl+G', 'Jump to a specific line number')

toolsMenu = wx.Menu()
tools_item = toolsMenu.Append(wx.ID_ANY, '&Tools\tCtrl+T', 'Run Tools')
Expand All @@ -119,9 +120,44 @@ def CreateMenuBar(self):
self.Bind(wx.EVT_MENU, self.OnPaste, paste_item)
self.Bind(wx.EVT_MENU, self.OnRunPylint, pylint_item)
self.Bind(wx.EVT_MENU, self.OnFindReplace, find_replace_item)

self.Bind(wx.EVT_MENU, self.OnJumpToLine, jump_line_item)
extension_menubar.main()

def OnJumpToLine(self, event):
current_tab = self.notebook.GetCurrentPage()
if current_tab:
text_area = current_tab.GetChildren()[0]

# Create a dialog to get the line number
line_dialog = wx.TextEntryDialog(self, "Enter line number:", "Jump to Line")

if line_dialog.ShowModal() == wx.ID_OK:
try:
# Convert the input to an integer line number
line_number = int(line_dialog.GetValue()) - 1 # Adjust for 0-based indexing

# Get the position of the specified line
line_pos = text_area.PositionFromLine(line_number)

# Scroll to the line and set the cursor
text_area.GotoPos(line_pos)
text_area.SetFocus()

# Optional: Highlight the line
text_area.EnsureCaretVisible()
text_area.SetSelection(line_pos, text_area.GetLineEndPosition(line_number))

# Update status bar
self.SetStatusText(f"Jumped to line {line_number + 1}")

except ValueError:
# Handle invalid input
wx.MessageBox("Please enter a valid line number", "Error", wx.OK | wx.ICON_ERROR)
except Exception as e:
# Handle any other potential errors
wx.MessageBox(f"Error jumping to line: {str(e)}", "Error", wx.OK | wx.ICON_ERROR)

line_dialog.Destroy()

def run_tools_script(self, event):
try:
Expand Down

0 comments on commit a56ac3b

Please sign in to comment.