TheSwamp
Code Red => .NET => Topic started by: dugk on March 23, 2010, 05:15:19 PM
-
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.
Thanks!
doug
-
Having never used doslib myself, but knowing a thing or two about .NET, you will have to give more of an explanation than that to get more help from some of us, me in particular.
With more background, it could be easy....
-
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.
Thanks!
doug
Do you want to know if it can be done or do you want someone to build it for you ?
Yes it can be done.
-
I don't use dosLib, so I have no clue what your after. Whats it do, and maybe I can help you
-
Man, you both beat me to it
-
I don't use dosLib, so I have no clue what your after. Whats it do, and maybe I can help you
piccy from help.
I have a .NET library under development at home, but can't make the source public.
-
Why using .NET or an ARX to define a LISP function which can be defined in plain LISP ?
;; gc:ListBox (gile)
;; Dialog box to make one ore more choice in a list (or popup)
;;
;; Arguments
;; title : the dialog title (string)
;; msg ; message (string), "" or nil for none
;; keylab : an association list ((key1 . label1) (key2 . label2) ...)
;; flag : 0 = popup list
;; 1 = single choice list
;; 2 = multi choices list
;;
;; Return : the option key (flag = 0 ou 1) or the options keys list (flag = 2)
;;
;; Examples
;; (gc:listbox "Layout" "Choose a layout" (mapcar 'cons (layoulist) (layoutlist)) 1)
;; (gc:listbox "Separator" "Specify the separator" '(("," . "Comma") (";" . "Semicolon") ("\t" . "Tabulation")) 1)
(defun gc:ListBox (title msg keylab flag / tmp file dcl_id choice)
(setq tmp (vl-filename-mktemp "tmp.dcl")
file (open tmp "w")
)
(write-line
(strcat "ListBox:dialog{label=\"" title "\";")
file
)
(if (and msg (/= msg ""))
(write-line (strcat ":text{label=\"" msg "\";}") file)
)
(write-line
(cond
((= 0 flag) "spacer;:popup_list{key=\"lst\";")
((= 1 flag) "spacer;:list_box{key=\"lst\";")
(T "spacer;:list_box{key=\"lst\";multiple_select=true;")
)
file
)
(write-line "}spacer;ok_cancel;}" file)
(close file)
(setq dcl_id (load_dialog tmp))
(if (not (new_dialog "ListBox" dcl_id))
(exit)
)
(start_list "lst")
(mapcar 'add_list (mapcar 'cdr keylab))
(end_list)
(action_tile
"accept"
"(or (= (get_tile \"lst\") \"\")
(if (= 2 flag) (progn
(foreach n (str2lst (get_tile \"lst\") \" \")
(setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice)))
(setq choice (reverse choice)))
(setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab)))))
(done_dialog)"
)
(start_dialog)
(unload_dialog dcl_id)
(vl-file-delete tmp)
choice
)
Example:
(gc:listbox "Separator" "Specify the separator" '(("," . "Comma") (";" . "Semicolon") ("\t" . "Tabulation")) 1)
returns: "\t"
-
Because Lisp is so painful compared to .NET...? :-)
-
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.
Thanks!
doug
Not going to happen without creating your own, but it's certainly not difficult to do. This example only took a few minutes.
xaml
<Window x:Class="ListBoxProject.SimpleListbox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" MinHeight="300" Width="300" MinWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="5" Text="{Binding Prompt}"/>
<ListBox Grid.Column="0" Grid.Row="1" Margin="5" ItemsSource="{Binding Contents}" SelectedItem="{Binding Selection}" />
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" Margin="5">
<Button IsDefault="True" Width="50" Margin="5" Click="OnOkClick">OK</Button>
<Button IsCancel="True" Width="50" Margin="5">Cancel</Button>
</StackPanel>
</Grid>
</Window>
Code behind
using System;
using System.Collections.Generic;
using System.Windows;
namespace ListBoxProject
{
/// <summary>
/// Interaction logic for SimpleListbox.xaml
/// </summary>
public partial class SimpleListbox : Window
{
public static SimpleListbox CreateSimpleListbox (string title, string prompt, IEnumerable<string> contents)
{
return new SimpleListbox { Title = title, Prompt = prompt, Contents = contents };
}
public SimpleListbox()
{
InitializeComponent();
DataContext = this;
}
public string Prompt { get; set; }
public IEnumerable<string> Contents { get; set; }
public string Selection { get; set; }
private void OnOkClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.Selection))
{
DialogResult = false;
}
else
{
DialogResult = true;
}
}
}
}
Usage
string[] layers = {"Layer1", "Layer2", "Layer3"};
SimpleListbox lb = SimpleListbox.CreateSimpleListbox("Set Current Layer", "Select a layer", layers);
if (lb.ShowDialog() != true)
{
//user didn't select anything from the list
}
else
{
//lb.Selection contains the result
}
-
Because Lisp is so painful compared to .NET...? :-)
It's a joke :?
I thaught dugk wanted a .NET defined LISP function...
-
I thought dugk wanted a .NET defined LISP function...
I thought he did too.
-
I thought dugk wanted a .NET defined LISP function...
I thought he did too.
Hmmm...you're probably correct. Something along this line should get it. This is competely untested and I'm not sure if the indices are correct, sorry lunch is never long enough.
EDIT: Indices corrected. Lunch STILL isn't long enough.
using System;
using System.Collections.Generic;
using ListBoxProject;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace DosLibLikeLibrary
{
public class LispCommands
{
//(listbox "TITLE" "prompt" '("layer1" "layer2" "layer3"))
[LispFunction("Listbox")]
public string Listbox(ResultBuffer inputList)
{
TypedValue[] args = inputList.AsArray();
string title = args[0].Value.ToString();
string prompt = args[1].Value.ToString();
List<string> choices = new List<string>();
for (int i = 3; i < args.Length -1; i++)
{
choices.Add(args[i].Value.ToString());
}
SimpleListbox listDialog = SimpleListbox.CreateSimpleListbox(title, prompt, choices);
if (acadApp.ShowModalWindow(listDialog) != true)
return "";
else
return listDialog.Selection;
}
}
}