Skip to content

Commit 881d3cb

Browse files
committed
refactoring context
1 parent b10ea64 commit 881d3cb

File tree

9 files changed

+300
-151
lines changed

9 files changed

+300
-151
lines changed

Flitro/Assets.xcassets/AccentColor.colorset/Contents.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
-79 Bytes
Loading
-35 Bytes
Loading
-76 Bytes
Loading

Flitro/Editor/ContextDetailsView.swift

Lines changed: 248 additions & 122 deletions
Large diffs are not rendered by default.

Flitro/Editor/ContextEditorView.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,27 @@ struct ContextEditorView: View {
3434
showAddTerminalDialog: $showAddTerminalDialog
3535
)
3636
.onDrop(of: [UTType.fileURL, UTType.url, UTType.text, UTType.plainText], isTargeted: nil) { providers in
37-
return handleUniversalDrop(providers: providers)
37+
return UniversalDropHandler.handleUniversalDrop(providers: providers, contextManager: contextManager, selectedContextID: selectedContextID)
3838
}
3939
}
4040
.frame(minWidth: 900, minHeight: 600)
4141
.frame(maxWidth: .infinity, maxHeight: .infinity)
4242
}
43+
}
4344

44-
private func handleUniversalDrop(providers: [NSItemProvider]) -> Bool {
45-
guard let contextIndex = contextManager.contexts.firstIndex(where: { $0.id == selectedContextID }) else {
45+
struct UniversalDropHandler {
46+
static func handleUniversalDrop(providers: [NSItemProvider], contextManager: ContextManager, selectedContextID: UUID?) -> Bool {
47+
guard let contextIndex = contextManager.contexts.firstIndex(where: { $0.id == selectedContextID }) else {
4648
print("No selected context found for drop")
47-
return false
49+
return false
4850
}
49-
5051
guard !providers.isEmpty else {
5152
print("No providers in drop")
5253
return false
5354
}
54-
5555
var handled = false
56-
5756
for provider in providers {
5857
print("Processing provider with types: \(provider.registeredTypeIdentifiers)")
59-
6058
if provider.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier) || provider.hasItemConformingToTypeIdentifier("public.file-url") {
6159
let typeIdentifier = provider.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier) ? UTType.fileURL.identifier : "public.file-url"
6260
provider.loadItem(forTypeIdentifier: typeIdentifier, options: nil) { item, error in
@@ -65,28 +63,24 @@ struct ContextEditorView: View {
6563
return
6664
}
6765
print("Loaded item: \(String(describing: item))")
68-
6966
var url: URL?
7067
if let urlObject = item as? URL {
7168
url = urlObject
7269
} else if let data = item as? Data {
7370
url = URL(dataRepresentation: data, relativeTo: nil)
7471
print("Converted data to URL: \(String(describing: url))")
7572
}
76-
7773
if let url = url {
7874
print("Processing URL: \(url)")
7975
DispatchQueue.main.async {
8076
if url.pathExtension == "app" {
81-
// Add as application
8277
if let bundle = Bundle(url: url), let bundleId = bundle.bundleIdentifier {
8378
let appItem = AppItem(name: url.deletingPathExtension().lastPathComponent, bundleIdentifier: bundleId, windowTitle: nil)
8479
contextManager.contexts[contextIndex].items.append(.application(appItem))
8580
contextManager.saveContexts()
8681
print("Added application: \(appItem.name)")
8782
}
8883
} else if url.pathExtension == "sh" {
89-
// Add as terminal session (shell script)
9084
let session = TerminalSession(
9185
workingDirectory: url.deletingLastPathComponent().path,
9286
command: url.path,
@@ -95,8 +89,23 @@ struct ContextEditorView: View {
9589
contextManager.contexts[contextIndex].items.append(.terminalSession(session))
9690
contextManager.saveContexts()
9791
print("Added terminal session for script: \(session.title)")
92+
var bookmark: Data? = nil
93+
do {
94+
bookmark = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
95+
} catch {
96+
bookmark = nil
97+
}
98+
let document = DocumentItem(
99+
name: url.deletingPathExtension().lastPathComponent,
100+
filePath: url.path,
101+
application: "",
102+
bookmark: bookmark
103+
)
104+
contextManager.contexts[contextIndex].items.append(.document(document))
105+
contextManager.saveContexts()
106+
print("Added document: \(document.name)")
98107
} else {
99-
// Add as document
108+
// Fallback: add as document for any other file type
100109
var bookmark: Data? = nil
101110
do {
102111
bookmark = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
@@ -144,7 +153,6 @@ struct ContextEditorView: View {
144153
}
145154
}
146155
handled = true
147-
} else if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
148156
provider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { item, _ in
149157
if let data = item as? Data, let url = URL(dataRepresentation: data, relativeTo: nil) {
150158
let browserTab = BrowserTab(title: url.absoluteString, url: url.absoluteString, browser: "default")
@@ -161,11 +169,9 @@ struct ContextEditorView: View {
161169
}
162170
}
163171
handled = true
164-
} else if provider.hasItemConformingToTypeIdentifier(UTType.text.identifier) || provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
165172
let typeIdentifier = provider.hasItemConformingToTypeIdentifier(UTType.text.identifier) ? UTType.text.identifier : UTType.plainText.identifier
166173
provider.loadItem(forTypeIdentifier: typeIdentifier, options: nil) { item, _ in
167174
if let text = item as? String, !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
168-
// Try to parse as URL first
169175
if let url = URL(string: text.trimmingCharacters(in: .whitespacesAndNewlines)) {
170176
let browserTab = BrowserTab(title: url.absoluteString, url: url.absoluteString, browser: "default")
171177
DispatchQueue.main.async {
@@ -179,7 +185,6 @@ struct ContextEditorView: View {
179185
handled = true
180186
}
181187
}
182-
183188
print("Drop handling complete. Handled: \(handled)")
184189
return handled
185190
}

xdocs/icon/Flitro.svg

Lines changed: 11 additions & 0 deletions
Loading

xdocs/icon/Flitro@22.svg

Lines changed: 11 additions & 0 deletions
Loading

xdocs/icon/make-icon.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ sips -z 128 128 ../../../xdocs/icon/Flitro@1024.png --out icon_128x128.png
88
sips -z 256 256 ../../../xdocs/icon/Flitro@1024.png --out icon_256x256.png
99
sips -z 512 512 ../../../xdocs/icon/Flitro@1024.png --out icon_512x512.png
1010
cp ../../../xdocs/icon/Flitro@1024.png icon_1024x1024.png
11-
)
11+
)
12+
13+
(
14+
cd ../../Flitro/Assets.xcassets/MenuBarIcon.imageset
15+
sips -z 22 22 -s format png ../../../xdocs/icon/Flitro@22.svg --out icon_22x22.png
16+
sips -z 44 44 -s format png ../../../xdocs/icon/Flitro.svg --out icon_44x44.png
17+
sips -z 66 66 -s format png ../../../xdocs/icon/Flitro.svg --out icon_66x66.png
18+
)

0 commit comments

Comments
 (0)