summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-07-15 05:51:35 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-07-15 05:51:35 +0000
commit24194964c2c833cf325c5c75dd39f2934fc5ab0e (patch)
treee5fbc38eb88502dc0a434b4e655613caee2316b1 /src
parentFix for bug #1024325 (DXF output, Python script error: No translation file fo... (diff)
downloadinkscape-24194964c2c833cf325c5c75dd39f2934fc5ab0e.tar.gz
inkscape-24194964c2c833cf325c5c75dd39f2934fc5ab0e.zip
Fix for 1023655 : Improvments to Embedded script UI
(bzr r11549)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/document-properties.cpp29
-rw-r--r--src/ui/dialog/filedialog.h5
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.cpp20
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.h7
-rw-r--r--src/ui/dialog/filedialogimpl-win32.cpp62
-rw-r--r--src/ui/dialog/filedialogimpl-win32.h8
6 files changed, 117 insertions, 14 deletions
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index 71fc3ac1f..2d79c6dd7 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -617,7 +617,7 @@ void DocumentProperties::build_scripting()
Gtk::Label *label_external= manage (new Gtk::Label("", Gtk::ALIGN_START));
label_external->set_markup (_("<b>External script files:</b>"));
- _external_add_btn.set_tooltip_text(_("Link"));
+ _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file"));
_external_add_btn.set_image(*manage(Glib::wrap(gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR ) )));
_external_remove_btn.set_tooltip_text(_("Remove"));
@@ -872,8 +872,9 @@ void DocumentProperties::browseExternalScript() {
Inkscape::UI::Dialog::FileOpenDialog::create(
*desktop->getToplevel(),
open_path,
- Inkscape::UI::Dialog::SVG_TYPES,
+ Inkscape::UI::Dialog::CUSTOM_TYPE,
_("Select a script to load"));
+ selectPrefsFileInstance->addFilterMenu("Javascript Files", "*.js");
}
//# Show the dialog
@@ -920,17 +921,19 @@ void DocumentProperties::removeExternalScript(){
const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );
while ( current ) {
- SPObject* obj = SP_OBJECT(current->data);
- SPScript* script = (SPScript*) obj;
- if (name == script->xlinkhref){
-
- //XML Tree being used directly here while it shouldn't be.
- Inkscape::XML::Node *repr = obj->getRepr();
- if (repr){
- sp_repr_unparent(repr);
-
- // inform the document, so we can undo
- DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, _("Remove external script"));
+ if (current->data && SP_IS_OBJECT(current->data)) {
+ SPObject* obj = SP_OBJECT(current->data);
+ SPScript* script = (SPScript*) obj;
+ if (name == script->xlinkhref){
+
+ //XML Tree being used directly here while it shouldn't be.
+ Inkscape::XML::Node *repr = obj->getRepr();
+ if (repr){
+ sp_repr_unparent(repr);
+
+ // inform the document, so we can undo
+ DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, _("Remove external script"));
+ }
}
}
current = g_slist_next(current);
diff --git a/src/ui/dialog/filedialog.h b/src/ui/dialog/filedialog.h
index 9b0e6a291..6a3436aea 100644
--- a/src/ui/dialog/filedialog.h
+++ b/src/ui/dialog/filedialog.h
@@ -46,7 +46,8 @@ typedef enum {
SVG_TYPES,
IMPORT_TYPES,
EXPORT_TYPES,
- EXE_TYPES
+ EXE_TYPES,
+ CUSTOM_TYPE
} FileDialogType;
/**
@@ -124,6 +125,8 @@ public:
virtual Glib::ustring getCurrentDirectory() = 0;
+ virtual void addFilterMenu(Glib::ustring name, Glib::ustring pattern) = 0;
+
protected:
/**
* Filename that was given
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp
index d1a3167a6..1663eb0b6 100644
--- a/src/ui/dialog/filedialogimpl-gtkmm.cpp
+++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp
@@ -732,8 +732,28 @@ FileOpenDialogImplGtk::~FileOpenDialogImplGtk()
}
+void FileOpenDialogImplGtk::addFilterMenu(Glib::ustring name, Glib::ustring pattern)
+{
+
+#if WITH_GTKMM_3_0
+ Glib::RefPtr<Gtk::FileFilter> allFilter = Gtk::FileFilter::create();
+ allFilter->set_name(_(name.c_str()));
+ allFilter->add_pattern(pattern);
+#else
+ Gtk::FileFilter allFilter;
+ allFilter.set_name(_(name.c_str()));
+ allFilter.add_pattern(pattern);
+#endif
+ extensionMap[Glib::ustring(_("All Files"))]=NULL;
+ add_filter(allFilter);
+}
+
void FileOpenDialogImplGtk::createFilterMenu()
{
+ if (_dialogType == CUSTOM_TYPE) {
+ return;
+ }
+
if (_dialogType == EXE_TYPES) {
#if WITH_GTKMM_3_0
Glib::RefPtr<Gtk::FileFilter> allFilter = Gtk::FileFilter::create();
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.h b/src/ui/dialog/filedialogimpl-gtkmm.h
index 4caa106ad..2c22e7367 100644
--- a/src/ui/dialog/filedialogimpl-gtkmm.h
+++ b/src/ui/dialog/filedialogimpl-gtkmm.h
@@ -236,6 +236,12 @@ public:
Glib::ustring getCurrentDirectory();
+ /// Add a custom file filter menu item
+ /// @param name - Name of the filter (such as "Javscript")
+ /// @param pattern - File filtering patter (such as "*.js")
+ /// Use the FileDialogType::CUSTOM_TYPE in constructor to not include other file types
+ void addFilterMenu(Glib::ustring name, Glib::ustring pattern);
+
private:
/**
@@ -243,6 +249,7 @@ private:
*/
void createFilterMenu();
+
/**
* Filter name->extension lookup
*/
diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp
index 089ec1737..5891f25ac 100644
--- a/src/ui/dialog/filedialogimpl-win32.cpp
+++ b/src/ui/dialog/filedialogimpl-win32.cpp
@@ -203,6 +203,64 @@ FileOpenDialogImplWin32::~FileOpenDialogImplWin32()
delete[] _extension_map;
}
+void FileOpenDialogImplWin32::addFilterMenu(Glib::ustring name, Glib::ustring pattern)
+{
+ list<Filter> filter_list;
+
+ int extension_index = 0;
+ int filter_length = 1;
+
+ ustring all_exe_files_filter = pattern;
+ Filter all_exe_files;
+
+ const gchar *all_exe_files_filter_name = name.data();
+
+ // Calculate the amount of memory required
+ int filter_count = 1;
+
+ _extension_map = new Inkscape::Extension::Extension*[filter_count];
+
+ // Filter Executable Files
+ all_exe_files.name = g_utf8_to_utf16(all_exe_files_filter_name,
+ -1, NULL, &all_exe_files.name_length, NULL);
+ all_exe_files.filter = g_utf8_to_utf16(all_exe_files_filter.data(),
+ -1, NULL, &all_exe_files.filter_length, NULL);
+ all_exe_files.mod = NULL;
+ filter_list.push_front(all_exe_files);
+
+ _filter = new wchar_t[filter_length];
+ wchar_t *filterptr = _filter;
+
+ for(list<Filter>::iterator filter_iterator = filter_list.begin();
+ filter_iterator != filter_list.end(); ++filter_iterator)
+ {
+ const Filter &filter = *filter_iterator;
+
+ wcsncpy(filterptr, (wchar_t*)filter.name, filter.name_length);
+ filterptr += filter.name_length;
+ g_free(filter.name);
+
+ *(filterptr++) = L'\0';
+ *(filterptr++) = L'*';
+
+ if(filter.filter != NULL)
+ {
+ wcsncpy(filterptr, (wchar_t*)filter.filter, filter.filter_length);
+ filterptr += filter.filter_length;
+ g_free(filter.filter);
+ }
+
+ *(filterptr++) = L'\0';
+
+ // Associate this input extension with the file type name
+ _extension_map[extension_index++] = filter.mod;
+ }
+ *(filterptr++) = L'\0';
+
+ _filter_count = extension_index;
+ _filter_index = 1; // Select the 1st filter in the list
+}
+
void FileOpenDialogImplWin32::createFilterMenu()
{
list<Filter> filter_list;
@@ -210,6 +268,10 @@ void FileOpenDialogImplWin32::createFilterMenu()
int extension_index = 0;
int filter_length = 1;
+ if (dialogType == CUSTOM_TYPE) {
+ return;
+ }
+
if (dialogType != EXE_TYPES) {
// Compose the filter string
Inkscape::Extension::DB::InputList extension_list;
diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h
index a6f7d6239..d016b0a24 100644
--- a/src/ui/dialog/filedialogimpl-win32.h
+++ b/src/ui/dialog/filedialogimpl-win32.h
@@ -54,6 +54,7 @@ public:
/// Get the path of the current directory
Glib::ustring getCurrentDirectory();
+
protected:
/// The dialog type
FileDialogType dialogType;
@@ -148,6 +149,13 @@ public:
virtual Inkscape::Extension::Extension* getSelectionType()
{ return FileDialogBaseWin32::getSelectionType(); }
+
+ /// Add a custom file filter menu item
+ /// @param name - Name of the filter (such as "Javscript")
+ /// @param pattern - File filtering patter (such as "*.js")
+ /// Use the FileDialogType::CUSTOM_TYPE in constructor to not include other file types
+ virtual void addFilterMenu(Glib::ustring name, Glib::ustring pattern);
+
private:
/// Create filter menu for this type of dialog