From 9c06d1219c66acc043b5f13ab29379f60eb00350 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 28 Jul 2009 01:02:40 +0000 Subject: Improve TablesList significantly: - If there are twenty or more tables, show a table quicksearch/filter at the top of the list, and update the rest of the code to match. This addresses issue #178. - Select tables and views alphabetically by user's current locale (instead of default MySQL "A B C a b c") - When adding or duplicating tables, insert them at the correct point - Fix a number of minor display bugs caused by incorrect interaction with the tables list caches --- Source/NSMutableArray-MultipleSort.h | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Source/NSMutableArray-MultipleSort.h (limited to 'Source/NSMutableArray-MultipleSort.h') diff --git a/Source/NSMutableArray-MultipleSort.h b/Source/NSMutableArray-MultipleSort.h new file mode 100644 index 00000000..91c8f3f2 --- /dev/null +++ b/Source/NSMutableArray-MultipleSort.h @@ -0,0 +1,54 @@ +// +// NSMutableArray-MultipleSort.h +// iContractor +// +// Created by Jeff LaMarche on 1/16/09. +// Copyright 2009 Jeff LaMarche. All rights reserved. +// + +// This category on NSMutableArray implements a shell sort based on the old NeXT example +// SortingInAction. It is functionally identical to sortArrayUsingSelector: except that +// it will sort other paired arrays based on the comparison values of the original array +// this is for use in paired array situations, such as when you use one array to store +// keys and another array to store values. This is a variadic method, so you can sort +// as many paired arrays as you have. + +// This source may be used, free of charge, for any purposes. commercial or non- +// commercial. There is no attribution requirement, nor any need to distribute +// your source code. If you do redistribute the source code, you must +// leave the original header comments, but you may add additional ones. + + +// Stride factor defines the size of the shell sort loop's stride. It can be tweaked +// for performance, though 3 seems to be a good general purpose value +#define STRIDE_FACTOR 3 + +#import + +// This compare method was taken from the GNUStep project. GNUStep is +// licensed under the LGPL, which allows such use. +static inline NSComparisonResult compare(id elem1, id elem2, void* context) +{ + NSComparisonResult (*imp)(id, SEL, id); + + if (context == 0) { + [NSException raise: NSInvalidArgumentException + format: @"compare null selector given"]; + } + + imp = (NSComparisonResult (*)(id, SEL, id)) + [elem1 methodForSelector: context]; + + if (imp == NULL) { + [NSException raise: NSGenericException + format: @"invalid selector passed to compare"]; + } + + return (*imp)(elem1, context, elem2); +} + +@interface NSMutableArray(MultipleSort) + +// Takes a comparator and a nil-terminated list of paired arrays +- (void)sortArrayUsingSelector:(SEL)comparator withPairedMutableArrays:(NSMutableArray *)array1, ...; +@end -- cgit v1.2.3