diff --git a/gui/builtinMarketBrowser/pfSearchBox.py b/gui/builtinMarketBrowser/pfSearchBox.py index 8d0871f6a..38706a34d 100644 --- a/gui/builtinMarketBrowser/pfSearchBox.py +++ b/gui/builtinMarketBrowser/pfSearchBox.py @@ -2,6 +2,7 @@ import wx import gui.utils.color as colorUtils import gui.utils.draw as drawUtils +from gui.utils.helpers_wxPython import HandleCtrlBackspace SearchButton, EVT_SEARCH_BTN = wx.lib.newevent.NewEvent() CancelButton, EVT_CANCEL_BTN = wx.lib.newevent.NewEvent() @@ -55,7 +56,7 @@ class PFSearchBox(wx.Window): self.EditBox.Bind(wx.EVT_SET_FOCUS, self.OnEditSetFocus) self.EditBox.Bind(wx.EVT_KILL_FOCUS, self.OnEditKillFocus) - + self.EditBox.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress) self.EditBox.Bind(wx.EVT_TEXT, self.OnText) self.EditBox.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter) @@ -83,6 +84,12 @@ class PFSearchBox(wx.Window): self.Clear() event.Skip() + def OnKeyPress(self, event): + if event.RawControlDown() and event.GetKeyCode() == wx.WXK_BACK: + HandleCtrlBackspace(self.EditBox) + else: + event.Skip() + def Clear(self): self.EditBox.Clear() # self.EditBox.ChangeValue(self.descriptiveText) diff --git a/gui/builtinShipBrowser/navigationPanel.py b/gui/builtinShipBrowser/navigationPanel.py index 204802c45..e7f339260 100644 --- a/gui/builtinShipBrowser/navigationPanel.py +++ b/gui/builtinShipBrowser/navigationPanel.py @@ -11,6 +11,7 @@ import gui.utils.fonts as fonts from .events import FitSelected, SearchSelected, ImportSelected, Stage1Selected, Stage2Selected, Stage3Selected from gui.bitmap_loader import BitmapLoader from service.fit import Fit +from gui.utils.helpers_wxPython import HandleCtrlBackspace pyfalog = Logger(__name__) @@ -72,7 +73,7 @@ class NavigationPanel(SFItem.SFBrowserItem): # self.BrowserSearchBox.Bind(wx.EVT_TEXT_ENTER, self.OnBrowserSearchBoxEnter) # self.BrowserSearchBox.Bind(wx.EVT_KILL_FOCUS, self.OnBrowserSearchBoxLostFocus) - self.BrowserSearchBox.Bind(wx.EVT_KEY_DOWN, self.OnBrowserSearchBoxEsc) + self.BrowserSearchBox.Bind(wx.EVT_KEY_DOWN, self.OnBrowserSearchBoxKeyPress) self.BrowserSearchBox.Bind(wx.EVT_TEXT, self.OnScheduleSearch) self.SetMinSize(size) @@ -103,9 +104,11 @@ class NavigationPanel(SFItem.SFBrowserItem): def OnBrowserSearchBoxLostFocus(self, event): self.BrowserSearchBox.Show(False) - def OnBrowserSearchBoxEsc(self, event): + def OnBrowserSearchBoxKeyPress(self, event): if event.GetKeyCode() == wx.WXK_ESCAPE: self.BrowserSearchBox.Show(False) + elif event.RawControlDown() and event.GetKeyCode() == wx.WXK_BACK: + HandleCtrlBackspace(self.BrowserSearchBox) else: event.Skip() diff --git a/gui/utils/helpers_wxPython.py b/gui/utils/helpers_wxPython.py index e0f9d0ae0..26f98c35d 100644 --- a/gui/utils/helpers_wxPython.py +++ b/gui/utils/helpers_wxPython.py @@ -6,3 +6,23 @@ def YesNoDialog(question='Are you sure you want to do this?', caption='Yes or no result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() return result + + +def HandleCtrlBackspace(textControl): + """ + Handles the behavior of Windows ctrl+space + deletes everything from the cursor to the left, + up to the next whitespace. + """ + curPos = textControl.GetInsertionPoint() + searchText = textControl.GetValue() + foundChar = False + for startIndex in range(curPos, -1, -1): + if startIndex - 1 < 0: + break + if searchText[startIndex - 1] != " ": + foundChar = True + elif foundChar: + break + textControl.Remove(startIndex, curPos) + textControl.SetInsertionPoint(startIndex) \ No newline at end of file