Skip to content

Commit

Permalink
Add recent files window
Browse files Browse the repository at this point in the history
  • Loading branch information
bartkessels committed Nov 3, 2017
1 parent 372953c commit 106ae7e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 3 deletions.
1 change: 1 addition & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ src/ui/menu_app.glade
src/ui/window_main.glade
src/ui/window_settings.glade
src/ui/window_shortcuts.glade
src/getit-application.c
src/getit-content-response.c
src/getit-messages.h
src/getit-stack.h
Expand Down
49 changes: 46 additions & 3 deletions src/getit-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ static void getit_application_cb_open (GApplication *app,
GFile **files,
gint n_files,
const gchar *hint);
static void getit_application_cb_preferences (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void getit_application_cb_recent (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void getit_application_cb_shortcuts (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void getit_application_cb_preferences (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void getit_application_cb_about (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
Expand All @@ -58,6 +61,7 @@ static void getit_application_cb_quit (GSimpleAction *action,
*
*/
const GActionEntry app_actions[] = {
{ "recent", getit_application_cb_recent },
{ "shortcuts", getit_application_cb_shortcuts },
{ "preferences", getit_application_cb_preferences },
{ "about", getit_application_cb_about },
Expand Down Expand Up @@ -181,6 +185,45 @@ getit_application_cb_open (GApplication *app,
gtk_window_present (window);
}

static void
getit_application_cb_recent (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
g_assert (GETIT_IS_APPLICATION (user_data));

GetitApplication *self;
GtkWindow *parent_window;
GtkRecentManager *recent_manager;
GtkRecentFilter *recent_filter;
GtkWidget *recent_chooser_dialog;
gint recent_chooser_dialog_result;
const gchar *selected_file;

self = GETIT_APPLICATION (user_data);
parent_window = gtk_application_get_active_window (GTK_APPLICATION (self));
recent_manager = gtk_recent_manager_get_default ();
recent_filter = gtk_recent_filter_new ();
gtk_recent_filter_set_name (recent_filter, _("GetIt Files"));
gtk_recent_filter_add_pattern (recent_filter, "*.getit");
recent_chooser_dialog = gtk_recent_chooser_dialog_new_for_manager (_("Recent Requests"),
parent_window,
recent_manager,
_("Open Request"), GTK_RESPONSE_ACCEPT,
NULL);

gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (recent_chooser_dialog), recent_filter);
recent_chooser_dialog_result = gtk_dialog_run (GTK_DIALOG (recent_chooser_dialog));
selected_file = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (recent_chooser_dialog));

gtk_widget_destroy (recent_chooser_dialog);

if (recent_chooser_dialog_result == GTK_RESPONSE_ACCEPT && selected_file != NULL) {
selected_file = getit_string_remove (selected_file, "file://");
getit_window_open_file (GETIT_WINDOW (parent_window), selected_file);
}
}

static void
getit_application_cb_preferences (GSimpleAction *action,
GVariant *parameter,
Expand Down
2 changes: 2 additions & 0 deletions src/getit-application.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

#pragma once

#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "getit-string.h"
#include "getit-window.h"
#include "getit-window-settings.h"
#include "getit-window-shortcuts.h"
Expand Down
51 changes: 51 additions & 0 deletions src/getit-string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* getit-string.c
*
* Copyright (C) 2017 Bart Kessels <bartkessels@bk-mail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "getit-string.h"

const gchar *
getit_string_remove (const gchar *complete_string,
const char *remove_string)
{
g_assert_nonnull (complete_string);
g_assert_nonnull (remove_string);

gchar **splitted_string;
gint splitted_string_index;
const gchar *new_string;

splitted_string_index = 0;
new_string = "";

/* Split string on the string to replace characters */
splitted_string = g_strsplit (complete_string, remove_string, 2);

while (splitted_string[splitted_string_index] != NULL) {
new_string = g_strconcat (new_string,
splitted_string[splitted_string_index],
NULL);

splitted_string_index++;
}

if (strlen (new_string) < 1) {
return complete_string;
}

return new_string;
}
26 changes: 26 additions & 0 deletions src/getit-string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* getit-string.h
*
* Copyright (C) 2017 Bart Kessels <bartkessels@bk-mail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <glib.h>
#include <string.h>

/* Public function signatures */
const gchar *getit_string_remove (const gchar *complete_string,
const char *remove_string);
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ getit_sources = [
'getit-notification.c',
'getit-settings.c',
'getit-stack.c',
'getit-string.c',
'getit-window.c',
'getit-window-settings.c',
'getit-window-shortcuts.c',
Expand Down
6 changes: 6 additions & 0 deletions src/ui/menu_app.glade
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0"?>
<interface>
<menu id="app-menu">
<section id="app-menu-action-section">
<item>
<attribute name="label" translatable="yes">_Recent</attribute>
<attribute name="action">app.recent</attribute>
</item>
</section>
<section id="app-menu-preferences-section">
<item>
<attribute name="label" translatable="yes">_Preferences</attribute>
Expand Down

0 comments on commit 106ae7e

Please sign in to comment.