• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheで画像のインラインプレビューを可能にするプラグイン


Commit MetaInfo

Revisiond990fa155c76fee2a9ef778e335053729b3985fd (tree)
Time2012-05-20 13:49:39
Authormasakih <masakih@user...>
Commitermasakih

Log Message

[Refactor] NSStringリテラルを一カ所にまとめた

Change Summary

Incremental Difference

--- a/Ex/BSIPEReplacer.m
+++ b/Ex/BSIPEReplacer.m
@@ -14,6 +14,12 @@
1414 - (NSAttributedString *)attachmentAttributedStringWithImage:(NSImage *)image;
1515 @end
1616
17+static NSString *BSIPEViewkey = @"BSIPEViewkey";
18+static NSString *BSIPERangeKey = @"BSIPERangeKey";
19+static NSString *BSIPEImageKey = @"BSIPEImageKey";
20+static NSString *BSIPEOffsetKey = @"BSIPEOffsetKey";
21+static NSString *BSIPELinkKey = @"BSIPELinkKey";
22+
1723 @interface BSIPEReplacer ()
1824 // 画像挿入によって引き起こしたNSTextStorageDidProcessEditingNotificationの回数
1925 @property NSUInteger selfNotified;
@@ -119,10 +125,10 @@ NSRange fixRange(NSRange range, NSTextStorage *ts)
119125 }
120126 - (void)insertImage:(NSDictionary *)attr
121127 {
122- NSTextView *tv = [attr objectForKey:@"View"];
123- NSRange range = NSRangeFromString([attr objectForKey:@"Range"]);
124- id newInsertion = [attr objectForKey:@"Image"];
125- NSUInteger offset = [[attr objectForKey:@"Offset"] unsignedIntegerValue];
128+ NSTextView *tv = [attr objectForKey:BSIPEViewkey];
129+ NSRange range = NSRangeFromString([attr objectForKey:BSIPERangeKey]);
130+ id newInsertion = [attr objectForKey:BSIPEImageKey];
131+ NSUInteger offset = [[attr objectForKey:BSIPEOffsetKey] unsignedIntegerValue];
126132 range.location += offset;
127133
128134 NSTextStorage *ts = [tv textStorage];
@@ -164,8 +170,8 @@ NSRange fixRange(NSRange range, NSTextStorage *ts)
164170 usingBlock:^(id value, NSRange range, BOOL *stop) {
165171 NSURL *url = [NSURL URLWithString:value];
166172 if([self.owner validateLink:url]) {
167- [links addObject:[NSDictionary dictionaryWithObjectsAndKeys:url, @"Link",
168- NSStringFromRange(range), @"Range", nil]];
173+ [links addObject:[NSDictionary dictionaryWithObjectsAndKeys:url, BSIPELinkKey,
174+ NSStringFromRange(range), BSIPERangeKey, nil]];
169175 }
170176 }];
171177
@@ -175,22 +181,22 @@ NSRange fixRange(NSRange range, NSTextStorage *ts)
175181 if(!self.textView) return;
176182
177183 id dict = [links objectAtIndex:index];
178- NSRange range = NSRangeFromString([dict objectForKey:@"Range"]);
184+ NSRange range = NSRangeFromString([dict objectForKey:BSIPERangeKey]);
179185 if([ts attribute:BSInlinePreviewerPreviewed atIndex:range.location longestEffectiveRange:NULL inRange:range]) {
180186 return;
181187 }
182188 // download image.
183- NSImage *image = [self.owner downloadImageURL:[dict objectForKey:@"Link"]];
189+ NSImage *image = [self.owner downloadImageURL:[dict objectForKey:BSIPELinkKey]];
184190 if(!image) return;
185191
186192 id newInsertion = [self.owner attachmentAttributedStringWithImage:image];
187193
188194
189195 NSDictionary *attr = [[NSDictionary alloc] initWithObjectsAndKeys:
190- newInsertion, @"Image",
191- [dict objectForKey:@"Range"], @"Range",
192- self.textView, @"View",
193- [NSNumber numberWithUnsignedInteger:offset], @"Offset",
196+ newInsertion, BSIPEImageKey,
197+ [dict objectForKey:BSIPERangeKey], BSIPERangeKey,
198+ self.textView, BSIPEViewkey,
199+ [NSNumber numberWithUnsignedInteger:offset], BSIPEOffsetKey,
194200 nil];
195201 [self performSelectorOnMainThread:@selector(insertImage:) withObject:attr waitUntilDone:NO];
196202 offset += [newInsertion length];