2013-08-23 2 views
2

MonoMac/C#을 사용 중이고 일부 항목을 편집 할 수있는 NSOutlineView가 있습니다. 따라서 항목을 선택한 다음 다시 클릭하면 (느린 더블 클릭) 행의 NSTextField가 편집 모드로 들어갑니다. 내 문제는 당신이 항목을 마우스 오른쪽 단추로 경우에도이 문제가 발생합니다. 왼쪽 클릭과 오른쪽 클릭을 혼합하여 편집 모드로 들어갈 수도 있습니다.두 번 오른쪽 클릭으로 NSTextField 편집 금지

행을 선택하고 마우스 오른쪽 버튼으로 클릭하면 컨텍스트 메뉴가 표시된 후 1 초가 지나면 편집 모드로 들어가기 때문에 매우 귀찮습니다.

NSOutlineView 또는 NSTextFields를 제한하는 방법이 있습니까? 행이 선택된 상태에서 Enter 키를 누른 채로 마우스 왼쪽 버튼을 사용하여 편집 모드로만 전환 할 수 있습니까?

감사합니다.

+0

... 내 첫 번째 생각은 NSOutlineView의 대리자에서 ShouldEditTableColumn을 무시하고 편집하지 않으려는 경우 false를 반환했지만 아직 작동하지 않았습니다. – salgarcia

+0

이 문제가 해결 되었습니까? – salgarcia

+0

아니, 아직. 더 많은 노출을주기 위해 투표를 할 수 있다면 감사하겠습니다. 감사. –

답변

1

내가 사용한 접근 방식은 "RightMouseDown"[1, 2] 메서드보다 우선합니다. NSOutlineView 및 NSTableCellView에서 행운을 얻으려고 시도한 후에, 트릭은 NSTextField에 대한 계층 구조의 하위 레벨로 이동하는 것이 었습니다. NSWindow 객체는 SendEvent를 사용하여 마우스 이벤트 [3]에 가장 가까운 뷰에 직접 이벤트를 전달하므로 이벤트는 가장 안쪽 뷰에서 가장 바깥 쪽 뷰로 진행됩니다.

당신이 사용자 정의 클래스를 사용하는 엑스 코드에 OutlineView에서 원하는 NSTextField있는을 변경할 수 있습니다 "RightMouseDown는"클릭 완전히 NSTextField있는 논리에 의해 하지 전화 base.RightMouseDown() 무시 않습니다

public partial class CustomTextField : NSTextField 
{ 
    #region Constructors 

    // Called when created from unmanaged code 
    public CustomTextField (IntPtr handle) : base (handle) 
    { 
     Initialize(); 
    } 
    // Called when created directly from a XIB file 
    [Export ("initWithCoder:")] 
    public CustomTextField (NSCoder coder) : base (coder) 
    { 
     Initialize(); 
    } 
    // Shared initialization code 
    void Initialize() 
    { 
    } 

    #endregion 

    public override void RightMouseDown (NSEvent theEvent) 
    { 
     NextResponder.RightMouseDown (theEvent); 
    } 
} 

때문에

. NextResponder.RightMouseDown()을 호출하면 이벤트가 뷰 계층 구조를 통과하여 컨텍스트 메뉴를 계속 트리거 할 수 있습니다.

[1] https://developer.apple.com/library/mac/documentation/cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/rightMouseDown : [2] https://developer.apple.com/library/mac/documentation/cocoa/conceptual/eventoverview/HandlingMouseEvents/HandlingMouseEvents.html 다음과 같이 [3] https://developer.apple.com/library/mac/documentation/cocoa/conceptual/eventoverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW21

0

The answer above by @salgarcia은 네이티브 스위프트 3 코드로 구성 될 수있다 : I이이 기능을 필요로 한

import AppKit 

class CustomTextField: NSTextField { 

    override func rightMouseDown(with event: NSEvent) { 

     // Right-clicking when the outline view row is already 
     // selected won't cause the text field to go into edit 
     // mode. Still can be edited by pressing Return while the 
     // row is sleected, as long as the textfield it is set to 
     // 'Editable' (in the storyboard or programmatically): 

     nextResponder?.rightMouseDown(with: event) 
    } 
} 
관련 문제