Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trash and Removable Device Icons #677

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

UUID = dash-to-dock@micxgx.gmail.com
BASE_MODULES = extension.js stylesheet.css metadata.json COPYING README.md
EXTRA_MODULES = dash.js docking.js appIcons.js appIconIndicators.js launcherAPI.js windowPreview.js intellihide.js prefs.js theming.js utils.js Settings.ui
EXTRA_MODULES = dash.js docking.js appIcons.js appIconIndicators.js fileManager1API.js launcherAPI.js locations.js windowPreview.js intellihide.js prefs.js theming.js utils.js Settings.ui
EXTRA_MEDIA = logo.svg glossy.svg highlight_stacked_bg.svg highlight_stacked_bg_h.svg
TOLOCALIZE = prefs.js appIcons.js
TOLOCALIZE = prefs.js appIcons.js locations.js
MSGSRC = $(wildcard po/*.po)
ifeq ($(strip $(DESTDIR)),)
INSTALLTYPE = local
Expand Down
84 changes: 84 additions & 0 deletions Settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,90 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="listboxrow18">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="shrink_dash4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkSwitch" id="show_trash_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="shrink_dash_label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Show trash can</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow" id="listboxrow19">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="shrink_dash5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkSwitch" id="show_mounts_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="shrink_dash_label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Show mounted volumes and devices</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
Expand Down
2 changes: 1 addition & 1 deletion appIconIndicators.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var RunningIndicatorBase = class DashToDock_RunningIndicatorBase extends Indicat

// In the case of workspace isolation, we need to hide the dots of apps with
// no windows in the current workspace
if (this._source.app.state != Shell.AppState.STOPPED && this._nWindows > 0)
if ((this._source.app.state != Shell.AppState.STOPPED || this._source.isLocation()) && this._nWindows > 0)
this._isRunning = true;
else
this._isRunning = false;
Expand Down
47 changes: 39 additions & 8 deletions appIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Util = imports.misc.util;
const Workspace = imports.ui.workspace;

const Me = imports.misc.extensionUtils.getCurrentExtension();
const Docking = Me.imports.docking;
const Utils = Me.imports.utils;
const WindowPreview = Me.imports.windowPreview;
const AppIconIndicators = Me.imports.appIconIndicators;
Expand Down Expand Up @@ -87,6 +88,9 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
this.remoteModel = remoteModel;
this._indicator = null;

let appInfo = app.get_app_info();
this._location = appInfo ? appInfo.get_string('XdtdUri') : null;

this._updateIndicatorStyle();

// Monitor windows-changes instead of app state.
Expand Down Expand Up @@ -131,6 +135,14 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
]);
}, this);

if (this._location) {
this._signalsHandler.add([
Docking.DockManager.getDefault().fm1Client,
'windows-changed',
this.onWindowsChanged.bind(this)
]);
}

this._dtdSettings.connect('changed::scroll-action', () => {
this._optionalScrollCycleWindows();
});
Expand Down Expand Up @@ -277,7 +289,7 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
[rect.x, rect.y] = this.actor.get_transformed_position();
[rect.width, rect.height] = this.actor.get_transformed_size();

let windows = this.app.get_windows();
let windows = this.getWindows();
if (this._dtdSettings.get_boolean('multi-monitor')){
let monitorIndex = this.monitorIndex;
windows = windows.filter(function(w) {
Expand Down Expand Up @@ -386,7 +398,7 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
// We check if the app is running, and that the # of windows is > 0 in
// case we use workspace isolation.
let windows = this.getInterestingWindows();
let appIsRunning = this.app.state == Shell.AppState.RUNNING
let appIsRunning = (this.app.state == Shell.AppState.RUNNING || this.isLocation())
&& windows.length > 0;

// Some action modes (e.g. MINIMIZE_OR_OVERVIEW) require overview to remain open
Expand Down Expand Up @@ -591,7 +603,7 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
// Try to manually activate the first window. Otherwise, when the app is activated by
// switching to a different workspace, a launch spinning icon is shown and disappers only
// after a timeout.
let windows = this.app.get_windows();
let windows = this.getWindows();
if (windows.length > 0)
Main.activateWindow(windows[0])
else
Expand Down Expand Up @@ -746,10 +758,19 @@ var MyAppIcon = class DashToDock_AppIcon extends AppDisplay.AppIcon {
return false;
}

getWindows() {
return getWindows(this.app, this._location);
}

// Filter out unnecessary windows, for instance
// nautilus desktop window.
getInterestingWindows() {
return getInterestingWindows(this.app, this._dtdSettings, this.monitorIndex);
return getInterestingWindows(this.app, this._dtdSettings, this.monitorIndex, this._location);
}

// Does the Icon represent a location rather than an App
isLocation() {
return this._location != null;
}
};
/**
Expand Down Expand Up @@ -832,7 +853,8 @@ const MyAppIconMenu = class DashToDock_MyAppIconMenu extends AppDisplay.AppIconM
});
}

let canFavorite = global.settings.is_writable('favorite-apps');
let canFavorite = global.settings.is_writable('favorite-apps') &&
!this._source.isLocation();

if (canFavorite) {
this._appendSeparator();
Expand All @@ -854,7 +876,8 @@ const MyAppIconMenu = class DashToDock_MyAppIconMenu extends AppDisplay.AppIconM
}
}

if (Shell.AppSystem.get_default().lookup_app('org.gnome.Software.desktop')) {
if (Shell.AppSystem.get_default().lookup_app('org.gnome.Software.desktop') &&
!this._source.isLocation()) {
this._appendSeparator();
let item = this._appendMenuItem(_("Show Details"));
item.connect('activate', () => {
Expand Down Expand Up @@ -976,10 +999,18 @@ const MyAppIconMenu = class DashToDock_MyAppIconMenu extends AppDisplay.AppIconM
};
Signals.addSignalMethods(MyAppIconMenu.prototype);

function getWindows(app, location) {
if (location != null && Docking.DockManager.getDefault().fm1Client) {
return Docking.DockManager.getDefault().fm1Client.getWindows(location);
} else {
return app.get_windows();
}
}

// Filter out unnecessary windows, for instance
// nautilus desktop window.
function getInterestingWindows(app, settings, monitorIndex) {
let windows = app.get_windows().filter(function(w) {
function getInterestingWindows(app, settings, monitorIndex, location) {
let windows = getWindows(app, location).filter(function(w) {
return !w.skip_taskbar;
});

Expand Down
31 changes: 31 additions & 0 deletions dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const AppIcons = Me.imports.appIcons;
const Locations = Me.imports.locations;

let DASH_ANIMATION_TIME = Dash.DASH_ANIMATION_TIME;
let DASH_ITEM_LABEL_HIDE_TIME = Dash.DASH_ITEM_LABEL_HIDE_TIME;
Expand Down Expand Up @@ -743,6 +744,36 @@ var MyDash = class DashToDock_MyDash {
}
}

if (this._dtdSettings.get_boolean('show-mounts')) {
if (!this._removables) {
this._removables = new Locations.Removables();
this._signalsHandler.addWithLabel('show-mounts',
[ this._removables,
'changed',
this._queueRedisplay.bind(this) ]);
}
Array.prototype.push.apply(newApps, this._removables.getApps());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just calling newApps.push(this._removables.getApps()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time I wrote the original patch, the js version in ghome-shell didn't directly support calling push and this was the way you had to do it. I'm not surprised that it's directly callable now, but I wouldn't change it until it was clear what the minimum supported gnome-shell version is.

} else if (this._removables) {
this._signalsHandler.removeWithLabel('show-mounts');
this._removables.destroy();
this._removables = null;
philipl marked this conversation as resolved.
Show resolved Hide resolved
}

if (this._dtdSettings.get_boolean('show-trash')) {
if (!this._trash) {
this._trash = new Locations.Trash();
this._signalsHandler.addWithLabel('show-trash',
[ this._trash,
'changed',
this._queueRedisplay.bind(this) ]);
}
newApps.push(this._trash.getApp());
} else if (this._trash) {
this._signalsHandler.removeWithLabel('show-trash');
this._trash.destroy();
this._trash = null;
philipl marked this conversation as resolved.
Show resolved Hide resolved
}

// Figure out the actual changes to the list of items; we iterate
// over both the list of items currently in the dash and the list
// of items expected there, and collect additions and removals.
Expand Down
53 changes: 52 additions & 1 deletion docking.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Intellihide = Me.imports.intellihide;
const Theming = Me.imports.theming;
const MyDash = Me.imports.dash;
const LauncherAPI = Me.imports.launcherAPI;
const FileManager1API = Me.imports.fileManager1API;

const DOCK_DWELL_CHECK_INTERVAL = 100;

Expand Down Expand Up @@ -481,6 +482,16 @@ var DockedDash = class DashToDock {
this._settings,
'changed::show-favorites',
() => { this.dash.resetAppIcons(); }
], [
this._settings,
'changed::show-trash',
() => { this.dash.resetAppIcons(); },
Utils.SignalsHandlerFlags.CONNECT_AFTER,
], [
this._settings,
'changed::show-mounts',
() => { this.dash.resetAppIcons(); },
Utils.SignalsHandlerFlags.CONNECT_AFTER
], [
this._settings,
'changed::show-running',
Expand Down Expand Up @@ -1566,6 +1577,8 @@ var DockManager = class DashToDock_DockManager {
this._remoteModel = new LauncherAPI.LauncherEntryRemoteModel();
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.dash-to-dock');
this._oldDash = Main.overview._dash;
this._ensureFileManagerClient();

/* Array of all the docks created */
this._allDocks = [];
this._createDocks();
Expand All @@ -1578,6 +1591,32 @@ var DockManager = class DashToDock_DockManager {
this._bindSettingsChanges();
}

static getDefault() {
return Me.imports.extension.dockManager
}

static get settings() {
return DockManager.getDefault()._settings;
}

get fm1Client() {
return this._fm1Client;
}

_ensureFileManagerClient() {
let supportsLocations = ['show-trash', 'show-mounts'].some((s) => {
return this._settings.get_boolean(s);
});

if (supportsLocations) {
if (!this._fm1Client)
this._fm1Client = new FileManager1API.FileManager1Client();
} else if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
}

_toggle() {
this._deleteDocks();
this._createDocks();
Expand Down Expand Up @@ -1611,7 +1650,15 @@ var DockManager = class DashToDock_DockManager {
this._settings,
'changed::dock-fixed',
this._adjustPanelCorners.bind(this)
]);
], [
this._settings,
'changed::show-trash',
() => this._ensureFileManagerClient()
], [
this._settings,
'changed::show-mounts',
() => this._ensureFileManagerClient()
], );
}

_createDocks() {
Expand Down Expand Up @@ -1823,6 +1870,10 @@ var DockManager = class DashToDock_DockManager {
this._deleteDocks();
this._revertPanelCorners();
this._restoreDash();
if (this._fm1Client) {
this._fm1Client.destroy();
this._fm1Client = null;
}
this._remoteModel.destroy();
}

Expand Down
Loading