Pergunta

I need to implement a "recent list" for uploaded images like in cloudapp or droplr. So whenever i upload an image it should create a nsmenuitem with its title(or url). There should be always the last 5 uploaded images. So i think i need a plist where i can save the last 5 images(title of images) and when ever the menu is opened it should load the recent 5. But i need some help from you because i am not sure how to do it. I would have to edit the plist whenever a new image is uploaded so it stands at the first place in the plist and all the old entrys would have to get their index+1.

I hope you understand me. Do you have an idea how to achieve this ? Thanks

Foi útil?

Solução

While I'm not sure this is what you actually want to do I implemented a similar feature not long ago. For my case it was just for files but should work in your case as well (or at least show you one way to do it)

void populateRecentList(const char** files)
{
    NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTitle:@"File"] submenu];
    NSMenu* recentItems = [[fileMenu itemWithTitle:@"Recent Files"] submenu];

    [recentItems removeAllItems];

    for (int i = 0; i < 4; ++i)
    {
        const char* filename = files[i];
        NSString* name = [NSString stringWithUTF8String: filename];

        NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onRecentFile:) keyEquivalent:@""];
        [newItem setTag:i];
        [newItem setRepresentedObject:[NSString stringWithFormat:@"%d",i]];
        [newItem setKeyEquivalentModifierMask: NSCommandKeyMask];
        [newItem setKeyEquivalent:[NSString stringWithFormat:@"%d",i + 1]];

        [recentItems addItem:newItem];

        [newItem release];
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top