Add file browser from My GtkUI 4.4

This commit is contained in:
daleclack 2024-02-07 17:57:17 +08:00
parent 3344c78d43
commit 130ac7cc2b
18 changed files with 775 additions and 409 deletions

View File

@ -25,7 +25,8 @@ link_directories (${GTK_LIBRARY_DIRS})
set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp
src/core/MyItem.cpp src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp src/core/MyItem.cpp src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp
src/ui/AppView.cpp) src/ui/AppView.cpp src/file_app/FileColumnView.cpp src/file_app/FileGridView.cpp
src/file_app/FileWindow.cpp)
#Compile resources with GCR_CMake #Compile resources with GCR_CMake
@ -51,6 +52,7 @@ set(RESOURCE_LIST
folder-images.svg folder-images.svg
image_file.svg image_file.svg
gnome-fs-regular.svg gnome-fs-regular.svg
dialog-error.png
icons/16x16/actions/finder_audio.svg icons/16x16/actions/finder_audio.svg
icons/16x16/actions/finder-battery.svg icons/16x16/actions/finder-battery.svg
icons/16x16/actions/finder-computer.svg icons/16x16/actions/finder-computer.svg
@ -94,6 +96,12 @@ set(RESOURCE_LIST
icons/scalable/status/finder-find-dark.svg icons/scalable/status/finder-find-dark.svg
icons/scalable/status/file-app.svg icons/scalable/status/file-app.svg
icons/scalable/status/file-app_running.svg icons/scalable/status/file-app_running.svg
icons/scalable/status/filewin-delete.svg
icons/scalable/status/filewin-go-home.svg
icons/scalable/status/filewin-go-up.svg
icons/scalable/status/filewin-new.svg
icons/scalable/status/filewin-view-grid.svg
icons/scalable/status/filewin-view-list.svg
icons/scalable/status/display_prefs.svg icons/scalable/status/display_prefs.svg
icons/scalable/status/myrunner.svg icons/scalable/status/myrunner.svg
icons/scalable/status/image_app.svg icons/scalable/status/image_app.svg

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 16 16.001" xmlns="http://www.w3.org/2000/svg">
<path d="M7.5 0C6.4 0 5.355.32 5.355.32L5 .428v1.683A13.88 13.88 0 0 0 2.002 3L2 4H1v1h1l.004 9c0 .439.04.788.15 1.082.111.294.311.528.563.668.503.28 1.12.25 1.953.25h5.664c.833 0 1.45.03 1.953-.25.252-.14.45-.374.56-.668.11-.294.153-.643.153-1.082l-.002-8h-1L12 14c0 .376-.04.603-.088.729-.034.09-.078.129-.11.146-.173.097-.611.125-1.468.125H4.67c-.857 0-1.295-.028-1.469-.125a.267.267 0 0 1-.113-.146v-.002c-.046-.122-.084-.348-.084-.727v-.002L3 5h11V4h-1.002L13 3a13.855 13.855 0 0 0-3-.889V.449L9.67.33S8.757 0 7.5 0zm0 1c.89 0 1.29.155 1.5.22v.739a14.05 14.05 0 0 0-1.498-.084c-.502 0-1.003.032-1.502.086v-.734C6.266 1.157 6.772 1 7.5 1zM5 6v6h1V6zm2 0v6h1V6zm2 0v6h1V6z" fill="gray" font-family="Ubuntu" font-size="15" font-weight="400" letter-spacing="0" text-anchor="middle" word-spacing="0"/>
</svg>

After

Width:  |  Height:  |  Size: 875 B

View File

@ -0,0 +1,10 @@
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g fill="gray">
<path d="M14 5V3h-2.002z" overflow="visible"/>
<g font-weight="400">
<path d="M2 7v8h9v-1H3V6.333zm11.002-1L13 15h1V7z" font-family="Ubuntu" font-size="15" letter-spacing="0" text-anchor="middle" word-spacing="0"/>
<path d="M8 8.986a8.47 8.47 0 0 1 .607-.122 5.24 5.24 0 0 1 .872-.064c.295 0 .54.043.735.129.195.08.35.197.465.35.119.147.202.326.25.535.047.21.071.44.071.693V14.2H8z" font-family="Ubuntu" letter-spacing="0" text-anchor="end" word-spacing="0"/>
<path d="M8 .293L.146 8.146l.708.708L8 1.707l7.146 7.147.708-.708z" fill-rule="evenodd" font-family="sans-serif" overflow="visible" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none" white-space="normal"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M16 10c-.874-.69-1.757-1.397-2.656-2.008-1-.679-1.972-1.287-2.912-1.825C9.564 5.67 8.658 5.297 8 5c-.658.297-1.564.67-2.432 1.167a44.819 44.819 0 0 0-2.912 1.825C1.756 8.602.874 9.309 0 10h1.49c.524-.4 1.062-.837 1.625-1.222.71-.486 1.437-.942 2.18-1.37a39.201 39.201 0 0 1 2.5-1.285h.001L8 6.027l.203.096c.71.334 1.747.852 2.501 1.285.744.428 1.47.884 2.181 1.37.562.385 1.1.822 1.625 1.222H16z" fill="gray"/>
</svg>

After

Width:  |  Height:  |  Size: 489 B

View File

@ -0,0 +1,6 @@
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<g fill="gray" font-family="sans-serif" font-weight="400" white-space="normal">
<path d="M3.994 1c-1.258.015-2.179-.029-2.932.387a1.878 1.878 0 0 0-.84.996C.059 2.82 0 3.343 0 4v8c0 .658.058 1.179.223 1.617.164.439.463.79.84.998.752.416 1.673.37 2.931.385H10v-1H4c-1.26-.015-2.087-.06-2.453-.262-.183-.1-.29-.212-.387-.472C1.063 13.006 1 12.592 1 12V8c0-.592.064-1.006.162-1.266s.203-.371.387-.472c.367-.203 1.195-.247 2.459-.262h3.435l2.022-2h2.527c1.264.015 2.092.06 2.46.262.183.1.288.212.386.472.098.26.162.674.162 1.266v4h1V6c0-.658-.058-1.179-.223-1.617-.02-.055-.048-.104-.074-.154l-.027-.057a1.838 1.838 0 0 0-.738-.787c-.753-.416-1.674-.37-2.932-.385H8.967L6.945 1H3.996zm.012 1h2.53L8.3 3.746 7.033 5H3.994c-1.258.014-2.179-.03-2.932.385-.022.012-.04.03-.062.043V4c0-.592.062-1.006.16-1.266s.203-.371.387-.472c.366-.203 1.195-.247 2.459-.262z" overflow="visible" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:none;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-transform:none"/>
<path d="m13 11v2h-2v1h2v2h1v-2h2v-1h-2v-2z" overflow="visible" style="isolation:auto;mix-blend-mode:normal;text-decoration-color:#000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-transform:none"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M2 2v5h5V2zm7 0v5h5V2zM3 3h3v3H3zm7 0h3v3h-3zM2 9v5h5V9zm7 0v5h5V9zm-6 1h3v3H3zm7 0h3v3h-3z" fill="gray" font-family="sans-serif" font-weight="400" overflow="visible" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none" white-space="normal"/>
</svg>

After

Width:  |  Height:  |  Size: 639 B

View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M2 2v3h3V2zm1 1h1v1H3zm3 0v1h8V3zM2 6v3h3V6zm1 1h1v1H3zm3 0v1h8V7zm-4 3v3h3v-3zm1 1h1v1H3zm3 0v1h8v-1z" fill="gray" font-family="sans-serif" font-weight="400" overflow="visible" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none" white-space="normal"/>
</svg>

After

Width:  |  Height:  |  Size: 650 B

View File

@ -0,0 +1,15 @@
#pragma once
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE(FileWindow, file_window, FILE, WINDOW, GtkApplicationWindow)
FileWindow *file_window_new(GtkWindow *win);
void home_clicked(GtkWidget *widget, FileWindow *win);
GListModel *file_window_get_grid_model(FileWindow *self);
GListModel *file_window_get_column_model(FileWindow *self);
GtkWidget *file_window_get_folder_entry(FileWindow *self);

View File

@ -1,71 +0,0 @@
#pragma once
#include <gtkmm.h>
enum class ViewMode{
MODE_ICON,
MODE_LIST
};
class FileWindow : public Gtk::Window{
public:
FileWindow();
~FileWindow();
void go_home();
private:
//List Model
class ModelColumns : public Gtk::TreeModelColumnRecord{
public:
ModelColumns(){
add(m_col_path);add(m_col_display_name);add(m_col_pixbuf);add(m_col_is_dir);
}
Gtk::TreeModelColumn<Glib::ustring> m_col_path;
Gtk::TreeModelColumn<Glib::ustring> m_col_display_name;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_col_pixbuf;
Gtk::TreeModelColumn<bool> m_col_is_dir;
};
ModelColumns columns;
Gtk::TreeView m_treeview;
Gtk::IconView m_iconview;
Glib::RefPtr<Gtk::TreeSelection> m_selection;
Glib::RefPtr<Gtk::ListStore> m_liststore;
//File Proprties
Glib::RefPtr<Gdk::Pixbuf> file_pixbuf;
Glib::RefPtr<Gdk::Pixbuf> folder_pixbuf;
Glib::ustring parent_str,tmp_str;
ViewMode view_mode;
//Child Widgets
Gtk::Box vbox,btnbox,menubox;
Gtk::Toolbar m_toolbar,m_viewbar;
Gtk::ToolButton up_button,home_button,new_button,delete_button;
Gtk::ToolItem view_item,menu_item;
Gtk::ScrolledWindow m_sw;
Gtk::Button view_button;
Gtk::MenuButton menubtn;
Gtk::Stack stack;
Gtk::Popover popover;
Gtk::CheckButton show_hidden;
Gtk::InfoBar m_infobar;
Gtk::Label info_label;
Gtk::Entry entry_file;
//Initalize Functions
void fill_store();
void initalize_views();
int sort_func(const Gtk::TreeModel::iterator &a,const Gtk::TreeModel::iterator &b);
//Signal Handlers
void item_activated(const Gtk::TreePath &path);
void row_activated(const Gtk::TreePath &path,Gtk::TreeViewColumn * sel_column);
void btnup_clicked();
void btnhome_clicked();
void btnnew_clicked();
void btndel_clicked();
void btnview_clicked();
void infobar_response(int response_id);
void dialog_response(int response_id,Gtk::Dialog * dialog);
void btnhide_clicked();
};

View File

@ -0,0 +1,165 @@
#include "FileColumnView.h"
#include "GetFileType.h"
static void setup_fileicon_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Create Image for icon
GtkWidget *image;
image = gtk_image_new();
gtk_image_set_pixel_size(GTK_IMAGE(image), 24);
gtk_list_item_set_child(item, image);
}
static void bind_fileicon_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Get the image widget
GtkWidget *image;
image = gtk_list_item_get_child(item);
// Set image for column
GFileInfo *info = G_FILE_INFO(gtk_list_item_get_item(item));
gtk_image_set_from_gicon(GTK_IMAGE(image), g_file_info_get_icon(info));
}
static void setup_filename_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Create label to show list item
GtkWidget *label;
label = gtk_label_new(" ");
// Set the mode for ellipsize
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars(GTK_LABEL(label), 20);
// Add the label to the item
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_list_item_set_child(item, label);
}
static void bind_filename_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Get child for list item
GtkWidget *label;
label = gtk_list_item_get_child(item);
// Get string and add the string to the label
GFileInfo *info = G_FILE_INFO(gtk_list_item_get_item(item));
const char *display_name = g_file_info_get_display_name(info);
gtk_label_set_label(GTK_LABEL(label), display_name);
}
static void setup_filetype_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Create label to show list item
GtkWidget *label;
label = gtk_label_new(" ");
// Set the mode for ellipsize
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars(GTK_LABEL(label), 10);
// Add the label to the item
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_list_item_set_child(item, label);
}
static void bind_filetype_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Get child for list item
GtkWidget *label;
label = gtk_list_item_get_child(item);
// Get string and set it to the label
GFileInfo *info = G_FILE_INFO(gtk_list_item_get_item(item));
const char *type_str = g_file_info_get_content_type(info);
gtk_label_set_label(GTK_LABEL(label), type_str);
}
static void setup_filesize_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Create label to show list item
GtkWidget *label;
label = gtk_label_new(" ");
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_list_item_set_child(item, label);
}
static void bind_filesize_item(GtkListItemFactory *factory, GtkListItem *item)
{
// Get child for list item
GtkWidget *label;
label = gtk_list_item_get_child(item);
// Get string and set it to the label
GFileInfo *info = G_FILE_INFO(gtk_list_item_get_item(item));
const char *size_str = g_format_size(g_file_info_get_size(info));
gtk_label_set_label(GTK_LABEL(label), size_str);
}
static void listview_activated(GtkColumnView *view, guint position, FileWindow *win)
{
// Get the model
GtkSelectionModel *model = gtk_column_view_get_model(view);
GFileInfo *info = G_FILE_INFO(g_list_model_get_item(G_LIST_MODEL(model), position));
GtkDirectoryList *list = GTK_DIRECTORY_LIST(file_window_get_column_model(win));
// if the file type is directory, open the directory
if (check_directory(info))
{
// Get the file and set it to the GtkDirectoryList
GFile *file = G_FILE(g_file_info_get_attribute_object(info, "standard::file"));
gtk_directory_list_set_file(list, file);
// Update string in the entry for path
char *path = g_file_get_path(file);
gtk_editable_set_text(GTK_EDITABLE(file_window_get_folder_entry(win)), path);
// g_print("%s\n", path);
g_free(path);
}
g_object_unref(info);
}
GtkWidget *create_column_view(FileWindow *win)
{
// Create view
GListModel *model = file_window_get_column_model(win);
GtkSingleSelection *selection = gtk_single_selection_new(model);
GtkWidget *view = gtk_column_view_new(GTK_SELECTION_MODEL(selection));
// Create Factory for file icon
GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
g_signal_connect(factory, "setup", G_CALLBACK(setup_fileicon_item), NULL);
g_signal_connect(factory, "bind", G_CALLBACK(bind_fileicon_item), NULL);
GtkColumnViewColumn *column = gtk_column_view_column_new(" ", factory);
gtk_column_view_append_column(GTK_COLUMN_VIEW(view), column);
g_object_unref(column);
// Create Factory for file name
factory = gtk_signal_list_item_factory_new();
g_signal_connect(factory, "setup", G_CALLBACK(setup_filename_item), NULL);
g_signal_connect(factory, "bind", G_CALLBACK(bind_filename_item), NULL);
column = gtk_column_view_column_new("Name", factory);
gtk_column_view_append_column(GTK_COLUMN_VIEW(view), column);
g_object_unref(column);
// Create Factory for file type
factory = gtk_signal_list_item_factory_new();
g_signal_connect(factory, "setup", G_CALLBACK(setup_filetype_item), NULL);
g_signal_connect(factory, "bind", G_CALLBACK(bind_filetype_item), NULL);
column = gtk_column_view_column_new("Type", factory);
gtk_column_view_append_column(GTK_COLUMN_VIEW(view), column);
g_object_unref(column);
// Create Factory for file size
factory = gtk_signal_list_item_factory_new();
g_signal_connect(factory, "setup", G_CALLBACK(setup_filesize_item), NULL);
g_signal_connect(factory, "bind", G_CALLBACK(bind_filesize_item), NULL);
column = gtk_column_view_column_new("Size", factory);
gtk_column_view_append_column(GTK_COLUMN_VIEW(view), column);
g_object_unref(column);
// Link signals
g_signal_connect(view, "activate", G_CALLBACK(listview_activated), win);
return view;
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "FileWindow.h"
// Create column view widget
GtkWidget *create_column_view(FileWindow *win);

View File

@ -0,0 +1,99 @@
#include "FileGridView.h"
#include "GetFileType.h"
static void setup_grid_item(GtkListItemFactory *factory, GtkListItem *item)
{
GtkWidget *under_box, *info_box;
GtkWidget *image;
GtkWidget *label_filename, *label_filetype, *label_filesize;
// Create box for file icon and file info
under_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
info_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
image = gtk_image_new();
label_filename = gtk_label_new(" ");
label_filetype = gtk_label_new(" ");
label_filesize = gtk_label_new(" ");
// Make labels support ellipsize
gtk_label_set_ellipsize(GTK_LABEL(label_filename), PANGO_ELLIPSIZE_END);
gtk_label_set_ellipsize(GTK_LABEL(label_filetype), PANGO_ELLIPSIZE_END);
gtk_label_set_ellipsize(GTK_LABEL(label_filesize), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars(GTK_LABEL(label_filename), 20);
// Pack widgets
gtk_image_set_pixel_size(GTK_IMAGE(image), 48);
gtk_box_append(GTK_BOX(under_box), image);
gtk_box_append(GTK_BOX(info_box), label_filename);
gtk_box_append(GTK_BOX(info_box), label_filetype);
gtk_box_append(GTK_BOX(info_box), label_filesize);
gtk_box_append(GTK_BOX(under_box), info_box);
gtk_list_item_set_child(item, under_box);
}
static void bind_grid_item(GtkListItemFactory *factory, GtkListItem *item)
{
GtkWidget *under_box, *info_box;
GtkWidget *image;
GtkWidget *label_filename, *label_filetype, *label_filesize;
// Get Widgets
under_box = gtk_list_item_get_child(item);
image = gtk_widget_get_first_child(under_box);
info_box = gtk_widget_get_next_sibling(image);
label_filename = gtk_widget_get_first_child(info_box);
label_filetype = gtk_widget_get_next_sibling(label_filename);
label_filesize = gtk_widget_get_next_sibling(label_filetype);
// Get GFileInfo
GFileInfo *info = G_FILE_INFO(gtk_list_item_get_item(item));
// The icon for file or folders
gtk_image_set_from_gicon(GTK_IMAGE(image), g_file_info_get_icon(info));
// File name, content type and size
gtk_label_set_label(GTK_LABEL(label_filename), g_file_info_get_display_name(info));
gtk_label_set_label(GTK_LABEL(label_filetype), g_file_info_get_content_type(info));
gtk_label_set_label(GTK_LABEL(label_filesize), g_format_size(g_file_info_get_size(info)));
}
static void gridview_activate(GtkGridView *view, guint position, FileWindow *win)
{
// Get the model
GtkSelectionModel *model = gtk_grid_view_get_model(view);
GFileInfo *info = G_FILE_INFO(g_list_model_get_item(G_LIST_MODEL(model), position));
GtkDirectoryList *list = GTK_DIRECTORY_LIST(file_window_get_grid_model(win));
// if the file type is directory, open the directory
if (check_directory(info))
{
// Get the file and set it to the GtkDirectoryList
GFile *file = G_FILE(g_file_info_get_attribute_object(info, "standard::file"));
gtk_directory_list_set_file(list, file);
// Update string in the entry for path
char *path = g_file_get_path(file);
gtk_editable_set_text(GTK_EDITABLE(file_window_get_folder_entry(win)), path);
g_free(path);
}
g_object_unref(info);
}
GtkWidget *create_grid_view(FileWindow *win)
{
// Get model for grid view
GListModel *model = file_window_get_grid_model(win);
// Create factory
GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
g_signal_connect(factory, "setup", G_CALLBACK(setup_grid_item), NULL);
g_signal_connect(factory, "bind", G_CALLBACK(bind_grid_item), NULL);
// Create view
GtkSingleSelection *selection = gtk_single_selection_new(model);
GtkWidget *grid_view = gtk_grid_view_new(GTK_SELECTION_MODEL(selection), factory);
// Link Signal
g_signal_connect(grid_view, "activate", G_CALLBACK(gridview_activate), win);
return grid_view;
}

View File

@ -0,0 +1,5 @@
#pragma once
#include "FileWindow.h"
GtkWidget *create_grid_view(FileWindow *win);

View File

@ -1,331 +0,0 @@
#include "FileWindow.hh"
#include <iostream>
FileWindow::FileWindow()
:parent_str("/"),
vbox(Gtk::Orientation::VERTICAL,5),
btnbox(Gtk::Orientation::HORIZONTAL,5),
menubox(Gtk::Orientation::VERTICAL,5),
show_hidden("Show hidden files")
{
//Initalize Window
set_default_size(650,400);
set_icon_name("file-app");
set_title("File Manager");
//Load Pixbufs
auto pixbuf1 = Gdk::Pixbuf::create_from_resource("/org/gtk/daleclack/gnome-fs-regular.svg");
file_pixbuf = pixbuf1->scale_simple(48,48,Gdk::InterpType::BILINEAR);
pixbuf1.reset();
pixbuf1 = Gdk::Pixbuf::create_from_resource("/org/gtk/daleclack/folder.svg");
folder_pixbuf = pixbuf1->scale_simple(48,48,Gdk::InterpType::BILINEAR);
pixbuf1.reset();
//Create Child Widgets
vbox.append(btnbox,Gtk::PACK_SHRINK);
add(vbox);
m_toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS);
btnbox.append(m_toolbar,Gtk::PACK_SHRINK);
btnbox.prepend(m_viewbar,Gtk::PACK_SHRINK);
//"Up" Button
up_button.set_icon_name("go-up");
up_button.set_is_important();
up_button.set_sensitive(false);
up_button.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btnup_clicked));
m_toolbar.insert(up_button,-1);
//"Home" Button
home_button.set_icon_name("go-home");
home_button.set_is_important();
home_button.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btnhome_clicked));
m_toolbar.insert(home_button,-1);
//"New Folder" Button
new_button.set_icon_name("folder-new");
new_button.set_is_important();
new_button.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btnnew_clicked));
m_toolbar.insert(new_button,-1);
//"Delete" Button
delete_button.set_icon_name("edit-delete");
delete_button.set_is_important();
delete_button.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btndel_clicked));
m_toolbar.insert(delete_button,-1);
//"View Mode" Button
view_item.add(view_button);
view_mode=ViewMode::MODE_ICON;
view_button.set_has_frame(false);
view_button.set_image_from_icon_name("view-grid-symbolic",Gtk::ICON_SIZE_LARGE_TOOLBAR);
view_button.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btnview_clicked));
m_viewbar.insert(view_item,-1);
//Menu Button
menu_item.add(menubtn);
menubtn.set_has_frame(false);
m_viewbar.insert(menu_item,-1);
m_viewbar.set_toolbar_style(Gtk::TOOLBAR_ICONS);
show_hidden.set_active(false);
show_hidden.signal_clicked().connect(sigc::mem_fun(*this,&FileWindow::btnhide_clicked));
menubox.append(show_hidden,Gtk::PACK_SHRINK);
popover.add(menubox);
menubtn.set_popover(popover);
popover.show_all_children();
//Info Bar
m_infobar.add_button("OK",Gtk::RESPONSE_OK);
auto pbox = dynamic_cast<Gtk::Container*>(m_infobar.get_content_area());
pbox->add(info_label);
vbox.append(m_infobar,Gtk::PACK_SHRINK);
m_infobar.signal_response().connect(sigc::mem_fun(*this,&FileWindow::infobar_response));
//Create Store
m_liststore = Gtk::ListStore::create(columns);
m_liststore->set_default_sort_func(sigc::mem_fun(*this,&FileWindow::sort_func));
m_liststore->set_sort_column(-1,Gtk::SORT_ASCENDING);
fill_store();
initalize_views();
m_sw.add(stack);
vbox.append(m_sw);
show_all_children();
m_infobar.hide();
}
void FileWindow::go_home(){
btnhome_clicked();
}
int FileWindow::sort_func(const Gtk::TreeModel::iterator &a,const Gtk::TreeModel::iterator &b){
bool is_dir_a,is_dir_b;
Glib::ustring name_a,name_b;
auto row_a= *a,row_b= *b;
is_dir_a = row_a[columns.m_col_is_dir];
is_dir_b = row_b[columns.m_col_is_dir];
name_a = row_a[columns.m_col_display_name];
name_b = row_b[columns.m_col_display_name];
if(!is_dir_a && is_dir_b){
return 1;
}
if(is_dir_a && !is_dir_b){
return -1;
}
if(name_a[0] != '.' && name_b[0] == '.'){
return 1;
}
if(name_a[0] == '.' && name_b[0] != '.'){
return -1;
}else{
return g_utf8_collate(name_a.c_str(),name_b.c_str());
}
}
void FileWindow::fill_store(){
Gtk::TreeModel::iterator iter;
//Clear the store
m_liststore->clear();
//Go through the directory and get information
try{
Glib::Dir dir1(parent_str);
bool is_dir;
Glib::ustring display_name;
std::string dir_name;
/* Ignore the files start with '.' when the button is not toggled */
do{
dir_name = dir1.read_name();
//std::cout<<dir_name<<std::endl;
char * path = g_build_filename(parent_str.c_str(),dir_name.c_str(),NULL);
is_dir = Glib::file_test(path,Glib::FILE_TEST_IS_DIR);
display_name = Glib::filename_to_utf8(dir_name);
if(dir_name[0] == '.' && !show_hidden.get_active()){
continue;
}
if(dir_name != ""){
auto row=*(m_liststore->append());
row[columns.m_col_display_name] = display_name;
row[columns.m_col_is_dir] = is_dir;
row[columns.m_col_path] = Glib::ustring(path);
row[columns.m_col_pixbuf] = is_dir ? folder_pixbuf : file_pixbuf;
}
g_free(path);
}while(dir_name != "");
}
catch(const Glib::Error &ex){
std::cout << ex.what() << std::endl;
parent_str = tmp_str;
fill_store();
}
}
void FileWindow::initalize_views(){
//Initalize IconView
m_iconview.set_model(m_liststore);
m_iconview.set_text_column(columns.m_col_display_name);
m_iconview.set_pixbuf_column(columns.m_col_pixbuf);
m_iconview.set_selection_mode(Gtk::SELECTION_MULTIPLE);
m_iconview.signal_item_activated().connect(sigc::mem_fun(*this,&FileWindow::item_activated));
m_iconview.set_row_spacing(0);
//Initalize TreeView
m_treeview.set_model(m_liststore);
m_treeview.append_column("",columns.m_col_pixbuf);
m_treeview.append_column("Name",columns.m_col_display_name);
m_treeview.signal_row_activated().connect(sigc::mem_fun(*this,&FileWindow::row_activated));
stack.add(m_iconview);
stack.add(m_treeview);
}
void FileWindow::item_activated(const Gtk::TreePath &path){
auto row = *(m_liststore->get_iter(path));
bool is_dir;
Glib::ustring path_name;
//Backup current parent dir
tmp_str = parent_str;
//Get Path Name and read
path_name = row[columns.m_col_path];
is_dir = row[columns.m_col_is_dir];
if(!is_dir){return ;}
parent_str = path_name;
fill_store();
up_button.set_sensitive();
}
void FileWindow::row_activated(const Gtk::TreePath &path,Gtk::TreeViewColumn * sel_column){
auto row = *(m_liststore->get_iter(path));
bool is_dir;
Glib::ustring path_name;
//Backup current parent dir
tmp_str = parent_str;
//Get Path Name and read
path_name = row[columns.m_col_path];
is_dir = row[columns.m_col_is_dir];
if(!is_dir){return ;}
parent_str = path_name;
fill_store();
up_button.set_sensitive();
}
void FileWindow::btnup_clicked(){
//Go to upper dir
Glib::ustring dir_name;
dir_name = Glib::path_get_dirname(parent_str);
parent_str = dir_name;
fill_store();
}
void FileWindow::btnhome_clicked(){
//Go to home dir
parent_str = Glib::ustring(Glib::get_home_dir());
fill_store();
}
void FileWindow::btnnew_clicked(){
//Create Dialog
Gtk::Dialog * dialog = new Gtk::Dialog("Create a folder",*this,Gtk::DIALOG_USE_HEADER_BAR);
dialog->add_button("OK",Gtk::RESPONSE_OK);
dialog->set_default_response(Gtk::RESPONSE_OK);
//Add Entry
Gtk::Box * pbox = dialog->get_content_area();
pbox->add(entry_file);
entry_file.set_activates_default();
dialog->signal_response().connect(sigc::bind(sigc::mem_fun(*this,&FileWindow::dialog_response),dialog));
dialog->show_all();
}
void FileWindow::btndel_clicked(){
Glib::ustring tmp;
switch(view_mode){
case ViewMode::MODE_ICON:
{
auto selected_items = m_iconview.get_selected_items();
for(auto it = selected_items.begin();it != selected_items.end(); it++){
auto row = *(m_liststore->get_iter(*it));
tmp = row[columns.m_col_path] + " delete failed!";
info_label.set_text(tmp);
m_infobar.show();
}
selected_items.clear();
}
break;
case ViewMode::MODE_LIST:
{
auto selected_item = m_treeview.get_selection();
auto row = *(selected_item->get_selected());
tmp = row[columns.m_col_path] + " delete failed!";
info_label.set_text(tmp);
m_infobar.show();
selected_item.reset();
}
break;
}
}
void FileWindow::btnview_clicked(){
switch(view_mode){
case ViewMode::MODE_ICON:
stack.set_visible_child(m_treeview);
view_button.set_image_from_icon_name("view-list-symbolic",Gtk::ICON_SIZE_LARGE_TOOLBAR);
view_mode = ViewMode::MODE_LIST;
break;
case ViewMode::MODE_LIST:
stack.set_visible_child(m_iconview);
view_button.set_image_from_icon_name("view-grid-symbolic",Gtk::ICON_SIZE_LARGE_TOOLBAR);
view_mode = ViewMode::MODE_ICON;
break;
}
}
void FileWindow::infobar_response(int response_id){
m_infobar.hide();
}
void FileWindow::dialog_response(int response_id,Gtk::Dialog * dialog){
if(response_id == Gtk::RESPONSE_OK){
Glib::ustring folder_name = entry_file.get_text();
if(parent_str.length() == 1 && parent_str[0] == '/'){
folder_name = parent_str + folder_name;
}else{
folder_name = parent_str + "/" + folder_name;
}
if(g_mkdir_with_parents(folder_name.c_str(),0755) == -1){
std::cout<<"Error Occured"<<std::endl;
}else{
fill_store();
}
}
delete dialog;
}
void FileWindow::btnhide_clicked(){
fill_store();
}
FileWindow::~FileWindow(){
folder_pixbuf.reset();
file_pixbuf.reset();
}

View File

@ -0,0 +1,368 @@
#include "FileWindow.h"
#include "FileColumnView.h"
#include "FileGridView.h"
enum SyncMode
{
MODEL_COLUMN_TO_GRID,
MODEL_GRID_TO_COLUMN
};
enum ViewMode
{
MODE_LIST,
MODE_GRID
};
struct _FileWindow
{
GtkApplicationWindow parent_instance;
GListModel *model_column, *model_grid;
GtkWidget *column_view, *grid_view;
GtkWidget *main_box, *btn_box;
GtkWidget *scrolled_window_column, *scrolled_window_grid;
GtkWidget *stack;
GtkWidget *folder_entry;
GtkWidget *btn_up, *btn_home, *btn_new, *btn_del, *btn_view;
GtkWidget *separator;
ViewMode view_mode;
};
G_DEFINE_TYPE(FileWindow, file_window, GTK_TYPE_APPLICATION_WINDOW)
static GFile *file_window_get_file(FileWindow *win)
{
GFile *file = NULL;
if (win->view_mode == ViewMode::MODE_LIST)
{
// In list view mode, get current directory from the model1
file = gtk_directory_list_get_file(GTK_DIRECTORY_LIST(win->model_column));
}
else
{
// In list view mode, get current directory from the model2
file = gtk_directory_list_get_file(GTK_DIRECTORY_LIST(win->model_grid));
}
return file;
}
static void sync_models(gpointer model1, gpointer model2, SyncMode mode)
{
if (mode == SyncMode::MODEL_COLUMN_TO_GRID)
{
// Set the file from model1
GFile *file = gtk_directory_list_get_file(GTK_DIRECTORY_LIST(model1));
if (file)
{
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(model2), file);
}
// g_object_unref(file);
}
else
{
// Set the file from model2
GFile *file = gtk_directory_list_get_file(GTK_DIRECTORY_LIST(model2));
if (file)
{
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(model1), file);
}
// g_object_unref(file);
}
}
static void btnview_clicked(GtkButton *button, FileWindow *win)
{
if (win->view_mode == ViewMode::MODE_LIST)
{
// Sync the models
sync_models(win->model_column, win->model_grid, SyncMode::MODEL_COLUMN_TO_GRID);
// Change view mode from list to grid
gtk_stack_set_visible_child(GTK_STACK(win->stack), win->scrolled_window_grid);
gtk_button_set_icon_name(button, "filewin-view-grid");
win->view_mode = ViewMode::MODE_GRID;
}
else
{
// Sync the models
sync_models(win->model_column, win->model_grid, SyncMode::MODEL_GRID_TO_COLUMN);
// Change view mode from grid to list
gtk_stack_set_visible_child(GTK_STACK(win->stack), win->scrolled_window_column);
gtk_button_set_icon_name(button, "filewin-view-list");
win->view_mode = ViewMode::MODE_LIST;
}
}
static void btnup_clicked(GtkWidget *widget, FileWindow *win)
{
// Get current directory and set to the new list
GFile *file = file_window_get_file(win);
char *path_str = g_file_get_path(file);
if (!(g_str_equal(path_str, "/") || (path_str[2] = '\\' && strlen(path_str) == 3)))
{
GFile *file1 = g_file_get_parent(file);
// Set the directory of models
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_column), file1);
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_grid), file1);
// Update string in the entry for path
char *path = g_file_get_path(file1);
gtk_editable_set_text(GTK_EDITABLE(win->folder_entry), path);
g_free(path);
g_object_unref(file1);
}
else
{
GFile *file1 = g_file_new_for_path("/");
// Set the directory of models
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_column), file1);
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_grid), file1);
// Update string in the entry for path
char *path = g_file_get_path(file1);
gtk_editable_set_text(GTK_EDITABLE(win->folder_entry), path);
g_free(path);
g_object_unref(file1);
}
}
static void btnok_clicked(GtkWidget *widget, GtkWidget *dialog)
{
// Get entry widget and the content of entry
GtkWidget *entry_new = gtk_widget_get_first_child(dialog);
const char *file_name = gtk_editable_get_text(GTK_EDITABLE(entry_new));
// Get the parent dir of file
FileWindow *win = FILE_WINDOW(gtk_window_get_transient_for(GTK_WINDOW(dialog)));
GFile *file = file_window_get_file(win);
char *parent_dir = g_file_get_path(file);
char *path = NULL;
// Create a new folder
if (parent_dir[strlen(parent_dir) - 1] != '/')
{
path = g_strdup_printf("%s/%s", parent_dir, file_name);
}
else
{
path = g_strdup_printf("%s%s", parent_dir, file_name);
}
if (g_mkdir_with_parents(path, 0755) == -1)
{
g_print("Error Occured!");
}
// g_print("%s\n", path);
g_free(parent_dir);
g_free(path);
gtk_window_destroy(GTK_WINDOW(dialog));
}
static void btnnew_clicked(GtkWidget *widget, FileWindow *win)
{
GtkWidget *dialog_new;
// Create the window
dialog_new = gtk_window_new();
gtk_window_set_title(GTK_WINDOW(dialog_new), "Create Folder");
gtk_window_set_transient_for(GTK_WINDOW(dialog_new), GTK_WINDOW(win));
// Add the entry and the "OK" button
GtkWidget *header, *btn_ok, *entry_new;
header = gtk_header_bar_new();
btn_ok = gtk_button_new_with_label("OK");
entry_new = gtk_entry_new();
// Link signal for "OK" button
g_signal_connect(entry_new, "activate", G_CALLBACK(btnok_clicked), dialog_new);
g_signal_connect(btn_ok, "clicked", G_CALLBACK(btnok_clicked), dialog_new);
// Add widgets to window
gtk_header_bar_pack_end(GTK_HEADER_BAR(header), btn_ok);
gtk_window_set_titlebar(GTK_WINDOW(dialog_new), header);
gtk_window_set_child(GTK_WINDOW(dialog_new), entry_new);
gtk_window_present(GTK_WINDOW(dialog_new));
}
void home_clicked(GtkWidget *widget, FileWindow *win)
{
// Set Current dir to home dir
GFile *file = g_file_new_for_path(g_get_home_dir());
// Update string in the entry for path
char *path = g_file_get_path(file);
gtk_editable_set_text(GTK_EDITABLE(win->folder_entry), path);
g_free(path);
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_column), file);
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_grid), file);
g_object_unref(file);
}
static void btndel_clicked(GtkWidget *widget, FileWindow *win)
{
GtkWidget *error_dialog;
// Create dialog
error_dialog = gtk_window_new();
gtk_window_set_title(GTK_WINDOW(error_dialog), "Error");
gtk_window_set_transient_for(GTK_WINDOW(error_dialog), GTK_WINDOW(win));
// Add a header bar
GtkWidget *header = gtk_header_bar_new();
GtkWidget *btn_ok = gtk_button_new_with_label("OK");
gtk_header_bar_pack_end(GTK_HEADER_BAR(header), btn_ok);
gtk_window_set_titlebar(GTK_WINDOW(error_dialog), header);
g_signal_connect_swapped(btn_ok, "clicked", G_CALLBACK(gtk_window_destroy), error_dialog);
// Add a label and a icon to show error
GtkWidget *dialog_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
GtkWidget *image = gtk_image_new_from_resource("/org/gtk/daleclack/dialog-error.png");
GtkWidget *label = gtk_label_new("Failed to delete file");
gtk_image_set_pixel_size(GTK_IMAGE(image), 48);
// Add widgets to the dialog
gtk_widget_set_margin_bottom(dialog_box, 20);
gtk_widget_set_margin_end(dialog_box, 20);
gtk_widget_set_margin_start(dialog_box, 20);
gtk_widget_set_margin_top(dialog_box, 20);
gtk_box_append(GTK_BOX(dialog_box), image);
gtk_box_append(GTK_BOX(dialog_box), label);
gtk_window_set_child(GTK_WINDOW(error_dialog), dialog_box);
gtk_window_present(GTK_WINDOW(error_dialog));
}
static void folder_entry_activated(GtkWidget *widget, FileWindow *win)
{
// Get Path and create a associated file
const char *path = gtk_editable_get_text(GTK_EDITABLE(widget));
GFile *file = g_file_new_for_path(path);
// Set the directory of models
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_column), file);
gtk_directory_list_set_file(GTK_DIRECTORY_LIST(win->model_grid), file);
}
GListModel *file_window_get_grid_model(FileWindow *self)
{
// Get Model for grid view
return self->model_grid;
}
GListModel *file_window_get_column_model(FileWindow *self)
{
// Get Model for list column view
return self->model_column;
}
GtkWidget *file_window_get_folder_entry(FileWindow *self)
{
// Get the entry widget
return self->folder_entry;
}
static void file_window_dispose(GObject *object)
{
// Clear List Model
G_OBJECT_CLASS(file_window_parent_class)->dispose(object);
}
static void file_window_init(FileWindow *self)
{
GtkColumnViewColumn *column;
// Initalize window
gtk_window_set_title(GTK_WINDOW(self), "My Finder");
gtk_window_set_icon_name(GTK_WINDOW(self), "file-manager1");
gtk_window_set_default_size(GTK_WINDOW(self), 640, 400);
// Create list model
GFile *file = g_file_new_for_path(g_get_home_dir());
self->model_column = G_LIST_MODEL(gtk_directory_list_new(
"standard::name,standard::display-name,standard::icon,standard::size,standard::content-type", file));
self->model_grid = G_LIST_MODEL(gtk_directory_list_new(
"standard::name,standard::display-name,standard::icon,standard::size,standard::content-type", file));
// Create column view widget
self->column_view = create_column_view(self);
// Create grid view widget
self->grid_view = create_grid_view(self);
// Create buttons
self->btn_up = gtk_button_new_from_icon_name("filewin-go-up");
self->btn_home = gtk_button_new_from_icon_name("filewin-go-home");
self->btn_new = gtk_button_new_from_icon_name("filewin-new");
self->btn_del = gtk_button_new_from_icon_name("filewin-delete");
self->btn_view = gtk_button_new_from_icon_name("filewin-view-list");
// Create entry for show and change the current folder
self->folder_entry = gtk_entry_new();
gtk_editable_set_text(GTK_EDITABLE(self->folder_entry), g_get_home_dir());
// Create widgets for layout
self->scrolled_window_column = gtk_scrolled_window_new();
self->scrolled_window_grid = gtk_scrolled_window_new();
self->main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
self->btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
self->stack = gtk_stack_new();
self->separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
// Add buttons to the btn_box
gtk_widget_set_hexpand(self->btn_box, TRUE);
gtk_box_append(GTK_BOX(self->btn_box), self->btn_up);
gtk_box_append(GTK_BOX(self->btn_box), self->btn_home);
gtk_box_append(GTK_BOX(self->btn_box), self->btn_new);
gtk_box_append(GTK_BOX(self->btn_box), self->btn_del);
gtk_widget_set_hexpand(self->separator, TRUE);
// gtk_widget_set_halign(self->btn_view, GTK_ALIGN_END);
gtk_box_append(GTK_BOX(self->btn_box), self->separator);
gtk_box_append(GTK_BOX(self->btn_box), self->btn_view);
// Link signals
g_signal_connect(self->btn_view, "clicked", G_CALLBACK(btnview_clicked), self);
g_signal_connect(self->btn_up, "clicked", G_CALLBACK(btnup_clicked), self);
g_signal_connect(self->btn_home, "clicked", G_CALLBACK(home_clicked), self);
g_signal_connect(self->btn_del, "clicked", G_CALLBACK(btndel_clicked), self);
g_signal_connect(self->btn_new, "clicked", G_CALLBACK(btnnew_clicked), self);
g_signal_connect(self->folder_entry, "activate", G_CALLBACK(folder_entry_activated), self);
// Add scrolled window for columns view
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scrolled_window_column),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_set_hexpand(self->scrolled_window_column, TRUE);
gtk_widget_set_vexpand(self->scrolled_window_column, TRUE);
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(self->scrolled_window_column), self->column_view);
gtk_stack_add_named(GTK_STACK(self->stack), self->scrolled_window_column, "Column View");
// Add scrolled window for grid view
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scrolled_window_grid),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_set_hexpand(self->scrolled_window_grid, TRUE);
gtk_widget_set_vexpand(self->scrolled_window_grid, TRUE);
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(self->scrolled_window_grid), self->grid_view);
gtk_stack_add_named(GTK_STACK(self->stack), self->scrolled_window_grid, "Grid View");
gtk_box_append(GTK_BOX(self->main_box), self->btn_box); // Box for control buttons
gtk_box_append(GTK_BOX(self->main_box), self->folder_entry); // Box for folder switcher
gtk_box_append(GTK_BOX(self->main_box), self->stack); // Box for main area
// gtk_stack_set_visible_child(GTK_STACK(self->stack), self->scrolled_window_grid);
gtk_window_set_child(GTK_WINDOW(self), self->main_box);
}
static void file_window_class_init(FileWindowClass *klass)
{
G_OBJECT_CLASS(klass)->dispose = file_window_dispose;
}
FileWindow *file_window_new(GtkWindow *win)
{
return FILE_WINDOW(g_object_new(file_window_get_type(), "transient-for", win, NULL));
}

View File

@ -0,0 +1,27 @@
/*
Patch for Microsoft Windows
*/
#pragma once
#include <gtk/gtk.h>
#include <cstring>
// Check the whether the selected file is directory
static inline gboolean check_directory(GFileInfo *info)
{
#ifdef _WIN32
// Since all files for windows will be "unknown" type,
// use content type to check file.
const char *file_type = g_file_info_get_content_type(info);
if(strncmp(file_type, "inode/directory", strlen("inode/directory")) == 0)
{
return TRUE;
}
#else
if(g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY){
return TRUE;
}
#endif
// Not a directory, return FALSE
return FALSE;
}

View File

@ -1,6 +1,7 @@
#include "MyDock.h" #include "MyDock.h"
#include "MyFinder.h" #include "MyFinder.h"
#include "AppView.h" #include "AppView.h"
#include "FileWindow.h"
enum PadPage enum PadPage
{ {
@ -32,6 +33,7 @@ struct _MyDock
GtkGesture *gesture; GtkGesture *gesture;
GtkWidget *context_menu; // Context menu GtkWidget *context_menu; // Context menu
MyPrefs *prefs_win; // Prefs window MyPrefs *prefs_win; // Prefs window
FileWindow *file_win; // File Broswer window
}; };
G_DEFINE_TYPE(MyDock, my_dock, GTK_TYPE_BOX) G_DEFINE_TYPE(MyDock, my_dock, GTK_TYPE_BOX)
@ -140,14 +142,54 @@ static void btnset_clicked(GtkWidget *widget, MyDock *dock)
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_set), "my_prefs_running"); gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_set), "my_prefs_running");
} }
static gboolean prefs_win_closed(GtkWindow *window, MyDock *dock) static gboolean prefs_win_closed(GtkWidget *window, MyDock *dock)
{ {
// For the preferences window, hide it // For the preferences window, hide it
gtk_widget_set_visible(GTK_WIDGET(dock->prefs_win), FALSE); gtk_widget_set_visible(window, FALSE);
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_set), "my_prefs"); gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_set), "my_prefs");
return TRUE; return TRUE;
} }
static void btnfiles_clicked(GtkWindow *window, MyDock *dock)
{
// When the window visible, unminimize it
if (gtk_widget_get_visible(GTK_WIDGET((dock->file_win))))
{
gtk_window_unminimize(GTK_WINDOW(dock->file_win));
}
else
{
// Show the window
gtk_window_set_transient_for(GTK_WINDOW(dock->file_win), dock->parent_win);
gtk_window_present(GTK_WINDOW(dock->file_win));
}
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_file), "file-app_running");
}
static void padfiles_clicked(GtkWindow *window, MyDock *dock)
{
// When the window visible, control window state
if (gtk_widget_get_visible(GTK_WIDGET((dock->file_win))))
{
window_ctrl(GTK_WINDOW(dock->file_win), dock->parent_win);
}
else
{
// Show the window
gtk_window_set_transient_for(GTK_WINDOW(dock->file_win), dock->parent_win);
gtk_window_present(GTK_WINDOW(dock->file_win));
}
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_file), "file-app_running");
}
static gboolean file_window_closed(GtkWidget *window, MyDock *dock)
{
// Hide the window
gtk_widget_set_visible(window, FALSE);
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_file), "file-app");
return TRUE;
}
static void my_dock_get_widgets(MyDock *self) static void my_dock_get_widgets(MyDock *self)
{ {
// Get widgets // Get widgets
@ -242,6 +284,15 @@ static void my_dock_init(MyDock *self)
// Create prefs window // Create prefs window
self->prefs_win = my_prefs_new(); self->prefs_win = my_prefs_new();
my_prefs_set_background(self->prefs_win, self->main_pic); my_prefs_set_background(self->prefs_win, self->main_pic);
g_signal_connect(self->btnset, "clicked", G_CALLBACK(btnset_clicked), self);
g_signal_connect(self->padset, "clicked", G_CALLBACK(padset_clicked), self);
g_signal_connect(self->prefs_win, "close-request", G_CALLBACK(prefs_win_closed), self);
// Create File Browser Window
self->file_win = file_window_new(self->parent_win);
g_signal_connect(self->btnfiles, "clicked", G_CALLBACK(btnfiles_clicked), self);
g_signal_connect(self->padfile, "clicked", G_CALLBACK(padfiles_clicked), self);
g_signal_connect(self->file_win, "close-request", G_CALLBACK(file_window_closed), self);
// Add finder // Add finder
self->finder = my_finder_new(GTK_ORIENTATION_HORIZONTAL, 5); self->finder = my_finder_new(GTK_ORIENTATION_HORIZONTAL, 5);
@ -286,9 +337,6 @@ static void my_dock_init(MyDock *self)
// Link Signals // Link Signals
g_signal_connect(self->btnlaunch, "clicked", G_CALLBACK(btnlaunch_clicked), self); g_signal_connect(self->btnlaunch, "clicked", G_CALLBACK(btnlaunch_clicked), self);
g_signal_connect(self->btnset, "clicked", G_CALLBACK(btnset_clicked), self);
g_signal_connect(self->padset, "clicked", G_CALLBACK(padset_clicked), self);
g_signal_connect(self->prefs_win, "close-request", G_CALLBACK(prefs_win_closed), self);
// Create Css Provider for styling // Create Css Provider for styling
GtkCssProvider *provider = gtk_css_provider_new(); GtkCssProvider *provider = gtk_css_provider_new();
@ -304,7 +352,6 @@ static void my_dock_init(MyDock *self)
my_finder_add_style(MY_FINDER(self->finder), provider); my_finder_add_style(MY_FINDER(self->finder), provider);
// Add Apps grid // Add Apps grid
// To make the default view layout same as the addon apps view // To make the default view layout same as the addon apps view
self->appgrid_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); self->appgrid_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
self->appgrid_label = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); self->appgrid_label = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);