2012-02-16 36 views
0

我想在表格視圖單元格的文本編輯會話期間攔截或禁用Cmd-Z/Shift-Cmd-Z。在編輯基於單元格的表格視圖時攔截撤銷

這是一個基於單元格的表格視圖,其中一系列列的值彼此相互影響,例如填充某些列會自動填充其他列。當用戶在編輯會話中按下Cmd-Z時,撤消管理器可以更改當前正在編輯的屬性,併爲用戶帶來混亂的結果。

下面是一個例子:

步驟1:用戶類型」 0.030" ,在第二列:

enter image description here

步驟2:用戶按下標籤上,模型自動更新列三個,四個,和五:

enter image description here

步驟3:用戶按下CTRL-Z,模型撤消變化到三個兩列,四,五,但編輯會話仍在進行中,因此舊值顯示在三個欄:

enter image description here

第4步:如果沒有輸入任何內容,用戶按下從第三列消失標籤其中取消編輯,和值:

enter image description here

沒有實際的 「錯誤」 發生在這裏,但它的混亂。

當其中一個單元格正在編輯時,我只想攔截Cmd-Z和Shift-Cmd-Z並忽略它們。我認爲我應該重寫-keyDown:作爲編輯期間的第一響應者。但那是什麼?表視圖根本沒有得到這些關鍵事件,並且該單元也不是響應者。

回答

0

找到了一個工作解決方案。在我的NSTableView小類中:

// Disable undo and redo while table's field editors have first responder status 
-(BOOL)validateMenuItem:(NSMenuItem *)menuItem { 
    if (self != self.window.firstResponder) 
     if (@selector(undo:) == menuItem.action || @selector(redo:) == menuItem.action) 
      return NO; 
    return YES; 
} 

// Intercept undo events while table's field editors have first responder status 
-(IBAction)undo:(id)sender { 
    if (self != self.window.firstResponder) 
     [self noResponderFor:_cmd]; 
    else 
     [self.nextResponder tryToPerform:@selector(undo:) with:sender]; 
} 
相關問題