The attribute editors are now subclassing TypeEditorView which has a

CommitChanges() method. Editors like the MimeTypeEditor will use this
to propagate their current content when the window receives QuitRequested().
Brought the StringEditor to a usable state (note, currently, all attribute
editors can only change what's there; they cannot change the size of the
attribute - this will be fixed at a later point).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6785 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-27 22:26:37 +00:00
parent 54df6d4d66
commit fa78c88efa
4 changed files with 114 additions and 52 deletions
+86 -37
View File
@@ -26,7 +26,7 @@ static const uint32 kMsgValueChanged = 'vlch';
static const uint32 kMimeTypeItem = 'miti'; static const uint32 kMimeTypeItem = 'miti';
class StringEditor : public BView { class StringEditor : public TypeEditorView {
public: public:
StringEditor(BRect rect, DataEditor &editor); StringEditor(BRect rect, DataEditor &editor);
@@ -34,13 +34,17 @@ class StringEditor : public BView {
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void UpdateText();
virtual void CommitChanges();
private: private:
DataEditor &fEditor; DataEditor &fEditor;
BTextView *fTextView; BTextView *fTextView;
BString fPreviousText;
}; };
class MimeTypeEditor : public BView { class MimeTypeEditor : public TypeEditorView {
public: public:
MimeTypeEditor(BRect rect, DataEditor &editor); MimeTypeEditor(BRect rect, DataEditor &editor);
@@ -49,6 +53,7 @@ class MimeTypeEditor : public BView {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void UpdateText(); void UpdateText();
virtual void CommitChanges();
private: private:
DataEditor &fEditor; DataEditor &fEditor;
@@ -57,7 +62,7 @@ class MimeTypeEditor : public BView {
}; };
class NumberEditor : public BView { class NumberEditor : public TypeEditorView {
public: public:
NumberEditor(BRect rect, DataEditor &editor); NumberEditor(BRect rect, DataEditor &editor);
@@ -66,7 +71,7 @@ class NumberEditor : public BView {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void UpdateText(); void UpdateText();
void UpdateNumber(); virtual void CommitChanges();
private: private:
const char *TypeLabel(); const char *TypeLabel();
@@ -79,7 +84,7 @@ class NumberEditor : public BView {
}; };
class BooleanEditor : public BView { class BooleanEditor : public TypeEditorView {
public: public:
BooleanEditor(BRect rect, DataEditor &editor); BooleanEditor(BRect rect, DataEditor &editor);
@@ -88,6 +93,7 @@ class BooleanEditor : public BView {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void UpdateMenuField(); void UpdateMenuField();
virtual void CommitChanges();
private: private:
DataEditor &fEditor; DataEditor &fEditor;
@@ -96,7 +102,7 @@ class BooleanEditor : public BView {
}; };
class ImageView : public BView { class ImageView : public TypeEditorView {
public: public:
ImageView(BRect rect, DataEditor &editor); ImageView(BRect rect, DataEditor &editor);
virtual ~ImageView(); virtual ~ImageView();
@@ -107,6 +113,7 @@ class ImageView : public BView {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
void UpdateImage(); void UpdateImage();
virtual void CommitChanges();
private: private:
DataEditor &fEditor; DataEditor &fEditor;
@@ -119,7 +126,7 @@ class ImageView : public BView {
StringEditor::StringEditor(BRect rect, DataEditor &editor) StringEditor::StringEditor(BRect rect, DataEditor &editor)
: BView(rect, "String Editor", B_FOLLOW_ALL, 0), : TypeEditorView(rect, "String Editor", B_FOLLOW_ALL, 0),
fEditor(editor) fEditor(editor)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -137,21 +144,6 @@ StringEditor::StringEditor(BRect rect, DataEditor &editor)
fTextView = new BTextView(rect, B_EMPTY_STRING, rect.OffsetToCopy(B_ORIGIN).InsetByCopy(5, 5), fTextView = new BTextView(rect, B_EMPTY_STRING, rect.OffsetToCopy(B_ORIGIN).InsetByCopy(5, 5),
B_FOLLOW_ALL, B_WILL_DRAW); B_FOLLOW_ALL, B_WILL_DRAW);
if (fEditor.Lock()) {
size_t viewSize = fEditor.ViewSize();
// that may need some more memory...
if (viewSize < fEditor.FileSize())
fEditor.SetViewSize(fEditor.FileSize());
const char *buffer;
if (fEditor.GetViewBuffer((const uint8 **)&buffer) == B_OK)
fTextView->SetText(buffer);
// restore old view size
fEditor.SetViewSize(viewSize);
fEditor.Unlock();
}
#if 0 #if 0
char *data = (char *)malloc(info.size); char *data = (char *)malloc(info.size);
if (data != NULL) { if (data != NULL) {
@@ -167,10 +159,43 @@ StringEditor::StringEditor(BRect rect, DataEditor &editor)
} }
void
StringEditor::UpdateText()
{
BAutolock locker(fEditor);
size_t viewSize = fEditor.ViewSize();
// that may need some more memory...
if (viewSize < fEditor.FileSize())
fEditor.SetViewSize(fEditor.FileSize());
const char *buffer;
if (fEditor.GetViewBuffer((const uint8 **)&buffer) == B_OK) {
fTextView->SetText(buffer);
fPreviousText.SetTo(buffer);
}
// restore old view size
fEditor.SetViewSize(viewSize);
}
void
StringEditor::CommitChanges()
{
if (fPreviousText != fTextView->Text()) {
fEditor.Replace(0, (const uint8 *)fTextView->Text(),
fTextView->TextLength() + 1);
}
}
void void
StringEditor::AttachedToWindow() StringEditor::AttachedToWindow()
{ {
fEditor.StartWatching(this); fEditor.StartWatching(this);
UpdateText();
} }
@@ -178,6 +203,8 @@ void
StringEditor::DetachedFromWindow() StringEditor::DetachedFromWindow()
{ {
fEditor.StopWatching(this); fEditor.StopWatching(this);
CommitChanges();
} }
@@ -192,7 +219,7 @@ StringEditor::MessageReceived(BMessage *message)
MimeTypeEditor::MimeTypeEditor(BRect rect, DataEditor &editor) MimeTypeEditor::MimeTypeEditor(BRect rect, DataEditor &editor)
: BView(rect, "MIME Type Editor", B_FOLLOW_LEFT_RIGHT, 0), : TypeEditorView(rect, "MIME Type Editor", B_FOLLOW_LEFT_RIGHT, 0),
fEditor(editor) fEditor(editor)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -214,14 +241,22 @@ MimeTypeEditor::MimeTypeEditor(BRect rect, DataEditor &editor)
void void
MimeTypeEditor::UpdateText() MimeTypeEditor::UpdateText()
{ {
if (fEditor.Lock()) { BAutolock locker(fEditor);
const char *mimeType; const char *mimeType;
if (fEditor.GetViewBuffer((const uint8 **)&mimeType) == B_OK) { if (fEditor.GetViewBuffer((const uint8 **)&mimeType) == B_OK) {
fTextControl->SetText(mimeType); fTextControl->SetText(mimeType);
fPreviousText.SetTo(mimeType); fPreviousText.SetTo(mimeType);
} }
}
fEditor.Unlock();
void
MimeTypeEditor::CommitChanges()
{
if (fPreviousText != fTextControl->Text()) {
fEditor.Replace(0, (const uint8 *)fTextControl->Text(),
strlen(fTextControl->Text()) + 1);
} }
} }
@@ -241,10 +276,7 @@ MimeTypeEditor::DetachedFromWindow()
{ {
fEditor.StopWatching(this); fEditor.StopWatching(this);
if (fPreviousText != fTextControl->Text()) { CommitChanges();
fEditor.Replace(0, (const uint8 *)fTextControl->Text(),
strlen(fTextControl->Text()) + 1);
}
} }
@@ -271,7 +303,7 @@ MimeTypeEditor::MessageReceived(BMessage *message)
NumberEditor::NumberEditor(BRect rect, DataEditor &editor) NumberEditor::NumberEditor(BRect rect, DataEditor &editor)
: BView(rect, "Number Editor", B_FOLLOW_LEFT_RIGHT, 0), : TypeEditorView(rect, "Number Editor", B_FOLLOW_LEFT_RIGHT, 0),
fEditor(editor) fEditor(editor)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -385,8 +417,11 @@ NumberEditor::UpdateText()
void void
NumberEditor::UpdateNumber() NumberEditor::CommitChanges()
{ {
if (fPreviousText == fTextControl->Text())
return;
const char *number = fTextControl->Text(); const char *number = fTextControl->Text();
uint8 buffer[8]; uint8 buffer[8];
@@ -478,6 +513,7 @@ NumberEditor::UpdateNumber()
} }
fEditor.Replace(0, buffer, Size()); fEditor.Replace(0, buffer, Size());
fPreviousText.SetTo((char *)buffer);
} }
@@ -613,8 +649,7 @@ NumberEditor::DetachedFromWindow()
{ {
fEditor.StopWatching(this); fEditor.StopWatching(this);
if (fPreviousText != fTextControl->Text()) CommitChanges();
UpdateNumber();
} }
@@ -623,7 +658,7 @@ NumberEditor::MessageReceived(BMessage *message)
{ {
switch (message->what) { switch (message->what) {
case kMsgValueChanged: case kMsgValueChanged:
UpdateNumber(); CommitChanges();
break; break;
case kMsgDataEditorUpdate: case kMsgDataEditorUpdate:
UpdateText(); UpdateText();
@@ -639,7 +674,7 @@ NumberEditor::MessageReceived(BMessage *message)
BooleanEditor::BooleanEditor(BRect rect, DataEditor &editor) BooleanEditor::BooleanEditor(BRect rect, DataEditor &editor)
: BView(rect, "Boolean Editor", B_FOLLOW_NONE, 0), : TypeEditorView(rect, "Boolean Editor", B_FOLLOW_NONE, 0),
fEditor(editor) fEditor(editor)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -675,6 +710,13 @@ BooleanEditor::UpdateMenuField()
} }
void
BooleanEditor::CommitChanges()
{
// we're commiting the changes as they happen
}
void void
BooleanEditor::AttachedToWindow() BooleanEditor::AttachedToWindow()
{ {
@@ -716,7 +758,7 @@ BooleanEditor::MessageReceived(BMessage *message)
ImageView::ImageView(BRect rect, DataEditor &editor) ImageView::ImageView(BRect rect, DataEditor &editor)
: BView(rect, "Image View", B_FOLLOW_NONE, B_WILL_DRAW), : TypeEditorView(rect, "Image View", B_FOLLOW_NONE, B_WILL_DRAW),
fEditor(editor), fEditor(editor),
fBitmap(NULL) fBitmap(NULL)
{ {
@@ -931,10 +973,17 @@ ImageView::UpdateImage()
} }
void
ImageView::CommitChanges()
{
// we're not an editor, we're just displaying something
}
// #pragma mark - // #pragma mark -
BView * TypeEditorView *
GetTypeEditorFor(BRect rect, DataEditor &editor) GetTypeEditorFor(BRect rect, DataEditor &editor)
{ {
switch (editor.Type()) { switch (editor.Type()) {
+12 -3
View File
@@ -6,13 +6,22 @@
#define ATTRIBUTE_EDITORS_H #define ATTRIBUTE_EDITORS_H
#include <Rect.h> #include <View.h>
class BView;
class DataEditor; class DataEditor;
extern BView *GetTypeEditorFor(BRect rect, DataEditor &editor); class TypeEditorView : public BView {
public:
TypeEditorView(BRect rect, const char *name, uint32 resizingMode, uint32 flags)
: BView(rect, name, resizingMode, flags)
{
}
virtual void CommitChanges() = 0;
};
extern TypeEditorView *GetTypeEditorFor(BRect rect, DataEditor &editor);
#endif /* ATTRIBUTE_EDITORS_H */ #endif /* ATTRIBUTE_EDITORS_H */
+5 -3
View File
@@ -205,9 +205,9 @@ AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribu
view->AddChild(tabView); view->AddChild(tabView);
BView *editor = GetTypeEditorFor(rect, fProbeView->Editor()); fTypeEditorView = GetTypeEditorFor(rect, fProbeView->Editor());
if (editor != NULL) if (fTypeEditorView != NULL)
tabView->SetTypeEditorTab(editor); tabView->SetTypeEditorTab(fTypeEditorView);
else { else {
// show the raw editor if we don't have a specialised type editor // show the raw editor if we don't have a specialised type editor
tabView->Select(1); tabView->Select(1);
@@ -261,6 +261,8 @@ AttributeWindow::MessageReceived(BMessage *message)
bool bool
AttributeWindow::QuitRequested() AttributeWindow::QuitRequested()
{ {
fTypeEditorView->CommitChanges();
bool quit = fProbeView->QuitRequested(); bool quit = fProbeView->QuitRequested();
if (!quit) if (!quit)
return false; return false;
+2
View File
@@ -9,6 +9,7 @@
#include "ProbeWindow.h" #include "ProbeWindow.h"
class ProbeView; class ProbeView;
class TypeEditorView;
class AttributeWindow : public ProbeWindow { class AttributeWindow : public ProbeWindow {
@@ -23,6 +24,7 @@ class AttributeWindow : public ProbeWindow {
private: private:
ProbeView *fProbeView; ProbeView *fProbeView;
TypeEditorView *fTypeEditorView;
char *fAttribute; char *fAttribute;
}; };