NSOutlineView Drag-n-Drop - PullRequest
       28

NSOutlineView Drag-n-Drop

1 голос
/ 31 января 2011

В моем приложении NSOutlineView используется как показано ниже, 1 - Использование CustomOutlineView, потому что я хочу контролировать фон NSOutlineView,

2 - Использование CustomeCell, потому что мне нужно настроить ячейку

Заголовочный файл: MyListView.h

/* 
 MyUICustomView is the Subclass from NSView and this is i need to have 
 for some other my application purpose 
*/
@interface MyListView : MyUICustomView<NSOutlineViewDataSource> 
{
      // MyCustomOutlineview because, i need to override DrawRect Method to have   
      //   customized background 
      MyCustomOutlineView *pMyOutlineView;

}

@property(nonatomic,retain)MyCustomOutlineView *pMyOutlineView;

, а также я должен иметь возможность перетаскивания в представлении структуры, за то, что у меня есть drag-n-drop, я сделал следующее:

  -(void)InitOutlineView{
        // Creating outline view 
        NSRect          scrollFrame = [self bounds];
    NSScrollView*   scrollView  = [[[NSScrollView alloc] initWithFrame:scrollFrame] autorelease];

    [scrollView setBorderType:NSNoBorder];
    [scrollView setHasVerticalScroller:YES];
    [scrollView setHasHorizontalScroller:NO];
    [scrollView setAutohidesScrollers:YES];
    [scrollView setDrawsBackground: NO];

    NSRect          clipViewBounds  = [[scrollView contentView] bounds];
    pMyOutlineView       = [[[MyCustomOutlineView alloc] initWithFrame:clipViewBounds] autorelease];


    NSTableColumn*  firstColumn     = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
#ifdef ENABLE_CUSTOM_CELL
        // Becuase cell should have Image, Header Info and brief detail in small font, 
        // so i need to have custom cell 
    ImageTextCell *pCell = [[ImageTextCell alloc]init];
    [firstColumn setDataCell:pCell];
        // SO i can fill the data 
    [pCell setDataDelegate:self];
# endif

        [pMyOutlineView setDataSource:self];
        /* This is to tell MyCustomOutlineView to handle the context menu */
    [pMyOutlineView setDataDelegate:self];
        [scrollView setDocumentView:pCTOutlineView];

        [pMyOutlineView  addTableColumn:firstColumn];
        [pMyOutlineView registerForDraggedTypes:
         [NSArray arrayWithObjects:OutlinePrivateTableViewDataType,nil]];

        [pMyOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];**

    }

и поддержка drag-n-drop. Реализован следующий метод

        - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard{
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items];
        [pboard declareTypes:[NSArray arrayWithObject:OutlinePrivateTableViewDataType] owner:self];
        [pboard setData:data forType:OutlinePrivateTableViewDataType];
        return YES;

    }


    - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index{
    // Add code here to validate the drop

    NSLog(@"validate Drop");
    return NSDragOperationEvery;
}

        - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index{
          NSLog(@"validate Drop");
    }

но все же, когда я пытаюсь перетащить строку NSOutlineView, ничего не происходит, даже я пытался отлаживать с помощью NSLog, но я не мог увидеть ни одного журнала из функции выше, Я пропускаю какой-нибудь важный метод? для поддержки Drag-n-drop

Ответы [ 2 ]

1 голос
/ 31 января 2011

Судя по вашему коду, похоже, что вы ничего не возвращаете для метода ... writeItems .... Предполагается, что этот метод возвращает BOOL (независимо от того, были ли элементы успешно написаны или вы отрицаете перетаскивание) Возврат ничего не должен давать вам предупреждение компилятора ...

0 голосов
/ 04 февраля 2011

HI, наконец-то удалось избавиться от этого, проблема в

[firstColumn setWidth:25];

Так что перетаскивание работало только до 25 пикселей слева, и я прокомментировал это, затем его рабочее время, но странно длявидите, мой контурный вид имеет только один столбец, для рисования, он не проверяет ограничение, но для перетаскивания его проверяет,

Спасибо, Джошуа

...