@@ -1150,37 +1150,49 @@ def save_tabs(self, filename='session.json'):
1150
1150
for key , nb in self .notebook_manager .get_notebooks ().items ():
1151
1151
tabs = []
1152
1152
for index in range (nb .get_n_pages ()):
1153
- page = nb .get_nth_page (index )
1154
- tabs .append ({
1155
- 'directory' : page .child .terminal .get_current_directory (),
1156
- 'label' : nb .get_tab_text_index (index ),
1157
- 'custom_label_set' : getattr (page , 'custom_label_set' , False )
1158
- })
1153
+ try :
1154
+ page = nb .get_nth_page (index )
1155
+ tabs .append ({
1156
+ 'directory' : page .child .terminal .get_current_directory (),
1157
+ 'label' : nb .get_tab_text_index (index ),
1158
+ 'custom_label_set' : getattr (page , 'custom_label_set' , False )
1159
+ })
1160
+ except FileNotFoundError :
1161
+ # discard same broken tabs
1162
+ pass
1159
1163
# NOTE: Maybe we will have frame inside the workspace in future
1160
1164
# So lets use list to store the tabs (as for each frame)
1161
1165
config ['workspace' ][key ] = [tabs ]
1162
1166
1163
- with open (self .get_xdg_config_directory () / filename , 'w' ) as f :
1167
+ if not self .get_xdg_config_directory ().exists ():
1168
+ self .get_xdg_config_directory ().mkdir (parents = True )
1169
+ session_file = self .get_xdg_config_directory () / filename
1170
+ with session_file .open ('w' ) as f :
1164
1171
json .dump (config , f , ensure_ascii = False , indent = 4 )
1165
1172
1166
- log .info ('Guake tabs saved' )
1173
+ log .info ('Guake tabs saved to %s' , session_file )
1167
1174
1168
1175
def restore_tabs (self , filename = 'session.json' , suppress_notify = False ):
1169
- path = self .get_xdg_config_directory () / filename
1170
- if not path .exists ():
1176
+ session_file = self .get_xdg_config_directory () / filename
1177
+ if not session_file .exists ():
1171
1178
log .info ('Cannot found tabs session.json file' )
1172
1179
return
1173
- with open (path ) as f :
1180
+ with session_file . open () as f :
1174
1181
try :
1175
1182
config = json .load (f )
1176
1183
except Exception :
1177
1184
log .warning ('session.json is broken' )
1178
- shutil .copy (path , self .get_xdg_config_directory () / '{}.bak' .format (filename ))
1185
+ shutil .copy (
1186
+ session_file ,
1187
+ self .get_xdg_config_directory () / '{0}.bak' .format (filename )
1188
+ )
1179
1189
img_filename = pixmapfile ('guake-notification.png' )
1180
1190
notifier .showMessage (
1181
1191
_ ('Guake Terminal' ),
1182
- _ ('Your session.json file is broken, backup to {}.bak' .format (filename )),
1183
- img_filename )
1192
+ _ ('Your session.json file is broken, backup to {session_filename}.bak' ).format (
1193
+ session_filename = filename
1194
+ ), img_filename
1195
+ )
1184
1196
return
1185
1197
1186
1198
# Disable auto save tabs
@@ -1198,9 +1210,8 @@ def restore_tabs(self, filename='session.json', suppress_notify=False):
1198
1210
for tabs in frames :
1199
1211
for index , tab in enumerate (tabs ):
1200
1212
nb .new_page_with_focus (
1201
- tab ['directory' ],
1202
- tab ['label' ],
1203
- tab ['custom_label_set' ])
1213
+ tab ['directory' ], tab ['label' ], tab ['custom_label_set' ]
1214
+ )
1204
1215
1205
1216
# Remove original pages in notebook
1206
1217
for i in range (current_pages ):
@@ -1213,20 +1224,18 @@ def restore_tabs(self, filename='session.json', suppress_notify=False):
1213
1224
img_filename = pixmapfile ('guake-notification.png' )
1214
1225
notifier .showMessage (
1215
1226
_ ('Guake Terminal' ),
1216
- _ ('Your session.json schema is broken, backup to {0}.bak,'
1217
- 'and error message has been saved to {0}.log.err' .format (filename )),
1218
- img_filename )
1227
+ _ (
1228
+ 'Your session.json schema is broken, backup to {0}.bak,'
1229
+ 'and error message has been saved to {0}.log.err' .format (filename )
1230
+ ), img_filename
1231
+ )
1219
1232
1220
1233
# Reset auto save tabs
1221
1234
self .settings .general .set_boolean ('save-tabs-when-changed' , v )
1222
1235
1223
1236
# Notify the user
1224
- if (self .settings .general .get_boolean ('restore-tabs-notify' ) and
1225
- not suppress_notify ):
1237
+ if (self .settings .general .get_boolean ('restore-tabs-notify' ) and not suppress_notify ):
1226
1238
filename = pixmapfile ('guake-notification.png' )
1227
- notifier .showMessage (
1228
- _ ("Guake Terminal" ),
1229
- _ ("Your tabs has been restored!" ),
1230
- filename )
1239
+ notifier .showMessage (_ ("Guake Terminal" ), _ ("Your tabs has been restored!" ), filename )
1231
1240
1232
- log .info ('Guake tabs restored' )
1241
+ log .info ('Guake tabs restored from %s' , session_file )
0 commit comments