"Fossies" - the Fresh Open Source Software Archive

Member "regexxer-0.10/src/controller.cc" (6 Oct 2011, 6091 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "controller.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2002-2007  Daniel Elstner  <daniel.kitta@gmail.com>
    3  *
    4  * This file is part of regexxer.
    5  *
    6  * regexxer is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * regexxer is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with regexxer; if not, write to the Free Software Foundation,
   18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19  */
   20 
   21 #include "controller.h"
   22 
   23 #include <gtkmm/button.h>
   24 #include <gtkmm/menu.h>
   25 #include <gtkmm/toolbutton.h>
   26 #include <gtkmm/builder.h>
   27 
   28 #include <config.h>
   29 
   30 
   31 namespace Regexxer
   32 {
   33 
   34 /**** Regexxer::ControlItem ************************************************/
   35 
   36 ControlItem::ControlItem(bool enable)
   37 :
   38   enabled_       (enable),
   39   group_enabled_ (true)
   40 {}
   41 
   42 ControlItem::~ControlItem()
   43 {}
   44 
   45 void ControlItem::activate()
   46 {
   47   if (enabled_ && group_enabled_)
   48     signal_activate_(); // emit
   49 }
   50 
   51 sigc::slot<void> ControlItem::slot()
   52 {
   53   return sigc::mem_fun(*this, &ControlItem::activate);
   54 }
   55 
   56 void ControlItem::connect(const sigc::slot<void>& slot_activated)
   57 {
   58   signal_activate_.connect(slot_activated);
   59 }
   60 
   61 void ControlItem::add_widget(Gtk::Widget& widget)
   62 {
   63   signal_set_sensitive_.connect(sigc::mem_fun(widget, &Gtk::Widget::set_sensitive));
   64   widget.set_sensitive(enabled_ && group_enabled_);
   65 }
   66 
   67 void ControlItem::add_widgets(const Glib::RefPtr<Gtk::Builder>& xml,
   68                               const char* menuitem_name, const char* button_name)
   69 {
   70   const sigc::slot<void> slot_activate = slot();
   71 
   72   Gtk::MenuItem* menuitem = 0;
   73   Gtk::Widget*   widget   = 0;
   74 
   75   if (menuitem_name)
   76     xml->get_widget(menuitem_name, menuitem);
   77 
   78   if (button_name)
   79     xml->get_widget(button_name, widget);
   80   
   81   if (menuitem_name)
   82   {
   83     menuitem->signal_activate().connect(slot_activate);
   84     add_widget(*menuitem);
   85   }
   86 
   87   if (button_name)
   88   {
   89     if (Gtk::ToolButton *const button = dynamic_cast<Gtk::ToolButton*>(widget))
   90       button->signal_clicked().connect(slot_activate);
   91     else if (Gtk::Button *const button = dynamic_cast<Gtk::Button*>(widget))
   92       button->signal_clicked().connect(slot_activate);
   93     else
   94       g_return_if_reached();
   95 
   96     add_widget(*widget);
   97   }
   98 }
   99 
  100 void ControlItem::set_enabled(bool enable)
  101 {
  102   if (enable != enabled_)
  103   {
  104     enabled_ = enable;
  105 
  106     if (group_enabled_)
  107       signal_set_sensitive_(enabled_); // emit
  108   }
  109 }
  110 
  111 void ControlItem::set_group_enabled(bool enable)
  112 {
  113   if (enable != group_enabled_)
  114   {
  115     group_enabled_ = enable;
  116 
  117     if (enabled_)
  118       signal_set_sensitive_(group_enabled_); // emit
  119   }
  120 }
  121 
  122 bool ControlItem::is_enabled() const
  123 {
  124   return (enabled_ && group_enabled_);
  125 }
  126 
  127 
  128 /**** Regexxer::ControlGroup ***********************************************/
  129 
  130 ControlGroup::ControlGroup(bool enable)
  131 :
  132   enabled_ (enable)
  133 {}
  134 
  135 ControlGroup::~ControlGroup()
  136 {}
  137 
  138 void ControlGroup::add(ControlItem& control)
  139 {
  140   signal_set_enabled_.connect(sigc::mem_fun(control, &ControlItem::set_group_enabled));
  141   control.set_group_enabled(enabled_);
  142 }
  143 
  144 void ControlGroup::set_enabled(bool enable)
  145 {
  146   if (enable != enabled_)
  147   {
  148     enabled_ = enable;
  149     signal_set_enabled_(enabled_); // emit
  150   }
  151 }
  152 
  153 
  154 /**** Regexxer::Controller *************************************************/
  155 
  156 Controller::Controller()
  157 :
  158   match_actions (true),
  159   edit_actions  (false),
  160   save_file     (false),
  161   save_all      (false),
  162   undo          (false),
  163   preferences   (true),
  164   quit          (true),
  165   about         (true),
  166   find_files    (false),
  167   find_matches  (false),
  168   next_file     (false),
  169   prev_file     (false),
  170   next_match    (false),
  171   prev_match    (false),
  172   replace       (false),
  173   replace_file  (false),
  174   replace_all   (false),
  175   cut           (true),
  176   copy          (true),
  177   paste         (true),
  178   erase         (true)
  179 {
  180   match_actions.add(undo);
  181   match_actions.add(find_files);
  182   match_actions.add(find_matches);
  183   match_actions.add(next_file);
  184   match_actions.add(prev_file);
  185   match_actions.add(next_match);
  186   match_actions.add(prev_match);
  187   match_actions.add(replace);
  188   match_actions.add(replace_file);
  189   match_actions.add(replace_all);
  190   edit_actions.add(cut);
  191   edit_actions.add(copy);
  192   edit_actions.add(paste);
  193   edit_actions.add(erase);
  194 }
  195 
  196 Controller::~Controller()
  197 {}
  198 
  199 void Controller::load_xml(const Glib::RefPtr<Gtk::Builder>& xml)
  200 {
  201   save_file   .add_widgets(xml, "menuitem_save",         "button_save");
  202   save_all    .add_widgets(xml, "menuitem_save_all",     "button_save_all");
  203   quit        .add_widgets(xml, "menuitem_quit",         "button_quit");
  204   undo        .add_widgets(xml, "menuitem_undo",         "button_undo");
  205   cut         .add_widgets(xml, "menuitem_cut",          0);
  206   copy        .add_widgets(xml, "menuitem_copy",         0);
  207   paste       .add_widgets(xml, "menuitem_paste",        0);
  208   erase       .add_widgets(xml, "menuitem_delete",       0);
  209   preferences .add_widgets(xml, "menuitem_preferences",  0);
  210   next_file   .add_widgets(xml, "menuitem_next_file",    "button_next_file");
  211   prev_file   .add_widgets(xml, "menuitem_prev_file",    "button_prev_file");
  212   next_match  .add_widgets(xml, "menuitem_next_match",   "button_next_match");
  213   prev_match  .add_widgets(xml, "menuitem_prev_match",   "button_prev_match");
  214   replace     .add_widgets(xml, "menuitem_replace",      "button_replace");
  215   replace_file.add_widgets(xml, "menuitem_replace_file", "button_replace_file");
  216   replace_all .add_widgets(xml, "menuitem_replace_all",  "button_replace_all");
  217   find_files  .add_widgets(xml, 0,                       "button_find_files");
  218   find_matches.add_widgets(xml, 0,                       "button_find_matches");
  219   about       .add_widgets(xml, "menuitem_about",        0);
  220 }
  221 
  222 } // namespace Regexxer