Skip to content

Commit

Permalink
Restore drag and drop feature
Browse files Browse the repository at this point in the history
  • Loading branch information
banagale committed Aug 20, 2024
1 parent 4ca190d commit 85529f3
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions filekitty/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ast
import os

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QGuiApplication, QKeySequence
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QIcon, QGuiApplication, QKeySequence, QDragEnterEvent, QDropEvent
from PyQt5.QtWidgets import (
QApplication, QWidget, QFileDialog, QVBoxLayout, QPushButton, QTextEdit,
QLabel, QListWidget, QDialog, QAction, QMenuBar
QLabel, QListWidget, QDialog, QAction, QMenuBar, QGraphicsColorizeEffect
)
from PyQt5.QtWidgets import (
QListWidgetItem
Expand Down Expand Up @@ -82,6 +82,7 @@ def __init__(self):
self.setWindowTitle('FileKitty')
self.setWindowIcon(QIcon(ICON_PATH))
self.setGeometry(100, 100, 800, 600)
self.setAcceptDrops(True) # Enable drag-and-drop functionality
self.selected_items = [] # Track selected items
self.currentFiles = [] # Track current files
self.initUI()
Expand Down Expand Up @@ -224,6 +225,41 @@ def detect_language(self, file_path):
else:
return 'plaintext'

def dragEnterEvent(self, event: QDragEnterEvent):
if event.mimeData().hasUrls():
event.acceptProposedAction()
else:
event.ignore()

def dropEvent(self, event: QDropEvent):
if event.mimeData().hasUrls():
files = []
for url in event.mimeData().urls():
if url.isLocalFile():
files.append(url.toLocalFile())
if files:
self.fileList.clear()
self.currentFiles = files
self.updateTextEdit()
self.btnSelectClassesFunctions.setEnabled(True)
self.animateDropSuccess()
event.acceptProposedAction()
else:
event.ignore()

def applyBrightnessEffect(self):
self.effect = QGraphicsColorizeEffect(self)
self.effect.setColor(Qt.darkBlue)
self.effect.setStrength(0.25)
self.setGraphicsEffect(self.effect)

def removeBrightnessEffect(self):
self.setGraphicsEffect(None)

def animateDropSuccess(self):
self.applyBrightnessEffect()
QTimer.singleShot(100, self.removeBrightnessEffect)


def parse_python_file(file_path):
try:
Expand All @@ -248,6 +284,7 @@ def parse_python_file(file_path):

return classes, functions, imports, file_content


def sanitize_path(file_path):
"""Remove sensitive directory information from file paths."""
parts = file_path.split(os.sep)
Expand All @@ -258,6 +295,7 @@ def sanitize_path(file_path):
return os.sep.join(sanitized_parts)
return file_path


def extract_code_and_imports(file_content, selected_items, sanitized_path):
tree = ast.parse(file_content)
selected_code = []
Expand Down

0 comments on commit 85529f3

Please sign in to comment.