BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / mediaconverter / MediaFileListView.cpp
blob1aa9b1fe4933cffd45c20f808be6d9c36583eadc
1 // Copyright 1999, Be Incorporated. All Rights Reserved.
2 // Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
3 // Copyright 2007, 2009 Stephan Aßmus. All Rights Reserved.
4 // This file may be used under the terms of the Be Sample Code License.
7 #include "MediaFileListView.h"
9 #include <new>
11 #include <Application.h>
12 #include <MediaFile.h>
13 #include <Messenger.h>
15 #include "MediaConverterWindow.h"
16 #include "MessageConstants.h"
19 // #pragma mark - MediaFileListItem
22 MediaFileListItem::MediaFileListItem(BMediaFile* file, const entry_ref& ref)
24 BStringItem(ref.name),
25 fRef(ref),
26 fMediaFile(file)
31 MediaFileListItem::~MediaFileListItem()
33 delete fMediaFile;
37 // #pragma mark - MediaFileListView
40 MediaFileListView::MediaFileListView()
42 BListView("MediaFileListView", B_SINGLE_SELECTION_LIST, B_WILL_DRAW
43 | B_NAVIGABLE | B_FRAME_EVENTS)
45 fEnabled = true;
49 MediaFileListView::~MediaFileListView()
51 BListItem *item;
52 while ((item = RemoveItem((int32)0)) != NULL) {
53 delete item;
58 void
59 MediaFileListView::SetEnabled(bool enabled)
61 if (enabled == fEnabled)
62 return;
64 fEnabled = enabled;
65 // TODO: visual indication of enabled status?
69 bool
70 MediaFileListView::IsEnabled() const
72 return fEnabled;
76 bool
77 MediaFileListView::AddMediaItem(BMediaFile* file, const entry_ref& ref)
79 MediaFileListItem* item = new(std::nothrow) MediaFileListItem(file, ref);
80 if (item == NULL || !AddItem(item)) {
81 delete item;
82 return false;
84 be_app_messenger.SendMessage(FILE_LIST_CHANGE_MESSAGE);
85 return true;
89 void
90 MediaFileListView::KeyDown(const char *bytes, int32 numBytes)
92 switch (bytes[0]) {
93 case B_DELETE:
94 if (IsEnabled()) {
95 int32 selection = CurrentSelection();
96 if (selection >= 0) {
97 delete RemoveItem(selection);
98 // select the previous item
99 int32 count = CountItems();
100 if (selection >= count)
101 selection = count - 1;
102 Select(selection);
103 be_app_messenger.SendMessage(FILE_LIST_CHANGE_MESSAGE);
106 break;
107 default:
108 BListView::KeyDown(bytes, numBytes);
113 void
114 MediaFileListView::SelectionChanged()
116 MediaConverterWindow* win = dynamic_cast<MediaConverterWindow*>(Window());
117 if (win != NULL)
118 win->SourceFileSelectionChanged();