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
|
/* LSFEditor.m
*
* Copyright (C) 2005-2016 Free Software Foundation, Inc.
*
* Author: Enrico Sersale <enrico@imago.ro>
* Date: January 2005
*
* This file is part of the GNUstep GWorkspace application
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
*/
#import <AppKit/AppKit.h>
#import "LSFEditor.h"
#import "LSFolder.h"
#import "FindModuleView.h"
#import "FinderModulesProtocol.h"
#import "Finder.h"
#import "SearchPlacesCell.h"
#import "GWFunctions.h"
#define WINH (186.0)
#define FMVIEWH (34.0)
#define BORDER (4.0)
#define HMARGIN (12.0)
#define CELLS_HEIGHT (28.0)
#define ICON_SIZE NSMakeSize(24.0, 24.0)
#define CHECKSIZE(sz) \
if (sz.width < 0) sz.width = 0; \
if (sz.height < 0) sz.height = 0
static NSString *nibName = @"LSFEditor";
@implementation LSFEditor
- (void)dealloc
{
RELEASE (modules);
RELEASE (fmviews);
[super dealloc];
}
- (id)initForFolder:(id)fldr
{
self = [super init];
if (self) {
NSDictionary *sizesDict;
NSArray *searchPaths;
SEL compareSel;
NSSize cs, ms;
NSUInteger i;
folder = fldr;
finder = [Finder finder];
if ([NSBundle loadNibNamed: nibName owner: self] == NO) {
NSLog(@"failed to load %@!", nibName);
DESTROY (self);
return self;
}
[win setTitle: [[folder node] name]];
[win setDelegate: self];
sizesDict = [folder getSizes];
if (sizesDict) {
id entry = [sizesDict objectForKey: @"editor_win"];
if (entry) {
[win setFrameFromString: entry];
}
}
[placesScroll setBorderType: NSBezelBorder];
[placesScroll setHasHorizontalScroller: NO];
[placesScroll setHasVerticalScroller: YES];
placesMatrix = [[NSMatrix alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)
mode: NSListModeMatrix
prototype: [[SearchPlacesCell new] autorelease]
numberOfRows: 0
numberOfColumns: 0];
[placesMatrix setIntercellSpacing: NSZeroSize];
[placesMatrix setCellSize: NSMakeSize(1, CELLS_HEIGHT)];
[placesMatrix setAutoscroll: YES];
[placesMatrix setAllowsEmptySelection: YES];
cs = [placesScroll contentSize];
ms = [placesMatrix cellSize];
ms.width = cs.width;
CHECKSIZE (ms);
[placesMatrix setCellSize: ms];
[placesScroll setDocumentView: placesMatrix];
RELEASE (placesMatrix);
searchPaths = [folder searchPaths];
for (i = 0; i < [searchPaths count]; i++) {
int count = [[placesMatrix cells] count];
FSNode *node = [FSNode nodeWithPath: [searchPaths objectAtIndex: i]];
SearchPlacesCell *cell;
[placesMatrix insertRow: count];
cell = [placesMatrix cellAtRow: count column: 0];
[cell setNode: node];
[cell setLeaf: YES];
[cell setIcon];
}
compareSel = [[FSNodeRep sharedInstance] defaultCompareSelector];
[placesMatrix sortUsingSelector: compareSel];
[placesMatrix setCellSize: NSMakeSize([placesScroll contentSize].width, CELLS_HEIGHT)];
[placesMatrix sizeToCells];
[recursiveSwitch setState: ([folder recursive] ? NSOnState : NSOffState)];
[searchLabel setStringValue: NSLocalizedString(@"Searching in:", @"")];
[modulesLabel setStringValue: NSLocalizedString(@"Modules:", @"")];
[recursiveSwitch setStringValue: NSLocalizedString(@"recursive", @"")];
fmviews = [NSMutableArray new];
[self setModules];
}
return self;
}
- (void)setModules
{
CREATE_AUTORELEASE_POOL(arp);
NSArray *fmods = [finder modules];
NSDictionary *searchCriteria = [folder searchCriteria];
NSArray *names = [searchCriteria allKeys];
NSArray *usedModules;
NSUInteger i;
while ([fmviews count] > 0) {
FindModuleView *view = [fmviews objectAtIndex: 0];
[[view mainBox] removeFromSuperview];
[fmviews removeObject: view];
}
DESTROY (modules);
modules = [NSMutableArray new];
for (i = 0; i < [fmods count]; i++) {
Class mclass = [[fmods objectAtIndex: i] class];
NSString *cname = NSStringFromClass(mclass);
id module = [[mclass alloc] initInterface];
if ([names containsObject: cname]) {
[module setControlsState: [searchCriteria objectForKey: cname]];
[module setInUse: YES];
} else {
[module setInUse: NO];
}
[modules addObject: module];
RELEASE (module);
}
usedModules = [self usedModules];
for (i = 0; i < [usedModules count]; i++) {
id module = [usedModules objectAtIndex: i];
id fmview = [[FindModuleView alloc] initWithDelegate: self];
[fmview setModule: module];
if ([usedModules count] == [modules count]) {
[fmview setAddEnabled: NO];
}
[[modulesBox contentView] addSubview: [fmview mainBox]];
[fmviews insertObject: fmview atIndex: [fmviews count]];
RELEASE (fmview);
}
RELEASE (arp);
}
- (void)activate
{
[win makeKeyAndOrderFront: nil];
[self tile];
}
- (NSArray *)modules
{
return modules;
}
- (NSArray *)usedModules
{
NSMutableArray *used = [NSMutableArray array];
NSUInteger i;
for (i = 0; i < [modules count]; i++) {
id module = [modules objectAtIndex: i];
if ([module used]) {
[used addObject: module];
}
}
return used;
}
- (id)firstUnusedModule
{
NSUInteger i;
for (i = 0; i < [modules count]; i++) {
id module = [modules objectAtIndex: i];
if ([module used] == NO) {
return module;
}
}
return nil;
}
- (id)moduleWithName:(NSString *)mname
{
int i;
for (i = 0; i < [modules count]; i++) {
id module = [modules objectAtIndex: i];
if ([[module moduleName] isEqual: mname]) {
return module;
}
}
return nil;
}
- (void)addModule:(FindModuleView *)aview
{
NSArray *usedModules = [self usedModules];
if ([usedModules count] < [modules count]) {
NSUInteger index = [fmviews indexOfObjectIdenticalTo: aview];
id module = [self firstUnusedModule];
id fmview = [[FindModuleView alloc] initWithDelegate: self];
NSUInteger count;
NSUInteger i;
[module setInUse: YES];
[fmview setModule: module];
[[modulesBox contentView] addSubview: [fmview mainBox]];
[fmviews insertObject: fmview atIndex: index + 1];
RELEASE (fmview);
count = [fmviews count];
for (i = 0; i < count; i++) {
fmview = [fmviews objectAtIndex: i];
[fmview updateMenuForModules: modules];
if (count == [modules count]) {
[fmview setAddEnabled: NO];
}
if (count > 1) {
[fmview setRemoveEnabled: YES];
}
}
[self tile];
}
}
- (void)removeModule:(FindModuleView *)aview
{
if ([fmviews count] > 1) {
int count;
int i;
[[aview module] setInUse: NO];
[[aview mainBox] removeFromSuperview];
[fmviews removeObject: aview];
count = [fmviews count];
for (i = 0; i < count; i++) {
id fmview = [fmviews objectAtIndex: i];
[fmview updateMenuForModules: modules];
[fmview setAddEnabled: YES];
if (count == 1) {
[fmview setRemoveEnabled: NO];
}
}
[self tile];
}
}
- (void)findModuleView:(FindModuleView *)aview
changeModuleTo:(NSString *)mname
{
id module = [self moduleWithName: mname];
if (module && ([aview module] != module)) {
int i;
[[aview module] setInUse: NO];
[module setInUse: YES];
[aview setModule: module];
for (i = 0; i < [fmviews count]; i++) {
[[fmviews objectAtIndex: i] updateMenuForModules: modules];
}
}
}
- (IBAction)buttonsAction:(id)sender
{
if (sender == cancelButt) {
[self setModules];
[self tile];
} else {
NSMutableDictionary *criteria = [NSMutableDictionary dictionary];
int i;
for (i = 0; i < [fmviews count]; i++) {
id module = [[fmviews objectAtIndex: i] module];
NSDictionary *dict = [module searchCriteria];
if (dict) {
[criteria setObject: dict forKey: NSStringFromClass([module class])];
}
}
if ([criteria count]) {
[folder setSearchCriteria: criteria
recursive: ([recursiveSwitch state] == NSOnState)];
}
}
}
- (void)tile
{
NSRect wrect = [win frame];
NSRect mbrect = [modulesBox bounds];
int count = [fmviews count];
float hspace = (count * FMVIEWH) + HMARGIN + BORDER;
int i;
if (mbrect.size.height != hspace) {
if (wrect.size.height != WINH) {
wrect.origin.y -= (hspace - mbrect.size.height);
}
wrect.size.height += (hspace - mbrect.size.height);
[win setFrame: wrect display: NO];
}
mbrect = [modulesBox bounds];
for (i = 0; i < count; i++) {
FindModuleView *fmview = [fmviews objectAtIndex: i];
NSBox *fmbox = [fmview mainBox];
NSRect mbr = [fmbox frame];
float posy = mbrect.size.height - (FMVIEWH * (i + 1)) - BORDER;
if (mbr.origin.y != posy) {
mbr.origin.y = posy;
[fmbox setFrame: mbr];
}
}
}
- (NSWindow *)win
{
return win;
}
//
// NSWindow delegate
//
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
}
- (BOOL)windowShouldClose:(id)sender
{
return YES;
}
- (void)windowWillClose:(NSNotification *)aNotification
{
[folder saveSizes];
}
@end
|