summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcadmio <gioresta87@gmail.com>2023-12-16 09:58:54 +0100
committercadmio <gioresta87@gmail.com>2023-12-16 09:58:54 +0100
commitd886d051ab6e7c9094876ce31d20a01458e8100c (patch)
tree0d81d9b3ef1ce9667f2363accad3dd37e5ef1f8a
parent8d85b820c55661e56e469f1fc2c7ce5865b8d9c4 (diff)
downloadlitos4-d886d051ab6e7c9094876ce31d20a01458e8100c.tar.gz
litos4-d886d051ab6e7c9094876ce31d20a01458e8100c.tar.bz2
litos4-d886d051ab6e7c9094876ce31d20a01458e8100c.zip
update all
-rw-r--r--gears-menu.ui10
-rw-r--r--litosaccels.c17
-rw-r--r--litosappwin.c126
-rw-r--r--litosfile.c12
-rw-r--r--window.ui2
5 files changed, 84 insertions, 83 deletions
diff --git a/gears-menu.ui b/gears-menu.ui
index 2e95933..93ca6c6 100644
--- a/gears-menu.ui
+++ b/gears-menu.ui
@@ -13,16 +13,16 @@
<attribute name="action">app.new</attribute>
</item>
</section>
- <section>
+ <section>
<item>
- <attribute name="label" translatable="yes">_Open</attribute>
- <attribute name="action">app.open</attribute>
+ <attribute name="label" translatable="yes">New From Template</attribute>
+ <attribute name="action">app.open_tmpl</attribute>
</item>
</section>
<section>
<item>
- <attribute name="label" translatable="yes">New From Template</attribute>
- <attribute name="action">app.open_tmpl</attribute>
+ <attribute name="label" translatable="yes">_Open</attribute>
+ <attribute name="action">app.open</attribute>
</item>
</section>
<section>
diff --git a/litosaccels.c b/litosaccels.c
index 554065d..14032e9 100644
--- a/litosaccels.c
+++ b/litosaccels.c
@@ -21,6 +21,7 @@ LitosFile * litos_app_window_new_file(LitosAppWindow *win);
guint litos_app_window_get_array_len(LitosAppWindow *win);
gboolean litos_app_window_quit (GtkWindow *window, gpointer user_data);
void ctrl_f(LitosAppWindow *win);
+void Esc(LitosAppWindow *win);
void litos_app_error_dialog(GtkWindow *window, GError *error, char *filename);
@@ -53,6 +54,14 @@ open_cb (GtkWidget *dialog, gint response, gpointer window)
}
static void
+esc_activated(GSimpleAction *action, GVariant *parameter, gpointer app)
+{
+ GtkWindow *window = gtk_application_get_active_window (GTK_APPLICATION (app));
+ LitosAppWindow *win = LITOS_APP_WINDOW(window);
+ Esc(win);
+}
+
+static void
open_activated(GSimpleAction *action, GVariant *parameter, gpointer app)
{
GtkWidget *dialog;
@@ -190,8 +199,8 @@ quit_activated (GSimpleAction *action, GVariant *parameter, gpointer app)
static void
new_file (GSimpleAction *action,
- GVariant *parameter,
- gpointer app)
+ GVariant *parameter,
+ gpointer app)
{
GtkWindow *window = gtk_application_get_active_window (GTK_APPLICATION (app));
LitosAppWindow *win = LITOS_APP_WINDOW(window);
@@ -270,8 +279,6 @@ find_selection (GSimpleAction *action, GVariant *parameter, gpointer app)
LitosAppWindow *win = LITOS_APP_WINDOW(window);
ctrl_f(win);
-
- //set_search_entry(win);
}
void setAccels (GApplication *app)
@@ -284,6 +291,7 @@ void setAccels (GApplication *app)
{"insert_html", insertHtmlTags, "s", NULL, NULL, {0,0,0}},
{"insert_char", insertChar, "s", NULL, NULL, {0,0,0}},
{"open", open_activated, NULL, NULL, NULL},
+ {"esc", esc_activated, NULL, NULL, NULL},
{"open_tmpl", open_tmpl, NULL, NULL, NULL},
{"new", new_file, NULL, NULL, NULL},
{"save", save, NULL, NULL, NULL, {0,0,0}},
@@ -304,6 +312,7 @@ void setAccels (GApplication *app)
{ "app.save_as", { "<Shift><Control>s", NULL} },
{ "app.close", { "<Control>w", NULL} },
{ "app.quit", { "<Control>q", NULL} },
+ { "app.esc", { "Escape", NULL} },
{ "app.find", { "<Control>f", NULL} },
{ "app.insert_html(\"<b>%s</b>\")", { "<Control>b", NULL} },
{ "app.insert_html(\"<i>%s</i>\")", { "<Control>i", NULL} },
diff --git a/litosappwin.c b/litosappwin.c
index 0e43348..b1ee51c 100644
--- a/litosappwin.c
+++ b/litosappwin.c
@@ -207,6 +207,40 @@ litos_app_window_set_search_context(LitosAppWindow *win, const char *stringToSea
}
static void
+replace_btn_clicked (GtkButton *button, gpointer userData)
+{
+ LitosAppWindow *win = LITOS_APP_WINDOW(userData);
+
+ if (win->search_context == NULL)
+ return;
+
+ guint count_replaced = 0;
+
+ const gchar *stringToSearch = gtk_editable_get_text(GTK_EDITABLE(win->search_entry));
+ const gchar *replaceString = gtk_editable_get_text(GTK_EDITABLE(win->replace_entry));
+
+ if (stringToSearch == NULL || replaceString == NULL)
+ return;
+
+ /* Search and Highlight replaced string */
+
+ count_replaced = gtk_source_search_context_replace_all (win->search_context,
+ replaceString,
+ -1,
+ NULL);
+
+ gtk_editable_set_text(GTK_EDITABLE(win->replace_entry),"");
+
+ char str[80];
+
+ sprintf(str, "%d replacement", count_replaced);
+
+ gtk_label_set_label (GTK_LABEL(win->lbl_number_occurences),
+ str
+ );
+}
+
+static void
search_text_changed (GtkEntry *entry,
LitosAppWindow *win)
{
@@ -250,13 +284,22 @@ search_text_changed (GtkEntry *entry,
&match_start,
&match_end);
}
+
+ gint counter = gtk_source_search_context_get_occurrences_count (win->search_context);
+
+ char str[80];
+
+ sprintf(str, "%d occurences", counter);
+
+ gtk_label_set_label (GTK_LABEL(win->lbl_number_occurences),
+ str
+ );
}
void set_search_entry(LitosAppWindow *win)
{
- /*GtkTextIter start, end;
+ GtkTextIter start, end;
LitosFile *file = litos_app_window_current_file(win);
- GtkEntryBuffer *entry_buffer;
GtkTextBuffer *buffer = litos_file_get_buffer(file);
@@ -269,20 +312,20 @@ void set_search_entry(LitosAppWindow *win)
&end,
FALSE);
- gtk_entry_buffer_insert_text (entry_buffer,
- 0,
- stringToSearch,
- -1
- );
+ gtk_editable_set_text(GTK_EDITABLE(win->search_entry),stringToSearch);
+ }
+}
- gtk_entry_set_buffer(GTK_ENTRY(win->search_entry), entry_buffer);
- }*/
+void Esc(LitosAppWindow *win)
+{
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(LITOS_APP_WINDOW(win)->btn_find_icon), FALSE);
}
void ctrl_f(LitosAppWindow *win)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(LITOS_APP_WINDOW(win)->btn_find_icon), TRUE);
gtk_widget_grab_focus(LITOS_APP_WINDOW(win)->search_entry);
+ set_search_entry(win);
}
void search_btn_clicked (GtkWidget *search_btn, gpointer user_data)
@@ -455,7 +498,7 @@ gboolean litos_app_window_quit (GtkWindow *window, gpointer user_data)
GtkApplication *app = gtk_window_get_application(window);
if (litos_app_window_get_array_len(win) == 0)
- g_application_quit (G_APPLICATION (app));
+ return FALSE;
else
{
@@ -463,8 +506,15 @@ gboolean litos_app_window_quit (GtkWindow *window, gpointer user_data)
while (win->quit == TRUE && litos_app_window_remove_child(win))
;
}
-
- return TRUE;
+
+ if (litos_app_window_get_array_len(win) == 0)
+ {
+ g_application_quit (G_APPLICATION (app));
+ return FALSE;
+ }
+
+ else
+ return TRUE;
}
void
@@ -497,58 +547,6 @@ litos_app_window_update_font ()
g_free (css_string);
}
-void replace_btn_clicked (GtkButton *button, gpointer userData)
-{
- LitosAppWindow *win = LITOS_APP_WINDOW(userData);
-
- guint count_replaced = 0;
-
- const gchar *stringToSearch = gtk_entry_get_text(GTK_ENTRY(win->search_entry));
- const gchar *replaceString = gtk_entry_get_text(GTK_ENTRY(win->replace_entry));
-
- if (stringToSearch == NULL || replaceString == NULL)
- return;
-
- /* Search and Highlight replaced string */
-
- count_replaced = gtk_source_search_context_replace_all (win->search_context,
- replaceString,
- -1,
- NULL);
-
- /* Don't search and highlight strings with spaces */
- /*if (!isspace(replaceString[0]))
- {
- searchString(litos, stringToSearch);
-
- GtkSourceSearchSettings *settings = gtk_source_search_settings_new ();
-
- clearSearchContext(litos);
-
- gtk_source_search_settings_set_case_sensitive (settings, TRUE);
-
- gtk_source_search_settings_set_search_text (settings, replaceString);
-
- highlightSearchBuffer = GTK_SOURCE_BUFFER(get_current_buffer(litos));
-
- litos->search_context = gtk_source_search_context_new(highlightSearchBuffer, settings);
-
- highlightWord(litos);
- }*/
-
- gtk_entry_set_text(GTK_ENTRY(win->replace_entry),"");
-
- char str[80];
-
- sprintf(str, "%d replacement", count_replaced);
-
- gtk_label_set_label (GTK_LABEL(win->lbl_number_occurences),
- str
- );
-
- g_print("%d replacement\n", count_replaced);
-}
-
static void
litos_app_window_init (LitosAppWindow *win)
{
diff --git a/litosfile.c b/litosfile.c
index acf0e33..db794ec 100644
--- a/litosfile.c
+++ b/litosfile.c
@@ -101,9 +101,9 @@ litos_file_set_property (GObject *object,
}
static void
-litos_file_get_property (GObject *object,
- guint property_id,
- GValue *value,
+litos_file_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
GParamSpec *pspec)
{
LitosFile *self = LITOS_FILE (object);
@@ -268,7 +268,6 @@ gboolean litos_file_load (LitosFile *file, GError **error)
return FALSE;
}
-
gboolean litos_file_save(LitosFile *file, GError *error)
{
if (file->gfile != NULL)
@@ -310,8 +309,3 @@ void litos_file_save_as(LitosFile* file, GFile *new_file)
litos_file_save(file, NULL);
}
-
-GtkWidget * litos_file_get_close_box(LitosFile *file)
-{
- return file->close_btn_box;
-}
diff --git a/window.ui b/window.ui
index a99d560..fbff360 100644
--- a/window.ui
+++ b/window.ui
@@ -62,7 +62,7 @@
</object>
</child>
<child>
- <object class="GtkText" id="replace_entry">
+ <object class="GtkEntry" id="replace_entry">
<property name="tooltip-text">Replace</property>
</object>
</child>