Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15448/src/gui

Modified Files:
        wxOptionsDlg.cpp 
Log Message:
finished config sources dialog implementation

Index: wxOptionsDlg.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxOptionsDlg.cpp,v
retrieving revision 1.422
retrieving revision 1.423
diff -b -u -2 -r1.422 -r1.423
--- wxOptionsDlg.cpp    5 Jul 2005 12:40:29 -0000       1.422
+++ wxOptionsDlg.cpp    5 Jul 2005 15:32:12 -0000       1.423
@@ -83,4 +83,5 @@
 extern const MPersMsgBox *M_MSGBOX_CONFIRM_EXIT;
 extern const MPersMsgBox *M_MSGBOX_OPT_STOREREMOTENOW;
+extern const MPersMsgBox *M_MSGBOX_WARN_RESTART_OPT;
 
 // ----------------------------------------------------------------------------
@@ -853,6 +854,22 @@
    };
 
+   // event handlers
+   void OnButtonUp(wxCommandEvent& event);
+   void OnButtonDown(wxCommandEvent& event);
+   void OnButtonAdd(wxCommandEvent& event);
+   void OnButtonDelete(wxCommandEvent& event);
+
+   void OnUpdateButtonUp(wxUpdateUIEvent& event);
+   void OnUpdateButtonDown(wxUpdateUIEvent& event);
+   void OnUpdateButtonDelete(wxUpdateUIEvent& event);
+
+   // exchange the contents of the 2 given rows
+   void ExchangeRows(int row1, int row2);
+
+
    wxGrid *m_sources;
 
+
+   DECLARE_EVENT_TABLE()
    DECLARE_NO_COPY_CLASS(wxConfigSourcesDialog)
 };
@@ -4759,4 +4776,15 @@
 // ----------------------------------------------------------------------------
 
+BEGIN_EVENT_TABLE(wxConfigSourcesDialog, wxManuallyLaidOutDialog)
+   EVT_BUTTON(wxID_UP, wxConfigSourcesDialog::OnButtonUp)
+   EVT_BUTTON(wxID_DOWN, wxConfigSourcesDialog::OnButtonDown)
+   EVT_BUTTON(wxID_ADD, wxConfigSourcesDialog::OnButtonAdd)
+   EVT_BUTTON(wxID_DELETE, wxConfigSourcesDialog::OnButtonDelete)
+
+   EVT_UPDATE_UI(wxID_UP, wxConfigSourcesDialog::OnUpdateButtonUp)
+   EVT_UPDATE_UI(wxID_DOWN, wxConfigSourcesDialog::OnUpdateButtonDown)
+   EVT_UPDATE_UI(wxID_DELETE, wxConfigSourcesDialog::OnUpdateButtonDelete)
+END_EVENT_TABLE()
+
 wxConfigSourcesDialog::wxConfigSourcesDialog(wxFrame *parent)
                      : wxManuallyLaidOutDialog(parent,
@@ -4769,27 +4797,38 @@
    wxStaticBox *box = CreateStdButtonsAndBox(_("&Sources:"));
 
-   // create a short help message above
-   wxStaticText *msg = new wxStaticText
-                           (
-                              this, -1,
-                              _("Mahogany will always read its options from "
-                                "the main config file first, but other 
config\n"
-                                "sources may be added here and will be used "
-                                "for the options not found in the main one.")
-                           );
+   // create the buttons
+   wxButton *btnUp = new wxButton(this, wxID_UP, _("&Up"));
    c = new wxLayoutConstraints;
-   c->left.SameAs(box, wxLeft, 2*LAYOUT_X_MARGIN);
-   c->right.SameAs(box, wxRight, 2*LAYOUT_X_MARGIN);
-   c->top.SameAs(box, wxTop, 4*LAYOUT_Y_MARGIN);
+   c->width.AsIs();
    c->height.AsIs();
-   msg->SetConstraints(c);
+   c->right.SameAs(box, wxRight, 2*LAYOUT_X_MARGIN);
+   c->bottom.SameAs(box, wxCentreY, LAYOUT_Y_MARGIN);
+   btnUp->SetConstraints(c);
 
-   // create the listbox with the buttons in the area which is left
+   wxButton *btnDown = new wxButton(this, wxID_DOWN, _("Do&wn"));
    c = new wxLayoutConstraints;
-   c->left.SameAs(box, wxLeft, 2*LAYOUT_X_MARGIN);
+   c->width.AsIs();
+   c->height.AsIs();
    c->right.SameAs(box, wxRight, 2*LAYOUT_X_MARGIN);
-   c->top.Below(msg, 2*LAYOUT_Y_MARGIN);
+   c->top.SameAs(box, wxCentreY, LAYOUT_Y_MARGIN);
+   btnDown->SetConstraints(c);
+
+   wxButton *btnAdd = new wxButton(this, wxID_ADD, _("&Add"));
+   c = new wxLayoutConstraints;
+   c->width.AsIs();
+   c->height.AsIs();
+   c->right.SameAs(box, wxCentreX, 2*LAYOUT_X_MARGIN);
    c->bottom.SameAs(box, wxBottom, 2*LAYOUT_Y_MARGIN);
+   btnAdd->SetConstraints(c);
 
+   wxButton *btnDelete = new wxButton(this, wxID_DELETE, _("&Delete"));
+   c = new wxLayoutConstraints;
+   c->width.AsIs();
+   c->height.AsIs();
+   c->left.RightOf(btnAdd, 2*LAYOUT_X_MARGIN);
+   c->top.SameAs(btnAdd, wxTop);
+   btnDelete->SetConstraints(c);
+
+   // create the grid in the area which is left
    m_sources = new wxGrid(this, -1);
    m_sources->CreateGrid(0, Col_Max, wxGrid::wxGridSelectRows);
@@ -4805,5 +4844,4 @@
                                     MismatchConfigSrcColumns );
 
-   wxListItem col;
    for ( int i = 0; i < Col_Max; i++ )
    {
@@ -4811,4 +4849,9 @@
    }
 
+   c = new wxLayoutConstraints;
+   c->left.SameAs(box, wxLeft, 2*LAYOUT_X_MARGIN);
+   c->right.LeftOf(btnDown, 2*LAYOUT_X_MARGIN);
+   c->top.SameAs(box, wxTop, 5*LAYOUT_Y_MARGIN);
+   c->bottom.Above(btnAdd, -2*LAYOUT_Y_MARGIN);
    m_sources->SetConstraints(c);
 
@@ -4887,4 +4930,5 @@
    }
 
+   m_sources->Fit();
    Layout();
 
@@ -4931,10 +4975,72 @@
       }
 
-      // TODO: AllConfigSources::Get().SetSources(names, types, specs);
+      if ( !AllConfigSources::Get().SetSources(names, types, specs) )
+         return false;
    }
 
+   MDialog_Message(_("Please notice that changes to configuration sources "
+                     "will only take effect during next program run."),
+                   NULL,
+                   _("Configuration Sources Updated"),
+                   GetPersMsgBoxName(M_MSGBOX_WARN_RESTART_OPT));
+
    return true;
 }
 
+void wxConfigSourcesDialog::ExchangeRows(int row1, int row2)
+{
+   wxString s;
+   for ( int col = 0; col < Col_Max; col++ )
+   {
+      s = m_sources->GetCellValue(row1, col);
+      m_sources->SetCellValue(row1, col, m_sources->GetCellValue(row2, col));
+      m_sources->SetCellValue(row2, col, s);
+   }
+
+   m_sources->SetGridCursor(row2, m_sources->GetGridCursorCol());
+}
+
+void wxConfigSourcesDialog::OnUpdateButtonUp(wxUpdateUIEvent& event)
+{
+   // first row must always remain on top, so row 1 can't be moved up
+   event.Enable( m_sources->GetCursorRow() > 1 );
+}
+
+void wxConfigSourcesDialog::OnUpdateButtonDown(wxUpdateUIEvent& event)
+{
+   // first row can't be moved down as it can't be moved at all and the last
+   // row can't be moved down any more neither
+   const int row = m_sources->GetCursorRow();
+   event.Enable( row > 0 && row < m_sources->GetNumberRows() - 1 );
+}
+
+void wxConfigSourcesDialog::OnUpdateButtonDelete(wxUpdateUIEvent& event)
+{
+   // first row can't be deleted, we always have local config
+   event.Enable( m_sources->GetCursorRow() > 0 );
+}
+
+void wxConfigSourcesDialog::OnButtonUp(wxCommandEvent& WXUNUSED(event))
+{
+   const int row = m_sources->GetCursorRow();
+   ExchangeRows(row, row - 1);
+}
+
+void wxConfigSourcesDialog::OnButtonDown(wxCommandEvent& WXUNUSED(event))
+{
+   const int row = m_sources->GetCursorRow();
+   ExchangeRows(row, row + 1);
+}
+
+void wxConfigSourcesDialog::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
+{
+   m_sources->AppendRows(1);
+}
+
+void wxConfigSourcesDialog::OnButtonDelete(wxCommandEvent& WXUNUSED(event))
+{
+   m_sources->DeleteRows(m_sources->GetCursorRow());
+}
+
 // ----------------------------------------------------------------------------
 // our public interface



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to