Skip to content

Commit

Permalink
Auto-Save plugin is now functional and can be configured from: Plugin…
Browse files Browse the repository at this point in the history
…s->Auto Save
  • Loading branch information
Eran Ifrah committed Sep 13, 2016
1 parent acdde88 commit d18cd2d
Show file tree
Hide file tree
Showing 12 changed files with 1,092 additions and 17 deletions.
32 changes: 24 additions & 8 deletions AutoSave/AutoSave.project
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<CodeLite_Project Name="AutoSave">
<VirtualDirectory Name="src">
<File Name="autosave.cpp"/>
<File Name="AutoSaveSettings.h"/>
<File Name="AutoSaveSettings.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="include">
<File Name="autosave.h"/>
Expand Down Expand Up @@ -38,12 +40,12 @@
<Command Enabled="yes">copy "$(IntermediateDirectory)\AutoSave-dbg.dll" ..\Runtime\plugins</Command>
</PostBuild>
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<CleanCommand/>
<BuildCommand/>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild></CustomPreBuild>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
</Configuration>
<Configuration Name="Win_x64_Release" CompilerType="g++-64" DebuggerType="GNU gdb debugger">
Expand Down Expand Up @@ -73,13 +75,27 @@
<Command Enabled="yes">copy "$(IntermediateDirectory)\AutoSave.dll" ..\Runtime\plugins</Command>
</PostBuild>
<CustomBuild Enabled="no">
<CleanCommand></CleanCommand>
<BuildCommand></BuildCommand>
<CleanCommand/>
<BuildCommand/>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild></CustomPostBuild>
<CustomPreBuild></CustomPreBuild>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
</Configuration>
</Settings>
<VirtualDirectory Name="UI">
<File Name="AutoSaveDlg.h"/>
<File Name="AutoSaveDlg.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="wxcrafter">
<File Name="AutoSaveUI.wxcp"/>
<VirtualDirectory Name="resources">
<File Name="AutoSaveUI_autosave_bitmaps.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="base">
<File Name="AutoSaveUI.h"/>
<File Name="AutoSaveUI.cpp"/>
</VirtualDirectory>
</VirtualDirectory>
</CodeLite_Project>
24 changes: 24 additions & 0 deletions AutoSave/AutoSaveDlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "AutoSaveDlg.h"
#include "AutoSaveSettings.h"

AutoSaveDlg::AutoSaveDlg(wxWindow* parent)
: AutoSaveDlgBase(parent)
{
AutoSaveSettings conf = AutoSaveSettings::Load();
m_checkBoxEnabled->SetValue(conf.HasFlag(AutoSaveSettings::kEnabled));
m_spinCtrlInterval->SetValue(conf.GetCheckInterval());
}

AutoSaveDlg::~AutoSaveDlg() {}

void AutoSaveDlg::OnEnabledUI(wxUpdateUIEvent& event) { event.Enable(m_checkBoxEnabled->IsChecked()); }

void AutoSaveDlg::OnOK(wxCommandEvent& event)
{
AutoSaveSettings conf;
conf.EnableFlag(AutoSaveSettings::kEnabled, m_checkBoxEnabled->IsChecked());
conf.SetCheckInterval(m_spinCtrlInterval->GetValue());
AutoSaveSettings::Save(conf);

EndModal(wxID_OK);
}
39 changes: 39 additions & 0 deletions AutoSave/AutoSaveDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright : (C) 2016 The CodeLite Team
// File name : AutoSaveDlg.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef AUTOSAVEDLG_H
#define AUTOSAVEDLG_H
#include "AutoSaveUI.h"

class AutoSaveDlg : public AutoSaveDlgBase
{
public:
AutoSaveDlg(wxWindow* parent);
virtual ~AutoSaveDlg();
protected:
virtual void OnOK(wxCommandEvent& event);
virtual void OnEnabledUI(wxUpdateUIEvent& event);
};
#endif // AUTOSAVEDLG_H
38 changes: 38 additions & 0 deletions AutoSave/AutoSaveSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "AutoSaveSettings.h"

AutoSaveSettings::AutoSaveSettings()
: clConfigItem("auto-save")
, m_flags(kEnabled)
, m_checkInterval(5)
{
}

AutoSaveSettings::~AutoSaveSettings() {}

void AutoSaveSettings::FromJSON(const JSONElement& json)
{
m_flags = json.namedObject("m_flags").toSize_t(m_flags);
m_checkInterval = json.namedObject("m_checkInterval").toSize_t(m_checkInterval);
}

JSONElement AutoSaveSettings::ToJSON() const
{
JSONElement json = JSONElement::createObject(GetName());
json.addProperty("m_flags", m_flags);
json.addProperty("m_checkInterval", m_checkInterval);
return json;
}

AutoSaveSettings AutoSaveSettings::Load()
{
AutoSaveSettings settings;
clConfig config("auto-save.conf");
config.ReadItem(&settings);
return settings;
}

void AutoSaveSettings::Save(const AutoSaveSettings& settings)
{
clConfig config("auto-save.conf");
config.WriteItem(&settings);
}
73 changes: 73 additions & 0 deletions AutoSave/AutoSaveSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// Copyright : (C) 2016 The CodeLite Team
// File name : AutoSaveSettings.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#ifndef AUTOSAVESETTINGS_H
#define AUTOSAVESETTINGS_H

#include "cl_config.h"

class AutoSaveSettings : public clConfigItem
{
public:
enum {
kEnabled = (1 << 0),
};

protected:
size_t m_flags;
size_t m_checkInterval;

public:
AutoSaveSettings();
~AutoSaveSettings();

virtual void FromJSON(const JSONElement& json);
virtual JSONElement ToJSON() const;

static AutoSaveSettings Load();
static void Save(const AutoSaveSettings& settings);

AutoSaveSettings& EnableFlag(int flag, bool b = true)
{
b ? (m_flags |= flag) : (m_flags &= ~flag);
return *this;
}

bool HasFlag(int flag) const { return m_flags & flag; }
AutoSaveSettings& SetFlags(size_t flags)
{
this->m_flags = flags;
return *this;
}
size_t GetFlags() const { return m_flags; }
AutoSaveSettings& SetCheckInterval(size_t checkInterval)
{
this->m_checkInterval = checkInterval;
return *this;
}
size_t GetCheckInterval() const { return m_checkInterval; }
};

#endif // AUTOSAVESETTINGS_H
87 changes: 87 additions & 0 deletions AutoSave/AutoSaveUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//////////////////////////////////////////////////////////////////////
// This file was auto-generated by codelite's wxCrafter Plugin
// wxCrafter project file: AutoSaveUI.wxcp
// Do not modify this file by hand!
//////////////////////////////////////////////////////////////////////

#include "AutoSaveUI.h"


// Declare the bitmap loading function
extern void wxCrafter7A2fyVInitBitmapResources();

static bool bBitmapLoaded = false;


AutoSaveDlgBase::AutoSaveDlgBase(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
: wxDialog(parent, id, title, pos, size, style)
{
if ( !bBitmapLoaded ) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafter7A2fyVInitBitmapResources();
bBitmapLoaded = true;
}

wxBoxSizer* boxSizer2 = new wxBoxSizer(wxVERTICAL);
this->SetSizer(boxSizer2);

wxFlexGridSizer* flexGridSizer8 = new wxFlexGridSizer(0, 2, 0, 0);
flexGridSizer8->SetFlexibleDirection( wxBOTH );
flexGridSizer8->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
flexGridSizer8->AddGrowableCol(1);

boxSizer2->Add(flexGridSizer8, 1, wxALL|wxEXPAND, WXC_FROM_DIP(5));

m_checkBoxEnabled = new wxCheckBox(this, wxID_ANY, _("Enable Auto Save"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
m_checkBoxEnabled->SetValue(true);

flexGridSizer8->Add(m_checkBoxEnabled, 0, wxALL, WXC_FROM_DIP(5));

flexGridSizer8->Add(0, 0, 1, wxALL, WXC_FROM_DIP(5));

m_staticText14 = new wxStaticText(this, wxID_ANY, _("Save interval:"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
m_staticText14->SetToolTip(_("Check and save modified files interval (in seconds)"));

flexGridSizer8->Add(m_staticText14, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, WXC_FROM_DIP(5));

m_spinCtrlInterval = new wxSpinCtrl(this, wxID_ANY, wxT("5"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxSP_WRAP|wxSP_ARROW_KEYS);
m_spinCtrlInterval->SetToolTip(_("Check and save modified files interval (in seconds)"));
m_spinCtrlInterval->SetRange(1, 100);
m_spinCtrlInterval->SetValue(5);

flexGridSizer8->Add(m_spinCtrlInterval, 0, wxALL, WXC_FROM_DIP(5));

m_stdBtnSizer4 = new wxStdDialogButtonSizer();

boxSizer2->Add(m_stdBtnSizer4, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, WXC_FROM_DIP(5));

m_button6 = new wxButton(this, wxID_OK, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
m_button6->SetDefault();
m_stdBtnSizer4->AddButton(m_button6);
m_stdBtnSizer4->Realize();

SetName(wxT("AutoSaveDlgBase"));
SetSize(-1,-1);
if (GetSizer()) {
GetSizer()->Fit(this);
}
if(GetParent()) {
CentreOnParent(wxBOTH);
} else {
CentreOnScreen(wxBOTH);
}
// Connect events
m_staticText14->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(AutoSaveDlgBase::OnEnabledUI), NULL, this);
m_spinCtrlInterval->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(AutoSaveDlgBase::OnEnabledUI), NULL, this);
m_button6->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AutoSaveDlgBase::OnOK), NULL, this);

}

AutoSaveDlgBase::~AutoSaveDlgBase()
{
m_staticText14->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(AutoSaveDlgBase::OnEnabledUI), NULL, this);
m_spinCtrlInterval->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(AutoSaveDlgBase::OnEnabledUI), NULL, this);
m_button6->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AutoSaveDlgBase::OnOK), NULL, this);

}
Loading

0 comments on commit d18cd2d

Please sign in to comment.