Skip to content

Commit

Permalink
Added errors messages and generate desktop file (not saved yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
glebihan committed Dec 21, 2011
1 parent c6088d3 commit 95ecb62
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/theme/cinnamon.css
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ StTooltip StLabel {
border: solid 1px #FFFFFF;
}

.add-launcher-description-entry {
.add-launcher-name-entry {
width: 23em;
color: white;
border: solid 1px #FFFFFF;
Expand Down
63 changes: 58 additions & 5 deletions js/ui/panelLaunchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Gio = imports.gi.Gio;
const PopupMenu = imports.ui.popupMenu;
const Main = imports.ui.main;
const ModalDialog = imports.ui.modalDialog;
const Signals = imports.signals;

function PanelAppLauncherMenu(launcher) {
this._init(launcher);
Expand Down Expand Up @@ -122,10 +123,10 @@ AddLauncherDialog.prototype = {
box = new St.BoxLayout();
this.contentLayout.add(box, { y_align: St.Align.START });
label = new St.Label();
label.set_text(_("Description"));
label.set_text(_("Name"));
box.add(label, { x_align: St.Align.START, x_fill: true, x_expand: true });
this._descriptionEntry = new St.Entry({ styleClass: 'add-launcher-description-entry' });
box.add(this._descriptionEntry, { x_align: St.Align.END, x_fill: false, x_expand: false });
this._nameEntry = new St.Entry({ styleClass: 'add-launcher-name-entry' });
box.add(this._nameEntry, { x_align: St.Align.END, x_fill: false, x_expand: false });

box = new St.BoxLayout();
this.contentLayout.add(box, { y_align: St.Align.START, x_fill: true });
Expand All @@ -135,6 +136,24 @@ AddLauncherDialog.prototype = {
this._commandEntry = new St.Entry({ styleClass: 'add-launcher-command-entry' });
box.add(this._commandEntry, { x_align: St.Align.END, x_fill: false, x_expand: false });

this._errorBox = new St.BoxLayout({ style_class: 'run-dialog-error-box' });
this.contentLayout.add(this._errorBox, { expand: true });

let errorIcon = new St.Icon({ icon_name: 'dialog-error', icon_size: 24, style_class: 'run-dialog-error-icon' });

this._errorBox.add(errorIcon, { y_align: St.Align.MIDDLE });

this._commandError = false;

this._errorMessage = new St.Label({ style_class: 'run-dialog-error-label' });
this._errorMessage.clutter_text.line_wrap = true;

this._errorBox.add(this._errorMessage, { expand: true,
y_align: St.Align.MIDDLE,
y_fill: false });

this._errorBox.hide();

this.setButtons([
{
label: _("Add"),
Expand All @@ -153,19 +172,42 @@ AddLauncherDialog.prototype = {
},

_onOpened: function() {
this._descriptionEntry.grab_key_focus();
this._nameEntry.grab_key_focus();
},

_validateAdd: function() {
if (this._nameEntry.clutter_text.get_text()==""){
this._errorMessage.clutter_text.set_text(_('Name cannot be empty !'));
this._errorBox.show();
return false;
}
if (this._commandEntry.clutter_text.get_text()==""){
this._errorMessage.clutter_text.set_text(_('Command cannot be empty !'));
this._errorBox.show();
return false;
}

let appid = this._saveNewLauncher(this._nameEntry.clutter_text.get_text(), this._commandEntry.clutter_text.get_text());
this.close();
this.emit("launcher-created", appid);
},

_saveNewLauncher: function(name, command, description, icon){
let desktopEntry = "[Desktop Entry]\nName="+name+"\nExec="+command+"\n";
if (description) desktopEntry += "Description="+description+"\n";
if (icon) desktopEntry += "Icon="+icon+"\n";
global.log(desktopEntry);
},

open: function(timestamp) {
this._commandEntry.clutter_text.set_text('');
this._descriptionEntry.clutter_text.set_text('');
this._nameEntry.clutter_text.set_text('');
this._errorBox.hide();

ModalDialog.ModalDialog.prototype.open.call(this, timestamp);
},
}
Signals.addSignalMethods(AddLauncherDialog.prototype);

function PanelLaunchersBox() {
this._init();
Expand All @@ -178,10 +220,21 @@ PanelLaunchersBox.prototype = {
this.actor._delegate = this;

this._addLauncherDialog = new AddLauncherDialog();
this._addLauncherDialog.connect("launcher-created", Lang.bind(this, this._onLauncherCreated));

this.reload();
},

_onLauncherCreated: function(obj, appid){
if (appid){
let settings = new Gio.Settings({ schema: 'org.cinnamon' });
let desktopFiles = settings.get_strv('panel-launchers');
desktopFiles.push(appid);
settings.set_strv('panel-launchers', desktopFiles);
this.reload();
}
},

loadApps: function() {
let settings = new Gio.Settings({ schema: 'org.cinnamon' });
let desktopFiles = settings.get_strv('panel-launchers');
Expand Down

0 comments on commit 95ecb62

Please sign in to comment.