-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivParser5.py
More file actions
1148 lines (967 loc) · 47.4 KB
/
Copy pathdivParser5.py
File metadata and controls
1148 lines (967 loc) · 47.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import os
from pathlib import Path
import threading
class ModernDirectoryParser:
def __init__(self):
self.root = tk.Tk()
self.root.title("Directory Parser Pro")
self.root.geometry("1600x1000")
self.root.configure(bg="#f5f5f7")
# Data storage
self.selected_folder_path = None
self.file_content_map = {}
self.item_states = {}
self.item_paths = {}
self.total_files = 0
# Configure styles
self.setup_styles()
# Create GUI
self.create_widgets()
def setup_styles(self):
style = ttk.Style()
# Dark mode color palette
self.colors = {
'bg_primary': '#181a1b',
'bg_secondary': '#23272a',
'bg_tertiary': '#2c2f33',
'text_primary': '#f5f6fa',
'text_secondary': '#b9bbbe',
'accent_blue': '#4f8cff',
'accent_blue_hover': '#2563eb',
'accent_green': '#43d17a',
'accent_green_hover': '#2fa866',
'border_light': '#36393f',
'shadow': '#23272a',
'selection': '#304ffe'
}
# Configure theme
style.theme_use("clam")
# Modern button styles with fallback fonts
style.configure("Modern.TButton",
background=self.colors['accent_blue'],
foreground="white",
borderwidth=0,
relief="flat",
padding=(20, 12),
font=("Segoe UI", 12, "normal"))
style.map("Modern.TButton",
background=[("active", self.colors['accent_blue_hover']),
("pressed", "#1e40af")])
style.configure("Success.TButton",
background=self.colors['accent_green'],
foreground="white",
borderwidth=0,
relief="flat",
padding=(20, 12),
font=("Segoe UI", 12, "normal"))
style.map("Success.TButton",
background=[("active", self.colors['accent_green_hover']),
("pressed", "#17643a")])
style.configure("Secondary.TButton",
background=self.colors['bg_tertiary'],
foreground=self.colors['text_primary'],
borderwidth=1,
relief="solid",
padding=(16, 10),
font=("Segoe UI", 11, "normal"))
style.map("Secondary.TButton",
background=[("active", self.colors['border_light']),
("pressed", "#23272a")])
# Treeview style with system fonts
style.configure("Modern.Treeview",
background=self.colors['bg_secondary'],
foreground=self.colors['text_primary'],
fieldbackground=self.colors['bg_secondary'],
borderwidth=0,
relief="flat",
rowheight=32,
font=("Segoe UI", 11, "normal"))
style.configure("Modern.Treeview.Heading",
background=self.colors['bg_tertiary'],
foreground=self.colors['text_primary'],
relief="flat",
borderwidth=0,
font=("Segoe UI", 12, "bold"))
style.map("Modern.Treeview",
background=[("selected", self.colors['selection'])],
foreground=[("selected", self.colors['text_primary'])])
# Frame styles
style.configure("Card.TFrame",
background=self.colors['bg_secondary'],
relief="flat",
borderwidth=0)
def create_widgets(self):
# Main container with padding
main_frame = tk.Frame(self.root, bg=self.colors['bg_primary'])
main_frame.pack(fill=tk.BOTH, expand=True, padx=24, pady=24)
# Header section
self.create_header(main_frame)
# Content area with card design
content_container = tk.Frame(main_frame, bg=self.colors['bg_primary'])
content_container.pack(fill=tk.BOTH, expand=True, pady=(24, 0))
# Create main content card
content_card = tk.Frame(content_container,
bg=self.colors['bg_secondary'],
relief="solid",
bd=1,
highlightbackground=self.colors['border_light'],
highlightthickness=1)
content_card.pack(fill=tk.BOTH, expand=True)
# Create paned window
self.paned_window = ttk.PanedWindow(content_card, orient=tk.HORIZONTAL)
self.paned_window.pack(fill=tk.BOTH, expand=True, padx=0, pady=0)
# Left and right panels
self.create_tree_panel()
self.create_output_panel()
# Status bar
self.create_status_bar(main_frame)
def create_header(self, parent):
header_frame = tk.Frame(parent, bg=self.colors['bg_primary'])
header_frame.pack(fill=tk.X, pady=(0, 16))
# Title section
title_section = tk.Frame(header_frame, bg=self.colors['bg_primary'])
title_section.pack(fill=tk.X)
# Main title with system fonts
title_label = tk.Label(title_section,
text="Directory Parser Pro",
font=("Segoe UI", 28, "bold"),
bg=self.colors['bg_primary'],
fg=self.colors['text_primary'])
title_label.pack(anchor="w")
# Subtitle
subtitle_label = tk.Label(title_section,
text="Parse and combine text files from any directory",
font=("Segoe UI", 14, "normal"),
bg=self.colors['bg_primary'],
fg=self.colors['text_secondary'])
subtitle_label.pack(anchor="w", pady=(4, 16))
# Controls section
controls_frame = tk.Frame(header_frame, bg=self.colors['bg_primary'])
controls_frame.pack(fill=tk.X)
# Button container
button_container = tk.Frame(controls_frame, bg=self.colors['bg_primary'])
button_container.pack(side=tk.LEFT)
# Primary buttons
self.select_btn = ttk.Button(button_container,
text="📁 Select Folder",
style="Modern.TButton",
command=self.select_folder)
self.select_btn.pack(side=tk.LEFT, padx=(0, 12))
self.parse_btn = ttk.Button(button_container,
text="⚡ Parse Directory",
style="Success.TButton",
command=self.start_parsing_thread,
state=tk.DISABLED)
self.parse_btn.pack(side=tk.LEFT, padx=(0, 24))
# Secondary buttons
self.copy_btn = ttk.Button(button_container,
text="📋 Copy",
style="Secondary.TButton",
command=self.copy_content,
state=tk.DISABLED)
self.copy_btn.pack(side=tk.LEFT, padx=(0, 12))
self.download_btn = ttk.Button(button_container,
text="💾 Download",
style="Secondary.TButton",
command=self.download_content,
state=tk.DISABLED)
self.download_btn.pack(side=tk.LEFT)
# Folder path display
path_container = tk.Frame(controls_frame, bg=self.colors['bg_primary'])
path_container.pack(side=tk.RIGHT, fill=tk.X, expand=True, padx=(24, 0))
self.folder_label = tk.Label(path_container,
text="No folder selected",
font=("Segoe UI", 12, "normal"),
bg=self.colors['bg_primary'],
fg=self.colors['text_secondary'],
anchor="e")
self.folder_label.pack(side=tk.RIGHT)
def create_tree_panel(self):
# Left panel container
left_container = tk.Frame(self.paned_window, bg=self.colors['bg_secondary'])
left_container.pack(fill=tk.BOTH, expand=True)
# Panel header
header_frame = tk.Frame(left_container, bg=self.colors['bg_secondary'])
header_frame.pack(fill=tk.X, padx=20, pady=(20, 16))
# Title with system fonts
title_label = tk.Label(header_frame,
text="Directory Structure",
font=("Segoe UI", 16, "bold"),
bg=self.colors['bg_secondary'],
fg=self.colors['text_primary'])
title_label.pack(side=tk.LEFT)
# Selection controls
controls_frame = tk.Frame(header_frame, bg=self.colors['bg_secondary'])
controls_frame.pack(side=tk.RIGHT)
select_all_btn = tk.Button(controls_frame,
text="Select All",
font=("Segoe UI", 10, "normal"),
bg=self.colors['accent_blue'],
fg="white",
relief="flat",
bd=0,
padx=16, pady=8,
cursor="hand2",
command=self.select_all)
select_all_btn.pack(side=tk.LEFT, padx=(0, 8))
deselect_all_btn = tk.Button(controls_frame,
text="Deselect All",
font=("Segoe UI", 10, "normal"),
bg=self.colors['bg_tertiary'],
fg=self.colors['text_primary'],
relief="flat",
bd=0,
padx=16, pady=8,
cursor="hand2",
command=self.deselect_all)
deselect_all_btn.pack(side=tk.LEFT)
# Tree container with rounded corners effect
tree_container = tk.Frame(left_container,
bg=self.colors['border_light'],
relief="flat", bd=1)
tree_container.pack(fill=tk.BOTH, expand=True, padx=20, pady=(0, 20))
# Tree widget
self.tree = ttk.Treeview(tree_container,
style="Modern.Treeview",
columns=("selection",),
show="tree",
selectmode="none")
# Configure columns
self.tree.column("#0", width=400, minwidth=200)
self.tree.column("selection", width=50, minwidth=50, anchor="center")
# Scrollbars
v_scrollbar = ttk.Scrollbar(tree_container, orient="vertical", command=self.tree.yview)
h_scrollbar = ttk.Scrollbar(tree_container, orient="horizontal", command=self.tree.xview)
self.tree.configure(yscrollcommand=v_scrollbar.set, xscrollcommand=h_scrollbar.set)
# Pack tree and scrollbars
self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=1, pady=1)
v_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Bind events
self.tree.bind("<Button-1>", self.on_tree_click)
self.paned_window.add(left_container, weight=2)
def create_output_panel(self):
# Right panel container
right_container = tk.Frame(self.paned_window, bg=self.colors['bg_secondary'])
right_container.pack(fill=tk.BOTH, expand=True)
# Panel header
header_frame = tk.Frame(right_container, bg=self.colors['bg_secondary'])
header_frame.pack(fill=tk.X, padx=20, pady=(20, 16))
title_label = tk.Label(header_frame,
text="Combined Content",
font=("Segoe UI", 16, "bold"),
bg=self.colors['bg_secondary'],
fg=self.colors['text_primary'])
title_label.pack(side=tk.LEFT)
# Content counter
self.content_counter = tk.Label(header_frame,
text="",
font=("Segoe UI", 11, "normal"),
bg=self.colors['bg_secondary'],
fg=self.colors['text_secondary'])
self.content_counter.pack(side=tk.RIGHT)
# Text container
text_container = tk.Frame(right_container,
bg=self.colors['border_light'],
relief="flat", bd=1)
text_container.pack(fill=tk.BOTH, expand=True, padx=20, pady=(0, 20))
# Text area with system monospace font
self.text_area = tk.Text(text_container,
bg=self.colors['bg_tertiary'],
fg=self.colors['text_primary'],
font=("Consolas", 11, "normal"),
wrap=tk.WORD,
relief="flat",
bd=0,
padx=20,
pady=20,
insertbackground=self.colors['accent_blue'],
selectbackground=self.colors['selection'],
spacing1=2,
spacing3=2)
# Scrollbars
text_v_scrollbar = ttk.Scrollbar(text_container, orient="vertical", command=self.text_area.yview)
text_h_scrollbar = ttk.Scrollbar(text_container, orient="horizontal", command=self.text_area.xview)
self.text_area.configure(yscrollcommand=text_v_scrollbar.set, xscrollcommand=text_h_scrollbar.set)
# Pack text area and scrollbars
self.text_area.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=1, pady=1)
text_v_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Initial message
welcome_text = """🚀 Welcome to Directory Parser Pro!
Follow these simple steps:
1. Click "Select Folder" to choose your directory
2. Click "Parse Directory" to scan for text files
3. Select the files you want to combine
4. Copy or download the combined content
Ready to get started?"""
self.text_area.insert(1.0, welcome_text)
self.text_area.config(state=tk.DISABLED)
self.paned_window.add(right_container, weight=3)
def create_status_bar(self, parent):
# Status container with modern card design
status_container = tk.Frame(parent, bg=self.colors['bg_primary'])
status_container.pack(fill=tk.X, pady=(16, 0))
status_card = tk.Frame(status_container,
bg=self.colors['bg_secondary'],
relief="flat", bd=0)
status_card.pack(fill=tk.X)
# Status content
status_frame = tk.Frame(status_card, bg=self.colors['bg_secondary'])
status_frame.pack(fill=tk.X, padx=20, pady=12)
# Status items
status_items = [
("📁", "files", "0"),
("✅", "selected", "0"),
("📄", "lines", "0"),
("🔤", "characters", "0"),
("💾", "size", "0 KB")
]
self.status_labels = {}
for i, (icon, key, default_value) in enumerate(status_items):
item_frame = tk.Frame(status_frame, bg=self.colors['bg_secondary'])
item_frame.pack(side=tk.LEFT, padx=(0, 32) if i < len(status_items) - 1 else (0, 0))
icon_label = tk.Label(item_frame,
text=icon,
font=("Segoe UI", 14),
bg=self.colors['bg_secondary'])
icon_label.pack(side=tk.LEFT, padx=(0, 8))
# Remove unsupported 'medium' style, use normal weight
text_label = tk.Label(item_frame,
text=f"{key.title()}: {default_value}",
font=("Segoe UI", 13, "normal"),
bg=self.colors['bg_secondary'],
fg=self.colors['text_primary'])
text_label.pack(side=tk.LEFT)
self.status_labels[key] = text_label
def get_comprehensive_text_extensions(self):
"""Returns a comprehensive set of text file extensions"""
return {
# Programming languages
'.py', '.pyw', '.pyi', '.pyx', # Python
'.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', # JavaScript/TypeScript
'.java', '.class', '.jar', # Java
'.c', '.h', '.cpp', '.hpp', '.cc', '.cxx', '.c++', # C/C++
'.cs', '.vb', '.fs', '.fsx', # .NET languages
'.php', '.php3', '.php4', '.php5', '.phtml', # PHP
'.rb', '.rbw', '.rake', '.gemspec', # Ruby
'.go', '.mod', '.sum', # Go
'.rs', '.toml', # Rust
'.swift', # Swift
'.kt', '.kts', # Kotlin
'.scala', '.sc', # Scala
'.clj', '.cljs', '.cljc', '.edn', # Clojure
'.hs', '.lhs', # Haskell
'.ml', '.mli', '.ocaml', # OCaml
'.elm', # Elm
'.dart', # Dart
'.lua', # Lua
'.pl', '.pm', '.t', '.pod', # Perl
'.r', '.R', '.rmd', '.rnw', # R
'.m', '.mm', # Objective-C
'.pas', '.pp', '.inc', # Pascal
'.asm', '.s', # Assembly
'.f', '.f90', '.f95', '.f03', '.f08', # Fortran
'.cobol', '.cob', '.cbl', # COBOL
'.ada', '.adb', '.ads', # Ada
'.d', # D
'.nim', # Nim
'.cr', # Crystal
'.ex', '.exs', # Elixir
'.erl', '.hrl', # Erlang
'.jl', # Julia
'.v', '.sv', '.vh', '.svh', # Verilog/SystemVerilog
'.vhd', '.vhdl', # VHDL
# Web technologies
'.html', '.htm', '.xhtml', '.shtml', # HTML
'.css', '.scss', '.sass', '.less', '.styl', # CSS/Preprocessors
'.xml', '.xsl', '.xslt', '.xsd', '.dtd', # XML
'.svg', # SVG
'.rss', '.atom', # Feed formats
'.asp', '.aspx', '.ascx', '.ashx', '.asmx', # ASP.NET
'.jsp', '.jspx', # JSP
'.erb', '.haml', '.slim', # Ruby templates
'.twig', '.blade', # PHP templates
'.vue', '.svelte', # Frontend frameworks
# Data formats
'.json', '.jsonl', '.geojson', # JSON
'.yaml', '.yml', # YAML
'.csv', '.tsv', '.dsv', # Delimited files
'.xml', '.rdf', '.owl', # XML/RDF
'.sql', '.ddl', '.dml', # SQL
'.graphql', '.gql', # GraphQL
'.proto', # Protocol Buffers
'.avro', # Avro
'.parquet', # Parquet (metadata)
'.ini', '.cfg', '.conf', '.config', # Configuration
'.properties', '.prop', # Properties files
'.env', '.envrc', # Environment
'.editorconfig', # Editor config
# Documentation
'.md', '.markdown', '.mdown', '.mkd', '.mkdn', # Markdown
'.rst', '.rest', # reStructuredText
'.txt', '.text', # Plain text
'.rtf', # Rich Text Format
'.tex', '.latex', '.cls', '.sty', # LaTeX
'.org', # Org mode
'.adoc', '.asciidoc', # AsciiDoc
'.wiki', '.mediawiki', # Wiki formats
'.pod', # Perl documentation
'.man', '.1', '.2', '.3', '.4', '.5', '.6', '.7', '.8', # Man pages
# Shell and scripts
'.sh', '.bash', '.zsh', '.fish', '.csh', '.tcsh', '.ksh', # Shell scripts
'.bat', '.cmd', '.ps1', '.psm1', '.psd1', # Windows scripts
'.applescript', '.scpt', # AppleScript
'.vbs', '.vb', # VBScript
'.awk', '.sed', # Text processing
# Build and project files
'.makefile', '.mk', '.mak', # Make
'.cmake', '.cmakelists', # CMake
'.gradle', '.gradlew', # Gradle
'.ant', '.build', # Ant
'.sbt', # SBT
'.bazel', '.bzl', # Bazel
'.ninja', # Ninja
'.dockerfile', '.containerfile', # Docker
'.docker-compose', '.compose', # Docker Compose
'.vagrant', '.vagrantfile', # Vagrant
'.tf', '.tfvars', '.hcl', # Terraform
'.ansible', '.playbook', # Ansible
'.k8s', '.kube', '.kubernetes', # Kubernetes
# Version control
'.gitignore', '.gitattributes', '.gitmodules', '.gitkeep', # Git
'.hgignore', '.hgrc', # Mercurial
'.svnignore', # Subversion
# IDE and editor files
'.vscode', '.sublime-project', '.sublime-workspace', # Editors
'.idea', '.iml', '.ipr', '.iws', # IntelliJ
'.project', '.classpath', '.settings', # Eclipse
'.code-workspace', # VS Code
# Package managers
'.package', '.packages', # General
'.requirements', '.pip', # Python pip
'.pipfile', '.pipfile.lock', # Pipenv
'.poetry', '.pyproject', # Poetry
'.conda', '.environment', # Conda
'.gemfile', '.gemfile.lock', # Ruby Gems
'.package.json', '.package-lock.json', '.yarn.lock', # npm/Yarn
'.composer.json', '.composer.lock', # Composer
'.cargo.toml', '.cargo.lock', # Cargo
'.go.mod', '.go.sum', # Go modules
'.pom.xml', '.gradle', # Java
'.nuget', '.csproj', '.sln', # .NET
# Log and temporary files
'.log', '.logs', # Logs
'.tmp', '.temp', '.cache', # Temporary
'.backup', '.bak', '.old', # Backups
'.orig', '.rej', # Patches
# Specialized formats
'.ics', '.ical', '.vcf', # Calendar/Contacts
'.opml', # OPML
'.rss', '.atom', # Feeds
'.sitemap', # Sitemaps
'.robots', # Robots.txt
'.htaccess', '.htpasswd', # Apache
'.nginx', '.conf', # Nginx
'.caddy', '.caddyfile', # Caddy
'.licensefile', '.license', '.copying', # Licenses
'.readme', '.changelog', '.history', '.news', # Documentation
'.authors', '.contributors', '.maintainers', # Project info
'.security', '.codeowners', # GitHub files
'.workflows', '.github', # GitHub Actions
'.travis', '.circle', '.appveyor', # CI/CD
'.jenkins', '.jenkinsfile', # Jenkins
# Database
'.sql', '.mysql', '.postgresql', '.sqlite', '.db', # SQL databases
'.cql', # Cassandra
'.cypher', # Neo4j
'.sparql', # SPARQL
'.n3', '.ttl', '.nt', # RDF/Turtle
# Scientific and data
'.ipynb', # Jupyter notebooks (JSON-based)
'.bib', '.bibtex', # Bibliography
'.cff', # Citation File Format
'.cwl', # Common Workflow Language
'.wdl', # Workflow Description Language
'.nextflow', '.nf', # Nextflow
'.snakemake', # Snakemake
'.galaxy', # Galaxy
# Game development
'.unity', '.scene', '.prefab', # Unity
'.godot', '.tscn', '.tres', # Godot
'.ue4', '.uproject', '.uplugin', # Unreal Engine
# Mobile development
'.xcodeproj', '.pbxproj', # Xcode
'.storyboard', '.xib', # iOS Interface Builder
'.manifest', '.gradle', # Android
'.flutter', '.pubspec', # Flutter
'.ionic', # Ionic
'.cordova', '.phonegap', # Cordova/PhoneGap
# Blockchain
'.sol', # Solidity
'.vy', # Vyper
'.move', # Move
'.cairo', # Cairo
# No extension files (common)
'makefile', 'dockerfile', 'vagrantfile', 'gemfile', 'rakefile',
'procfile', 'requirements', 'pipfile', 'readme', 'license',
'changelog', 'authors', 'contributors', 'copying', 'install',
'news', 'todo', 'hacking', 'bugs', 'thanks', 'acknowledgments'
}
def is_text_file(self, file_path):
"""Enhanced text file detection with comprehensive extension list"""
text_extensions = self.get_comprehensive_text_extensions()
filename = file_path.name.lower()
file_extension = file_path.suffix.lower()
# Check by extension
if file_extension in text_extensions:
return True
# Check by filename (no extension files)
if filename in text_extensions:
return True
# Additional checks for files without extensions
no_extension_patterns = {
'makefile', 'dockerfile', 'vagrantfile', 'gemfile', 'rakefile',
'procfile', 'requirements', 'pipfile', 'readme', 'license',
'changelog', 'authors', 'contributors', 'copying', 'install',
'news', 'todo', 'hacking', 'bugs', 'thanks', 'acknowledgments',
'gitignore', 'gitattributes', 'gitmodules', 'gitkeep',
'editorconfig', 'eslintrc', 'prettierrc', 'babelrc',
'npmrc', 'yarnrc', 'nvmrc', 'node-version', 'python-version'
}
# Check if filename matches any pattern
for pattern in no_extension_patterns:
if pattern in filename:
return True
# Check for hidden config files
if filename.startswith('.') and len(filename) > 1:
base_name = filename[1:] # Remove the dot
if any(base_name.endswith(ext) for ext in ['.json', '.yaml', '.yml', '.toml', '.ini', '.cfg', '.conf']):
return True
return False
def select_folder(self):
folder_path = filedialog.askdirectory(title="Select Directory to Parse")
if folder_path:
self.selected_folder_path = Path(folder_path)
# Update UI
display_path = str(self.selected_folder_path)
if len(display_path) > 80:
display_path = "..." + display_path[-77:]
self.folder_label.config(text=display_path, fg=self.colors['text_primary'])
# Enable parse button
self.parse_btn.config(state=tk.NORMAL)
# Clear previous results
self.clear_results()
def clear_results(self):
# Clear tree
for item in self.tree.get_children():
self.tree.delete(item)
# Clear data
self.item_states.clear()
self.item_paths.clear()
self.file_content_map.clear()
self.total_files = 0
# Reset text area
self.text_area.config(state=tk.NORMAL)
self.text_area.delete(1.0, tk.END)
self.text_area.insert(1.0, "Ready to parse directory structure...")
self.text_area.config(state=tk.DISABLED)
# Reset status
self.update_status_bar()
# Disable action buttons
self.copy_btn.config(state=tk.DISABLED)
self.download_btn.config(state=tk.DISABLED)
def start_parsing_thread(self):
if not self.selected_folder_path:
return
# Update UI for parsing state
self.parse_btn.config(state=tk.DISABLED, text="⏳ Parsing...")
self.select_btn.config(state=tk.DISABLED)
# Update text area
self.text_area.config(state=tk.NORMAL)
self.text_area.delete(1.0, tk.END)
self.text_area.insert(1.0, "🔍 Scanning directory structure...\n\nPlease wait while we discover all text files...")
self.text_area.config(state=tk.DISABLED)
# Start parsing in background
threading.Thread(target=self.parse_directory, daemon=True).start()
def parse_directory(self):
try:
self.total_files = 0
# Create root item
root_item = self.tree.insert("", "end",
text=f"📁 {self.selected_folder_path.name}",
values=("☐",),
open=True,
tags=("folder",))
self.item_states[root_item] = False
self.item_paths[root_item] = ""
# Build directory tree
self.add_directory_contents(self.selected_folder_path, root_item)
# Complete parsing on main thread
self.root.after(0, self.parsing_complete)
except Exception as e:
self.root.after(0, lambda: self.show_error(f"Error parsing directory: {str(e)}"))
def add_directory_contents(self, directory_path, parent_item, max_depth=25, current_depth=0):
if current_depth >= max_depth:
return
try:
items = []
# Collect all valid items
for item_path in directory_path.iterdir():
# Skip hidden files and directories
if item_path.name.startswith('.') and item_path.name not in {'.env', '.gitignore', '.htaccess', '.editorconfig'}:
continue
if item_path.is_dir():
# Skip common directories to ignore
skip_dirs = {
'node_modules', '__pycache__', '.git', '.svn', '.hg',
'.vscode', '.idea', '.vs', 'venv', '.env', 'env',
'build', 'dist', 'target', 'bin', 'obj', '.next',
'.nuxt', 'coverage', '.coverage', '.pytest_cache',
'.mypy_cache', '.tox', '.eggs', '*.egg-info',
'.DS_Store', 'Thumbs.db', '.sass-cache', '.cache'
}
if item_path.name in skip_dirs:
continue
items.append((item_path, "folder"))
elif item_path.is_file() and self.is_text_file(item_path):
items.append((item_path, "file"))
# Sort items: folders first, then files, alphabetically
items.sort(key=lambda x: (x[1] == "file", x[0].name.lower()))
# Add items to tree
for item_path, item_type in items:
relative_path = str(item_path.relative_to(self.selected_folder_path))
if item_type == "folder":
tree_item = self.tree.insert(parent_item, "end",
text=f"📁 {item_path.name}",
values=("☐",),
open=False,
tags=("folder",))
self.item_states[tree_item] = False
self.item_paths[tree_item] = relative_path
# Recursively add subdirectory contents
self.add_directory_contents(item_path, tree_item, max_depth, current_depth + 1)
else: # file
# Choose appropriate icon based on file type
icon = self.get_file_icon(item_path)
tree_item = self.tree.insert(parent_item, "end",
text=f"{icon} {item_path.name}",
values=("☐",),
tags=("file",))
self.item_states[tree_item] = False
self.item_paths[tree_item] = relative_path
self.total_files += 1
# Load file content
self.load_file_content(item_path, relative_path)
except PermissionError:
# Skip directories we can't access
pass
except Exception as e:
print(f"Error processing directory {directory_path}: {e}")
def get_file_icon(self, file_path):
"""Return appropriate emoji icon for file type"""
extension = file_path.suffix.lower()
filename = file_path.name.lower()
# Programming languages
if extension in ['.py', '.pyw', '.pyi']:
return '🐍'
elif extension in ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs']:
return '🟨'
elif extension in ['.html', '.htm', '.xhtml']:
return '🌐'
elif extension in ['.css', '.scss', '.sass', '.less']:
return '🎨'
elif extension in ['.json', '.jsonl']:
return '📋'
elif extension in ['.xml', '.xsl', '.xslt']:
return '📄'
elif extension in ['.md', '.markdown', '.mdown']:
return '📖'
elif extension in ['.yaml', '.yml']:
return '⚙️'
elif extension in ['.sql', '.ddl', '.dml']:
return '🗄️'
elif extension in ['.sh', '.bash', '.zsh', '.fish']:
return '🐚'
elif extension in ['.java', '.class']:
return '☕'
elif extension in ['.c', '.h', '.cpp', '.hpp']:
return '⚡'
elif extension in ['.cs', '.vb']:
return '🔷'
elif extension in ['.php']:
return '🐘'
elif extension in ['.rb', '.rake']:
return '💎'
elif extension in ['.go']:
return '🐹'
elif extension in ['.rs']:
return '🦀'
elif extension in ['.swift']:
return '🦉'
elif extension in ['.kt', '.kts']:
return '🟣'
elif extension in ['.dockerfile'] or filename == 'dockerfile':
return '🐳'
elif extension in ['.env'] or filename.startswith('.env'):
return '🔐'
elif filename in ['makefile', 'makefile.am', 'makefile.in']:
return '🔨'
elif filename in ['readme', 'readme.txt', 'readme.md']:
return '📚'
elif filename in ['license', 'license.txt', 'license.md']:
return '📜'
elif extension in ['.log', '.logs']:
return '📊'
elif extension in ['.csv', '.tsv']:
return '📈'
elif extension in ['.ini', '.cfg', '.conf', '.config']:
return '⚙️'
else:
return '📄'
def load_file_content(self, file_path, relative_path):
try:
# Try different encodings
encodings = ['utf-8', 'utf-16', 'latin-1', 'cp1252']
content = None
for encoding in encodings:
try:
with open(file_path, 'r', encoding=encoding, errors='ignore') as f:
content = f.read()
break
except UnicodeDecodeError:
continue
if content is not None:
self.file_content_map[relative_path] = content
else:
self.file_content_map[relative_path] = f"Error: Could not decode file with standard encodings"
except Exception as e:
self.file_content_map[relative_path] = f"Error reading file: {str(e)}"
def parsing_complete(self):
# Re-enable buttons
self.parse_btn.config(state=tk.NORMAL, text="⚡ Parse Directory")
self.select_btn.config(state=tk.NORMAL)
# Update text area with completion message
self.text_area.config(state=tk.NORMAL)
self.text_area.delete(1.0, tk.END)
completion_text = f"""✅ Parsing Complete!
📊 Discovery Summary:
• Found {self.total_files:,} text files
• Directory: {self.selected_folder_path.name}
• Ready for selection
🔧 Next Steps:
1. Browse the directory structure on the left
2. Check the files/folders you want to combine
3. View the combined content here
4. Copy or download when ready
Start by selecting some files from the tree! 🌳"""
self.text_area.insert(1.0, completion_text)
self.text_area.config(state=tk.DISABLED)
# Update status
self.update_status_bar()
def on_tree_click(self, event):
region = self.tree.identify_region(event.x, event.y)
item = self.tree.identify_row(event.y)
column = self.tree.identify_column(event.x)
if item and column == "#1": # Clicked on selection column
self.toggle_item(item)
elif item and region == "tree":
# Handle folder expansion
if self.tree.get_children(item): # Has children (folder)
current_state = self.tree.item(item, 'open')
self.tree.item(item, open=not current_state)
def toggle_item(self, item):
current_state = self.item_states.get(item, False)
new_state = not current_state
# Update item state
self.item_states[item] = new_state
checkbox = "☑️" if new_state else "☐"
self.tree.item(item, values=(checkbox,))
# Update children recursively
self.set_children_state(item, new_state)
# Update parent state
self.update_parent_state(item)
# Update content display
self.update_content()
def set_children_state(self, parent_item, state):
for child_item in self.tree.get_children(parent_item):
self.item_states[child_item] = state
checkbox = "☑️" if state else "☐"
self.tree.item(child_item, values=(checkbox,))
self.set_children_state(child_item, state)
def update_parent_state(self, item):
parent_item = self.tree.parent(item)
if not parent_item:
return
children = self.tree.get_children(parent_item)
if not children:
return
# Check children states
child_states = [self.item_states.get(child, False) for child in children]
if all(child_states):
# All children selected
self.item_states[parent_item] = True
self.tree.item(parent_item, values=("☑️",))
elif any(child_states):
# Some children selected - show mixed state
checkbox = "☑️" if self.item_states.get(parent_item, False) else "☐"
self.tree.item(parent_item, values=(checkbox,))
else:
# No children selected
self.item_states[parent_item] = False
self.tree.item(parent_item, values=("☐",))
# Recurse up the tree
self.update_parent_state(parent_item)
def select_all(self):
for item in self.tree.get_children():
self.item_states[item] = True
self.tree.item(item, values=("☑️",))
self.set_children_state(item, True)
self.update_content()
def deselect_all(self):
for item in self.tree.get_children():
self.item_states[item] = False
self.tree.item(item, values=("☐",))
self.set_children_state(item, False)
self.update_content()
def update_content(self):
if not self.selected_folder_path:
return
# Collect selected files
selected_files = []
self.collect_selected_files("", selected_files)
# Sort files by path
selected_files.sort()
if not selected_files:
# No files selected
self.text_area.config(state=tk.NORMAL)
self.text_area.delete(1.0, tk.END)
self.text_area.insert(1.0, "🔍 No files selected\n\nSelect files from the directory tree to view their combined content here.")
self.text_area.config(state=tk.DISABLED)
self.copy_btn.config(state=tk.DISABLED)
self.download_btn.config(state=tk.DISABLED)
self.content_counter.config(text="")
self.update_status_bar()
return
# Build content
content_parts = []
content_parts.append(f"# Combined Content from: {self.selected_folder_path.name}\n")