Skip to content

Commit a1d030d

Browse files
authored
Merge pull request #31 from nlpsuge/fix-forward-slash-in-session-name
1. Session names cannot contains the forward slash (/) 2. Display the raw error message when failed to save the windows session to the disk
2 parents d2adc0c + 80fb67a commit a1d030d

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

saveSession.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ var SaveSession = class {
180180
} catch (e) {
181181
logError(e, `Failed to write session to disk`);
182182
global.notify_error(`Failed to write session to disk`, e.message);
183+
throw e;
183184
}
184185

185186
return false;

ui/popupMenuButtonItems.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,14 @@ class PopupMenuButtonItemSave extends PopupMenuButtonItem {
291291
track_hover: true,
292292
can_focus: true
293293
});
294-
const clutterText = this.saveCurrentSessionEntry.clutter_text
295-
clutterText.connect('key-press-event', this._onKeyPressEvent.bind(this));
294+
const clutterText = this.saveCurrentSessionEntry.clutter_text;
295+
clutterText.connect('activate', this._onTextActivate.bind(this));
296296
this.actor.add_child(this.saveCurrentSessionEntry);
297297

298298
}
299299

300-
_onKeyPressEvent(entry, event) {
301-
const symbol = event.get_key_symbol();
302-
if (symbol == Clutter.KEY_Return || symbol == Clutter.KEY_KP_Enter || symbol == Clutter.KEY_ISO_Enter) {
303-
this._gotoSaveSession();
304-
}
300+
_onTextActivate(entry, event) {
301+
this._gotoSaveSession();
305302
}
306303

307304
_gotoSaveSession() {
@@ -317,23 +314,18 @@ class PopupMenuButtonItemSave extends PopupMenuButtonItem {
317314

318315
const [canSave, reason] = this._canSave(sessionName);
319316
if (!canSave) {
320-
this.savingLabel.set_text(reason);
321-
this._timeline.set_actor(this.savingLabel);
322-
this._timeline.connect('new-frame', (_timeline, _frame) => {
323-
this.savingLabel.show();
324-
this.hideYesAndNoButtons();
325-
});
326-
this._timeline.start();
327-
this._timeline.connect('completed', () => {
328-
this._timeline.stop();
329-
this.savingLabel.hide();
330-
this.showYesAndNoButtons();
331-
});
332-
317+
this._displayMessage(reason);
333318
return;
334319
}
335320

336-
this._saveSession.saveSession(sessionName);
321+
try {
322+
this._saveSession.saveSession(sessionName);
323+
} catch (e) {
324+
logError(e, `Failed to save session`);
325+
global.notify_error(`Failed to save session`, e.message);
326+
this._displayMessage(e.message);
327+
return;
328+
}
337329

338330
// clear entry
339331
this.saveCurrentSessionEntry.set_text('');
@@ -354,6 +346,24 @@ class PopupMenuButtonItemSave extends PopupMenuButtonItem {
354346
});
355347
}
356348

349+
_displayMessage(message) {
350+
// To prevent saving session many times by holding and not releasing Enter
351+
this.saveCurrentSessionEntry.hide();
352+
this.savingLabel.set_text(message);
353+
this._timeline.set_actor(this.savingLabel);
354+
this._timeline.connect('new-frame', (_timeline, _frame) => {
355+
this.savingLabel.show();
356+
this.hideYesAndNoButtons();
357+
});
358+
this._timeline.start();
359+
this._timeline.connect('completed', () => {
360+
this._timeline.stop();
361+
this.savingLabel.hide();
362+
this.saveCurrentSessionEntry.show();
363+
this.showYesAndNoButtons();
364+
});
365+
}
366+
357367
_canSave(sessionName) {
358368
if (sessionName === FileUtils.sessions_backup_folder_name) {
359369
return [false, `ERROR: ${sessionName} is a reserved word, can't be used.`];
@@ -362,6 +372,10 @@ class PopupMenuButtonItemSave extends PopupMenuButtonItem {
362372
if (FileUtils.isDirectory(sessionName)) {
363373
return [false, `ERROR: Can't save windows using '${sessionName}', it's an existing directory!`];
364374
}
375+
376+
if (sessionName.indexOf('/') != -1) {
377+
return [false, `ERROR: Session names cannot contain '/'`];
378+
}
365379
return [true, ''];
366380
}
367381

0 commit comments

Comments
 (0)