Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
karudu
/
C-editor
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ce221e14
authored
Mar 03, 2022
by
hounas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Algne text editor. Avab file chooseri(ei salvesta).
parent
5c2963ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
0 deletions
testgui.c
testgui.c
0 → 100644
View file @
ce221e14
#include <gtk/gtk.h>
void
save_file
(
GtkToolButton
*
save
,
gpointer
data
,
GtkTextBuffer
*
buffer
){
GtkWidget
*
dialog
;
dialog
=
gtk_file_chooser_dialog_new
(
"Valige fail"
,
NULL
,
GTK_FILE_CHOOSER_ACTION_SAVE
,
GTK_STOCK_CANCEL
,
GTK_RESPONSE_CANCEL
,
GTK_STOCK_SAVE
,
GTK_RESPONSE_ACCEPT
,
NULL
);
if
(
gtk_dialog_run
(
GTK_DIALOG
(
dialog
))
==
GTK_RESPONSE_ACCEPT
){
char
*
filename
;
char
*
text
;
GtkTextBuffer
*
savebuffer
;
GtkTextIter
*
start
;
GtkTextIter
*
end
;
gboolean
result
;
GError
*
err
;
filename
=
gtk_file_chooser_get_filename
(
GTK_FILE_CHOOSER
(
dialog
));
gtk_widget_set_sensitive
(
data
,
FALSE
);
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
data
));
gtk_text_buffer_get_start_iter
(
buffer
,
&
start
);
gtk_text_buffer_get_end_iter
(
buffer
,
&
end
);
text
=
gtk_text_buffer_get_text
(
buffer
,
&
start
,
&
end
,
FALSE
);
gtk_text_buffer_set_modified
(
buffer
,
FALSE
);
gtk_widget_set_sensitive
(
data
,
TRUE
);
if
(
filename
!=
NULL
)
result
=
g_file_set_contents
(
filename
,
text
,
-
1
,
&
err
);
else
result
=
g_file_set_contents
(
filename
,
text
,
-
1
,
&
err
);
if
(
result
==
FALSE
)
{
//midagi siia
}
g_free
(
text
);
}
gtk_widget_destroy
(
dialog
);
}
void
update_statusbar
(
GtkTextBuffer
*
buffer
,
GtkStatusbar
*
statusbar
)
{
gchar
*
msg
;
gint
row
,
col
;
GtkTextIter
iter
;
gtk_statusbar_pop
(
statusbar
,
0
);
gtk_text_buffer_get_iter_at_mark
(
buffer
,
&
iter
,
gtk_text_buffer_get_insert
(
buffer
));
row
=
gtk_text_iter_get_line
(
&
iter
);
col
=
gtk_text_iter_get_line_offset
(
&
iter
);
msg
=
g_strdup_printf
(
"Col: %d Ln: %d"
,
col
+
1
,
row
+
1
);
gtk_statusbar_push
(
statusbar
,
0
,
msg
);
g_free
(
msg
);
}
void
mark_set_callback
(
GtkTextBuffer
*
buffer
,
const
GtkTextIter
*
new_location
,
GtkTextMark
*
mark
,
gpointer
data
)
{
update_statusbar
(
buffer
,
GTK_STATUSBAR
(
data
));
}
int
main
(
int
argc
,
char
*
argv
[])
{
GtkWidget
*
window
;
GtkWidget
*
vbox
;
GtkWidget
*
toolbar
;
GtkWidget
*
view
;
GtkWidget
*
statusbar
;
GtkWidget
*
error
;
GtkToolItem
*
exit
;
GtkToolItem
*
undo
;
GtkToolItem
*
redo
;
GtkToolItem
*
save
;
GtkToolItem
*
newfile
;
GtkTextBuffer
*
buffer
;
gtk_init
(
&
argc
,
&
argv
);
window
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
gtk_window_set_position
(
GTK_WINDOW
(
window
),
GTK_WIN_POS_CENTER
);
gtk_window_set_default_size
(
GTK_WINDOW
(
window
),
1000
,
800
);
gtk_window_set_title
(
GTK_WINDOW
(
window
),
"C-Editor"
);
vbox
=
gtk_vbox_new
(
FALSE
,
0
);
gtk_container_add
(
GTK_CONTAINER
(
window
),
vbox
);
toolbar
=
gtk_toolbar_new
();
gtk_toolbar_set_style
(
GTK_TOOLBAR
(
toolbar
),
GTK_TOOLBAR_ICONS
);
exit
=
gtk_tool_button_new_from_stock
(
GTK_STOCK_QUIT
);
gtk_toolbar_insert
(
GTK_TOOLBAR
(
toolbar
),
exit
,
-
1
);
newfile
=
gtk_tool_button_new_from_stock
(
GTK_STOCK_FILE
);
gtk_toolbar_insert
(
GTK_TOOLBAR
(
toolbar
),
newfile
,
-
1
);
save
=
gtk_tool_button_new_from_stock
(
GTK_STOCK_SAVE
);
gtk_toolbar_insert
(
GTK_TOOLBAR
(
toolbar
),
save
,
-
1
);
undo
=
gtk_tool_button_new_from_stock
(
GTK_STOCK_UNDO
);
gtk_toolbar_insert
(
GTK_TOOLBAR
(
toolbar
),
undo
,
-
1
);
redo
=
gtk_tool_button_new_from_stock
(
GTK_STOCK_REDO
);
gtk_toolbar_insert
(
GTK_TOOLBAR
(
toolbar
),
redo
,
-
1
);
gtk_box_pack_start
(
GTK_BOX
(
vbox
),
toolbar
,
FALSE
,
FALSE
,
5
);
view
=
gtk_text_view_new
();
gtk_text_view_set_wrap_mode
(
GTK_TEXT_VIEW
(
view
),
GTK_WRAP_WORD
);
gtk_box_pack_start
(
GTK_BOX
(
vbox
),
view
,
TRUE
,
TRUE
,
0
);
gtk_widget_grab_focus
(
view
);
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
view
));
statusbar
=
gtk_statusbar_new
();
gtk_box_pack_start
(
GTK_BOX
(
vbox
),
statusbar
,
FALSE
,
FALSE
,
0
);
g_signal_connect
(
G_OBJECT
(
exit
),
"clicked"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
g_signal_connect
(
G_OBJECT
(
save
),
"clicked"
,
G_CALLBACK
(
save_file
),
NULL
);
g_signal_connect
(
buffer
,
"changed"
,
G_CALLBACK
(
update_statusbar
),
statusbar
);
g_signal_connect_object
(
buffer
,
"mark_set"
,
G_CALLBACK
(
mark_set_callback
),
statusbar
,
0
);
g_signal_connect_swapped
(
G_OBJECT
(
window
),
"destroy"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
gtk_widget_show_all
(
window
);
update_statusbar
(
buffer
,
GTK_STATUSBAR
(
statusbar
));
gtk_main
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment