File: FolderListController.m

package info (click to toggle)
lusernet.app 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 828 kB
  • sloc: objc: 8,495; makefile: 22
file content (166 lines) | stat: -rw-r--r-- 3,965 bytes parent folder | download
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
/*
 *
 * Copyright 2002 Alexander Malmberg <alexander@malmberg.org>
 *           2012 The Free Software Foundation
 *
 * Authors: Alexander Malmberg <alexander@malmberg.org>
 *          Riccardo Mottola <rm@gnu.org>
 *
 */

#import <Foundation/NSObject.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSDictionary.h>
#import <AppKit/NSWindow.h>
#import <AppKit/NSScrollView.h>
#import <AppKit/NSTableView.h>
#import <AppKit/NSTableColumn.h>
#import <AppKit/NSCell.h>

#import "FolderListController.h"

#import "MsgDB.h"
#import "main.h"


@implementation FolderListController

-(void) updateFolderNames
{
	NSEnumerator *e;
	NSString *s;
	DESTROY(folder_names);
	folder_names=[[NSMutableArray alloc] init];
	for (e=[[mdb folders] keyEnumerator];(s=[e nextObject]);)
		[folder_names addObject: [s copy]];
	[folder_names sortUsingSelector: @selector(compare:)];

	[folders reloadData];
}

-(int) numberOfRowsInTableView: (NSTableView *)tv
{
	return [folder_names count];
}

-(id) tableView: (NSTableView *)tv  objectValueForTableColumn: (NSTableColumn *)tc  row: (int)row
{
	if (tc==c_name)
		return [folder_names objectAtIndex: row];
	else
	if (tc==c_num)
		return [NSNumber numberWithInt: [[[mdb folders] objectForKey: [folder_names objectAtIndex: row]] numMessages]];
	else
		abort();
}


- initWithMsgDB: (MsgDB *)m;
{
	NSWindow *win;
	win=[[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,250,200)
		styleMask: NSClosableWindowMask|NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask
		backing: NSBackingStoreRetained
		defer: YES];

	if (!(self=[super initWithWindow: win])) return nil;

	ASSIGN(mdb,m);

	folder_names=[[NSMutableArray alloc] init];

	{
		NSScrollView *sv;

		[win setTitle: _(@"Folder list")];

		c_name=[[NSTableColumn alloc] initWithIdentifier: @"Name"];
		[[c_name headerCell] setStringValue: _(@"Name")];
		[c_name setEditable: NO];
		[c_name setResizable: YES];
		[c_name setWidth: 180];

		c_num=[[NSTableColumn alloc] initWithIdentifier: @"Messages"];
		[[c_num headerCell] setStringValue: _(@"Messages")];
		[[c_num headerCell] setAlignment: NSRightTextAlignment];
		[[c_num dataCell] setAlignment: NSRightTextAlignment];
		[c_num setEditable: NO];
		[c_num setResizable: YES];
		[c_num setWidth: 50];

		folders=[[NSTableView alloc] init];
		[folders setAllowsColumnReordering: YES];
		[folders setAllowsColumnResizing: YES];
		[folders setAllowsMultipleSelection: NO];
		[folders setAllowsColumnSelection: NO];
		[folders addTableColumn: c_name];
		[folders addTableColumn: c_num];
		[folders setDataSource: self];
		[folders setDoubleAction: @selector(openFolder:)];

		[folders setAutosaveName: @"FolderList"];
		[folders setAutosaveTableColumns: YES];

		sv=[[NSScrollView alloc] init];
		[sv setDocumentView: folders];
		[sv setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
		[sv setAutoresizesSubviews: YES];
		[sv setHasVerticalScroller: YES];
		[sv setBorderType: NSBezelBorder];

		[win setContentView: sv];

		[sv release];
	}
	[win setDelegate: self];
	[win setFrameUsingName: @"FolderList"];
	[win setFrameAutosaveName: @"FolderList"];

	[win release];

	[self updateFolderNames];

	[[NSNotificationCenter defaultCenter]
		addObserver: self
		selector: @selector(updateFolderNames)
		name: MsgDB_FolderAddMsgNotification
		object: mdb];

	[[NSNotificationCenter defaultCenter]
		addObserver: self
		selector: @selector(updateFolderNames)
		name: MsgDB_FolderAddNotification
		object: mdb];

	return self;
}

-(void) dealloc
{
	[[NSNotificationCenter defaultCenter] removeObserver: self];

	DESTROY(c_name);
	DESTROY(c_num);
	DESTROY(folders);

	DESTROY(folder_names);
	DESTROY(mdb);
	[super dealloc];
}


-(void) display
{
	[[self window] makeKeyAndOrderFront: self];
}

-(void) openFolder: (id)sender
{
	int r=[folders selectedRow];
	if (r>=0 && r<[folder_names count])
		[app_delegate openFolderWindow: [folder_names objectAtIndex: r]];
}

@end