Skip to content

Commit

Permalink
[GTK4 Prep] Moved Granite.Widgets.SourceList source code into codebase (
Browse files Browse the repository at this point in the history
#1419)

* Granite.Widgets.SourceList is now an internal Code widget

* Use internal value for SourceList css class

* Move SourceList widgets into new 'SourceList' directory

* Use updated style classes in SourceList cell renderers

---------

Co-authored-by: Jeremy Wootten <[email protected]>
  • Loading branch information
colinkiama and jeremypw authored Jan 27, 2024
1 parent 5aff3f7 commit afcc098
Show file tree
Hide file tree
Showing 13 changed files with 3,203 additions and 46 deletions.
16 changes: 8 additions & 8 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* SourceList that displays folders and their contents.
*/
public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.PaneSwitcher {
public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.PaneSwitcher {
private GLib.Settings settings;
private Scratch.Services.GitManager git_manager;

Expand Down Expand Up @@ -60,7 +60,7 @@ public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.P
});
}

private void on_item_selected (Granite.Widgets.SourceList.Item? item) {
private void on_item_selected (Code.Widgets.SourceList.Item? item) {
// This is a workaround for SourceList silliness: you cannot remove an item
// without it automatically selecting another one.
if (ignore_next_select) {
Expand All @@ -82,8 +82,8 @@ public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.P
public void open_folder (File folder) {
if (is_open (folder)) {
var existing = find_path (root, folder.path);
if (existing is Granite.Widgets.SourceList.ExpandableItem) {
((Granite.Widgets.SourceList.ExpandableItem)existing).expanded = true;
if (existing is Code.Widgets.SourceList.ExpandableItem) {
((Code.Widgets.SourceList.ExpandableItem)existing).expanded = true;
}

return;
Expand Down Expand Up @@ -146,7 +146,7 @@ public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.P
}
}

private unowned Granite.Widgets.SourceList.Item? find_path (Granite.Widgets.SourceList.ExpandableItem list,
private unowned Code.Widgets.SourceList.Item? find_path (Code.Widgets.SourceList.ExpandableItem list,
string path,
bool expand = false) {
foreach (var item in list.children) {
Expand All @@ -156,8 +156,8 @@ public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.P
return (!)item;
}

if (item is Granite.Widgets.SourceList.ExpandableItem) {
var expander = item as Granite.Widgets.SourceList.ExpandableItem;
if (item is Code.Widgets.SourceList.ExpandableItem) {
var expander = item as Code.Widgets.SourceList.ExpandableItem;
if (!path.has_prefix (code_item.path)) {
continue;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public class Scratch.FolderManager.FileView : Granite.Widgets.SourceList, Code.P
return null;
}

public unowned Granite.Widgets.SourceList.Item? expand_to_path (string path) {
public unowned Code.Widgets.SourceList.Item? expand_to_path (string path) {
return find_path (root, path, true);
}

Expand Down
26 changes: 13 additions & 13 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Scratch.FolderManager {
private GLib.FileMonitor monitor;
private bool children_loaded = false;
private bool has_dummy;
private Granite.Widgets.SourceList.Item dummy; /* Blank item for expanded empty folders */
private Code.Widgets.SourceList.Item dummy; /* Blank item for expanded empty folders */

public FolderItem (File file, FileView view) requires (file.is_valid_directory) {
Object (file: file, view: view);
Expand All @@ -40,9 +40,9 @@ namespace Scratch.FolderManager {
construct {
selectable = false;

dummy = new Granite.Widgets.SourceList.Item ("");
dummy = new Code.Widgets.SourceList.Item ("");
// Must add dummy on unexpanded folders else expander will not show
((Granite.Widgets.SourceList.ExpandableItem)this).add (dummy);
((Code.Widgets.SourceList.ExpandableItem)this).add (dummy);
has_dummy = true;

toggled.connect (on_toggled);
Expand All @@ -63,7 +63,7 @@ namespace Scratch.FolderManager {
file.children.size > 0) {

foreach (var child in file.children) {
Granite.Widgets.SourceList.Item item = null;
Code.Widgets.SourceList.Item item = null;
if (child.is_valid_directory ()) {
item = new FolderItem (child, view);
} else if (child.is_valid_textfile) {
Expand Down Expand Up @@ -237,24 +237,24 @@ namespace Scratch.FolderManager {
}
}

private void remove_badge (Granite.Widgets.SourceList.Item item) {
private void remove_badge (Code.Widgets.SourceList.Item item) {
if (item is FolderItem) {
((FolderItem) item).remove_all_badges ();
}

item.badge = "";
}

public new void add (Granite.Widgets.SourceList.Item item) {
public new void add (Code.Widgets.SourceList.Item item) {
if (has_dummy && n_children == 1) {
((Granite.Widgets.SourceList.ExpandableItem)this).remove (dummy);
((Code.Widgets.SourceList.ExpandableItem)this).remove (dummy);
has_dummy = false;
}

((Granite.Widgets.SourceList.ExpandableItem)this).add (item);
((Code.Widgets.SourceList.ExpandableItem)this).add (item);
}

public new void remove (Granite.Widgets.SourceList.Item item) {
public new void remove (Code.Widgets.SourceList.Item item) {
if (item is FolderItem) {
var folder = (FolderItem)item;
foreach (var child in folder.children) {
Expand All @@ -263,16 +263,16 @@ namespace Scratch.FolderManager {
}

view.ignore_next_select = true;
((Granite.Widgets.SourceList.ExpandableItem)this).remove (item);
((Code.Widgets.SourceList.ExpandableItem)this).remove (item);
// Add back dummy if empty unless we are removing a rename item
if (!(item is RenameItem || has_dummy || n_children > 0)) {
((Granite.Widgets.SourceList.ExpandableItem)this).add (dummy);
((Code.Widgets.SourceList.ExpandableItem)this).add (dummy);
has_dummy = true;
}
}

public new void clear () {
((Granite.Widgets.SourceList.ExpandableItem)this).clear ();
((Code.Widgets.SourceList.ExpandableItem)this).clear ();
has_dummy = false;
}

Expand Down Expand Up @@ -436,7 +436,7 @@ namespace Scratch.FolderManager {
}
}

internal class RenameItem : Granite.Widgets.SourceList.Item {
internal class RenameItem : Code.Widgets.SourceList.Item {
public bool is_folder { get; construct; }

public RenameItem (string name, bool is_folder) {
Expand Down
6 changes: 3 additions & 3 deletions src/FolderManager/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Scratch.FolderManager {
/**
* Common abstract class for file and folder items.
*/
public abstract class Item: Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable {
public abstract class Item: Code.Widgets.SourceList.ExpandableItem, Code.Widgets.SourceListSortable {
public File file { get; construct; }

public FileView view { get; construct; }
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace Scratch.FolderManager {
file.trash ();
}

public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) {
public int compare (Code.Widgets.SourceList.Item a, Code.Widgets.SourceList.Item b) {
if (a is RenameItem) {
return -1;
} else if (b is RenameItem) {
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace Scratch.FolderManager {
}
}

public ProjectFolderItem? get_root_folder (Granite.Widgets.SourceList.ExpandableItem? start = null) {
public ProjectFolderItem? get_root_folder (Code.Widgets.SourceList.ExpandableItem? start = null) {
if (start == null) {
start = this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SymbolPane/C/CtagsSymbol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

public class Scratch.Services.CtagsSymbol : Granite.Widgets.SourceList.ExpandableItem {
public class Scratch.Services.CtagsSymbol : Code.Widgets.SourceList.ExpandableItem {
public Scratch.Services.Document doc { get; construct set; }
public int line { get; construct set; }

Expand Down
8 changes: 4 additions & 4 deletions src/SymbolPane/C/CtagsSymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin

private async void parse_output (GLib.Subprocess subprocess) {
var parent_dependent = new Gee.LinkedList<CtagsSymbolIter> ();
var new_root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
var new_root = new Code.Widgets.SourceList.ExpandableItem (_("Symbols"));

var datainput = new GLib.DataInputStream (subprocess.get_stdout_pipe ());
try {
Expand Down Expand Up @@ -206,7 +206,7 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin
});
}

private void destroy_root (Granite.Widgets.SourceList.ExpandableItem to_destroy) {
private void destroy_root (Code.Widgets.SourceList.ExpandableItem to_destroy) {
var children = iterate_children (to_destroy);
to_destroy.clear ();
foreach (var item in children) {
Expand All @@ -218,15 +218,15 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin
}
}

private Gee.TreeSet<CtagsSymbol> iterate_children (Granite.Widgets.SourceList.ExpandableItem parent) {
private Gee.TreeSet<CtagsSymbol> iterate_children (Code.Widgets.SourceList.ExpandableItem parent) {
var result = new Gee.TreeSet<CtagsSymbol> ();
foreach (var child in parent.children) {
result.add_all (iterate_children ((CtagsSymbol)child));
}
return result;
}

CtagsSymbol? find_existing (string name, Granite.Widgets.SourceList.ExpandableItem parent) {
CtagsSymbol? find_existing (string name, Code.Widgets.SourceList.ExpandableItem parent) {
CtagsSymbol match = null;
foreach (var child in parent.children) {
var child_symbol = child as CtagsSymbol;
Expand Down
8 changes: 4 additions & 4 deletions src/SymbolPane/SymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
public abstract class Scratch.Services.SymbolOutline : Object {
public Scratch.Services.Document doc { get; construct; }

protected Granite.Widgets.SourceList store;
protected Granite.Widgets.SourceList.ExpandableItem root;
protected Code.Widgets.SourceList store;
protected Code.Widgets.SourceList.ExpandableItem root;
protected Gtk.CssProvider source_list_style_provider;
public Gtk.Widget get_widget () { return store; }
public abstract void parse_symbols ();

construct {
store = new Granite.Widgets.SourceList ();
root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
store = new Code.Widgets.SourceList ();
root = new Code.Widgets.SourceList.ExpandableItem (_("Symbols"));
store.root.add (root);

set_up_css ();
Expand Down
2 changes: 1 addition & 1 deletion src/SymbolPane/Vala/ValaComparisonHelper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

namespace Scratch.Services.ValaComparison {
int sort_function (Granite.Widgets.SourceList.Item str1, Granite.Widgets.SourceList.Item str2) {
int sort_function (Code.Widgets.SourceList.Item str1, Code.Widgets.SourceList.Item str2) {
if (!(str1 is ValaSymbolItem && str2 is ValaSymbolItem))
return str1.name.collate (str2.name);
var a = (ValaSymbolItem) str1;
Expand Down
4 changes: 2 additions & 2 deletions src/SymbolPane/Vala/ValaSymbolItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

public class Scratch.Services.ValaSymbolItem : Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListSortable {
public class Scratch.Services.ValaSymbolItem : Code.Widgets.SourceList.ExpandableItem, Code.Widgets.SourceListSortable {
public Vala.Symbol symbol { get; set; }

public ValaSymbolItem (Vala.Symbol symbol) {
Expand All @@ -34,7 +34,7 @@ public class Scratch.Services.ValaSymbolItem : Granite.Widgets.SourceList.Expand
debug ("Destroy Vala symbol");
}

public int compare (Granite.Widgets.SourceList.Item a, Granite.Widgets.SourceList.Item b) {
public int compare (Code.Widgets.SourceList.Item a, Code.Widgets.SourceList.Item b) {
return ValaComparison.sort_function (a, b);
}

Expand Down
20 changes: 10 additions & 10 deletions src/SymbolPane/Vala/ValaSymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
var root_children = store.root.children; // Keep reference to children for later destruction
store.root.clear (); // This does not destroy children but disconnects signals - avoids terminal warnings
foreach (var child in root_children) { // Destroy items after clearing list to avoid memory leak
destroy_all_children ((Granite.Widgets.SourceList.ExpandableItem)child);
destroy_all_children ((Code.Widgets.SourceList.ExpandableItem)child);
}

store.root.add (new_root);
Expand All @@ -93,27 +93,27 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
});
}

private void destroy_all_children (Granite.Widgets.SourceList.ExpandableItem parent) {
private void destroy_all_children (Code.Widgets.SourceList.ExpandableItem parent) {
foreach (var child in parent.children) {
remove (child, parent);
}
}

private new void remove (Granite.Widgets.SourceList.Item item, Granite.Widgets.SourceList.ExpandableItem parent) {
if (item is Granite.Widgets.SourceList.ExpandableItem) {
destroy_all_children ((Granite.Widgets.SourceList.ExpandableItem)item);
private new void remove (Code.Widgets.SourceList.Item item, Code.Widgets.SourceList.ExpandableItem parent) {
if (item is Code.Widgets.SourceList.ExpandableItem) {
destroy_all_children ((Code.Widgets.SourceList.ExpandableItem)item);
}

parent.remove (item);
}

private Granite.Widgets.SourceList.ExpandableItem construct_tree (GLib.Cancellable cancellable) {
private Code.Widgets.SourceList.ExpandableItem construct_tree (GLib.Cancellable cancellable) {
var fields = resolver.get_properties_fields ();
var symbols = resolver.get_symbols ();
// Remove fake fields created by the vala parser.
symbols.remove_all (fields);

var new_root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
var new_root = new Code.Widgets.SourceList.ExpandableItem (_("Symbols"));
foreach (var symbol in symbols) {
if (cancellable.is_cancelled ())
break;
Expand All @@ -130,8 +130,8 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
return new_root;
}

private ValaSymbolItem construct_child (Vala.Symbol symbol, Granite.Widgets.SourceList.ExpandableItem given_parent, GLib.Cancellable cancellable) {
Granite.Widgets.SourceList.ExpandableItem parent;
private ValaSymbolItem construct_child (Vala.Symbol symbol, Code.Widgets.SourceList.ExpandableItem given_parent, GLib.Cancellable cancellable) {
Code.Widgets.SourceList.ExpandableItem parent;
if (symbol.scope.parent_scope.owner.name == null)
parent = given_parent;
else
Expand Down Expand Up @@ -194,7 +194,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
return tree_child;
}

ValaSymbolItem? find_existing (Vala.Symbol symbol, Granite.Widgets.SourceList.ExpandableItem parent, GLib.Cancellable cancellable) {
ValaSymbolItem? find_existing (Vala.Symbol symbol, Code.Widgets.SourceList.ExpandableItem parent, GLib.Cancellable cancellable) {
ValaSymbolItem match = null;
foreach (var _child in parent.children) {
if (cancellable.is_cancelled ())
Expand Down
Loading

0 comments on commit afcc098

Please sign in to comment.