Display recent used styles at the top of list (close #553)

This commit is contained in:
1024jp 2016-05-10 16:17:38 +09:00
parent eda8454d58
commit c47d45b595
11 changed files with 73 additions and 5 deletions

View File

@ -5,6 +5,11 @@ Change Log
develop
--------------------------
### New Features
- Display recent used syntax styles at the top of the toolbar syntax style popup list.
### Improvements
- Drop support for __OS X Mountain Lion__ and __Mavericks__.

View File

@ -67,10 +67,10 @@
<popUpButton key="view" verticalHuggingPriority="750" tag="3" id="RTF-Xf-Dgz">
<rect key="frame" x="0.0" y="14" width="120" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" id="hb4-gd-uwc">
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" autoenablesItems="NO" id="hb4-gd-uwc">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" id="plp-5x-eBz"/>
<menu key="menu" autoenablesItems="NO" id="plp-5x-eBz"/>
</popUpButtonCell>
</popUpButton>
</toolbarItem>

View File

@ -229,6 +229,7 @@
CEDefaultSavesTextOrientationKey: @YES,
CEDefaultLayoutTextVerticalKey: @NO,
CEDefaultEnableSmartIndentKey: @YES,
CEDefaultRecentlyUsedStylesLimitKey: @6U,
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];

View File

@ -157,6 +157,7 @@ extern NSString *_Nonnull const CEDefaultFindRegexUsesUnicodeBoundariesKey;
// settings that are not in preferences
extern NSString *_Nonnull const CEDefaultColorCodeTypeKey;
extern NSString *_Nonnull const CEDefaultSidebarWidthKey;
extern NSString *_Nonnull const CEDefaultRecentlyUsedStyleNamesKey;
// hidden settings
extern NSString *_Nonnull const CEDefaultLineNumFontNameKey;
@ -176,6 +177,7 @@ extern NSString *_Nonnull const CEDefaultAutosavingDelayKey;
extern NSString *_Nonnull const CEDefaultSavesTextOrientationKey;
extern NSString *_Nonnull const CEDefaultLayoutTextVerticalKey;
extern NSString *_Nonnull const CEDefaultEnableSmartIndentKey;
extern NSString *_Nonnull const CEDefaultRecentlyUsedStylesLimitKey;
extern NSString *_Nonnull const CEDefaultLastVersionKey;

View File

@ -157,6 +157,7 @@ NSString *_Nonnull const CEDefaultFindRegexUsesUnicodeBoundariesKey = @"regexUse
// settings that are not in preferences
NSString *_Nonnull const CEDefaultColorCodeTypeKey = @"colorCodeType";
NSString *_Nonnull const CEDefaultSidebarWidthKey = @"sidebarWidth";
NSString *_Nonnull const CEDefaultRecentlyUsedStyleNamesKey = @"recentlyUsedStyleNames";
// hidden settings
NSString *_Nonnull const CEDefaultLineNumFontNameKey = @"lineNumFontName";
@ -176,5 +177,6 @@ NSString *_Nonnull const CEDefaultAutosavingDelayKey = @"autosavingDelay";
NSString *_Nonnull const CEDefaultSavesTextOrientationKey = @"savesTextOrientation";
NSString *_Nonnull const CEDefaultLayoutTextVerticalKey = @"layoutTextVertical";
NSString *_Nonnull const CEDefaultEnableSmartIndentKey = @"enableSmartIndent";
NSString *_Nonnull const CEDefaultRecentlyUsedStylesLimitKey = @"recentlyUsedStylesLimit";
NSString *_Nonnull const CEDefaultLastVersionKey = @"lastVersion";

View File

@ -33,6 +33,9 @@
/// Posted when the line-up of syntax styles is updated. This will be used for syntax style menus.
extern NSString *_Nonnull const CESyntaxListDidUpdateNotification;
/// Posted when the recently used style list is updated. This will be used for syntax style menu in toolbar.
extern NSString *_Nonnull const CESyntaxHistoryDidUpdateNotification;
/// Posted when a syntax style is updated. Information about new/previous style name is in userInfo.
extern NSString *_Nonnull const CESyntaxDidUpdateNotification;
@ -50,6 +53,7 @@ extern NSString *_Nonnull const CESyntaxValidationMessageKey;
// readonly
@property (readonly, nonatomic, nonnull, copy) NSArray<NSString *> *styleNames;
@property (readonly, nonatomic, nonnull, copy) NSArray<NSString *> *recentlyUsedStyleNames;
/// conflict error dicts
@property (readonly, nonatomic, nonnull, copy) NSDictionary<NSString *, NSMutableArray<NSString *> *> *extensionConflicts;
@property (readonly, nonatomic, nonnull, copy) NSDictionary<NSString *, NSMutableArray<NSString *> *> *filenameConflicts;

View File

@ -30,6 +30,7 @@
#import "CESyntaxStyle.h"
#import "CEAppDelegate.h"
#import "CESyntaxDictionaryKeys.h"
#import "CEDefaults.h"
#import "Constants.h"
#import <YAML-Framework/YAMLSerialization.h>
@ -38,6 +39,7 @@
// notifications
NSString *_Nonnull const CESyntaxListDidUpdateNotification = @"CESyntaxListDidUpdateNotification";
NSString *_Nonnull const CESyntaxDidUpdateNotification = @"CESyntaxDidUpdateNotification";
NSString *_Nonnull const CESyntaxHistoryDidUpdateNotification = @"CESyntaxHistoryDidUpdateNotification";
// keys for validation result
NSString *_Nonnull const CESyntaxValidationTypeKey = @"SyntaxTypeKey";
@ -48,6 +50,7 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
@interface CESyntaxManager ()
@property (nonatomic, nonnull, copy) NSMutableOrderedSet<NSString *> *recentlyUsedStyleNameSet;
@property (nonatomic, nonnull) NSMutableDictionary<NSString *, NSMutableDictionary *> *styleCaches; //
@property (nonatomic, nonnull, copy) NSDictionary<NSString *, NSDictionary<NSString *, NSArray *> *> *map; // style/
@ -101,6 +104,7 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
{
self = [super init];
if (self) {
_recentlyUsedStyleNameSet = [NSMutableOrderedSet orderedSetWithArray:[[NSUserDefaults standardUserDefaults] stringArrayForKey:CEDefaultRecentlyUsedStyleNamesKey]];
_styleCaches = [NSMutableDictionary dictionary];
// style
@ -122,20 +126,40 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
#pragma mark Public Methods
// ------------------------------------------------------
/// return recently used style history as an array
- (nonnull NSArray<NSString *> *)recentlyUsedStyleNames
// ------------------------------------------------------
{
NSUInteger itemNumber = MIN([[self recentlyUsedStyleNameSet] count], [[NSUserDefaults standardUserDefaults] integerForKey:CEDefaultRecentlyUsedStylesLimitKey]);
return [[[self recentlyUsedStyleNameSet] array] subarrayWithRange:NSMakeRange(0, itemNumber)];
}
// ------------------------------------------------------
/// create new CESyntaxStyle instance
- (nullable CESyntaxStyle *)styleWithName:(NSString *)styleName
// ------------------------------------------------------
{
CESyntaxStyle *style = nil;
if (!styleName || [styleName isEqualToString:NSLocalizedString(@"None", nil)]) {
return [[CESyntaxStyle alloc] initWithDictionary:nil name:NSLocalizedString(@"None", nil)];
style = [[CESyntaxStyle alloc] initWithDictionary:nil name:NSLocalizedString(@"None", nil)];
} else if ([[self styleNames] containsObject:styleName]) {
NSDictionary<NSString *, id> *highlightDictionary = [self styleDictionaryWithStyleName:styleName];
return [[CESyntaxStyle alloc] initWithDictionary:highlightDictionary name:styleName];
style = [[CESyntaxStyle alloc] initWithDictionary:highlightDictionary name:styleName];
}
return nil;
if (style) {
[[self recentlyUsedStyleNameSet] removeObject:styleName];
[[self recentlyUsedStyleNameSet] insertObject:styleName atIndex:0];
[[NSUserDefaults standardUserDefaults] setObject:[self recentlyUsedStyleNames] forKey:CEDefaultRecentlyUsedStyleNamesKey];
[[NSNotificationCenter defaultCenter] postNotificationName:CESyntaxHistoryDidUpdateNotification
object:self];
}
return style;
}
@ -788,6 +812,11 @@ NSString *_Nonnull const CESyntaxValidationMessageKey = @"MessageKey";
NSMutableArray<NSString *> *styleNames = [[map allKeys] mutableCopy];
[styleNames sortUsingSelector:@selector(caseInsensitiveCompare:)];
[self setStyleNames:styleNames];
// remove deleted styles
// -> don't care about style name change just for laziness
[[self recentlyUsedStyleNameSet] intersectSet:[NSSet setWithArray:styleNames]];
[[NSUserDefaults standardUserDefaults] setObject:[self recentlyUsedStyleNames] forKey:CEDefaultRecentlyUsedStyleNamesKey];
}

View File

@ -89,6 +89,11 @@
selector:@selector(buildSyntaxPopupButton)
name:CESyntaxListDidUpdateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(buildSyntaxPopupButton)
name:CESyntaxHistoryDidUpdateNotification
object:nil];
}
@ -217,12 +222,29 @@
// ------------------------------------------------------
{
NSArray<NSString *> *styleNames = [[CESyntaxManager sharedManager] styleNames];
NSArray<NSString *> *recentlyUsedStyleNames = [[CESyntaxManager sharedManager] recentlyUsedStyleNames];
[[self syntaxPopupButton] removeAllItems];
[[[self syntaxPopupButton] menu] addItemWithTitle:NSLocalizedString(@"None", nil)
action:@selector(changeSyntaxStyle:)
keyEquivalent:@""];
[[[self syntaxPopupButton] menu] addItem:[NSMenuItem separatorItem]];
if ([recentlyUsedStyleNames count] > 0) {
NSMenuItem *titleItem = [[NSMenuItem alloc] init];
[titleItem setTitle:NSLocalizedString(@"Recently Used", @"menu heading in syntax style list on toolbar popup")];
[titleItem setEnabled:NO];
[[[self syntaxPopupButton] menu] addItem:titleItem];
for (NSString *styleName in recentlyUsedStyleNames) {
[[[self syntaxPopupButton] menu] addItemWithTitle:styleName
action:@selector(changeSyntaxStyle:)
keyEquivalent:@""];
}
[[[self syntaxPopupButton] menu] addItem:[NSMenuItem separatorItem]];
}
for (NSString *styleName in styleNames) {
[[[self syntaxPopupButton] menu] addItemWithTitle:styleName
action:@selector(changeSyntaxStyle:)

View File

@ -47,6 +47,7 @@
"Auto-Detect" = "Auto-Erkennung";
// Format - Syntax coloring menu item title
"None" = "Ohne";
"Recently Used" = "Zuletzt Benutzt";
"Re-Color All" = "Alles umfärben";
// Importing theme

View File

@ -48,6 +48,7 @@
"Auto-Detect" = "自動認識";
// Format - Syntax coloring menu item title
"None" = "なし";
"Recently Used" = "最近使った項目";
"Re-Color All" = "再カラーリング";
// Importing theme

View File

@ -47,6 +47,7 @@
"Auto-Detect" = "自动检测";
// Format - Syntax coloring menu item title
"None" = "无";
"Recently Used" = "最近使用";
"Re-Color All" = "全部重新着色";
// Importing theme