public
Description: A popular sample Cocoa application rewritten in Nu. Original code by Aaron Hillegass, ported to Nu by Tim Burks.
Homepage: http://programming.nu/posts/2007/12/12/nupagepacker
Clone URL: git://github.com/timburks/nupagepacker.git
Render unto Objective-C that which is Objective-C's...

Return a few hard-to-convert methods to Objective-C.
Renamed the application "NuPagePacker" to avoid confusion
with Aaron's work.
timburks (author)
Tue Nov 27 13:07:56 -0800 2007
commit  c1f2fb8d664e9f0452fe0b73e1297c0ab048b087
tree    e46e86a15dd23c18ee88ff9e0feb6ecc0cdf3d3b
parent  acad4ca1d96d4d91109bdfecd11233ac15b05917
...
18
19
20
21
 
22
23
24
25
 
26
27
28
...
34
35
36
37
38
 
 
39
40
41
...
18
19
20
 
21
22
23
24
 
25
26
27
28
...
34
35
36
 
 
37
38
39
40
41
0
@@ -18,11 +18,11 @@
0
                         "CFBundleTypeName" "DocumentType"
0
                         "CFBundleTypeRole" "Editor"
0
                         "NSDocumentClass" "MyDocument"))
0
- "CFBundleExecutable" "PagePacker"
0
+ "CFBundleExecutable" "NuPagePacker"
0
            "CFBundleHelpBookFolder" "PagePackerHelp"
0
            "CFBundleHelpBookName" "PagePacker Help"
0
            "CFBundleIconFile" "PPApp"
0
- "CFBundleIdentifier" "nu.programming.PagePacker"
0
+ "CFBundleIdentifier" "nu.programming.NuPagePacker"
0
            "CFBundleInfoDictionaryVersion" "6.0"
0
            "CFBundleName" "PagePacker"
0
            "CFBundlePackageType" "APPL"
0
@@ -34,8 +34,8 @@
0
            "OSAScriptingDefinition" "PagePacker.sdef"))
0
 
0
 ;; application description
0
-(set @application "PagePacker")
0
-(set @application_identifier "nu.programming.pagepacker")
0
+(set @application "NuPagePacker")
0
+(set @application_identifier "nu.programming.nupagepacker")
0
 (set @application_icon_file "PPApp.icns")
0
 (set @application_help_folder "PagePackerHelp")
0
 
...
29
30
31
 
32
33
 
 
34
35
36
...
69
70
71
72
73
 
74
75
76
...
95
96
97
98
99
100
101
 
 
 
102
103
104
...
191
192
193
194
195
 
196
197
198
...
380
381
382
383
 
384
385
386
...
477
478
479
480
481
482
483
...
497
498
499
500
501
502
503
504
505
506
507
508
509
 
510
511
512
...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
775
776
777
778
 
779
780
781
...
791
792
793
 
794
795
796
...
807
808
809
810
811
812
813
814
...
29
30
31
32
33
 
34
35
36
37
38
...
71
72
73
 
 
74
75
76
77
...
96
97
98
 
 
 
 
99
100
101
102
103
104
...
191
192
193
 
 
194
195
196
197
...
379
380
381
 
382
383
384
385
...
476
477
478
 
479
480
481
...
495
496
497
 
 
 
 
 
 
 
 
 
 
498
499
500
501
...
666
667
668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
670
671
672
673
674
 
 
 
675
676
677
...
745
746
747
 
748
749
750
751
...
761
762
763
764
765
766
767
...
778
779
780
 
 
781
782
783
0
@@ -29,8 +29,10 @@
0
         (@pdfView setDocument:pdfDoc)
0
         (@pdfView setDisplayMode:kPDFDisplaySinglePage)
0
         (set w (@pdfView window))
0
+(NSLog "window #{w}, self #{self}")
0
         (w setBecomesKeyOnlyIfNeeded:YES)
0
- (w setNextResponder:self))
0
+ (w setNextResponder:self)
0
+)
0
      
0
      (- (void)changeToPage:(int)i is
0
         (unless (eq @currentPageIndex i)
0
@@ -69,8 +71,7 @@
0
         (@pageSlider setIntValue:@currentPageIndex)))
0
 
0
 
0
-(class MyDocument is NSDocument
0
- (ivar (id) packModel (id) packerView)
0
+(class MyDocument
0
      
0
      (- (id)init is
0
         (super init)
0
@@ -95,10 +96,9 @@
0
         (set @packModel (NSKeyedUnarchiver unarchiveObjectWithData:data))
0
         (@packModel setUndoManager:(self undoManager))
0
         (if @packerView (self updateUI))
0
- YES)
0
-
0
- (- (id)printOperationWithSettings:(id)printSettings error:(id)outError is ;; last type should be "NSError **"
0
- (NSPrintOperation printOperationWithView:packerView printInfo:(self printInfo))))
0
+ YES))
0
+
0
+
0
 
0
 (global NSDragOperationCopy 1)
0
 (global NSPDFPboardType "Apple PDF pasteboard type")
0
@@ -191,8 +191,7 @@
0
      (- (void) replacePageInfoAt:(int) i withPageInfo:(id) pi is
0
         (set oldInfo (@pageInfos objectAtIndex:i))
0
         (unless (eq pi oldInfo)
0
- ;; invocation-based undo is broken
0
- ;((@undoManager prepareWithInvocationTarget:self) replacePageInfoAt:i withPageInfo:oldInfo)
0
+ ((@undoManager prepareWithInvocationTarget:self) replacePageInfoAt:i withPageInfo:oldInfo)
0
                 (@pageInfos replaceObjectAtIndex:i withObject:pi)
0
                 ((NSNotificationCenter defaultCenter) postNotificationName:"PackModelChangedNotification" object:self userInfo:NULL)))
0
      
0
@@ -380,7 +379,7 @@
0
 
0
 (set $numberAttributes nil)
0
 
0
-(class PackerView is NSView
0
+(class PackerView
0
      (ivar (id) packModel
0
            (id) foldLines
0
            (id) cutLine
0
@@ -477,7 +476,6 @@
0
         
0
         
0
         (set @foldLines (NSBezierPath bezierPath))
0
- ;(set $foldLines @foldLines) ;; there is a memory problem. This keeps @foldlines from being released.
0
         
0
         (@foldLines setLineWidth:1.0)
0
         
0
@@ -497,16 +495,7 @@
0
         (@foldLines moveToPoint:(list midV lowerH))
0
         (@foldLines lineToPoint:(list midV bottom))
0
         
0
- ;float dashes[2] = {7.0, 3.0};
0
- (set @cutLine (NSBezierPath bezierPath))
0
- (set $cutLine @cutLine) ;; there is a memory problem. This keeps @cutLine from being released.
0
- ;[cutLine setLineDash:dashes ;; how are we going to do this?
0
- ; count:2
0
- ; phase:0];
0
- (@cutLine moveToPoint:(list midV upperH))
0
- (@cutLine lineToPoint:(list midV lowerH))
0
- (@cutLine setLineWidth:1.0))
0
-
0
+ (set @cutLine (self cutlineFromPoint:(list midV upperH) toPoint:(list midV lowerH))))
0
      
0
      (- (void)drawImageRep:(id)rep inRect:(NSRect)rect isLeft:(BOOL)isLeft is
0
         (set imageSize (rep size))
0
@@ -677,31 +666,12 @@
0
      
0
      ;;;; Pagination
0
      
0
- (if 0 ;; this function cannot be defined in Nu
0
- (- (BOOL)knowsPageRange:(NSRange *)rptr
0
- ;; As a sort of odd side-effect, I'm also informing the view
0
- ;; of how much of the page the printer can actually draw.
0
- ;; I waited until now so that I could use the printer that the
0
- ;; user actually selected.
0
- (set op (NSPrintOperation currentOperation))
0
- (set pi (op printInfo))
0
- (if pi (self setImageablePageRect:(pi imageablePageBounds)))
0
-
0
- ;; It is a one-page document
0
- ;rptr->location = 1;
0
- ;rptr->length = 1;
0
- YES))
0
-
0
-
0
      (- (NSRect) rectForPage:(int) i is (self bounds))
0
      
0
      ;;;; For Debugging Purposes
0
      
0
      (- (id) description is "<PackerView: #{(@packModel description)}>")
0
      
0
-
0
-
0
-
0
      (- acceptsFirstMouse:theEvent is YES)
0
      
0
      (- (void) placeButtons is
0
@@ -775,7 +745,7 @@
0
         ; Draw the cutting line
0
         ((NSColor blackColor) set)
0
         (@cutLine stroke)
0
-
0
+
0
         ; If drawing to screen, draw imageable Rect
0
         (if (isScreen)
0
             (if @showsImageableRect
0
@@ -791,6 +761,7 @@
0
                 (dropColor set)
0
                 (NSBezierPath fillRect:(self fullRectForPage:@dropPage))))))
0
 
0
+
0
 (class TextDisplayView is NSView
0
      (ivar (id) attString (NSSize) pageSize)
0
      
0
@@ -807,8 +778,6 @@
0
         (set bounds (NSInsetRect (self bounds) 3 3))
0
         (@attString drawInRect:bounds)))
0
 
0
-
0
-
0
 (global PaperSizeChangedNotification "PaperSizeChangedNotification")
0
 (global PaperSizeKey "PaperSize")
0
 (global FontFamilyKey "FontFamily")

Comments

    No one has commented yet.