Changeset 0586368ef50fee5ed7de7b6e77e1118c58e6b267

Show
Ignore:
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:
12 modified

Legend:

Unmodified
Added
Removed
  • inc/documentlist.hpp

    r096ff14 r0586368  
    2626#include "toolwindow.hpp" 
    2727#include "header.hpp" 
     28#include "config.hpp" 
    2829 
    2930namespace Gobby 
     
    4647        }; 
    4748 
    48         DocumentList(Gtk::Window& parent, 
    49                      Header& header); 
     49        DocumentList(Gtk::Window& parent, Header& header, Config& config); 
    5050 
    5151        // Calls from the window 
  • inc/preferences.hpp

    r086ff99 r0586368  
    7272        { 
    7373                Gtk::ToolbarStyle toolbar_show; 
     74                bool remember; 
    7475        } appearance; 
    7576}; 
  • inc/preferencesdialog.hpp

    r086ff99 r0586368  
    133133 
    134134                Gtk::ToolbarStyle get_toolbar_style() const; 
     135 
     136                bool get_remember() const; 
    135137        protected: 
    136138                Gtk::VBox m_box; 
    137139                Gtk::Frame m_frame_toolbar; 
     140                Gtk::Frame m_frame_windows; 
    138141 
    139142                Gtk::VBox m_box_toolbar; 
    140143                Gtk::ComboBoxText m_cmb_toolbar_style; 
     144 
     145                Gtk::VBox m_box_windows; 
     146                Gtk::CheckButton m_btn_remember; 
    141147        }; 
    142148 
  • inc/toolwindow.hpp

    r02f4d24 r0586368  
    2222#include <gtkmm/window.h> 
    2323#include <gtkmm/toggleaction.h> 
     24#include "config.hpp" 
    2425 
    2526namespace Gobby 
     
    3435        ToolWindow(Gtk::Window& parent, 
    3536                   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(); 
    3741 
    3842protected: 
     
    4347 
    4448        Glib::RefPtr<Gtk::ToggleAction> m_action; 
     49 
     50        Config& m_config; 
     51        Glib::ustring m_config_key; 
    4552}; 
    4653 
  • inc/userlist.hpp

    r02f4d24 r0586368  
    2727#include "toolwindow.hpp" 
    2828#include "header.hpp" 
     29#include "config.hpp" 
    2930 
    3031namespace Gobby 
     
    4647        }; 
    4748 
    48         UserList(Gtk::Window& parent, 
    49                  Header& header); 
     49        UserList(Gtk::Window& parent, Header& header, Config& config); 
    5050        ~UserList(); 
    5151 
     
    6969                                 const obby::local_document_info& info); 
    7070 
    71         /** Reference to header. 
    72          */ 
    7371        Header& m_header; 
    7472 
  • inc/window.hpp

    ra78113f r0586368  
    5151protected: 
    5252        // Gtk::Window overrides 
     53        virtual void on_show(); 
    5354        virtual void on_realize(); 
    5455 
     
    115116 
    116117        // Config 
    117         Config m_config; 
     118        Config& m_config; 
    118119        Preferences m_preferences; 
    119120        const IconManager& m_icon_mgr; 
  • src/documentlist.cpp

    r096ff14 r0586368  
    3939 
    4040Gobby::DocumentList::DocumentList(Gtk::Window& parent, 
    41                                   Header& header): 
     41                                  Header& header, 
     42                                  Config& config): 
    4243        ToolWindow( 
    4344                parent, 
    4445                _("Document list"), 
    45                 header.action_window_documentlist 
     46                header.action_window_documentlist, 
     47                config, 
     48                "documentlist" 
    4649        ), 
    4750        m_btn_subscribe(_("Subscribe") ), 
  • src/preferences.cpp

    r086ff99 r0586368  
    5353                ) 
    5454        ); 
     55        appearance.remember = 
     56                config["appearance"]["windows"]["remember"].get<bool>(true); 
    5557} 
    5658 
     
    8284        config["appearance"]["toolbar"]["show"].set( 
    8385                static_cast<int>(appearance.toolbar_show) ); 
     86        config["appearance"]["windows"]["remember"].set(appearance.remember); 
    8487} 
    8588 
  • src/preferencesdialog.cpp

    r086ff99 r0586368  
    235235        const Gobby::Preferences& preferences) 
    236236 : 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") ) 
    238240{ 
    239241        Gtk::ToolbarStyle style = preferences.appearance.toolbar_show; 
     242        bool remember = preferences.appearance.remember; 
    240243 
    241244        m_cmb_toolbar_style.append_text(_("Show text only") ); 
     
    256259        m_frame_toolbar.add(m_box_toolbar); 
    257260 
     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 
    258268        m_box.set_spacing(5); 
    259269        m_box.pack_start(m_frame_toolbar, Gtk::PACK_SHRINK); 
     270        m_box.pack_start(m_frame_windows, Gtk::PACK_SHRINK); 
    260271 
    261272        set_border_width(10); 
     
    276287        case 2: default: return Gtk::TOOLBAR_BOTH; 
    277288        } 
     289} 
     290 
     291bool Gobby::PreferencesDialog::Appearance::get_remember() const 
     292{ 
     293        return m_btn_remember.get_active(); 
    278294} 
    279295 
  • src/toolwindow.cpp

    r02f4d24 r0586368  
    2121Gobby::ToolWindow::ToolWindow(Gtk::Window& parent, 
    2222                              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) 
    2530{ 
    2631        set_transient_for(parent); 
    27         set_position(Gtk::WIN_POS_CENTER_ON_PARENT); 
    2832        set_title(title); 
    2933 
     
    3539 
    3640        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 
     59Gobby::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        } 
    3772} 
    3873 
     
    5691        Gtk::Window::on_hide(); 
    5792} 
     93 
  • src/userlist.cpp

    rd548326 r0586368  
    6565} 
    6666 
    67 Gobby::UserList::UserList(Gtk::Window& parent, 
    68                           Header& header): 
    69         ToolWindow(parent, _("User list"), header.action_window_userlist), 
     67Gobby::UserList::UserList(Gtk::Window& parent, Header& header, Config& config): 
     68        ToolWindow(parent, _("User list"), header.action_window_userlist, 
     69                config, "userlist"), 
    7070        m_header(header) 
    7171{ 
  • src/window.cpp

    ra78113f r0586368  
    5858   m_header(), 
    5959   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), 
    6262   m_folder(m_header, m_preferences), 
    6363   m_statusbar(m_header, m_folder) 
     
    161161        } 
    162162#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        } 
    163185} 
    164186 
     
    169191        // Serialise preferences into config 
    170192        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 
     209void 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        } 
    171220} 
    172221