Mercurial Hosting > editor
comparison src/luan_editor/Window.luan @ 67:2c050fcf2614
add document count
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 06 Jun 2025 18:59:44 -0600 |
| parents | 1c68552e8ac2 |
| children | 694359b01e06 |
comparison
equal
deleted
inserted
replaced
| 66:d10058fd247d | 67:2c050fcf2614 |
|---|---|
| 146 window.text_area = text_area | 146 window.text_area = text_area |
| 147 local title = file and file.canonical().to_string() or "new" | 147 local title = file and file.canonical().to_string() or "new" |
| 148 if document ~= nil then | 148 if document ~= nil then |
| 149 text_area.document = document | 149 text_area.document = document |
| 150 elseif file ~= nil then | 150 elseif file ~= nil then |
| 151 local document = documents[title] | 151 local document_info = documents[title] |
| 152 if document ~= nil then | 152 if document_info ~= nil then |
| 153 text_area.document = document | 153 text_area.document = document_info.document |
| 154 document_info.count = document_info.count + 1 | |
| 154 else | 155 else |
| 155 documents[title] = text_area.document | 156 document_info = { document = text_area.document, count = 1 } |
| 157 documents[title] = document_info | |
| 156 if file.exists() then | 158 if file.exists() then |
| 157 text_area.text = file.read_text() | 159 text_area.text = file.read_text() |
| 158 text_area.document.clear_unedited() | 160 text_area.document.clear_unedited() |
| 159 end | 161 end |
| 160 end | 162 end |
| 195 n_windows = n_windows - 1 | 197 n_windows = n_windows - 1 |
| 196 if n_windows == 0 then | 198 if n_windows == 0 then |
| 197 Luan.exit() | 199 Luan.exit() |
| 198 end | 200 end |
| 199 remove_list_window_item(list_window_item) | 201 remove_list_window_item(list_window_item) |
| 202 local document_info = documents[title] or error() | |
| 203 document_info.count = document_info.count - 1 | |
| 204 if document_info.count == 0 then | |
| 205 documents[title] = nil | |
| 206 end | |
| 200 end) | 207 end) |
| 201 frame.add_window_focus_listener(function() | 208 frame.add_window_focus_listener(function() |
| 202 list_view.selected_value = list_window_item | 209 list_view.selected_value = list_window_item |
| 203 end) | 210 end) |
| 204 frame.add_resize_stopped_listener( 200, function() | 211 frame.add_resize_stopped_listener( 200, function() |
| 250 } | 257 } |
| 251 if file == nil then | 258 if file == nil then |
| 252 return false | 259 return false |
| 253 end | 260 end |
| 254 title = file.canonical().to_string() | 261 title = file.canonical().to_string() |
| 255 documents[title] = text_area.document | 262 documents[title] = { document = text_area.document, count = 1 } |
| 256 window.is_unedited = nil | 263 window.is_unedited = nil |
| 257 undo_listener() | 264 undo_listener() |
| 258 end | 265 end |
| 259 try | 266 try |
| 260 file.write_text(text_area.text) | 267 file.write_text(text_area.text) |
