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
+93 -44
View File
@@ -26,7 +26,7 @@ static const uint32 kMsgValueChanged = 'vlch';
static const uint32 kMimeTypeItem = 'miti';
class StringEditor : public BView {
class StringEditor : public TypeEditorView {
public:
StringEditor(BRect rect, DataEditor &editor);
@@ -34,13 +34,17 @@ class StringEditor : public BView {
virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage *message);
void UpdateText();
virtual void CommitChanges();
private:
DataEditor &fEditor;
BTextView *fTextView;
BString fPreviousText;
};
class MimeTypeEditor : public BView {
class MimeTypeEditor : public TypeEditorView {
public:
MimeTypeEditor(BRect rect, DataEditor &editor);
@@ -49,6 +53,7 @@ class MimeTypeEditor : public BView {
virtual void MessageReceived(BMessage *message);
void UpdateText();
virtual void CommitChanges();
private:
DataEditor &fEditor;
@@ -57,7 +62,7 @@ class MimeTypeEditor : public BView {
};
class NumberEditor : public BView {
class NumberEditor : public TypeEditorView {
public:
NumberEditor(BRect rect, DataEditor &editor);
@@ -66,7 +71,7 @@ class NumberEditor : public BView {
virtual void MessageReceived(BMessage *message);
void UpdateText();
void UpdateNumber();
virtual void CommitChanges();
private:
const char *TypeLabel();
@@ -79,7 +84,7 @@ class NumberEditor : public BView {
};
class BooleanEditor : public BView {
class BooleanEditor : public TypeEditorView {
public:
BooleanEditor(BRect rect, DataEditor &editor);
@@ -88,6 +93,7 @@ class BooleanEditor : public BView {
virtual void MessageReceived(BMessage *message);
void UpdateMenuField();
virtual void CommitChanges();
private:
DataEditor &fEditor;
@@ -96,7 +102,7 @@ class BooleanEditor : public BView {
};
class ImageView : public BView {
class ImageView : public TypeEditorView {
public:
ImageView(BRect rect, DataEditor &editor);
virtual ~ImageView();
@@ -107,6 +113,7 @@ class ImageView : public BView {
virtual void Draw(BRect updateRect);
void UpdateImage();
virtual void CommitChanges();
private:
DataEditor &fEditor;
@@ -119,7 +126,7 @@ class ImageView : public BView {
StringEditor::StringEditor(BRect rect, DataEditor &editor)
: BView(rect, "String Editor", B_FOLLOW_ALL, 0),
: TypeEditorView(rect, "String Editor", B_FOLLOW_ALL, 0),
fEditor(editor)
{
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),
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
char *data = (char *)malloc(info.size);
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
StringEditor::AttachedToWindow()
{
fEditor.StartWatching(this);
UpdateText();
}
@@ -178,6 +203,8 @@ void
StringEditor::DetachedFromWindow()
{
fEditor.StopWatching(this);
CommitChanges();
}
@@ -192,7 +219,7 @@ StringEditor::MessageReceived(BMessage *message)
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)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -211,17 +238,25 @@ MimeTypeEditor::MimeTypeEditor(BRect rect, DataEditor &editor)
}
void
void
MimeTypeEditor::UpdateText()
{
if (fEditor.Lock()) {
const char *mimeType;
if (fEditor.GetViewBuffer((const uint8 **)&mimeType) == B_OK) {
fTextControl->SetText(mimeType);
fPreviousText.SetTo(mimeType);
}
BAutolock locker(fEditor);
fEditor.Unlock();
const char *mimeType;
if (fEditor.GetViewBuffer((const uint8 **)&mimeType) == B_OK) {
fTextControl->SetText(mimeType);
fPreviousText.SetTo(mimeType);
}
}
void
MimeTypeEditor::CommitChanges()
{
if (fPreviousText != fTextControl->Text()) {
fEditor.Replace(0, (const uint8 *)fTextControl->Text(),
strlen(fTextControl->Text()) + 1);
}
}
@@ -240,11 +275,8 @@ void
MimeTypeEditor::DetachedFromWindow()
{
fEditor.StopWatching(this);
if (fPreviousText != fTextControl->Text()) {
fEditor.Replace(0, (const uint8 *)fTextControl->Text(),
strlen(fTextControl->Text()) + 1);
}
CommitChanges();
}
@@ -271,7 +303,7 @@ MimeTypeEditor::MessageReceived(BMessage *message)
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)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -385,8 +417,11 @@ NumberEditor::UpdateText()
void
NumberEditor::UpdateNumber()
NumberEditor::CommitChanges()
{
if (fPreviousText == fTextControl->Text())
return;
const char *number = fTextControl->Text();
uint8 buffer[8];
@@ -478,6 +513,7 @@ NumberEditor::UpdateNumber()
}
fEditor.Replace(0, buffer, Size());
fPreviousText.SetTo((char *)buffer);
}
@@ -613,8 +649,7 @@ NumberEditor::DetachedFromWindow()
{
fEditor.StopWatching(this);
if (fPreviousText != fTextControl->Text())
UpdateNumber();
CommitChanges();
}
@@ -623,7 +658,7 @@ NumberEditor::MessageReceived(BMessage *message)
{
switch (message->what) {
case kMsgValueChanged:
UpdateNumber();
CommitChanges();
break;
case kMsgDataEditorUpdate:
UpdateText();
@@ -639,7 +674,7 @@ NumberEditor::MessageReceived(BMessage *message)
BooleanEditor::BooleanEditor(BRect rect, DataEditor &editor)
: BView(rect, "Boolean Editor", B_FOLLOW_NONE, 0),
: TypeEditorView(rect, "Boolean Editor", B_FOLLOW_NONE, 0),
fEditor(editor)
{
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
BooleanEditor::AttachedToWindow()
{
@@ -716,7 +758,7 @@ BooleanEditor::MessageReceived(BMessage *message)
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),
fBitmap(NULL)
{
@@ -931,10 +973,17 @@ ImageView::UpdateImage()
}
void
ImageView::CommitChanges()
{
// we're not an editor, we're just displaying something
}
// #pragma mark -
BView *
TypeEditorView *
GetTypeEditorFor(BRect rect, DataEditor &editor)
{
switch (editor.Type()) {
+12 -3
View File
@@ -6,13 +6,22 @@
#define ATTRIBUTE_EDITORS_H
#include <Rect.h>
#include <View.h>
class BView;
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 */
+5 -3
View File
@@ -205,9 +205,9 @@ AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribu
view->AddChild(tabView);
BView *editor = GetTypeEditorFor(rect, fProbeView->Editor());
if (editor != NULL)
tabView->SetTypeEditorTab(editor);
fTypeEditorView = GetTypeEditorFor(rect, fProbeView->Editor());
if (fTypeEditorView != NULL)
tabView->SetTypeEditorTab(fTypeEditorView);
else {
// show the raw editor if we don't have a specialised type editor
tabView->Select(1);
@@ -261,6 +261,8 @@ AttributeWindow::MessageReceived(BMessage *message)
bool
AttributeWindow::QuitRequested()
{
fTypeEditorView->CommitChanges();
bool quit = fProbeView->QuitRequested();
if (!quit)
return false;
+4 -2
View File
@@ -9,6 +9,7 @@
#include "ProbeWindow.h"
class ProbeView;
class TypeEditorView;
class AttributeWindow : public ProbeWindow {
@@ -22,8 +23,9 @@ class AttributeWindow : public ProbeWindow {
virtual bool Contains(const entry_ref &ref, const char *attribute);
private:
ProbeView *fProbeView;
char *fAttribute;
ProbeView *fProbeView;
TypeEditorView *fTypeEditorView;
char *fAttribute;
};
#endif /* ATTRIBUTE_WINDOW_H */