Skip to content

Commit 1af6a18

Browse files
author
Jean-Francois Moy
committed
Line number view width updated directly in all opened documents when modified in general preferences
1 parent f119fa8 commit 1af6a18

File tree

11 files changed

+242
-116
lines changed

11 files changed

+242
-116
lines changed

Classes/FRAInterfacePerformer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,6 @@ Unless required by applicable law or agreed to in writing, software distributed
7070

7171
- (void)changeViewWithAnimationForWindow:(NSWindow *)window oldView:(NSView *)oldView newView:(NSView *)newView newRect:(NSRect)newRect;
7272

73+
- (void) updateGutterViewForDocument:(id)document;
74+
7375
@end

Classes/FRAInterfacePerformer.m

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ - (void)insertDocumentIntoSecondContentView:(id)document
138138
[textStorage addLayoutManager:layoutManager];
139139
[[document valueForKey:@"syntaxColouring"] setSecondLayoutManager:layoutManager];
140140

141-
NSInteger gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
141+
u_int16_t gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
142142

143143
NSView *secondContentViewNavigationBar = [FRACurrentProject secondContentViewNavigationBar];
144144
CGFloat secondContentViewNavigationBarHeight = [secondContentViewNavigationBar bounds].size.height;
@@ -237,7 +237,7 @@ - (void)insertDocumentIntoThirdContentView:(id)document orderFront:(BOOL)orderFr
237237
[textStorage addLayoutManager:layoutManager];
238238
[[document valueForKey:@"syntaxColouring"] setThirdLayoutManager:layoutManager];
239239

240-
NSInteger gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
240+
u_int16_t gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
241241

242242
NSScrollView *textScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(gutterWidth, -1, [thirdContentView bounds].size.width - gutterWidth, [thirdContentView bounds].size.height + 2)]; // +2 and -1 to remove extra line at the top and bottom
243243
NSSize contentSize = [textScrollView contentSize];
@@ -305,7 +305,7 @@ - (void)insertDocumentIntoFourthContentView:(id)document
305305
[textStorage addLayoutManager:layoutManager];
306306
[[document valueForKey:@"syntaxColouring"] setFourthLayoutManager:layoutManager];
307307

308-
NSInteger gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
308+
u_int16_t gutterWidth = [[document valueForKey:@"firstGutterScrollView"] bounds].size.width;
309309

310310
NSView *fourthContentView = [[FRAAdvancedFindController sharedInstance] resultDocumentContentView];
311311

@@ -361,8 +361,62 @@ - (void)insertDocumentIntoFourthContentView:(id)document
361361
[document setValue:gutterScrollView forKey:@"fourthGutterScrollView"];
362362
}
363363

364+
/**
365+
* Update gutter views to adjust its size to newly defined width for the specified
366+
* document. It refreshes every views used to display the document afterwards.
367+
**/
368+
- (void) updateGutterViewForDocument:(id)document {
369+
NSArray *viewNumbers = [NSArray arrayWithObjects:@"first",@"second", @"third", nil];
370+
NSView *contentView = nil;
371+
u_int16_t gutterWidth = [[FRADefaults valueForKey:@"GutterWidth"] integerValue];
372+
NSRect frame;
373+
374+
// Update document value first.
375+
[document setValue:[NSNumber numberWithUnsignedInt:gutterWidth] forKey:@"gutterWidth"];
376+
377+
for (NSString* viewNumber in viewNumbers) {
378+
NSScrollView *gutterScrollView = (NSScrollView *) [document valueForKey:[NSString stringWithFormat:@"%@GutterScrollView", viewNumber]];
379+
NSTextView *textView = (NSTextView *)[document valueForKey:[NSString stringWithFormat:@"%@TextView", viewNumber]];
380+
NSScrollView *textScrollView = (NSScrollView *)[document valueForKey:[NSString stringWithFormat:@"%@TextScrollView", viewNumber]];
381+
382+
if ([viewNumber isEqualToString:@"first"]) {
383+
contentView = [FRACurrentProject firstContentView];
384+
}
385+
else if ([viewNumber isEqualToString:@"second"]) {
386+
contentView = [FRACurrentProject secondContentView];
387+
}
388+
else if ([viewNumber isEqualToString:@"third"]) {
389+
if ([document valueForKey:@"singleDocumentWindow"] == nil) {
390+
continue;
391+
}
392+
contentView = [[document valueForKey:@"singleDocumentWindow"] contentView];
393+
}
394+
395+
// Text Scroll View
396+
if (textScrollView != nil) {
397+
frame = [textScrollView frame];
398+
[textScrollView setFrame:NSMakeRect(gutterWidth, frame.origin.y, [contentView bounds].size.width - gutterWidth, frame.size.height)];
399+
[textScrollView setNeedsDisplay:YES];
400+
}
401+
402+
// Text View
403+
if (textView != nil) {
404+
frame = [textView frame];
405+
[textView setFrame:NSMakeRect(gutterWidth, frame.origin.y, [contentView bounds].size.width - gutterWidth, frame.size.height)];
406+
[textView setNeedsDisplay:YES];
407+
}
408+
409+
// Gutter Scroll View
410+
if (gutterScrollView != nil) {
411+
frame = [gutterScrollView frame];
412+
[gutterScrollView setFrame:NSMakeRect(frame.origin.x, frame.origin.y, gutterWidth, frame.size.height)];
413+
[gutterScrollView setNeedsDisplay:YES];
414+
}
415+
}
416+
}
417+
364418

365-
- (void)updateStatusBar
419+
- (void) updateStatusBar
366420
{
367421
if ([[FRADefaults valueForKey:@"ShowStatusBar"] boolValue] == NO) {
368422
return;

Classes/FRAPreferencesController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Unless required by applicable law or agreed to in writing, software distributed
6262
- (IBAction)openSetFolderAction:(id)sender;
6363
- (IBAction)saveAsSetFolderAction:(id)sender;
6464

65-
65+
- (IBAction)changeGutterWidth:(id)sender;
6666

6767
- (NSManagedObjectContext *)managedObjectContext;
6868

Classes/FRAPreferencesController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "FRAMainController.h"
2828
#import "FRAApplicationDelegate.h"
2929
#import "FRAProject.h"
30+
#import "FRALineNumbers.h"
3031
#import "NSToolbarItem+Fraise.h"
3132

3233
@implementation FRAPreferencesController
@@ -599,6 +600,13 @@ - (void)saveAsPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode
599600
}
600601
}
601602

603+
- (IBAction)changeGutterWidth:(id)sender {
604+
NSEnumerator *documentEnumerator = [[[FRACurrentProject documentsArrayController] arrangedObjects] objectEnumerator];
605+
for (id document in documentEnumerator) {
606+
[FRAInterface updateGutterViewForDocument:document];
607+
[[document valueForKey:@"lineNumbers"] updateLineNumbersCheckWidth:YES recolour:YES];
608+
}
609+
}
602610

603611
- (NSManagedObjectContext *)managedObjectContext
604612
{

English.lproj/FRAPreferencesGeneral.xib

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,6 @@
852852
<string key="NSExtension">NSResponder</string>
853853
</object>
854854
<object class="NSUserDefaultsController" id="478176690">
855-
<object class="NSMutableArray" key="NSDeclaredKeys">
856-
<bool key="EncodedWithXMLCoder">YES</bool>
857-
<string>automaticallyChecksForUpdates</string>
858-
</object>
859855
<bool key="NSSharedInstance">YES</bool>
860856
</object>
861857
<object class="NSCustomObject" id="479498089">
@@ -1177,6 +1173,14 @@
11771173
</object>
11781174
<int key="connectionID">182</int>
11791175
</object>
1176+
<object class="IBConnectionRecord">
1177+
<object class="IBActionConnection" key="connection">
1178+
<string key="label">changeGutterWidth:</string>
1179+
<reference key="source" ref="1034643593"/>
1180+
<reference key="destination" ref="811493167"/>
1181+
</object>
1182+
<int key="connectionID">183</int>
1183+
</object>
11801184
</object>
11811185
<object class="IBMutableOrderedSet" key="objectRecords">
11821186
<object class="NSArray" key="orderedObjects">
@@ -1678,7 +1682,6 @@
16781682
<string>156.IBPluginDependency</string>
16791683
<string>157.IBPluginDependency</string>
16801684
<string>160.IBPluginDependency</string>
1681-
<string>161.IBPluginDependency</string>
16821685
<string>162.IBPluginDependency</string>
16831686
<string>163.IBPluginDependency</string>
16841687
<string>171.IBPluginDependency</string>
@@ -1775,14 +1778,13 @@
17751778
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17761779
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17771780
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
1778-
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17791781
<string>{{745, 671}, {121, 83}}</string>
17801782
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17811783
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17821784
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17831785
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17841786
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
1785-
<string>{{401, 387}, {600, 398}}</string>
1787+
<string>{{407, 43}, {600, 398}}</string>
17861788
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17871789
<integer value="1"/>
17881790
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1855,41 +1857,19 @@
18551857
</object>
18561858
</object>
18571859
<nil key="sourceID"/>
1858-
<int key="maxID">182</int>
1860+
<int key="maxID">183</int>
18591861
</object>
18601862
<object class="IBClassDescriber" key="IBDocument.Classes">
18611863
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
18621864
<bool key="EncodedWithXMLCoder">YES</bool>
1863-
<object class="IBPartialClassDescription">
1864-
<string key="className">FirstResponder</string>
1865-
<string key="superclassName">NSObject</string>
1866-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1867-
<string key="majorKey">IBUserSource</string>
1868-
<string key="minorKey"/>
1869-
</object>
1870-
</object>
1871-
<object class="IBPartialClassDescription">
1872-
<string key="className">NSObject</string>
1873-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1874-
<string key="majorKey">IBProjectSource</string>
1875-
<string key="minorKey">PSMTabBar/PSMTabBarControl.h</string>
1876-
</object>
1877-
</object>
1878-
<object class="IBPartialClassDescription">
1879-
<string key="className">NSObject</string>
1880-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1881-
<string key="majorKey">IBUserSource</string>
1882-
<string key="minorKey"/>
1883-
</object>
1884-
</object>
18851865
<object class="IBPartialClassDescription">
18861866
<string key="className">FRAPreferencesController</string>
18871867
<string key="superclassName">NSObject</string>
18881868
<object class="NSMutableDictionary" key="actions">
18891869
<bool key="EncodedWithXMLCoder">YES</bool>
18901870
<object class="NSArray" key="dict.sortedKeys">
18911871
<bool key="EncodedWithXMLCoder">YES</bool>
1892-
<string>checkNowAction:</string>
1872+
<string>changeGutterWidth:</string>
18931873
<string>openSetFolderAction:</string>
18941874
<string>revertToStandardSettingsAction:</string>
18951875
<string>saveAsSetFolderAction:</string>
@@ -1915,7 +1895,6 @@
19151895
<string>encodingsTableView</string>
19161896
<string>generalView</string>
19171897
<string>lastSavedFormatPopUp</string>
1918-
<string>noUpdateAvailableTextField</string>
19191898
<string>openSaveView</string>
19201899
<string>preferencesWindow</string>
19211900
<string>syntaxColouringPopUp</string>
@@ -1931,7 +1910,6 @@
19311910
<string>NSTableView</string>
19321911
<string>NSView</string>
19331912
<string>NSPopUpButton</string>
1934-
<string>NSTextField</string>
19351913
<string>NSView</string>
19361914
<string>NSWindow</string>
19371915
<string>NSPopUpButton</string>
@@ -1956,6 +1934,28 @@
19561934
<string key="minorKey"/>
19571935
</object>
19581936
</object>
1937+
<object class="IBPartialClassDescription">
1938+
<string key="className">FirstResponder</string>
1939+
<string key="superclassName">NSObject</string>
1940+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1941+
<string key="majorKey">IBUserSource</string>
1942+
<string key="minorKey"/>
1943+
</object>
1944+
</object>
1945+
<object class="IBPartialClassDescription">
1946+
<string key="className">NSObject</string>
1947+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1948+
<string key="majorKey">IBProjectSource</string>
1949+
<string key="minorKey">PSMTabBar/PSMTabBarControl.h</string>
1950+
</object>
1951+
</object>
1952+
<object class="IBPartialClassDescription">
1953+
<string key="className">NSObject</string>
1954+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1955+
<string key="majorKey">IBUserSource</string>
1956+
<string key="minorKey"/>
1957+
</object>
1958+
</object>
19591959
</object>
19601960
<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+">
19611961
<bool key="EncodedWithXMLCoder">YES</bool>

French.lproj/FRAPreferencesGeneral.xib

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,14 @@
11801180
</object>
11811181
<int key="connectionID">182</int>
11821182
</object>
1183+
<object class="IBConnectionRecord">
1184+
<object class="IBActionConnection" key="connection">
1185+
<string key="label">changeGutterWidth:</string>
1186+
<reference key="source" ref="1034643593"/>
1187+
<reference key="destination" ref="811493167"/>
1188+
</object>
1189+
<int key="connectionID">183</int>
1190+
</object>
11831191
</object>
11841192
<object class="IBMutableOrderedSet" key="objectRecords">
11851193
<object class="NSArray" key="orderedObjects">
@@ -1783,7 +1791,7 @@
17831791
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17841792
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17851793
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
1786-
<string>{{401, 365}, {640, 420}}</string>
1794+
<string>{{385, 143}, {640, 420}}</string>
17871795
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
17881796
<integer value="1"/>
17891797
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1856,7 +1864,7 @@
18561864
</object>
18571865
</object>
18581866
<nil key="sourceID"/>
1859-
<int key="maxID">182</int>
1867+
<int key="maxID">183</int>
18601868
</object>
18611869
<object class="IBClassDescriber" key="IBDocument.Classes">
18621870
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1868,6 +1876,7 @@
18681876
<bool key="EncodedWithXMLCoder">YES</bool>
18691877
<object class="NSArray" key="dict.sortedKeys">
18701878
<bool key="EncodedWithXMLCoder">YES</bool>
1879+
<string>changeGutterWidth:</string>
18711880
<string>openSetFolderAction:</string>
18721881
<string>revertToStandardSettingsAction:</string>
18731882
<string>saveAsSetFolderAction:</string>
@@ -1879,6 +1888,7 @@
18791888
<string>id</string>
18801889
<string>id</string>
18811890
<string>id</string>
1891+
<string>id</string>
18821892
</object>
18831893
</object>
18841894
<object class="NSMutableDictionary" key="outlets">

0 commit comments

Comments
 (0)