Changeset 847:5cbdf59de0c0 for pida/services/sessions/sessions.py
- Timestamp:
- 05/11/07 20:29:04 (20 months ago)
- Files:
-
- 1 modified
-
pida/services/sessions/sessions.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pida/services/sessions/sessions.py
r807 r847 86 86 self._path = session_path 87 87 self._config = ConfigObj(self._path) 88 self.name = self._config['name'] 89 self._files = self._config['files'] 90 # self._project = self._config['project'] 88 89 if self._config.has_key('name') and self._config.has_key('files'): 90 self.name = self._config.get('name') 91 self._files = self._config.get('files') 92 # self._project = self._config['project'] 93 else: 94 # something has gone horribly wrong 95 # return false and log it in the service 96 raise IOError('Failed to read config file') 91 97 92 98 def _parse_session_path(self, path): … … 104 110 self._files = files 105 111 112 def get_path(self): 113 return self._path 114 106 115 107 116 class SessionsActionsConfig(ActionsConfig): … … 179 188 ) 180 189 181 182 190 gladefile = 'sessions-properties' 183 191 label_text = _('Sessions Properties') … … 188 196 189 197 198 class SessionsEventsConfig(EventsConfig): 199 200 def subscribe_foreign_events(self): 201 self.subscribe_foreign_event('buffer', 'document-changed', self.svc.save_last_session) 202 self.subscribe_foreign_event('editor', 'started', self.svc.load_last_session) 190 203 191 204 class Sessions(Service): … … 207 220 files = [buffer.filename for buffer in current_buffers] 208 221 """ 209 # TODO - Make Sessions align with Pida style guide210 # TODO - Create the Pida Prefrences Gui211 222 # TODO - Save the last session on close 212 223 # TODO - Allow restoring of last session on startup … … 215 226 actions_config = SessionsActionsConfig 216 227 options_config = SessionsOptionsConfig 228 events_config = SessionsEventsConfig 229 last_session_file = 'last.session' 217 230 218 231 def pre_start(self): 219 232 self.sessions_dir = os.path.join(self.boss.get_pida_home(), 220 233 'sessions') 234 self.last_session_path = os.path.join(self.sessions_dir, 235 self.last_session_file) 221 236 if not os.path.exists(self.sessions_dir): 222 237 os.mkdir(self.sessions_dir) 238 239 self.last_session = SessionObject() 240 241 if not os.path.exists(self.last_session_path): 242 self.last_session.new(self.last_session_path, []) 243 self.last_session.save() 244 else: 245 self.last_session.load(self.last_session_path) 246 223 247 self._set_current_session(None) 224 # self.current_session = None 225 226 def load_session(self, file_path): 248 249 def load_last_session(self): 250 if self.opt('load_last_session'): 251 self.load_session(self.last_session_path) 252 253 def load_session(self, file_path, set_current=None): 227 254 """ 228 255 load the saved session file from disk 229 256 """ 230 257 session = SessionObject() 231 session.load(file_path) 232 self._set_current_session(session) 233 self.load_buffers(session.get_files()) 258 try: 259 session.load(file_path) 260 if set_current: 261 self._set_current_session(session) 262 self.load_buffers(session.get_files()) 263 except IOError: 264 # when we catch this exception we should really make an attempt 265 # at repairing whatever session file it was failing on. 266 self.log_warn(_('Session file:%s failed to load') % file_path) 267 return 268 269 def save_last_session(self, document): 270 self.last_session.set_files(self._get_current_buffers()) 271 self.last_session.save() 234 272 235 273 def save_current_session(self, file_path=None): 236 if not self.current_session: 274 """ 275 If no file_path is given save_current_session assumes you will be 276 saving to the default last_session path which is /sessions/last.session 277 """ 278 279 if self.current_session: 280 self.current_session.set_files(self._get_current_buffers()) 281 self.current_session.save(file_path) 282 else: 237 283 self.current_session = SessionObject() 238 284 self.current_session.new(file_path, 239 files = self._get_current_buffers())285 files = self._get_current_buffers()) 240 286 self.current_session.save() 241 else:242 self.current_session.set_files(self._get_current_buffers())243 self.current_session.save(file_path)244 287 245 288 def _set_current_session(self, session):
