[regexxer] Fix #3018653 - Remember the window position, size, and state.
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [regexxer] Fix #3018653 - Remember the window position, size, and state.
- Date: Sun, 20 Feb 2011 13:25:26 +0000 (UTC)
commit 023f8d01d6f177f3128f23ade5f35b08ba457c08
Author: Fabien Parent <parent f gmail com>
Date: Sun Feb 20 14:25:13 2011 +0100
Fix #3018653 - Remember the window position, size, and state.
src/globalstrings.h | 5 +++
src/mainwindow.cc | 58 +++++++++++++++++++++++++++++++++++++-----
src/mainwindow.h | 11 ++++---
ui/org.regexxer.gschema.xml | 35 ++++++++++++++++++++++++++
4 files changed, 97 insertions(+), 12 deletions(-)
---
diff --git a/src/globalstrings.h b/src/globalstrings.h
index 3311b46..fc94b62 100644
--- a/src/globalstrings.h
+++ b/src/globalstrings.h
@@ -39,6 +39,11 @@ const char *const conf_key_current_match_color = "current-match-color";
const char *const conf_key_fallback_encoding = "fallback-encoding";
const char *const conf_key_substitution_patterns = "substitution-patterns";
const char *const conf_key_regex_patterns = "regex-patterns";
+const char *const conf_key_window_width = "window-width";
+const char *const conf_key_window_height = "window-height";
+const char *const conf_key_window_position_x = "window-position-x";
+const char *const conf_key_window_position_y = "window-position-y";
+const char *const conf_key_window_maximized = "window-maximized";
const char *const ui_mainwindow_filename = REGEXXER_PKGDATADIR G_DIR_SEPARATOR_S
"mainwindow.ui";
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index b77b2cc..be455a2 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -204,24 +204,24 @@ MainWindow::MainWindow()
undo_stack_ (new UndoStack())
{
load_xml();
-
+
entry_regex_ = comboboxentry_regex_->get_entry();
entry_substitution_ = comboboxentry_substitution_->get_entry();
-
+
textview_->set_buffer(FileBuffer::create());
window_->set_title(PACKAGE_NAME);
vbox_main_->pack_start(*statusline_, Gtk::PACK_SHRINK);
scrollwin_filetree_->add(*filetree_);
table_file_->attach(*combo_entry_pattern_, 1, 2, 1, 2);
-
+
scrollwin_textview_->add(*textview_);
-
+
statusline_->show_all();
filetree_->show_all();
combo_entry_pattern_->show_all();
scrollwin_textview_->show_all();
-
+
connect_signals();
}
@@ -230,6 +230,20 @@ MainWindow::~MainWindow()
void MainWindow::initialize(const InitState& init)
{
+ Glib::RefPtr<Gio::Settings> settings = Settings::instance();
+ int width = settings->get_int(conf_key_window_width);
+ int height = settings->get_int(conf_key_window_height);
+
+ int x = settings->get_int(conf_key_window_position_x);
+ int y = settings->get_int(conf_key_window_position_y);
+
+ bool maximized = settings->get_boolean(conf_key_window_maximized);
+
+ window_->resize(width, height);
+ window_->move(x, y);
+ if (maximized)
+ window_->maximize();
+
std::string folder;
if (!init.folder.empty())
@@ -251,7 +265,7 @@ void MainWindow::initialize(const InitState& init)
comboboxentry_regex_->set_text_column(entry_regex_completion_stack_.get_completion_column());
comboboxentry_substitution_->set_model(entry_substitution_completion_stack_.get_completion_model());
comboboxentry_substitution_->set_text_column(entry_substitution_completion_stack_.get_completion_column());
-
+
entry_regex_completion_->set_model(entry_regex_completion_stack_.get_completion_model());
entry_regex_completion_->set_text_column(entry_regex_completion_stack_.get_completion_column());
entry_regex_completion_->set_inline_completion(true);
@@ -417,7 +431,9 @@ void MainWindow::on_style_changed(const Glib::RefPtr<Gtk::Style>&)
bool MainWindow::on_delete_event(GdkEventAny*)
{
- return !confirm_quit_request();
+ bool quit = confirm_quit_request();
+ save_window_state();
+ return !quit;
}
void MainWindow::on_cut()
@@ -500,7 +516,35 @@ void MainWindow::on_erase()
void MainWindow::on_quit()
{
if (confirm_quit_request())
+ {
+ save_window_state();
window_->hide();
+ }
+}
+
+void MainWindow::save_window_state()
+{
+ int x = 0;
+ int y = 0;
+
+ int width = 0;
+ int height = 0;
+
+ window_->get_position(x, y);
+ window_->get_size(width, height);
+ bool maximized = (window_->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED);
+
+ Glib::RefPtr<Gio::Settings> settings = Settings::instance();
+
+ settings->set_int(conf_key_window_position_x, x);
+ settings->set_int(conf_key_window_position_y, y);
+ settings->set_boolean(conf_key_window_maximized, maximized);
+
+ if (!maximized)
+ {
+ settings->set_int(conf_key_window_width, width);
+ settings->set_int(conf_key_window_height, height);
+ }
}
bool MainWindow::confirm_quit_request()
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 2aef98a..2f0c4e1 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -94,16 +94,16 @@ private:
std::auto_ptr<Gtk::Window> window_;
Controller controller_;
-
+
Gtk::VBox* vbox_main_;
Gtk::Toolbar* toolbar_;
Gtk::Table* table_file_;
Gtk::FileChooser* button_folder_;
-
+
Gtk::ComboBoxEntryText* combo_entry_pattern_;
-
+
Gtk::CheckButton* button_recursive_;
Gtk::CheckButton* button_hidden_;
@@ -111,12 +111,12 @@ private:
Gtk::Entry* entry_regex_;
CompletionStack entry_regex_completion_stack_;
Glib::RefPtr<Gtk::EntryCompletion> entry_regex_completion_;
-
+
Gtk::ComboBoxEntry* comboboxentry_substitution_;
Gtk::Entry* entry_substitution_;
CompletionStack entry_substitution_completion_stack_;
Glib::RefPtr<Gtk::EntryCompletion> entry_substitution_completion_;
-
+
Gtk::CheckButton* button_multiple_;
Gtk::CheckButton* button_caseless_;
@@ -142,6 +142,7 @@ private:
void load_xml();
void connect_signals();
bool autorun_idle();
+ void save_window_state();
void on_hide();
void on_style_changed(const Glib::RefPtr<Gtk::Style>& previous_style);
diff --git a/ui/org.regexxer.gschema.xml b/ui/org.regexxer.gschema.xml
index 68dded3..b05b2f5 100644
--- a/ui/org.regexxer.gschema.xml
+++ b/ui/org.regexxer.gschema.xml
@@ -5,30 +5,65 @@
<summary>Regex Patterns</summary>
<description>List of last patterns used for the regex entry.</description>
</key>
+
<key name="substitution-patterns" type="as">
<default>[]</default>
<summary>Regex Patterns</summary>
<description>List of last patterns used for the substitution entry.</description>
</key>
+
<key name="textview-font" type="s">
<default>'Monospace 10'</default>
<summary>Text view font</summary>
<description>The font used in the file editor.</description>
</key>
+
<key name="match-color" type="s">
<default>'#9DB8D2'</default>
<summary>Match color</summary>
<description>The background color used to highlight matches of the search expression.</description>
</key>
+
<key name="current-match-color" type="s">
<default>'#EED680'</default>
<summary>Current-match color</summary>
<description>The background color used to highlight the currently selected match of the search expression.</description>
</key>
+
<key name="fallback-encoding" type="s">
<default>'ISO-8859-15'</default>
<summary>Fallback encoding</summary>
<description>Name of the character encoding to use if a file is not readable in either UTF-8 or the codeset specified by the current locale. Try "iconv --list" for a complete list of possible values.</description>
</key>
+
+ <key name="window-width" type="i">
+ <default>800</default>
+ <summary>window width</summary>
+ <description>The width of the window.</description>
+ </key>
+
+ <key name="window-height" type="i">
+ <default>600</default>
+ <summary>window height</summary>
+ <description>The height of the window.</description>
+ </key>
+
+ <key name="window-position-x" type="i">
+ <default>10</default>
+ <summary>window x position</summary>
+ <description>The X coordinate of the window.</description>
+ </key>
+
+ <key name="window-position-y" type="i">
+ <default>10</default>
+ <summary>window y position</summary>
+ <description>The Y coordinate of the window.</description>
+ </key>
+
+ <key name="window-maximized" type="b">
+ <default>false</default>
+ <summary>window maximization</summary>
+ <description>Whether the window is maximized.</description>
+ </key>
</schema>
</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]