Skip to content

Commit

Permalink
WIP: Enable case sensitive and add icons
Browse files Browse the repository at this point in the history
  • Loading branch information
MHendricks committed Mar 8, 2024
1 parent 626f277 commit ab9e7f1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
34 changes: 31 additions & 3 deletions preditor/gui/find_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from collections import deque

from Qt.QtCore import Qt
from Qt.QtGui import QIcon
from Qt.QtWidgets import QApplication, QShortcut, QWidget

from ..gui import loadUi
from .. import resourcePath
from . import loadUi


class FindFiles(QWidget):
Expand All @@ -18,19 +20,38 @@ def __init__(self, parent=None, managers=None, console=None):

loadUi(__file__, self)

# Set the icons
self.uiCaseSensitiveBTN.setIcon(
QIcon(resourcePath("img/format-letter-case.svg"))
)
self.uiCloseBTN.setIcon(QIcon(resourcePath('img/close-thick.png')))
self.uiRegexBTN.setIcon(QIcon(resourcePath("img/regex.svg")))

# Create shortcuts
self.uiCloseSCT = QShortcut(
Qt.Key_Escape, self, context=Qt.WidgetWithChildrenShortcut
)
self.uiCloseSCT.activated.connect(self.hide)

self.uiCaseSensitiveSCT = QShortcut(
Qt.AltModifier | Qt.Key_C, self, context=Qt.WidgetWithChildrenShortcut
)
self.uiCaseSensitiveSCT.activated.connect(self.uiCaseSensitiveBTN.toggle)

self.uiRegexSCT = QShortcut(
Qt.AltModifier | Qt.Key_R, self, context=Qt.WidgetWithChildrenShortcut
)
self.uiRegexSCT.activated.connect(self.uiRegexBTN.toggle)

def activate(self):
"""Called to make this widget ready for the user to interact with."""
self.show()
self.uiFindTXT.setFocus()

def find(self):
find_text = self.uiFindTXT.text()
self.insert_text("\nFind in workboxs: {}\n\n".format(find_text))
cs = " (case sensitive)" if self.uiCaseSensitiveBTN.isChecked() else ""
self.insert_text('\nFind in workboxs: "{}"{}\n\n'.format(find_text, cs))

for manager in self.managers:
for (
Expand Down Expand Up @@ -118,7 +139,14 @@ def search_file_simple(self, editor, path, workbox_id):
find_text = self.uiFindTXT.text()
# Ensure the editor text is loaded
editor.__show__()
raw_lines = editor.__text__().splitlines()

raw_text = editor.__text__()
# Handle case-insensitive searching
if not self.uiCaseSensitiveBTN.isChecked():
find_text = find_text.lower()
raw_lines = raw_text.lower()

raw_lines = raw_text.splitlines()
# Add enough padding to cover the number of lines in the file
padding = len(str(len(raw_lines)))
fmt = " {{num: >{}}}{{split}} {{line}}".format(padding)
Expand Down
15 changes: 12 additions & 3 deletions preditor/gui/ui/find_files.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,37 @@
<layout class="QHBoxLayout" name="uiFindOptionsLYT">
<item>
<widget class="QToolButton" name="uiRegexBTN">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Regex</string>
<string>Regex (Alt + R)</string>
</property>
<property name="text">
<string>Regex</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="uiCaseSensitiveBTN">
<property name="toolTip">
<string>Case Sensitive</string>
<string>Case Sensitive (Alt + C)</string>
</property>
<property name="text">
<string>Case Sensitive</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="uiContextSPN">
<property name="toolTip">
<string>Context Lines</string>
<string># of lines of context to show</string>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
Expand Down
2 changes: 1 addition & 1 deletion preditor/gui/ui/loggerwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
</widget>
<widget class="QMenu" name="menu_Run">
<property name="title">
<string>&amp;Run</string>
<string>Run</string>
</property>
<addaction name="uiRunSelectedACT"/>
<addaction name="uiRunAllACT"/>
Expand Down
10 changes: 10 additions & 0 deletions preditor/resource/img/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
Converted to multi-resolution icon using: https://convertico.com/svg-to-ico/

Most other icons downloaded from https://materialdesignicons.com/.

Svg icons are preferred as they are plain text files that play nicely with git.
Please make sure to update the sources table when adding or updating images.

# Sources for resources

| File | Source | Notes | Author |
|---|---|---|---|
| ![](preditor/resource/img/format-letter-case.svg) [content-save.svg](preditor/resource/img/format-letter-case.svg) | https://pictogrammers.com/library/mdi/icon/format-letter-case/ | | [Austin Andrews](https://pictogrammers.com/contributor/Templarian/) |
| ![](preditor/resource/img/regex.svg) [content-save.svg](preditor/resource/img/regex.svg) | https://pictogrammers.com/library/mdi/icon/regex/ | | [Doug C. Hardester](https://pictogrammers.com/contributor/r3volution11/) |
1 change: 1 addition & 0 deletions preditor/resource/img/format-letter-case.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions preditor/resource/img/regex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab9e7f1

Please sign in to comment.