Bugfixes to saving and loading colorsets
Added some safeguards to prevent saving sets with the (now) reserved name 'Default' git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4978 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,10 +39,12 @@
|
|||||||
|
|
||||||
#include "APRView.h"
|
#include "APRView.h"
|
||||||
#include <PortLink.h>
|
#include <PortLink.h>
|
||||||
|
#include <PortMessage.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "ColorWell.h"
|
#include "ColorWell.h"
|
||||||
#include <ColorUtils.h>
|
#include <ColorUtils.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include <ServerProtocol.h>
|
||||||
#include "ColorWhichItem.h"
|
#include "ColorWhichItem.h"
|
||||||
#include "ServerConfig.h"
|
#include "ServerConfig.h"
|
||||||
|
|
||||||
@@ -171,7 +173,7 @@ APRView::APRView(const BRect &frame, const char *name, int32 resize, int32 flags
|
|||||||
savepanel=new BFilePanel(B_SAVE_PANEL, NULL, &ref, 0, false);
|
savepanel=new BFilePanel(B_SAVE_PANEL, NULL, &ref, 0, false);
|
||||||
|
|
||||||
attribute=B_PANEL_BACKGROUND_COLOR;
|
attribute=B_PANEL_BACKGROUND_COLOR;
|
||||||
attrstring="Background";
|
attrstring="Panel Background";
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +213,7 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
{
|
{
|
||||||
picker->SetValue(*col);
|
picker->SetValue(*col);
|
||||||
colorwell->SetColor(*col);
|
colorwell->SetColor(*col);
|
||||||
|
colorwell->Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +221,10 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
{
|
{
|
||||||
case DELETE_COLORSET:
|
case DELETE_COLORSET:
|
||||||
{
|
{
|
||||||
|
// We can't delete the Default set
|
||||||
|
if(currentset->name.Compare("Default")==0)
|
||||||
|
break;
|
||||||
|
|
||||||
// Construct the path and delete
|
// Construct the path and delete
|
||||||
BString path(COLOR_SET_DIR);
|
BString path(COLOR_SET_DIR);
|
||||||
path+=currentset->name;
|
path+=currentset->name;
|
||||||
@@ -258,6 +265,10 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
case SAVE_COLORSET:
|
case SAVE_COLORSET:
|
||||||
{
|
{
|
||||||
|
// Saving the Default set is rather dumb
|
||||||
|
if(currentset->name.Compare("Default")==0)
|
||||||
|
break;
|
||||||
|
|
||||||
savepanel->Show();
|
savepanel->Show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -269,6 +280,13 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
STRACE(("MSG: Save Request - couldn't find file name\n"));
|
STRACE(("MSG: Save Request - couldn't find file name\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(name.ICompare("Default")==0)
|
||||||
|
{
|
||||||
|
BAlert *a=new BAlert("OpenBeOS","The name 'Default' is reserved. Please choose another.","OK");
|
||||||
|
a->Go();
|
||||||
|
savepanel->Show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
SaveColorSet(name);
|
SaveColorSet(name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -310,10 +328,7 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
if(!whichitem)
|
if(!whichitem)
|
||||||
break;
|
break;
|
||||||
attrstring=whichitem->Text();
|
attrstring=whichitem->Text();
|
||||||
rgb_color col=currentset->StringToColor(whichitem->Text()).GetColor32();
|
UpdateControlsFromAttr(whichitem->Text());
|
||||||
picker->SetValue(col);
|
|
||||||
colorwell->SetColor(col);
|
|
||||||
colorwell->Invalidate();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case APPLY_SETTINGS:
|
case APPLY_SETTINGS:
|
||||||
@@ -375,10 +390,7 @@ void APRView::MessageReceived(BMessage *msg)
|
|||||||
apply->SetEnabled(true);
|
apply->SetEnabled(true);
|
||||||
}
|
}
|
||||||
SetDefaults();
|
SetDefaults();
|
||||||
rgb_color col=currentset->StringToColor(attrstring.String()).GetColor32();
|
UpdateControlsFromAttr(attrstring.String());
|
||||||
picker->SetValue(col);
|
|
||||||
colorwell->SetColor(col);
|
|
||||||
colorwell->Invalidate();
|
|
||||||
if(Window())
|
if(Window())
|
||||||
Window()->PostMessage(SET_UI_COLORS);
|
Window()->PostMessage(SET_UI_COLORS);
|
||||||
break;
|
break;
|
||||||
@@ -518,8 +530,7 @@ void APRView::LoadColorSet(const BString &name)
|
|||||||
currentset->ConvertFromMessage(&settings);
|
currentset->ConvertFromMessage(&settings);
|
||||||
SetColorSetName(currentset->name.String());
|
SetColorSetName(currentset->name.String());
|
||||||
|
|
||||||
picker->SetValue(currentset->StringToColor(attrstring.String()).GetColor32());
|
UpdateControlsFromAttr(attrstring.String());
|
||||||
colorwell->SetColor(picker->ValueAsColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APRView::SaveColorSet(const BString &name)
|
void APRView::SaveColorSet(const BString &name)
|
||||||
@@ -543,7 +554,9 @@ void APRView::SaveColorSet(const BString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BMessage settings;
|
BMessage settings;
|
||||||
|
currentset->name=name;
|
||||||
currentset->ConvertToMessage(&settings);
|
currentset->ConvertToMessage(&settings);
|
||||||
|
|
||||||
if(settings.Flatten(&file)!=B_OK)
|
if(settings.Flatten(&file)!=B_OK)
|
||||||
{
|
{
|
||||||
STRACE(("SaveColorSet: Couldn't flatten settings to file\n"));
|
STRACE(("SaveColorSet: Couldn't flatten settings to file\n"));
|
||||||
@@ -558,6 +571,11 @@ void APRView::SaveColorSet(const BString &name)
|
|||||||
STRACE(("SaveColorSet: Error in adding item to menu\n"));
|
STRACE(("SaveColorSet: Error in adding item to menu\n"));
|
||||||
}
|
}
|
||||||
SetColorSetName(name.String());
|
SetColorSetName(name.String());
|
||||||
|
|
||||||
|
// If we saved the color set after Applying it, the name won't be updated on disk, so
|
||||||
|
// save again to disk if this has happened.
|
||||||
|
if(prevset==NULL)
|
||||||
|
SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APRView::SetColorSetName(const char *name)
|
void APRView::SetColorSetName(const char *name)
|
||||||
@@ -595,7 +613,23 @@ void APRView::LoadSettings(void)
|
|||||||
// Load the current GUI color settings from disk. This is done instead of
|
// Load the current GUI color settings from disk. This is done instead of
|
||||||
// getting them from the server at this point for testing purposes.
|
// getting them from the server at this point for testing purposes.
|
||||||
|
|
||||||
// TODO: Add app_server UI color query code
|
/* TODO: Uncomment the following disabled code when the app_server will handle the message
|
||||||
|
|
||||||
|
// Query the server for the current settings
|
||||||
|
port_id port=find_port(SERVER_PORT_NAME);
|
||||||
|
if(port!=B_NAME_NOT_FOUND)
|
||||||
|
{
|
||||||
|
STRACE(("Retrieving settings from app_server\n"));
|
||||||
|
PortLink link(port);
|
||||||
|
PortMessage pmsg;
|
||||||
|
|
||||||
|
link.SetOpCode(AS_GET_UI_COLORS);
|
||||||
|
link.FlushWithReply(&pmsg);
|
||||||
|
pmsg.Read<ColorSet>(currentset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*/
|
||||||
STRACE(("Loading settings from disk\n"));
|
STRACE(("Loading settings from disk\n"));
|
||||||
|
|
||||||
BDirectory dir,newdir;
|
BDirectory dir,newdir;
|
||||||
@@ -627,14 +661,14 @@ void APRView::LoadSettings(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentset->ConvertFromMessage(&settings);
|
currentset->ConvertFromMessage(&settings);
|
||||||
|
// }
|
||||||
|
|
||||||
SetColorSetName(currentset->name.String());
|
SetColorSetName(currentset->name.String());
|
||||||
|
|
||||||
picker->SetValue(currentset->StringToColor(attrstring.String()).GetColor32());
|
UpdateControlsFromAttr(attrstring.String());
|
||||||
colorwell->SetColor(picker->ValueAsColor());
|
|
||||||
|
|
||||||
if(currentset->name.String()!="Default")
|
if(currentset->name.Compare("Default")!=0)
|
||||||
defaults->SetEnabled(true);
|
defaults->SetEnabled(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APRView::SetDefaults(void)
|
void APRView::SetDefaults(void)
|
||||||
@@ -677,3 +711,14 @@ void APRView::NotifyServer(void)
|
|||||||
if(Window())
|
if(Window())
|
||||||
Window()->PostMessage(SET_UI_COLORS);
|
Window()->PostMessage(SET_UI_COLORS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void APRView::UpdateControlsFromAttr(const char *string)
|
||||||
|
{
|
||||||
|
if(!string)
|
||||||
|
return;
|
||||||
|
STRACE(("Update color for %s\n",string));
|
||||||
|
|
||||||
|
picker->SetValue(currentset->StringToColor(string).GetColor32());
|
||||||
|
colorwell->SetColor(picker->ValueAsColor());
|
||||||
|
colorwell->Invalidate();
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
// rgb_color GetColorFromMessage(BMessage *msg, const char *name, int32 index=0);
|
// rgb_color GetColorFromMessage(BMessage *msg, const char *name, int32 index=0);
|
||||||
protected:
|
protected:
|
||||||
friend APRWindow;
|
friend APRWindow;
|
||||||
|
void UpdateControlsFromAttr(const char *string);
|
||||||
BMenu *LoadColorSets(void);
|
BMenu *LoadColorSets(void);
|
||||||
void SaveColorSet(const BString &name);
|
void SaveColorSet(const BString &name);
|
||||||
void LoadColorSet(const BString &name);
|
void LoadColorSet(const BString &name);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void ColorWhichItem::SetAttribute(color_which which)
|
|||||||
case B_PANEL_BACKGROUND_COLOR:
|
case B_PANEL_BACKGROUND_COLOR:
|
||||||
{
|
{
|
||||||
attribute=which;
|
attribute=which;
|
||||||
SetText("Background");
|
SetText("Panel Background");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_PANEL_TEXT_COLOR:
|
case B_PANEL_TEXT_COLOR:
|
||||||
|
|||||||
Reference in New Issue
Block a user