-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[[email protected]] Fix for 6.4 (#6746)
* [gpaste-reloaded] 6.4 fix Refactoring for new dialogs * Remove duplicate icon and install.sh * Fix crash after first dialog close
- Loading branch information
Showing
11 changed files
with
1,143 additions
and
1 deletion.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
[email protected]/files/[email protected]/6.4/GPasteHistoryItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
const Lang = imports.lang; | ||
const St = imports.gi.St; | ||
const PopupMenu = imports.ui.popupMenu; | ||
const Pango = imports.gi.Pango; | ||
const Clutter = imports.gi.Clutter; | ||
|
||
// ------------------------------------------------------------------------------------------------------ | ||
|
||
function GPasteHistoryItem(text, index) { | ||
this._init(text, index); | ||
} | ||
|
||
GPasteHistoryItem.prototype = { | ||
__proto__: PopupMenu.PopupBaseMenuItem.prototype, | ||
|
||
_init: function(applet) { | ||
PopupMenu.PopupBaseMenuItem.prototype._init.call(this); | ||
|
||
this._applet = applet; | ||
|
||
// | ||
// Label | ||
|
||
this.label = new St.Label({ text: '' }); | ||
this.label.clutter_text.set_ellipsize(Pango.EllipsizeMode.END); | ||
this.addActor(this.label); | ||
|
||
this.setTextLength(); | ||
this._settingsChangedID = this._applet.clientSettings.connect('changed::element-size', Lang.bind(this, this.setTextLength)); | ||
|
||
// | ||
// Delete button | ||
|
||
const iconDelete = new St.Icon({ | ||
icon_name: 'edit-delete', | ||
icon_type: St.IconType.SYMBOLIC, | ||
style_class: 'popup-menu-icon' | ||
}); | ||
this.deleteButton = new St.Button({ child: iconDelete }); | ||
this.deleteButton.connect('clicked', Lang.bind(this, this.remove)); | ||
this.addActor(this.deleteButton, { expand: false, span: -1, align: St.Align.END }); | ||
|
||
// | ||
// | ||
|
||
this.actor.connect('destroy', Lang.bind(this, this._onDestroy)); | ||
}, | ||
|
||
/* | ||
* Override key press event | ||
*/ | ||
_onKeyPressEvent: function(actor, event) { | ||
let symbol = event.get_key_symbol(); | ||
|
||
if (symbol == Clutter.KEY_space || symbol == Clutter.KEY_Return) { | ||
this.activate(event); | ||
return true; | ||
} else if (symbol == Clutter.KEY_Delete || symbol == Clutter.KEY_BackSpace) { | ||
this.remove(); | ||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
/* | ||
* Set max text length using GPaste's setting | ||
*/ | ||
setTextLength: function() { | ||
this.label.clutter_text.set_max_length(this._applet.clientSettings.get_element_size()); | ||
}, | ||
|
||
/* | ||
* Set specified index and get respective history item's content | ||
*/ | ||
setIndex: function(index) { | ||
this._index = index; | ||
|
||
if (index != -1) { | ||
this._applet.client.get_element_at_index(index, Lang.bind(this, function (client, result) { | ||
let item = client.get_element_at_index_finish(result); | ||
this._uuid = item.get_uuid(); | ||
this.label.set_text(item.get_value().replace(/[\t\n\r]/g, '')); | ||
})); | ||
|
||
this.actor.show(); | ||
} | ||
else { | ||
this.actor.hide(); | ||
} | ||
}, | ||
|
||
/* | ||
* Refresh history item's content | ||
*/ | ||
refresh: function() { | ||
this._applet.client.get_element_at_index(this._index, Lang.bind(this, function(client, result) { | ||
let item = client.get_element_at_index_finish(result); | ||
this._uuid = item.get_uuid(); | ||
this.label.set_text(item.get_value().replace(/[\t\n\r]/g, '')); | ||
})); | ||
}, | ||
|
||
/* | ||
* Remove history item | ||
*/ | ||
remove: function() { | ||
this._applet.client.delete(this._uuid, null); | ||
}, | ||
|
||
// | ||
// Events | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* History item has been removed, disconnect bindings | ||
*/ | ||
_onDestroy: function() { | ||
this._applet.clientSettings.disconnect(this._settingsChangedID); | ||
}, | ||
|
||
// | ||
// Overrides | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* Select history item | ||
*/ | ||
activate: function(event) { | ||
this._applet.client.select(this._uuid, null); | ||
this._applet.menu.toggle(); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
[email protected]/files/[email protected]/6.4/GPasteHistoryListItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const PopupMenu = imports.ui.popupMenu; | ||
|
||
// ------------------------------------------------------------------------------------------------------ | ||
|
||
function GPasteHistoryListItem(text, index) { | ||
this._init(text, index); | ||
} | ||
|
||
GPasteHistoryListItem.prototype = { | ||
__proto__: PopupMenu.PopupMenuItem.prototype, | ||
|
||
_init: function(applet, name, params) { | ||
PopupMenu.PopupMenuItem.prototype._init.call(this, name, params); | ||
|
||
this._applet = applet; | ||
this._histName = name; | ||
}, | ||
|
||
// | ||
// Overrides | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* Select history item | ||
*/ | ||
activate: function(event) { | ||
this._applet.selectHistory(this._histName); | ||
this._applet.contextMenu.close(true); | ||
}, | ||
}; |
125 changes: 125 additions & 0 deletions
125
[email protected]/files/[email protected]/6.4/GPasteNewItemDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const ModalDialog = imports.ui.modalDialog; | ||
const St = imports.gi.St; | ||
const Pango = imports.gi.Pango; | ||
const Gtk = imports.gi.Gtk; | ||
const GObject = imports.gi.GObject; | ||
|
||
const _ = require('./__init__')._; | ||
|
||
// ------------------------------------------------------------------------------------------------------ | ||
var GPasteNewItemDialog = GObject.registerClass( | ||
class GPasteNewItemDialog extends ModalDialog.ModalDialog { | ||
_init(callback) { | ||
super._init({ styleClass: 'gpaste__new-item-dialog', destroyOnClose: false }); | ||
|
||
this._callback = callback; | ||
this.entry = new St.Entry({ | ||
name: 'GPasteNewItemEntry' | ||
}); | ||
this.entry.clutter_text.set_activatable(false); | ||
this.entry.clutter_text.set_single_line_mode(false); | ||
this.entry.clutter_text.set_line_wrap(true); | ||
this.entry.clutter_text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR); | ||
this.entry.clutter_text.connect('text-changed', () => this._resizeEntry()); | ||
this._prevEntryHeight = -1; | ||
|
||
this._contentBox = new St.BoxLayout({ | ||
vertical: true, | ||
styleClass: 'gpaste__new-item-dialog__scroll-box__inner' | ||
}); | ||
this._contentBox.add_actor(this.entry); | ||
|
||
this.scrollBox = new St.ScrollView({ | ||
x_fill: true, | ||
y_fill: false, | ||
y_align: St.Align.START, | ||
styleClass: 'gpaste__new-item-dialog__scroll-box' | ||
}); | ||
this.scrollBox.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC); | ||
this.scrollBox.add_actor(this._contentBox); | ||
|
||
this.contentLayout.add(new St.Label({ text: _("Please enter the text you want to add to the current history:") })); | ||
this.contentLayout.add(this.scrollBox); | ||
this.contentLayout.add_style_class_name('gpaste__new-item-dialog__content'); | ||
|
||
this.setButtons([ | ||
{ | ||
label: _("OK"), | ||
action: () => this._onOK() | ||
}, | ||
{ | ||
label: _("Cancel"), | ||
action: () => { | ||
this.close(global.get_current_time()); | ||
} | ||
} | ||
]); | ||
} | ||
|
||
/* | ||
* Calculate the padding that is added to the text field | ||
*/ | ||
_calcEntryHeightDiff() { | ||
const textBackup = this.entry.get_text(); | ||
this.entry.set_text(""); | ||
|
||
let width = this.entry.get_width(); | ||
const themeNode = this.entry.get_theme_node(); | ||
width = themeNode.adjust_for_width(width); | ||
|
||
const [minHeight, natHeight] = this.entry.clutter_text.get_preferred_height(width); | ||
const [minHeightAdjusted, natHeightAdjusted] = themeNode.adjust_preferred_height(minHeight, natHeight); | ||
|
||
this.entryHeightDiff = natHeightAdjusted - natHeight; | ||
|
||
this.entry.set_text(textBackup); | ||
} | ||
|
||
/* | ||
* Resize the text field | ||
*/ | ||
_resizeEntry() { | ||
let width = this.entry.get_width(); | ||
const themeNode = this.entry.get_theme_node(); | ||
width = themeNode.adjust_for_width(width); | ||
|
||
const [minHeight, natHeight] = this.entry.clutter_text.get_preferred_height(width); | ||
const height = natHeight + this.entryHeightDiff; | ||
|
||
if (this._prevEntryHeight != height) { | ||
this._prevEntryHeight = height; | ||
|
||
this.entry.set_height(height); | ||
} | ||
} | ||
|
||
// | ||
// Events | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* The OK button was pressed | ||
*/ | ||
_onOK() { | ||
this.close(global.get_current_time()); | ||
this._callback(this.entry.get_text()); | ||
|
||
this.entry.set_text(""); | ||
} | ||
|
||
// | ||
// Overrides | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* Overridden so the text field's padding will be calculated as soon as | ||
* the dialog is displayed (it doesn't work correctly if it is hidden) | ||
*/ | ||
open(timestamp) { | ||
ModalDialog.ModalDialog.prototype.open.call(this, timestamp); | ||
|
||
this._calcEntryHeightDiff(); | ||
global.stage.set_key_focus(this.entry); | ||
} | ||
} | ||
); |
42 changes: 42 additions & 0 deletions
42
[email protected]/files/[email protected]/6.4/GPasteNotInstalledDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const ModalDialog = imports.ui.modalDialog; | ||
const St = imports.gi.St; | ||
const GObject = imports.gi.GObject; | ||
|
||
const _ = require('./__init__')._; | ||
|
||
// ------------------------------------------------------------------------------------------------------ | ||
var GPasteNotInstalledDialog = GObject.registerClass( | ||
class GPasteNotInstalledDialog extends ModalDialog.ModalDialog { | ||
_init(callback) { | ||
super._init({ styleClass: 'gpaste__not-found-dialog', destroyOnClose: false }); | ||
|
||
this.contentLayout.add(new St.Label({ text: _("GPaste is not installed. Please install the necessary packages and then restart Cinnamon for this applet to start working.") })); | ||
this.contentLayout.add_style_class_name('gpaste__not-found-dialog__content'); | ||
|
||
this.setButtons([ | ||
{ | ||
label: _("OK"), | ||
action: () => this._onOK() | ||
} | ||
]); | ||
} | ||
|
||
// | ||
// Events | ||
// --------------------------------------------------------------------------------- | ||
|
||
/* | ||
* The OK button was pressed | ||
*/ | ||
_onOK() { | ||
this.close(global.get_current_time()); | ||
} | ||
|
||
open(timestamp) { | ||
ModalDialog.ModalDialog.prototype.open.call(this, timestamp); | ||
|
||
this._calcEntryHeightDiff(); | ||
global.stage.set_key_focus(this.entry); | ||
} | ||
} | ||
); |
Oops, something went wrong.