Changeset 1682:cfc7a1a73805
- Timestamp:
- 11/22/08 00:05:18 (7 weeks ago)
- Author:
- Ali Afshar <aafshar@…>
- Parents:
- 1679:b24dbcc340fd, 1681:b6979d84d3f8
- Message:
-
merged 270
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1680
|
r1682
|
|
| 82 | 82 | |
| 83 | 83 | def __init__(self, boss, filename=None, project=None): |
| | 84 | """ |
| | 85 | Create a new Document instance. |
| | 86 | |
| | 87 | @boss: boss this document belongs to |
| | 88 | @filename: path to the file or None (unamed buffer) |
| | 89 | @project: project this document belongs to |
| | 90 | """ |
| 84 | 91 | self.boss = boss |
| 85 | 92 | if filename is not None: |
| 86 | | filename = os.path.realpath(filename) |
| 87 | | self.filename = filename |
| | 93 | self.filename = os.path.realpath(filename) |
| | 94 | else: |
| | 95 | self.filename = None |
| 88 | 96 | self.project = project |
| 89 | 97 | self.editor = None |
| … |
… |
|
| 108 | 116 | |
| 109 | 117 | def clear(self): |
| | 118 | """ |
| | 119 | Clear document caches |
| | 120 | """ |
| 110 | 121 | self._str = None |
| 111 | 122 | self._lines = None |
| … |
… |
|
| 171 | 182 | @property |
| 172 | 183 | def stat(self): |
| | 184 | """ |
| | 185 | Returns the stat of the current file |
| | 186 | """ |
| 173 | 187 | try: |
| 174 | 188 | return os.stat(self.filename) |
| … |
… |
|
| 178 | 192 | @cached_property |
| 179 | 193 | def mimetype(self): |
| | 194 | """ |
| | 195 | Returns the mimetype guessed from the file |
| | 196 | """ |
| 180 | 197 | #FIXME: use doctypes |
| 181 | 198 | typ, encoding = mimetypes.guess_type(self.filename) |
| … |
… |
|
| 188 | 205 | @property |
| 189 | 206 | def filesize(self): |
| | 207 | """ |
| | 208 | Filesize of Document |
| | 209 | """ |
| 190 | 210 | return self.stat[stat.ST_SIZE] |
| 191 | 211 | |
| … |
… |
|
| 210 | 230 | @property |
| 211 | 231 | def markup_title(self): |
| 212 | | """Returns a markup version of unicode""" |
| | 232 | """ |
| | 233 | Returns a markup version of unicode |
| | 234 | """ |
| 213 | 235 | if self.filename is None: |
| 214 | 236 | if self.newfile_index > 1: |
| … |
… |
|
| 229 | 251 | @property |
| 230 | 252 | def encoding(self): |
| | 253 | """ |
| | 254 | Encoding of file |
| | 255 | """ |
| 231 | 256 | self._load() |
| 232 | 257 | # FIXME: if self.is_new we should run the _encode detection from |
| … |
… |
|
| 243 | 268 | @property |
| 244 | 269 | def live(self): |
| | 270 | """ |
| | 271 | Returns a boolean if the document is loaded in the editor |
| | 272 | """ |
| 245 | 273 | # live indicates that this object has a editor instance which get_content |
| 246 | 274 | #self.live = False |
| … |
… |
|
| 250 | 278 | return False |
| 251 | 279 | |
| 252 | | def get_content(self): |
| 253 | | if hasattr(self.editor, 'get_content') and self.editor: |
| | 280 | def get_content(self, live=True): |
| | 281 | """ |
| | 282 | Returns the content of the document. |
| | 283 | If live is true and the document is loaded into an editor the |
| | 284 | content of the editor is returned |
| | 285 | """ |
| | 286 | if live and hasattr(self.editor, 'get_content') and self.editor: |
| 254 | 287 | return self.boss.editor.get_content(self.editor) |
| 255 | 288 | self._load() |
| 256 | 289 | return self._str |
| 257 | 290 | |
| 258 | | def set_content(self, value, flush=True): |
| | 291 | def set_content(self, value, flush=True, live=True): |
| | 292 | """ |
| | 293 | Sets the content of the document. |
| | 294 | If live is True and the document is loaded, it's content is returned |
| | 295 | """ |
| 259 | 296 | if hasattr(self.boss.editor, 'set_content') and self.editor: |
| 260 | 297 | return self.boss.editor.set_content(self.editor, value) |
| … |
… |
|
| 269 | 306 | |
| 270 | 307 | def flush(self): |
| | 308 | """ |
| | 309 | Flush the buffer. |
| | 310 | If editor has loaded this document, it's value |
| | 311 | is fetched befor writing to disc |
| | 312 | """ |
| 271 | 313 | if hasattr(self.editor, 'get_content') and self.editor: |
| 272 | 314 | value = self.boss.editor.get_content(self.editor) |
| … |
… |
|
| 294 | 336 | @property |
| 295 | 337 | def directory(self): |
| | 338 | """ |
| | 339 | Directory name the Document is located in |
| | 340 | """ |
| 296 | 341 | if self.is_new: |
| 297 | 342 | return None |
| … |
… |
|
| 300 | 345 | @property |
| 301 | 346 | def directory_basename(self): |
| | 347 | """ |
| | 348 | Directory's name the Document is located in |
| | 349 | """ |
| 302 | 350 | if self.is_new: |
| 303 | 351 | return None |
| … |
… |
|
| 306 | 354 | @property |
| 307 | 355 | def basename(self): |
| | 356 | """ |
| | 357 | Basename of the file. It's actuall filename |
| | 358 | """ |
| 308 | 359 | if self.is_new: |
| 309 | 360 | return None |
| … |
… |
|
| 319 | 370 | |
| 320 | 371 | def get_markup(self, markup_string=None, style=None): |
| | 372 | """ |
| | 373 | Returns a markup version the Document designed for |
| | 374 | beeing embedded in gtk views |
| | 375 | """ |
| 321 | 376 | if markup_string is None: |
| 322 | 377 | if self.project: |
| … |
… |
|
| 335 | 390 | |
| 336 | 391 | def get_markup_tworow(self, style=None): |
| | 392 | """ |
| | 393 | Two rowed version of above |
| | 394 | """ |
| 337 | 395 | if self.project: |
| 338 | 396 | mark = self.get_markup(self.markup_string_tworow_project) |
| … |
… |
|
| 359 | 417 | @property |
| 360 | 418 | def project_name(self): |
| | 419 | """ |
| | 420 | Name of Project or None |
| | 421 | """ |
| 361 | 422 | if self.project is not None: |
| 362 | 423 | return self.project.display_name |
| … |
… |
|
| 365 | 426 | |
| 366 | 427 | def get_project_relative_path(self): |
| | 428 | """ |
| | 429 | Returns the relative path to Project's root |
| | 430 | """ |
| 367 | 431 | if self.filename is None: |
| 368 | 432 | return None, None |
| … |
… |
|
| 379 | 443 | @property |
| 380 | 444 | def is_new(self): |
| | 445 | """ |
| | 446 | True if the Document is not associated to a filename |
| | 447 | """ |
| 381 | 448 | return self.filename is None |
| 382 | 449 | |
| … |
… |
|
| 401 | 468 | |
| 402 | 469 | def append(self, line): |
| | 470 | """ |
| | 471 | Add a line to the Document |
| | 472 | """ |
| 403 | 473 | self._list.append(line) |
| 404 | 474 | self._update_content_from_lines() |