Commit 81753d24 authored by Daniel Elstner's avatar Daniel Elstner
Browse files

Make init_state_ a value member of the class instead creating it

* src/main.cc (RegexxerOptions): Make init_state_ a value member
of the class instead creating it dynamically.  This simplification
is now possible since the RegexxerOptions object will be allocated
dynamically anyway.
(RegexxerOptions::init_state): Rename from take_init_state(), and
make it return a const reference.
(main): Use new init_state() method when initializing the window.

* src/mainwindow.{cc,h} (MainWindow::initialize): Change init
parameter type to a const reference.

svn path=/trunk/; revision=627
parent dddf937a
2007-01-11 Daniel Elstner <daniel.kitta@gmail.com>
* src/main.cc (RegexxerOptions): Make init_state_ a value member
of the class instead creating it dynamically. This simplification
is now possible since the RegexxerOptions object will be allocated
dynamically anyway.
(RegexxerOptions::init_state): Rename from take_init_state(), and
make it return a const reference.
(main): Use new init_state() method when initializing the window.
* src/mainwindow.{cc,h} (MainWindow::initialize): Change init
parameter type to a const reference.
2007-01-11 Daniel Elstner <daniel.kitta@gmail.com>
* Makefile.am (global_defs): Define REGEXXER_LOCALEDIR to the
......
......@@ -64,12 +64,23 @@ struct StockItemData
const char* label;
};
const StockIconData stock_icon_save_all[] =
{
{ stock_save_all_16, sizeof(stock_save_all_16), Gtk::ICON_SIZE_MENU },
{ stock_save_all_24, sizeof(stock_save_all_24), Gtk::ICON_SIZE_SMALL_TOOLBAR }
};
const StockItemData regexxer_stock_items[] =
{
{ "regexxer-save-all", stock_icon_save_all, G_N_ELEMENTS(stock_icon_save_all), N_("Save _all") }
};
class RegexxerOptions
{
private:
std::auto_ptr<Regexxer::InitState> init_state_;
Glib::OptionGroup group_;
Glib::OptionContext context_;
Regexxer::InitState init_state_;
Glib::OptionGroup group_;
Glib::OptionContext context_;
static Glib::OptionEntry entry(const char* long_name, char short_name,
const char* description, const char* arg_description = 0);
......@@ -79,19 +90,8 @@ public:
static std::auto_ptr<RegexxerOptions> create();
~RegexxerOptions();
Glib::OptionContext& context() { return context_; }
std::auto_ptr<Regexxer::InitState> take_init_state() { return init_state_; }
};
const StockIconData stock_icon_save_all[] =
{
{ stock_save_all_16, sizeof(stock_save_all_16), Gtk::ICON_SIZE_MENU },
{ stock_save_all_24, sizeof(stock_save_all_24), Gtk::ICON_SIZE_SMALL_TOOLBAR }
};
const StockItemData regexxer_stock_items[] =
{
{ "regexxer-save-all", stock_icon_save_all, G_N_ELEMENTS(stock_icon_save_all), N_("Save _all") }
Glib::OptionContext& context() { return context_; }
Regexxer::InitState& init_state() { return init_state_; }
};
// static
......@@ -113,7 +113,7 @@ Glib::OptionEntry RegexxerOptions::entry(const char* long_name, char short_name,
RegexxerOptions::RegexxerOptions()
:
init_state_ (new Regexxer::InitState()),
init_state_ (),
group_ (PACKAGE_TARNAME, Glib::ustring()),
context_ ()
{}
......@@ -126,8 +126,8 @@ std::auto_ptr<RegexxerOptions> RegexxerOptions::create()
{
std::auto_ptr<RegexxerOptions> options (new RegexxerOptions());
Glib::OptionGroup& group = options->group_;
Regexxer::InitState& init = *options->init_state_;
Glib::OptionGroup& group = options->group_;
Regexxer::InitState& init = options->init_state_;
group.add_entry(entry("pattern", 'p', N_("Find files matching PATTERN"), N_("PATTERN")),
init.pattern);
......@@ -214,7 +214,7 @@ void initialize_configuration()
client->set_error_handling(CLIENT_HANDLE_ALL);
client->add_dir(REGEXXER_GCONF_DIRECTORY, CLIENT_PRELOAD_ONELEVEL);
const std::list<Entry> entries (client->all_entries(REGEXXER_GCONF_DIRECTORY));
const std::list<Entry> entries = client->all_entries(REGEXXER_GCONF_DIRECTORY);
// Issue an artificial value_changed() signal for each entry in /apps/regexxer.
// Reusing the signal handlers this way neatly avoids the need for separate
......@@ -245,7 +245,7 @@ int main(int argc, char** argv)
Regexxer::MainWindow window;
initialize_configuration();
window.initialize(options->take_init_state());
window.initialize(options->init_state());
options.reset();
Gtk::Main::run(*window.get_window());
......
......@@ -207,36 +207,36 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{}
void MainWindow::initialize(std::auto_ptr<InitState> init)
void MainWindow::initialize(const InitState& init)
{
std::string folder;
if (!init->folder.empty())
folder = init->folder.front();
if (!init.folder.empty())
folder = init.folder.front();
if (!Glib::path_is_absolute(folder))
folder = Glib::build_filename(Glib::get_current_dir(), folder);
const bool folder_exists = button_folder_->set_current_folder(folder);
entry_pattern_ ->set_text((init->pattern.empty()) ? Glib::ustring("*") : init->pattern);
entry_regex_ ->set_text(init->regex);
entry_substitution_->set_text(init->substitution);
entry_pattern_->set_text((init.pattern.empty()) ? Glib::ustring("*") : init.pattern);
entry_regex_ ->set_text(init.regex);
entry_substitution_->set_text(init.substitution);
button_recursive_->set_active(!init->no_recursive);
button_hidden_ ->set_active(init->hidden);
button_multiple_ ->set_active(!init->no_global);
button_caseless_ ->set_active(init->ignorecase);
button_recursive_->set_active(!init.no_recursive);
button_hidden_ ->set_active(init.hidden);
button_multiple_ ->set_active(!init.no_global);
button_caseless_ ->set_active(init.ignorecase);
if (init->feedback)
if (init.feedback)
filetree_->signal_feedback.connect(&print_location);
// Strangely, folder_exists seems to be always true, probably because the
// file chooser works asynchronously but the GLib main loop isn't running
// yet. As a work-around, explicitely check whether the directory exists
// on the file system as well.
if (folder_exists && !init->no_autorun
&& !init->folder.empty() && !init->pattern.empty()
if (folder_exists && !init.no_autorun
&& !init.folder.empty() && !init.pattern.empty()
&& Glib::file_test(folder, Glib::FILE_TEST_IS_DIR))
{
Glib::signal_idle().connect(sigc::mem_fun(*this, &MainWindow::autorun_idle));
......
......@@ -78,7 +78,7 @@ public:
MainWindow();
virtual ~MainWindow();
void initialize(std::auto_ptr<InitState> init);
void initialize(const InitState& init);
Gtk::Window* get_window() { return window_.get(); }
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment