Commit f85eda3b authored by daniel_e's avatar daniel_e
Browse files

Remove config option "menutool_mode" because it's crack now that we have

* src/configdata.{cc,h}: Remove config option "menutool_mode" because it's
crack now that we have undo et al.  Add config options "textview_font",
"match_color" and "current_match_color".

* src/filebuffer.{cc,h} (pango_context_changed): Assign default font to the
error_message tag.
([gs]et_match_color): New accessors to tag colors.
([gs]et_current_color): ditto.

* src/mainwindow.{cc,h} ([gs]et_menutool_mode): Get rid of these.
(on_filetree_switch_buffer): No longer modify the TextView font globally
since we set the tag now.
(on_preferences): Handle the added config settings.
(load_configuration): ditto
(save_configuration): ditto.

* src/prefdialog.{cc,h} (FontSelectionButton): New utility widget.
(ColorSelectionButton): Another new utility widget.
(PrefDialog): Revamp the preferences dialog.  That is, add GUI for the new
config settings and remove the old one.  Also replace the radio buttons for
selecting the toolbar style with an option menu.
parent feb80eb1
2002-12-25 Daniel Elstner <daniel.elstner@gmx.net>
* src/configdata.{cc,h}: Remove config option "menutool_mode"
because it's crack now that we have undo et al. Add config options
"textview_font", "match_color" and "current_match_color".
* src/filebuffer.{cc,h} (pango_context_changed): Assign default
font to the error_message tag.
([gs]et_match_color): New accessors to tag colors.
([gs]et_current_color): ditto.
* src/mainwindow.{cc,h} ([gs]et_menutool_mode): Get rid of these.
(on_filetree_switch_buffer): No longer modify the TextView font
globally since we set the tag now.
(on_preferences): Handle the added config settings.
(load_configuration): ditto
(save_configuration): ditto.
* src/prefdialog.{cc,h} (FontSelectionButton): New utility widget.
(ColorSelectionButton): Another new utility widget.
(PrefDialog): Revamp the preferences dialog. That is, add GUI for
the new config settings and remove the old one. Also replace the
radio buttons for selecting the toolbar style with an option menu.
2002-12-25 Daniel Elstner <daniel.elstner@gmx.net>
* src/stringutils.{cc,h} (contains_null): Remove.
......
......@@ -65,6 +65,23 @@ public:
#endif /* HAVE_UMASK */
void print_warning(const char* text)
{
g_warning("%s", text);
}
void print_warning(const char* text, const Glib::ustring& what)
{
g_warning(text, what.c_str());
}
void print_invalid_value_warning(const Glib::ustring& value, const Glib::ustring& key)
{
g_warning("Error in configuration file: invalid value `%s' for key `%s'",
value.c_str(), key.c_str());
}
struct NickValuePair
{
const char* nick;
......@@ -82,8 +99,7 @@ int enum_from_string(const Glib::ustring& value, const Glib::ustring& key,
return p->value;
}
g_warning("Error in configuration file: invalid value `%s' for key `%s'",
value.c_str(), key.c_str());
print_invalid_value_warning(value, key);
return p->value; // return some fallback value
}
......@@ -99,14 +115,12 @@ Glib::ustring enum_to_string(int value, const NickValuePair* value_map)
g_return_val_if_reached("");
}
const NickValuePair menutool_mode_values[] =
void color_from_string(Gdk::Color& color, const Glib::ustring& value, const Glib::ustring& key)
{
{ "menu_and_tool", Regexxer::MODE_MENU_AND_TOOL },
{ "menu_only", Regexxer::MODE_MENU_ONLY },
{ "tool_only", Regexxer::MODE_TOOL_ONLY },
{ 0, Regexxer::MODE_MENU_AND_TOOL }
};
if(!color.parse(value))
print_invalid_value_warning(value, key);
}
const NickValuePair toolbar_style_values[] =
{
......@@ -118,16 +132,6 @@ const NickValuePair toolbar_style_values[] =
};
void print_warning(const char* text)
{
g_warning("%s", text);
}
void print_warning(const char* text, const Glib::ustring& what)
{
g_warning(text, what.c_str());
}
Glib::RefPtr<Glib::IOChannel> open_config_file(const std::string& mode)
{
const std::string filename = Glib::build_filename(Glib::get_home_dir(), ".regexxer");
......@@ -208,7 +212,9 @@ namespace Regexxer
ConfigData::ConfigData()
:
menutool_mode (MODE_MENU_AND_TOOL),
textview_font ("Monospace"),
match_color ("orange"),
current_color ("yellow"),
toolbar_style (Gtk::TOOLBAR_BOTH_HORIZ),
fallback_encoding ("ISO-8859-15")
{}
......@@ -227,13 +233,22 @@ void ConfigData::load()
while(read_config_entry(channel, key, value))
{
if(key.raw() == "menutool_mode")
menutool_mode = MenuToolMode(enum_from_string(value, key, menutool_mode_values));
if(key.raw() == "textview_font")
textview_font = value;
else if(key.raw() == "match_color")
color_from_string(match_color, value, key);
else if(key.raw() == "current_match_color")
color_from_string(current_color, value, key);
else if(key.raw() == "toolbar_style")
toolbar_style = Gtk::ToolbarStyle(enum_from_string(value, key, toolbar_style_values));
else if(key.raw() == "fallback_encoding")
set_fallback_encoding_from_string(value);
else
else if(key.raw() != "menutool_mode") // ignore key: menutool_mode is no longer supported
print_warning("Error in configuration file: unknown key `%s'", key);
}
}
......@@ -257,9 +272,11 @@ void ConfigData::save()
#endif
const Glib::RefPtr<Glib::IOChannel> channel = open_config_file("w");
channel->write("# regexxer configuration file\n");
channel->write("# " PACKAGE_STRING " configuration file\n");
write_config_entry(channel, "menutool_mode", enum_to_string(menutool_mode, menutool_mode_values));
write_config_entry(channel, "textview_font", textview_font);
write_config_entry(channel, "match_color", Util::color_to_string(match_color));
write_config_entry(channel, "current_match_color", Util::color_to_string(current_color));
write_config_entry(channel, "toolbar_style", enum_to_string(toolbar_style, toolbar_style_values));
write_config_entry(channel, "fallback_encoding", get_string_from_fallback_encoding());
......@@ -286,7 +303,7 @@ void ConfigData::set_fallback_encoding_from_string(const Glib::ustring& value)
}
else
{
print_warning("Error in configuration file: invalid value `%s' for key `fallback_encoding'", value);
print_invalid_value_warning(value, "fallback_encoding");
}
}
......
......@@ -21,24 +21,19 @@
#ifndef REGEXXER_CONFIGDATA_H_INCLUDED
#define REGEXXER_CONFIGDATA_H_INCLUDED
#include <gdkmm/color.h>
#include <glibmm/ustring.h>
#include <gtkmm/toolbar.h>
#include <string>
namespace Regexxer
{
enum MenuToolMode
{
MODE_MENU_AND_TOOL,
MODE_MENU_ONLY,
MODE_TOOL_ONLY
};
struct ConfigData
{
MenuToolMode menutool_mode;
Glib::ustring textview_font;
Gdk::Color match_color;
Gdk::Color current_color;
Gtk::ToolbarStyle toolbar_style;
std::string fallback_encoding;
......
......@@ -195,12 +195,14 @@ FileBuffer::create_with_error_message(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf,
// static
void FileBuffer::pango_context_changed(const Glib::RefPtr<Pango::Context>& context)
{
const Pango::FontDescription font_description (context->get_font_description());
// This magic code calculates the height to rise the error message title,
// so that it's displayed approximately in line with the error icon. By
// default the text would appear at the bottom, and since the icon is
// about 48 pixels tall this looks incredibly ugly.
int font_size = context->get_font_description().get_size();
int font_size = font_description.get_size();
if(font_size <= 0) // urgh, fall back to some reasonable value
font_size = 10 * Pango::SCALE;
......@@ -215,7 +217,32 @@ void FileBuffer::pango_context_changed(const Glib::RefPtr<Pango::Context>& conte
const Glib::RefPtr<RegexxerTags>& tagtable = RegexxerTags::instance();
tagtable->error_title->property_rise() = rise_height;
tagtable->error_message->property_font_desc() = font_description;
tagtable->error_title ->property_rise() = rise_height;
}
// static
void FileBuffer::set_match_color(const Gdk::Color& color)
{
RegexxerTags::instance()->match->property_background_gdk() = color;
}
// static
void FileBuffer::set_current_color(const Gdk::Color& color)
{
RegexxerTags::instance()->current->property_background_gdk() = color;
}
// static
Gdk::Color FileBuffer::get_match_color()
{
return RegexxerTags::instance()->match->property_background_gdk();
}
// static
Gdk::Color FileBuffer::get_current_color()
{
return RegexxerTags::instance()->current->property_background_gdk();
}
bool FileBuffer::is_freeable() const
......
......@@ -41,6 +41,11 @@ public:
static void pango_context_changed(const Glib::RefPtr<Pango::Context>& context);
static void set_match_color(const Gdk::Color& color);
static void set_current_color(const Gdk::Color& color);
static Gdk::Color get_match_color();
static Gdk::Color get_current_color();
virtual ~FileBuffer();
bool is_freeable() const;
......
......@@ -20,6 +20,7 @@
#include "mainwindow.h"
#include "aboutdialog.h"
#include "configdata.h"
#include "filetree.h"
#include "imagebutton.h"
#include "pcreshell.h"
......@@ -155,8 +156,7 @@ MainWindow::MainWindow()
busy_action_running_ (false),
busy_action_cancel_ (false),
busy_action_iteration_ (0),
undo_stack_ (new UndoStack()),
fileview_font_ ("mono")
undo_stack_ (new UndoStack())
{
using SigC::bind;
using SigC::slot;
......@@ -217,28 +217,6 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{}
void MainWindow::set_menutool_mode(MenuToolMode menutool_mode)
{
switch(menutool_mode)
{
case MODE_MENU_AND_TOOL: menubar_handle_->show(); toolbar_handle_->show(); break;
case MODE_MENU_ONLY: toolbar_handle_->hide(); menubar_handle_->show(); break;
case MODE_TOOL_ONLY: menubar_handle_->hide(); toolbar_handle_->show(); break;
}
}
MenuToolMode MainWindow::get_menutool_mode() const
{
const bool menubar_shown = menubar_handle_->is_visible();
const bool toolbar_shown = toolbar_handle_->is_visible();
if(menubar_shown && toolbar_shown) return MODE_MENU_AND_TOOL;
else if(menubar_shown) return MODE_MENU_ONLY;
else if(toolbar_shown) return MODE_TOOL_ONLY;
g_return_val_if_reached(MODE_MENU_AND_TOOL);
}
/**** Regexxer::MainWindow -- protected ************************************/
void MainWindow::on_hide()
......@@ -443,7 +421,6 @@ Gtk::Widget* MainWindow::create_right_pane()
entry_preview_->set_has_frame(false);
entry_preview_->set_editable(false);
entry_preview_->unset_flags(CAN_FOCUS);
entry_preview_->modify_font(fileview_font_);
#if REGEXXER_HAVE_GTKMM_22
entry_preview_->get_accessible()->set_name("Preview");
......@@ -457,7 +434,7 @@ Gtk::Widget* MainWindow::create_right_pane()
tooltips_.set_tip(*button_multiple_, "Find all possible matches in a line");
tooltips_.set_tip(*button_caseless_, "Do case insensitive matching");
tooltips_.set_tip(*button_find_matches, "Find all matches of the regular expression");
tooltips_.set_tip(*entry_preview_, "Preview of the substitution in the current line");
tooltips_.set_tip(*entry_preview_, "Preview of the substitution");
return vbox.release();
}
......@@ -653,8 +630,6 @@ void MainWindow::on_filetree_switch_buffer(FileInfoPtr fileinfo, int file_index)
if(!fileinfo->load_failed)
{
textview_->modify_font(fileview_font_);
buffer_connections_.push_back(buffer->signal_match_count_changed.
connect(SigC::slot(*this, &MainWindow::on_buffer_match_count_changed)));
......@@ -667,10 +642,6 @@ void MainWindow::on_filetree_switch_buffer(FileInfoPtr fileinfo, int file_index)
buffer_connections_.push_back(buffer->signal_preview_line_changed.
connect(SigC::slot(*this, &MainWindow::update_preview)));
}
else
{
textview_->modify_font(get_pango_context()->get_font_description());
}
set_title_filename(Util::filename_to_utf8_fallback(fileinfo->fullname));
......@@ -687,7 +658,6 @@ void MainWindow::on_filetree_switch_buffer(FileInfoPtr fileinfo, int file_index)
textview_->set_buffer(FileBuffer::create());
textview_->set_editable(false);
textview_->set_cursor_visible(false);
textview_->modify_font(get_pango_context()->get_font_description());
set_title_filename();
......@@ -990,12 +960,20 @@ void MainWindow::on_preferences()
{
std::auto_ptr<PrefDialog> dialog (new PrefDialog(*this));
dialog->set_pref_menutool_mode(get_menutool_mode());
dialog->set_pref_toolbar_style(toolbar_->get_toolbar_style());
dialog->set_pref_textview_font (textview_->get_pango_context()->get_font_description());
dialog->set_pref_match_color (FileBuffer::get_match_color());
dialog->set_pref_current_color (FileBuffer::get_current_color());
dialog->set_pref_toolbar_style (toolbar_->get_toolbar_style());
dialog->set_pref_fallback_encoding(filetree_->get_fallback_encoding());
dialog->signal_pref_menutool_mode_changed.connect(
SigC::slot(*this, &MainWindow::set_menutool_mode));
dialog->signal_pref_textview_font_changed.connect(
SigC::slot(*textview_, &Gtk::Widget::modify_font));
dialog->signal_pref_textview_font_changed.connect(
SigC::slot(*entry_preview_, &Gtk::Widget::modify_font));
dialog->signal_pref_match_color_changed .connect(&FileBuffer::set_match_color);
dialog->signal_pref_current_color_changed.connect(&FileBuffer::set_current_color);
dialog->signal_pref_toolbar_style_changed.connect(
SigC::slot(*toolbar_, &Gtk::Toolbar::set_toolbar_style));
......@@ -1022,7 +1000,13 @@ void MainWindow::load_configuration()
config.load();
set_menutool_mode(config.menutool_mode);
const Pango::FontDescription font (config.textview_font);
textview_ ->modify_font(font);
entry_preview_->modify_font(font);
FileBuffer::set_match_color(config.match_color);
FileBuffer::set_current_color(config.current_color);
toolbar_->set_toolbar_style(config.toolbar_style);
filetree_->set_fallback_encoding(config.fallback_encoding);
}
......@@ -1031,8 +1015,10 @@ void MainWindow::save_configuration()
{
ConfigData config;
config.menutool_mode = get_menutool_mode();
config.toolbar_style = toolbar_->get_toolbar_style();
config.textview_font = textview_->get_pango_context()->get_font_description().to_string();
config.match_color = FileBuffer::get_match_color();
config.current_color = FileBuffer::get_current_color();
config.toolbar_style = toolbar_->get_toolbar_style();
config.fallback_encoding = filetree_->get_fallback_encoding();
config.save();
......
......@@ -21,12 +21,10 @@
#ifndef REGEXXER_MAINWINDOW_H_INCLUDED
#define REGEXXER_MAINWINDOW_H_INCLUDED
#include "configdata.h"
#include "controller.h"
#include "filebuffer.h"
#include "sharedptr.h"
#include <pangomm.h>
#include <gtkmm/tooltips.h>
#include <gtkmm/window.h>
......@@ -59,9 +57,6 @@ public:
MainWindow();
virtual ~MainWindow();
void set_menutool_mode(MenuToolMode menutool_mode);
MenuToolMode get_menutool_mode() const;
protected:
virtual void on_hide();
virtual void on_style_changed(const Glib::RefPtr<Gtk::Style>& previous_style);
......@@ -99,7 +94,6 @@ private:
UndoStackPtr undo_stack_;
Pango::FontDescription fileview_font_;
std::list<SigC::Connection> buffer_connections_;
std::auto_ptr<AboutDialog> about_dialog_;
......
......@@ -22,14 +22,26 @@
#include "stringutils.h"
#include <glib.h>
#include <gtk/gtkrc.h>
#include <gtk/gtkwidget.h>
#include <gtkmm.h>
#include <algorithm>
#include <memory>
#include <config.h>
namespace
{
const Gtk::ToolbarStyle toolbar_style_values[] =
{
Gtk::TOOLBAR_ICONS,
Gtk::TOOLBAR_TEXT,
Gtk::TOOLBAR_BOTH,
Gtk::TOOLBAR_BOTH_HORIZ
};
class ImageLabel : public Gtk::HBox
{
public:
......@@ -56,21 +68,244 @@ ImageLabel::~ImageLabel()
namespace Regexxer
{
/**** Regexxer::FontSelectionButton ****************************************/
class FontSelectionButton : public Gtk::Button
{
public:
FontSelectionButton();
virtual ~FontSelectionButton();
void set_selected_font(const Pango::FontDescription& font);
Pango::FontDescription get_selected_font() const;
SigC::Signal0<void> signal_font_selected;
protected:
virtual void on_clicked();
private:
Gtk::Label* label_font_;
Gtk::Label* label_size_;
};
FontSelectionButton::FontSelectionButton()
:
label_font_ (0),
label_size_ (0)
{
using namespace Gtk;
Box *const box = new HBox(false, 0);
add(*manage(box));
box->pack_start(*manage(label_font_ = new Label()), PACK_EXPAND_WIDGET, 5);
box->pack_start(*manage(new VSeparator()), PACK_SHRINK);
box->pack_start(*manage(label_size_ = new Label()), PACK_SHRINK, 5);
box->show_all();
}
FontSelectionButton::~FontSelectionButton()
{}
void FontSelectionButton::set_selected_font(const Pango::FontDescription& font)
{
label_font_->set_text(font.get_family());
label_size_->set_text(Util::int_to_string((font.get_size() + Pango::SCALE / 2) / Pango::SCALE));
label_font_->modify_font(font);
#if REGEXXER_HAVE_GTKMM_22
get_accessible()->set_name(font.to_string());
#endif
}
Pango::FontDescription FontSelectionButton::get_selected_font() const
{
return label_font_->get_pango_context()->get_font_description();
}
void FontSelectionButton::on_clicked()
{
Gtk::FontSelectionDialog dialog;
dialog.set_modal(true);
if(Gtk::Window *const toplevel = dynamic_cast<Gtk::Window*>(get_toplevel()))
dialog.set_transient_for(*toplevel);
dialog.set_font_name(get_selected_font().to_string());
if(dialog.run() == Gtk::RESPONSE_OK)
{
set_selected_font(Pango::FontDescription(dialog.get_font_name()));
signal_font_selected(); // emit
}
}
/**** Regexxer::ColorSelectionButton ***************************************/
class ColorSelectionButton : public Gtk::Button
{
public:
ColorSelectionButton();
virtual ~ColorSelectionButton();
void set_selected_color(const Gdk::Color& color);
Gdk::Color get_selected_color() const;
SigC::Signal0<void> signal_color_selected;
protected:
virtual void on_clicked();
private:
class ColorLabel : public Gtk::Label
{
public:
ColorLabel();
virtual ~ColorLabel();
void adapt_activity_colors();
protected:
virtual void on_realize();
virtual bool on_expose_event(GdkEventExpose* event);
};
ColorLabel* colorlabel_;
};
ColorSelectionButton::ColorSelectionButton()
{
add(*Gtk::manage(colorlabel_ = new ColorLabel()));
colorlabel_->show();
}
ColorSelectionButton::~ColorSelectionButton()
{}
void ColorSelectionButton::set_selected_color(const Gdk::Color& color)
{
colorlabel_->modify_bg(Gtk::STATE_NORMAL, color);
if(colorlabel_->is_realized())
colorlabel_->adapt_activity_colors();
colorlabel_->set_text(Util::color_to_string(color));
}
Gdk::Color ColorSelectionButton::get_selected_color() const
{
return colorlabel_->get_style()->get_bg(Gtk::STATE_NORMAL);
}
void ColorSelectionButton::on_clicked()
{
Gtk::ColorSelectionDialog dialog;
dialog.set_modal(true);
dialog.set_title("Color selection");
if(Gtk::Window *const toplevel = dynamic_cast<Gtk::Window*>(get_toplevel()))
dialog.set_transient_for(*toplevel);
Gtk::ColorSelection& colorsel = *dialog.get_colorsel();
colorsel.set_has_palette(true);
colorsel.set_current_color(get_selected_color());
if(dialog.run() == Gtk::RESPONSE_OK)
{
set_selected_color(colorsel.get_current_color());
signal_color_selected(); // emit
}
}
ColorSelectionButton::ColorLabel::ColorLabel()
{
#if REGEXXER_HAVE_GTKMM_22
const Glib::ustring none = "<none>";
modify_bg_pixmap(Gtk::STATE_NORMAL, none);
modify_bg_pixmap(Gtk::STATE_ACTIVE, none);
modify_bg_pixmap(Gtk::STATE_PRELIGHT, none);
#else
const Glib::RefPtr<Gtk::RcStyle> rcstyle = get_modifier_style();
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_NORMAL]);
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_ACTIVE]);
g_free(rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_PRELIGHT]);
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_NORMAL] = g_strdup("<none>");
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_ACTIVE] = g_strdup("<none>");
rcstyle->gobj()->bg_pixmap_name[Gtk::STATE_PRELIGHT] = g_strdup("<none>");
modify_style(rcstyle);
#endif
}