-
Notifications
You must be signed in to change notification settings - Fork 33
/
UKFilePathView.h
150 lines (117 loc) · 5.12 KB
/
UKFilePathView.h
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
//
// UKFilePathView.h
// Shovel
//
// Created by Uli Kusterer on Thu Mar 25 2004.
// Copyright (c) 2004 Uli Kusterer.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#import <AppKit/AppKit.h>
/*
An NSView that displays a file path. This looks kind of like how Sherlock
displays the location of a file. Basically you get each folder's display
name with its icon in front of it, and little grey triangles between
them, and you get the icon of the file or folder at the end and its display
name.
If the path is too long, this takes items out of the middle and displays
an ellipsis character (...) instead.
You can also right-click or control-click on this to get a contextual menu
that contains "Reveal in Finder" and "Show Real Names" menu choices. Real
names displays the actual path, starting with "/", and using the actual
file names instead of their display names. As a shortcut, double-clicking
this view is the same as "Reveal in Finder".
This needs:
- UKGraphics.h/.m (for drawing the bezel around the view)
*/
@class UKFilePathEntry; // Private, internal class.
@interface UKFilePathView : NSView
{
NSString* filePath; // The path to be displayed.
BOOL noDisplayNames; // Show actual names, not display names.
BOOL canChooseFiles; // Handed on directly to the open panel.
BOOL canChooseDirectories; // Handed on directly to the open panel.
BOOL treatsFilePackagesAsDirectories; // Handed on directly to the open/save panels.
NSArray* types; // Handed on directly to the open panel.
SEL action;
id target;
BOOL drawDropHighlight;
NSString* placeholderString; // A placeholder to show when path is NIL. Defaults to "none".
NSBorderType borderType;
BOOL acceptDrops;
BOOL allowContextMenu;
NSMutableArray* pathEntries; // array of UKFilePathEntry objects for the path components we display.
NSDictionary* textAttributes; // As you'd have them in an NSAttributedString.
unsigned selectedPathEntry; // Entry to highlight during mouse tracking.
}
-(NSString *) filePath;
-(void) setFilePath: (NSString *)newFilePath;
-(id) target;
-(void) setTarget: (id) theTarget;
-(SEL) action;
-(void) setAction: (SEL) theAction;
-(void) revealInFinder: (id)sender;
-(void) showRealNames: (id)sender;
-(void) toggleShowRealNames: (id)sender;
-(NSString *) stringValue; // same as filePath.
-(void) setStringValue: (NSString*)s; // same as setFilePath.
-(void) setPlaceholderString: (NSString*)string;
-(NSString*) placeholderString;
-(void) setBorderType: (NSBorderType)aType; // Only NSBezelBorder and NSNoBorder so far.
-(NSBorderType) borderType;
-(NSString*) fullPathAsDisplayString;
-(void) setAcceptDrops: (BOOL)doAccept;
-(BOOL) acceptDrops;
-(void) setAllowContextMenu: (BOOL)doCMM;
-(BOOL) allowContextMenu;
-(NSDictionary*) textAttributes;
-(void) setTextAttributes: (NSDictionary*)dict;
// UI for changing value:
-(IBAction) pickFile: (id)sender; // NSOpenPanel. Chooses existing files.
-(IBAction) pickNewFile: (id)sender; // NSSavePanel. Lets the user specify name and location for new files.
-(IBAction) pickNoFile: (id)sender; // Sets the file path to NIL.
// Getters/setters for the NSOpenPanel properties:
-(BOOL) canChooseFiles;
-(void) setCanChooseFiles: (BOOL)flag;
-(BOOL) canChooseDirectories;
-(void) setCanChooseDirectories: (BOOL)flag;
-(NSArray*) types;
-(void) setTypes: (NSArray*)theTypes;
// Getters/setters for NSOpenPanel/NSSavePanel properties:
-(BOOL) treatsFilePackagesAsDirectories;
-(void) setTreatsFilePackagesAsDirectories: (BOOL)flag;
// private:
-(NSImage*) pathArrowImage;
-(void) rebuildPathComponentArray;
-(void) relayoutPathComponents;
-(unsigned) indexOfPathEntryAtPoint: (NSPoint)pos;
-(UKFilePathEntry*) lastVisiblePathEntry;
@end
// Some constants we use for this view's metrics:
#define UK_PATH_NAME_LEFT_MARGIN 4
#define UK_PATH_NAME_RIGHT_MARGIN 4
#define UK_PATH_NAME_TOP_MARGIN 2
#define UK_PATH_NAME_BOTTOM_MARGIN 2
#define UK_PATH_NAME_TOTAL_VMARGIN (UK_PATH_NAME_TOP_MARGIN +UK_PATH_NAME_BOTTOM_MARGIN)
#define UK_PATH_NAME_TOTAL_HMARGIN (UK_PATH_NAME_LEFT_MARGIN +UK_PATH_NAME_RIGHT_MARGIN)
#define UK_PATH_ARROW_IMG_WIDTH 16
#define UK_PATH_ICON_IMG_WIDTH 16
#define UK_PATH_ICON_NAME_HDISTANCE 2
#define UK_MIN_TEXT_WIDTH 6