Tab機能の拡張を諦める。

VisualにTabを選択したいため、タブを一覧表示で、カレントなWindowを示すコードを書こうとした。

../../../_images/CurrentTab.png

一応、以下の非公開メソッドを使うことでできそうだが実装は諦める。

tabの切り替えのための over view の画面は格好良いけど、”select next tab”にショートカットをつける方が画面がすぐに変わるので便利だ。

つまり、以下のコードを無駄。

@IBAction func log(_ sender: Any?)
{
    if let theStack = self.window!.value(forKeyPath:
        "windowStackController.tabPickerViewController.tabPickerController" ) as? NSViewController
    {
        if let orderedTabViewItems = theStack.value(forKey: "orderedTabViewItems") as? NSArray
        {
            if let indexOfSelectedTab = theStack.value(forKey: "indexOfSelectedTab") as? NSNumber
            {
                if let theSelectedObject = orderedTabViewItems.object(at: indexOfSelectedTab.intValue) as? NSObject
                {
                    // タイトルを" this is a Current Tab "に変更
                    theSelectedObject.setValue("this is a Current Tab", forKey: "label")
                    // 再描画させる
                    theStack.perform(NSSelectorFromString("reloadTabBarItem:"), with: theSelectedObject)
                }
            }
        }
    }
}

Servicesメニューの実装

Cocoa勉強会2019/02/20の資料。NSServicesメニューの実装の説明。

プロジェクトファイルは、 NSServicesメニューの実装.zip に置いておきます。

ヒレガス本 21章 課題1 swift版

昨日のヒレガス本の課題をswiftへ移植。あまり綺麗なコードにはならなかった。

それぞれのメソッドを地道に移植した。注意事項はない。必要なのは努力だけ。

プロジェクトファイルは、 TypingTutor_swift.zip に置いておきます。

ヒレガス本 21章 課題1

サンプルコードの雛形が欲しかったので、久しぶりにヒレがス本の課題の続きを行なった。

第21章でBigLetterViewにコピー&ペースト機能をつけた。

課題は、コピー時に、テキストだけでなくPDFもペーストボードに書き込めとのこと。

単純にwriteToPasteboardメソッドを書き換える。

- (void)writeToPasteboard:(NSPasteboard*)pb
{
    [pb clearContents];

    // pdfデータの準備
    NSData* thePDFData  = [self dataWithPDFInsideRect:self.bounds];

    NSPasteboardItem* thePDFItem = [[NSPasteboardItem alloc] init];
    [thePDFItem setData:thePDFData forType:NSPasteboardTypePDF];

    NSPasteboardItem* theTextItem = [[NSPasteboardItem alloc] init];
    [theTextItem setString:self.string forType:NSPasteboardTypeString];

    [pb writeObjects:@[thePDFItem, theTextItem]];
}

一種類のデータだけならば、NSPasteboardを使うだけで良いが、複数のデータを扱う場合は、NSPasteboardItemを使う必要がある。

プロジェクトファイルは、 TypingTutor_3.zip に置いておきます。