Commit 023f8d01 authored by Fabien Parent's avatar Fabien Parent
Browse files

Fix #3018653 - Remember the window position, size, and state.

parent 720ae89d
......@@ -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";
......
......@@ -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()
......
......@@ -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);
......
......@@ -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>
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