Replace type-checks with simple cast where possible

This commit is contained in:
Rico Tzschichholz 2014-06-22 19:54:46 +02:00
parent e1097f5882
commit f3a3c848db
6 changed files with 32 additions and 30 deletions

View File

@ -270,7 +270,7 @@ namespace Gala
public void remove_window (Meta.Window window, bool animate = true)
{
foreach (var child in get_children ()) {
var w = child as WindowIcon;
unowned WindowIcon w = (WindowIcon) child;
if (w.window == window) {
if (animate) {
w.set_easing_mode (AnimationMode.LINEAR);
@ -313,7 +313,7 @@ namespace Gala
// single icon => big icon
if (n_windows == 1) {
var icon = get_child_at_index (0) as WindowIcon;
var icon = (WindowIcon) get_child_at_index (0);
icon.place (0, 0, 64);
return false;
@ -402,7 +402,7 @@ namespace Gala
var x = x_offset;
var y = y_offset;
for (var i = 0; i < n_windows; i++) {
var window = get_child_at_index (i) as WindowIcon;
var window = (WindowIcon) get_child_at_index (i);
// draw an ellipsis at the 9th position if we need one
if (show_ellipsis && i == 8) {

View File

@ -37,7 +37,7 @@ namespace Gala
unowned List<Workspace> existing_workspaces = screen.get_workspaces ();
foreach (var child in get_children ()) {
var icon_group = child as IconGroup;
unowned IconGroup icon_group = (IconGroup) child;
// we don't use meta_workspace_index() here because it crashes
// the wm if the workspace has already been removed. This could

View File

@ -83,7 +83,7 @@ namespace Gala
unowned List<Workspace> existing_workspaces = screen.get_workspaces ();
foreach (var child in workspaces.get_children ()) {
var workspace_clone = child as WorkspaceClone;
unowned WorkspaceClone workspace_clone = (WorkspaceClone) child;
if (existing_workspaces.index (workspace_clone.workspace) < 0) {
workspace_clone.window_selected.disconnect (window_selected);
workspace_clone.selected.disconnect (activate_workspace);
@ -157,7 +157,7 @@ namespace Gala
var active_x = 0.0f;
foreach (var child in workspaces.get_children ()) {
var workspace_clone = child as WorkspaceClone;
unowned WorkspaceClone workspace_clone = (WorkspaceClone) child;
var index = workspace_clone.workspace.index ();
var dest_x = index * (workspace_clone.width - 150);
@ -210,8 +210,7 @@ namespace Gala
unowned List<Meta.Workspace> existing_workspaces = screen.get_workspaces ();
foreach (var child in workspaces.get_children ()) {
var clone = child as WorkspaceClone;
unowned WorkspaceClone clone = (WorkspaceClone) child;
if (existing_workspaces.index (clone.workspace) < 0) {
workspace = clone;
break;
@ -286,7 +285,7 @@ namespace Gala
WorkspaceClone get_active_workspace_clone ()
{
foreach (var child in workspaces.get_children ()) {
var workspace_clone = child as WorkspaceClone;
unowned WorkspaceClone workspace_clone = (WorkspaceClone) child;
if (workspace_clone.workspace == screen.get_active_workspace ()) {
return workspace_clone;
}
@ -332,7 +331,7 @@ namespace Gala
WorkspaceClone? active_workspace = null;
var active = screen.get_active_workspace ();
foreach (var child in workspaces.get_children ()) {
var workspace = child as WorkspaceClone;
unowned WorkspaceClone workspace = (WorkspaceClone) child;
if (workspace.workspace == active) {
active_workspace = workspace;
break;
@ -344,10 +343,11 @@ namespace Gala
update_positions (false);
foreach (var child in workspaces.get_children ()) {
unowned WorkspaceClone workspace = (WorkspaceClone) child;
if (opening)
(child as WorkspaceClone).open ();
workspace.open ();
else
(child as WorkspaceClone).close ();
workspace.close ();
}
if (!opening) {

View File

@ -365,10 +365,9 @@ namespace Gala
void drag_destination_crossed (Actor destination, bool hovered)
{
if (!(destination is IconGroup))
return;
var icon_group = destination as IconGroup;
if (icon_group == null)
return;
if (icon_group.workspace == window.get_workspace ()
&& window.get_monitor () == window.get_screen ().get_primary_monitor ())
@ -401,11 +400,11 @@ namespace Gala
Meta.Workspace workspace = null;
if (destination is IconGroup) {
workspace = (destination as IconGroup).workspace;
workspace = ((IconGroup) destination).workspace;
} else if (destination is FramedBackground) {
workspace = (destination.get_parent () as WorkspaceClone).workspace;
workspace = ((WorkspaceClone) destination.get_parent ()).workspace;
} else if (destination is MonitorClone) {
window.move_to_monitor ((destination as MonitorClone).monitor);
window.move_to_monitor (((MonitorClone) destination).monitor);
unmanaged ();
return;
}

View File

@ -59,7 +59,7 @@ namespace Gala
// make sure our windows are where they belong in case they were moved
// while were closed.
foreach (var window in get_children ()) {
(window as TiledWindow).transition_to_original_state (false);
((TiledWindow) window).transition_to_original_state (false);
}
restack ();
@ -77,8 +77,9 @@ namespace Gala
}
set {
foreach (var child in get_children ()) {
if ((child as TiledWindow).window == value) {
_current_window = child as TiledWindow;
unowned TiledWindow tiled_window = (TiledWindow) child;
if (tiled_window.window == value) {
_current_window = tiled_window;
break;
}
}
@ -102,7 +103,7 @@ namespace Gala
var children = get_children ();
var added = false;
foreach (var child in children) {
if (stacking_order.get ((int)(child as TiledWindow).window.get_stable_sequence ()) < new_seq) {
if (stacking_order.get ((int)((TiledWindow) child).window.get_stable_sequence ()) < new_seq) {
insert_child_below (new_window, child);
added = true;
break;
@ -120,7 +121,7 @@ namespace Gala
public void remove_window (Window window)
{
foreach (var child in get_children ()) {
if ((child as TiledWindow).window == window) {
if (((TiledWindow) child).window == window) {
remove_child (child);
break;
}
@ -137,6 +138,8 @@ namespace Gala
void window_destroyed (Actor actor)
{
var window = actor as TiledWindow;
if (window == null)
return;
window.destroy.disconnect (window_destroyed);
window.selected.disconnect (window_selected_cb);
@ -153,8 +156,8 @@ namespace Gala
foreach (var child1 in get_children ()) {
var i = 0;
foreach (var child2 in get_children ()) {
int index1 = stacking_order.get ((int)(child1 as TiledWindow).window.get_stable_sequence ());
int index2 = stacking_order.get ((int)(child2 as TiledWindow).window.get_stable_sequence ());
int index1 = stacking_order.get ((int)((TiledWindow) child1).window.get_stable_sequence ());
int index2 = stacking_order.get ((int)((TiledWindow) child2).window.get_stable_sequence ());
if (index1 < index2) {
set_child_at_index (child1, i);
i++;
@ -171,7 +174,7 @@ namespace Gala
var windows = new List<InternalUtils.TilableWindow?> ();
foreach (var child in get_children ()) {
var window = child as TiledWindow;
unowned TiledWindow window = (TiledWindow) child;
windows.prepend ({ window.window.get_outer_rect (), window });
}
windows.reverse ();
@ -189,7 +192,7 @@ namespace Gala
var window_positions = InternalUtils.calculate_grid_placement (area, windows);
foreach (var tilable in window_positions) {
var window = (TiledWindow)tilable.id;
unowned TiledWindow window = (TiledWindow) tilable.id;
window.take_slot (tilable.rect);
window.place_widgets (tilable.rect.width, tilable.rect.height);
}
@ -201,7 +204,7 @@ namespace Gala
return;
if (_current_window == null) {
_current_window = get_child_at_index (0) as TiledWindow;
_current_window = (TiledWindow) get_child_at_index (0);
return;
}
@ -212,7 +215,7 @@ namespace Gala
if (window == _current_window)
continue;
var window_rect = (window as TiledWindow).slot;
var window_rect = ((TiledWindow) window).slot;
switch (direction) {
case MotionDirection.LEFT:

View File

@ -168,7 +168,7 @@ namespace Gala
return;
foreach (var child in window_container.get_children ())
if ((child as TiledWindow).window == window)
if (((TiledWindow) child).window == window)
return;
window_container.add_window (window);