]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gnome/FormUrl.C
Remove unneeded files, we have switched to use the libglade and there is no
[lyx.git] / src / frontends / gnome / FormUrl.C
index afd39f614c49d0c949e5e658e76acb13b21a2813..f3b6f51b01a80fcd6017cb9a92d6ce44cd82d388 100644 (file)
 // -*- C++ -*-
 /* This file is part of
- * ====================================================== 
+ * =================================================
+ * 
+ *          LyX, The Document Processor
+ *          Copyright 1995-2000 The LyX Team.
  *
- *           LyX, The Document Processor
+ * ================================================= 
  *
- *           Copyright 2000 The LyX Team.
- *
- * ======================================================
+ * \author Baruch Even
  */
 
-#include <config.h>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
+#include <config.h>
 
-#include "gettext.h"
-#include "Dialogs.h"
+#include "gnomeBC.h"
 #include "FormUrl.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "lyxfunc.h"
 
-extern "C" {
-#include "diainserturl_interface.h"
-#include "support.h"
-}
+#include <gtk--/entry.h>
+#include <gtk--/checkbutton.h>
 
-#include <gtk--/base.h>
+FormUrl::FormUrl(ControlUrl & c)
+       : FormCB<ControlUrl>(c, "diainserturl.glade", "DiaInsertUrl")
+{}
 
-FormUrl::FormUrl(LyXView * lv, Dialogs * d)
-       : lv_(lv), d_(d), u_(0), h_(0), ih_(0), inset_(0), dialog_(NULL)
+
+FormUrl::~FormUrl()
 {
-  // let the dialog be shown
-  // These are permanent connections so we won't bother
-  // storing a copy because we won't be disconnecting.
-  d->showUrl.connect(slot(this, &FormUrl::showInset));
-  d->createUrl.connect(slot(this, &FormUrl::createInset));
+       // Note that there is no need to destroy the class itself, it seems
+       // like everything is managed inside it. Deleting the class itself will
+       // a crash at the end of the program.
+       //dialog_->destroy();
 }
 
 
-FormUrl::~FormUrl()
+void FormUrl::build()
 {
-  hide();
+       // Connect the buttons.
+       ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
+       cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
+       apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
+       restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
+
+       // Manage the buttons state
+       bc().setOK(ok_btn());
+       bc().setCancel(cancel_btn());
+       bc().setApply(apply_btn());
+       bc().setUndoAll(restore_btn());
+
+       // Make sure everything is in the correct state.
+       bc().refresh();
+       
+       // Manage the read-only aware widgets.
+       bc().addReadOnly(html());
+       bc().addReadOnly(name());
+       bc().addReadOnly(url());
 }
 
-void FormUrl::showInset( InsetCommand * const inset )
+
+void FormUrl::connect_signals()
 {
-  if( dialog_!=NULL || inset == 0 ) return;
-  
-  inset_ = inset;
-  ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
-  
-  params = inset->params();
-  show();
+       // Get notifications on input change
+       slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
+       slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
+       slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
 }
 
 
-void FormUrl::createInset( string const & arg )
+void FormUrl::disconnect_signals()
 {
-  if( dialog_!=NULL ) return;
-  
-  params.setFromString( arg );
-  show();
+       slot_url_.disconnect();
+       slot_name_.disconnect();
+       slot_html_.disconnect();
 }
 
-void FormUrl::show()
+
+void FormUrl::apply()
 {
-  if (!dialog_)
-    {
-      GtkWidget * pd = create_DiaInsertUrl();
-
-      dialog_ = Gtk::wrap(pd);
-      url_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "url") ) );
-      name_ = Gtk::wrap( GNOME_ENTRY( lookup_widget(pd, "name") ) );
-      html_type_ = Gtk::wrap( GTK_CHECK_BUTTON( lookup_widget(pd, "html_type") ) );
-      
-      b_ok = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_ok") ) );
-      b_cancel = Gtk::wrap( GTK_BUTTON( lookup_widget(pd, "button_cancel") ) );
-
-      b_ok->clicked.connect(slot(this, &FormUrl::apply));
-      b_ok->clicked.connect(dialog_->destroy.slot());
-      b_cancel->clicked.connect(dialog_->destroy.slot());
-      dialog_->destroy.connect(slot(this, &FormUrl::free));
-
-      u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
-      h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
-
-      if (!dialog_->is_visible()) dialog_->show_all();
-
-      update();  // make sure its up-to-date
-    }
-  else
-    {
-      Gdk_Window dialog_win(dialog_->get_window());
-      dialog_win.raise();
-    }
+       controller().params().setContents(url()->get_text());
+       controller().params().setOptions(name()->get_text());
+
+       string cmdname("url");
+       if (html()->get_active())
+               cmdname = "htmlurl";
+
+       controller().params().setCmdName(cmdname);
 }
 
+
 void FormUrl::update()
 {
-  if (dialog_ != NULL &&
-      lv_->view()->available())
-    {
-      url_->get_entry()->set_text(params.getContents().c_str());
-      name_->get_entry()->set_text(params.getOptions().c_str());
+       // Disconnect signals so we dont trigger the input changed state.
+       // This avoids the problem of having the buttons enabled when the dialog
+       // starts.
+       disconnect_signals();
+       
+       url()->set_text(controller().params().getContents());
+       name()->set_text(controller().params().getOptions());
+
+       html()->set_active("url" != controller().params().getCmdName());
+
+       // Reconnect the signals.
+       connect_signals();
+}
 
-      html_type_->set_active( (params.getCmdName() == "htmlurl") );
 
-      bool sens = (!(lv_->buffer()->isReadonly()));
+bool FormUrl::validate() const
+{
+       // Always valid! (not really so, needs fixing).
+       return true;
+}
 
-      html_type_->set_sensitive(sens);
-      url_->set_sensitive(sens);
-      name_->set_sensitive(sens);
-      b_ok->set_sensitive(sens);
-    }
+
+Gtk::Entry * FormUrl::url() const
+{
+       return getWidget<Gtk::Entry>("url");
 }
 
-void FormUrl::hide()
+Gtk::Entry * FormUrl::name() const
 {
-  if (dialog_!=NULL) dialog_->destroy();
+       return getWidget<Gtk::Entry>("name");
 }
 
-void FormUrl::free()
+Gtk::CheckButton * FormUrl::html() const
 {
-  if (dialog_!=NULL)
-    {
-      dialog_ = NULL;
-      u_.disconnect();
-      h_.disconnect();
-      inset_ = 0;
-      ih_.disconnect();
-    }
+       return getWidget<Gtk::CheckButton>("html_type");
 }
 
-void FormUrl::apply()
+
+Gtk::Button * FormUrl::ok_btn() const
+{
+       return getWidget<Gtk::Button>("button_ok");
+}
+
+
+Gtk::Button * FormUrl::cancel_btn() const
+{
+       return getWidget<Gtk::Button>("button_cancel");
+}
+
+
+Gtk::Button * FormUrl::apply_btn() const
+{
+       return getWidget<Gtk::Button>("button_apply");
+}
+
+
+Gtk::Button * FormUrl::restore_btn() const
 {
-  if( lv_->buffer()->isReadonly() ) return;
-
-  params.setContents( url_->get_entry()->get_text() );
-  params.setOptions( name_->get_entry()->get_text() );
-
-  if (html_type_->get_active())
-    params.setCmdName("htmlurl");
-  else
-    params.setCmdName("url");
-  
-  if( inset_ != 0 )
-    {
-      // Only update if contents have changed
-      if( params != inset_->params() ) {
-       inset_->setParams( params );
-       lv_->view()->updateInset( inset_, true );
-      }
-    }
-  else
-    {
-      lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
-                                  params.getAsString().c_str() );
-    }
+       return getWidget<Gtk::Button>("button_restore");
 }