sciteproj-1.05/ 0000755 0001750 0001750 00000000000 12570535072 013017 5 ustar gusnan gusnan sciteproj-1.05/Makefile 0000644 0001750 0001750 00000005407 12570535072 014465 0 ustar gusnan gusnan #
# Copyright (C) 2009-2014 Andreas Rönnquist
# This file is distributed under the same license
# as the sciteproj package, see COPYING file.
#
ifndef CC
CC=gcc
endif
SRC=src
BIN=bin
GRPH=graphics
OBJ=obj
ifdef DEBUG
STD_CFLAGS=-Wall -g3 -ggdb -D_DEBUG
else
STD_CFLAGS=-Wall -Wformat -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -Wformat=2 -Wdeprecated-declarations
endif
OBJECTS=$(OBJ)/about.o $(OBJ)/addfiles.o $(OBJ)/clipboard.o $(OBJ)/expand.o\
$(OBJ)/file_utils.o $(OBJ)/folder_config.o\
$(OBJ)/graphics.o $(OBJ)/gui.o $(OBJ)/gui_callbacks.o\
$(OBJ)/icon.o $(OBJ)/load_folder.o $(OBJ)/menus.o $(OBJ)/main.o $(OBJ)/prefs.o\
$(OBJ)/properties_dialog.o $(OBJ)/recent_files.o $(OBJ)/remove.o\
$(OBJ)/scite_utils.o $(OBJ)/script.o $(OBJ)/sort.o $(OBJ)/statusbar.o\
$(OBJ)/string_utils.o $(OBJ)/tree_manipulation.o
GRAPHICS_INCLUDES=$(GRPH)/dir-close.xpm \
$(GRPH)/dir-open.xpm \
$(GRPH)/sciteproj.xpm
ifndef PREFIX
ifdef INSTALL_PREFIX
PREFIX=$(INSTALL_PREFIX)
else
PREFIX=/usr/local
endif
endif
NAME=sciteproj
PROG=${BIN}/${NAME}
DEPEND=Makefile.dep
DATADIR= ${DESTDIR}${PREFIX}/share
LOCALEDIR = ${DATADIR}/locale
VERSION=$(shell cat ./VERSION)
ifdef GTK2
PKG_GTK=gtk+-2.0
CHECK_GTK3=1
else
PKG_GTK=gtk+-3.0
endif
LIB_CFLAGS=$(shell pkg-config --cflags --silence-errors $(PKG_GTK) $(PKG_WNCK) lua5.1 || pkg-config --cflags $(PKG_GTK) $(PKG_WNCK) lua)
STD_LDFLAGS=
LIBS=-lX11 $(shell pkg-config --libs --silence-errors $(PKG_GTK) $(PKG_WNCK) lua5.1 || pkg-config --libs $(PKG_GTK) $(PKG_WNCK) lua)
LOCAL_CFLAGS=$(STD_CFLAGS) $(DEPRECATED) $(CFLAGS) $(LIB_CFLAGS)
LOCAL_LDFLAGS=$(STD_CFLAGS) $(LDFLAGS) $(STD_LDFLAGS)
LOCAL_CPPFLAGS=$(CPPFLAGS)
ifdef CHECK_GTK3
LOCAL_CFLAGS+=-DGTK_DISABLE_SINGLE_INCLUDES
LOCAL_CFLAGS+=-DGSEAL_ENABLE
CHECK_DEPRECATED=1
endif
ifdef CHECK_DEPRECATED
LOCAL_CFLAGS+=-DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
endif
LOCAL_CFLAGS+=-DLOCALEDIR=\"$(LOCALEDIR)\" -DPACKAGE=\"$(NAME)\" -DSCITEPROJ_VERSION=\"$(VERSION)\"
all: $(BIN)/$(NAME)
${MAKE} -C po -j1 all
$(OBJ)/%.o: $(SRC)/%.c
$(CC) $(LOCAL_CFLAGS) $(LOCAL_CPPFLAGS) -c $< -o $@
$(BIN)/$(NAME): $(OBJECTS)
$(CC) $(LOCAL_CFLAGS) $(LOCAL_LDFLAGS) $(OBJECTS) -o $(PROG) $(LIBS)
clean:
rm -rf $(OBJECTS) $(PROG) $(DEPEND)
${MAKE} -C po clean
install:
install -d $(DESTDIR)$(PREFIX)/bin
install -m 755 $(PROG) $(DESTDIR)$(PREFIX)/bin
install -d $(DESTDIR)$(PREFIX)/share/pixmaps
install -m 644 graphics/sciteproj.xpm $(DESTDIR)$(PREFIX)/share/pixmaps
${MAKE} -C po install
uninstall:
rm -f $(DESTDIR)$(PREFIX)/$(PROG)
rm -f $(DESTDIR)$(PREFIX)/share/pixmaps/sciteproj.xpm
${MAKE} -C po uninstall
$(DEPEND):
$(CC) $(LOCAL_CFLAGS) -MM $(SRC)/*.c | sed -e "s/\([A-Za-z0-9+-0._&+-]*:\)/\$(OBJ)\/\1/g" > $(DEPEND)
-include $(DEPEND)
sciteproj-1.05/bin/ 0000755 0001750 0001750 00000000000 12570535072 013567 5 ustar gusnan gusnan sciteproj-1.05/bin/placeholder.txt 0000644 0001750 0001750 00000000000 12570535072 016600 0 ustar gusnan gusnan sciteproj-1.05/src/ 0000755 0001750 0001750 00000000000 12570535072 013606 5 ustar gusnan gusnan sciteproj-1.05/src/folder_config.c 0000644 0001750 0001750 00000001477 12570535072 016563 0 ustar gusnan gusnan /**
* folder_config.c - per folder configuration loaded from LUA
*
* Copyright 2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include "folder_config.h"
/**
*
*/
sciteproj-1.05/src/statusbar.c 0000644 0001750 0001750 00000005465 12570535072 015774 0 ustar gusnan gusnan /**
* statusbar.c - statusbar for SciteProj
*
* Copyright 2009-2014 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include "statusbar.h"
#define APP_SCITEPROJ_ERROR g_quark_from_static_string("APP_GUI_ERROR")
GtkWidget *statusbar = NULL;
guint context_id;
/**
* init_statusbar
*/
gboolean init_statusbar(GtkWidget *widget, GtkWidget *next_to, GError **err)
{
statusbar = gtk_statusbar_new();
if (!statusbar) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Could not init statusbar", __func__);
return FALSE;
}
// gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar),TRUE);
gtk_widget_set_size_request(statusbar, 1, -1);
context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "Info");
set_statusbar_text(_("Welcome to SciteProj\n"));
gtk_widget_set_size_request(statusbar, -1, 20);
#if GTK_MAJOR_VERSION >= 3
gtk_grid_attach_next_to(GTK_GRID(widget), statusbar, next_to, GTK_POS_BOTTOM, 1, 1);
#else
gtk_box_pack_end (GTK_BOX (widget), statusbar, FALSE, FALSE, 0);
#endif
gtk_widget_show (statusbar);
return TRUE;
}
/**
* set_statusbar_text
*/
void set_statusbar_text(const gchar *text)
{
if (statusbar) {
int co = 0;
// new string - fill it with characters from text indata, but skip
// non-showable characters.
gchar *newstring = (gchar*)(g_malloc((int)(strlen(text) + 1)));
int newco = 0;
for (co = 0; co < (int)strlen(text); co++) {
if (text[co] != '\n') {
newstring[newco] = text[co];
newco++;
}
}
newstring[newco] = '\0';
// Pop what message that was previously on the statusbar stack
gtk_statusbar_pop(GTK_STATUSBAR(statusbar), context_id);
// Push the new message (the statusbar will show the message that
// is on top of the statusbar stack, the one pushed will be shown)
// We popped the last one, because we don't take advantage of the
// context_id system of the statusbar.
gtk_statusbar_push(GTK_STATUSBAR(statusbar), context_id, newstring);
g_free(newstring);
}
}
/**
* done_statusbar
*/
void done_statusbar()
{
if (statusbar!=NULL) gtk_widget_destroy(statusbar);
}
sciteproj-1.05/src/clicked_node.h 0000644 0001750 0001750 00000002020 12570535072 016354 0 ustar gusnan gusnan /**
* clicked_node.h - clicked node struct for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_CLICKED_NODE_
#define __HEADER_CLICKED_NODE_
/**
*
*/
struct ClickedNode
{
gboolean valid;
GtkTreeIter iter;
gchar *name;
gint type;
};
typedef struct ClickedNode ClickedNode;
#endif /*__HEADER_CLICKED_NODE_*/
sciteproj-1.05/src/gtk3_compat.h 0000644 0001750 0001750 00000002313 12570535072 016171 0 ustar gusnan gusnan /**
* gtk3_compat.h - GTK3 compatibility definitions
*
* Copyright 2011-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_GTK3_COMPAT_
#define __HEADER_GTK3_COMPAT_
#include
#include
#ifndef GDK_KEY_Return
#define GDK_KEY_BackSpace GDK_BackSpace
#define GDK_KEY_Delete GDK_Delete
#define GDK_KEY_Insert GDK_Insert
#define GDK_KEY_Return GDK_Return
#define GDK_KEY_KP_Enter GDK_KP_Enter
#define GDK_KEY_Escape GDK_Escape
#define GDK_KEY_F2 GDK_F2
#define GDK_KEY_F5 GDK_F5
#endif
#endif /*__HEADER_GTK3_COMPAT_*/
sciteproj-1.05/src/gui.h 0000644 0001750 0001750 00000003114 12570535072 014542 0 ustar gusnan gusnan /**
* gui.h - GUI code for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_GUI_
#define __HEADER_GUI_
/**
* Variables
*/
extern gchar *window_saved_title;
extern GtkWidget *projectTreeView;
extern GtkWidget *recentTreeView;
extern GtkCellRenderer *textCellRenderer;
extern ClickedNode clicked_node;
extern GtkTreeViewColumn *column1;
extern ClickedNode clicked_node;
// Initialize the GUI
gboolean setup_gui(GError **err);
void gui_close();
// Enable/Disable the "Save Project" button
void set_save_button_sensitivity(gboolean enabled);
// Set the window title
void set_window_title(const gchar *newName);
// Is a given row expanded?
gboolean tree_row_is_expanded(GtkTreePath *path);
// Expand a row
void expand_tree_row(GtkTreePath *path, gboolean expandChildren);
gboolean dialog_response_is_exit(gint test);
void recent_files_switch_visible();
#endif /*__HEADER_GUI_*/
sciteproj-1.05/src/graphics.c 0000644 0001750 0001750 00000006052 12570535072 015555 0 ustar gusnan gusnan /**
* graphics.c - graphics code for SciteProj
*
* Copyright 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include "string_utils.h"
#include "graphics.h"
#include "about.h"
#include "../graphics/dir-close.xpm"
#include "../graphics/dir-open.xpm"
#include "../graphics/sciteproj.xpm"
#include "prefs.h"
GdkPixbuf *header_file_pixbuf = NULL;
GdkPixbuf *cpp_file_pixbuf = NULL;
GdkPixbuf *txt_file_pixbuf = NULL;
GdkPixbuf *java_file_pixbuf = NULL;
GdkPixbuf *lua_file_pixbuf = NULL;
GdkPixbuf *directory_closed_pixbuf = NULL;
GdkPixbuf *directory_open_pixbuf = NULL;
GdkPixbuf *program_icon_pixbuf = NULL;
GdkCursor *standard_cursor = NULL;
GdkCursor *busy_cursor = NULL;
#define APP_SCITEPROJ_ERROR g_quark_from_static_string("APP_GRAPHICS_ERROR")
/**
* Loads all graphics required by the program
* @return TRUE on success, FALSE on failure
* @param err returns any errors
* @param widget - we need a widget for the gtk_widget_render_icon function
*
*/
gboolean load_graphics(GtkWidget *widget, GError **err)
{
#if GTK_MAJOR_VERSION >= 3
GtkIconTheme *icon_theme;
icon_theme = gtk_icon_theme_get_default();
#endif
program_icon_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)sciteproj_xpm);
if (prefs.use_stock_folder_icon) {
// use GTK_STOCK_DIRECTORY
#if GTK_MAJOR_VERSION >= 3
directory_closed_pixbuf = gtk_icon_theme_load_icon(icon_theme, "folder", 14, 0, NULL);
directory_open_pixbuf = gtk_icon_theme_load_icon(icon_theme, "folder", 14, 0, NULL);
#else
directory_closed_pixbuf = gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
directory_open_pixbuf = gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
#endif
} else {
directory_open_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)dir_open_xpm);
directory_closed_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)dir_close_xpm);
}
GdkDisplay *default_display = NULL;
default_display = gdk_display_get_default();
standard_cursor=gdk_cursor_new_for_display(default_display, GDK_X_CURSOR);
busy_cursor=gdk_cursor_new_for_display(default_display, GDK_WATCH);
return TRUE;
}
/**
*
*/
void unload_graphics()
{
if (program_icon_pixbuf != NULL) g_object_unref(program_icon_pixbuf);
if (directory_closed_pixbuf != NULL) g_object_unref(directory_closed_pixbuf);
if (directory_open_pixbuf != NULL) g_object_unref(directory_open_pixbuf);
}
sciteproj-1.05/src/load_folder.h 0000644 0001750 0001750 00000002212 12570535072 016226 0 ustar gusnan gusnan /**
* load_folder.h - folder loading support for sciteproj
*
* Copyright 2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_LOAD_FOLDER_
#define __HEADER_LOAD_FOLDER_
gboolean ignore_pattern_matches(gchar *folder_name, const gchar *filename, GSList *filter_list);
gboolean load_folder(gchar *project_path, GError **err);
GSList *load_folder_to_list(gchar *folder_path, gboolean read_directories, GCompareFunc compare_func, GSList *filter_list);
#endif /*__HEADER_LOAD_FOLDER_*/
sciteproj-1.05/src/sort.c 0000644 0001750 0001750 00000013750 12570535072 014747 0 ustar gusnan gusnan /**
* sort.c - Helpers for sorting
*
* Copyright 2012-2013 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include "file_utils.h"
#include "sort.h"
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "script.h"
/**
*
*/
gint compare_strings_bigger(gconstpointer a, gconstpointer b)
{
const gchar *test1 = get_filename_from_full_path((gchar*)a);
const gchar *test2 = get_filename_from_full_path((gchar*)b);
return g_ascii_strcasecmp(test1, test2);
}
/**
*
*/
gint compare_strings_smaller(gconstpointer a, gconstpointer b)
{
const gchar *test1 = get_filename_from_full_path((gchar*)a);
const gchar *test2 = get_filename_from_full_path((gchar*)b);
return g_ascii_strcasecmp(test2, test1);
}
/**
*
*/
gint file_sort_by_extension_bigger_func(gconstpointer a, gconstpointer b)
{
gint result=0;
gchar *filename1 = (gchar*)a;
gchar *filename2 = (gchar*)b;
gchar *ext1 = get_file_extension(filename1);
gchar *ext2 = get_file_extension(filename2);
result = g_ascii_strcasecmp(ext1, ext2);
if (result == 0) {
result = g_ascii_strcasecmp(filename1, filename2);
}
return result;
}
/**
*
*/
gint file_sort_by_extension_smaller_func(gconstpointer a, gconstpointer b)
{
gint result=0;
gchar *filename1 = (gchar*)a;
gchar *filename2 = (gchar*)b;
gchar *ext1 = get_file_extension(filename1);
gchar *ext2 = get_file_extension(filename2);
result = g_ascii_strcasecmp(ext2, ext1);
if (result == 0) {
result = g_ascii_strcasecmp(filename2, filename1);
}
return result;
}
/**
*
*/
void sort_ascending_cb()
{
GError *err = NULL;
if (clicked_node.valid && clicked_node.type == ITEMTYPE_FILE) {
goto EXITPOINT;
}
sort_children(&(clicked_node.iter), &err, compare_strings_smaller);
EXITPOINT:
//
if (err) g_error_free(err);
}
/**
*
*/
void sort_descending_cb()
{
GError *err = NULL;
if (clicked_node.valid && clicked_node.type == ITEMTYPE_FILE) {
goto EXITPOINT;
}
sort_children(&clicked_node.iter, &err, compare_strings_bigger);
EXITPOINT:
//
if (err) g_error_free(err);
}
/**
*
*/
void sort_ascending_by_extension_cb()
{
GError *err = NULL;
if (clicked_node.valid && clicked_node.type == ITEMTYPE_FILE) {
goto EXITPOINT;
}
sort_children(&clicked_node.iter, &err, file_sort_by_extension_smaller_func);
EXITPOINT:
if (err) g_error_free(err);
}
/**
*
*/
void sort_descending_by_extension_cb()
{
GError *err = NULL;
if (clicked_node.valid && clicked_node.type == ITEMTYPE_FILE) {
goto EXITPOINT;
}
sort_children(&clicked_node.iter, &err, file_sort_by_extension_bigger_func);
EXITPOINT:
if (err) g_error_free(err);
}
/**
*
*/
GCompareFunc get_sort_order_of_folder(gchar *folder_name)
{
// We default to compare_strings_smaller
GCompareFunc result = compare_strings_smaller;
gchar *script_filename = g_build_filename(get_project_directory(),
"sciteprojrc.lua", NULL);
lua_State *lua = NULL;
if (g_file_test(script_filename, G_FILE_TEST_EXISTS)) {
int num = -1;
lua = init_script();
if (load_script(lua, script_filename) != 0) {
printf("error loading script: %s\n", script_filename);
goto EXITPOINT;
}
run_script(lua);
lua_getglobal(lua, "sort_order");
// Make sure that we have a value at all
if (lua_isnil(lua, -1)) {
goto EXITPOINT;
}
// and make sure it really is a table
if (!lua_istable(lua, -1)) {
printf("sort_order is expected to be a table!\n");
goto EXITPOINT;
}
lua_pushnil(lua);
while(lua_next(lua, -2)) {
gchar *key = NULL;
if (lua_type(lua, -2) == LUA_TSTRING) { // key type is string
key = g_strdup(lua_tostring(lua, -2));
gchar *temp = clean_folder(key);
g_free(key);
key = temp;
//printf(" key: %s\n", key);
}
if (lua_type(lua, -1) == LUA_TNUMBER) { // value is number
num = lua_tonumber(lua, -1);
//printf(" value: %d\n", num);
}
/* gboolean abs_path_to_relative_path(const gchar *absPath,
gchar **relativePath,
const gchar *basePath,
GError **err);
// convert the absolute path to a relative path
*/
gchar *relative_path = NULL;
if (g_strcmp0(folder_name, get_project_directory()) == 0) {
relative_path = g_strdup("."); //get_project_directory();
}
if (!relative_path) {
if (abs_path_to_relative_path(folder_name,
&relative_path,
get_project_directory(),
NULL)) {
//printf("relative_path: %s\n", relative_path);
}
}
//printf("Relative path: %s\n", relative_path);
gchar *folder_cleaned = clean_folder(relative_path);
//printf("folder_cleaned: %s\n", folder_cleaned);
if (g_strcmp0(key, folder_cleaned) == 0) {
switch (num)
{
case 0:
result = compare_strings_smaller;
break;
case 1:
result = compare_strings_bigger;
break;
case 2:
result = file_sort_by_extension_smaller_func;
break;
case 3:
result = file_sort_by_extension_bigger_func;
break;
};
}
if (key) g_free(key);
if (relative_path) g_free(relative_path);
if (folder_cleaned) g_free(folder_cleaned);
lua_pop(lua, 1);
}
lua_pop(lua,1);
}
EXITPOINT:
g_free(script_filename);
if (lua)
done_script(lua);
return result;
} sciteproj-1.05/src/string_utils.h 0000644 0001750 0001750 00000002104 12570535072 016502 0 ustar gusnan gusnan /**
* string_utils.h - misc string utils for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_STRING_UTILS_
#define __HEADER_STRING_UTILS_
// Append a string to a (possibly) existing string
gboolean str_append(gchar **dst, const gchar *src, GError **err);
void debug_printf(const char *st, ...);
char *remove_newline(char *s);
#endif /*__HEADER_STRING_UTILS_*/
sciteproj-1.05/src/recent_files.h 0000644 0001750 0001750 00000002310 12570535072 016415 0 ustar gusnan gusnan /**
* recent_files.h - list of recently opened files
*
* Copyright 2011-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_RECENT_FILES_
#define __HEADER_RECENT_FILES_
/**
*
*/
extern GtkWidget *recentTreeView;
//extern GtkWidget *recentPopupMenu;
GtkWidget *init_recent_files(GError **err);
gboolean add_file_to_recent(gchar *filepath, GError **err);
void popup_open_recent_file_cb();
void popup_remove_recent_file_cb();
void copy_recent_filename_to_clipboard_cb();
void properties_recent_file_cb();
#endif /*__HEADER_RECENT_FILES_*/
sciteproj-1.05/src/menus.c 0000644 0001750 0001750 00000023362 12570535072 015107 0 ustar gusnan gusnan /**
* menus.c - Menus for SciteProj
*
* Copyright 2009-2014 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "gui_callbacks.h"
#include "properties_dialog.h"
#include "menus.h"
#include "clicked_node.h"
#include "gui.h"
#include "sort.h"
#include "clipboard.h"
#include "recent_files.h"
GtkWidget *menuBar = NULL;
GtkWidget *fileMenuEntry = NULL;
GtkWidget *editMenuEntry = NULL;
GtkWidget *viewMenuEntry = NULL;
GtkWidget *helpMenuEntry = NULL;
GtkWidget *filePopupMenu = NULL;
GtkWidget *editPopupMenu = NULL;
GtkWidget *viewPopupMenu = NULL;
GtkWidget *helpPopupMenu = NULL;
GtkWidget *fileRightClickPopupMenu = NULL;
GtkWidget *groupRightClickPopupMenu = NULL;
GtkWidget *generalPopupMenu = NULL;
GtkWidget *sortPopupMenu = NULL;
GtkWidget *quitMenuItem = NULL;
GtkWidget *aboutMenuItem = NULL;
GtkWidget *sortMenuItem = NULL;
GtkWidget *sortAscendingMenuItem = NULL;
GtkWidget *sortDescendingMenuItem = NULL;
GtkWidget *sortAscendingExtensionMenuItem = NULL;
GtkWidget *sortDescendingExtensionMenuItem = NULL;
GtkWidget *openFileMenuItem = NULL;
GtkWidget *copyFilenameMenuItem = NULL;
GtkWidget *propertiesMenuItem = NULL;
GtkWidget *propertiesFileMenuItem = NULL;
GtkWidget *propertiesGroupMenuItem = NULL;
GtkWidget *showRecentFileMenuItem = NULL;
GtkWidget *menuSeparator = NULL;
GtkWidget *sortSeparator = NULL;
GtkWidget *fileRightClickSeparator = NULL;
GtkWidget *folderPopupSeparator1 = NULL;
GtkWidget *folderPopupSeparator2 = NULL;
GtkWidget *updateFolderContentMenuItem = NULL;
GtkAccelGroup *accelerator_group = NULL;
GtkWidget *recentPopupMenu = NULL;
GtkWidget *recentMenuOpenFileItem = NULL;
GtkWidget *recentMenuRemoveFileItem = NULL;
GtkWidget *recentMenuCopyFilenameItem = NULL;
GtkWidget *recentMenuPropertiesItem = NULL;
GtkWidget *recentMenuSeparator = NULL;
/**
*
*/
int init_menus(GtkWidget *window)
{
menuBar = gtk_menu_bar_new();
fileMenuEntry = gtk_menu_item_new_with_mnemonic(_("_File"));
editMenuEntry = gtk_menu_item_new_with_mnemonic(_("_Edit"));
viewMenuEntry = gtk_menu_item_new_with_mnemonic(_("_View"));
helpMenuEntry = gtk_menu_item_new_with_mnemonic(_("_Help"));
filePopupMenu = gtk_menu_new();
editPopupMenu = gtk_menu_new();
viewPopupMenu = gtk_menu_new();
helpPopupMenu = gtk_menu_new();
menuSeparator = gtk_separator_menu_item_new();
quitMenuItem = gtk_menu_item_new_with_mnemonic(_("_Quit"));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMenuEntry), filePopupMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(editMenuEntry), editPopupMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(viewMenuEntry), viewPopupMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(helpMenuEntry), helpPopupMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(filePopupMenu), quitMenuItem);
propertiesMenuItem = gtk_menu_item_new_with_mnemonic(_("Edit properties"));
gtk_menu_shell_append(GTK_MENU_SHELL(editPopupMenu), propertiesMenuItem);
g_signal_connect(G_OBJECT(propertiesMenuItem), "activate", G_CALLBACK(edit_properties_cb), NULL);
showRecentFileMenuItem = gtk_menu_item_new_with_mnemonic(_("Show Recent Files"));
g_signal_connect(G_OBJECT(showRecentFileMenuItem), "activate", G_CALLBACK(recent_files_switch_visible), NULL);
gtk_widget_add_accelerator(showRecentFileMenuItem, "activate", accelerator_group, GDK_KEY_r, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_menu_shell_append(GTK_MENU_SHELL(viewPopupMenu), showRecentFileMenuItem);
aboutMenuItem = gtk_menu_item_new_with_mnemonic(_("About"));
g_signal_connect(G_OBJECT(aboutMenuItem), "activate", G_CALLBACK(about_menu_cb), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(helpPopupMenu), aboutMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), fileMenuEntry);
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), editMenuEntry);
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), viewMenuEntry);
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), helpMenuEntry);
fileRightClickPopupMenu = gtk_menu_new();
openFileMenuItem = gtk_menu_item_new_with_mnemonic(_("Open file in SciTE"));
gtk_menu_shell_append(GTK_MENU_SHELL(fileRightClickPopupMenu), openFileMenuItem);
copyFilenameMenuItem = gtk_menu_item_new_with_mnemonic(_("Copy filename to clipboard"));
gtk_menu_shell_append(GTK_MENU_SHELL(fileRightClickPopupMenu), copyFilenameMenuItem);
fileRightClickSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(fileRightClickPopupMenu), fileRightClickSeparator);
propertiesFileMenuItem = gtk_menu_item_new_with_mnemonic(_("Properties"));
gtk_menu_shell_append(GTK_MENU_SHELL(fileRightClickPopupMenu), propertiesFileMenuItem);
g_signal_connect(G_OBJECT(openFileMenuItem), "activate", G_CALLBACK(popup_open_file_cb), NULL);
g_signal_connect(G_OBJECT(copyFilenameMenuItem), "activate", G_CALLBACK(copy_filename_to_clipboard_cb), NULL);
g_signal_connect(G_OBJECT(propertiesFileMenuItem), "activate", G_CALLBACK(file_properties_cb), NULL);
sortPopupMenu = gtk_menu_new();
sortMenuItem = gtk_menu_item_new_with_mnemonic(_("Sort folder contents"));
sortAscendingMenuItem = gtk_menu_item_new_with_mnemonic(_("Sort ascending by name"));
sortDescendingMenuItem = gtk_menu_item_new_with_mnemonic(_("Sort descending by name"));
sortAscendingExtensionMenuItem = gtk_menu_item_new_with_mnemonic(_("Sort ascending by extension"));
sortDescendingExtensionMenuItem = gtk_menu_item_new_with_mnemonic(_("Sort descending by extension"));
sortSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(sortPopupMenu), sortAscendingMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(sortPopupMenu), sortDescendingMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(sortPopupMenu), sortSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL(sortPopupMenu), sortAscendingExtensionMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(sortPopupMenu), sortDescendingExtensionMenuItem);
g_signal_connect(G_OBJECT(sortAscendingMenuItem), "activate", G_CALLBACK(sort_ascending_cb), NULL);
g_signal_connect(G_OBJECT(sortDescendingMenuItem), "activate", G_CALLBACK(sort_descending_cb), NULL);
g_signal_connect(G_OBJECT(sortAscendingExtensionMenuItem), "activate", G_CALLBACK(sort_ascending_by_extension_cb), NULL);
g_signal_connect(G_OBJECT(sortDescendingExtensionMenuItem), "activate", G_CALLBACK(sort_descending_by_extension_cb), NULL);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(sortMenuItem), sortPopupMenu);
groupRightClickPopupMenu = gtk_menu_new();
folderPopupSeparator1 = gtk_separator_menu_item_new();
folderPopupSeparator2 = gtk_separator_menu_item_new();
propertiesGroupMenuItem = gtk_menu_item_new_with_mnemonic(_("Properties"));
updateFolderContentMenuItem = gtk_menu_item_new_with_mnemonic(_("Update folder content"));
gtk_menu_shell_append(GTK_MENU_SHELL(groupRightClickPopupMenu), sortMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(groupRightClickPopupMenu), folderPopupSeparator1);
gtk_menu_shell_append(GTK_MENU_SHELL(groupRightClickPopupMenu), updateFolderContentMenuItem);
gtk_menu_shell_append(GTK_MENU_SHELL(groupRightClickPopupMenu), folderPopupSeparator2);
gtk_menu_shell_append(GTK_MENU_SHELL(groupRightClickPopupMenu), propertiesGroupMenuItem);
g_signal_connect(G_OBJECT(propertiesGroupMenuItem), "activate", G_CALLBACK(group_properties_cb), NULL);
g_signal_connect(G_OBJECT(updateFolderContentMenuItem), "activate", G_CALLBACK(refresh_folder_cb), NULL);
gtk_widget_show_all(groupRightClickPopupMenu);
gtk_widget_show_all(fileRightClickPopupMenu);
gtk_widget_show_all(GTK_WIDGET(menuBar));
gtk_widget_add_accelerator(quitMenuItem, "activate", accelerator_group, GDK_KEY_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
g_signal_connect(G_OBJECT(quitMenuItem), "activate", G_CALLBACK(quit_menu_cb), NULL);
recentPopupMenu = gtk_menu_new();
recentMenuOpenFileItem = gtk_menu_item_new_with_mnemonic(_("Open file in SciTE"));
recentMenuRemoveFileItem = gtk_menu_item_new_with_mnemonic(_("Remove file from this list"));
recentMenuCopyFilenameItem = gtk_menu_item_new_with_mnemonic(_("Copy filename to clipboard"));
recentMenuPropertiesItem = gtk_menu_item_new_with_mnemonic(_("Properties"));
recentMenuSeparator = gtk_separator_menu_item_new();
g_signal_connect(G_OBJECT(recentMenuOpenFileItem), "activate", G_CALLBACK(popup_open_recent_file_cb), NULL);
g_signal_connect(G_OBJECT(recentMenuRemoveFileItem), "activate", G_CALLBACK(popup_remove_recent_file_cb), NULL);
g_signal_connect(G_OBJECT(recentMenuCopyFilenameItem), "activate", G_CALLBACK(copy_recent_filename_to_clipboard_cb), NULL);
g_signal_connect(G_OBJECT(recentMenuPropertiesItem), "activate", G_CALLBACK(properties_recent_file_cb), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(recentPopupMenu),recentMenuOpenFileItem);
gtk_menu_shell_append(GTK_MENU_SHELL(recentPopupMenu),recentMenuRemoveFileItem);
gtk_menu_shell_append(GTK_MENU_SHELL(recentPopupMenu),recentMenuCopyFilenameItem);
gtk_menu_shell_append(GTK_MENU_SHELL(recentPopupMenu),recentMenuSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL(recentPopupMenu),recentMenuPropertiesItem);
gtk_widget_show_all(GTK_WIDGET(recentPopupMenu));
return 0;
}
/**
*
*/
void done_menus()
{
}
sciteproj-1.05/src/icon.h 0000644 0001750 0001750 00000002205 12570535072 014706 0 ustar gusnan gusnan /**
* icon.h - Icon helper functions
*
* Copyright (C) 2006 - Jesse van den Kieboom
* (C) 2012 - Andreas Rönnquist
*
* 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 .
*/
/*
This is a modified and stripped version of gedit-file-bookmarks-utils.h of
the gedit project
*/
#ifndef __HEADER_ICON_
#define __HEADER_ICON_
/**
*
*/
GdkPixbuf *get_pixbuf_from_file(GFile *file,GtkIconSize size);
GdkPixbuf *get_pixbuf_from_filename(gchar *filename, GtkIconSize size);
#endif /*__HEADER_ICON_*/
sciteproj-1.05/src/tree_manipulation.h 0000644 0001750 0001750 00000010017 12570535072 017475 0 ustar gusnan gusnan /**
* tree_manipulation.h - GtkTreeView manipulation code for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj.
* If not, see .
*
*/
#ifndef __HEADER_TREE_MANIPULATION_
#define __HEADER_TREE_MANIPULATION_
// Node relative-position indicators
enum NodePosition {
ADD_BEFORE,
ADD_AFTER,
ADD_CHILD
};
// Mnemonic identifiers for the columns in the GtkTreeStore
enum {
COLUMN_ITEMTYPE = 0,
COLUMN_FILEPATH,
COLUMN_FILENAME,
COLUMN_FILESIZE,
COLUMN_FONTWEIGHT,
COLUMN_FONTWEIGHTSET,
COLUMN_ICON,
COLUMN_EXPANDED,
COLUMN_FOLDER_CONTENT_LOADED,
COLUMN_EOL
};
// The type of each row in the tree datamodel
enum {
ITEMTYPE_GROUP,
ITEMTYPE_FILE
};
// The types for each column in the tree datamodel
#define TYPE_ITEMTYPE G_TYPE_UINT
#define TYPE_FILEPATH G_TYPE_STRING
#define TYPE_FILENAME G_TYPE_STRING
#define TYPE_FILESIZE G_TYPE_STRING
#define TYPE_FONTWEIGHT G_TYPE_INT
#define TYPE_FONTWEIGHTSET G_TYPE_BOOLEAN
#define TYPE_ICON GDK_TYPE_PIXBUF
#define TYPE_EXPANDED G_TYPE_BOOLEAN
#define TYPE_FOLDER_CONTENT_LOADED G_TYPE_BOOLEAN
typedef gint(*StringCompareFunction)(gconstpointer,gconstpointer);
// Set the Project filepath
gboolean set_project_filepath(const gchar *filepath, GError **err);
// Get the GTKTreeStore
GtkTreeStore* create_treestore(GError **err);
// Get the project file directory
const gchar* get_project_directory();
gchar* get_project_filepath();
// Allow user to select and add files to the project
gboolean add_files_to_project(GtkTreeIter *parentIter, GError **err);
// Add a file node to a GtkTreeModel
gboolean add_tree_file(GtkTreeIter *currentIter,
enum NodePosition position,
const gchar* filepath,
GtkTreeIter *newIter,
gboolean makeRelative,
GError **err);
//gboolean add_tree_filelist(GtkTreeIter *parentIter, GSList *fileList, GError **err);
gboolean add_tree_filelist(GtkTreeIter *parentIter, GSList *fileList, GError **err);
// Add a group node to a GtkTreeModel
gboolean add_tree_group(GtkTreeIter *parentIter,
enum NodePosition position,
const gchar* groupname,
const gchar* full_name,
gboolean expanded,
GtkTreeIter *newIter,
GError **err);
// Remove a node from a GtkTreeModel
gboolean remove_tree_node(GtkTreeIter *iter, GError **err);
// Remove a node from a GtkTreeModel
gboolean set_tree_node_name(GtkTreeIter *iter, const gchar *newContents, GError **err);
gboolean set_tree_node_expanded(GtkTreeIter *iter, gboolean expanded, GError **err);
gboolean set_tree_node_icon(GtkTreeIter *iter, GdkPixbuf *pixbuf, GError **err);
gboolean set_tree_node_loaded(GtkTreeIter *iter, gboolean loaded, GError **err);
// Copy a node in the tree (including children)
gboolean copy_tree_node(GtkTreeIter *srcIter,
GtkTreeIter *dstIter,
enum NodePosition position,
GtkTreeIter *newIter,
GError **err);
gchar *get_path_string(GtkTreeIter *iter);
void sort_children(GtkTreeIter *node,GError **err,StringCompareFunction compare_func);
gboolean add_tree_folderlist(GtkTreeIter *iter, GSList *folder_list, gchar *folder_path);
#endif /*__HEADER_TREE_MANIPULATION_*/
sciteproj-1.05/src/string_utils.c 0000644 0001750 0001750 00000004413 12570535072 016502 0 ustar gusnan gusnan /**
* string_utils.c - misc string utils for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include "string_utils.h"
#include "file_utils.h"
#include
#include
#include
#define APP_SCITEPROJ_ERROR g_quark_from_static_string("APP_STRINGUTILS_ERROR")
/**
* Append a string to an existing string, expanding the allocation of the string.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param dst is the string to append onto
* @param src is the string to append to dst
* @param err returns any errors
*/
gboolean str_append(gchar **dst, const gchar *src, GError **err)
{
gboolean finalResult = FALSE;
g_assert(dst != NULL);
g_assert(src != NULL);
gulong dstLength = (*dst == NULL) ? 0 : strlen(*dst);
gulong srcLength = strlen(src);
gulong totalLength = dstLength + srcLength + 1;
gchar *newDst = (gchar *) g_try_realloc(*dst, totalLength);
if (newDst == NULL) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Could not allocate memory, g_try_realloc(%ld) = NULL", __func__, totalLength);
goto EXITPOINT;
}
g_memmove(newDst + dstLength, src, srcLength + 1);
*dst = newDst;
finalResult = TRUE;
EXITPOINT:
return finalResult;
}
/**
*
*/
void debug_printf(const char *st, ...)
{
va_list ap;
va_start(ap,st);
#ifdef _DEBUG
vprintf(st,ap);
#endif
va_end(ap);
}
/**
*
*/
char *remove_newline( char *s )
{
int len=strlen(s);
if (s[len-1] == '\n') {
s[len-1] = '\0';
}
return s;
}
sciteproj-1.05/src/tree_manipulation.c 0000644 0001750 0001750 00000046200 12570535072 017473 0 ustar gusnan gusnan /**
* tree_manipulation.c - GtkTreeView manipulation code for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include "tree_manipulation.h"
#include "string_utils.h"
#include "graphics.h"
#include "prefs.h"
#include "clicked_node.h"
#include "gui.h"
#include "icon.h"
#include "file_utils.h"
#define APP_SCITEPROJ_ERROR g_quark_from_static_string("APP_TREEMANIPULATION_ERROR")
GtkTreeStore *sTreeStore = NULL;
static gchar *sProjectFilepath = NULL;
static gchar *sProjectDir = NULL;
gchar *saved_file_folder = NULL;
// Predeclare static functions
gboolean add_tree_filelist(GtkTreeIter *parentIter, GSList *fileList, GError **err);
gboolean set_project_filepath(const gchar *filepath, GError **err);
/**
* Set the project filepath
*
* @param filepath is the new project filepath
* @param err returns any error information
*/
gboolean set_project_filepath(const gchar *filepath, GError **err)
{
gboolean finalResult = FALSE;
gchar *windowTitle = NULL;
// Clear old data
if (sProjectFilepath) g_free(sProjectFilepath);
sProjectFilepath = NULL;
if (sProjectDir) g_free(sProjectDir);
sProjectDir = NULL;
// Copy the filepath
sProjectFilepath = g_strdup(filepath);
/*
// Is filepath a directory and not a file - then leave it be
if (g_file_test(filepath, G_FILE_TEST_IS_DIR)) {
sProjectDir = g_strdup(sProjectFilepath);
} else {
*/
// Extract the project's base directory
if (sProjectFilepath) {
// Check for absolut path
if (g_path_is_absolute(sProjectFilepath) == TRUE) {
sProjectDir = g_strdup(sProjectFilepath);
}
else {
if (!relative_path_to_abs_path(sProjectFilepath, &sProjectDir, NULL, err)) {
goto EXITPOINT;
}
}
if (sProjectDir[strlen(sProjectDir)-1] == G_DIR_SEPARATOR) {
gchar *finalSlash = strrchr(sProjectDir, G_DIR_SEPARATOR);
if (finalSlash != NULL) {
*finalSlash = '\0';
};
}
}
//}
windowTitle=g_strdup_printf("%s", get_filename_from_full_path(sProjectFilepath));
set_window_title(windowTitle);
finalResult = TRUE;
goto EXITPOINT;
EXITPOINT:
if (windowTitle) g_free(windowTitle);
return finalResult;
}
/**
* Get the project file directory.
*
* @return the project file's directory (pointer to static global-- do not modify!)
*/
const gchar* get_project_directory()
{
return sProjectDir;
}
/**
* Get the GTKTreeStore (evil, but necessary for setup_gui).
*
* @return the GtkTreeStore* for the project or NULL if a GtkTreeStore could not be allocate
*
* @param err returns any error information
*/
GtkTreeStore* create_treestore(GError **err)
{
if (sTreeStore == NULL) {
sTreeStore = gtk_tree_store_new(COLUMN_EOL,
TYPE_ITEMTYPE,
TYPE_FILEPATH,
TYPE_FILENAME,
TYPE_FILESIZE,
TYPE_FONTWEIGHT,
TYPE_FONTWEIGHTSET,
TYPE_ICON,
TYPE_EXPANDED,
TYPE_FOLDER_CONTENT_LOADED);
if (sTreeStore == NULL) {
g_set_error(err,
APP_SCITEPROJ_ERROR, -1, "%s: Could not create GtkTreeStore, gtk_tree_store_new() = NULL", __func__);
}
}
return sTreeStore;
}
/**
* Add a list of files to a GtkTreeStore.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param parentIter is a pointer to the parent GtkTreeIter to add to, or NULL to add to the root of the tree
* @param fileList is the list of files to add to the tree
* @param number_of_errors returns the number of files that couldn't be added due to duplicates
* @param err returns any errors
*/
gboolean add_tree_filelist(GtkTreeIter *parentIter, GSList *fileList, GError **err)
{
g_assert(sTreeStore != NULL);
g_assert(fileList != NULL);
gboolean finalResult = FALSE;
GtkTreeIter newIter;
GSList *listIter;
// Reverse the list
fileList=g_slist_reverse(fileList);
listIter = fileList;
for (listIter = fileList; listIter != NULL; listIter = g_slist_next(listIter)) {
gchar *absFilename = (gchar *) (listIter->data);
if (!absFilename) {
continue;
}
if (listIter == fileList) {
add_tree_file(parentIter, ADD_CHILD, absFilename, &newIter, TRUE, err);
}
else {
add_tree_file(&newIter, ADD_AFTER, absFilename, &newIter, TRUE, err);
}
}
finalResult = TRUE;
return finalResult;
}
/**
* Add a group node to an existing parent node, or to the root of the GtkTreeStore.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param parentIter is a pointer to the parent GtkTreeIter to add to,
* or NULL to add to the root of the tree
* @param position indicates the relative position to add the file node
* @param newIter returns the new GtkTreeIter (pass NULL if this result is not needed)
* @param groupname is the name of the group to add to the tree
* @param err returns any errors
*/
gboolean add_tree_group(GtkTreeIter *parentIter,
enum NodePosition position,
const gchar* groupname,
const gchar* full_name,
gboolean expanded,
GtkTreeIter *newIter,
GError **err)
{
g_assert(sTreeStore != NULL);
g_assert(groupname != NULL);
gboolean finalResult = FALSE;
GtkTreeIter iter;
// Append to root, or before/after/within an existing node?
// swap before and after
if (parentIter == NULL) {
gtk_tree_store_insert_before(sTreeStore, &iter, NULL, NULL);
}
else if (position == ADD_BEFORE) {
gtk_tree_store_insert_before(sTreeStore, &iter, NULL, parentIter);
}
else if (position == ADD_AFTER) {
gtk_tree_store_insert_after(sTreeStore, &iter, NULL, parentIter);
}
else if (position == ADD_CHILD) {
gtk_tree_store_insert(sTreeStore,&iter,parentIter,1000);
}
if (newIter) {
*newIter = iter;
}
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ITEMTYPE, ITEMTYPE_GROUP, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FILENAME, groupname, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FILEPATH, full_name, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FONTWEIGHT, PANGO_WEIGHT_BOLD, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FONTWEIGHTSET, TRUE, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FOLDER_CONTENT_LOADED, FALSE, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, directory_closed_pixbuf, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_EXPANDED, expanded, -1);
finalResult = TRUE;
return finalResult;
}
/**
* Add a file node to an existing parent node, or to the root of the GtkTreeStore.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param currentIter is a pointer to the parent GtkTreeIter to add to, or NULL to add to the root of the tree
* @param position indicates the relative position to add the file node
* @param filepath is the filepath to add to the tree
* @param newIter returns the GtkTreeIter that refers to the new node
* @param makeRelative indicates whether the filepath should be converted to a relative path before being added to the tree
* @param err returns any errors
*/
gboolean add_tree_file(GtkTreeIter *currentIter,
enum NodePosition position,
const gchar* filepath,
GtkTreeIter *newIter,
gboolean makeRelative,
GError **err)
{
g_assert(sTreeStore != NULL);
g_assert(filepath != NULL);
g_assert(position == ADD_BEFORE || position == ADD_AFTER || position == ADD_CHILD);
gboolean finalResult = FALSE;
GtkTreeIter iter;
const gchar* fileName = NULL;
gchar *relFilename = NULL;
gchar *fileExt=NULL;
if (!makeRelative) {
relFilename = g_strdup(filepath);
}
else if (!abs_path_to_relative_path(filepath, &relFilename, sProjectDir, err)) {
printf("abs_path_to_relative_path FAILED!\n");
goto EXITPOINT;
}
// Extract filename from filepath
fileName = get_filename_from_full_path((gchar*)filepath);
// Append to root, or before/after/within an existing node?
if (currentIter == NULL) {
gtk_tree_store_insert_before(sTreeStore, &iter, NULL, NULL);
}
else if (position == ADD_BEFORE) {
gtk_tree_store_insert_before(sTreeStore, &iter, NULL, currentIter);
}
else if (position == ADD_AFTER) {
gtk_tree_store_insert_after(sTreeStore, &iter, NULL, currentIter);
}
else if (position == ADD_CHILD) {
gtk_tree_store_insert(sTreeStore,&iter,currentIter,1000);
}
fileExt=strrchr(fileName, '.');
if (fileExt != NULL) {
++fileExt;
}
if (fileExt == NULL || strlen(fileExt) <= 0) {
fileExt = (gchar*)fileName;
}
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ITEMTYPE, ITEMTYPE_FILE, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FILEPATH, relFilename, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FILENAME, fileName, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_EXPANDED, FALSE, -1);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_FOLDER_CONTENT_LOADED, FALSE, -1);
/*
if (
(strcmp(fileExt,"cc")==0) ||
(strcmp(fileExt,"c++")==0) ||
(strcmp(fileExt,"c")==0) ||
(strcmp(fileExt,"cpp")==0)
) {
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, cpp_file_pixbuf, -1);
} else if (
(strcmp(fileExt,"hh")==0) ||
(strcmp(fileExt,"h++")==0) ||
(strcmp(fileExt,"h")==0) ||
(strcmp(fileExt,"hpp")==0)
) {
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, header_file_pixbuf, -1);
} else if (
(strcmp(fileExt,"lua")==0)
) {
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, lua_file_pixbuf, -1);
} else if (
(strcmp(fileExt,"java")==0)
) {
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, java_file_pixbuf, -1);
} else {
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, txt_file_pixbuf, -1);
}
*/
GdkPixbuf *icon_pixbuf = get_pixbuf_from_filename((gchar*)(filepath), GTK_ICON_SIZE_MENU);
gtk_tree_store_set(sTreeStore, &iter, COLUMN_ICON, icon_pixbuf, -1);
if (newIter) {
*newIter = iter;
}
finalResult = TRUE;
EXITPOINT:
if (relFilename) g_free(relFilename);
return finalResult;
}
/**
*
*/
void helper_remove(GtkTreeIter *iter)
{
GtkTreeIter *tempIter = gtk_tree_iter_copy(iter);
GtkTreeIter newIter;
if (gtk_tree_model_iter_children(GTK_TREE_MODEL(sTreeStore),&newIter,tempIter)) {
gboolean next_valid = TRUE;
do {
if (next_valid) {
gchar *nodeContents;
int itemType;
gtk_tree_model_get(GTK_TREE_MODEL(sTreeStore), &newIter,
COLUMN_ITEMTYPE, &itemType,
COLUMN_FILEPATH, &nodeContents, -1);
//gchar *fileName = get_filename_from_full_path((gchar*)nodeContents);
if (itemType == ITEMTYPE_GROUP) {
helper_remove(&newIter);
} else {
//printf("Removed: %s, %s\n",fileName,nodeContents);
//remove_item(fileName,nodeContents);
}
}
next_valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(sTreeStore), &newIter);
} while(next_valid);
}
}
/**
* Remove a node from the GtkTreeStore.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param iter references the node to remove
* @param err returns any errors
*/
extern gboolean remove_tree_node(GtkTreeIter *iter, GError **err)
{
gchar *file_path;
int itemType;
// Get the node type and content
gtk_tree_model_get(GTK_TREE_MODEL(sTreeStore), iter, COLUMN_ITEMTYPE, &itemType, COLUMN_FILEPATH, &file_path, -1);
if (itemType == ITEMTYPE_GROUP) {
helper_remove(iter);
} else {
//gchar *fileName = get_filename_from_full_path((gchar*)file_path);
//remove_item(fileName,file_path);
}
gtk_tree_store_remove(sTreeStore, iter);
return TRUE;
}
/**
* Set the contents of a node. (Should only be used for directories, and not for
* adding files)
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param iter is a reference to the node to change
* @param newContents is the new content for the node
* @param err returns any errors
*/
gboolean set_tree_node_name(GtkTreeIter *iter, const gchar *newContents, GError **err)
{
g_assert(iter != NULL);
g_assert(newContents != NULL);
// What is saved on disk
gtk_tree_store_set(sTreeStore, iter, COLUMN_FILEPATH, newContents, -1);
// What is visible in gui
gtk_tree_store_set(sTreeStore, iter, COLUMN_FILENAME, newContents, -1);
return TRUE;
}
/**
* Set the icon of a node
*
* @return TRUE on success, FALSE on error
*
* @param iter is a reference to the node who's icon we want to change
* @param pixbuf is the pixbuf we want as icon
* @param err to return any error details
*
*/
gboolean set_tree_node_icon(GtkTreeIter *iter, GdkPixbuf *pixbuf, GError **err)
{
g_assert(iter != NULL);
g_assert(pixbuf != NULL);
/* What is saved on disk */
gtk_tree_store_set(sTreeStore, iter, COLUMN_ICON, pixbuf, -1);
g_object_ref(pixbuf);
return TRUE;
}
/**
* set_tree_node_expanded
*/
gboolean set_tree_node_expanded(GtkTreeIter *iter, gboolean expanded, GError **err)
{
g_assert(iter != NULL);
gtk_tree_store_set(sTreeStore, iter, COLUMN_EXPANDED, expanded, -1);
return TRUE;
}
/**
*
*/
gboolean set_tree_node_loaded(GtkTreeIter *iter, gboolean loaded, GError **err)
{
g_assert(iter != NULL);
gtk_tree_store_set(sTreeStore, iter, COLUMN_FOLDER_CONTENT_LOADED, loaded, -1);
return TRUE;
}
/**
* Copy a node (and children) within the tree.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param srcIter is a reference to the node to move
* @param dstIter is a reference to the destination node; NULL if the root of the tree
* @param newIter returns the iter of the copy
* @param position indicates where copy the node, relative to srcIter
* @param err returns any errors
*/
gboolean copy_tree_node(GtkTreeIter *srcIter,
GtkTreeIter *dstIter,
enum NodePosition position,
GtkTreeIter *newIter,
GError **err)
{
g_assert(srcIter != NULL);
g_assert(position == ADD_BEFORE || position == ADD_AFTER || position == ADD_CHILD);
gchar *nodeContents = NULL;
gboolean finalResult = FALSE;
gint itemType;
GtkTreeIter srcChildIter;
GtkTreeIter dstChildIter;
GtkTreePath *srcPath = NULL;
GtkTreePath *newPath = NULL;
gboolean groupIsExpanded = FALSE;
GtkTreeIter newGroupIter;
// Get the node type and content
gtk_tree_model_get(GTK_TREE_MODEL(sTreeStore), srcIter,
COLUMN_ITEMTYPE, &itemType,
COLUMN_FILEPATH, &nodeContents, -1);
// Add a file or group?
if (itemType == ITEMTYPE_FILE) {
if (!add_tree_file(dstIter, position, nodeContents, newIter, FALSE, err)) {
goto EXITPOINT;
}
}
else {
// Is the source group currently expanded?
srcPath = gtk_tree_model_get_path(GTK_TREE_MODEL(sTreeStore), srcIter);
groupIsExpanded = tree_row_is_expanded(srcPath);
// Add the copy of the group
if (!add_tree_group(dstIter, position, nodeContents, nodeContents, groupIsExpanded, &newGroupIter, err)) {
goto EXITPOINT;
}
if (newIter) {
*newIter = newGroupIter;
}
// Recursively copy the group's contents, too
if (gtk_tree_model_iter_children(GTK_TREE_MODEL(sTreeStore), &srcChildIter, srcIter)) {
// Copy the first child as ADD_CHILD
if (!copy_tree_node(&srcChildIter, &newGroupIter, ADD_CHILD, &dstChildIter, err)) {
goto EXITPOINT;
}
// Copy each subsequent child ADD_AFTER its prior sibling
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(sTreeStore), &srcChildIter)) {
if (!copy_tree_node(&srcChildIter, &dstChildIter, ADD_AFTER, &dstChildIter, err)) {
goto EXITPOINT;
}
}
}
// Expand the new group?
if (groupIsExpanded) {
newPath = gtk_tree_model_get_path(GTK_TREE_MODEL(sTreeStore), &newGroupIter);
expand_tree_row(newPath, FALSE);
}
}
finalResult = TRUE;
EXITPOINT:
if (nodeContents) g_free(nodeContents);
if (srcPath) gtk_tree_path_free(srcPath);
if (newPath) gtk_tree_path_free(newPath);
return finalResult;
}
/**
*
*/
void sort_children(GtkTreeIter *node,GError **err,StringCompareFunction compare_func)
{
GtkTreeIter *saved_iter=node;
GtkTreeIter childIter;
GtkTreeModel *tree_model = GTK_TREE_MODEL(sTreeStore);
gint nodeType = -1;
GSList *itemList=NULL;
if (gtk_tree_model_iter_children(tree_model,&childIter,node)) {
int q = gtk_tree_model_iter_n_children(tree_model,node);
while (q > 0) {
gchar *nodeContents;
gtk_tree_model_get(tree_model, &childIter,
COLUMN_ITEMTYPE, &nodeType,
COLUMN_FILEPATH, &nodeContents, -1);
if (nodeType == ITEMTYPE_FILE) {
gchar *newAbsPath = NULL;
relative_path_to_abs_path(nodeContents, &newAbsPath, get_project_directory(),err);
if (itemList == NULL) {
itemList = g_slist_append(itemList, newAbsPath);
} else {
itemList = g_slist_insert_sorted(itemList, newAbsPath, compare_func);
}
gtk_tree_store_remove(sTreeStore,&childIter);
} else {
gtk_tree_model_iter_next(tree_model,&childIter);
}
q--;
}
}
if (itemList != NULL)
add_tree_filelist(saved_iter, itemList, err);
GtkTreePath *path = gtk_tree_model_get_path(tree_model,saved_iter);
expand_tree_row(path, TRUE);
}
/*
struct TestStruct
{
gchar *string_to_check_for;
gboolean found;
};
typedef struct TestStruct TestStruct;
gboolean foreach_finder(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
gint nodeType=-1;
gchar *node_contents;
gtk_tree_model_get(model, iter, COLUMN_ITEMTYPE, &nodeType, COLUMN_FILENAME, &node_contents, -1);
TestStruct *test=(TestStruct*)(data);
gboolean res=FALSE;
if (g_ascii_strcasecmp(node_contents,test->string_to_check_for)==0) {
test->found=TRUE;
res=TRUE;
}
g_free(node_contents);
return res;
}
*/
/**
*
*/
gboolean add_tree_folderlist(GtkTreeIter *iter, GSList *folder_list, gchar *folder_path)
{
if (folder_list)
{
while(folder_list != NULL) {
gchar *short_filename;
gchar *current_file;
short_filename = (gchar*)(folder_list->data);
current_file=g_build_filename(folder_path, short_filename, NULL);
if (g_file_test(current_file, G_FILE_TEST_IS_DIR)) {
GtkTreeIter *new_iter = gtk_tree_iter_copy(iter);
add_tree_group(new_iter, ADD_CHILD, short_filename, current_file, TRUE, new_iter, NULL);
if (get_number_of_files_in_folder(current_file) > 0) {
add_tree_file(new_iter, ADD_CHILD, "", new_iter, FALSE, NULL);
}
}
folder_list = folder_list->next;
}
}
return TRUE;
}
sciteproj-1.05/src/icon.c 0000644 0001750 0001750 00000004312 12570535072 014702 0 ustar gusnan gusnan /*
* icon.c - Icon helper functions
*
* Copyright (C) 2006 - Jesse van den Kieboom
* (C) 2012 - Andreas Rönnquist
*
* 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 .
*/
/*
This is a modified and stripped version of gedit-file-bookmarks-utils.c of
the gedit project
*/
#include
/**
*
*/
/**
*
*/
GdkPixbuf *
get_pixbuf_from_icon(GIcon *icon, GtkIconSize size)
{
GdkPixbuf *result = NULL;
GtkIconTheme *theme;
GtkIconInfo *info;
gint width;
if (!icon)
return NULL;
theme=gtk_icon_theme_get_default();
gtk_icon_size_lookup(size, &width, NULL);
info=gtk_icon_theme_lookup_by_gicon(theme,
icon,
width,
GTK_ICON_LOOKUP_USE_BUILTIN);
if (!info)
return NULL;
result=gtk_icon_info_load_icon(info, NULL);
return result;
}
/**
*
*/
GdkPixbuf *
get_pixbuf_from_file(GFile *file, GtkIconSize size)
{
GIcon *icon;
GFileInfo *info;
GdkPixbuf *result = NULL;
info=g_file_query_info(file,
G_FILE_ATTRIBUTE_STANDARD_ICON,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
if (!info)
return NULL;
icon=g_file_info_get_icon(info);
if (icon != NULL) {
result=get_pixbuf_from_icon(icon,size);
}
g_object_unref(info);
return result;
}
/**
*
*/
GdkPixbuf *
get_pixbuf_from_filename(gchar *filename, GtkIconSize size)
{
GFile *tempfile=g_file_new_for_path(filename);
GdkPixbuf *result=get_pixbuf_from_file(tempfile, size);
return result;
}
sciteproj-1.05/src/graphics.h 0000644 0001750 0001750 00000002176 12570535072 015565 0 ustar gusnan gusnan /**
* graphics.h - graphics code for SciteProj
*
* Copyright 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_GRAPHICS_
#define __HEADER_GRAPHICS_
/**
*
*/
extern GdkPixbuf *directory_closed_pixbuf;
extern GdkPixbuf *directory_open_pixbuf;
extern GdkPixbuf *program_icon_pixbuf;
gboolean load_graphics(GtkWidget *widget, GError **err);
void unload_graphics();
extern GdkCursor *standard_cursor;
extern GdkCursor *busy_cursor;
#endif /*__HEADER_GRAPHICS_*/
sciteproj-1.05/src/expand.h 0000644 0001750 0001750 00000002037 12570535072 015240 0 ustar gusnan gusnan /**
* expand.h - expand a folder in the treeview
*
* Copyright 2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* devilspie2 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.
*
* devilspie2 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 devilspie2.
* If not, see .
*/
#ifndef __HEADER_EXPAND_
#define __HEADER_EXPAND_
/**
*
*/
void expand_tree(GtkTreeModel *tree_model, GtkTreeIter *start_iter);
void start_expand_tree(GtkTreeModel *tree_model, GtkTreeIter *iter);
gboolean get_expand_folder(gchar *folder_name);
#endif /*__HEADER_EXPAND_*/
sciteproj-1.05/src/addfiles.c 0000644 0001750 0001750 00000002753 12570535072 015534 0 ustar gusnan gusnan /**
* addfiles.c - Interface for adding files to the project
*
* Copyright 2011-2012 Andreas Rönnquist
*
* This file is part of SciteProj
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "addfiles.h"
/**
* Callback for menu manager to populate GUI widgets
*
* @param ui is the GtkUIManager
* @param widget is the GtkWidget to add to the UI
* @param container is the container to add widget to
*/
void menu_add_widget_cb(GtkUIManager *ui, GtkWidget *widget, GtkContainer *container)
{
// use Grid instead of box packing on GTK3
#if GTK_MAJOR_VERSION >= 3
gtk_grid_attach(GTK_GRID(container), widget, 0, 0, 1, 1);
#else
gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0);
#endif
gtk_widget_show(widget);
}
sciteproj-1.05/src/clipboard.h 0000644 0001750 0001750 00000001743 12570535072 015723 0 ustar gusnan gusnan /**
* clipboard.h - clipboard support for SciteProj
*
* Copyright 2010-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_CLIPBOARD_
#define __HEADER_CLIPBOARD_
/**
*
*/
void copy_filename_to_clipboard(GtkTreeModel *model, GtkTreeIter *iter);
void copy_filename_to_clipboard_cb();
#endif /*__HEADER_CLIPBOARD_*/
sciteproj-1.05/src/scite_utils.c 0000644 0001750 0001750 00000054500 12570535072 016305 0 ustar gusnan gusnan /**
* scite_utils_linux.c - Code for working with Scite (GNU/Linux version)
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "scite_utils.h"
// This is for SciteProj :
#include "prefs.h"
#include "clicked_node.h"
#include "gui.h"
#include "graphics.h"
#include "string_utils.h"
#include "statusbar.h"
#include "file_utils.h"
#define APP_SCITEPROJ_ERROR g_quark_from_static_string("APP_SCITEUTILS_ERROR")
// Indicates whether Scite was successfully forked/executed
static gboolean sSciteLaunched = FALSE;
// File descriptor of the request pipe
static int sRequestPipeFD = 0;
// File descriptor of the response pipe
static int sResponsePipeFD = 0;
// GLib GIOChannel of the response pipe
static GIOChannel* sResponsePipeGIOChannel = NULL;
// Scite executable name
static gchar *sSciteExecName0 = (gchar*)"/usr/local/bin/SciTE";
static gchar *sSciteExecName1 = (gchar*)"/usr/local/bin/scite";
static gchar *sSciteExecName2 = (gchar*)"SciTE";
static gchar *sSciteExecName3 = (gchar*)"scite";
// -----------------
// X11 display
Display *sDisplay = NULL;
// Scite X11 window
Window sSciteWin = 0;
gboolean scite_exists = FALSE;
void set_scite_launched(gboolean launched);
/**
* Determine if Scite is open and ready for communication.
*
* @return TRUE if Scite has been forked/executed and we have an open pipe, FALSE otherwise
*/
gboolean scite_ready()
{
return (sSciteLaunched && sRequestPipeFD != 0);
}
/**
* Shut down all the Scite pipes and associated GIOChannels.
*/
void shutdown_pipes()
{
if (sRequestPipeFD) {
close(sRequestPipeFD);
sRequestPipeFD = 0;
}
if (sResponsePipeGIOChannel) {
g_io_channel_unref(sResponsePipeGIOChannel);
g_io_channel_shutdown(sResponsePipeGIOChannel, FALSE, NULL);
sResponsePipeGIOChannel = NULL;
}
if (sResponsePipeFD) {
close(sResponsePipeFD);
sResponsePipeFD = 0;
}
sSciteWin = 0;
}
/**
* Callback for data-ready on the pipe we use to read from Scite. We don't actually do anything with
* the messages from Scite right now, other than echo them to the console.
*
* @param source is the GIOChannel associated with the pipe Scite writes to
* @param condition is the GIOCondition for the event that triggered the callback
* @param data is the user data item (not used)
*/
gboolean scite_pipe_read_ready_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
g_assert(source == sResponsePipeGIOChannel);
static gchar buff[1024];
gboolean finalResult = TRUE;
gsize bytes_read;
GError *error = NULL;
#ifdef DEBUG_SCITE
debug_printf("scite_pipe_read_ready_cb\n");
#endif
if (condition & G_IO_IN) {
if (g_io_channel_read_chars(source, buff, sizeof(buff) - 1, &bytes_read, &error) != G_IO_STATUS_NORMAL) {
g_print("%s: %s = %s\n",
__func__,
"g_io_channel_read_chars failed",
(error != NULL) ? error->message : "");
}
else {
if ((bytes_read-1) > 0) {
buff[bytes_read] = '\0';
// This is for SciteProj :
//if(prefs.verbosity>50) {
#ifdef DEBUG_SCITE
debug_printf("%s: read data '%s'\n", __func__, buff);
#endif
//}
// If the string ends with a newline, remove it!
int len=strlen(buff);
if (buff[len-1] == '\n') {
gchar *temp = g_strndup(buff, len-1);
g_snprintf(buff, 1024, "%s", temp);
g_free(temp);
}
// Is it the response to an "askproperty" command? Dunno why they are prefixed with "macro:stringinfo:" though....
static char *askpropertyResponse = (char*)"macro:stringinfo:";
if (g_str_has_prefix(buff, askpropertyResponse)) {
char *windowIDStr = buff + strlen(askpropertyResponse);
sSciteWin = strtol(windowIDStr, NULL, 0);
}
if (g_str_has_prefix(buff, "closed:")) {
gchar *file=get_filename_from_full_path(buff);
gchar *status_string = g_strdup_printf(_("Closed %s"),file);
set_statusbar_text(status_string);
g_free(status_string);
}
if (g_str_has_prefix(buff, "closing:")) {
set_statusbar_text(_("Closed SciTE"));
}
if (g_str_has_prefix(buff, "switched:")) {
gchar *file=get_filename_from_full_path(buff);
gchar *status_string = g_strdup_printf(_("Switched to %s"),file);
set_statusbar_text(status_string);
g_free(status_string);
}
if (g_str_has_prefix(buff, "opened:")) {
gchar *file=get_filename_from_full_path(buff);
gchar *status_string = g_strdup_printf(_("Opened %s"),file);
set_statusbar_text(status_string);
g_free(status_string);
}
}
}
}
if (condition & G_IO_ERR) {
g_print("%s: condition = G_IO_ERR\n", __func__);
finalResult = FALSE;
}
if (condition & G_IO_HUP) {
// This is for SciteProj :
if(prefs.verbosity>50) {
g_print("%s: condition = G_IO_HUP\n", __func__);
}
finalResult = FALSE;
}
if (!finalResult) {
// We want to stop monitoring this GIOChannel, so shut it all down
shutdown_pipes();
set_scite_launched(FALSE);
//~ GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Connection to current instance of Scite has been broken");
//~ gtk_dialog_run(GTK_DIALOG(dialog));
//~ gtk_widget_destroy(dialog);
}
if (error) g_error_free(error);
return finalResult;
}
/**
* Callback for the progress dialog shown when opening Scite. This callback simply sets a boolean
* pointed to by the userData paramater.
*
* @param dialog is the pointer to the dialog
* @param responseID is the responseID of the cancel button
* @param userData is a pointer to a boolean that we set to true
*/
static void cancel_button_cb(GtkDialog *dialog, gint responseID, gpointer userData)
{
if (userData) {
*((gboolean *) userData) = TRUE;
}
}
/**
* Fork and execute an instance of Scite, then connect to its "Director" pipe. This is uglier than
* I expected it to be, once I factored in the progress feedback, user cancellation, handling of
* failure of the fork/exec, etc.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param err returns any errors
*/
gboolean launch_scite(gchar *instring,GError **err)
{
debug_printf("launch_scite: %s\n", instring);
gboolean resultCode = FALSE;
gchar* ipcDirectorName = (gchar*)"ipc.director.name";
gchar* ipcSciteName = (gchar*)"ipc.scite.name";
GtkWidget* dialog = NULL;
int childPipePair[2] = { 0, 0 };
fd_set readFDS;
struct timeval timeVal;
gboolean userClickedCancel = FALSE;
gchar responsePipePath[256];
gchar requestPipePath[256];
// Clean up anything open from previous attempts/activity
shutdown_pipes();
set_scite_launched(FALSE);
if (scite_exists) {
gchar *scite_command;
char scite_arg1[256];
char scite_arg2[256];
char scite_arg3[256];
char scite_arg4[256];
static unsigned long usecsDelta = 100000;
static unsigned long usecsDialogDelay;
// We need our process id for use in forming the named pipe filenames
pid_t childPID = 0;
gulong usecs = 0;
int errCode;
pid_t ourPID = getpid();
// The response pipe will be used by Scite to send data to us
g_snprintf(responsePipePath, sizeof(responsePipePath), "/tmp/sciteproj.%ld", (unsigned long) ourPID);
if (setenv(ipcDirectorName, responsePipePath, TRUE)) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, setenv(\"%s\", \"%s\") failed, error = %s",
__func__, ipcDirectorName, responsePipePath, strerror(errCode));
goto EXITPOINT;
}
// The request pipe will be used to send data to Scite
g_snprintf(requestPipePath, sizeof(requestPipePath), "/tmp/scite.%ld", (unsigned long) ourPID);
if (setenv(ipcSciteName, requestPipePath, TRUE)) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, setenv(\"%s\", \"%s\") failed, error = %s",
__func__, ipcSciteName, requestPipePath, strerror(errCode));
goto EXITPOINT;
}
// Remove any existing files that conflict with the pipe names
if (remove(responsePipePath) && errno != ENOENT) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, remove(\"%s\") failed, error = %s",
__func__, responsePipePath, strerror(errCode));
goto EXITPOINT;
}
if (remove(requestPipePath) && errno != ENOENT) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, remove(\"%s\") failed, error = %s",
__func__, requestPipePath, strerror(errCode));
goto EXITPOINT;
}
// Now create our response pipe (Scite creates the request pipe, as long as it doesn't already exist)
if (mkfifo(responsePipePath, 0777)) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, mkfifo(\"%s\") failed, error = %s",
__func__, responsePipePath, strerror(errCode));
goto EXITPOINT;
}
// Open the Scite response pipe
if ((sResponsePipeFD = open(responsePipePath, O_RDONLY | O_NONBLOCK)) <= 0) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, open(\"%s\") failed, error = %s",
__func__, responsePipePath, strerror(errCode));
goto EXITPOINT;
}
// Hook up the Scite response pipe to our Gtk/GLib main loop
if ((sResponsePipeGIOChannel = g_io_channel_unix_new(sResponsePipeFD)) == NULL) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, g_io_channel_unix_new(\"%s\") failed, error = %s",
__func__, responsePipePath, strerror(errCode));
goto EXITPOINT;
}
if ((g_io_channel_set_encoding(sResponsePipeGIOChannel, NULL, err)) != G_IO_STATUS_NORMAL) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, g_io_channel_set_encoding( ) failed, error = %s",
__func__, (err != NULL && *err != NULL) ? (*err)->message : "");
goto EXITPOINT;
}
g_io_add_watch(sResponsePipeGIOChannel,
(GIOCondition) (G_IO_IN | G_IO_ERR | G_IO_HUP),
scite_pipe_read_ready_cb,
NULL);
// Also create a pipe pair so our child process can alert us if it fails to execute Scite
if (pipe(childPipePair)) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, pipe( ) failed, errno = %d = %s",
__func__, errCode, strerror(errCode));
goto EXITPOINT;
}
// Fix the instring
gchar *opt1 = NULL;
gchar *opt2 = NULL;
if (instring != NULL) {
int len = strlen(instring);
int split = -1;
gchar *tempstring = instring;
gchar *place = NULL;
int co;
for (co=0; co < len; co++) {
gchar temp = instring[co];
if (temp == ' ') {
split = co;
co = len;
place = tempstring;
}
tempstring++;
}
if (split != -1) {
opt1 = g_strndup(instring, split);
opt2 = g_strdup(place);
} else {
opt1 = g_strdup(instring);
}
}
debug_printf("opt1:%s\n", opt1);
debug_printf("opt2:%s\n", opt2);
// Set up the command line
if (opt1 != NULL) {
opt1 = g_strchug(opt1);
opt1 = g_strchomp(opt1);
strcpy(scite_arg1, opt1);
} else {
strcpy(scite_arg1, "");
}
if (opt2 != NULL) {
opt2 = g_strchug(opt2);
opt2 = g_strchomp(opt2);
strcpy(scite_arg2, opt2);
} else {
strcpy(scite_arg2, "");
}
strcpy(scite_arg3, "");
strcpy(scite_arg4, "");
// Fork and (we hope) exec Scite
childPID = fork();
if (childPID == -1) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, fork() failed, errno = %d = %s",
__func__, errCode, strerror(errCode));
goto EXITPOINT;
}
else if (childPID == 0) {
debug_printf("Launching:'%s','%s','%s','%s'\n",scite_arg1,scite_arg2,scite_arg3,scite_arg4);
// We are the child process, so close our end of the read pipe
close(childPipePair[0]);
if (prefs.scite_path != NULL) {
execlp(prefs.scite_path, prefs.scite_path, scite_arg1, scite_arg2, scite_arg3, scite_arg4, (char *) NULL);
} else {
// Execute Scite, if we can (Check for SciTE)
execlp(sSciteExecName0, sSciteExecName0, scite_arg1, scite_arg2, scite_arg3, scite_arg4, (char *) NULL);
// Apparently the execlp failed, so try the alternative SciTE executable name (scite)
execlp(sSciteExecName1, sSciteExecName1, scite_arg1, scite_arg2, scite_arg3, scite_arg4, (char *) NULL);
// (/usr/local/bin/SciTE)
execlp(sSciteExecName2, sSciteExecName2, scite_arg1, scite_arg2, scite_arg3, scite_arg4, (char *) NULL);
// (/usr/local/bin/scite)
execlp(sSciteExecName3, sSciteExecName3, scite_arg1, scite_arg2, scite_arg3, scite_arg4, (char *) NULL);
}
// If we get here, the execlp() failed, so tell our parent and exit
char *message = (gchar*)"Error: Could not execute Scite from child process";
int messageLength = strlen(message);
int bytesWritten;
g_print("%s: %s\n", __func__, message);
bytesWritten = write(childPipePair[1], message, messageLength);
if (bytesWritten < messageLength) {
g_print("%s: Problem sending message to parent: messageLength = %d, bytesWritten = %d\n", __func__, messageLength, bytesWritten);
}
close(childPipePair[1]);
//_exit(0);
}
// We are the parent process, and everything looks good so far
set_scite_launched(TRUE);
// Close our end of the child write pipe
close(childPipePair[1]);
childPipePair[1] = 0;
// Wait for Scite to create a request pipe, or for our child to report failure, or for the user to cancel
for (usecs = 0; ; usecs += usecsDelta) {
// If the pipe is there, stop waiting
struct stat fileStat;
if (stat(requestPipePath, &fileStat) == 0 && S_ISFIFO(fileStat.st_mode)) {
break;
}
// Did our child send back an error message?
FD_ZERO(&readFDS);
FD_SET(childPipePair[0], &readFDS);
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
if (select(childPipePair[0] + 1, &readFDS, NULL, NULL, &timeVal) > 0) {
// If the child sent *any* data, it failed to exec Scite
set_scite_launched(FALSE);
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Could not launch Scite, execlp( ) failed", __func__);
goto EXITPOINT;
}
// No luck yet, so display a progress dialog and wait a bit longer
if (usecs > usecsDialogDelay && !dialog) {
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL, _("Connecting to Scite...."));
g_signal_connect(dialog, "response", G_CALLBACK(cancel_button_cb), (void *) &userClickedCancel);
gtk_widget_show_all(dialog);
}
while (gtk_events_pending()) {
gtk_main_iteration();
}
if (userClickedCancel) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Could not connect to Scite", __func__);
goto EXITPOINT;
}
g_usleep(usecsDelta);
}
// Try to open the request pipe
if ((sRequestPipeFD = open(requestPipePath, O_WRONLY | O_NONBLOCK)) <= 0) {
errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not launch Scite, open(\"%s\") failed, error = %s",
__func__, requestPipePath, strerror(errCode));
goto EXITPOINT;
}
// Ask SciTE for the x11 window ID
scite_command = (gchar*)"askproperty:x11.windowid\n";
if (!send_scite_command(scite_command, err)) {
goto EXITPOINT;
}
// g_print("%s: Problem sending message to parent: messageLength = %d, bytesWritten = %d\n", __func__, messageLength, bytesWritten);
// Now, let's resize the new window --
// if (!send_scite_command("property:position.left=300\n", err)) {
// goto EXITPOINT;
// }
// Wow-- it all actually worked!
resultCode = TRUE;
set_statusbar_text(_("Launched SciTE"));
}
debug_printf("All done launching SciTE...\n");
EXITPOINT:
if (dialog) gtk_widget_destroy(dialog);
if (childPipePair[0]) close(childPipePair[0]);
if (childPipePair[1]) close(childPipePair[1]);
if (!resultCode) {
shutdown_pipes();
set_scite_launched(FALSE);
}
return resultCode;
}
/**
* Send a command to Scite.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param command is the command to send to Scite
* @param err returns any errors
*/
gboolean send_scite_command(gchar *command, GError **err)
{
g_assert(command != NULL);
#ifdef DEBUG_SCITE
debug_printf("send_scite_command(%s)\n",command);
#endif
gboolean resultCode = FALSE;
int commandLength = strlen(command);
// Ensure we are connected to a running instance of Scite
if (!scite_ready() && !launch_scite(NULL,err)) {
goto EXITPOINT;
}
// Send the command over the request pipe....
if ((write(sRequestPipeFD, command, commandLength)) < commandLength) {
int errCode = errno;
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not send command to Scite, write(\"%s\") failed, errno = %d = %s",
__func__, command, errCode, strerror(errCode));
goto EXITPOINT;
}
resultCode = TRUE;
EXITPOINT:
return resultCode;
}
/**
* Activate our child SciTE instance (i.e. bring it to the front)
*
* @return TRUE if SciTE could be activated; FALSE otherwise (see err for more information)
*
* @param err returns any errors
*/
gboolean activate_scite(GError **err)
{
gboolean finalResult = FALSE;
XEvent event;
Window rootWindow;
long eventMask = SubstructureRedirectMask | SubstructureNotifyMask;
// Open the X11 display, if we haven't already done so
if (sDisplay == NULL) {
char *displayName = getenv("DISPLAY");
if (displayName == NULL || *displayName == '\0') {
displayName = (char*)":0.0";
}
sDisplay = XOpenDisplay(displayName);
if (sDisplay == NULL) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not open X display, XOpenDisplay() = NULL", __func__);
goto EXITPOINT;
}
}
// Do we actually have a reference to the SciTE window?
if (sSciteWin == 0) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: Could not activate SciTE window, X11 window ID invalid", __func__);
goto EXITPOINT;
}
// Send the "_NET_ACTIVE_WINDOW" message to the ewmh-compliant window manager (we hope)
rootWindow = DefaultRootWindow(sDisplay);
event.xclient.type = ClientMessage;
event.xclient.window = sSciteWin;
event.xclient.message_type = XInternAtom(sDisplay, "_NET_ACTIVE_WINDOW", False);
event.xclient.format = 32;
event.xclient.data.l[0] = 1;
event.xclient.data.l[1] = 0;
event.xclient.data.l[2] = 0;
event.xclient.data.l[3] = 0;
event.xclient.data.l[4] = 0;
//~ g_print("%s: sDisplay = 0x%lX, message_type = 0x%lX, window = 0x%lX, rootWindow = 0x%lX\n", __func__, (long) sDisplay, (long) event.xclient.message_type, (long) event.xclient.window, (long) rootWindow);
if (!XSendEvent(sDisplay, rootWindow, False, eventMask, &event)) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Could not activate SciTE, XSendEvent() = FALSE", __func__);
}
XFlush(sDisplay);
XMapRaised(sDisplay, sSciteWin);
finalResult = TRUE;
EXITPOINT:
return finalResult;
}
/**
*
*/
void set_scite_launched(gboolean launched)
{
sSciteLaunched=launched;
}
/**
* scite_exists
*/
gboolean check_if_scite_exists()
{
// Check if a config-file exists
gboolean exists = FALSE;
#ifdef DEBUG_SCITE
debug_printf("prefs:%s\n", prefs.scite_path);
#endif
if (prefs.scite_path != NULL) {
if (g_file_test(prefs.scite_path, G_FILE_TEST_EXISTS)) exists = TRUE;
} else {
if (g_file_test(sSciteExecName0, G_FILE_TEST_EXISTS)) exists = TRUE;
if (g_file_test(sSciteExecName1, G_FILE_TEST_EXISTS)) exists = TRUE;
// Check both
gchar *test_filename = g_build_filename("/bin", sSciteExecName2, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
test_filename = g_build_filename("/usr/bin", sSciteExecName2, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
test_filename = g_build_filename("/usr/local/bin", sSciteExecName2, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
test_filename = g_build_filename("/bin", sSciteExecName3, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
test_filename = g_build_filename("/usr/bin", sSciteExecName3, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
test_filename = g_build_filename("/usr/local/bin", sSciteExecName3, NULL);
if (g_file_test(test_filename, G_FILE_TEST_EXISTS)) exists = TRUE;
if (test_filename != NULL) g_free(test_filename);
}
scite_exists = exists;
return exists;
}
/**
* init_scite_connection
* currently doesn't do anything on GNU/Linux
*/
void init_scite_connection()
{
}
/**
*
*/
gboolean open_filename(gchar *filename,gchar *project_directory,GError **err)
{
gchar *command = NULL;
if (!relative_path_to_abs_path(filename, &filename, project_directory, err)) {
return FALSE;
}
// It's a file, so try to open it
if ((command = g_strdup_printf("open:%s\n", filename)) == NULL) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: Error formatting Scite director command, g_strdup_printf() = NULL", __func__);
return FALSE;
}
else {
if (send_scite_command(command, err)) {
// Try to activate SciTE; ignore errors
activate_scite(NULL);
if (prefs.give_scite_focus == TRUE) {
send_scite_command((gchar*)"focus:0", NULL);
}
}
}
return TRUE;
}
sciteproj-1.05/src/gui.c 0000644 0001750 0001750 00000060230 12570535072 014537 0 ustar gusnan gusnan /**
* gui.c - GUI code for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2014 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "scite_utils.h"
#include "string_utils.h"
#include "prefs.h"
#include "statusbar.h"
#include "graphics.h"
#include "about.h"
#include "properties_dialog.h"
#include "file_utils.h"
#include "clipboard.h"
#include "remove.h"
#include "addfiles.h"
#include "recent_files.h"
#include "gui_callbacks.h"
#include "sort.h"
#include "menus.h"
#include "gtk3_compat.h"
// Forward-declare static functions
static gint window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data);
static void tree_row_activated_cb(GtkTreeView *treeView, GtkTreePath *path,
GtkTreeViewColumn *column, gpointer userData);
static gboolean mouse_button_pressed_cb(GtkWidget *treeView, GdkEventButton *event, gpointer userData);
//gboolean dialog_response_is_exit(gint test);
void recent_files_switch_visible();
gboolean tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key,
GtkTreeIter *iter, gpointer search_data);
gboolean is_name_valid(gchar *instring);
gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer userData);
gchar *window_saved_title = NULL;
static GtkWidget *sMainWindow = NULL;
GtkWidget *projectTreeView = NULL;
ClickedNode clicked_node;
GtkCellRenderer *textCellRenderer = NULL;
GtkCellRenderer *pixbuffCellRenderer = NULL;
GtkWidget *scrolledWindow = NULL;
GtkTreeViewColumn *column1 = NULL;
#if GTK_MAJOR_VERSION>=3
GtkWidget *recentGrid = NULL;
#else
GtkWidget *recentVbox=NULL;
#endif
GtkWidget *recentHbox = NULL;
/**
* Initialize globals (i.e. create the main window and populate it). This is a long chunk of code.
*
* @return TRUE on success, FALSE on failure (further details returned in err)
*
* @param err returns any errors
*/
gboolean setup_gui(GError **err)
{
gboolean resultCode = FALSE;
GtkTreeSelection *selection = NULL;
GtkWidget *vpaned = NULL;
GtkTreeStore *projectTreeStore = NULL;
//GtkAccelGroup* accelgroup = NULL;
GError *tempErr = NULL;
#if GTK_MAJOR_VERSION>=3
GtkWidget *grid;
GtkWidget *fullGrid = NULL;
#else
GtkWidget *vbox=NULL;
GtkWidget *hbox=NULL;
GtkWidget *statusBarVbox=NULL;
GtkWidget *fullVbox=NULL;
#endif
GtkWidget *recentScrolledWindow = NULL;
clicked_node.valid = FALSE;
clicked_node.name = NULL;
clicked_node.type = -1;
window_saved_title=g_strdup_printf(_("[UNTITLED]"));
// Create top-level window, configure it
if (!(sMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_window_new() = NULL",
__func__,
"Couldn't init main window"
);
goto EXITPOINT;
}
// TODO: call these in load_graphics instead
if (!(load_graphics(sMainWindow, err))) {
goto EXITPOINT;
}
gtk_window_set_icon(GTK_WINDOW(sMainWindow), program_icon_pixbuf);
gtk_window_set_default_icon(program_icon_pixbuf);
gtk_window_set_title(GTK_WINDOW(sMainWindow), window_saved_title);
gtk_container_set_border_width(GTK_CONTAINER(sMainWindow), 0); //3
g_signal_connect(G_OBJECT(sMainWindow), "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
// Main content of the window is a vpaned
#if GTK_MAJOR_VERSION>=3
vpaned = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
// Then we need a grid
grid = gtk_grid_new();
#else
vpaned=gtk_vpaned_new();
// Then we need a vbox
if (!(vbox = gtk_vbox_new(FALSE, 0))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_vbox_new() = NULL",
__func__,
"Couldn't init main vbox"
);
goto EXITPOINT;
}
//gtk_container_add(GTK_CONTAINER(sMainWindow), vbox);
#endif
// Create menus
/*
if (!(sActionGroup = gtk_action_group_new("SciteProjActions"))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_action_group_new() = NULL",
__func__,
"Couldn't init gtk_action_group"
);
goto EXITPOINT;
}
*/
/*
if (!(sGtkUIManager = gtk_ui_manager_new())) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_ui_manager_new() = NULL",
__func__,
"Couldn't init gtk_ui_manager"
);
goto EXITPOINT;
}
*/
#if GTK_MAJOR_VERSION>=3
//g_signal_connect(sGtkUIManager, "add_widget", G_CALLBACK(menu_add_widget_cb), grid);
#else
//g_signal_connect(sGtkUIManager, "add_widget", G_CALLBACK(menu_add_widget_cb), vpaned);
// g_signal_connect(sGtkUIManager, "add_widget", G_CALLBACK(menu_add_widget_cb), vbox);
#endif
// Fix the context-based translations for the menu strings
/*
int co=0;
gchar *temp=NULL;
gchar *context=NULL;
do {
context=menustrings[co].context;
if (context!=NULL) {
temp = (gchar*)g_dpgettext2(PACKAGE,menustrings[co].context,menustrings[co].string);
if (temp!=NULL) {
sMenuActions[co].label = g_strdup_printf("%s",temp);
++co;
}
}
} while (context!=NULL);
*/
/*
gtk_action_group_set_translation_domain(sActionGroup,PACKAGE);
gtk_action_group_add_actions(sActionGroup, sMenuActions, sNumMenuActions, NULL);
gtk_ui_manager_insert_action_group(sGtkUIManager, sActionGroup, 0);
if (gtk_ui_manager_add_ui_from_string(sGtkUIManager, sMenuDefXML, strlen(sMenuDefXML), &tempErr) == 0) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_ui_manager_add_ui_from_string() = %s",
__func__,
"Couldn't init menus from XML",
tempErr->message
);
goto EXITPOINT;
}
gtk_ui_manager_ensure_update(sGtkUIManager);
*/
// Activate the keyboard accelerators
accelerator_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(sMainWindow), accelerator_group);
/*
// Create popup menus (shown when user right-clicks in gui elements)
sGeneralPopupMenu = gtk_ui_manager_get_widget(sGtkUIManager, "/ui/GeneralPopup");
sGroupPopupMenu = gtk_ui_manager_get_widget(sGtkUIManager, "/ui/GroupPopup");
//sFilePopupMenu = gtk_ui_manager_get_widget(sGtkUIManager, "/ui/FilePopup");
*/
//sFilePopupMenu = gtk_menu_new();
if (init_menus(sMainWindow)!=0) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_scrolled_window_new() = NULL",
__func__,
"Couldn't init menus"
);
goto EXITPOINT;
}
/*
recentPopupMenu = gtk_ui_manager_get_widget(sGtkUIManager, "/ui/RecentPopup");
sSortPopupMenu = gtk_ui_manager_get_widget(sGtkUIManager, "/ui/SortPopup");
*/
// Add a scrolled window to the main window
if (!(scrolledWindow = gtk_scrolled_window_new(NULL, NULL))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_scrolled_window_new() = NULL",
__func__,
"Couldn't init main scrolled window"
);
goto EXITPOINT;
}
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
#if GTK_MAJOR_VERSION>=3
gtk_grid_attach(GTK_GRID(grid), scrolledWindow, 0, 1, 1, 1);
gtk_widget_set_vexpand(scrolledWindow, TRUE);
gtk_widget_set_hexpand(scrolledWindow, TRUE);
#else
gtk_box_pack_start(GTK_BOX(vbox), scrolledWindow, TRUE, TRUE, 0);
hbox=gtk_hbox_new(FALSE,0);
gtk_widget_show(hbox);
gtk_box_pack_end(GTK_BOX(vbox),hbox,FALSE,TRUE,0);
#endif
// Create the tree datastore
if ((projectTreeStore = create_treestore(&tempErr)) == NULL) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s",
tempErr->message,
"Couldn't init treestore"
);
goto EXITPOINT;
}
// Create the treeview, set it up to render the tree datastore, and add it to the hbox
if (!(projectTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(projectTreeStore)))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_tree_view_new_with_model() = NULL",
__func__,
"Couldn't init gtk_tree_view"
);
goto EXITPOINT;
}
//g_object_unref(G_OBJECT(projectTreeStore));
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(projectTreeView), TRUE);
if (!(textCellRenderer = gtk_cell_renderer_text_new())) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s, gtk_cell_renderer_text_new() = NULL",
__func__,
"Couldn't init cell renderer"
);
goto EXITPOINT;
}
g_object_set(G_OBJECT(textCellRenderer),
"editable", FALSE,
"mode", GTK_CELL_RENDERER_MODE_EDITABLE,
NULL);
if (!(pixbuffCellRenderer = gtk_cell_renderer_pixbuf_new())) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, gtk_cell_renderer_pixbuf_new() = NULL",
__func__,
"Couldn't init gtk_cell_renderer_pixbuf"
);
goto EXITPOINT;
}
if (!(column1 = gtk_tree_view_column_new())) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, gtk_tree_view_column_new() = NULL",
__func__,
"Couldn't init gtk_tree_view_column"
);
goto EXITPOINT;
}
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(projectTreeView), FALSE);
gtk_tree_view_column_set_resizable(column1, TRUE);
gtk_tree_view_column_set_min_width(column1, (int)(prefs.width*.75));
gtk_tree_view_column_pack_start(column1, pixbuffCellRenderer, FALSE);
gtk_tree_view_column_add_attribute(column1, pixbuffCellRenderer, "pixbuf", COLUMN_ICON);
gtk_tree_view_column_pack_start(column1, textCellRenderer, TRUE);
gtk_tree_view_column_add_attribute(column1, textCellRenderer, "text", COLUMN_FILENAME);
gtk_tree_view_column_add_attribute(column1, textCellRenderer, "weight", COLUMN_FONTWEIGHT);
gtk_tree_view_column_add_attribute(column1, textCellRenderer, "weight-set", COLUMN_FONTWEIGHTSET);
//g_signal_connect(G_OBJECT(textCellRenderer), "edited", G_CALLBACK(rename_cb), NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(projectTreeView), column1);
// Stoopid gtk always expands the last column
gtk_container_add(GTK_CONTAINER(scrolledWindow), projectTreeView);
// Get tree events
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(projectTreeView));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
g_signal_connect(G_OBJECT(projectTreeView), "row-activated",
G_CALLBACK(tree_row_activated_cb), NULL);
gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(projectTreeView),
tree_view_search_equal_func,NULL,NULL);
g_signal_connect(G_OBJECT(projectTreeView), "row-expanded",
G_CALLBACK(row_expand_or_collapse_cb), NULL);
g_signal_connect(G_OBJECT(projectTreeView), "row-collapsed",
G_CALLBACK(row_expand_or_collapse_cb), NULL);
g_signal_connect(G_OBJECT(projectTreeView), "button-press-event",
G_CALLBACK(mouse_button_pressed_cb), projectTreeView);
g_signal_connect(G_OBJECT(projectTreeView), "key-press-event",
G_CALLBACK(key_press_cb), projectTreeView);
// --------------------------------
// Recent file stuff:
#if GTK_MAJOR_VERSION>=3
if (!(recentGrid = gtk_grid_new())) {
g_set_error(err, APP_SCITEPROJ_ERROR,-1,
"%s: %s, gtk_grid_new() = NULL",
"Couldn't init recent grid",
__func__);
goto EXITPOINT;
}
#else
if (!(recentVbox=gtk_vbox_new(FALSE, 0))) {
g_set_error(err, APP_SCITEPROJ_ERROR,-1,
"%s: %s, gtk_vbox_new() = NULL",
__func__,
"Couldn't init recent grid"
);
goto EXITPOINT;
}
#endif
#if GTK_MAJOR_VERSION>=3
if (!(recentHbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0))) {
#else
if (!(recentHbox=gtk_hbox_new(FALSE,0))) {
#endif
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, gtk_hbox_new() = NULL",
__func__,
"Couldn't init main vbox"
);
goto EXITPOINT;
}
if ((recentScrolledWindow = init_recent_files(&tempErr)) == NULL) {
goto EXITPOINT;
}
#if GTK_MAJOR_VERSION>=3
gtk_widget_set_vexpand(recentScrolledWindow, TRUE);
gtk_widget_set_hexpand(recentScrolledWindow, TRUE);
gtk_grid_attach(GTK_GRID(recentGrid), recentScrolledWindow, 0, 0, 1, 1);
fullGrid = gtk_grid_new();
#else
if (!(fullVbox=gtk_vbox_new(FALSE,0))) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, gtk_hbox_new() = NULL",
__func__,
"Couldn't init full_vbox"
);
goto EXITPOINT;
}
gtk_box_pack_start(GTK_BOX(recentVbox),recentScrolledWindow, TRUE,TRUE,0);
gtk_box_pack_end(GTK_BOX(recentVbox),recentHbox,FALSE,TRUE,0);
statusBarVbox=gtk_vbox_new(FALSE,0);
if (!statusBarVbox) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, gtk_hbox_new() = NULL",
__func__,
"Couldn't init statusbar_vbox"
);
goto EXITPOINT;
}
#endif
#if GTK_MAJOR_VERSION>=3
gtk_paned_pack1(GTK_PANED(vpaned), grid, TRUE, FALSE);
gtk_paned_pack2(GTK_PANED(vpaned), recentGrid, TRUE, TRUE);
#else
gtk_paned_pack1(GTK_PANED(vpaned),vbox,TRUE,FALSE);
gtk_paned_pack2(GTK_PANED(vpaned),recentVbox,TRUE,TRUE);
#endif
gtk_widget_show(vpaned);
#if GTK_MAJOR_VERSION>=3
gtk_grid_insert_row(GTK_GRID(fullGrid), 0);
gtk_grid_attach(GTK_GRID(fullGrid), vpaned, 0, 0, 1, 1);
gtk_grid_insert_row(GTK_GRID(fullGrid), 0);
gtk_grid_attach(GTK_GRID(fullGrid), menuBar, 0, 0, 1, 1);
gtk_widget_show(menuBar);
gtk_widget_show(GTK_WIDGET(fullGrid));
if (!prefs.hide_statusbar) {
if (!init_statusbar(fullGrid,vpaned, &tempErr)) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s", tempErr->message,"Error initing statusbar");
goto EXITPOINT;
}
}
gtk_container_add(GTK_CONTAINER(sMainWindow), fullGrid);
#else
gtk_box_pack_start(GTK_BOX(fullVbox),menuBar, FALSE, FALSE, 0);
gtk_widget_show(menuBar);
gtk_box_pack_start(GTK_BOX(fullVbox),vpaned,TRUE,TRUE,0);
gtk_widget_show(GTK_WIDGET(fullVbox));
if (!prefs.hide_statusbar) {
if (!init_statusbar(fullVbox,vpaned,&tempErr)) {
g_set_error(err, APP_SCITEPROJ_ERROR, -1, "%s: %s",
tempErr->message,
"Couldn't init statusbar"
);
goto EXITPOINT;
}
}
gtk_container_add(GTK_CONTAINER(sMainWindow), fullVbox);
gtk_widget_show(fullVbox);
gtk_widget_show(vpaned);
#endif
g_signal_connect(G_OBJECT(recentTreeView), "key-press-event", G_CALLBACK(key_press_cb), recentTreeView);
gtk_window_resize(GTK_WINDOW(sMainWindow), prefs.width, prefs.height);
gtk_window_move(GTK_WINDOW(sMainWindow), prefs.xpos, prefs.ypos);
int window_xsize, window_ysize;
gtk_window_get_size(GTK_WINDOW(sMainWindow), &window_xsize, &window_ysize);
gtk_paned_set_position(GTK_PANED(vpaned), (int)(window_ysize*0.75));
// Show it all....
#if GTK_MAJOR_VERSION>=3
gtk_widget_show(recentGrid);
if (!prefs.show_recent) {
gtk_widget_hide(recentGrid);
} else {
gtk_widget_show(recentGrid);
}
#else
gtk_widget_show(recentVbox);
if (!prefs.show_recent) {
gtk_widget_hide(recentVbox);
} else {
gtk_widget_show(recentVbox);
}
#endif
gtk_widget_show(projectTreeView);
gtk_widget_show(scrolledWindow);
#if GTK_MAJOR_VERSION>=3
gtk_widget_show(grid);
#else
gtk_widget_show(vbox);
#endif
gtk_widget_show(sMainWindow);
resultCode = TRUE;
EXITPOINT:
if (tempErr) g_error_free(tempErr);
return resultCode;
}
/**
*
*/
void gui_close()
{
if (window_saved_title) g_free(window_saved_title);
if (scrolledWindow) gtk_widget_destroy(scrolledWindow);
unload_graphics();
done_statusbar();
if (sMainWindow) gtk_widget_destroy(sMainWindow);
}
/**
* Determine whether a specified row in the tree is expanded.
*
* @return TRUE if the row is expanded; FALSE otherwise
*
* @param path is the GtkTreePath referencing the row
*/
gboolean tree_row_is_expanded(GtkTreePath *path)
{
g_assert(path != NULL);
return gtk_tree_view_row_expanded(GTK_TREE_VIEW(projectTreeView), path);
}
/**
* Expand a row in the tree.
*
* @param path is the GtkTreePath referencing the row
* @param expandChildren indicates whether all children should be expanded
*/
void expand_tree_row(GtkTreePath *path, gboolean expandChildren)
{
if (path!=NULL) {
gtk_tree_view_expand_row(GTK_TREE_VIEW(projectTreeView), path, FALSE);
}
}
/**
* Callback for Gtk "delete_event" message for the top-level application window.
*
* @param widget is not used
* @param event is not used
* @param data is not used
*/
static gint window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
gboolean eventHandled = TRUE;
gtk_main_quit();
return eventHandled;
}
/**
*
*/
static void switch_folder_icon(GtkTreeView *treeView,GtkTreePath *path)
{
GtkTreeIter iter;
gint nodeItemType;
gchar *relFilePath = NULL;
GtkTreeModel *treeModel = gtk_tree_view_get_model(treeView);
GdkPixbuf *pixbuf;
gtk_tree_model_get_iter(treeModel, &iter, path);
gtk_tree_model_get(treeModel, &iter, COLUMN_ITEMTYPE, &nodeItemType,
COLUMN_FILEPATH, &relFilePath,
COLUMN_ICON, &pixbuf,
-1);
gboolean res=gtk_tree_view_row_expanded(treeView,path);
if (res) {
gtk_tree_view_collapse_row(treeView,path);
} else {
gtk_tree_view_expand_row(treeView,path,FALSE);
}
g_free(relFilePath);
}
/**
* Callback handler for Gtk "row-activated" event.
*
* @param treeView is the GtkTreeView
* @param path is the GtkTreePath of the activated row
* @param column is not used
* @param userData is not used
*/
static void tree_row_activated_cb(GtkTreeView *treeView,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer userData)
{
GtkTreeIter iter;
gchar *relFilePath = NULL;
gchar *absFilePath = NULL;
gchar *command = NULL;
GError *err = NULL;
GtkWidget *dialog = NULL;
gint nodeItemType;
gchar *fixed = NULL;
// Get the data from the row that was activated
GtkTreeModel *treeModel = gtk_tree_view_get_model(treeView);
gtk_tree_model_get_iter(treeModel, &iter, path);
gtk_tree_model_get(treeModel, &iter, COLUMN_ITEMTYPE, &nodeItemType, COLUMN_FILEPATH, &relFilePath, -1);
// We can only open files
if (nodeItemType != ITEMTYPE_FILE) {
switch_folder_icon(treeView,path);
goto EXITPOINT;
}
absFilePath=fix_path((gchar*)get_project_directory(), relFilePath);
fixed=fix_path((gchar*)get_project_directory(), relFilePath);
if ((command = g_strdup_printf("open:%s\n", fixed)) == NULL) {
g_set_error(&err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, g_strdup_printf() = NULL",
"Error formatting SciTE command",
__func__);
}
else {
if (send_scite_command(command, &err)) {
// Try to activate SciTE; ignore errors
activate_scite(NULL);
if (prefs.give_scite_focus==TRUE) {
send_scite_command((gchar*)"focus:0", NULL);
}
add_file_to_recent(fixed,NULL);
gchar *statusbar_text = g_strdup_printf(_("Opened %s"),
remove_newline(get_filename_from_full_path(command)));
set_statusbar_text(statusbar_text);
g_free(statusbar_text);
}
}
EXITPOINT:
if (err != NULL) {
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
_("Could not open selected file: \n\n%s"), err->message);
gtk_dialog_run(GTK_DIALOG (dialog));
}
if (relFilePath) g_free(relFilePath);
if (absFilePath) g_free(absFilePath);
if (command) g_free(command);
if (err) g_error_free(err);
if (dialog) gtk_widget_destroy(dialog);
if (fixed) g_free(fixed);
}
/**
* Respond to a Gtk "button-press-event" message.
*
* @param treeView is the GTKTreeView widget in which the mouse-button event occurred
* @param event is the GdkEventButton event object
* @param userData is not currently used
*/
static gboolean mouse_button_pressed_cb(GtkWidget *treeView, GdkEventButton *event, gpointer userData)
{
gboolean eventHandled = FALSE;
GtkTreePath *path = NULL;
GtkTreeModel *treeModel = NULL;
gchar *nodeName = NULL;
gint nodeItemType;
GtkTreeIter iter;
GtkTreeSelection *tree_selection = NULL;
g_assert(treeView != NULL);
g_assert(event != NULL);
// Until we know for sure, assume that the user has not clicked on a node
clicked_node.valid=FALSE;
// If it is not a right-click, then ignore it
if (event->type != GDK_BUTTON_PRESS || event->button != 3) {
goto EXITPOINT;
}
// Find if the user has clicked on a node
if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeView),
(gint) event->x, (gint) event->y,
&path, NULL, NULL, NULL)) {
// Nope-- user clicked in the GtkTreeView, but not on a node
gtk_menu_popup(GTK_MENU(generalPopupMenu),
NULL, NULL, NULL, NULL,
event->button, gdk_event_get_time((GdkEvent*) event));
goto EXITPOINT;
}
// User clicked on a node, so retrieve the particulars
treeModel = gtk_tree_view_get_model(GTK_TREE_VIEW(treeView));
if (!gtk_tree_model_get_iter(treeModel, &iter, path)) {
goto EXITPOINT;
}
gtk_tree_model_get(treeModel, &iter, COLUMN_ITEMTYPE, &nodeItemType, COLUMN_FILEPATH, &nodeName, -1);
// Save the node info for use by the popup menu callbacks
if (clicked_node.name) g_free(clicked_node.name);
clicked_node.valid = TRUE;
clicked_node.iter = iter;
clicked_node.type = nodeItemType;
clicked_node.name = nodeName;
nodeName = NULL;
// Check if something is selected
tree_selection=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
if (tree_selection!=NULL) {
// Check if clicked on something in the selection, otherwise make the clicked one the selection.
if (gtk_tree_selection_path_is_selected(tree_selection, path)==FALSE) {
// clear selection and make current line selected
gtk_tree_selection_unselect_all(tree_selection);
gtk_tree_selection_select_path (tree_selection, path);
}
}
// Pop up the appropriate menu for the node type
if (nodeItemType == ITEMTYPE_FILE) {
gtk_menu_popup(GTK_MENU(fileRightClickPopupMenu), NULL, NULL, NULL, NULL,
event->button, gdk_event_get_time((GdkEvent*) event));
}
else if (nodeItemType == ITEMTYPE_GROUP) {
gtk_menu_popup(GTK_MENU(groupRightClickPopupMenu), NULL, NULL, NULL, NULL,
event->button, gdk_event_get_time((GdkEvent*) event));
}
// We took care of the event, so no need to propogate it
eventHandled = TRUE;
EXITPOINT:
if (path) gtk_tree_path_free(path);
if (nodeName) g_free(nodeName);
return eventHandled;
}
/**
* Set the title of the main window.
*
* @param newName is the desired new name of the window.
*/
void set_window_title(const gchar *newName)
{
g_assert(newName != NULL);
gchar *temp_string = g_new(gchar,512);
g_snprintf(temp_string,512,"%s",newName);
gtk_window_set_title(GTK_WINDOW(sMainWindow), temp_string);
g_free(window_saved_title);
window_saved_title = g_strdup_printf("%s",newName);
g_free(temp_string);
}
/**
*
*/
gboolean dialog_response_is_exit(gint test)
{
gboolean result = FALSE;
if ((test==GTK_RESPONSE_REJECT) || (test==GTK_RESPONSE_CANCEL) ||
(test==GTK_RESPONSE_DELETE_EVENT) || (test==GTK_RESPONSE_NONE)) {
result = TRUE;
}
return result;
}
/**
*
*/
void recent_files_switch_visible()
{
gboolean visible = FALSE;
#if GTK_MAJOR_VERSION>=3
g_object_get(G_OBJECT(recentGrid), "visible", &visible, NULL);
if (visible) {
gtk_widget_hide(recentGrid);
gtk_widget_grab_focus(projectTreeView);
} else {
gtk_widget_show(recentGrid);
}
#else
g_object_get(G_OBJECT(recentVbox),"visible", &visible,NULL);
if (visible) {
gtk_widget_hide(recentVbox);
gtk_widget_grab_focus(projectTreeView);
} else {
gtk_widget_show(recentVbox);
}
#endif
}
sciteproj-1.05/src/script.c 0000644 0001750 0001750 00000011120 12570535072 015251 0 ustar gusnan gusnan /**
* script.c - Script code for sciteproj
*
* Copyright 2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include "prefs.h"
#include "script.h"
#include "tree_manipulation.h"
/**
*
*/
lua_State *
init_script()
{
lua_State *lua = luaL_newstate();
if (!lua) {
printf("ERROR!\n");
return NULL;
}
luaL_openlibs(lua);
register_cfunctions(lua);
return lua;
}
/**
*
*/
void
register_cfunctions(lua_State *lua)
{
}
/**
*
*/
int
load_script(lua_State *lua, char *filename)
{
if (lua) {
int result = luaL_loadfile(lua, filename);
if (result) {
// We got an error, print it
printf("%s\n", lua_tostring(lua, -1));
lua_pop(lua, 1);
return -1;
}
} else {
return -1;
}
return 0;
}
/**
*
*/
int load_script_buffer(lua_State *lua, const char *buffer)
{
if (lua) {
int error;
error = luaL_loadbuffer(lua, buffer, strlen(buffer), "script_buffer");
if (error) {
//printf("\n\n\nERROR!\n\n\n");
fprintf(stderr, "%s\n", lua_tostring(lua, -1));
lua_pop(lua, -1);
return -1;
}
} else {
printf("invalid lua state...\n");
return -1;
}
return 0;
}
/**
*
*/
void run_script(lua_State *lua)
{
int s = lua_pcall( lua, 0, LUA_MULTRET, 0 );
if (s > 0) {
char *error_msg;
error_msg=(char*)lua_tostring( lua, -1 );
//std::string luaErrorString=getLuaErrorString(s);
/*
mssOut.str( "" );
mssOut << "Script::runScript : Error caught running script "
<< sScriptName << "\n"
<< " Error code is " << luaErrorString << ".\n"
<< " Error msg is: " << errorMsg;
throw( ScriptException( mssOut.str().c_str(), errorMsg ) );
*/
printf(_("Error: %s"), error_msg);
printf("\n");
}
}
/**
*
*/
void
done_script(lua_State *lua)
{
if (lua)
lua_close(lua);
}
/**
*
*/
GSList *load_filter_from_lua()
{
gchar *script_filename = g_build_filename(get_project_directory(), "sciteprojrc.lua", NULL);
lua_State *lua = NULL;
GSList *list = NULL;
if (g_file_test(script_filename, G_FILE_TEST_EXISTS)) {
lua = init_script();
if (load_script(lua, script_filename) != 0) {
printf("Error loading script: %s\n", script_filename);
goto EXITPOINT;
}
run_script(lua);
lua_getglobal(lua, "hide_filter");
// Make sure we got a value at all
if (lua_isnil(lua, -1)) {
goto EXITPOINT;
}
// Make sure it is a table
if (!lua_istable(lua, -1)) {
// We didn't find a table with the required name, then just exit
goto EXITPOINT;
}
lua_pushnil(lua);
while(lua_next(lua, -2)) {
if (lua_isstring(lua, -1)) {
char *temp = (char *)lua_tostring(lua, -1);
list = g_slist_append(list,g_strdup(temp));
}
lua_pop(lua,1);
}
lua_pop(lua,1);
}
EXITPOINT:
g_free(script_filename);
if (lua)
done_script(lua);
return list;
}
/**
*
*/
int lua_get_boolean(lua_State *lua, char *variable_name)
{
lua_getglobal(lua, variable_name);
int temp = 0;
gboolean result = FALSE;
//if (lua_type(lua,-1)==LUA_TBOOLEAN) {
if (lua_isboolean(lua, -1)!=0) {
temp = (int)lua_toboolean(lua, -1);
} else {
printf("%s isn't a bool!\n", variable_name);
}
lua_pop(lua, 1);
if (temp != 0) result = TRUE;
return result;
}
/**
*
*/
double lua_get_number(lua_State *lua, char *variable_name)
{
int result = -1;
lua_getglobal(lua, variable_name);
if (lua_isnumber(lua, -1) != 0) {
result = (int)lua_tonumber(lua, -1);
} else {
printf("%s isn't a number!\n", variable_name);
}
lua_pop(lua, 1);
return result;
}
/**
*
*/
int error(lua_State *L, const char *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
lua_close(L);
return 0;
}
/**
*
*/
gboolean lua_global_exists(lua_State *lua, char *variable_name)
{
gboolean result = TRUE;
lua_getglobal(lua, variable_name);
if (lua_isnil(lua, -1) != 0) {
result = FALSE;
} else {
lua_pop(lua, 1);
}
return result;
} sciteproj-1.05/src/gui_callbacks.c 0000644 0001750 0001750 00000025764 12570535072 016553 0 ustar gusnan gusnan /**
* gui_callbacks.c - GUI callback code for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "gui_callbacks.h"
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "scite_utils.h"
#include "string_utils.h"
#include "prefs.h"
#include "statusbar.h"
#include "graphics.h"
#include "about.h"
#include "properties_dialog.h"
#include "file_utils.h"
#include "addfiles.h"
#include "recent_files.h"
#include "remove.h"
#include "sort.h"
#include "load_folder.h"
#include "gtk3_compat.h"
#include "script.h"
/**
* Open the selected file.
* This is called when a file is rightclicked and open is selected in the menu
*/
void popup_open_file_cb()
{
gchar *command = NULL;
GError *err = NULL;
GtkWidget *dialog = NULL;
gchar *absFilePath = NULL;
// several files in selection?
// We can only open files
if (!clicked_node.valid || clicked_node.type != ITEMTYPE_FILE) {
goto EXITPOINT;
}
if (!open_filename(clicked_node.name, (gchar*)(get_project_directory()), &err)) {
goto EXITPOINT;
}
add_file_to_recent(clicked_node.name,NULL);
EXITPOINT:
if (err != NULL) {
dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("Could not open selected file: \n\n%s"),
err->message);
gtk_dialog_run(GTK_DIALOG (dialog));
}
if (command) g_free(command);
if (absFilePath) g_free(absFilePath);
if (err) g_error_free(err);
if (dialog) gtk_widget_destroy(dialog);
}
/**
* Open the LUA rc file for the project folder
*/
void edit_properties_cb()
{
GError *err = NULL;
gchar *command = NULL;
if ((command = g_strdup_printf("open:%s\n", prefs_filename)) == NULL) {
g_set_error(&err, APP_SCITEPROJ_ERROR, -1,
"%s: %s, g_strdup_printf() = NULL",
"Error formatting SciTE command",
__func__);
}
else {
if (send_scite_command(command, &err)) {
// Try to activate SciTE; ignore errors
activate_scite(NULL);
if (prefs.give_scite_focus==TRUE) {
send_scite_command((gchar*)"focus:0", NULL);
}
}
}
}
/**
* step-through function for expand/collapse folder
*
* @param tree_view
* @param newiter
* @param tree_path
*/
static void fix_folders_step_through(GtkTreeView *tree_view, GtkTreeIter newiter, GtkTreePath *tree_path)
{
GtkTreeModel *tree_model = gtk_tree_view_get_model(tree_view);
gchar *relFilePath;
GError *error;
gint nodeItemType;
GtkTreeIter iter=newiter;
do {
gtk_tree_model_get(tree_model, &iter, COLUMN_ITEMTYPE, &nodeItemType, -1);
if (nodeItemType==ITEMTYPE_GROUP) {
GtkTreePath *srcPath = gtk_tree_model_get_path(tree_model, &iter);
gboolean groupIsExpanded = tree_row_is_expanded(srcPath);
if (groupIsExpanded) {
set_tree_node_icon(&iter, directory_open_pixbuf, &error);
} else {
set_tree_node_icon(&iter, directory_closed_pixbuf, &error);
}
set_tree_node_expanded(&iter, groupIsExpanded, NULL);
gtk_tree_model_get(tree_model, &iter, COLUMN_FILEPATH, &relFilePath, -1);
if (gtk_tree_model_iter_has_child(tree_model, &iter)) {
GtkTreeIter newIter;
gtk_tree_model_iter_children(tree_model, &newIter, &iter);
fix_folders_step_through(tree_view,newIter, tree_path);
}
g_free(relFilePath);
gtk_tree_path_free(srcPath);
} else {
}
} while(gtk_tree_model_iter_next(tree_model,&iter));
}
/**
*
*/
void load_tree_at_iter(GtkTreeView *tree_view, GtkTreeIter *iter)
{
// We've got the folder - get the child
GtkTreeIter child;
GtkTreeModel *tree_model = gtk_tree_view_get_model(tree_view);
if (iter) {
if (gtk_tree_model_iter_children(tree_model, &child, iter)) {
remove_tree_node(&child,NULL);
gchar *folder_path;
gtk_tree_model_get(tree_model, iter, COLUMN_FILEPATH, &folder_path, -1);
// Load the wanted filter from the LUA config
GSList *filter_list=load_filter_from_lua(folder_path);
GSList *file_list; //=load_folder_to_list(folder_path, FALSE,
GSList *folder_list;
// default sorting here compare_strings_bigger - since we turn the
// list backwards after
GCompareFunc comparer=get_sort_order_of_folder(folder_path);
file_list=load_folder_to_list(folder_path, FALSE, comparer /*file_sort_by_extension_bigger_func*/, filter_list);
folder_list=load_folder_to_list(folder_path, TRUE, compare_strings_bigger, filter_list);
// Here we should filter out the unwanted items
add_tree_folderlist(iter, folder_list, folder_path);
if (file_list) {
//file_list=g_slist_reverse(file_list);
add_tree_filelist(iter, file_list, NULL);
}
set_tree_node_expanded(iter,TRUE, NULL);
GtkTreePath *tree_path = gtk_tree_model_get_path(tree_model, iter);
gtk_tree_view_expand_row(tree_view, tree_path, FALSE);
gtk_tree_path_free(tree_path);
g_slist_foreach(filter_list, (GFunc)g_free, NULL);
g_slist_free(filter_list);
}
}
}
/**
* Callback for expand/collapse event of GtkTreeView
*
* @param treeView is not used
* @param arg1 is not used
* @param arg2 is not used
* @param user_data is not used
*/
void row_expand_or_collapse_cb(GtkTreeView *tree_view, GtkTreeIter *iter,
GtkTreePath *tree_path, gpointer user_data)
{
/* Switch the folder icon open/closed*/
GtkTreeModel *tree_model = gtk_tree_view_get_model(tree_view);
// make sure all icons the folder (and folders inside it) are set to a correct icon.
fix_folders_step_through(tree_view,*iter,tree_path);
gchar *temp;
gboolean expanded;
gboolean loaded;
gtk_tree_model_get(tree_model, iter, COLUMN_FILEPATH, &temp, -1);
gtk_tree_model_get(tree_model, iter, COLUMN_EXPANDED, &expanded, -1);
gtk_tree_model_get(tree_model, iter, COLUMN_FOLDER_CONTENT_LOADED, &loaded, -1);
//printf("%s : %d\n", temp, (int)expanded);
if (!loaded) {
set_tree_node_loaded(iter, TRUE, NULL);
load_tree_at_iter(tree_view, iter);
}
}
/**
* Callback for "Quit" menu item
*/
void quit_menu_cb()
{
gtk_main_quit();
}
/**
* Callback for "About" menu item
*/
void about_menu_cb()
{
show_about_dialog();
}
/**
*
*/
gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer userData)
{
switch (event->keyval)
{
case GDK_KEY_BackSpace:
{
debug_printf((gchar*)"key_press_cb: keyval = %d = GDK_BackSpace, hardware_keycode = %d\n",
event->keyval, event->hardware_keycode);
break;
}
case GDK_KEY_Delete:
{
do_remove_node(TRUE);
break;
}
case GDK_KEY_Insert:
{
break;
}
/*
case GDK_KEY_F2:
{
do_rename_node(TRUE);
return TRUE;
}
*/
default:
{
debug_printf("key_press_cb: keyval = %d = '%c', hardware_keycode = %d\n",
event->keyval, (char) event->keyval, event->hardware_keycode);
return FALSE;
}
}
if (event->state & GDK_SHIFT_MASK) debug_printf(", GDK_SHIFT_MASK");
if (event->state & GDK_CONTROL_MASK) debug_printf(", GDK_CONTROL_MASK");
if (event->state & GDK_MOD1_MASK) debug_printf(", GDK_MOD1_MASK");
if (event->state & GDK_MOD2_MASK) debug_printf(", GDK_MOD2_MASK");
if (event->state & GDK_MOD3_MASK) debug_printf(", GDK_MOD3_MASK");
if (event->state & GDK_MOD4_MASK) debug_printf(", GDK_MOD4_MASK");
if (event->state & GDK_MOD5_MASK) debug_printf(", GDK_MOD5_MASK");
debug_printf("\n");
return FALSE;
}
/**
* search function for the gtk_tree_view_set_search_equal_func
* @return TRUE when rows DONT match, FALSE when rows match
*/
gboolean tree_view_search_equal_func(GtkTreeModel *model,gint column,
const gchar *key,GtkTreeIter *iter,
gpointer search_data)
{
gchar *filename;
// For some reason this should return TRUE if the row DONT match
gboolean res=TRUE;
gtk_tree_model_get(model, iter, COLUMN_FILENAME, &filename, -1);
// zero when matches, which means we should return FALSE
if (g_ascii_strncasecmp(key,filename,strlen(key))==0) res=FALSE;
g_free(filename);
return res;
}
/**
*
*/
void refresh_folder_cb()
{
if (!clicked_node.valid || clicked_node.type != ITEMTYPE_GROUP) {
return;
}
gchar *folder_name;
GtkTreeModel *tree_model=gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView));
GtkTreeIter iter=clicked_node.iter;
GtkTreeIter *stored_iter=gtk_tree_iter_copy(&iter);
gboolean expanded;
gtk_tree_model_get(tree_model, &iter, COLUMN_FILENAME, &folder_name,
COLUMN_EXPANDED, &expanded,
-1);
// If the folder is expanded
if (expanded) {
// add all rows below to a list of GtkTreePath
GtkTreeIter child;
GList *list_of_items=NULL;
// First, store all GtkTreePath in a linked list
if (gtk_tree_model_iter_children(tree_model, &child, &iter)) {
int co=0;
GtkTreePath *tree_path;
GtkTreeIter *temp_iter=&child;
do {
gchar *temp;
gtk_tree_model_get(tree_model, temp_iter, COLUMN_FILENAME, &temp, -1);
tree_path=gtk_tree_model_get_path(tree_model, temp_iter);
GtkTreeRowReference *row_reference=gtk_tree_row_reference_new(tree_model, tree_path);
list_of_items=g_list_append(list_of_items, row_reference);
gtk_tree_path_free(tree_path);
co++;
} while(gtk_tree_model_iter_next(tree_model, temp_iter));
// go through the list of row-references
GList *node;
for (node = list_of_items; node != NULL; node = node -> next) {
tree_path=gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
if (tree_path) {
GtkTreeIter iter;
if (gtk_tree_model_get_iter(tree_model, &iter, tree_path))
remove_tree_node(&iter,NULL);
}
}
g_list_foreach(list_of_items, (GFunc) gtk_tree_row_reference_free, NULL);
}
GtkTreeIter *temp_iter=gtk_tree_iter_copy(stored_iter);
gchar *folder;
gtk_tree_model_get(tree_model, temp_iter,
COLUMN_FILEPATH, &folder,
-1);
GtkTreeIter new_iter;
if (get_number_of_files_in_folder(folder)>0) {
add_tree_file(temp_iter, ADD_CHILD, "", &new_iter, FALSE, NULL);
}
load_tree_at_iter(GTK_TREE_VIEW(projectTreeView), temp_iter);
//set_tree_node_loaded(temp_iter, TRUE, NULL);
// get the default sort order
//sort_children(stored_iter, NULL, compare_strings_smaller);
} else {
}
}
sciteproj-1.05/src/properties_dialog.c 0000644 0001750 0001750 00000016655 12570535072 017502 0 ustar gusnan gusnan /**
* properties_dialog.c - Properties Dialogs code for SciteProj
*
* Copyright 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include
#include "properties_dialog.h"
#include "tree_manipulation.h"
#include "clicked_node.h"
#include "gui.h"
#include "string_utils.h"
#include "file_utils.h"
/**
* My set align
*/
void my_set_align(GtkWidget *widget)
{
#if GTK_MAJOR_VERSION>=3
gtk_widget_set_halign(widget, GTK_ALIGN_START);
gtk_widget_set_valign(widget, GTK_ALIGN_START);
#else
gtk_misc_set_alignment(GTK_MISC(widget), 0, 0);
#endif
}
/**
* Group properties callback
*/
void group_properties_gui(GtkTreeModel *tree_model, GtkTreeIter *iter)
{
GError *err = NULL;
GtkWidget *dialog = NULL;
gchar *nodename = NULL;
GtkWidget *table;
GtkWidget *label1,*label2;
GtkWidget *filename, *filepath_label;
gchar *filePath = NULL;
int nodeType = -1;
gtk_tree_model_get(tree_model, iter,
COLUMN_FILENAME, &nodename,
COLUMN_ITEMTYPE, &nodeType,
COLUMN_FILEPATH, &filePath,
-1);
#if GTK_MAJOR_VERSION>=3
dialog = gtk_dialog_new_with_buttons(_("Group Properties"), NULL, GTK_DIALOG_MODAL,
_("OK"), GTK_RESPONSE_ACCEPT, NULL);
#else
dialog = gtk_dialog_new_with_buttons(_("Group Properties"), NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK,GTK_RESPONSE_OK,NULL);
#endif
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
label1 = gtk_label_new(_("Group name:"));
label2 = gtk_label_new(_("Full folder:"));
filename = gtk_label_new(nodename);
filepath_label = gtk_label_new(filePath);
my_set_align(filename);
my_set_align(filepath_label);
my_set_align(label1);
my_set_align(label2);
#if GTK_MAJOR_VERSION>=3
table = gtk_grid_new();
gtk_grid_attach(GTK_GRID(table), label1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(table), label2, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(table),filename, 1, 0, 4, 1);
gtk_grid_attach(GTK_GRID(table),filepath_label,1,1,4,1);
gtk_grid_set_row_spacing (GTK_GRID (table), 6);
gtk_grid_set_column_spacing (GTK_GRID (table), 6);
#else
table = gtk_table_new(3,3,FALSE);
gtk_table_attach_defaults(GTK_TABLE(table), label1, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), label2, 0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table), filename, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), filepath_label, 1, 2, 1, 2);
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
gtk_table_set_col_spacings(GTK_TABLE(table), 5);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
#endif
GtkWidget *container_vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_box_pack_start(GTK_BOX(container_vbox), table, TRUE, TRUE, 0);
gtk_widget_show_all(dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
//EXITPOINT:
if (err) g_error_free(err);
if (dialog) gtk_widget_destroy(dialog);
}
/**
* File properties callback
*/
void file_properties_gui(GtkTreeModel *model, GtkTreeIter *iter)
{
GError *err = NULL;
gchar *nodename = NULL;
GtkWidget *table;
GtkWidget *label1, *label2, *label3;
GtkWidget *path, *filename, *filesize_label;
GtkWidget *container_vbox = NULL;
GtkWidget *dialog = NULL;
gchar *filePath = NULL;
int nodeType = -1;
gtk_tree_model_get(model, iter,
COLUMN_FILENAME, &nodename,
COLUMN_ITEMTYPE, &nodeType,
COLUMN_FILEPATH, &filePath,
-1);
debug_printf((gchar*)"Node name: %s\n", nodename);
debug_printf((gchar*)"File name: %s\n", filePath);
#if GTK_MAJOR_VERSION>=3
dialog = gtk_dialog_new_with_buttons(_("File Properties"), NULL, GTK_DIALOG_MODAL,
_("OK"), GTK_RESPONSE_ACCEPT,NULL);
#else
dialog = gtk_dialog_new_with_buttons(_("File Properties"),NULL,GTK_DIALOG_MODAL,GTK_STOCK_OK,GTK_RESPONSE_OK,NULL);
#endif
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
gchar *absFilePath = NULL; //g_strdup_printf("%s",filePath);
// filePath is NULL?
//if (!relative_path_to_abs_path(sClickedNodeName, &absFilePath, get_project_directory(), &err)) {
if (!relative_path_to_abs_path(filePath, &absFilePath, get_project_directory(), &err)) {
goto EXITPOINT;
}
gchar *size_string;
// get the size of the file
struct stat file_status;
if(stat(absFilePath, &file_status) != 0) {
perror("could not stat");
//goto EXITPOINT;
}
size_string = g_strdup_printf("%d bytes", (int)(file_status.st_size));
label1 = gtk_label_new(_("Filename:"));
label2 = gtk_label_new(_("Path:"));
label3 = gtk_label_new(_("File size:"));
filename = gtk_label_new(nodename);
path = gtk_label_new(absFilePath/*sClickedNodeName*/);
filesize_label = gtk_label_new(size_string);
my_set_align(filename);
my_set_align(path);
my_set_align(filesize_label);
my_set_align(label1);
my_set_align(label2);
my_set_align(label3);
#if GTK_MAJOR_VERSION >= 3
table = gtk_grid_new();
gtk_grid_attach(GTK_GRID(table), label1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(table), label2, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(table), label3, 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(table), filename, 1, 0, 4, 1);
gtk_grid_attach(GTK_GRID(table), path, 1, 1, 4, 1);
gtk_grid_attach(GTK_GRID(table), filesize_label, 1, 2, 4, 1);
gtk_grid_set_row_spacing (GTK_GRID (table), 6);
gtk_grid_set_column_spacing (GTK_GRID (table), 6);
#else
table=gtk_table_new(3,2,FALSE);
gtk_table_attach_defaults(GTK_TABLE(table), label1, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), label2, 0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table), label3, 0, 1, 2, 3);
gtk_table_attach_defaults(GTK_TABLE(table), filename, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), path, 1, 2, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table), filesize_label, 1, 2, 2, 3);
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
gtk_table_set_col_spacings(GTK_TABLE(table), 5);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
#endif
container_vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_box_pack_start(GTK_BOX(container_vbox), table, TRUE, TRUE, 0);
gtk_widget_show_all(dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
EXITPOINT:
if (err) g_error_free(err);
if (dialog) gtk_widget_destroy(dialog);
}
/**
*
*/
void group_properties_cb()
{
if (!clicked_node.valid || clicked_node.type != ITEMTYPE_GROUP) {
//goto EXITPOINT;
} else {
group_properties_gui(gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView)), &(clicked_node.iter));
}
}
/**
*
*/
void file_properties_cb()
{
if (!clicked_node.valid || clicked_node.type != ITEMTYPE_FILE) {
//goto EXITPOINT;
} else {
file_properties_gui(gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView)), &(clicked_node.iter));
}
}
sciteproj-1.05/src/properties_dialog.h 0000644 0001750 0001750 00000002115 12570535072 017471 0 ustar gusnan gusnan /**
* properties_dialog.h - Properties Dialogs code for SciteProj
*
* Copyright 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_PROPERTIES_DIALOG_
#define __HEADER_PROPERTIES_DIALOG_
void group_properties_gui(GtkTreeModel *model, GtkTreeIter *iter);
void file_properties_gui(GtkTreeModel *model, GtkTreeIter *iter);
void group_properties_cb();
void file_properties_cb();
#endif /*__HEADER_PROPERTIES_DIALOG_*/
sciteproj-1.05/src/clipboard.c 0000644 0001750 0001750 00000004350 12570535072 015713 0 ustar gusnan gusnan /**
* clipboard.c - clipboard code for SciteProj
*
* Copyright 2010-2015 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "file_utils.h"
#include "string_utils.h"
#include "clipboard.h"
/**
* Copies the filename including full folder to the clipboard
*/
void copy_filename_to_clipboard(GtkTreeModel *model, GtkTreeIter *iter)
{
GError *err = NULL;
gchar *nodename = NULL;
gchar *filePath = NULL;
int nodeType = -1;
GdkDisplay *display = NULL;
GtkClipboard *clipboard = NULL;
gtk_tree_model_get(model, iter,
COLUMN_FILENAME, &nodename,
COLUMN_ITEMTYPE, &nodeType,
COLUMN_FILEPATH, &filePath,
-1);
gchar *absFilePath = NULL; //g_strdup_printf("%s",filePath);
// filePath is NULL?
//if (!relative_path_to_abs_path(sClickedNodeName, &absFilePath, get_project_directory(), &err)) {
if (!relative_path_to_abs_path(filePath, &absFilePath, get_project_directory(), &err)) {
goto EXITPOINT;
}
display = gdk_display_get_default();
clipboard = gtk_clipboard_get_for_display(display, GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, absFilePath, -1);
EXITPOINT:
if (err) g_error_free(err);
}
/**
* Callback for the menu item
*/
void copy_filename_to_clipboard_cb()
{
if (!clicked_node.valid || clicked_node.type != ITEMTYPE_FILE) {
//goto EXITPOINT;
} else {
copy_filename_to_clipboard(gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView)), &(clicked_node.iter));
}
}
sciteproj-1.05/src/remove.h 0000644 0001750 0001750 00000001677 12570535072 015267 0 ustar gusnan gusnan /**
* remove.h - code for removing nodes
*
* Copyright 2011-2012 Andreas Rönnquist
*
* This file is part of SciteProj
*
* SciteProj 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.
*
* SciteProj 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 SciteProj.
* If not, see .
*/
#ifndef __HEADER_REMOVE_
#define __HEADER_REMOVE_
void do_remove_node(gboolean ignore_clicked_node);
void popup_remove_node_cb();
void removeitem_menu_cb();
#endif /*__HEADER_REMOVE_*/
sciteproj-1.05/src/remove.c 0000644 0001750 0001750 00000025351 12570535072 015255 0 ustar gusnan gusnan /**
* remove.c - code for removing nodes
*
* Copyright 2011-2012 Andreas Rönnquist
*
* This file is part of SciteProj
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*/
#include
#include
#include
#include
#include "clicked_node.h"
#include "gui.h"
#include "tree_manipulation.h"
#include "remove.h"
#include "file_utils.h"
#include "prefs.h"
/**
* delete_file
* deletes a file (or directory) from the filesystem - directories needs to
* be empty to be able to delete them.
*/
gboolean delete_file(gchar *filename,GError **error)
{
gboolean result = FALSE;
gchar *file_to_delete;
if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
file_to_delete = filename;
// We have already checked if the folder is empty
} else {
if (!relative_path_to_abs_path(filename, &file_to_delete, get_project_directory(), error)) {
result = FALSE;
goto EXITPOINT;
}
}
printf("%s\n", file_to_delete);
result=TRUE;
EXITPOINT:
return result;
}
/**
*
*/
GList *get_list_of_selected_items_rows(GtkTreeView *treeview)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
GtkTreeModel *model;
if (gtk_tree_selection_count_selected_rows(selection) == 0)
return NULL;
model = gtk_tree_view_get_model(treeview);
GList *result_list = gtk_tree_selection_get_selected_rows(selection, &model);
return result_list;
}
/**
*
*/
GList *get_list_of_selected_items_string_list(GtkTreeView *treeview)
{
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
GList *row_list = get_list_of_selected_items_rows(treeview);
GList *string_list = NULL;
// Begin at the end, and go to the start
row_list = g_list_last(row_list);
GtkTreeIter iter;
int count = 0;
while (row_list) {
GtkTreePath *path = (GtkTreePath *)row_list->data;
if (path) {
gtk_tree_model_get_iter(model, &iter, path);
gchar *path;
gtk_tree_model_get(model, &iter, COLUMN_FILEPATH, &path, -1);
string_list = g_list_prepend(string_list, path);
count++;
}
row_list = row_list -> prev;
}
g_list_foreach (row_list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (row_list);
return string_list;
}
/**
* get_list_of_selected_items_strings
* Will only give the 7 first values, orelse it probably wouldn't fit in a
* dialog
*/
gchar *get_list_of_selected_items_strings(GtkTreeView *treeview)
{
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
GList *list = get_list_of_selected_items_rows(treeview);
// Begin at the end, and go to the start
list = g_list_last(list);
GtkTreeIter iter;
gchar *result_string = g_strdup("\n\n");
int count = 0;
while (list) {
GtkTreePath *path = (GtkTreePath *)list->data;
if (path) {
gtk_tree_model_get_iter(model, &iter, path);
gchar *path;
gtk_tree_model_get(model, &iter,
COLUMN_FILEPATH, &path, -1);
if (count <7) {
gchar *temp = g_strconcat(result_string, path, "\n", NULL);
g_free(result_string);
result_string=temp;
} else if (count == 7) {
gchar *temp = g_strconcat(result_string, "...\n", NULL);
g_free(result_string);
result_string=temp;
}
count++;
}
list = list -> prev;
}
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (list);
return result_string;
}
/**
* Actually remove selected nodes
*/
void remove_selected_items ( GtkTreeView *treeview )
{
GError *error=NULL;
GtkTreeIter iter;
GtkTreeModel *model=gtk_tree_view_get_model(treeview);
GList *list = get_list_of_selected_items_rows(treeview); // gtk_tree_selection_get_selected_rows( selection, &model );
int nRemoved = 0;
// Begin at the end and go to the start
list=g_list_last(list);
while(list) {
GString *fixed_path = g_string_new("");
g_string_printf(fixed_path, "%s", gtk_tree_path_to_string((GtkTreePath*)list->data)/*ipath*/);
GtkTreePath *path = gtk_tree_path_new_from_string(fixed_path->str);
g_string_free(fixed_path, TRUE);
if (path) {
if ( gtk_tree_model_get_iter ( model, &iter, path) ) { // get iter from specified path
remove_tree_node(&iter, &error);
nRemoved++;
}
else { // invalid path
g_error(_("Error!!!\n"));
}
gtk_tree_path_free (path);
}
else {
g_error(_("Error!!!\n"));
}
list=list->prev;
}
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (list);
}
/**
*
*/
GtkWidget *do_question_dialog(const gchar *buffer)
{
GtkWidget *dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_OK_CANCEL,
"%s", buffer);
return dialog;
}
/**
*
*/
gboolean really_do_delete_question(const gchar *format, ...)
{
GtkWidget *dialog = NULL;
gint dialog_response;
char buffer[256];
gboolean result;
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
dialog = do_question_dialog(buffer);
va_end(args);
result=TRUE;
dialog_response = gtk_dialog_run(GTK_DIALOG (dialog));
if (dialog_response_is_exit(dialog_response)) {
result = FALSE;
goto EXITPOINT;
}
// Ask again to really make sure the user knows what he/she is doing.
if (result) {
gtk_widget_destroy(dialog);
gchar *extended_question_string = g_strdup_printf(
"Are you really really sure? \n"
"This will actually delete the files\n"
"from the filesystem.\n\n%s",buffer);
dialog = do_question_dialog(extended_question_string);
dialog_response=gtk_dialog_run(GTK_DIALOG(dialog));
if (dialog_response_is_exit(dialog_response)) {
result = FALSE;
goto EXITPOINT;
}
}
EXITPOINT:
gtk_widget_destroy(dialog);
return result;
}
/**
*
*/
void do_remove_node(gboolean ignore_clicked_node)
{
GError *err = NULL;
GtkWidget *dialog = NULL;
gchar *nodename = NULL;
gint selected_rows = 0;
gboolean multiple_selected = FALSE;
// Check if we are in "write-protect" mode
if (prefs.write_protect) {
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"You are in write protected mode!\n\n"
"You cannot delete anything when using sciteproj in this mode.\n"
"To be able to delete files, either use your terminal, your\n"
"file-manager of choice, or you can set the 'write_protect'\n"
"variable in your sciteprojrc.lua to false.\n");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
dialog=NULL;
goto EXITPOINT;
}
// Make sure a node has been selected
if (!ignore_clicked_node) {
if (!clicked_node.valid) {
goto EXITPOINT;
}
}
GtkTreeSelection *tree_select;
tree_select = gtk_tree_view_get_selection(GTK_TREE_VIEW(projectTreeView));
selected_rows = gtk_tree_selection_count_selected_rows(tree_select);
if (selected_rows>1) {
multiple_selected = TRUE;
}
if (!ignore_clicked_node) {
// Figure out the node name
nodename = strrchr(clicked_node.name, '/');
if (nodename) {
++nodename;
}
else {
nodename = clicked_node.name;
}
} else {
// if there is only one selected, get its name
nodename=NULL;
multiple_selected=TRUE;
}
// Confirm removal from project
if (multiple_selected) {
gchar *file_list_string = get_list_of_selected_items_strings(GTK_TREE_VIEW(projectTreeView));
gchar *question_string = g_strdup_printf("%s\n%s",_("Delete all selected items?"),file_list_string);
if (really_do_delete_question(question_string)) {
// remove them!
GList *string_list = get_list_of_selected_items_string_list(GTK_TREE_VIEW(projectTreeView));
while (string_list) {
gchar *temp = (gchar *)string_list->data;
if (!delete_file(temp, &err)) {
goto EXITPOINT;
}
string_list = string_list->next;
};
remove_selected_items(GTK_TREE_VIEW(projectTreeView));
}
g_free(file_list_string);
g_free(question_string);
} else {
gboolean really_do_delete=FALSE;
if (clicked_node.type == ITEMTYPE_FILE) {
if (nodename) {
really_do_delete = really_do_delete_question(_("Delete file '%s'?"), nodename);
} else {
really_do_delete = really_do_delete_question(_("Delete file?"));
}
}
else {
// TODO: check if the folder is empty already here before "confirmation" questions
gchar *filepath;
GtkTreeModel *tree_model = gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView));
gtk_tree_model_get(tree_model, &clicked_node.iter,
COLUMN_FILEPATH, &filepath, -1);
if (get_number_of_files_in_folder(filepath) > 0) {
GtkWidget *dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Folder need to be empty to be able to delete it!");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
goto EXITPOINT;
}
if (nodename) {
really_do_delete = really_do_delete_question(_("Delete folder '%s' and any contained files?"),nodename);
} else {
really_do_delete = really_do_delete_question(_("Delete folder and any contained files?"));
}
}
if (!really_do_delete) {
goto EXITPOINT;
}
// Delete the file
gchar *filepath;
GtkTreeModel *tree_model = gtk_tree_view_get_model(GTK_TREE_VIEW(projectTreeView));
gtk_tree_model_get(tree_model, &clicked_node.iter,
COLUMN_FILEPATH, &filepath, -1);
if (!delete_file(filepath, &err)) {
goto EXITPOINT;
}
// Remove the node
if (!remove_tree_node(&(clicked_node.iter), &err)) {
GtkWidget *errDialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
_("Could not delete the selected node: \n\n%s"),
err->message);
gtk_dialog_run(GTK_DIALOG (errDialog));
gtk_widget_destroy(errDialog);
}
}
EXITPOINT:
if (err) g_error_free(err);
if (dialog) gtk_widget_destroy(dialog);
}
sciteproj-1.05/src/statusbar.h 0000644 0001750 0001750 00000001762 12570535072 015775 0 ustar gusnan gusnan /**
* statusbar.h - statusbar for SciteProj
*
* Copyright 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_STATUSBAR_
#define __HEADER_STATUSBAR_
gboolean init_statusbar(GtkWidget *grid, GtkWidget *next_to, GError **err);
void set_statusbar_text(const gchar *text);
void done_statusbar();
#endif /*__HEADER_STATUSBAR_*/
sciteproj-1.05/src/prefs.h 0000644 0001750 0001750 00000002710 12570535072 015076 0 ustar gusnan gusnan /**
* prefs.h - prefs for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#ifndef __HEADER_PREFS_
#define __HEADER_PREFS_
#define PREFS_BUFSIZE 256
/**
*
*/
typedef struct {
int lhs;
int width, height;
int verbosity;
int last_file_filter;
int xpos,ypos;
int search_xpos,search_ypos;
int search_width,search_height;
gboolean give_scite_focus;
gboolean search_give_scite_focus;
gchar *scite_path;
gboolean show_recent;
gboolean recent_add_to_bottom;
gboolean hide_statusbar;
gboolean use_stock_folder_icon;
gboolean write_protect;
gboolean start_scite;
} sciteproj_prefs;
extern sciteproj_prefs prefs;
extern gchar *prefs_filename;
gboolean init_prefs(gchar *target_directory, GError **error);
void done_prefs();
#endif /*__HEADER_PREFS_*/
sciteproj-1.05/src/prefs.c 0000644 0001750 0001750 00000024304 12570535072 015074 0 ustar gusnan gusnan /**
* prefs.c - prefs for SciteProj
*
* Copyright 2006 Roy Wood, 2009-2012 Andreas Rönnquist
*
* This file is part of SciteProj.
*
* SciteProj 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.
*
* SciteProj 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 SciteProj. If not, see .
*
*/
#include
#include
#include
#include
#include
#include "prefs.h"
#include "string_utils.h"
#include "script.h"
#include "file_utils.h"
/**
*
*/
gboolean check_for_old_style_config();
int load_lua_config(gchar *filename, gchar *full_string);
/**
*
*/
sciteproj_prefs prefs;
gchar *prefs_filename;
gchar *default_config_string = (gchar*)"" \
"-----------------------------\n"
"-- Configuration for SciteProj\n"
"-----------------------------\n"
"\n"
"-- Window geometry:\n"
"xpos=40\n"
"ypos=40\n"
"width=200\n"
"height=400\n"
"\n"
"-- Search window geometry (-1 on xpos and ypos means default center screen):\n"
"search_xpos=-1\n"
"search_ypos=-1\n"
"search_width=500\n"
"search_height=400\n"
"\n"
"search_alert_file_warnings=TRUE\n"
"search_match_case=FALSE\n"
"search_match_whole_words=FALSE\n"
"search_trim_results=TRUE\n"
"\n"
"-- other:\n"
"give_scite_focus=FALSE\n"
"search_give_scite_focus=TRUE\n"
"\n"
"show_recent=FALSE\n"
"recent_add_to_bottom=FALSE\n"
"\n"
"hide_statusbar=FALSE\n"
"\n"
"\n";
/**
* Check config string - is it valid?
*/
gboolean check_config_string(gchar *in_config)
{
gboolean result = FALSE;
int co=0;
gdouble tempdouble;
gchar *tempstring = NULL;
int pos=-1;
gchar *value=in_config;
// clear scite Path
prefs.scite_path = NULL;
for (co=0; co < (int)strlen(in_config); co++) {
if (in_config[co] == '=') pos=co;
if (pos == -1) {
value++;
}
}
if (pos != -1) {
tempstring = g_strndup(in_config, pos);
value++;
}
if ((tempstring != NULL) && (value != NULL)) {
tempstring = g_strchug(tempstring);
tempstring = g_strchomp(tempstring);
value = g_strchug(value);
value = g_strchomp(value);
if (g_ascii_strcasecmp(tempstring, "xpos")==0) {
tempdouble = g_ascii_strtod(value, NULL);
prefs.xpos = (int) tempdouble;
}
if (g_ascii_strcasecmp(tempstring, "ypos")==0) {
tempdouble = g_ascii_strtod(value, NULL);
prefs.ypos = (int)tempdouble;
}
if (g_ascii_strcasecmp(tempstring, "width")==0) {
tempdouble = g_ascii_strtod(value, NULL);
prefs.width = (int)tempdouble;
}
if (g_ascii_strcasecmp(tempstring, "height")==0) {
tempdouble = g_ascii_strtod(value, NULL);
prefs.height = (int)tempdouble;
}
if (g_ascii_strcasecmp(tempstring, "give_scite_focus")==0) {
if (g_ascii_strcasecmp(value, "TRUE")==0) {
prefs.give_scite_focus = TRUE;
}
}
if (g_ascii_strcasecmp(tempstring, "scite_path")==0) {
prefs.scite_path = g_strdup_printf("%s", value);
}
if (g_ascii_strcasecmp(tempstring, "show_recent") == 0) {
if (g_ascii_strcasecmp(value, "TRUE") == 0) {
prefs.show_recent = TRUE;
}
}
if (g_ascii_strcasecmp(tempstring, "recent_add_to_bottom")==0) {
if (g_ascii_strcasecmp(value, "TRUE") == 0) {
prefs.recent_add_to_bottom = TRUE;
}
}
if (g_ascii_strcasecmp(tempstring, "hide_statusbar") == 0) {
if (g_ascii_strcasecmp(value, "TRUE") == 0) {
prefs.hide_statusbar = TRUE;
}
}
if (g_ascii_strcasecmp(tempstring, "start_scite") == 0) {
if (g_ascii_strcasecmp(value, "TRUE") == 0) {
prefs.start_scite = TRUE;
}
}
}
if (tempstring != NULL) g_free(tempstring);
return result;
}
/**
* init_prefs
*/
gboolean init_prefs(gchar *target_directory, GError **err)
{
//FILE *fp;
//gchar buf[PREFS_BUFSIZE];
gchar *config_string = NULL;
gboolean result = TRUE;
// the list of strings
gchar **list = NULL;
// Set default values
prefs.lhs = 1;
prefs.width = 200;
prefs.height = 600;
prefs.verbosity = 0; // No informational messages
prefs.last_file_filter = -1; // All files (my choice)
prefs.give_scite_focus = FALSE;
prefs.show_recent = FALSE;
prefs.recent_add_to_bottom = FALSE;
prefs.scite_path = NULL;
prefs.hide_statusbar = FALSE;
prefs.start_scite = FALSE;
// First, check the file ~/.config/sciteprojrc.lua
gchar *test_prefs_filename = g_build_filename(g_get_user_config_dir(), "sciteprojrc.lua",NULL);
if (g_file_test(test_prefs_filename, G_FILE_TEST_IS_REGULAR)) {
// the file exists, load it:
if (!g_file_get_contents(test_prefs_filename, &config_string, NULL, err)) {
result = FALSE;
goto ERROR;
}
if (load_lua_config(test_prefs_filename, config_string) != 0) {
printf("error loading LUA config!\n");
}
g_free(config_string);
}
g_free(test_prefs_filename);
// Otherwise, check current directory, and the directories that the previous
// versions used
test_prefs_filename = g_build_filename(target_directory, "sciteprojrc.lua", NULL);
if (!g_file_test(test_prefs_filename, G_FILE_TEST_IS_REGULAR)) {
// the result of g_get_user_config_dir doesn't need to be freed, so we
// dont need to put it in a pointer of its own.
prefs_filename = g_build_filename(g_get_user_config_dir(), "sciteprojrc",NULL);
// Check if a config-file exists
if (!g_file_test(prefs_filename, G_FILE_TEST_IS_REGULAR)) {
// First, check if ~/.sciteproj exists.
gchar *old_configfilename = g_build_filename(g_get_home_dir(), ".sciteproj", NULL);
if (!g_file_test(old_configfilename, G_FILE_TEST_IS_REGULAR)) {
// No config-file exists, default to sciteprojrc.lua
prefs_filename = g_strdup(test_prefs_filename);
}
}
} else {
prefs_filename = g_strdup(test_prefs_filename);
}
g_free(test_prefs_filename);
// Load preferences from config
if (!g_file_get_contents(prefs_filename, &config_string, NULL, err)) {
result = FALSE;
goto ERROR;
}
// Check if it is an old-style config, or a new LUA one
if (check_for_old_style_config(config_string)) {
gchar **savedlist = NULL;
debug_printf("Old style config\n");
// split out the lines, and add each to the list of strings
list = g_strsplit(config_string, "\n", -1);
savedlist = list;
gchar *temp = NULL;
do {
temp = *list;
if (temp != NULL) {
if ((temp[0] != '#') && (strcmp(temp, "")!=0)) {
// We got a valid string:
// no starting #, and not an empty string.
check_config_string(temp);
}
list++;
}
} while (temp != NULL);
g_strfreev(savedlist);
} else {
// ----- New style (LUA) config
//if (!load_lua_config(config_string)) {
if (load_lua_config(prefs_filename, config_string)!=0) {
printf("error loading LUA config!\n");
}
}
ERROR:
g_free(config_string);
return result;
}
/**
*
*/
void done_prefs()
{
g_free(prefs_filename);
}
/**
*
*/
gboolean check_for_old_style_config(const gchar *teststring)
{
gboolean result = FALSE;
int co = 0;
// We satisfy it by checking for the default header and assume that if
// that is there, we have an old-styled (non-LUA) config file
if (g_str_has_prefix(teststring,
"# ---------------------------\n"
"# Configuration for SciteProj\n"
"# ---------------------------\n")
) {
result = TRUE;
}
// Another way to check is to check for lines starting with # - as a comment
// LUA uses "--", so this is should work to identify oldstyle config.
for (co=0; co