Skip to content

Commit

Permalink
feat: add 'show all types of files' option
Browse files Browse the repository at this point in the history
  • Loading branch information
netdcy committed Aug 12, 2024
1 parent 2ca6717 commit 8fc8ae8
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 30 deletions.
17 changes: 16 additions & 1 deletion FlowVision/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,24 @@ CA
<action selector="toggleIsShowHiddenFile:" target="Voe-Tx-rLC" id="L0l-RG-uc0"/>
</connections>
</menuItem>
<menuItem title="Hide Camera RAW Files" keyEquivalent="R" id="3W1-Yw-Gn8">
<menuItem title="Show All Types of Files" id="S31-Ni-z5u">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleIsShowAllTypeFile:" target="Voe-Tx-rLC" id="85b-hE-Eij"/>
</connections>
</menuItem>
<menuItem title="Hide Camera RAW Files" id="3W1-Yw-Gn8">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleIsHideRawFile:" target="Voe-Tx-rLC" id="f3u-r3-KmD"/>
</connections>
</menuItem>
<menuItem title="Hide Video Files" id="UYl-gy-bK8">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleIsHideVideoFile:" target="Voe-Tx-rLC" id="P93-ip-O3J"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="p0a-iP-jCL"/>
<menuItem title="Justified View" keyEquivalent="1" id="rIE-So-qGu">
<connections>
Expand Down Expand Up @@ -852,6 +865,8 @@ CA
<outlet property="switchToFitToWindowMenuItem" destination="d9h-3l-mAH" id="gda-Df-WtZ"/>
<outlet property="systemThemeMenuItem" destination="I6E-O3-RVP" id="AYN-qT-D7o"/>
<outlet property="toggleIsHideRawFileMenuItem" destination="3W1-Yw-Gn8" id="0Xl-oh-wrP"/>
<outlet property="toggleIsHideVideoFileMenuItem" destination="UYl-gy-bK8" id="W0c-o3-Rfz"/>
<outlet property="toggleIsShowAllTypeFileMenuItem" destination="S31-Ni-z5u" id="0Tm-OY-l8R"/>
<outlet property="toggleIsShowHiddenFileMenuItem" destination="Tbh-PX-yFW" id="YS8-lw-tc2"/>
<outlet property="togglePortableModeMenuItem" destination="oP8-xB-4fx" id="edf-9A-uz9"/>
<outlet property="toggleSidebarMenuItem" destination="Yr6-zE-34v" id="Jn2-F6-Uei"/>
Expand Down
11 changes: 11 additions & 0 deletions FlowVision/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,17 @@
}
}
},
"Show All Types of Files" : {
"comment" : "显示所有类型文件",
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "显示所有类型文件"
}
}
}
},
"Show Hidden Files" : {
"comment" : "显示隐藏文件",
"localizations" : {
Expand Down
2 changes: 2 additions & 0 deletions FlowVision/Resources/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@
"oP8-xB-4fx.title" = "便携浏览模式";

"Tbh-PX-yFW.title" = "显示隐藏文件";
"S31-Ni-z5u.title" = "显示所有类型文件";
"3W1-Yw-Gn8.title" = "不显示相机RAW文件";
"UYl-gy-bK8.title" = "不显示视频文件";

"I6E-O3-RVP.title" = "系统主题";
"iPW-fb-GmX.title" = "浅色模式";
Expand Down
60 changes: 38 additions & 22 deletions FlowVision/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
@IBOutlet weak var togglePortableModeMenuItem: NSMenuItem!
@IBOutlet weak var toggleIsShowHiddenFileMenuItem: NSMenuItem!
@IBOutlet weak var toggleIsHideRawFileMenuItem: NSMenuItem!
@IBOutlet weak var toggleIsHideVideoFileMenuItem: NSMenuItem!
@IBOutlet weak var toggleIsShowAllTypeFileMenuItem: NSMenuItem!

var commonParentPath=""

Expand Down Expand Up @@ -93,41 +95,44 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
}
UserDefaults.standard.set(false, forKey: "hasNormalExit")

if let savedIsShowHiddenFile = UserDefaults.standard.value(forKey: "isShowHiddenFile") as? Bool {
globalVar.isShowHiddenFile = savedIsShowHiddenFile
if let isShowHiddenFile = UserDefaults.standard.value(forKey: "isShowHiddenFile") as? Bool {
globalVar.isShowHiddenFile = isShowHiddenFile
}
if let savedIsHideRawFile = UserDefaults.standard.value(forKey: "isHideRawFile") as? Bool {
globalVar.isHideRawFile = savedIsHideRawFile
if let isHideRawFile = UserDefaults.standard.value(forKey: "isHideRawFile") as? Bool {
globalVar.isHideRawFile = isHideRawFile
}
if let savedIsHideVideoFile = UserDefaults.standard.value(forKey: "isHideVideoFile") as? Bool {
globalVar.isHideVideoFile = savedIsHideVideoFile
if let isShowAllTypeFile = UserDefaults.standard.value(forKey: "isShowAllTypeFile") as? Bool {
globalVar.isShowAllTypeFile = isShowAllTypeFile
}
if let savedTerminateAfterLastWindowClosed = UserDefaults.standard.value(forKey: "terminateAfterLastWindowClosed") as? Bool {
globalVar.terminateAfterLastWindowClosed = savedTerminateAfterLastWindowClosed
if let isHideVideoFile = UserDefaults.standard.value(forKey: "isHideVideoFile") as? Bool {
globalVar.isHideVideoFile = isHideVideoFile
}
if let terminateAfterLastWindowClosed = UserDefaults.standard.value(forKey: "terminateAfterLastWindowClosed") as? Bool {
globalVar.terminateAfterLastWindowClosed = terminateAfterLastWindowClosed
}
if let autoHideToolbar = UserDefaults.standard.value(forKey: "autoHideToolbar") as? Bool {
globalVar.autoHideToolbar = autoHideToolbar
}
if let savedMemUseLimit = UserDefaults.standard.value(forKey: "memUseLimit") as? Int {
globalVar.memUseLimit = savedMemUseLimit
if let memUseLimit = UserDefaults.standard.value(forKey: "memUseLimit") as? Int {
globalVar.memUseLimit = memUseLimit
}
if let savedThumbThreadNum = UserDefaults.standard.value(forKey: "thumbThreadNum") as? Int {
globalVar.thumbThreadNum = savedThumbThreadNum
if let thumbThreadNum = UserDefaults.standard.value(forKey: "thumbThreadNum") as? Int {
globalVar.thumbThreadNum = thumbThreadNum
}
if let savedFolderSearchDepth = UserDefaults.standard.value(forKey: "folderSearchDepth") as? Int {
globalVar.folderSearchDepth = savedFolderSearchDepth
if let folderSearchDepth = UserDefaults.standard.value(forKey: "folderSearchDepth") as? Int {
globalVar.folderSearchDepth = folderSearchDepth
}
if let savedThumbThreadNum_External = UserDefaults.standard.value(forKey: "thumbThreadNum_External") as? Int {
globalVar.thumbThreadNum_External = savedThumbThreadNum_External
if let thumbThreadNum_External = UserDefaults.standard.value(forKey: "thumbThreadNum_External") as? Int {
globalVar.thumbThreadNum_External = thumbThreadNum_External
}
if let savedFolderSearchDepth_External = UserDefaults.standard.value(forKey: "folderSearchDepth_External") as? Int {
globalVar.folderSearchDepth_External = savedFolderSearchDepth_External
if let folderSearchDepth_External = UserDefaults.standard.value(forKey: "folderSearchDepth_External") as? Int {
globalVar.folderSearchDepth_External = folderSearchDepth_External
}
if let savedDoNotUseFFmpeg = UserDefaults.standard.value(forKey: "doNotUseFFmpeg") as? Bool {
globalVar.doNotUseFFmpeg = savedDoNotUseFFmpeg
if let doNotUseFFmpeg = UserDefaults.standard.value(forKey: "doNotUseFFmpeg") as? Bool {
globalVar.doNotUseFFmpeg = doNotUseFFmpeg
}
if let savedPortableMode = UserDefaults.standard.value(forKey: "portableMode") as? Bool {
globalVar.portableMode = savedPortableMode
if let portableMode = UserDefaults.standard.value(forKey: "portableMode") as? Bool {
globalVar.portableMode = portableMode
}
if let isGenHdThumb = UserDefaults.standard.value(forKey: "isGenHdThumb") as? Bool {
globalVar.isGenHdThumb = isGenHdThumb
Expand Down Expand Up @@ -449,6 +454,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
onTopMenuItem.keyEquivalentModifierMask=[]

toggleIsShowHiddenFileMenuItem.state = globalVar.isShowHiddenFile ? .on : .off
toggleIsShowAllTypeFileMenuItem.state = globalVar.isShowAllTypeFile ? .on : .off
toggleIsHideRawFileMenuItem.state = globalVar.isHideRawFile ? .on : .off
toggleIsHideVideoFileMenuItem.state = globalVar.isHideVideoFile ? .on : .off

justifiedViewMenuItem.state = (mainViewController.publicVar.layoutType == .justified) ? .on : .off
waterfallViewModeMenuItem.state = (mainViewController.publicVar.layoutType == .waterfall) ? .on : .off
Expand Down Expand Up @@ -656,6 +664,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, NSMenuItemVa
getMainViewController()?.toggleIsHideRawFile()
}

@IBAction func toggleIsHideVideoFile(_ sender: NSMenuItem){
getMainViewController()?.toggleIsHideVideoFile()
}

@IBAction func toggleIsShowAllTypeFile(_ sender: NSMenuItem){
getMainViewController()?.toggleIsShowAllTypeFile()
}

@IBAction func switchToSystemTheme(_ sender: NSMenuItem){
let defaults = UserDefaults.standard
defaults.set("", forKey: "appearance")
Expand Down
5 changes: 3 additions & 2 deletions FlowVision/Sources/Common/GlobalVariable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var HandledImageExtensions: [String] = []
var HandledVideoExtensions: [String] = []
var HandledOtherExtensions: [String] = []
var HandledNotNativeSupportedExtensions: [String] = []
var HandledExternalExtensions: [String] = []
//var HandledExternalExtensions: [String] = []
var HandledFileExtensions: [String] = []
var HandledSearchExtensions: [String] = []
var HandledFolderThumbExtensions: [String] = []
Expand All @@ -29,7 +29,7 @@ func setFileExtensions(){
}
HandledOtherExtensions = [] //["pdf"] //不能为"",否则会把目录异常包含进来
HandledNotNativeSupportedExtensions = ["mkv", "mts", "ts", "avi", "flv", "f4v", "asf", "wmv", "rmvb", "rm", "webm", "divx", "xvid", "3gp", "3g2"]
HandledExternalExtensions = HandledVideoExtensions // + ["pdf"] //外部程序打开的
//HandledExternalExtensions = HandledVideoExtensions // + ["pdf"] //外部程序打开的
HandledFileExtensions = HandledImageExtensions + HandledVideoExtensions + HandledOtherExtensions //文件列表显示的
HandledSearchExtensions = HandledImageExtensions + HandledVideoExtensions //作为鼠标手势查找的目标
HandledFolderThumbExtensions = HandledImageExtensions.filter{$0 != "svg"} + HandledVideoExtensions // + ["pdf"] //目录缩略图
Expand Down Expand Up @@ -64,6 +64,7 @@ class GlobalVar{
var folderSearchDepth_External: Int = 0

var isShowHiddenFile = false
var isShowAllTypeFile = false
var isHideRawFile = false
var isHideVideoFile = false
var isGenHdThumb = false
Expand Down
10 changes: 7 additions & 3 deletions FlowVision/Sources/Common/ImageProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func getImageThumb(url: URL, size: NSSize? = nil, refSize: NSSize? = nil) -> NSI
//return nil
}

}else{ //处理其它缩略图
}else if (HandledImageExtensions+["pdf"]).contains(url.pathExtension.lowercased()) { //处理其它缩略图
//gif特殊处理
if( "gif" == url.pathExtension.lowercased() ){
return NSImage(contentsOf: url)
Expand Down Expand Up @@ -505,6 +505,9 @@ func getImageThumb(url: URL, size: NSSize? = nil, refSize: NSSize? = nil) -> NSI
}

}

//默认情况
return nil

}

Expand Down Expand Up @@ -769,7 +772,7 @@ func getImageSize(url: URL) -> NSSize? {
}else if "pdf" == url.pathExtension.lowercased() {
if let thumb = getImageThumb(url: url) {return thumb.size}
return nil
}else{
}else if HandledImageExtensions.contains(url.pathExtension.lowercased()){
guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { return nil }
guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any] else { return nil }
guard let width = imageProperties[kCGImagePropertyPixelWidth as String] as? CGFloat,
Expand All @@ -786,8 +789,9 @@ func getImageSize(url: URL) -> NSSize? {
default:
return NSSize(width: width, height: height)
}
}else{
return nil
}

}

func getResizedImageDeprecated1(url: URL, size: NSSize) -> NSImage? {
Expand Down
10 changes: 8 additions & 2 deletions FlowVision/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,12 @@ class ViewController: NSViewController, NSSplitViewDelegate {
refreshAll([])
}

func toggleIsShowAllTypeFile(){
globalVar.isShowAllTypeFile.toggle()
UserDefaults.standard.set(globalVar.isShowAllTypeFile, forKey: "isShowAllTypeFile")
refreshAll([])
}

func toggleIsHideRawFile(){
globalVar.isHideRawFile.toggle()
UserDefaults.standard.set(globalVar.isHideRawFile, forKey: "isHideRawFile")
Expand Down Expand Up @@ -2346,7 +2352,7 @@ class ViewController: NSViewController, NSSplitViewDelegate {
var imageCount=0
var searchCount=0
for file in contents {
if HandledFileExtensions.contains(file.pathExtension.lowercased()) {
if HandledFileExtensions.contains(file.pathExtension.lowercased()) || (globalVar.isShowAllTypeFile && file.pathExtension.lowercased() != "") {
filesUrlInFolder.append(file)
}
if HandledImageExtensions.contains(file.pathExtension.lowercased()) {
Expand Down Expand Up @@ -3451,7 +3457,7 @@ class ViewController: NSViewController, NSSplitViewDelegate {
if(url.hasDirectoryPath){
switchDirByDirection(direction: .zero, dest: item.file.path, stackDeep: 0)
}
else if HandledExternalExtensions.contains(url.pathExtension.lowercased()) {
else if !HandledImageExtensions.contains(url.pathExtension.lowercased()) {
NSWorkspace.shared.open(url)
}else{
if largeImageView.isHidden {
Expand Down
8 changes: 8 additions & 0 deletions FlowVision/Sources/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ extension WindowController: NSToolbarDelegate {
actionItemShowHiddenFile.state = (globalVar.isShowHiddenFile) ? .on : .off
actionItemShowHiddenFile.keyEquivalentModifierMask = [.command, .shift]

let showAllTypeFile = menu.addItem(withTitle: NSLocalizedString("Show All Types of Files", comment: "显示所有类型文件"), action: #selector(showAllTypeFileAction), keyEquivalent: "")
showAllTypeFile.state = (globalVar.isShowAllTypeFile) ? .on : .off

let hideRawFile = menu.addItem(withTitle: NSLocalizedString("Hide Camera RAW Files", comment: "不显示相机RAW文件"), action: #selector(hideRawFileAction), keyEquivalent: "")
hideRawFile.state = (globalVar.isHideRawFile) ? .on : .off

Expand Down Expand Up @@ -940,6 +943,11 @@ extension WindowController: NSToolbarDelegate {
viewController.toggleIsShowHiddenFile()
}

@objc func showAllTypeFileAction(_ sender: NSMenuItem) {
guard let viewController = contentViewController as? ViewController else {return}
viewController.toggleIsShowAllTypeFile()
}

@objc func hideRawFileAction(_ sender: NSMenuItem) {
guard let viewController = contentViewController as? ViewController else {return}
viewController.toggleIsHideRawFile()
Expand Down

0 comments on commit 8fc8ae8

Please sign in to comment.