diff options
author | fluxgen <fluxgen> | 2005-06-23 03:07:25 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2005-06-23 03:07:25 (GMT) |
commit | 5373f6d840abaa49685c15fee2f411e77472a7da (patch) | |
tree | 46da25845eac32769bad85c264e4edf335cc1783 /src/Remember.cc | |
parent | 18cf5862495aa6f37110c90286bb6c315a145526 (diff) | |
download | fluxbox_paul-5373f6d840abaa49685c15fee2f411e77472a7da.zip fluxbox_paul-5373f6d840abaa49685c15fee2f411e77472a7da.tar.bz2 |
moved window menu from FluxboxWindow to BScreen
Diffstat (limited to 'src/Remember.cc')
-rw-r--r-- | src/Remember.cc | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/src/Remember.cc b/src/Remember.cc index e3d3db0..9eae24b 100644 --- a/src/Remember.cc +++ b/src/Remember.cc | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "FbMenu.hh" | 31 | #include "FbMenu.hh" |
32 | #include "FbCommands.hh" | 32 | #include "FbCommands.hh" |
33 | #include "fluxbox.hh" | 33 | #include "fluxbox.hh" |
34 | #include "WindowCmd.hh" | ||
34 | 35 | ||
35 | #include "FbTk/I18n.hh" | 36 | #include "FbTk/I18n.hh" |
36 | #include "FbTk/StringUtil.hh" | 37 | #include "FbTk/StringUtil.hh" |
@@ -60,53 +61,58 @@ namespace { | |||
60 | 61 | ||
61 | class RememberMenuItem : public FbTk::MenuItem { | 62 | class RememberMenuItem : public FbTk::MenuItem { |
62 | public: | 63 | public: |
63 | RememberMenuItem(const char *label, Remember &remember, | 64 | RememberMenuItem(const char *label, |
64 | FluxboxWindow &fbwin, | ||
65 | Remember::Attribute attrib) : | 65 | Remember::Attribute attrib) : |
66 | FbTk::MenuItem(label), m_remember(remember), | 66 | FbTk::MenuItem(label), |
67 | m_win(fbwin), m_attrib(attrib) { | 67 | m_attrib(attrib) { |
68 | setToggleItem(true); | 68 | setToggleItem(true); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool isSelected() const { | 71 | bool isSelected() const { |
72 | if (m_win.numClients()) // ensure it HAS clients | 72 | if (WindowCmd<void>::window() == 0) |
73 | return m_remember.isRemembered(m_win.winClient(), m_attrib); | 73 | return false; |
74 | |||
75 | if (WindowCmd<void>::window()->numClients()) // ensure it HAS clients | ||
76 | return Remember::instance().isRemembered(WindowCmd<void>::window()->winClient(), m_attrib); | ||
74 | else | 77 | else |
75 | return false; | 78 | return false; |
76 | } | 79 | } |
77 | 80 | ||
78 | bool isEnabled() const { | 81 | bool isEnabled() const { |
82 | if (WindowCmd<void>::window() == 0) | ||
83 | return false; | ||
84 | |||
79 | if (m_attrib != Remember::REM_JUMPWORKSPACE) | 85 | if (m_attrib != Remember::REM_JUMPWORKSPACE) |
80 | return true; | 86 | return true; |
81 | else if (m_win.numClients()) | 87 | else if (WindowCmd<void>::window()->numClients()) |
82 | return (m_remember.isRemembered(m_win.winClient(), Remember::REM_WORKSPACE)); | 88 | return (Remember::instance().isRemembered(WindowCmd<void>::window()->winClient(), Remember::REM_WORKSPACE)); |
83 | else | 89 | else |
84 | return false; | 90 | return false; |
85 | } | 91 | } |
86 | 92 | ||
87 | void click(int button, int time) { | 93 | void click(int button, int time) { |
88 | if (isSelected()) { | 94 | if (WindowCmd<void>::window() != 0) { |
89 | m_remember.forgetAttrib(m_win.winClient(), m_attrib); | 95 | if (isSelected()) { |
90 | } else { | 96 | Remember::instance().forgetAttrib(WindowCmd<void>::window()->winClient(), m_attrib); |
91 | m_remember.rememberAttrib(m_win.winClient(), m_attrib); | 97 | } else { |
98 | Remember::instance().rememberAttrib(WindowCmd<void>::window()->winClient(), m_attrib); | ||
99 | } | ||
92 | } | 100 | } |
93 | m_remember.save(); | 101 | Remember::instance().save(); |
94 | FbTk::MenuItem::click(button, time); | 102 | FbTk::MenuItem::click(button, time); |
95 | } | 103 | } |
96 | 104 | ||
97 | private: | 105 | private: |
98 | // my remember manager | ||
99 | Remember &m_remember; | ||
100 | FluxboxWindow &m_win; | ||
101 | Remember::Attribute m_attrib; | 106 | Remember::Attribute m_attrib; |
102 | }; | 107 | }; |
103 | 108 | ||
104 | FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win, bool enabled) { | 109 | FbTk::Menu *createRememberMenu(BScreen &screen) { |
105 | // each fluxboxwindow has its own windowmenu | 110 | // each fluxboxwindow has its own windowmenu |
106 | // so we also create a remember menu just for it... | 111 | // so we also create a remember menu just for it... |
107 | FbTk::Menu *menu = win.screen().createMenu(""); | 112 | FbTk::Menu *menu = screen.createMenu(""); |
108 | 113 | ||
109 | // if enabled, then we want this to be a unavailable menu | 114 | // if enabled, then we want this to be a unavailable menu |
115 | /* | ||
110 | if (!enabled) { | 116 | if (!enabled) { |
111 | FbTk::MenuItem *item = new FbTk::MenuItem("unavailable"); | 117 | FbTk::MenuItem *item = new FbTk::MenuItem("unavailable"); |
112 | item->setEnabled(false); | 118 | item->setEnabled(false); |
@@ -114,28 +120,28 @@ FbTk::Menu *createRememberMenu(Remember &remember, FluxboxWindow &win, bool enab | |||
114 | menu->updateMenu(); | 120 | menu->updateMenu(); |
115 | return menu; | 121 | return menu; |
116 | } | 122 | } |
117 | 123 | */ | |
118 | _FB_USES_NLS; | 124 | _FB_USES_NLS; |
119 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), | 125 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), |
120 | remember, win, Remember::REM_WORKSPACE)); | 126 | Remember::REM_WORKSPACE)); |
121 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), | 127 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), |
122 | remember, win, Remember::REM_JUMPWORKSPACE)); | 128 | Remember::REM_JUMPWORKSPACE)); |
123 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Head, "Head", "Remember Head"), | 129 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Head, "Head", "Remember Head"), |
124 | remember, win, Remember::REM_HEAD)); | 130 | Remember::REM_HEAD)); |
125 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), | 131 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), |
126 | remember, win, Remember::REM_DIMENSIONS)); | 132 | Remember::REM_DIMENSIONS)); |
127 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), | 133 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), |
128 | remember, win, Remember::REM_POSITION)); | 134 | Remember::REM_POSITION)); |
129 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), | 135 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), |
130 | remember, win, Remember::REM_STUCKSTATE)); | 136 | Remember::REM_STUCKSTATE)); |
131 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), | 137 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), |
132 | remember, win, Remember::REM_DECOSTATE)); | 138 | Remember::REM_DECOSTATE)); |
133 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Shaded, "Shaded", "Remember shaded"), | 139 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Shaded, "Shaded", "Remember shaded"), |
134 | remember, win, Remember::REM_SHADEDSTATE)); | 140 | Remember::REM_SHADEDSTATE)); |
135 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Layer, "Layer", "Remember Layer"), | 141 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, Layer, "Layer", "Remember Layer"), |
136 | remember, win, Remember::REM_LAYER)); | 142 | Remember::REM_LAYER)); |
137 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"), | 143 | menu->insert(new RememberMenuItem(_FBTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"), |
138 | remember, win, Remember::REM_SAVEONCLOSE)); | 144 | Remember::REM_SAVEONCLOSE)); |
139 | 145 | ||
140 | menu->updateMenu(); | 146 | menu->updateMenu(); |
141 | return menu; | 147 | return menu; |
@@ -217,16 +223,23 @@ Application::Application(bool grouped) | |||
217 | save_on_close_remember = false; | 223 | save_on_close_remember = false; |
218 | } | 224 | } |
219 | 225 | ||
220 | /******************************************************** | 226 | /************ |
221 | * Remember * | 227 | * Remember * |
222 | ************/ | 228 | ************/ |
223 | 229 | ||
230 | Remember *Remember::s_instance = 0; | ||
231 | |||
224 | Remember::Remember() { | 232 | Remember::Remember() { |
233 | if (s_instance != 0) | ||
234 | throw string("Can not create more than one instance of Remember"); | ||
235 | |||
236 | s_instance = this; | ||
225 | enableUpdate(); | 237 | enableUpdate(); |
226 | load(); | 238 | load(); |
227 | } | 239 | } |
228 | 240 | ||
229 | Remember::~Remember() { | 241 | Remember::~Remember() { |
242 | |||
230 | // free our resources | 243 | // free our resources |
231 | 244 | ||
232 | // the patterns free the "Application"s | 245 | // the patterns free the "Application"s |
@@ -245,6 +258,8 @@ Remember::~Remember() { | |||
245 | delete (*ait); | 258 | delete (*ait); |
246 | ++ait; | 259 | ++ait; |
247 | } | 260 | } |
261 | |||
262 | s_instance = 0; | ||
248 | } | 263 | } |
249 | 264 | ||
250 | Application* Remember::find(WinClient &winclient) { | 265 | Application* Remember::find(WinClient &winclient) { |
@@ -811,9 +826,6 @@ void Remember::setupFrame(FluxboxWindow &win) { | |||
811 | // we don't touch the window if it is a transient | 826 | // we don't touch the window if it is a transient |
812 | // of something else | 827 | // of something else |
813 | 828 | ||
814 | // All windows get the remember menu. | ||
815 | win.addExtraMenu(_FBTEXT(Remember, MenuItemName, "Remember...", "Remember item in menu"), | ||
816 | createRememberMenu(*this, win, (winclient.transientFor() == 0))); | ||
817 | 829 | ||
818 | if (winclient.transientFor()) | 830 | if (winclient.transientFor()) |
819 | return; | 831 | return; |
@@ -936,6 +948,13 @@ void Remember::updateClientClose(WinClient &winclient) { | |||
936 | 948 | ||
937 | } | 949 | } |
938 | 950 | ||
951 | void Remember::initForScreen(BScreen &screen) { | ||
952 | // All windows get the remember menu. | ||
953 | screen.addExtraWindowMenu(_FBTEXT(Remember, MenuItemName, "Remember...", "Remember item in menu"), | ||
954 | createRememberMenu(screen)); | ||
955 | |||
956 | } | ||
957 | |||
939 | void Remember::updateFrameClose(FluxboxWindow &win) { | 958 | void Remember::updateFrameClose(FluxboxWindow &win) { |
940 | // scan all applications and remove this fbw if it is a recorded group | 959 | // scan all applications and remove this fbw if it is a recorded group |
941 | Patterns::iterator it = m_pats.begin(); | 960 | Patterns::iterator it = m_pats.begin(); |