Skip to content

Commit

Permalink
Moved settings handling out of ecore and into it's own class (eSettin…
Browse files Browse the repository at this point in the history
…gs).

It now saves the settings in JSON format.
  • Loading branch information
Alexander Stigsen committed Apr 27, 2009
1 parent 865089e commit 34a6299
Show file tree
Hide file tree
Showing 29 changed files with 4,672 additions and 4,215 deletions.
49 changes: 3 additions & 46 deletions ecore/Catalyst.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Document;
class SyncEvent;
class RemoteProfile;
class cxInternal;
class eSettings;

// Type definitions
typedef int REVISION_ID; // DOCUMENT_ID
Expand Down Expand Up @@ -323,6 +324,7 @@ class Catalyst {
bool IsMirroredSpecific(const doc_id& di) const;
bool GetMirrorPaths(const doc_id& di, wxArrayString& paths) const;
bool GetMirrorPathsForDraft(const doc_id& di, wxArrayString& paths) const;
bool VerifyMirror(const wxString& path, const doc_id& di) const;

Dispatcher& GetDispatcher();

Expand All @@ -339,39 +341,7 @@ class Catalyst {

// Settings functions
const wxLongLong& GetId() const;
int GetPageCount() const;
void SetPageSettings(int page_id, const wxString& path, doc_id di, int pos, int topline, const wxString& syntax, const vector<unsigned int>& folds, const vector<cxBookmark>& bookmarks);
void GetPageSettings(int page_id, wxString& path, doc_id& di, int& pos, int& topline, wxString& syntax, vector<unsigned int>& folds, vector<unsigned int>& bookmarks) const;
wxString GetPagePath(unsigned int page_id) const;
void DeletePageSettings(int page_id);
void DeleteAllPageSettings();
void ValidatePagesSettings();
void SetSettingBool(const wxString& name, bool value);
void SetSettingInt(const wxString& name, int value);
void SetSettingLong(const wxString& name, wxLongLong value);
void SetSettingString(const wxString& name, const wxString& value);
bool GetSettingBool(const wxString& name, bool& value) const;
bool GetSettingInt(const wxString& name, int& value) const;
bool GetSettingLong(const wxString& name, wxLongLong& value) const;
bool GetSettingString(const wxString& name, wxString& value) const;
void RemoveSettingString(const wxString& name);
void RemoveSettingInt(const wxString& name);
void RemoveSettingBool(const wxString& name);
void AddRecentFile(const wxString& path);
void AddRecentProject(const wxString& path);
void GetRecentFiles(wxArrayString& recentfiles) const;
void GetRecentProjects(wxArrayString& recentprojects) const;

// Remote profiles
unsigned int GetRemoteProfileCount() const;
wxString GetRemoteProfileName(unsigned int profile_id) const;
unsigned int AddRemoteProfile(const RemoteProfile& profile);
void SetRemoteProfile(unsigned int profile_id, const RemoteProfile& profile);
const RemoteProfile* GetRemoteProfile(unsigned int profile_id);
const RemoteProfile* GetRemoteProfileFromUrl(const wxString& url, bool withDir);
void SetRemoteProfileLogin(const RemoteProfile* rp, const wxString& username, const wxString& pwd, bool toDb);
//bool GetRemoteProfile(const wxString& url, RemoteProfile& profile) const;
void DeleteRemoteProfile(unsigned int profile_id);
void MoveOldSettings(eSettings& settings);

// List of documents
void GetDocList(vector<doc_id>& doclist) const;
Expand Down Expand Up @@ -432,25 +402,12 @@ class Catalyst {
// Utility functions
wxLongLong GetRand64() const;

// Remote profiles
RemoteProfile* DoGetRemoteProfile(unsigned int profile_id);
void SaveRemoteProfile(RemoteProfile* rp);

// Member variables
mutable RecursiveCriticalSection m_critSec;
cxInternal* m_i;

// Settings
wxLongLong m_id;
c4_View m_vPages;
c4_View m_v64hash;
c4_View m_vInthash;
c4_View m_vStringhash;
c4_View m_vRecentFiles;
c4_View m_vRecentPrj;

c4_View m_vRemotes;
auto_vector<RemoteProfile> m_tempRemotes;

friend class Document;
friend class cxInternal;
Expand Down
Binary file modified ecore/ecore.lib
Binary file not shown.
Binary file modified ecore/ecored.lib
Binary file not shown.
Binary file modified ecore/libecore.so
Binary file not shown.
Binary file modified ecore/libecored.so
Binary file not shown.
14 changes: 6 additions & 8 deletions src/CygwinDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ BEGIN_EVENT_TABLE(CygwinDlg, wxDialog)
EVT_BUTTON(wxID_OK, CygwinDlg::OnButtonOk)
END_EVENT_TABLE()

CygwinDlg::CygwinDlg(wxWindow *parent, CatalystWrapper& cw, cxCygwinDlgMode mode)
: wxDialog (parent, wxID_ANY, wxEmptyString, wxDefaultPosition), m_catalyst(cw), m_mode(mode) {
CygwinDlg::CygwinDlg(wxWindow *parent, cxCygwinDlgMode mode)
: wxDialog (parent, wxID_ANY, wxEmptyString, wxDefaultPosition), m_mode(mode) {
if (m_mode == cxCYGWIN_INSTALL) SetTitle(_("Cygwin not installed!"));
else SetTitle(_("Update Cygwin"));

Expand Down Expand Up @@ -54,15 +54,15 @@ CygwinDlg::CygwinDlg(wxWindow *parent, CatalystWrapper& cw, cxCygwinDlgMode mode
void CygwinDlg::OnButtonOk(wxCommandEvent& WXUNUSED(event)) {
const wxString appPath = ((eApp*)wxTheApp)->GetAppPath();
const cxCygwinInstallMode install_mode = m_autoRadio->GetValue() ? cxCYGWIN_AUTO : cxCYGWIN_MANUAL;
new CygwinInstallThread(m_catalyst, install_mode, appPath);
new CygwinInstallThread(install_mode, appPath);

EndModal(wxID_OK);
}

// ---- CygwinInstallThread ------------------------------------------------------------

CygwinDlg::CygwinInstallThread::CygwinInstallThread(CatalystWrapper& cw, cxCygwinInstallMode mode, const wxString& appPath)
: m_catalyst(cw), m_mode(mode), m_appPath(appPath) {
CygwinDlg::CygwinInstallThread::CygwinInstallThread(cxCygwinInstallMode mode, const wxString& appPath)
: m_mode(mode), m_appPath(appPath) {
Create();
Run();
}
Expand Down Expand Up @@ -128,9 +128,7 @@ void* CygwinDlg::CygwinInstallThread::Entry() {
// Mark this update as done
const wxFileName supportFile(supportScript);
const wxDateTime updateTime = supportFile.GetModificationTime();
cxLOCK_WRITE(m_catalyst)
catalyst.SetSettingLong(wxT("cyg_date"), updateTime.GetValue());
cxENDLOCK
((eApp*)wxTheApp)->GetSettings().SetSettingLong(wxT("cyg_date"), updateTime.GetValue());

return NULL;
}
7 changes: 2 additions & 5 deletions src/CygwinDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef __CYGWINDDLG_H__
#define __CYGWINDDLG_H__

#include "Catalyst.h"
#include "wx/wxprec.h" // For compilers that support precompilation, includes "wx/wx.h".

enum cxCygwinDlgMode {
Expand All @@ -29,7 +28,7 @@ enum cxCygwinInstallMode {

class CygwinDlg : public wxDialog {
public:
CygwinDlg(wxWindow *parent, CatalystWrapper& cw, cxCygwinDlgMode mode);
CygwinDlg(wxWindow *parent, cxCygwinDlgMode mode);

private:
// Event handlers
Expand All @@ -38,16 +37,14 @@ class CygwinDlg : public wxDialog {

class CygwinInstallThread : public wxThread {
public:
CygwinInstallThread(CatalystWrapper& cw, cxCygwinInstallMode mode, const wxString& appPath);
CygwinInstallThread(cxCygwinInstallMode mode, const wxString& appPath);
virtual void *Entry();
private:
CatalystWrapper& m_catalyst;
const cxCygwinInstallMode m_mode;
const wxString m_appPath;
};

// Member variables
CatalystWrapper& m_catalyst;
const cxCygwinDlgMode m_mode;
wxRadioButton* m_autoRadio;
wxRadioButton* m_manualRadio;
Expand Down
8 changes: 5 additions & 3 deletions src/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "doc_byte_iter.h"
#include "cx_pcre.h"
#include "Utf.h"
#include "eApp.h"

// Constructor
Document::Document(const doc_id& di, CatalystWrapper cw)
Expand Down Expand Up @@ -60,7 +61,8 @@ void Document::CreateNew() {
void Document::SetDefaultEncoding() {
// Check if we need to set eol property
wxString eolStr;
if (m_catalyst.GetSettingString(wxT("formatEol"), eolStr)) {
eSettings& settings = ((eApp*)wxTheApp)->GetSettings();
if (settings.GetSettingString(wxT("formatEol"), eolStr)) {
wxTextFileType eol = wxTextBuffer::typeDefault;
if (eolStr == wxT("crlf")) eol = wxTextFileType_Dos;
else if (eolStr == wxT("lf")) eol = wxTextFileType_Unix;
Expand All @@ -70,14 +72,14 @@ void Document::SetDefaultEncoding() {

// Check if we need to set encoding property
wxString encStr;
if (m_catalyst.GetSettingString(wxT("formatEncoding"), encStr)) {
if (settings.GetSettingString(wxT("formatEncoding"), encStr)) {
const wxFontEncoding enc = wxFontMapper::GetEncodingFromName(encStr);
SetPropertyEncoding(enc);
}

// Check if we need to set bom property
bool bom;
if (m_catalyst.GetSettingBool(wxT("formatBom"), bom)) {
if (settings.GetSettingBool(wxT("formatBom"), bom)) {
SetPropertyBOM(bom);
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/EditorCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ EditorCtrl::EditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap,
wxString syntax;
vector<unsigned int> folds;
vector<unsigned int> bookmarks;
cxLOCK_READ(m_catalyst)
// Retrieve the page info
wxASSERT(page_id >= 0 && page_id < catalyst.GetPageCount());
catalyst.GetPageSettings(page_id, mirrorPath, di, newpos, topline, syntax, folds, bookmarks);
cxENDLOCK

// Retrieve the page info
eSettings& settings = ((eApp*)wxTheApp)->GetSettings();
wxASSERT(page_id >= 0 && page_id < (int)settings.GetPageCount());
settings.GetPageSettings(page_id, mirrorPath, di, newpos, topline, syntax, folds, bookmarks);

const bool isBundleItem = m_parentFrame.IsBundlePath(mirrorPath);

if (m_parentFrame.IsRemotePath(mirrorPath)) {
Expand Down Expand Up @@ -227,13 +228,12 @@ void EditorCtrl::Init() {
m_wrapAtMargin = false;
bool doShowMargin = false;
int marginChars = 80;
cxLOCK_READ(m_catalyst)
catalyst.GetSettingBool(wxT("autoPair"), m_doAutoPair);
catalyst.GetSettingBool(wxT("autoWrap"), m_doAutoWrap);
catalyst.GetSettingBool(wxT("showMargin"), doShowMargin);
catalyst.GetSettingBool(wxT("wrapMargin"), m_wrapAtMargin);
catalyst.GetSettingInt(wxT("marginChars"), marginChars);
cxENDLOCK
eSettings& settings = ((eApp*)wxTheApp)->GetSettings();
settings.GetSettingBool(wxT("autoPair"), m_doAutoPair);
settings.GetSettingBool(wxT("autoWrap"), m_doAutoWrap);
settings.GetSettingBool(wxT("showMargin"), doShowMargin);
settings.GetSettingBool(wxT("wrapMargin"), m_wrapAtMargin);
settings.GetSettingInt(wxT("marginChars"), marginChars);
m_lastScopePos = -1; // scope selection
if (!doShowMargin) m_wrapAtMargin = false;

Expand Down Expand Up @@ -2887,7 +2887,7 @@ bool EditorCtrl::SaveText(bool askforpath) {

// Check if we need to force the native end-of-line
bool forceNativeEOL = false; // default value
((eApp*)wxTheApp)->GetSettingBool(wxT("force_native_eol"), forceNativeEOL);
((eApp*)wxTheApp)->GetSettings().GetSettingBool(wxT("force_native_eol"), forceNativeEOL);

// Save the text
cxFileResult savedResult;
Expand Down Expand Up @@ -8154,13 +8154,12 @@ void EditorCtrl::OnSettingsChanged(EditorCtrl* self, void* WXUNUSED(data), int W
int marginChars = 80;

// Update settings
cxLOCK_READ(self->m_catalyst)
catalyst.GetSettingBool(wxT("autoPair"), self->m_doAutoPair);
catalyst.GetSettingBool(wxT("autoWrap"), self->m_doAutoWrap);
catalyst.GetSettingBool(wxT("showMargin"), doShowMargin);
catalyst.GetSettingBool(wxT("wrapMargin"), self->m_wrapAtMargin);
catalyst.GetSettingInt(wxT("marginChars"), marginChars);
cxENDLOCK
eSettings& settings = ((eApp*)wxTheApp)->GetSettings();
settings.GetSettingBool(wxT("autoPair"), self->m_doAutoPair);
settings.GetSettingBool(wxT("autoWrap"), self->m_doAutoWrap);
settings.GetSettingBool(wxT("showMargin"), doShowMargin);
settings.GetSettingBool(wxT("wrapMargin"), self->m_wrapAtMargin);
settings.GetSettingInt(wxT("marginChars"), marginChars);

if (!doShowMargin) {
marginChars = 0;
Expand Down
Loading

0 comments on commit 34a6299

Please sign in to comment.