Changeset 0586368ef50fee5ed7de7b6e77e1118c58e6b267
- Timestamp:
- 01/06/07 23:53:30 (6 years ago)
- Author:
- Philipp Kern <phil@…>
- Parents:
- a78113f8b06bcdc8bc7c7355d36814b7cc1145c7
- Children:
- 51b236c1846da0708cf013194f4d2877e97b8308
- git-committer:
- Philipp Kern <phil@0x539.de> / 2007-01-06T22:53:30Z+0000
- Message:
-
[project @ Remember the window positions]
Original author: Philipp Kern <phil@…>
Date: 2005-11-13 17:10:11+00:00
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r096ff14
|
r0586368
|
|
| 26 | 26 | #include "toolwindow.hpp" |
| 27 | 27 | #include "header.hpp" |
| | 28 | #include "config.hpp" |
| 28 | 29 | |
| 29 | 30 | namespace Gobby |
| … |
… |
|
| 46 | 47 | }; |
| 47 | 48 | |
| 48 | | DocumentList(Gtk::Window& parent, |
| 49 | | Header& header); |
| | 49 | DocumentList(Gtk::Window& parent, Header& header, Config& config); |
| 50 | 50 | |
| 51 | 51 | // Calls from the window |
-
|
r086ff99
|
r0586368
|
|
| 72 | 72 | { |
| 73 | 73 | Gtk::ToolbarStyle toolbar_show; |
| | 74 | bool remember; |
| 74 | 75 | } appearance; |
| 75 | 76 | }; |
-
|
r086ff99
|
r0586368
|
|
| 133 | 133 | |
| 134 | 134 | Gtk::ToolbarStyle get_toolbar_style() const; |
| | 135 | |
| | 136 | bool get_remember() const; |
| 135 | 137 | protected: |
| 136 | 138 | Gtk::VBox m_box; |
| 137 | 139 | Gtk::Frame m_frame_toolbar; |
| | 140 | Gtk::Frame m_frame_windows; |
| 138 | 141 | |
| 139 | 142 | Gtk::VBox m_box_toolbar; |
| 140 | 143 | Gtk::ComboBoxText m_cmb_toolbar_style; |
| | 144 | |
| | 145 | Gtk::VBox m_box_windows; |
| | 146 | Gtk::CheckButton m_btn_remember; |
| 141 | 147 | }; |
| 142 | 148 | |
-
|
r02f4d24
|
r0586368
|
|
| 22 | 22 | #include <gtkmm/window.h> |
| 23 | 23 | #include <gtkmm/toggleaction.h> |
| | 24 | #include "config.hpp" |
| 24 | 25 | |
| 25 | 26 | namespace Gobby |
| … |
… |
|
| 34 | 35 | ToolWindow(Gtk::Window& parent, |
| 35 | 36 | const Glib::ustring& title, |
| 36 | | const Glib::RefPtr<Gtk::ToggleAction>& action); |
| | 37 | const Glib::RefPtr<Gtk::ToggleAction>& action, |
| | 38 | Config& config, |
| | 39 | const Glib::ustring& config_key); |
| | 40 | ~ToolWindow(); |
| 37 | 41 | |
| 38 | 42 | protected: |
| … |
… |
|
| 43 | 47 | |
| 44 | 48 | Glib::RefPtr<Gtk::ToggleAction> m_action; |
| | 49 | |
| | 50 | Config& m_config; |
| | 51 | Glib::ustring m_config_key; |
| 45 | 52 | }; |
| 46 | 53 | |
-
|
r02f4d24
|
r0586368
|
|
| 27 | 27 | #include "toolwindow.hpp" |
| 28 | 28 | #include "header.hpp" |
| | 29 | #include "config.hpp" |
| 29 | 30 | |
| 30 | 31 | namespace Gobby |
| … |
… |
|
| 46 | 47 | }; |
| 47 | 48 | |
| 48 | | UserList(Gtk::Window& parent, |
| 49 | | Header& header); |
| | 49 | UserList(Gtk::Window& parent, Header& header, Config& config); |
| 50 | 50 | ~UserList(); |
| 51 | 51 | |
| … |
… |
|
| 69 | 69 | const obby::local_document_info& info); |
| 70 | 70 | |
| 71 | | /** Reference to header. |
| 72 | | */ |
| 73 | 71 | Header& m_header; |
| 74 | 72 | |
-
|
ra78113f
|
r0586368
|
|
| 51 | 51 | protected: |
| 52 | 52 | // Gtk::Window overrides |
| | 53 | virtual void on_show(); |
| 53 | 54 | virtual void on_realize(); |
| 54 | 55 | |
| … |
… |
|
| 115 | 116 | |
| 116 | 117 | // Config |
| 117 | | Config m_config; |
| | 118 | Config& m_config; |
| 118 | 119 | Preferences m_preferences; |
| 119 | 120 | const IconManager& m_icon_mgr; |
-
|
r096ff14
|
r0586368
|
|
| 39 | 39 | |
| 40 | 40 | Gobby::DocumentList::DocumentList(Gtk::Window& parent, |
| 41 | | Header& header): |
| | 41 | Header& header, |
| | 42 | Config& config): |
| 42 | 43 | ToolWindow( |
| 43 | 44 | parent, |
| 44 | 45 | _("Document list"), |
| 45 | | header.action_window_documentlist |
| | 46 | header.action_window_documentlist, |
| | 47 | config, |
| | 48 | "documentlist" |
| 46 | 49 | ), |
| 47 | 50 | m_btn_subscribe(_("Subscribe") ), |
-
|
r086ff99
|
r0586368
|
|
| 53 | 53 | ) |
| 54 | 54 | ); |
| | 55 | appearance.remember = |
| | 56 | config["appearance"]["windows"]["remember"].get<bool>(true); |
| 55 | 57 | } |
| 56 | 58 | |
| … |
… |
|
| 82 | 84 | config["appearance"]["toolbar"]["show"].set( |
| 83 | 85 | static_cast<int>(appearance.toolbar_show) ); |
| | 86 | config["appearance"]["windows"]["remember"].set(appearance.remember); |
| 84 | 87 | } |
| 85 | 88 | |
-
|
r086ff99
|
r0586368
|
|
| 235 | 235 | const Gobby::Preferences& preferences) |
| 236 | 236 | : Page(preferences), |
| 237 | | m_frame_toolbar(_("Toolbar") ) |
| | 237 | m_frame_toolbar(_("Toolbar") ), |
| | 238 | m_frame_windows(_("Windows") ), |
| | 239 | m_btn_remember(_("Remember the positions and states") ) |
| 238 | 240 | { |
| 239 | 241 | Gtk::ToolbarStyle style = preferences.appearance.toolbar_show; |
| | 242 | bool remember = preferences.appearance.remember; |
| 240 | 243 | |
| 241 | 244 | m_cmb_toolbar_style.append_text(_("Show text only") ); |
| … |
… |
|
| 256 | 259 | m_frame_toolbar.add(m_box_toolbar); |
| 257 | 260 | |
| | 261 | m_box_windows.set_spacing(5); |
| | 262 | m_box_windows.set_border_width(5); |
| | 263 | m_btn_remember.set_active(remember); |
| | 264 | m_box_windows.pack_start(m_btn_remember, Gtk::PACK_SHRINK); |
| | 265 | |
| | 266 | m_frame_windows.add(m_box_windows); |
| | 267 | |
| 258 | 268 | m_box.set_spacing(5); |
| 259 | 269 | m_box.pack_start(m_frame_toolbar, Gtk::PACK_SHRINK); |
| | 270 | m_box.pack_start(m_frame_windows, Gtk::PACK_SHRINK); |
| 260 | 271 | |
| 261 | 272 | set_border_width(10); |
| … |
… |
|
| 276 | 287 | case 2: default: return Gtk::TOOLBAR_BOTH; |
| 277 | 288 | } |
| | 289 | } |
| | 290 | |
| | 291 | bool Gobby::PreferencesDialog::Appearance::get_remember() const |
| | 292 | { |
| | 293 | return m_btn_remember.get_active(); |
| 278 | 294 | } |
| 279 | 295 | |
-
|
r02f4d24
|
r0586368
|
|
| 21 | 21 | Gobby::ToolWindow::ToolWindow(Gtk::Window& parent, |
| 22 | 22 | const Glib::ustring& title, |
| 23 | | const Glib::RefPtr<Gtk::ToggleAction>& action): |
| 24 | | Gtk::Window(Gtk::WINDOW_TOPLEVEL), m_action(action) |
| | 23 | const Glib::RefPtr<Gtk::ToggleAction>& action, |
| | 24 | Config& config, |
| | 25 | const Glib::ustring& config_key): |
| | 26 | Gtk::Window(Gtk::WINDOW_TOPLEVEL), |
| | 27 | m_action(action), |
| | 28 | m_config(config), |
| | 29 | m_config_key(config_key) |
| 25 | 30 | { |
| 26 | 31 | set_transient_for(parent); |
| 27 | | set_position(Gtk::WIN_POS_CENTER_ON_PARENT); |
| 28 | 32 | set_title(title); |
| 29 | 33 | |
| … |
… |
|
| 35 | 39 | |
| 36 | 40 | set_border_width(0); |
| | 41 | |
| | 42 | if(config["appearance"]["windows"]["remember"].get<bool>(true) ) |
| | 43 | { |
| | 44 | // Read the ToolWindow's last position from the configuration, |
| | 45 | // relative to the parent window. |
| | 46 | const int x = config[config_key]["x"].get<int>(0); |
| | 47 | const int y = config[config_key]["y"].get<int>(0); |
| | 48 | const int w = config[config_key]["width"].get<int>(0); |
| | 49 | const int h = config[config_key]["height"].get<int>(0); |
| | 50 | const bool visible = config[config_key]["visible"].get<bool>(false); |
| | 51 | if((x != 0) || (y != 0)) |
| | 52 | { |
| | 53 | move(x, y); |
| | 54 | resize(w, h); |
| | 55 | } |
| | 56 | } |
| | 57 | } |
| | 58 | |
| | 59 | Gobby::ToolWindow::~ToolWindow() |
| | 60 | { |
| | 61 | if(m_config["appearance"]["windows"]["remember"].get<bool>(true) ) |
| | 62 | { |
| | 63 | int x, y, w, h; |
| | 64 | get_position(x, y); |
| | 65 | get_size(w, h); |
| | 66 | m_config[m_config_key]["x"].set(x); |
| | 67 | m_config[m_config_key]["y"].set(y); |
| | 68 | m_config[m_config_key]["width"].set(w); |
| | 69 | m_config[m_config_key]["height"].set(h); |
| | 70 | m_config[m_config_key]["visible"].set(is_visible() ); |
| | 71 | } |
| 37 | 72 | } |
| 38 | 73 | |
| … |
… |
|
| 56 | 91 | Gtk::Window::on_hide(); |
| 57 | 92 | } |
| | 93 | |
-
|
rd548326
|
r0586368
|
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | | Gobby::UserList::UserList(Gtk::Window& parent, |
| 68 | | Header& header): |
| 69 | | ToolWindow(parent, _("User list"), header.action_window_userlist), |
| | 67 | Gobby::UserList::UserList(Gtk::Window& parent, Header& header, Config& config): |
| | 68 | ToolWindow(parent, _("User list"), header.action_window_userlist, |
| | 69 | config, "userlist"), |
| 70 | 70 | m_header(header) |
| 71 | 71 | { |
-
|
ra78113f
|
r0586368
|
|
| 58 | 58 | m_header(), |
| 59 | 59 | m_finddialog(*this), |
| 60 | | m_userlist(*this, m_header), |
| 61 | | m_documentlist(*this, m_header), |
| | 60 | m_userlist(*this, m_header, config), |
| | 61 | m_documentlist(*this, m_header, config), |
| 62 | 62 | m_folder(m_header, m_preferences), |
| 63 | 63 | m_statusbar(m_header, m_folder) |
| … |
… |
|
| 161 | 161 | } |
| 162 | 162 | #endif |
| | 163 | |
| | 164 | if(m_preferences.appearance.remember) |
| | 165 | { |
| | 166 | // Restore the window's position from the configuration |
| | 167 | const int x = config["window"]["x"].get<int>(0); |
| | 168 | const int y = config["window"]["y"].get<int>(0); |
| | 169 | const int w = config["window"]["width"].get<int>(0); |
| | 170 | const int h = config["window"]["height"].get<int>(0); |
| | 171 | const int s_w = config["screen"]["width"].get<int>(0); |
| | 172 | const int s_h = config["screen"]["height"].get<int>(0); |
| | 173 | const bool first_run = (x == 0) && (y == 0) |
| | 174 | && (w == 0) && (h == 0); |
| | 175 | Glib::RefPtr<Gdk::Screen> screen(get_screen() ); |
| | 176 | if((screen->get_width() >= s_w && screen->get_height() >= s_h) |
| | 177 | && !first_run) |
| | 178 | { |
| | 179 | move(x, y); |
| | 180 | resize(w, h); |
| | 181 | } |
| | 182 | else |
| | 183 | set_position(Gtk::WIN_POS_CENTER); |
| | 184 | } |
| 163 | 185 | } |
| 164 | 186 | |
| … |
… |
|
| 169 | 191 | // Serialise preferences into config |
| 170 | 192 | m_preferences.serialise(m_config); |
| | 193 | |
| | 194 | // Save the window's current position |
| | 195 | if(m_preferences.appearance.remember) |
| | 196 | { |
| | 197 | int x, y, w, h; |
| | 198 | get_position(x, y); get_size(w, h); |
| | 199 | Glib::RefPtr<Gdk::Screen> screen(get_screen() ); |
| | 200 | m_config["window"]["x"].set(x); |
| | 201 | m_config["window"]["y"].set(y); |
| | 202 | m_config["window"]["width"].set(w); |
| | 203 | m_config["window"]["height"].set(h); |
| | 204 | m_config["screen"]["width"].set(screen->get_width() ); |
| | 205 | m_config["screen"]["height"].set(screen->get_height() ); |
| | 206 | } |
| | 207 | } |
| | 208 | |
| | 209 | void Gobby::Window::on_show() |
| | 210 | { |
| | 211 | Gtk::Window::on_show(); |
| | 212 | |
| | 213 | if(m_preferences.appearance.remember) |
| | 214 | { |
| | 215 | if(m_config["userlist"]["visible"].get<bool>(false) ) |
| | 216 | m_userlist.show(); |
| | 217 | if(m_config["documentlist"]["visible"].get<bool>(false) ) |
| | 218 | m_documentlist.show(); |
| | 219 | } |
| 171 | 220 | } |
| 172 | 221 | |