Skip to content

Commit

Permalink
Add class CFortranIndentConfigDlg to Configure Fortran Indent
Browse files Browse the repository at this point in the history
Add CFortranIndentConfigDlg.h/.cpp
Add Format_Fortran_Indent_Plugin.xrc
Add Format_Fortran_Indent_Plugin(-off).png
  • Loading branch information
ywx committed Apr 27, 2012
1 parent 1e4f69c commit 7a34e2f
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 83 deletions.
84 changes: 84 additions & 0 deletions CFortranIndentConfigDlg.cpp
@@ -0,0 +1,84 @@
/***************************************************************
* Name: CFortranIndentConfigDlg.cpp
* Purpose: Class to Configure Fortran Indent Dialog
* Author: YWX (wxFortranIndent@163.com)
* Created: 2012-4-24
* Copyright: (c) YWX <wxFortranIndent@163.com>
* Licence: GNU General Public License, version 3
**************************************************************/

#include <sdk.h>
#include "CFortranIndentConfigDlg.h"
#include <configmanager.h>
#include <wx/xrc/xmlres.h>
#include <wx/checkbox.h>
#include <wx/spinctrl.h>
#include <string>

BEGIN_EVENT_TABLE( CFortranIndentConfigDlg, wxPanel )
EVT_CHECKBOX( XRCID("cb_SameAsEditor"), CFortranIndentConfigDlg::OnIsSameAsEditorClick )
EVT_CHECKBOX( XRCID("cb_UseTab"), CFortranIndentConfigDlg::OnIsUseTabClick )
END_EVENT_TABLE()

CFortranIndentConfigDlg::CFortranIndentConfigDlg(wxWindow* parent)
{
wxXmlResource::Get()->LoadPanel(this, parent, _T("dlgFortranIndent"));

LoadSettings();
}

CFortranIndentConfigDlg::~CFortranIndentConfigDlg()
{
}

void CFortranIndentConfigDlg::LoadSettings()
{
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("fortran_indent"));

bool isSameAsEditor = true;
bool isUseTab = false;
int iTabWidth = 4;
bool isKeepBlankLineOnly = false;
bool isTrimLineFromRight = false;

if( cfg->Read( _T("is_SameAsEditor"), & isSameAsEditor ) )
{
cfg->Read( _T("is_UseTab"), & isUseTab );
cfg->Read( _T("i_TabWidth"), & iTabWidth );
cfg->Read( _T("is_KeepBlankLineOnly"), & isKeepBlankLineOnly );
cfg->Read( _T("is_TrimLineFromRight"), & isTrimLineFromRight );
}

XRCCTRL(*this, "cb_SameAsEditor", wxCheckBox)->SetValue( isSameAsEditor );
XRCCTRL(*this, "cb_UseTab", wxCheckBox)->SetValue( isUseTab );
XRCCTRL(*this, "cb_UseTab", wxCheckBox)->Enable( ! isSameAsEditor );
XRCCTRL(*this, "sp_TabWidth", wxSpinCtrl)->SetValue( iTabWidth );
XRCCTRL(*this, "sp_TabWidth", wxCheckBox)->Enable( ! ( isSameAsEditor || isUseTab ) );
XRCCTRL(*this, "cb_KeepBlankLineOnly", wxCheckBox)->SetValue( isKeepBlankLineOnly );
XRCCTRL(*this, "cb_TrimLineFromRight", wxCheckBox)->SetValue( isTrimLineFromRight );
}

void CFortranIndentConfigDlg::SaveSettings()
{
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("fortran_indent"));

cfg->Write(_T("is_SameAsEditor"), (bool) XRCCTRL(*this, "cb_SameAsEditor", wxCheckBox)->GetValue());
cfg->Write(_T("is_UseTab"), (bool) XRCCTRL(*this, "cb_UseTab", wxCheckBox)->GetValue());
cfg->Write(_T("i_TabWidth"), (int) XRCCTRL(*this, "sp_TabWidth", wxSpinCtrl)->GetValue());
cfg->Write(_T("is_KeepBlankLineOnly"), (bool) XRCCTRL(*this, "cb_KeepBlankLineOnly", wxCheckBox)->GetValue());
cfg->Write(_T("is_TrimLineFromRight"), (bool) XRCCTRL(*this, "cb_TrimLineFromRight", wxCheckBox)->GetValue());
}

void CFortranIndentConfigDlg::OnIsSameAsEditorClick(wxCommandEvent& event)
{
bool isSameAsEditor = XRCCTRL(*this, "cb_SameAsEditor", wxCheckBox)->GetValue();
XRCCTRL(*this, "cb_UseTab", wxCheckBox)->Enable( ! ( isSameAsEditor ) );
bool isUseTab = XRCCTRL(*this, "cb_UseTab", wxCheckBox)->GetValue();
XRCCTRL(*this, "sp_TabWidth", wxCheckBox)->Enable( ! ( isSameAsEditor || isUseTab ) );
}

void CFortranIndentConfigDlg::OnIsUseTabClick(wxCommandEvent& event)
{
///
XRCCTRL(*this, "sp_TabWidth", wxCheckBox)->Enable( ! ( XRCCTRL(*this, "cb_UseTab", wxCheckBox)->GetValue() ) );
}
64 changes: 64 additions & 0 deletions CFortranIndentConfigDlg.h
@@ -0,0 +1,64 @@
/***************************************************************
* Name: CFortranIndentConfigDlg.h
* Purpose: declaration of CFortranIndentConfigDlg class
* Author: YWX (wxFortranIndent@163.com)
* Created: 2012-4-25
* Copyright: (c) YWX <wxFortranIndent@163.com>
* Licence: GNU General Public License, version 3
**************************************************************/

#ifndef _MY_WX_CFortranIndentConfigDlg_H_
#define _MY_WX_CFortranIndentConfigDlg_H_

#include <wx/intl.h>
#include "configurationpanel.h"


struct CMyFortranIndentConfig
{
bool isSameAsEditor;
bool isUseTab;
int iTabWidth;
bool isKeepBlankLineOnly;
bool isTrimLineFromRight;

CMyFortranIndentConfig()
{
reset();
}

void reset()
{
isSameAsEditor = true;
isUseTab = false;
iTabWidth = 4;
isKeepBlankLineOnly = false;
isTrimLineFromRight = false;
}
};


class CFortranIndentConfigDlg : public cbConfigurationPanel
{
public:
CFortranIndentConfigDlg(wxWindow* parent);
virtual ~CFortranIndentConfigDlg();

protected:
virtual wxString GetTitle() const { return _("Fortran Indent"); }
virtual wxString GetBitmapBaseName() const { return _T("Format_Fortran_Indent_Plugin"); }
virtual void OnApply(){ SaveSettings(); }
virtual void OnCancel(){}

void LoadSettings();
void SaveSettings();

void OnIsSameAsEditorClick(wxCommandEvent& event);
void OnIsUseTabClick(wxCommandEvent& event);

private:
DECLARE_EVENT_TABLE()
};


#endif // _MY_WX_CFortranIndentConfigDlg_H_
17 changes: 10 additions & 7 deletions CMyWxFortranIndent.cpp
Expand Up @@ -218,18 +218,21 @@ void CMyWxFortranIndent::getFortranIndentLine( const wxString & src1, int & inde

// Special code to compare strings which doesn't care
// about spaces leading up to the EOL.
bool CMyWxFortranIndent::BuffersDiffer( const wxString &a, const wxString &b, const wxString &eolChars )
bool CMyWxFortranIndent::BuffersDiffer( const wxString &a, const wxString &b, const wxString &eolChars, const bool isDelBlank )
{
wxString ta = a;
wxString tb = b;

ta.Trim(); //ta.Trim(true) from right
tb.Trim();

wxASSERT( 0 != myFortranRegEx[wxT("regexBlankLine") ] );
if( isDelBlank )
{
myFortranRegEx[wxT("regexBlankLine")]->ReplaceAll( &ta, eolChars );
myFortranRegEx[wxT("regexBlankLine")]->ReplaceAll( &tb, eolChars );
ta.Trim(); //ta.Trim(true) from right
tb.Trim();

wxASSERT( 0 != myFortranRegEx[wxT("regexBlankLine") ] );
{
myFortranRegEx[wxT("regexBlankLine")]->ReplaceAll( &ta, eolChars );
myFortranRegEx[wxT("regexBlankLine")]->ReplaceAll( &tb, eolChars );
}
}

bool changed = false;
Expand Down
2 changes: 1 addition & 1 deletion CMyWxFortranIndent.h
Expand Up @@ -36,7 +36,7 @@ class CMyWxFortranIndent
void myCreateFortranRegEx();
void myDelFortranRegEx();

bool BuffersDiffer( const wxString &a, const wxString &b, const wxString &eolChars );
bool BuffersDiffer( const wxString &a, const wxString &b, const wxString &eolChars,const bool isDelBlank=true );
bool getIsHasLineContinuation( const wxString & srcLine );
void delLineContinuation( wxString & srcLine );
void delComment( wxString & srcLine );
Expand Down
9 changes: 7 additions & 2 deletions FormatFortranIndentPlugin.cbp
Expand Up @@ -40,15 +40,20 @@
<Add directory="$(#wx.lib)\gcc_dll" />
</Linker>
<ExtraCommands>
<Add after="zip -j9 Format_Fortran_Indent_Plugin.zip manifest.xml" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin.cbplugin Format_Fortran_Indent_Plugin.dll Format_Fortran_Indent_Plugin.zip" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin.zip manifest.xml Format_Fortran_Indent_Plugin.xrc" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin.cbplugin Format_Fortran_Indent_Plugin.dll Format_Fortran_Indent_Plugin.zip Format_Fortran_Indent_Plugin.png Format_Fortran_Indent_Plugin-off.png" />
</ExtraCommands>
</Target>
</Build>
<Unit filename="CFortranIndentConfigDlg.cpp" />
<Unit filename="CFortranIndentConfigDlg.h" />
<Unit filename="CMyWxFortranIndent.cpp" />
<Unit filename="CMyWxFortranIndent.h" />
<Unit filename="Format_Fortran_Indent_Plugin-off.png" />
<Unit filename="Format_Fortran_Indent_Plugin.cpp" />
<Unit filename="Format_Fortran_Indent_Plugin.h" />
<Unit filename="Format_Fortran_Indent_Plugin.png" />
<Unit filename="Format_Fortran_Indent_Plugin.xrc" />
<Unit filename="manifest.xml" />
<Extensions>
<code_completion />
Expand Down
13 changes: 9 additions & 4 deletions FormatFortranIntentPlugin_linux.cbp
Expand Up @@ -24,15 +24,20 @@
<Add option="`wx-config --libs`" />
</Linker>
<ExtraCommands>
<Add after="zip -j9 Format_Fortran_Indent_Plugin.zip manifest.xml" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin_linux.cbplugin Format_Fortran_Indent_Plugin.so Format_Fortran_Indent_Plugin.zip" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin.zip manifest.xml Format_Fortran_Indent_Plugin.xrc" />
<Add after="zip -j9 Format_Fortran_Indent_Plugin_linux.cbplugin Format_Fortran_Indent_Plugin.so Format_Fortran_Indent_Plugin.zip Format_Fortran_Indent_Plugin.png Format_Fortran_Indent_Plugin-off.png" />
</ExtraCommands>
</Target>
</Build>
<Unit filename="Format_Fortran_Indent_Plugin.cpp" />
<Unit filename="Format_Fortran_Indent_Plugin.h" />
<Unit filename="CFortranIndentConfigDlg.cpp" />
<Unit filename="CFortranIndentConfigDlg.h" />
<Unit filename="CMyWxFortranIndent.cpp" />
<Unit filename="CMyWxFortranIndent.h" />
<Unit filename="Format_Fortran_Indent_Plugin-off.png" />
<Unit filename="Format_Fortran_Indent_Plugin.cpp" />
<Unit filename="Format_Fortran_Indent_Plugin.h" />
<Unit filename="Format_Fortran_Indent_Plugin.png" />
<Unit filename="Format_Fortran_Indent_Plugin.xrc" />
<Unit filename="manifest.xml" />
<Extensions>
<envvars />
Expand Down
Binary file added Format_Fortran_Indent_Plugin-off.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Format_Fortran_Indent_Plugin.cbplugin
Binary file not shown.

0 comments on commit 7a34e2f

Please sign in to comment.