|
From: CVS C. to T. <the...@li...> - 2010-11-03 22:55:18
|
Revision: 562
http://themis.svn.sourceforge.net/themis/?rev=562&view=rev
Author: mark_hellegers
Date: 2010-11-03 22:55:11 +0000 (Wed, 03 Nov 2010)
Log Message:
-----------
Moved css parser preferences to the css parser module.
Modified Paths:
--------------
trunk/themis/framework/PrefsViews.cpp
trunk/themis/framework/PrefsViews.h
trunk/themis/framework/PrefsWin.cpp
trunk/themis/framework/app.cpp
trunk/themis/makefile
trunk/themis/modules/CSSParser/CSSParserPlugin.cpp
trunk/themis/modules/CSSParser/CSSParserPlugin.hpp
Added Paths:
-----------
trunk/themis/modules/CSSParser/CSSParserPrefsView.cpp
trunk/themis/modules/CSSParser/CSSParserPrefsView.hpp
Modified: trunk/themis/framework/PrefsViews.cpp
===================================================================
--- trunk/themis/framework/PrefsViews.cpp 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/framework/PrefsViews.cpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -335,106 +335,3 @@
mMainBox->AddChild(CookieBox);
}
-
-
-/*
- * CSSParserPrefsView
- */
-
-
-CSSParserPrefsView :: CSSParserPrefsView(BRect frame,
- const char* name)
- : BasePrefsView(frame,
- name) {
-
- /* CSS file selection */
- mPopUpMenu = new BPopUpMenu(
- "No CSS selected or available!",
- true,
- true,
- B_ITEMS_IN_COLUMN);
-
- /* find a CSS file */
- AppSettings->FindString(kPrefsSettingsDirectory, &mCSSDir);
- mCSSDir.Append("/css/");
- printf("CSS dir: %s\n", mCSSDir.String());
-
- BDirectory dir(mCSSDir.String());
- if(dir.InitCheck() != B_OK) {
- printf("CSS directory (%s) not found!\n", mCSSDir.String());
- printf("Setting CSSToUsePath to \"none\"\n");
- AppSettings->AddString(kPrefsActiveCSSPath, kNoCSSFoundString);
- }
- else {
- BString activeCSS;
- AppSettings->FindString(kPrefsActiveCSSPath, &activeCSS);
-
- BEntry entry;
- while(dir.GetNextEntry(&entry, false) != B_ENTRY_NOT_FOUND) {
- BPath path;
- entry.GetPath(&path);
- char name[B_FILE_NAME_LENGTH];
- entry.GetName(name);
-
- BString nstring(name);
- printf("----------------\n");
- printf("found CSS file: %s\n", nstring.String());
-
- /* add the file to the popupmenu */
- BMessage* msg = new BMessage(CSS_SELECTED);
- msg->AddString("CSSFileString", path.Path());
- BMenuItem* item = new BMenuItem(name, msg, 0, 0);
- mPopUpMenu->AddItem(item);
-
- // if the path of the current file equals the one of the settings,
- // mark the item
- if(strcmp(activeCSS.String(), path.Path() ) == 0) {
- printf("CSS from settings found -> SetMarked( true )\n");
- (mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1))->SetMarked(true);
- }
- } // while
-
- }
- // end: find a CSS file
-
- BRect rect = mMainBox->Bounds();
- rect.InsetBy(kItemSpacing, kItemSpacing);
- rect.top += kBBoxExtraInset;
-
- BMenuField* cssmenufield = new BMenuField(
- rect,
- "CSSFIELD", "Cascading Style Sheet:",
- mPopUpMenu,
- true,
- B_FOLLOW_TOP,
- B_WILL_DRAW);
- cssmenufield->SetDivider(be_plain_font->StringWidth("Cascading Style Sheet:") + kItemSpacing);
- mMainBox->AddChild(cssmenufield);
-}
-
-void CSSParserPrefsView :: AttachedToWindow() {
-
- // if we found some CSS files, but still no CSS file is saved in the prefs,
- // or no CSS file is selected:
- // set the last found CSS file in the prefs. we save it to the prefs,
- // because the user might not reselect a CSS file in the list, which
- // would save the CSS file.
- BMessage imsg(CSS_SELECTED);
- BMessenger msgr(NULL, Window()->Looper());
- if (mPopUpMenu->CountItems() > 0) {
- if (mPopUpMenu->FindMarked() == NULL) {
- printf("no marked item found\n");
- BMenuItem* item = mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1);
- item->SetMarked(true);
- // as we cannot invoke the item here, send the CSS_SELECTED message here
- BString cssstring(mCSSDir.String());
- cssstring.Append(item->Label());
- imsg.AddString("CSSFileString", cssstring.String());
- msgr.SendMessage(&imsg);
- }
- }
- else {
- imsg.AddString("CSSFileString", kNoCSSFoundString);
- msgr.SendMessage(&imsg);
- }
-}
Modified: trunk/themis/framework/PrefsViews.h
===================================================================
--- trunk/themis/framework/PrefsViews.h 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/framework/PrefsViews.h 2010-11-03 22:55:11 UTC (rev 562)
@@ -52,24 +52,6 @@
};
-/*
- * CSS ParserPrefsView
- */
-
-
-class CSSParserPrefsView : public BasePrefsView {
-
- private:
- BPopUpMenu * mPopUpMenu;
- BString mCSSDir;
-
- public:
- CSSParserPrefsView(BRect frame,
- const char* name);
- virtual void AttachedToWindow();
-
-};
-
#endif
Modified: trunk/themis/framework/PrefsWin.cpp
===================================================================
--- trunk/themis/framework/PrefsWin.cpp 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/framework/PrefsWin.cpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -334,23 +334,6 @@
break;
}
- case CSS_SELECTED: {
- printf("PREFS: CSS_SELECTED\n");
-
- BString str;
- msg->FindString("CSSFileString", &str);
-
- AppSettings->ReplaceString(kPrefsActiveCSSPath, str.String());
-
- SaveAppSettings();
-
- /*
- * use the app to tell css parser about the CSS change.
- */
- be_app_messenger.SendMessage(CSS_CHANGED);
-
- break;
- }
default :
BWindow::MessageReceived(msg);
}
Modified: trunk/themis/framework/app.cpp
===================================================================
--- trunk/themis/framework/app.cpp 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/framework/app.cpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -266,15 +266,6 @@
break;
}
- case CSS_CHANGED :
- {
- printf( "APP CSS_CHANGED\n" );
- BMessage* chgmsg = new BMessage( CSS_CHANGED_PARSER );
- chgmsg->AddInt32( "command", COMMAND_INFO );
- Broadcast( MS_TARGET_PARSER, chgmsg );
- delete chgmsg;
- break;
- }
case PREFSWIN_CLOSE :
{
printf( "APP PREFSWIN_CLOSE\n" );
@@ -608,55 +599,6 @@
if( !AppSettings->HasInt8( kPrefsTabHistoryDepth ) )
AppSettings->AddInt8( kPrefsTabHistoryDepth, 10 );
- /* Prefs Parser */
- if( !AppSettings->HasString( kPrefsActiveCSSPath ) ||
- strcmp( AppSettings->FindString( kPrefsActiveCSSPath ), kNoCSSFoundString ) == 0 )
- {
- /* set our default */
- if( !AppSettings->HasString( kPrefsActiveCSSPath ) )
- AppSettings->AddString( kPrefsActiveCSSPath, kNoCSSFoundString );
-
- /* find a CSS file */
- BString cssdir;
- AppSettings->FindString( kPrefsSettingsDirectory, &cssdir );
- cssdir.Append( "/css/" );
- printf( "CSS dir: %s\n", cssdir.String() );
-
- BDirectory dir( cssdir.String() );
- if( dir.InitCheck() != B_OK )
- {
- printf( "CSS directory (%s) not found!\n", cssdir.String() );
- printf( "Setting kPrefsActiveCSSPath to \"none\"\n" );
- AppSettings->AddString( kPrefsActiveCSSPath, kNoCSSFoundString );
- }
- else
- {
- BEntry entry;
- while( dir.GetNextEntry( &entry, false ) != B_ENTRY_NOT_FOUND )
- {
- BPath path;
- entry.GetPath( &path );
- char name[B_FILE_NAME_LENGTH];
- entry.GetName( name );
-
- BString nstring( name );
- printf( "----------------\n" );
- printf( "found CSS file: %s\n", nstring.String() );
- if( AppSettings->HasString( kPrefsActiveCSSPath ) )
- {
- printf( "replacing kPrefsActiveCSSPath with: %s\n", path.Path() );
- AppSettings->ReplaceString( kPrefsActiveCSSPath, path.Path() );
- }
- else
- {
- printf( "adding kPrefsActiveCSSPath: %s\n", path.Path() );
- AppSettings->AddString( kPrefsActiveCSSPath, path.Path() );
- }
- }
- }
- /* end: find a CSS file */
- }
-
AppSettings->PrintToStream();
}
Modified: trunk/themis/makefile
===================================================================
--- trunk/themis/makefile 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/makefile 2010-11-03 22:55:11 UTC (rev 562)
@@ -223,7 +223,8 @@
CSSParser/MediaAtRuleParser.cpp \
CSSParser/Position.cpp \
CSSParser/ReadException.cpp \
- CSSParser/RuleSetParser.cpp
+ CSSParser/RuleSetParser.cpp \
+ CSSParser/CSSParserPrefsView.cpp
DOMVIEWSOURCES= \
DOMView/DOMView.cpp \
Modified: trunk/themis/modules/CSSParser/CSSParserPlugin.cpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPlugin.cpp 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/modules/CSSParser/CSSParserPlugin.cpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -42,16 +42,20 @@
#include <algorithm>
#include <ctype.h>
-// Be headers
+// BeOS headers
#include <Message.h>
#include <DataIO.h>
+#include <storage/Directory.h>
-// CSSParser headers
-#include "CSSParserPlugin.hpp"
+// Themis headers
#include "commondefs.h"
#include "plugman.h"
#include "PrefsDefs.h"
+// CSSParser headers
+#include "CSSParserPlugin.hpp"
+#include "CSSParserPrefsView.hpp"
+
CSSParserPlugin * parser;
BMessage ** appSettings_p;
BMessage * appSettings;
@@ -104,6 +108,18 @@
// We only support one mimetype at the momemt.
mMimeTypes.push_back("text/css");
+
+ // Check the settings...
+ if(!appSettings->HasString(kPrefsCSSDirectory)) {
+ BString dir;
+ AppSettings->FindString(kPrefsSettingsDirectory, &dir);
+ dir.Append("/css");
+ AppSettings->AddString(kPrefsCSSDirectory, dir.String());
+ BEntry ent(dir.String(), true);
+ if (!ent.Exists()) {
+ create_directory(dir.String(), 0555);
+ }
+ }
}
@@ -269,7 +285,27 @@
void CSSParserPlugin :: MessageReceived(BMessage * aMessage) {
- BHandler::MessageReceived(aMessage);
+ switch (aMessage->what) {
+ case CSS_CHANGED_PARSER: {
+ Debug("Request to change base css file", PlugID());
+ if (appSettings != NULL) {
+ const char * path;
+ appSettings->FindString(kPrefsActiveCSSPath, &path);
+ string cssLoad = "Loading new CSS file: ";
+ cssLoad += path;
+ printf("%s\n", cssLoad.c_str());
+ Debug(cssLoad.c_str(), PlugID());
+ CSSStyleSheetPtr document = mParser->parse(path);
+ mDocuments.push_back(document);
+ NotifyParseFinished(mDocuments.end() - 1, "cssdom", aMessage);
+ }
+ break;
+ }
+ default: {
+ BHandler::MessageReceived(aMessage);
+ break;
+ }
+ }
}
@@ -305,7 +341,7 @@
float CSSParserPlugin :: PlugVersion() {
- return 0.2;
+ return 0.3;
}
@@ -341,21 +377,6 @@
}
break;
}
- case CSS_CHANGED_PARSER: {
- Debug("Request to change base css file", PlugID());
- if (appSettings != NULL) {
- const char * path;
- appSettings->FindString(kPrefsActiveCSSPath, &path);
- string cssLoad = "Loading new CSS file: ";
- cssLoad += path;
- printf("%s\n", cssLoad.c_str());
- Debug(cssLoad.c_str(), PlugID());
- CSSStyleSheetPtr document = mParser->parse(path);
- mDocuments.push_back(document);
- NotifyParseFinished(mDocuments.end() - 1, "cssdom", aMessage);
- }
- break;
- }
case SH_PARSE_DOC_FINISHED: {
BString type;
aMessage->FindString("type", &type);
@@ -407,3 +428,19 @@
return TARGET_PARSER;
}
+
+char * CSSParserPlugin :: SettingsViewLabel() {
+
+ return "CSS Parser";
+}
+
+BView * CSSParserPlugin :: SettingsView(BRect aFrame) {
+
+ CSSParserPrefsView * view = new CSSParserPrefsView(
+ aFrame,
+ "CSS Parser",
+ this);
+
+ return view;
+
+}
Modified: trunk/themis/modules/CSSParser/CSSParserPlugin.hpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPlugin.hpp 2010-11-02 22:18:34 UTC (rev 561)
+++ trunk/themis/modules/CSSParser/CSSParserPlugin.hpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -112,6 +112,8 @@
status_t BroadcastReply(BMessage * aMessage);
uint32 BroadcastTarget();
int32 Type();
+ char * SettingsViewLabel();
+ BView * SettingsView(BRect aFrame);
};
Added: trunk/themis/modules/CSSParser/CSSParserPrefsView.cpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPrefsView.cpp (rev 0)
+++ trunk/themis/modules/CSSParser/CSSParserPrefsView.cpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -0,0 +1,158 @@
+/*
+ Copyright (c) 2010 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: November 03, 2010
+*/
+
+/* CSSParserPrefsView implementation
+ See CSSParserPrefsView.hpp for more information
+*/
+
+// Standard C headers
+#include <stdio.h>
+
+// BeOS headers
+#include <interface/Window.h>
+#include <interface/Box.h>
+#include <interface/PopUpMenu.h>
+#include <interface/MenuItem.h>
+#include <interface/MenuField.h>
+#include <storage/Directory.h>
+#include <storage/Entry.h>
+#include <storage/Path.h>
+
+// Themis headers
+#include "commondefs.h"
+#include "PrefsDefs.h"
+#include "plugclass.h"
+
+
+// CSSParser headers
+#include "CSSParserPrefsView.hpp"
+
+CSSParserPrefsView :: CSSParserPrefsView(BRect aFrame,
+ const char* aName,
+ BHandler * aPlugin)
+ : BasePrefsView(aFrame,
+ aName) {
+
+ mPlugin = aPlugin;
+
+ /* CSS file selection */
+ mPopUpMenu = new BPopUpMenu(
+ "No CSS selected or available!",
+ true,
+ true,
+ B_ITEMS_IN_COLUMN);
+
+ /* find a CSS file */
+ AppSettings->FindString(kPrefsSettingsDirectory, &mCSSDir);
+ mCSSDir.Append("/css/");
+ printf("CSS dir: %s\n", mCSSDir.String());
+
+ BDirectory dir(mCSSDir.String());
+ if(dir.InitCheck() != B_OK) {
+ printf("CSS directory (%s) not found!\n", mCSSDir.String());
+ printf("Setting CSSToUsePath to \"none\"\n");
+ AppSettings->AddString(kPrefsActiveCSSPath, kNoCSSFoundString);
+ }
+ else {
+ BString activeCSS;
+ AppSettings->FindString(kPrefsActiveCSSPath, &activeCSS);
+
+ BEntry entry;
+ while(dir.GetNextEntry(&entry, false) != B_ENTRY_NOT_FOUND) {
+ BPath path;
+ entry.GetPath(&path);
+ char name[B_FILE_NAME_LENGTH];
+ entry.GetName(name);
+
+ BString nstring(name);
+ printf("----------------\n");
+ printf("found CSS file: %s\n", nstring.String());
+
+ /* add the file to the popupmenu */
+ BMessage* msg = new BMessage(CSS_CHANGED_PARSER);
+ msg->AddString("CSSFileString", path.Path());
+ BMenuItem* item = new BMenuItem(name, msg, 0, 0);
+ item->SetTarget(mPlugin);
+ mPopUpMenu->AddItem(item);
+
+ // if the path of the current file equals the one of the settings,
+ // mark the item
+ if(strcmp(activeCSS.String(), path.Path() ) == 0) {
+ printf("CSS from settings found -> SetMarked( true )\n");
+ (mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1))->SetMarked(true);
+ }
+ } // while
+
+ }
+ // end: find a CSS file
+
+ BRect rect = mMainBox->Bounds();
+ rect.InsetBy(kItemSpacing, kItemSpacing);
+ rect.top += kBBoxExtraInset;
+
+ BMenuField* cssmenufield = new BMenuField(
+ rect,
+ "CSSFIELD", "Cascading Style Sheet:",
+ mPopUpMenu,
+ true,
+ B_FOLLOW_TOP,
+ B_WILL_DRAW);
+ cssmenufield->SetDivider(be_plain_font->StringWidth("Cascading Style Sheet:") + kItemSpacing);
+ mMainBox->AddChild(cssmenufield);
+
+}
+
+void CSSParserPrefsView :: AttachedToWindow() {
+
+ // if we found some CSS files, but still no CSS file is saved in the prefs,
+ // or no CSS file is selected:
+ // set the last found CSS file in the prefs. we save it to the prefs,
+ // because the user might not reselect a CSS file in the list, which
+ // would save the CSS file.
+ BMessage msg(CSS_CHANGED_PARSER);
+ BMessenger msgr(mPlugin);
+ if (mPopUpMenu->CountItems() > 0) {
+ if (mPopUpMenu->FindMarked() == NULL) {
+ printf("no marked item found\n");
+ BMenuItem* item = mPopUpMenu->ItemAt(mPopUpMenu->CountItems() - 1);
+ item->SetMarked(true);
+ // as we cannot invoke the item here, send the CSS_SELECTED message here
+ BString cssstring(mCSSDir.String());
+ cssstring.Append(item->Label());
+ msg.AddString("CSSFileString", cssstring.String());
+ msgr.SendMessage(&msg);
+ }
+ }
+ else {
+ msg.AddString("CSSFileString", kNoCSSFoundString);
+ msgr.SendMessage(&msg);
+ }
+
+}
Added: trunk/themis/modules/CSSParser/CSSParserPrefsView.hpp
===================================================================
--- trunk/themis/modules/CSSParser/CSSParserPrefsView.hpp (rev 0)
+++ trunk/themis/modules/CSSParser/CSSParserPrefsView.hpp 2010-11-03 22:55:11 UTC (rev 562)
@@ -0,0 +1,73 @@
+/*
+ Copyright (c) 2010 Mark Hellegers. All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice
+ shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Original Author: Mark Hellegers (ma...@fi...)
+ Project Start Date: October 18, 2000
+ Class Start Date: October 31, 2010
+*/
+
+/* HTMLParserPrefsView
+ Contains the preferences view for the HTML parser addon.
+
+ Mark Hellegers (ma...@fi...)
+ 03-11-2010
+*/
+
+#ifndef CSSPARSERPREFSVIEW_HPP
+#define CSSPARSERPREFSVIEW_HPP
+
+// BeOS headers
+#include <String.h>
+
+// Themis headers
+#include "BasePrefsView.hpp"
+
+// Declarations used
+class BPopUpMenu;
+class BHandler;
+
+/// Class to view the preferences of the CSS parser addon.
+
+/**
+ This class is a view of the preferences of the CSS parser addon.
+*/
+
+class CSSParserPrefsView : public BasePrefsView {
+
+ private:
+ BPopUpMenu * mPopUpMenu;
+ BString mCSSDir;
+ BHandler * mPlugin;
+
+ public:
+ CSSParserPrefsView(BRect aFrame,
+ const char* aName,
+ BHandler * aPlugin);
+ virtual void AttachedToWindow();
+
+};
+
+#endif
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|